]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step2.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Import / views / view.step2.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description: view handler for step 2 of the import process
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  ********************************************************************************/
44
45 require_once('modules/Import/views/ImportView.php');
46
47
48 class ImportViewStep2 extends ImportView
49 {
50         protected $pageTitleKey = 'LBL_STEP_2_TITLE';
51
52
53         /**
54      * @see SugarView::display()
55      */
56         public function display()
57     {
58         global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map, $import_mod_strings;
59
60         $this->instruction = 'LBL_SELECT_UPLOAD_INSTRUCTION';
61         $this->ss->assign('INSTRUCTION', $this->getInstruction());
62
63         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
64         $this->ss->assign("IMP", $import_mod_strings);
65         $this->ss->assign("CURRENT_STEP", $this->currentStep);
66         $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
67         $this->ss->assign("CUSTOM_DELIMITER", ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
68         $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
69             ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other'
70                 ? $_REQUEST['custom_enclosure'] :
71                 ( !empty($_REQUEST['custom_enclosure_other'])
72                     ? $_REQUEST['custom_enclosure_other'] : "" ) )));
73
74         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
75         $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
76         $this->ss->assign("JAVASCRIPT", $this->_getJS());
77         $this->ss->assign("SAMPLE_URL", "<a href=\"javascript: void(0);\" onclick=\"window.location.href='index.php?entryPoint=export&module=".$_REQUEST['import_module']."&action=index&all=true&sample=true'\" >".$mod_strings['LBL_EXAMPLE_FILE']."</a>");
78
79         $displayBackBttn = isset($_REQUEST['action']) && $_REQUEST['action'] == 'Step2' && isset($_REQUEST['current_step']) && $_REQUEST['current_step']!=='2'? TRUE : FALSE; //bug 51239
80         $this->ss->assign("displayBackBttn", $displayBackBttn);
81
82         // get user defined import maps
83         $is_admin = is_admin($current_user);
84         if($is_admin)
85             $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_ADMIN_HELP'];
86         else
87             $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_HELP'];
88
89         $this->ss->assign('savedMappingHelpText',$savedMappingHelpText);
90         $this->ss->assign('is_admin',$is_admin);
91
92         $import_map_seed = new ImportMap();
93         $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields( array('assigned_user_id' => $current_user->id, 'is_published' => 'no','module' => $_REQUEST['import_module']));
94
95         if( count($custom_imports_arr) )
96         {
97             $custom = array();
98             foreach ( $custom_imports_arr as $import)
99             {
100                 $custom[] = array( "IMPORT_NAME" => $import->name,"IMPORT_ID"   => $import->id);
101             }
102             $this->ss->assign('custom_imports',$custom);
103         }
104
105         // get globally defined import maps
106         $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(array('is_published' => 'yes', 'module' => $_REQUEST['import_module'],) );
107         if ( count($published_imports_arr) )
108         {
109             $published = array();
110             foreach ( $published_imports_arr as $import)
111             {
112                 $published[] = array("IMPORT_NAME" => $import->name, "IMPORT_ID"   => $import->id);
113             }
114             $this->ss->assign('published_imports',$published);
115         }
116         //End custom mapping
117
118         // add instructions for anything other than custom_delimited
119         $instructions = array();
120         $lang_key = "CUSTOM";
121
122         for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
123         {
124             $instructions[] = array(
125                 "STEP_NUM"         => $mod_strings["LBL_NUM_$i"],
126                 "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
127             );
128         }
129         $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
130         $this->ss->assign("instructions",$instructions);
131
132         $content = $this->ss->fetch('modules/Import/tpls/step2.tpl');
133         $this->ss->assign("CONTENT",$content);
134         $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
135     }
136
137     /**
138      * Returns JS used in this view
139      */
140     private function _getJS()
141     {
142         global $mod_strings;
143
144         return <<<EOJAVASCRIPT
145
146 if( document.getElementById('goback') )
147 {
148     document.getElementById('goback').onclick = function()
149     {
150         document.getElementById('importstep2').action.value = 'Step1';
151         return true;
152     }
153 }
154
155 document.getElementById('gonext').onclick = function(){
156     // warning message that tells user that updates can not be undone
157     if(document.getElementById('import_update').checked)
158     {
159         ret = confirm(SUGAR.language.get("Import", 'LBL_CONFIRM_IMPORT'));
160         if (!ret) {
161             return false;
162         }
163     }
164     clear_all_errors();
165     var isError = false;
166     // be sure we specify a file to upload
167     if (document.getElementById('importstep2').userfile.value == "") {
168         add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
169         isError = true;
170     }
171
172     return !isError;
173
174 }
175
176 function publishMapping(elem, publish, mappingId)
177 {
178     if( typeof(elem.publish) != 'undefined' )
179         publish = elem.publish;
180
181     var url = 'index.php?action=mapping&module=Import&publish=' + publish + '&import_map_id=' + mappingId;
182     var callback = {
183                         success: function(o)
184                         {
185                             var r = YAHOO.lang.JSON.parse(o.responseText);
186                             if( r.message != '')
187                                 alert(r.message);
188                         },
189                         failure: function(o) {}
190                    };
191     YAHOO.util.Connect.asyncRequest('GET', url, callback);
192     //Toggle the button title
193     if(publish == 'yes')
194     {
195         var newTitle = SUGAR.language.get('Import','LBL_UNPUBLISH');
196         var newPublish = 'no';
197     }
198     else
199     {
200         var newTitle = SUGAR.language.get('Import','LBL_PUBLISH');
201         var newPublish = 'yes';
202     }
203
204     elem.value = newTitle;
205     elem.publish = newPublish;
206
207 }
208 function deleteMapping(elemId, mappingId )
209 {
210     var elem = document.getElementById(elemId);
211     var table = elem.parentNode;
212     table.deleteRow(elem.rowIndex);
213
214     var url = 'index.php?action=mapping&module=Import&delete_map_id=' + mappingId;
215     var callback = {
216                         success: function(o)
217                         {
218                             var r = YAHOO.lang.JSON.parse(o.responseText);
219                             if( r.message != '')
220                                 alert(r.message);
221                         },
222                         failure: function(o) {}
223                    };
224     YAHOO.util.Connect.asyncRequest('GET', url, callback);
225 }
226 var deselectEl = document.getElementById('deselect');
227 if(deselectEl)
228 {
229     deselectEl.onclick = function() {
230         var els = document.getElementsByName('source');
231         for(i=0;i<els.length;i++)
232         {
233             els[i].checked = false;
234         }
235     }
236 }
237
238 EOJAVASCRIPT;
239     }
240 }
241
242