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('include/MVC/View/SugarView.php');
47 class ImportViewStep1 extends SugarView
50 * @see SugarView::getMenu()
52 public function getMenu(
56 global $mod_strings, $current_language;
59 $module = $_REQUEST['import_module'];
61 $old_mod_strings = $mod_strings;
62 $mod_strings = return_module_language($current_language, $module);
63 $returnMenu = parent::getMenu($module);
64 $mod_strings = $old_mod_strings;
70 * @see SugarView::_getModuleTab()
72 protected function _getModuleTab()
74 global $app_list_strings, $moduleTabMap;
76 // Need to figure out what tab this module belongs to, most modules have their own tabs, but there are exceptions.
77 if ( !empty($_REQUEST['module_tab']) )
78 return $_REQUEST['module_tab'];
79 elseif ( isset($moduleTabMap[$_REQUEST['import_module']]) )
80 return $moduleTabMap[$_REQUEST['import_module']];
81 // Default anonymous pages to be under Home
82 elseif ( !isset($app_list_strings['moduleList'][$_REQUEST['import_module']]) )
85 return $_REQUEST['import_module'];
89 * @see SugarView::_getModuleTitleParams()
91 protected function _getModuleTitleParams($browserTitle = false)
93 global $mod_strings, $app_list_strings;
95 $iconPath = $this->getModuleTitleIconPath($this->module);
96 $returnArray = array();
97 if (!empty($iconPath) && !$browserTitle) {
98 $returnArray[] = "<a href='index.php?module={$_REQUEST['import_module']}&action=index'><img src='{$iconPath}' alt='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' title='{$app_list_strings['moduleList'][$_REQUEST['import_module']]}' align='absmiddle'></a>";
101 $returnArray[] = $app_list_strings['moduleList'][$_REQUEST['import_module']];
103 $returnArray[] = "<a href='index.php?module=Import&action=Step1&import_module={$_REQUEST['import_module']}'>".$mod_strings['LBL_MODULE_NAME']."</a>";
104 $returnArray[] = $mod_strings['LBL_STEP_1_TITLE'];
109 private function _retrieveParams() {
110 $selectedData = new stdClass();
111 foreach ($_POST as $key => &$value) {
112 trim(strip_tags($value));
113 $selectedData->$key = $value;
115 if (isset($selectedData->custom_enclosure)) {
116 if ($selectedData->custom_enclosure != '"' and $selectedData->custom_enclosure != ''' and $selectedData->custom_enclosure != '') {
117 $selectedData->custom_other = true;
120 $this->ss->assign('selectedData', $selectedData);
121 return $selectedData;
125 * @see SugarView::display()
127 public function display()
129 global $mod_strings, $app_strings, $current_user;
130 global $sugar_config;
132 $selectedData = $this->_retrieveParams();
134 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle());
135 $this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
136 $this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
137 $this->ss->assign("UNPUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" alt="'.$mod_strings['LBL_UNPUBLISH'].'" border="0"'));
138 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
139 $this->ss->assign("JAVASCRIPT", $this->_getJS(isset($selectedData->source) ? $selectedData->source : false));
142 // handle publishing and deleting import maps
143 if (isset($_REQUEST['delete_map_id'])) {
144 $import_map = new ImportMap();
145 $import_map->mark_deleted($_REQUEST['delete_map_id']);
148 if (isset($_REQUEST['publish']) ) {
149 $import_map = new ImportMap();
152 $import_map = $import_map->retrieve($_REQUEST['import_map_id'], false);
154 if ($_REQUEST['publish'] == 'yes') {
155 $result = $import_map->mark_published($current_user->id,true);
157 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_PUBLISH']);
160 elseif ( $_REQUEST['publish'] == 'no') {
161 // if you don't own this importmap, you do now!
162 // unless you have a map by the same name
163 $result = $import_map->mark_published($current_user->id,false);
165 $this->ss->assign("ERROR",$mod_strings['LBL_ERROR_UNABLE_TO_UNPUBLISH']);
171 // trigger showing other software packages
172 $this->ss->assign("show_salesforce",false);
173 $this->ss->assign("show_outlook",false);
174 $this->ss->assign("show_act",false);
175 switch ($_REQUEST['import_module']) {
179 $this->ss->assign("show_salesforce",true);
180 $this->ss->assign("show_act",true);
183 $this->ss->assign("show_salesforce",true);
184 $this->ss->assign("show_outlook",true);
185 $this->ss->assign("show_act",true);
188 $this->ss->assign("show_salesforce",true);
192 // show any custom mappings
193 if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import'))
195 while (($file = readdir($dir)) !== false)
197 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
199 require_once("custom/modules/Import/{$file}");
200 $classname = str_replace('.php','',$file);
201 $mappingClass = new $classname;
202 $custom_mappings[] = $mappingClass->name;
208 // get user defined import maps
209 $this->ss->assign('is_admin',is_admin($current_user));
210 $import_map_seed = new ImportMap();
211 $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
213 'assigned_user_id' => $current_user->id,
214 'is_published' => 'no',
215 'module' => $_REQUEST['import_module'],
219 if ( count($custom_imports_arr) ) {
221 foreach ( $custom_imports_arr as $import) {
223 "IMPORT_NAME" => $import->name,
224 "IMPORT_ID" => $import->id,
227 $this->ss->assign('custom_imports',$custom);
230 // get globally defined import maps
231 $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(
233 'is_published' => 'yes',
234 'module' => $_REQUEST['import_module'],
238 if ( count($published_imports_arr) ) {
239 $published = array();
240 foreach ( $published_imports_arr as $import) {
241 $published[] = array(
242 "IMPORT_NAME" => $import->name,
243 "IMPORT_ID" => $import->id,
246 $this->ss->assign('published_imports',$published);
249 $this->ss->display('modules/Import/tpls/step1.tpl');
253 * Returns JS used in this view
255 private function _getJS($sourceType = false)
262 $getElementById = "document.getElementById('source_{$sourceType}')";
263 $sourceType = "defineEnclosureSelectPosition('{$sourceType}', {$getElementById});";
265 return <<<EOJAVASCRIPT
266 <script type="text/javascript">
268 document.getElementById('custom_enclosure').onchange = function()
270 document.getElementById('importstep1').custom_enclosure_other.style.display = ( this.value == 'other' ? '' : 'none' );
273 document.getElementById('gonext').onclick = function()
276 var sourceSelected = false;
277 var typeSelected = false;
279 var inputs = document.getElementsByTagName('input');
280 for (var i = 0; i < inputs.length; ++i ){
281 if ( !sourceSelected && inputs[i].name == 'source' ){
282 if (inputs[i].checked) {
283 sourceSelected = true;
284 if ( inputs[i].value == 'other' && document.getElementById('importstep1').custom_delimiter.value == '' ) {
285 add_error_style('importstep1','custom_delimiter',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_CUSTOM_DELIMITER']}");
290 if ( !typeSelected && inputs[i].name == 'type' ){
291 if (inputs[i].checked) {
296 if ( !sourceSelected ) {
297 add_error_style('importstep1','source\'][\'' + (document.getElementById('importstep1').source.length - 1) + '',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_WHAT_IS']}");
300 if ( !typeSelected ) {
301 add_error_style('importstep1','type\'][\'1',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['LBL_IMPORT_TYPE']}");
307 YAHOO.util.Event.onDOMReady(function()
309 var defineEnclosureSelectPosition = function(sourceType, inputElement)
311 if (typeof (sourceType) == 'undefined') {
312 sourceType = this.value;
314 parentRow = inputElement.parentNode.parentNode;
317 enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
318 parentRow.parentNode.insertBefore(enclosureRow, document.getElementById('customDelimiter').nextSibling);
319 document.getElementById('customDelimiter').style.display = '';
320 document.getElementById('customEnclosure').style.display = '';
322 case 'tab': case 'csv':
323 enclosureRow = document.getElementById('customEnclosure').parentNode.removeChild(document.getElementById('customEnclosure'));
324 parentRow.parentNode.insertBefore(enclosureRow, parentRow.nextSibling);
325 document.getElementById('customDelimiter').style.display = 'none';
326 document.getElementById('customEnclosure').style.display = '';
329 document.getElementById('customDelimiter').style.display = 'none';
330 document.getElementById('customEnclosure').style.display = 'none';
334 var inputs = document.getElementsByTagName('input');
335 for (var i = 0; i < inputs.length; ++i ){
336 if (inputs[i].name == 'source' ) {
337 inputs[i].onclick = function () {
338 defineEnclosureSelectPosition(this.value, this);