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