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 3 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 ImportViewStep3 extends ImportView
55 protected $pageTitleKey = 'LBL_STEP_3_TITLE';
56 protected $currentFormID = 'importstep3';
57 protected $previousAction = 'Confirm';
58 protected $nextAction = 'dupcheck';
61 * @see SugarView::display()
63 public function display()
65 global $mod_strings, $app_strings, $current_user, $sugar_config, $app_list_strings, $locale;
67 $this->ss->assign("IMPORT_MODULE", $_REQUEST['import_module']);
68 $has_header = ( isset( $_REQUEST['has_header']) ? 1 : 0 );
69 $sugar_config['import_max_records_per_file'] = ( empty($sugar_config['import_max_records_per_file']) ? 1000 : $sugar_config['import_max_records_per_file'] );
70 $this->ss->assign("CURRENT_STEP", $this->currentStep);
71 // attempt to lookup a preexisting field map
72 // use the custom one if specfied to do so in step 1
73 $mapping_file = new ImportMap();
74 $field_map = $mapping_file->set_get_import_wizard_fields();
75 $default_values = array();
76 $ignored_fields = array();
78 if ( !empty( $_REQUEST['source_id']))
80 $GLOBALS['log']->fatal("Loading import map properties.");
81 $mapping_file = new ImportMap();
82 $mapping_file->retrieve( $_REQUEST['source_id'],false);
83 $_REQUEST['source'] = $mapping_file->source;
84 $has_header = $mapping_file->has_header;
85 if (isset($mapping_file->delimiter))
86 $_REQUEST['custom_delimiter'] = $mapping_file->delimiter;
87 if (isset($mapping_file->enclosure))
88 $_REQUEST['custom_enclosure'] = htmlentities($mapping_file->enclosure);
89 $field_map = $mapping_file->getMapping();
90 //print_r($field_map);die();
91 $default_values = $mapping_file->getDefaultValues();
92 $this->ss->assign("MAPNAME",$mapping_file->name);
93 $this->ss->assign("CHECKMAP",'checked="checked" value="on"');
97 // Try to see if we have a custom mapping we can use
98 // based upon the where the records are coming from
99 // and what module we are importing into
100 $classname = 'ImportMap' . ucfirst($_REQUEST['source']);
101 if ( file_exists("modules/Import/maps/{$classname}.php") )
102 require_once("modules/Import/maps/{$classname}.php");
103 elseif ( file_exists("custom/modules/Import/maps/{$classname}.php") )
104 require_once("custom/modules/Import/maps/{$classname}.php");
106 require_once("custom/modules/Import/maps/ImportMapOther.php");
107 $classname = 'ImportMapOther';
108 $_REQUEST['source'] = 'other';
111 if ( class_exists($classname) )
113 $mapping_file = new $classname;
114 $ignored_fields = $mapping_file->getIgnoredFields($_REQUEST['import_module']);
115 $field_map2 = $mapping_file->getMapping($_REQUEST['import_module']);
116 $field_map = array_merge($field_map,$field_map2);
120 $delimeter = $this->getRequestDelimiter();
122 $this->ss->assign("CUSTOM_DELIMITER", $delimeter);
123 $this->ss->assign("CUSTOM_ENCLOSURE", ( !empty($_REQUEST['custom_enclosure']) ? $_REQUEST['custom_enclosure'] : "" ));
125 //populate import locale values from import mapping if available, these values will be used througout the rest of the code path
127 $uploadFileName = $_REQUEST['file_name'];
129 // Now parse the file and look for errors
130 $importFile = new ImportFile( $uploadFileName, $delimeter, html_entity_decode($_REQUEST['custom_enclosure'],ENT_QUOTES), FALSE);
132 if ( !$importFile->fileExists() ) {
133 $this->_showImportError($mod_strings['LBL_CANNOT_OPEN'],$_REQUEST['import_module'],'Step2');
137 $charset = $importFile->autoDetectCharacterSet();
139 // retrieve first 3 rows
142 //Keep track of the largest row count found.
144 for ( $i = 0; $i < 3; $i++ )
146 $rows[] = $importFile->getNextRow();
147 $maxFieldCount = $importFile->getFieldCount() > $maxFieldCount ? $importFile->getFieldCount() : $maxFieldCount;
149 $ret_field_count = $maxFieldCount;
151 // Bug 14689 - Parse the first data row to make sure it has non-empty data in it
153 if ( $rows[(int)$has_header] != false ) {
154 foreach ( $rows[(int)$has_header] as $value ) {
155 if ( strlen(trim($value)) > 0 ) {
162 if ($isempty || $rows[(int)$has_header] == false) {
163 $this->_showImportError($mod_strings['LBL_NO_LINES'],$_REQUEST['import_module'],'Step2');
167 // save first row to send to step 4
168 $this->ss->assign("FIRSTROW", base64_encode(serialize($rows[0])));
170 // Now build template
171 $this->ss->assign("TMP_FILE", $uploadFileName );
172 $this->ss->assign("SOURCE", $_REQUEST['source'] );
173 $this->ss->assign("TYPE", $_REQUEST['type'] );
174 $this->ss->assign("DELETE_INLINE_PNG", SugarThemeRegistry::current()->getImage('basic_search','align="absmiddle" alt="'.$app_strings['LNK_DELETE'].'" border="0"'));
175 $this->ss->assign("PUBLISH_INLINE_PNG", SugarThemeRegistry::current()->getImage('advanced_search','align="absmiddle" alt="'.$mod_strings['LBL_PUBLISH'].'" border="0"'));
177 $this->instruction = 'LBL_SELECT_MAPPING_INSTRUCTION';
178 $this->ss->assign('INSTRUCTION', $this->getInstruction());
180 $this->ss->assign("MODULE_TITLE", $this->getModuleTitle(false));
181 $this->ss->assign("STEP4_TITLE",
182 strip_tags(str_replace("\n","",getClassicModuleTitle(
183 $mod_strings['LBL_MODULE_NAME'],
184 array($mod_strings['LBL_MODULE_NAME'],$mod_strings['LBL_STEP_4_TITLE']),
188 $this->ss->assign("HEADER", $app_strings['LBL_IMPORT']." ". $mod_strings['LBL_MODULE_NAME']);
190 // we export it as email_address, but import as email1
191 $field_map['email_address'] = 'email1';
193 // build each row; row count is determined by the the number of fields in the import file
195 $mappedFields = array();
197 // this should be populated if the request comes from a 'Back' button click
198 $importColumns = $this->getImportColumns();
199 $column_sel_from_req = false;
200 if (!empty($importColumns)) {
201 $column_sel_from_req = true;
204 for($field_count = 0; $field_count < $ret_field_count; $field_count++) {
205 // See if we have any field map matches
207 // Bug 31260 - If the data rows have more columns than the header row, then just add a new header column
208 if ( !isset($rows[0][$field_count]) )
209 $rows[0][$field_count] = '';
210 // See if we can match the import row to a field in the list of fields to import
211 $firstrow_name = trim(str_replace(":","",$rows[0][$field_count]));
212 if ($has_header && isset( $field_map[$firstrow_name] ) ) {
213 $defaultValue = $field_map[$firstrow_name];
215 elseif (isset($field_map[$field_count])) {
216 $defaultValue = $field_map[$field_count];
218 elseif (empty( $_REQUEST['source_id'])) {
219 $defaultValue = trim($rows[0][$field_count]);
222 // build string of options
223 $fields = $this->bean->get_importable_fields();
226 global $current_language;
227 $moduleStrings = return_module_language($current_language, $this->bean->module_dir);
229 foreach ( $fields as $fieldname => $properties ) {
231 if (!empty($moduleStrings['LBL_EXPORT_'.strtoupper($fieldname)]) )
233 $displayname = str_replace(":","", $moduleStrings['LBL_EXPORT_'.strtoupper($fieldname)] );
235 else if (!empty ($properties['vname']))
237 $displayname = str_replace(":","",translate($properties['vname'] ,$this->bean->module_dir));
240 $displayname = str_replace(":","",translate($properties['name'] ,$this->bean->module_dir));
241 // see if this is required
244 if ( array_key_exists($fieldname, $this->bean->get_import_required_fields()) ) {
245 $req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
246 $req_class = ' class="required" ';
248 // see if we have a match
250 if ($column_sel_from_req && isset($importColumns[$field_count])) {
251 if ($fieldname == $importColumns[$field_count]) {
252 $selected = ' selected="selected" ';
253 $defaultField = $fieldname;
254 $mappedFields[] = $fieldname;
257 if ( !empty($defaultValue) && !in_array($fieldname,$mappedFields)
258 && !in_array($fieldname,$ignored_fields) )
260 if ( strtolower($fieldname) == strtolower($defaultValue)
261 || strtolower($fieldname) == str_replace(" ","_",strtolower($defaultValue))
262 || strtolower($displayname) == strtolower($defaultValue)
263 || strtolower($displayname) == str_replace(" ","_",strtolower($defaultValue)) )
265 $selected = ' selected="selected" ';
266 $defaultField = $fieldname;
267 $mappedFields[] = $fieldname;
271 // get field type information
273 if ( isset($properties['type'])
274 && isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])]) )
275 $fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
276 if ( isset($properties['comment']) )
277 $fieldtype .= ' - ' . $properties['comment'];
278 $options[$displayname.$fieldname] = '<option value="'.$fieldname.'" title="'. $displayname . htmlentities($fieldtype) . '"'
279 . $selected . $req_class . '>' . $displayname . $req_mark . '</option>\n';
282 // get default field value
283 $defaultFieldHTML = '';
284 if ( !empty($defaultField) ) {
285 $defaultFieldHTML = getControl(
286 $_REQUEST['import_module'],
288 $fields[$defaultField],
289 ( isset($default_values[$defaultField]) ? $default_values[$defaultField] : '' )
293 if ( isset($default_values[$defaultField]) )
294 unset($default_values[$defaultField]);
296 // Bug 27046 - Sort the column name picker alphabetically
299 // to be displayed in UTF-8 format
300 if (!empty($charset) && $charset != 'UTF-8') {
301 if (isset($rows[1][$field_count])) {
302 $rows[1][$field_count] = $locale->translateCharset($rows[1][$field_count], $charset);
306 $cellOneData = isset($rows[0][$field_count]) ? $rows[0][$field_count] : '';
307 $cellTwoData = isset($rows[1][$field_count]) ? $rows[1][$field_count] : '';
308 $cellThreeData = isset($rows[2][$field_count]) ? $rows[2][$field_count] : '';
310 'field_choices' => implode('',$options),
311 'default_field' => $defaultFieldHTML,
312 'cell1' => str_replace(""",'', htmlspecialchars($cellOneData)),
313 'cell2' => str_replace(""",'', htmlspecialchars($cellTwoData)),
314 'cell3' => str_replace(""",'', htmlspecialchars($cellThreeData)),
315 'show_remove' => false,
319 // add in extra defaulted fields if they are in the mapping record
320 if ( count($default_values) > 0 ) {
321 foreach ( $default_values as $field_name => $default_value ) {
322 // build string of options
323 $fields = $this->bean->get_importable_fields();
326 foreach ( $fields as $fieldname => $properties ) {
328 if (!empty ($properties['vname']))
329 $displayname = str_replace(":","",translate($properties['vname'] ,$this->bean->module_dir));
331 $displayname = str_replace(":","",translate($properties['name'] ,$this->bean->module_dir));
332 // see if this is required
335 if ( array_key_exists($fieldname, $this->bean->get_import_required_fields()) ) {
336 $req_mark = ' ' . $app_strings['LBL_REQUIRED_SYMBOL'];
337 $req_class = ' class="required" ';
339 // see if we have a match
341 if ( strtolower($fieldname) == strtolower($field_name)
342 && !in_array($fieldname,$mappedFields)
343 && !in_array($fieldname,$ignored_fields) ) {
344 $selected = ' selected="selected" ';
345 $defaultField = $fieldname;
346 $mappedFields[] = $fieldname;
348 // get field type information
350 if ( isset($properties['type'])
351 && isset($mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])]) )
352 $fieldtype = ' [' . $mod_strings['LBL_IMPORT_FIELDDEF_' . strtoupper($properties['type'])] . '] ';
353 if ( isset($properties['comment']) )
354 $fieldtype .= ' - ' . $properties['comment'];
355 $options[$displayname.$fieldname] = '<option value="'.$fieldname.'" title="'. $displayname . $fieldtype . '"' . $selected . $req_class . '>'
356 . $displayname . $req_mark . '</option>\n';
359 // get default field value
360 $defaultFieldHTML = '';
361 if ( !empty($defaultField) ) {
362 $defaultFieldHTML = getControl(
363 $_REQUEST['import_module'],
365 $fields[$defaultField],
370 // Bug 27046 - Sort the column name picker alphabetically
374 'field_choices' => implode('',$options),
375 'default_field' => $defaultFieldHTML,
376 'show_remove' => true,
383 $this->ss->assign("COLUMNCOUNT",$ret_field_count);
384 $this->ss->assign("rows",$columns);
386 $this->ss->assign('datetimeformat', $GLOBALS['timedate']->get_cal_date_time_format());
388 // handle building index selector
389 global $dictionary, $current_language;
392 if ( $this->bean instanceof Person )
393 $module_key = "LBL_CONTACTS_NOTE_";
394 elseif ( $this->bean instanceof Company )
395 $module_key = "LBL_ACCOUNTS_NOTE_";
397 $module_key = "LBL_".strtoupper($_REQUEST['import_module'])."_NOTE_";
399 for ($i = 1;isset($mod_strings[$module_key.$i]);$i++) {
400 $notetext .= '<li>' . $mod_strings[$module_key.$i] . '</li>';
402 $this->ss->assign("NOTETEXT",$notetext);
403 $this->ss->assign("HAS_HEADER",($has_header ? 'on' : 'off' ));
405 // get list of required fields
407 foreach ( array_keys($this->bean->get_import_required_fields()) as $name ) {
408 $properties = $this->bean->getFieldDefinition($name);
409 if (!empty ($properties['vname']))
410 $required[$name] = str_replace(":","",translate($properties['vname'] ,$this->bean->module_dir));
412 $required[$name] = str_replace(":","",translate($properties['name'] ,$this->bean->module_dir));
414 // include anything needed for quicksearch to work
415 require_once("include/TemplateHandler/TemplateHandler.php");
416 $quicksearch_js = TemplateHandler::createQuickSearchCode($fields,$fields,'importstep3');
418 $this->ss->assign("QS_JS", $quicksearch_js);
419 $this->ss->assign("JAVASCRIPT", $this->_getJS($required));
421 $this->ss->assign('required_fields',implode(', ',$required));
422 $this->ss->assign('CSS', $this->_getCSS());
424 $content = $this->ss->fetch('modules/Import/tpls/step3.tpl');
425 $this->ss->assign("CONTENT",$content);
426 $this->ss->display('modules/Import/tpls/wizardWrapper.tpl');
430 protected function getRequestDelimiter()
432 $delimiter = !empty($_REQUEST['custom_delimiter']) ? $_REQUEST['custom_delimiter'] : ",";
437 $delimiter = $_REQUEST['custom_delimiter_other'];
446 protected function getImportColumns()
448 $importColumns = array();
449 foreach ($_REQUEST as $name => $value)
451 // only look for var names that start with "fieldNum"
452 if (strncasecmp($name, "colnum_", 7) != 0)
455 // pull out the column position for this field name
456 $pos = substr($name, 7);
458 // now mark that we've seen this field
459 $importColumns[$pos] = $value;
462 return $importColumns;
465 protected function _getCSS()
469 textarea { width: 20em }
470 .detail tr td[scope="row"] {
474 background: transparent url('index.php?entryPoint=getImage&themeName=Sugar&themeName=Sugar&imageName=sugar-yui-sprites.png') no-repeat 0 -90px;
480 background: transparent url('index.php?entryPoint=getImage&themeName=Sugar&themeName=Sugar&imageName=sugar-yui-sprites.png') no-repeat -0 -110px;
485 border: none !important;
486 background-image: none !important;
487 background-color: transparent;
502 * Returns JS used in this view
504 * @param array $required fields that are required for the import
505 * @return string HTML output with JS code
507 protected function _getJS($required)
511 $print_required_array = "";
512 foreach ($required as $name=>$display) {
513 $print_required_array .= "required['$name'] = '". $display . "';\n";
515 $sqsWaitImage = SugarThemeRegistry::current()->getImageURL('sqsWait.gif');
517 return <<<EOJAVASCRIPT
518 document.getElementById('goback').onclick = function(){
519 document.getElementById('{$this->currentFormID}').action.value = '{$this->previousAction}';
526 validateMappings : function()
530 var form = document.getElementById('{$this->currentFormID}');
531 var hash = new Object();
532 var required = new Object();
533 $print_required_array
535 for ( i = 0; i < form.length; i++ ) {
536 if ( form.elements[i].name.indexOf("colnum",0) == 0) {
537 if ( form.elements[i].value == "-1") {
540 if ( hash[ form.elements[i].value ] == 1) {
542 add_error_style('{$this->currentFormID}',form.elements[i].name,"{$mod_strings['ERR_MULTIPLE']}");
544 hash[form.elements[i].value] = 1;
548 // check for required fields
549 for(var field_name in required) {
550 // contacts hack to bypass errors if full_name is set
551 if (field_name == 'last_name' &&
552 hash['full_name'] == 1) {
555 if ( hash[ field_name ] != 1 ) {
557 add_error_style('{$this->currentFormID}',form.colnum_0.name,
558 "{$mod_strings['ERR_MISSING_REQUIRED_FIELDS']} " + required[field_name]);
562 // return false if we got errors
563 if (isError == true) {
574 if( document.getElementById('gonext') )
576 document.getElementById('gonext').onclick = function(){
578 if( ImportView.validateMappings() )
580 // Move on to next step
581 document.getElementById('{$this->currentFormID}').action.value = '{$this->nextAction}';
589 // handle adding new row
590 document.getElementById('addrow').onclick = function(){
592 toggleDefaultColumnVisibility(false);
593 rownum = document.getElementById('{$this->currentFormID}').columncount.value;
594 newrow = document.createElement("tr");
596 column0 = document.getElementById('row_0_col_0').cloneNode(true);
597 column0.id = 'row_' + rownum + '_col_0';
598 for ( i = 0; i < column0.childNodes.length; i++ ) {
599 if ( column0.childNodes[i].name == 'colnum_0' ) {
600 column0.childNodes[i].name = 'colnum_' + rownum;
601 column0.childNodes[i].onchange = function(){
602 var module = document.getElementById('{$this->currentFormID}').import_module.value;
603 var fieldname = this.value;
604 var matches = /colnum_([0-9]+)/i.exec(this.name);
605 var fieldnum = matches[1];
606 if ( fieldname == -1 ) {
607 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '';
610 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '<img src="{$sqsWaitImage}" />'
611 YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=Import&action=GetControl&import_module='+module+'&field_name='+fieldname,
615 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = o.responseText;
616 SUGAR.util.evalScript(o.responseText);
619 failure: function(o) {/*failure handler code*/}
625 var removeButton = document.createElement("button");
626 removeButton.title = "{$mod_strings['LBL_REMOVE_ROW']}";
627 removeButton.id = 'deleterow_' + rownum;
628 removeButton.className = "removeButton";
629 var imgButton = document.createElement("img");
630 imgButton.src = "index.php?entryPoint=getImage&themeName=Sugar&imageName=id-ff-remove.png";
631 removeButton.appendChild(imgButton);
634 if ( document.getElementById('row_0_header') ) {
635 column1 = document.getElementById('row_0_header').cloneNode(true);
636 column1.innerHTML = ' ';
637 column1.style.textAlign = "right";
638 newrow.appendChild(column1);
639 column1.appendChild(removeButton);
642 newrow.appendChild(column0);
646 column3 = document.createElement('td');
647 column3.className = 'tabDetailViewDL';
648 if ( !document.getElementById('row_0_header') ) {
652 newrow.appendChild(column3);
654 column2 = document.getElementById('defaultvaluepicker_0').cloneNode(true);
655 column2.id = 'defaultvaluepicker_' + rownum;
656 newrow.appendChild(column2);
658 document.getElementById('{$this->currentFormID}').columncount.value = parseInt(document.getElementById('{$this->currentFormID}').columncount.value) + 1;
660 document.getElementById('row_0_col_0').parentNode.parentNode.insertBefore(newrow,this.parentNode.parentNode);
662 document.getElementById('deleterow_' + rownum).onclick = function(){
663 this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
669 function toggleDefaultColumnVisibility(hide)
671 if( typeof(hide) != 'undefined' && typeof(hide) == 'boolean')
673 var currentStyle = hide ? '' : 'none';
677 var currentStyle = YAHOO.util.Dom.getStyle('default_column_header_span', 'display');
679 if(currentStyle == 'none')
682 var bgColor = '#eeeeee';
683 YAHOO.util.Dom.addClass('hide_default_link', 'collapse');
684 YAHOO.util.Dom.removeClass('hide_default_link', 'expand');
685 var col2Rowspan = "1";
689 var newStyle = 'none';
690 var bgColor = '#dddddd';
691 YAHOO.util.Dom.addClass('hide_default_link', 'expand');
692 YAHOO.util.Dom.removeClass('hide_default_link', 'collapse');
693 var col2Rowspan = "2";
696 YAHOO.util.Dom.setStyle('default_column_header_span', 'display', newStyle);
697 YAHOO.util.Dom.setStyle('default_column_header', 'backgroundColor', bgColor);
700 var columnCount = document.getElementById('{$this->currentFormID}').columncount.value;
701 for(i=0;i<columnCount;i++)
703 YAHOO.util.Dom.setStyle('defaultvaluepicker_' + i, 'display', newStyle);
704 YAHOO.util.Dom.setAttribute('row_'+i+'_col_2', 'colspan', col2Rowspan);
708 var notesEl = document.getElementById('toggleNotes');
711 notesEl.onclick = function() {
712 if (document.getElementById('importNotes').style.display == 'none'){
713 document.getElementById('importNotes').style.display = '';
714 document.getElementById('toggleNotes').value='{$mod_strings['LBL_HIDE_NOTES']}';
717 document.getElementById('importNotes').style.display = 'none';
718 document.getElementById('toggleNotes').value='{$mod_strings['LBL_SHOW_NOTES']}';
724 YAHOO.util.Event.onDOMReady(function(){
725 toggleDefaultColumnVisibility();
726 YAHOO.util.Event.addListener('hide_default_link', "click", toggleDefaultColumnVisibility);
728 var selects = document.getElementsByTagName('select');
729 for (var i = 0; i < selects.length; ++i ){
730 if (selects[i].name.indexOf("colnum_") != -1 ) {
731 // fetch the field input control via ajax
732 selects[i].onchange = function(){
733 var module = document.getElementById('{$this->currentFormID}').import_module.value;
734 var fieldname = this.value;
735 var matches = /colnum_([0-9]+)/i.exec(this.name);
736 var fieldnum = matches[1];
737 if ( fieldname == -1 ) {
738 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '';
742 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = '<img src="{$sqsWaitImage}" />'
743 YAHOO.util.Connect.asyncRequest('GET', 'index.php?module=Import&action=GetControl&import_module='+module+'&field_name='+fieldname,
747 document.getElementById('defaultvaluepicker_'+fieldnum).innerHTML = o.responseText;
748 SUGAR.util.evalScript(o.responseText);
751 failure: function(o) {/*failure handler code*/}
756 var inputs = document.getElementsByTagName('input');
757 for (var i = 0; i < inputs.length; ++i ){
758 if (inputs[i].id.indexOf("deleterow_") != -1 ) {
759 inputs[i].onclick = function(){
760 this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);