]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step2.php
Release 6.2.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-2011 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('include/MVC/View/SugarView.php');
46
47         
48 class ImportViewStep2 extends SugarView 
49 {       
50         /**
51      * @see SugarView::getMenu()
52      */
53     public function getMenu(
54         $module = null
55         )
56     {
57         global $mod_strings, $current_language;
58         
59         if ( empty($module) )
60             $module = $_REQUEST['import_module'];
61         
62         $old_mod_strings = $mod_strings;
63         $mod_strings = return_module_language($current_language, $module);
64         $returnMenu = parent::getMenu($module);
65         $mod_strings = $old_mod_strings;
66         
67         return $returnMenu;
68     }
69     
70         /**
71      * @see SugarView::_getModuleTab()
72      */
73         protected function _getModuleTab()
74     {
75         global $app_list_strings, $moduleTabMap;
76         
77                 // Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
78         if ( !empty($_REQUEST['module_tab']) )
79             return $_REQUEST['module_tab'];
80         elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
81             return $moduleTabMap[$_REQUEST['import_module']];
82         // Default anonymous pages to be under Home
83         elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
84             return 'Home';
85         else
86             return $_REQUEST['import_module'];
87         }
88         
89         /**
90          * @see SugarView::_getModuleTitleParams()
91          */
92         protected function _getModuleTitleParams()
93         {
94             global $mod_strings, $app_list_strings;
95             
96             $iconPath = $this->getModuleTitleIconPath($this->module);
97             $returnArray = array();
98             if (!empty($iconPath) && !$browserTitle) {
99                 $returnArray[] = "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><img src='{$iconPath}' alt='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' title='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' align='absmiddle'></a>";
100         }
101         else {
102             $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
103         }
104             $returnArray[] = "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>";
105             $returnArray[] = $mod_strings['LBL_STEP_2_TITLE'];
106         
107             return $returnArray;
108     }
109     
110         /** 
111      * @see SugarView::display()
112      */
113         public function display()
114     {
115         global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
116         global $import_mod_strings;
117         
118         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
119         $this->ss->assign("IMP", $import_mod_strings);
120         $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
121         $this->ss->assign("CUSTOM_DELIMITER",
122             ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
123         $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
124             ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other' 
125                 ? $_REQUEST['custom_enclosure'] : 
126                 ( !empty($_REQUEST['custom_enclosure_other']) 
127                     ? $_REQUEST['custom_enclosure_other'] : "" ) )));
128         
129         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
130         $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
131         $this->ss->assign("JAVASCRIPT", $this->_getJS());
132         
133         // special for importing from Outlook
134         if ($_REQUEST['source'] == "outlook") {
135             $this->ss->assign("SOURCE", $_REQUEST['source']);
136             $this->ss->assign("SOURCE_NAME","Outlook ");
137             $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
138         }
139         // see if the source starts with 'custom'
140         // if so, pull off the id, load that map, and get the name
141         elseif ( strncasecmp("custom:",$_REQUEST['source'],7) == 0) {
142             $id = substr($_REQUEST['source'],7);
143             $import_map_seed = new ImportMap();
144             $import_map_seed->retrieve($id, false);
145         
146             $this->ss->assign("SOURCE_ID", $import_map_seed->id);
147             $this->ss->assign("SOURCE_NAME", $import_map_seed->name);
148             $this->ss->assign("SOURCE", $import_map_seed->source);
149             if (isset($import_map_seed->delimiter)) 
150                 $this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
151             if (isset($import_map_seed->enclosure)) 
152                 $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
153             if ($import_map_seed->has_header)
154                 $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
155         }
156         else {
157             $classname = 'ImportMap' . ucfirst($_REQUEST['source']);
158             if ( file_exists("modules/Import/{$classname}.php") )
159                 require_once("modules/Import/{$classname}.php");
160             elseif ( file_exists("custom/modules/Import/{$classname}.php") )
161                 require_once("custom/modules/Import/{$classname}.php");
162             else {
163                 require_once("custom/modules/Import/ImportMapOther.php");
164                 $classname = 'ImportMapOther';
165                 $_REQUEST['source'] = 'other';
166             }
167             if ( class_exists($classname) ) {
168                 $import_map_seed = new $classname;
169                 if (isset($import_map_seed->delimiter)) 
170                     $this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
171                 if (isset($import_map_seed->enclosure)) 
172                     $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
173                 if ($import_map_seed->has_header)
174                     $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
175                 $this->ss->assign("SOURCE", $_REQUEST['source']);
176             }
177         }
178         
179         // add instructions for anything other than custom_delimited
180         if ($_REQUEST['source'] != 'other')
181         {
182             $instructions = array();
183             $lang_key = '';
184             switch($_REQUEST['source']) {
185                 case "act":
186                     $lang_key = "ACT";
187                     break;
188                 case "outlook":
189                     $lang_key = "OUTLOOK";
190                     break;
191                 case "salesforce":
192                     $lang_key = "SF";
193                     break;
194                 case "tab":
195                     $lang_key = "TAB";
196                     break;
197                 case "csv":
198                     $lang_key = "CUSTOM";
199                     break;
200                 case "other":
201                     break;
202                 default:
203                     $lang_key = "CUSTOM_MAPPING_".strtoupper($import_map_seed->name);
204                     break;
205             }
206             if ( $lang_key != '' ) {
207                 for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++) {
208                     $instructions[] = array(
209                         "STEP_NUM"         => $mod_strings["LBL_NUM_$i"],
210                         "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
211                     );
212                 }
213                 $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
214                 $this->ss->assign("instructions",$instructions);
215             }
216         }
217         
218         $this->ss->display('modules/Import/tpls/step2.tpl');
219     }
220     
221     /**
222      * Returns JS used in this view
223      */
224     private function _getJS()
225     {
226         global $mod_strings;
227     
228         return <<<EOJAVASCRIPT
229 <script type="text/javascript">
230 <!--
231 document.getElementById('goback').onclick = function(){
232     document.getElementById('importstep2').action.value = 'Step1';
233     return true;
234 }
235
236 document.getElementById('gonext').onclick = function(){
237     document.getElementById('importstep2').action.value = 'Step3';
238     clear_all_errors();
239     var isError = false;
240     // be sure we specify a file to upload
241     if (document.getElementById('importstep2').userfile.value == "") {
242         add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
243         isError = true;
244     }
245     return !isError;
246 }
247 -->
248 </script>
249
250 EOJAVASCRIPT;
251     }
252 }