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 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;
59 global $import_mod_strings;
61 $this->instruction = 'LBL_SELECT_UPLOAD_INSTRUCTION';
62 $this->ss->assign('INSTRUCTION', $this->getInstruction());
64 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
65 $this->ss->assign("IMP", $import_mod_strings);
66 $this->ss->assign("CURRENT_STEP", $this->currentStep);
67 $this->ss->assign("TYPE",( !empty($_REQUEST['type']) ? $_REQUEST['type'] : "import" ));
68 $this->ss->assign("CUSTOM_DELIMITER", ( !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : "," ));
69 $this->ss->assign("CUSTOM_ENCLOSURE",htmlentities(
70 ( !empty($_REQUEST['custom_enclosure']) && $_REQUEST['custom_enclosure'] != 'other'
71 ? $_REQUEST['custom_enclosure'] :
72 ( !empty($_REQUEST['custom_enclosure_other'])
73 ? $_REQUEST['custom_enclosure_other'] : "" ) )));
75 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
76 $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
77 $this->ss->assign("JAVASCRIPT", $this->_getJS());
78 $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>");
80 $displayBackBttn = isset($_REQUEST['action']) && $_REQUEST['action'] != 'index'? TRUE : FALSE;
81 $this->ss->assign("displayBackBttn", $displayBackBttn);
83 $importSource = isset($_REQUEST['source']) ? $_REQUEST['source'] : 'csv' ;
84 //Start custom mapping
85 // show any custom mappings
86 if (sugar_is_dir('custom/modules/Import') && $dir = opendir('custom/modules/Import'))
88 while (($file = readdir($dir)) !== false)
90 if (sugar_is_file("custom/modules/Import/{$file}") && strpos($file,".php") !== false)
92 require_once("custom/modules/Import/{$file}");
93 $classname = str_replace('.php','',$file);
94 $mappingClass = new $classname;
95 $custom_mappings[] = $mappingClass->name;
99 // get user defined import maps
100 $is_admin = is_admin($current_user);
102 $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_ADMIN_HELP'];
104 $savedMappingHelpText = $mod_strings['LBL_MY_SAVED_HELP'];
106 $this->ss->assign('savedMappingHelpText',$savedMappingHelpText);
107 $this->ss->assign('is_admin',$is_admin);
109 $import_map_seed = new ImportMap();
110 $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']));
112 if( count($custom_imports_arr) )
115 foreach ( $custom_imports_arr as $import)
117 $custom[] = array( "IMPORT_NAME" => $import->name,"IMPORT_ID" => $import->id);
119 $this->ss->assign('custom_imports',$custom);
122 // get globally defined import maps
123 $published_imports_arr = $import_map_seed->retrieve_all_by_string_fields(array('is_published' => 'yes', 'module' => $_REQUEST['import_module'],) );
124 if ( count($published_imports_arr) )
126 $published = array();
127 foreach ( $published_imports_arr as $import)
129 $published[] = array("IMPORT_NAME" => $import->name, "IMPORT_ID" => $import->id);
131 $this->ss->assign('published_imports',$published);
135 // add instructions for anything other than custom_delimited
136 $instructions = array();
137 $lang_key = "CUSTOM";
139 for ($i = 1; isset($mod_strings["LBL_{$lang_key}_NUM_$i"]);$i++)
141 $instructions[] = array(
142 "STEP_NUM" => $mod_strings["LBL_NUM_$i"],
143 "INSTRUCTION_STEP" => $mod_strings["LBL_{$lang_key}_NUM_$i"],
146 $this->ss->assign("INSTRUCTIONS_TITLE",$mod_strings["LBL_IMPORT_{$lang_key}_TITLE"]);
147 $this->ss->assign("instructions",$instructions);
149 $content = $this->ss->fetch('modules/Import/tpls/step2.tpl');
150 $this->ss->assign("CONTENT",$content);
151 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
155 * Returns JS used in this view
157 private function _getJS()
161 return <<<EOJAVASCRIPT
163 if( document.getElementById('goback') )
165 document.getElementById('goback').onclick = function()
167 document.getElementById('importstep2').action.value = 'Step1';
172 document.getElementById('gonext').onclick = function(){
173 // warning message that tells user that updates can not be undone
174 if(document.getElementById('import_update').checked)
176 ret = confirm(SUGAR.language.get("Import", 'LBL_CONFIRM_IMPORT'));
183 // be sure we specify a file to upload
184 if (document.getElementById('importstep2').userfile.value == "") {
185 add_error_style(document.getElementById('importstep2').name,'userfile',"{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} {$mod_strings['ERR_SELECT_FILE']}");
193 function publishMapping(elem, publish, mappingId)
195 if( typeof(elem.publish) != 'undefined' )
196 publish = elem.publish;
198 var url = 'index.php?action=mapping&module=Import&publish=' + publish + '&import_map_id=' + mappingId;
202 var r = YAHOO.lang.JSON.parse(o.responseText);
206 failure: function(o) {}
208 YAHOO.util.Connect.asyncRequest('GET', url, callback);
209 //Toggle the button title
212 var newTitle = SUGAR.language.get('Import','LBL_UNPUBLISH');
213 var newPublish = 'no';
217 var newTitle = SUGAR.language.get('Import','LBL_PUBLISH');
218 var newPublish = 'yes';
221 elem.value = newTitle;
222 elem.publish = newPublish;
225 function deleteMapping(elemId, mappingId )
227 var elem = document.getElementById(elemId);
228 var table = elem.parentNode;
229 table.deleteRow(elem.rowIndex);
231 var url = 'index.php?action=mapping&module=Import&delete_map_id=' + mappingId;
235 var r = YAHOO.lang.JSON.parse(o.responseText);
239 failure: function(o) {}
241 YAHOO.util.Connect.asyncRequest('GET', url, callback);
243 var deselectEl = document.getElementById('deselect');
246 deselectEl.onclick = function() {
247 var els = document.getElementsByName('source');
248 for(i=0;i<els.length;i++)
250 els[i].checked = false;