]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/view.dupcheck.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Import / views / view.dupcheck.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
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');
49
50 require_once('include/upload_file.php');
51
52 class ImportViewDupcheck extends ImportView
53 {
54     protected $pageTitleKey = 'LBL_STEP_DUP_TITLE';
55
56         /**
57      * @see SugarView::display()
58      */
59         public function display()
60     {
61         global $mod_strings, $app_strings, $current_user;
62         global $sugar_config;
63
64         $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
65
66         $this->instruction = 'LBL_SELECT_DUPLICATE_INSTRUCTION';
67         $this->ss->assign('INSTRUCTION', $this->getInstruction());
68
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());
76
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');
80     }
81
82     private function getImportMap()
83     {
84         if( !empty($_REQUEST['source_id']) )
85         {
86             $import_map_seed = new ImportMap();
87             $import_map_seed->retrieve($_REQUEST['source_id'], false);
88
89             return $import_map_seed->getMapping();
90         }
91         else
92         {
93             return array();
94         }
95     }
96
97     /**
98      * Returns JS used in this view
99      */
100     private function _getJS()
101     {
102         global $mod_strings, $sugar_config;
103
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();
110
111         //BEGIN DRAG DROP WIDGET
112         $idc = new ImportDuplicateCheck($this->bean);
113         $dupe_indexes = $idc->getDuplicateCheckIndexes();
114
115          //grab all the import enabled fields and the field map
116          $field_map = $this->getImportMap();
117          $import_fields = $idc->getDuplicateCheckIndexedFiles();
118
119          //check for saved entries from mapping
120          $dupe_disabled =  array();
121          $dupe_enabled =  array();
122          $mapped_fields = array('full_name');
123
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;
129                  }
130              }
131          }
132
133          foreach($import_fields as $ik=>$iv){
134
135              //grab the field value from the key
136              $ik_field = explode('::', $ik);
137
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
141                 continue;
142              }
143
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);
147             }else{
148                 //index is not defined in mapping, so display as disabled if not already defined
149                 $dupe_disabled[] =  array("dupeVal" => $ik, "label" => $iv);
150             }
151         }
152
153         $enabled_dupes = json_encode($dupe_enabled);
154         $disabled_dupes = json_encode($dupe_disabled);
155
156         $stepTitle4 = $mod_strings['LBL_IMPORT_RECORDS'];
157
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
163
164
165
166
167 /**
168  * Singleton to handle processing the import
169  */
170 ProcessImport = new function()
171 {
172     /*
173      * number of file to process processed
174      */
175     this.fileCount         = 0;
176
177     /*
178      * total files to processs
179      */
180     this.fileTotal         = {$count};
181
182     /*
183      * total records to process
184      */
185     this.recordCount       = {$recCount};
186
187     /*
188      * maximum number of records per file
189      */
190     this.recordThreshold   = {$sugar_config['import_max_records_per_file']};
191
192     /*
193      * submits the form
194      */
195     this.submit = function()
196     {
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',
201             {
202                 success: function(o) {
203                     if (o.responseText.replace(/^\s+|\s+$/g, '') != '') {
204                         this.failure(o);
205                     }
206                     else {
207                         var locationStr = "index.php?module=Import"
208                             + "&action=Last"
209                             + "&current_step=" + document.getElementById("importstepdup").current_step.value
210                             + "&type={$type}"
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);
216                         }
217                         else {
218                             document.getElementById("importstepdup").save_map_as.value = '';
219                             ProcessImport.fileCount++;
220                             ProcessImport.submit();
221                         }
222                     }
223                 },
224                 failure: function(o) {
225                         YAHOO.SUGAR.MessageBox.minWidth = 500;
226                         YAHOO.SUGAR.MessageBox.show({
227                         type:  "alert",
228                         title: '{$mod_strings['LBL_IMPORT_ERROR']}',
229                         msg:   o.responseText,
230                         fn: function() { window.location.reload(true); }
231                     });
232                 }
233             }
234         );
235         var move = 0;
236         if ( this.fileTotal > 0 ) {
237             move = this.fileCount/this.fileTotal;
238         }
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 );
243     }
244
245     /*
246      * begins the form submission process
247      */
248     this.begin = function()
249     {
250         datestarted = '{$mod_strings['LBL_IMPORT_STARTED']} ' +
251                 YAHOO.util.Date.format('{$dateTimeFormat}');
252         YAHOO.SUGAR.MessageBox.show({
253             title: '{$stepTitle4}',
254             msg: datestarted,
255             width: 500,
256             type: "progress",
257             closable:false,
258             animEl: 'importnow'
259         });
260         SUGAR.saveConfigureDupes();
261         this.submit();
262     }
263 }
264
265 //begin dragdrop code
266         var enabled_dupes = {$enabled_dupes};
267         var disabled_dupes = {$disabled_dupes};
268         var lblEnabled = '{$lblUsed}';
269         var lblDisabled = '{$lblNotUsed}';
270
271
272         SUGAR.enabledDupesTable = new YAHOO.SUGAR.DragDropTable(
273                 "enabled_div",
274                 [{key:"label",  label: lblEnabled, width: 225, sortable: false},
275                  {key:"module", label: lblEnabled, hidden:true}],
276                 new YAHOO.util.LocalDataSource(enabled_dupes, {
277                         responseSchema: {
278                            resultsList : "dupeVal",
279                            fields : [{key : "dupeVal"}, {key : "label"}]
280                         }
281                 }),
282                 {
283                         height: "300px",
284                         group: ["enabled_div", "disabled_div"]
285                 }
286         );
287         SUGAR.disabledDupesTable = new YAHOO.SUGAR.DragDropTable(
288                 "disabled_div",
289                 [{key:"label",  label: lblDisabled, width: 225, sortable: false},
290                  {key:"module", label: lblDisabled, hidden:true}],
291                 new YAHOO.util.LocalDataSource(disabled_dupes, {
292                         responseSchema: {
293                            resultsList : "dupeVal",
294                            fields : [{key : "dupeVal"}, {key : "label"}]
295                         }
296                 }),
297                 {
298                         height: "300px",
299                         group: ["enabled_div", "disabled_div"]
300                  }
301         );
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();
308
309
310         SUGAR.saveConfigureDupes = function()
311         {
312                 var enabledTable = SUGAR.enabledDupesTable;
313                 var dupeVal = [];
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;
318                 }
319                     YAHOO.util.Dom.get('enabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);
320
321         var disabledTable = SUGAR.disabledDupesTable;
322                 var dupeVal = [];
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;
327                 }
328                         YAHOO.util.Dom.get('disabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);
329         }
330
331
332
333
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']);
347
348                 }
349
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});
353 }
354
355 document.getElementById('importnow').onclick = function(){
356     SUGAR.saveConfigureDupes();
357
358     var form = document.getElementById('importstepdup');
359     // Move on to next step
360     document.getElementById('importstepdup').action.value = 'Step4';
361     ProcessImport.begin();
362 }
363
364
365 enableQS(false);
366
367 EOJAVASCRIPT;
368     }
369 }
370
371 ?>