]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.step1.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Import / views / view.step1.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 1 of the import process
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  ********************************************************************************/
44 require_once('modules/Import/views/ImportView.php');
45 require_once('include/externalAPI/ExternalAPIFactory.php');
46 require_once('modules/Import/Importer.php');
47
48
49 class ImportViewStep1 extends ImportView
50 {
51
52     protected $pageTitleKey = 'LBL_STEP_1_TITLE';
53
54     public function __construct($bean = null, $view_object_map = array())
55     {
56         parent::__construct($bean, $view_object_map);
57         $this->currentStep = isset($_REQUEST['current_step']) ? ($_REQUEST['current_step'] + 1) : 1;
58         $this->importModule = isset($_REQUEST['import_module']) ? $_REQUEST['import_module'] : '';
59         if( isset($_REQUEST['from_admin_wizard']) &&  $_REQUEST['from_admin_wizard'] )
60         {
61             $this->importModule = 'Administration';
62         }
63         }
64         
65         /**
66          * @see SugarView::_getModuleTitleParams()
67          */
68         protected function _getModuleTitleParams($browserTitle = false)
69         {
70             global $mod_strings, $app_list_strings;
71             
72             $iconPath = $this->getModuleTitleIconPath($this->module);
73             $returnArray = array();
74             if (!empty($iconPath) && !$browserTitle) {
75                 $returnArray[] = "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><!--not_in_theme!--><img src='{$iconPath}' alt='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' title='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' align='absmiddle'></a>";
76         }
77         else {
78             $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
79         }
80             $returnArray[] = "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>";
81             $returnArray[] = $mod_strings['LBL_STEP_1_TITLE'];
82         
83             return $returnArray;
84     }
85
86         /** 
87      * @see SugarView::display()
88      */
89         public function display()
90     {
91         global $mod_strings, $app_strings, $current_user;
92         global $sugar_config;
93
94         $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
95         $this->ss->assign("DELETE_INLINE_PNG",  SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" border="0"',null,null,'.gif',$app_strings['LNK_DELETE']));
96         $this->ss->assign("PUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" border="0"', null,null,'.gif',$mod_strings['LBL_PUBLISH']));
97         $this->ss->assign("UNPUBLISH_INLINE_PNG",  SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" border="0"', null,null,'.gif',$mod_strings['LBL_UNPUBLISH']));
98         $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
99
100         $showModuleSelection = ($this->importModule == 'Administration');
101         $importableModulesOptions = array();
102         $importablePersonModules = array();
103         //If we are coming from the admin link, get the module list.
104         if($showModuleSelection)
105         {
106             $tmpImportable = Importer::getImportableModules();
107             $importableModulesOptions = get_select_options_with_id($tmpImportable, '');
108             $importablePersonModules = $this->getImportablePersonModulesJS();
109             $this->ss->assign("IMPORT_MODULE", key($tmpImportable));
110         }
111         else
112         {
113             $this->instruction = 'LBL_SELECT_DS_INSTRUCTION';
114             $this->ss->assign('INSTRUCTION', $this->getInstruction());
115         }
116         $this->ss->assign("FROM_ADMIN", $showModuleSelection);
117         $this->ss->assign("PERSON_MODULE_LIST", json_encode($importablePersonModules));
118         $this->ss->assign("showModuleSelection", $showModuleSelection);
119         $this->ss->assign("IMPORTABLE_MODULES_OPTIONS", $importableModulesOptions);
120
121         $this->ss->assign("EXTERNAL_SOURCES", $this->getAllImportableExternalEAPMs());
122         $this->ss->assign("EXTERNAL_AUTHENTICATED_SOURCES", json_encode($this->getAuthenticatedImportableExternalEAPMs()) );
123         $selectExternal = !empty($_REQUEST['application']) ? $_REQUEST['application'] : '';
124         $this->ss->assign("selectExternalSource", $selectExternal);
125
126         $content = $this->ss->fetch('modules/Import/tpls/step1.tpl');
127         
128         $submitContent = "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"right\">";
129         $submitContent .= "<input title=\"".$mod_strings['LBL_IMPORT_COMPLETE']."\" onclick=\"SUGAR.importWizard.closeDialog();\" accessKey=\"\" class=\"button\" type=\"submit\" name=\"finished\" value=\"  ".$mod_strings['LBL_IMPORT_COMPLETE']."  \" id=\"finished\">";
130         $submitContent .= "<input title=\"".$mod_strings['LBL_NEXT']."\" accessKey=\"\" class=\"button primary\" type=\"submit\" name=\"button\" value=\"  ".$mod_strings['LBL_NEXT']."  \"  id=\"gonext\"></td></tr></table>";
131
132         $this->ss->assign("JAVASCRIPT",$this->_getJS() );
133         $this->ss->assign("CONTENT",$content);
134         $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
135
136     }
137
138     private function getImportablePersonModulesJS()
139     {
140         global $beanList;
141         $results = array();
142         foreach ($beanList as $moduleName => $beanName)
143         {
144             if( class_exists($beanName) )
145             {
146                 $tmp = new $beanName();
147                 if( isset($tmp->importable) && $tmp->importable && ($tmp instanceof Person))
148                     $results[$moduleName] = $moduleName;
149             }
150         }
151
152         return $results;
153     }
154
155     private function getAllImportableExternalEAPMs()
156     {
157         ExternalAPIFactory::clearCache();
158         return ExternalAPIFactory::getModuleDropDown('Import', TRUE, FALSE);
159     }
160
161     private function getAuthenticatedImportableExternalEAPMs()
162     {
163         return ExternalAPIFactory::getModuleDropDown('Import', FALSE, FALSE);
164     }
165     /**
166      * Returns JS used in this view
167      */
168     private function _getJS($sourceType = false)
169     {
170         global $mod_strings;
171         $EXTERNAL_AUTHENTICATED_SOURCES = json_encode($this->getAuthenticatedImportableExternalEAPMs());
172         $selectExternalSource = !empty($_REQUEST['application']) ? $_REQUEST['application'] : '';
173         
174         $showModuleSelection = ($this->importModule == 'Administration');
175         $importableModulesOptions = array();
176         $importablePersonModules = array();
177         //If we are coming from the admin link, get the module list.
178         if($showModuleSelection)
179         {
180                     $importablePersonModules = $this->getImportablePersonModulesJS();
181         }
182
183
184         $PERSON_MODULE_LIST = json_encode($importablePersonModules);
185         
186         return <<<EOJAVASCRIPT
187
188
189 document.getElementById('gonext').onclick = function()
190 {
191     clear_all_errors();
192     var csvSourceEl = document.getElementById('csv_source');
193     var isCsvSource = csvSourceEl ? csvSourceEl.checked : true;
194     if( isCsvSource )
195     {
196         document.getElementById('importstep1').action.value = 'Step2';
197         return true;
198     }
199     else
200     {
201         if(selectedExternalSource == '')
202         {
203             add_error_style('importstep1','external_source',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_EXTERNAL_SOURCE']}");
204             return false;
205         }
206
207         document.getElementById('importstep1').action.value = 'ExtStep1';
208         document.getElementById('importstep1').external_source.value = selectedExternalSource;
209
210         return true;
211     }
212 }
213
214 YAHOO.util.Event.onDOMReady(function(){
215
216     var oButtonGroup = new YAHOO.widget.ButtonGroup("smtpButtonGroup");
217
218     function toggleExternalSource(el)
219     {
220         var trEl = document.getElementById('external_sources_tr');
221         var externalSourceBttns = oButtonGroup.getButtons();
222
223         if(this.value == 'csv')
224         {
225             trEl.style.display = 'none';
226             document.getElementById('gonext').disabled = false;
227             document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
228
229             //Turn off ext source selection
230             oButtonGroup.set("checkedButton", null, true);
231             for(i=0;i<externalSourceBttns.length;i++)
232             {
233                 externalSourceBttns[i].set("checked", true, true);
234             }
235             selectedExternalSource = '';
236         }
237         else
238         {
239             trEl.style.display = '';
240             document.getElementById('gonext').disabled = true;
241             
242             //Highlight the first selection by default
243             if(externalSourceBttns.length >= 1)
244             {
245                 if(selectedExternalSource == '')
246                     oButtonGroup.check(0);
247             }
248         }
249     }
250
251     YAHOO.util.Event.addListener(['ext_source','csv_source'], "click", toggleExternalSource);
252
253     function isExtSourceAuthenticated(source)
254     {
255         if( typeof(auth_sources[source]) != 'undefined')
256             return true;
257         else
258             return false;
259     }
260
261     function isExtSourceValid(v)
262     {
263         if(v == '')
264         {
265             document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
266             return '';
267         }
268         if( !isExtSourceAuthenticated(v) )
269         {
270             document.getElementById('ext_source_sign_in_bttn').style.display = '';
271             document.getElementById('gonext').disabled = true;
272         }
273         else
274         {
275             document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
276             document.getElementById('gonext').disabled = false;
277         }
278     }
279
280     function openExtAuthWindow()
281     {
282         var import_module = document.getElementById('importstep1').import_module.value;
283         var url = "index.php?module=EAPM&return_module=Import&action=EditView&application=" + selectedExternalSource + "&return_action=" + import_module;
284         document.location = url;
285     }
286
287     function setImportModule()
288     {
289         var selectedModuleEl = document.getElementById('admin_import_module');
290         if(!selectedModuleEl)
291         {
292             return;
293         }
294
295         //Check if the module selected by the admin is a person type module, if not hide
296         //the external source.
297         var selectedModule = selectedModuleEl.value;
298         document.getElementById('importstep1').import_module.value = selectedModule;
299     }
300
301     YAHOO.util.Event.addListener('ext_source_sign_in_bttn', "click", openExtAuthWindow);
302     YAHOO.util.Event.addListener('admin_import_module', "change", setImportModule);
303
304     
305     function initExtSourceSelection()
306     {
307         var el1 = YAHOO.util.Dom.get('ext_source');
308         if(selectedExternalSource == '')
309             return;
310
311         el1.checked = true;
312         toggleExternalSource();
313         isExtSourceValid(selectedExternalSource);
314     }
315     initExtSourceSelection();
316
317     setImportModule();
318 });
319
320
321 var auth_sources = {$EXTERNAL_AUTHENTICATED_SOURCES}
322 var selectedExternalSource = '{$selectExternalSource}';
323 var personModules = {$PERSON_MODULE_LIST};
324
325 EOJAVASCRIPT;
326     }
327 }
328
329 ?>