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('modules/Import/sources/ImportFile.php');
46 require_once('modules/Import/ImportFileSplitter.php');
47 require_once('modules/Import/ImportCacheFiles.php');
48 require_once('modules/Import/ImportDuplicateCheck.php');
50 require_once('include/upload_file.php');
52 class ImportViewDupcheck extends ImportView
54 protected $pageTitleKey = 'LBL_STEP_DUP_TITLE';
57 * @see SugarView::display()
59 public function display()
61 global $mod_strings, $app_strings, $current_user;
64 $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
66 $this->instruction = 'LBL_SELECT_DUPLICATE_INSTRUCTION';
67 $this->ss->assign('INSTRUCTION', $this->getInstruction());
69 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
70 $this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('delete_inline','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
71 $this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('publish_inline','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
72 $this->ss->assign("UNPUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('unpublish_inline','align="absmiddle" alt="'.$mod_strings['LBL_UNPUBLISH'].'" border="0"'));
73 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
74 $this->ss->assign("CURRENT_STEP", $this->currentStep);
75 $this->ss->assign("JAVASCRIPT", $this->_getJS());
77 $content = $this->ss->fetch('modules/Import/tpls/dupcheck.tpl');
78 $this->ss->assign("CONTENT", $content);
79 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
82 private function getImportMap()
84 if( !empty($_REQUEST['source_id']) )
86 $import_map_seed = new ImportMap();
87 $import_map_seed->retrieve($_REQUEST['source_id'], false);
89 return $import_map_seed->getMapping();
98 * Returns JS used in this view
100 private function _getJS()
102 global $mod_strings, $sugar_config;
104 $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
105 $uploadFileName = "upload://".basename($_REQUEST['tmp_file']);
106 $splitter = new ImportFileSplitter($uploadFileName, $sugar_config['import_max_records_per_file']);
107 $splitter->splitSourceFile( $_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES), $has_header);
108 $count = $splitter->getFileCount()-1;
109 $recCount = $splitter->getRecordCount();
111 //BEGIN DRAG DROP WIDGET
112 $idc = new ImportDuplicateCheck($this->bean);
113 $dupe_indexes = $idc->getDuplicateCheckIndexes();
115 //grab all the import enabled fields and the field map
116 $field_map = $this->getImportMap();
117 $import_fields = $idc->getDuplicateCheckIndexedFiles();
119 //check for saved entries from mapping
120 $dupe_disabled = array();
121 $dupe_enabled = array();
122 $mapped_fields = array('full_name');
124 //grab the list of user mapped fields
125 foreach($_REQUEST as $req_k => $req_v){
126 if(strpos($req_k,'olnum')>0){
127 if(empty($req_v) || $req_v != '-1'){
128 $mapped_fields[] = $req_v;
133 foreach($import_fields as $ik=>$iv){
135 //grab the field value from the key
136 $ik_field = explode('::', $ik);
138 //field is not a custom field and was not included in the key, or was not in mapped fields, so skip
139 if(strpos($ik_field[0],'ustomfield::')>0 && (empty($ik_field[1]) || !in_array($ik_field[1], $mapped_fields))){
140 //skip indexed fields that are not defined in user mapping or
144 if(isset($field_map['dupe_'.$ik])){
145 //index is defined in mapping, so set this index as enabled if not already defined
146 $dupe_enabled[] = array("dupeVal" => $ik, "label" => $iv);
148 //index is not defined in mapping, so display as disabled if not already defined
149 $dupe_disabled[] = array("dupeVal" => $ik, "label" => $iv);
153 $enabled_dupes = json_encode($dupe_enabled);
154 $disabled_dupes = json_encode($dupe_disabled);
156 $stepTitle4 = $mod_strings['LBL_IMPORT_RECORDS'];
158 $dateTimeFormat = $GLOBALS['timedate']->get_cal_date_time_format();
159 $type = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : '';
160 $lblUsed = str_replace(":","",$mod_strings['LBL_INDEX_USED']);
161 $lblNotUsed = str_replace(":","",$mod_strings['LBL_INDEX_NOT_USED']);
162 return <<<EOJAVASCRIPT
168 * Singleton to handle processing the import
170 ProcessImport = new function()
173 * number of file to process processed
178 * total files to processs
180 this.fileTotal = {$count};
183 * total records to process
185 this.recordCount = {$recCount};
188 * maximum number of records per file
190 this.recordThreshold = {$sugar_config['import_max_records_per_file']};
195 this.submit = function()
197 document.getElementById("importstepdup").tmp_file.value =
198 document.getElementById("importstepdup").tmp_file_base.value + '-' + this.fileCount;
199 YAHOO.util.Connect.setForm(document.getElementById("importstepdup"));
200 YAHOO.util.Connect.asyncRequest('POST', 'index.php',
202 success: function(o) {
203 if (o.responseText.replace(/^\s+|\s+$/g, '') != '') {
207 var locationStr = "index.php?module=Import"
209 + "¤t_step=" + document.getElementById("importstepdup").current_step.value
211 + "&import_module={$_REQUEST['import_module']}"
212 + "&has_header=" + document.getElementById("importstepdup").has_header.value ;
213 if ( ProcessImport.fileCount >= ProcessImport.fileTotal ) {
214 YAHOO.SUGAR.MessageBox.updateProgress(1,'{$mod_strings['LBL_IMPORT_COMPLETED']}');
215 SUGAR.util.hrefURL(locationStr);
218 document.getElementById("importstepdup").save_map_as.value = '';
219 ProcessImport.fileCount++;
220 ProcessImport.submit();
224 failure: function(o) {
225 YAHOO.SUGAR.MessageBox.minWidth = 500;
226 YAHOO.SUGAR.MessageBox.show({
228 title: '{$mod_strings['LBL_IMPORT_ERROR']}',
230 fn: function() { window.location.reload(true); }
236 if ( this.fileTotal > 0 ) {
237 move = this.fileCount/this.fileTotal;
239 YAHOO.SUGAR.MessageBox.updateProgress( move,
240 "{$mod_strings['LBL_IMPORT_RECORDS']} " + ((this.fileCount * this.recordThreshold) + 1)
241 + " {$mod_strings['LBL_IMPORT_RECORDS_TO']} " + Math.min(((this.fileCount+1) * this.recordThreshold),this.recordCount)
242 + " {$mod_strings['LBL_IMPORT_RECORDS_OF']} " + this.recordCount );
246 * begins the form submission process
248 this.begin = function()
250 datestarted = '{$mod_strings['LBL_IMPORT_STARTED']} ' +
251 YAHOO.util.Date.format('{$dateTimeFormat}');
252 YAHOO.SUGAR.MessageBox.show({
253 title: '{$stepTitle4}',
260 SUGAR.saveConfigureDupes();
265 //begin dragdrop code
266 var enabled_dupes = {$enabled_dupes};
267 var disabled_dupes = {$disabled_dupes};
268 var lblEnabled = '{$lblUsed}';
269 var lblDisabled = '{$lblNotUsed}';
272 SUGAR.enabledDupesTable = new YAHOO.SUGAR.DragDropTable(
274 [{key:"label", label: lblEnabled, width: 225, sortable: false},
275 {key:"module", label: lblEnabled, hidden:true}],
276 new YAHOO.util.LocalDataSource(enabled_dupes, {
278 resultsList : "dupeVal",
279 fields : [{key : "dupeVal"}, {key : "label"}]
284 group: ["enabled_div", "disabled_div"]
287 SUGAR.disabledDupesTable = new YAHOO.SUGAR.DragDropTable(
289 [{key:"label", label: lblDisabled, width: 225, sortable: false},
290 {key:"module", label: lblDisabled, hidden:true}],
291 new YAHOO.util.LocalDataSource(disabled_dupes, {
293 resultsList : "dupeVal",
294 fields : [{key : "dupeVal"}, {key : "label"}]
299 group: ["enabled_div", "disabled_div"]
302 SUGAR.enabledDupesTable.disableEmptyRows = true;
303 SUGAR.disabledDupesTable.disableEmptyRows = true;
304 SUGAR.enabledDupesTable.addRow({module: "", label: ""});
305 SUGAR.disabledDupesTable.addRow({module: "", label: ""});
306 SUGAR.enabledDupesTable.render();
307 SUGAR.disabledDupesTable.render();
310 SUGAR.saveConfigureDupes = function()
312 var enabledTable = SUGAR.enabledDupesTable;
314 for(var i=0; i < enabledTable.getRecordSet().getLength(); i++){
315 var data = enabledTable.getRecord(i).getData();
316 if (data.dupeVal && data.dupeVal != '')
317 dupeVal[i] = data.dupeVal;
319 YAHOO.util.Dom.get('enabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);
321 var disabledTable = SUGAR.disabledDupesTable;
323 for(var i=0; i < disabledTable.getRecordSet().getLength(); i++){
324 var data = disabledTable.getRecord(i).getData();
325 if (data.dupeVal && data.dupeVal != '')
326 dupeVal[i] = data.dupeVal;
328 YAHOO.util.Dom.get('disabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);
334 document.getElementById('goback').onclick = function(){
335 document.getElementById('importstepdup').action.value = 'step3';
336 document.getElementById('importstepdup').to_pdf.value = '0';
337 var success = function(data) {
338 var response = YAHOO.lang.JSON.parse(data.responseText);
339 importWizardDialogDiv = document.getElementById('importWizardDialogDiv');
340 importWizardDialogTitle = document.getElementById('importWizardDialogTitle');
341 submitDiv = document.getElementById('submitDiv');
342 importWizardDialogDiv.innerHTML = response['html'];
343 importWizardDialogTitle.innerHTML = response['title'];
344 SUGAR.util.evalScript(response['html']);
345 submitDiv.innerHTML = response['submitContent'];
346 eval(response['script']);
350 var formObject = document.getElementById('importstepdup');
351 YAHOO.util.Connect.setForm(formObject);
352 var cObj = YAHOO.util.Connect.asyncRequest('POST', "index.php", {success: success, failure: success});
355 document.getElementById('importnow').onclick = function(){
356 SUGAR.saveConfigureDupes();
358 var form = document.getElementById('importstepdup');
359 // Move on to next step
360 document.getElementById('importstepdup').action.value = 'Step4';
361 ProcessImport.begin();