]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step2.php
Release 6.1.4
[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 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;
95             
96         return array(
97            "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><img src='".SugarThemeRegistry::current()->getImageURL('icon_'.$_REQUEST['import_module'].'_32.png')."' alt='".$_REQUEST['import_module']."' title='".$_REQUEST['import_module']."' align='absmiddle'></a>",
98                 "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>",
99            $mod_strings['LBL_STEP_2_TITLE'],
100            );
101     }
102     
103         /** 
104      * @see SugarView::display()
105      */
106         public function display()
107     {
108         global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map;
109         global $import_mod_strings;
110         
111         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
112         $this->ss->assign("MOD", $mod_strings);
113         $this->ss->assign("APP", $app_strings);
114         $this->ss->assign("IMP", $import_mod_strings);
115         $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
116         $this->ss->assign("CUSTOM_DELIMITER",
117             ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
118         $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
119             ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other' 
120                 ? $_REQUEST['custom_enclosure'] : 
121                 ( !empty($_REQUEST['custom_enclosure_other']) 
122                     ? $_REQUEST['custom_enclosure_other'] : "" ) )));
123         
124         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
125         $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
126         $this->ss->assign("JAVASCRIPT", $this->_getJS());
127         
128         // load bean
129         $focus = loadImportBean($_REQUEST['import_module']);
130         if ( !$focus ) {
131             showImportError($mod_strings['LBL_ERROR_IMPORTS_NOT_SET_UP'],$_REQUEST['import_module']);
132             return;
133         }
134         
135         // special for importing from Outlook
136         if ($_REQUEST['source'] == "outlook") {
137             $this->ss->assign("SOURCE", $_REQUEST['source']);
138             $this->ss->assign("SOURCE_NAME","Outlook ");
139             $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
140         }
141         // see if the source starts with 'custom'
142         // if so, pull off the id, load that map, and get the name
143         elseif ( strncasecmp("custom:",$_REQUEST['source'],7) == 0) {
144             $id = substr($_REQUEST['source'],7);
145             $import_map_seed = new ImportMap();
146             $import_map_seed->retrieve($id, false);
147         
148             $this->ss->assign("SOURCE_ID", $import_map_seed->id);
149             $this->ss->assign("SOURCE_NAME", $import_map_seed->name);
150             $this->ss->assign("SOURCE", $import_map_seed->source);
151             if (isset($import_map_seed->delimiter)) 
152                 $this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
153             if (isset($import_map_seed->enclosure)) 
154                 $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
155             if ($import_map_seed->has_header)
156                 $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
157         }
158         else {
159             $classname = 'ImportMap' . ucfirst($_REQUEST['source']);
160             require("modules/Import/{$classname}.php");
161             $import_map_seed = new $classname;
162             if (isset($import_map_seed->delimiter)) 
163                 $this->ss->assign("CUSTOM_DELIMITER", $import_map_seed->delimiter);
164             if (isset($import_map_seed->enclosure)) 
165                 $this->ss->assign("CUSTOM_ENCLOSURE", htmlentities($import_map_seed->enclosure));
166             if ($import_map_seed->has_header)
167                 $this->ss->assign("HAS_HEADER_CHECKED"," CHECKED");
168             $this->ss->assign("SOURCE", $_REQUEST['source']);
169         }
170         
171         // add instructions for anything other than custom_delimited
172         if ($_REQUEST['source'] != 'other')
173         {
174             $instructions = array();
175             $lang_key = '';
176             switch($_REQUEST['source']) {
177                 case "act":
178                     $lang_key = "ACT";
179                     break;
180                 case "outlook":
181                     $lang_key = "OUTLOOK";
182                     break;
183                 case "salesforce":
184                     $lang_key = "SF";
185                     break;
186                 case "tab":
187                     $lang_key = "TAB";
188                     break;
189                 case "csv":
190                     $lang_key = "CUSTOM";
191                     break;
192             }
193             if ( $lang_key != '' ) {
194                 for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++) {
195                     $instructions[] = array(
196                         "STEP_NUM"         => $mod_strings["LBL_NUM_$i"],
197                         "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
198                     );
199                 }
200                 $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
201                 $this->ss->assign("instructions",$instructions);
202             }
203         }
204         
205         $this->ss->display('modules/Import/tpls/step2.tpl');
206     }
207     
208     /**
209      * Returns JS used in this view
210      */
211     private function _getJS()
212     {
213         global $mod_strings;
214     
215         return <<<EOJAVASCRIPT
216 <script type="text/javascript">
217 <!--
218 document.getElementById('goback').onclick = function(){
219     document.getElementById('importstep2').action.value = 'Step1';
220     return true;
221 }
222
223 document.getElementById('gonext').onclick = function(){
224     document.getElementById('importstep2').action.value = 'Step3';
225     clear_all_errors();
226     var isError = false;
227     // be sure we specify a file to upload
228     if (document.getElementById('importstep2').userfile.value == "") {
229         add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
230         isError = true;
231     }
232     return !isError;
233 }
234 -->
235 </script>
236
237 EOJAVASCRIPT;
238     }
239 }