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.
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'] )
60 $this->importModule = 'Administration';
64 * @see SugarView::display()
66 public function display()
68 global $mod_strings, $app_strings, $current_user;
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']);
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)
83 $tmpImportable = Importer::getImportableModules();
84 $importableModulesOptions = get_select_options_with_id($tmpImportable, '');
85 $importablePersonModules = $this->getImportablePersonModulesJS();
86 $this->ss->assign("IMPORT_MODULE", key($tmpImportable));
90 $this->instruction = 'LBL_SELECT_DS_INSTRUCTION';
91 $this->ss->assign('INSTRUCTION', $this->getInstruction());
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);
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);
103 $content = $this->ss->fetch('modules/Import/tpls/step1.tpl');
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>";
109 $this->ss->assign("JAVASCRIPT",$this->_getJS() );
110 $this->ss->assign("CONTENT",$content);
111 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
115 private function getImportablePersonModulesJS()
119 foreach ($beanList as $moduleName => $beanName)
121 if( class_exists($beanName) )
123 $tmp = new $beanName();
124 if( isset($tmp->importable) && $tmp->importable && ($tmp instanceof Person))
125 $results[$moduleName] = $moduleName;
132 private function getAllImportableExternalEAPMs()
134 ExternalAPIFactory::clearCache();
135 return ExternalAPIFactory::getModuleDropDown('Import', TRUE, FALSE);
138 private function getAuthenticatedImportableExternalEAPMs()
140 return ExternalAPIFactory::getModuleDropDown('Import', FALSE, FALSE);
143 * Returns JS used in this view
145 private function _getJS($sourceType = false)
148 $EXTERNAL_AUTHENTICATED_SOURCES = json_encode($this->getAuthenticatedImportableExternalEAPMs());
149 $selectExternalSource = !empty($_REQUEST['application']) ? $_REQUEST['application'] : '';
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)
157 $importablePersonModules = $this->getImportablePersonModulesJS();
161 $PERSON_MODULE_LIST = json_encode($importablePersonModules);
163 return <<<EOJAVASCRIPT
166 document.getElementById('gonext').onclick = function()
169 var csvSourceEl = document.getElementById('csv_source');
170 var isCsvSource = csvSourceEl ? csvSourceEl.checked : true;
173 document.getElementById('importstep1').action.value = 'Step2';
178 if(selectedExternalSource == '')
180 add_error_style('importstep1','external_source',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_EXTERNAL_SOURCE']}");
184 document.getElementById('importstep1').action.value = 'ExtStep1';
185 document.getElementById('importstep1').external_source.value = selectedExternalSource;
191 YAHOO.util.Event.onDOMReady(function(){
193 var oButtonGroup = new YAHOO.widget.ButtonGroup("smtpButtonGroup");
195 function toggleExternalSource(el)
197 var trEl = document.getElementById('external_sources_tr');
198 var externalSourceBttns = oButtonGroup.getButtons();
200 if(this.value == 'csv')
202 trEl.style.display = 'none';
203 document.getElementById('gonext').disabled = false;
204 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
206 //Turn off ext source selection
207 oButtonGroup.set("checkedButton", null, true);
208 for(i=0;i<externalSourceBttns.length;i++)
210 externalSourceBttns[i].set("checked", true, true);
215 trEl.style.display = '';
216 document.getElementById('gonext').disabled = true;
218 //Highlight the first selection by default
219 if(externalSourceBttns.length >= 1)
221 selectedExternalSource = externalSourceBttns[0].get("value");
222 externalSourceBttns[0].set("checked", true, true);
223 isExtSourceValid(selectedExternalSource);
228 YAHOO.util.Event.addListener(['ext_source','csv_source'], "click", toggleExternalSource);
230 function isExtSourceAuthenticated(source)
232 if( typeof(auth_sources[source]) != 'undefined')
238 function isExtSourceValid(v)
242 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
245 if( !isExtSourceAuthenticated(v) )
247 document.getElementById('ext_source_sign_in_bttn').style.display = '';
248 document.getElementById('gonext').disabled = true;
252 document.getElementById('ext_source_sign_in_bttn').style.display = 'none';
253 document.getElementById('gonext').disabled = false;
257 function openExtAuthWindow()
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;
264 function setImportModule()
266 var selectedModuleEl = document.getElementById('admin_import_module');
267 if(!selectedModuleEl)
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;
278 YAHOO.util.Event.addListener('ext_source_sign_in_bttn', "click", openExtAuthWindow);
279 YAHOO.util.Event.addListener('admin_import_module', "change", setImportModule);
282 function initExtSourceSelection()
284 var el1 = YAHOO.util.Dom.get('ext_source');
285 if(selectedExternalSource == '')
289 toggleExternalSource();
290 isExtSourceValid(selectedExternalSource);
292 initExtSourceSelection();
298 var auth_sources = {$EXTERNAL_AUTHENTICATED_SOURCES}
299 var selectedExternalSource = '{$selectExternalSource}';
300 var personModules = {$PERSON_MODULE_LIST};