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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
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');
49 class ImportViewStep1 extends ImportView
52 protected $pageTitleKey = 'LBL_STEP_1_TITLE';
54 public function __construct($bean = null, $view_object_map = array())
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'] )
61 $this->importModule = 'Administration';
66 * @see SugarView::_getModuleTitleParams()
68 protected function _getModuleTitleParams($browserTitle = false)
70 global $mod_strings, $app_list_strings;
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>";
78 $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
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'];
87 * @see SugarView::display()
89 public function display()
91 global $mod_strings, $app_strings, $current_user;
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']);
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)
106 $tmpImportable = Importer::getImportableModules();
107 $importableModulesOptions = get_select_options_with_id($tmpImportable, '');
108 $importablePersonModules = $this->getImportablePersonModulesJS();
109 $this->ss->assign("IMPORT_MODULE", key($tmpImportable));
113 $this->instruction = 'LBL_SELECT_DS_INSTRUCTION';
114 $this->ss->assign('INSTRUCTION', $this->getInstruction());
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);
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);
126 $content = $this->ss->fetch('modules/Import/tpls/step1.tpl');
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();\" class=\"button\" type=\"submit\" name=\"finished\" value=\" ".$mod_strings['LBL_IMPORT_COMPLETE']." \" id=\"finished\">";
130 $submitContent .= "<input title=\"".$mod_strings['LBL_NEXT']."\" class=\"button primary\" type=\"submit\" name=\"button\" value=\" ".$mod_strings['LBL_NEXT']." \" id=\"gonext\"></td></tr></table>";
132 $this->ss->assign("JAVASCRIPT",$this->_getJS() );
133 $this->ss->assign("CONTENT",$content);
134 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
138 private function getImportablePersonModulesJS()
142 foreach ($beanList as $moduleName => $beanName)
144 if( class_exists($beanName) )
146 $tmp = new $beanName();
147 if( isset($tmp->importable) && $tmp->importable && ($tmp instanceof Person))
148 $results[$moduleName] = $moduleName;
155 private function getAllImportableExternalEAPMs()
157 ExternalAPIFactory::clearCache();
158 return ExternalAPIFactory::getModuleDropDown('Import', TRUE, FALSE);
161 private function getAuthenticatedImportableExternalEAPMs()
163 return ExternalAPIFactory::getModuleDropDown('Import', FALSE, FALSE);
166 * Returns JS used in this view
168 private function _getJS($sourceType = false)
171 $EXTERNAL_AUTHENTICATED_SOURCES = json_encode($this->getAuthenticatedImportableExternalEAPMs());
172 $selectExternalSource = !empty($_REQUEST['application']) ? $_REQUEST['application'] : '';
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)
180 $importablePersonModules = $this->getImportablePersonModulesJS();
184 $PERSON_MODULE_LIST = json_encode($importablePersonModules);
186 return <<<EOJAVASCRIPT
189 document.getElementById('gonext').onclick = function()
192 var csvSourceEl = document.getElementById('csv_source');
193 var isCsvSource = csvSourceEl ? csvSourceEl.checked : true;
196 document.getElementById('importstep1').action.value = 'Step2';
201 if(selectedExternalSource == '')
203 add_error_style('importstep1','external_source',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_EXTERNAL_SOURCE']}");
207 document.getElementById('importstep1').action.value = 'ExtStep1';
208 document.getElementById('importstep1').external_source.value = selectedExternalSource;
214 YAHOO.util.Event.onDOMReady(function(){
216 var oButtonGroup = new YAHOO.widget.ButtonGroup("smtpButtonGroup");
218 function toggleExternalSource(el)
220 var trEl = document.getElementById('external_sources_tr');
221 var externalSourceBttns = oButtonGroup.getButtons();
223 if(this.value == 'csv')
225 trEl.style.display = 'none';
226 document.getElementById('gonext').disabled = false;
227 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
229 //Turn off ext source selection
230 oButtonGroup.set("checkedButton", null, true);
231 for(i=0;i<externalSourceBttns.length;i++)
233 externalSourceBttns[i].set("checked", true, true);
235 selectedExternalSource = '';
239 trEl.style.display = '';
240 document.getElementById('gonext').disabled = true;
242 //Highlight the first selection by default
243 if(externalSourceBttns.length >= 1)
245 if(selectedExternalSource == '')
246 oButtonGroup.check(0);
251 YAHOO.util.Event.addListener(['ext_source','csv_source'], "click", toggleExternalSource);
253 function isExtSourceAuthenticated(source)
255 if( typeof(auth_sources[source]) != 'undefined')
261 function isExtSourceValid(v)
265 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
268 if( !isExtSourceAuthenticated(v) )
270 document.getElementById('ext_source_sign_in_bttn').style.display = '';
271 document.getElementById('gonext').disabled = true;
275 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
276 document.getElementById('gonext').disabled = false;
280 function openExtAuthWindow()
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;
287 function setImportModule()
289 var selectedModuleEl = document.getElementById('admin_import_module');
290 if(!selectedModuleEl)
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;
301 YAHOO.util.Event.addListener('ext_source_sign_in_bttn', "click", openExtAuthWindow);
302 YAHOO.util.Event.addListener('admin_import_module', "change", setImportModule);
305 function initExtSourceSelection()
307 var el1 = YAHOO.util.Dom.get('ext_source');
308 if(selectedExternalSource == '')
312 toggleExternalSource();
313 isExtSourceValid(selectedExternalSource);
315 initExtSourceSelection();
321 var auth_sources = {$EXTERNAL_AUTHENTICATED_SOURCES}
322 var selectedExternalSource = '{$selectExternalSource}';
323 var personModules = {$PERSON_MODULE_LIST};