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-2013 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 2 of the import process
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 ********************************************************************************/
45 require_once('modules/Import/views/ImportView.php');
48 class ImportViewStep2 extends ImportView
50 protected $pageTitleKey = 'LBL_STEP_2_TITLE';
54 * @see SugarView::display()
56 public function display()
58 global $mod_strings, $app_list_strings, $app_strings, $current_user, $import_bean_map, $import_mod_strings;
60 $this->instruction = 'LBL_SELECT_UPLOAD_INSTRUCTION';
61 $this->ss->assign('INSTRUCTION', $this->getInstruction());
63 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
64 $this->ss->assign("IMP", $import_mod_strings);
65 $this->ss->assign("CURRENT_STEP", $this->currentStep);
66 $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
67 $this->ss->assign("CUSTOM_DELIMITER", ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
68 $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
69 ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other'
70 ? $_REQUEST['custom_enclosure'] :
71 ( !empty($_REQUEST['custom_enclosure_other'])
72 ? $_REQUEST['custom_enclosure_other'] : "" ) )));
74 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
75 $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
76 $this->ss->assign("JAVASCRIPT", $this->_getJS());
77 $this->ss->assign("SAMPLE_URL", "<a href=\"javascript: void(0);\" onclick=\"window.location.href='index.php?entryPoint=export&module=".$_REQUEST['import_module']."&action=index&all=true&sample=true'\" >".$mod_strings['LBL_EXAMPLE_FILE']."</a>");
79 $displayBackBttn = isset($_REQUEST['action']) && $_REQUEST['action'] == 'Step2' && isset($_REQUEST['current_step']) && $_REQUEST['current_step']!=='2'? TRUE : FALSE; //bug 51239
80 $this->ss->assign("displayBackBttn", $displayBackBttn);
82 // get user defined import maps
83 $is_admin = is_admin($current_user);
85 $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_ADMIN_HELP'];
87 $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_HELP'];
89 $this->ss->assign('savedMappingHelpText',$savedMappingHelpText);
90 $this->ss->assign('is_admin',$is_admin);
92 $import_map_seed = new ImportMap();
93 $custom_imports_arr = $import_map_seed->retrieve_all_by_string_fields( array('assigned_user_id' => $current_user->id, 'is_published' => 'no','module' => $_REQUEST['import_module']));
95 if( count($custom_imports_arr) )
98 foreach ( $custom_imports_arr as $import)
100 $custom[] = array( "IMPORT_NAME" => $import->name,"IMPORT_ID" => $import->id);
102 $this->ss->assign('custom_imports',$custom);
105 // get globally defined import maps
106 $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(array('is_published' => 'yes', 'module' => $_REQUEST['import_module'],) );
107 if ( count($published_imports_arr) )
109 $published = array();
110 foreach ( $published_imports_arr as $import)
112 $published[] = array("IMPORT_NAME" => $import->name, "IMPORT_ID" => $import->id);
114 $this->ss->assign('published_imports',$published);
118 // add instructions for anything other than custom_delimited
119 $instructions = array();
120 $lang_key = "CUSTOM";
122 for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
124 $instructions[] = array(
125 "STEP_NUM" => $mod_strings["LBL_NUM_$i"],
126 "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
129 $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
130 $this->ss->assign("instructions",$instructions);
132 $content = $this->ss->fetch('modules/Import/tpls/step2.tpl');
133 $this->ss->assign("CONTENT",$content);
134 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
138 * Returns JS used in this view
140 private function _getJS()
144 return <<<EOJAVASCRIPT
146 if( document.getElementById('goback') )
148 document.getElementById('goback').onclick = function()
150 document.getElementById('importstep2').action.value = 'Step1';
155 document.getElementById('gonext').onclick = function(){
156 // warning message that tells user that updates can not be undone
157 if(document.getElementById('import_update').checked)
159 ret = confirm(SUGAR.language.get("Import", 'LBL_CONFIRM_IMPORT'));
166 // be sure we specify a file to upload
167 if (document.getElementById('importstep2').userfile.value == "") {
168 add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
176 function publishMapping(elem, publish, mappingId)
178 if( typeof(elem.publish) != 'undefined' )
179 publish = elem.publish;
181 var url = 'index.php?action=mapping&module=Import&publish=' + publish + '&import_map_id=' + mappingId;
185 var r = YAHOO.lang.JSON.parse(o.responseText);
189 failure: function(o) {}
191 YAHOO.util.Connect.asyncRequest('GET', url, callback);
192 //Toggle the button title
195 var newTitle = SUGAR.language.get('Import','LBL_UNPUBLISH');
196 var newPublish = 'no';
200 var newTitle = SUGAR.language.get('Import','LBL_PUBLISH');
201 var newPublish = 'yes';
204 elem.value = newTitle;
205 elem.publish = newPublish;
208 function deleteMapping(elemId, mappingId )
210 var elem = document.getElementById(elemId);
211 var table = elem.parentNode;
212 table.deleteRow(elem.rowIndex);
214 var url = 'index.php?action=mapping&module=Import&delete_map_id=' + mappingId;
218 var r = YAHOO.lang.JSON.parse(o.responseText);
222 failure: function(o) {}
224 YAHOO.util.Connect.asyncRequest('GET', url, callback);
226 var deselectEl = document.getElementById('deselect');
229 deselectEl.onclick = function() {
230 var els = document.getElementsByName('source');
231 for(i=0;i<els.length;i++)
233 els[i].checked = false;