Example #1
0
    /**
     * Returns JS used in this view
     */
    private function _getJS()
    {
        global $mod_strings, $sugar_config;
        $has_header = $_REQUEST['has_header'] == 'on' ? TRUE : FALSE;
        $uploadFileName = "upload://" . basename($_REQUEST['tmp_file']);
        $splitter = new ImportFileSplitter($uploadFileName, $sugar_config['import_max_records_per_file']);
        $splitter->splitSourceFile($_REQUEST['custom_delimiter'], html_entity_decode($_REQUEST['custom_enclosure'], ENT_QUOTES), $has_header);
        $count = $splitter->getFileCount() - 1;
        $recCount = $splitter->getRecordCount();
        //BEGIN DRAG DROP WIDGET
        $idc = new ImportDuplicateCheck($this->bean);
        $dupe_indexes = $idc->getDuplicateCheckIndexes();
        //grab all the import enabled fields and the field map
        $field_map = $this->getImportMap();
        $import_fields = $idc->getDuplicateCheckIndexedFiles();
        //check for saved entries from mapping
        $dupe_disabled = array();
        $dupe_enabled = array();
        $mapped_fields = array('full_name');
        //grab the list of user mapped fields
        foreach ($_REQUEST as $req_k => $req_v) {
            if (strpos($req_k, 'olnum') > 0) {
                if (empty($req_v) || $req_v != '-1') {
                    $mapped_fields[] = $req_v;
                }
            }
        }
        foreach ($import_fields as $ik => $iv) {
            //grab the field value from the key
            $ik_field = explode('::', $ik);
            //field is not a custom field and was not included in the key, or was not in mapped fields, so skip
            if (strpos($ik_field[0], 'ustomfield::') > 0 || (empty($ik_field[1]) || !in_array($ik_field[1], $mapped_fields))) {
                //skip indexed fields that are not defined in user mapping or
                continue;
            }
            if (isset($field_map['dupe_' . $ik])) {
                //index is defined in mapping, so set this index as enabled if not already defined
                $dupe_enabled[] = array("dupeVal" => $ik, "label" => $iv);
            } else {
                //index is not defined in mapping, so display as disabled if not already defined
                $dupe_disabled[] = array("dupeVal" => $ik, "label" => $iv);
            }
        }
        $enabled_dupes = json_encode($dupe_enabled);
        $disabled_dupes = json_encode($dupe_disabled);
        $stepTitle4 = $mod_strings['LBL_IMPORT_RECORDS'];
        $dateTimeFormat = $GLOBALS['timedate']->get_cal_date_time_format();
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
        $lblUsed = str_replace(":", "", $mod_strings['LBL_INDEX_USED']);
        $lblNotUsed = str_replace(":", "", $mod_strings['LBL_INDEX_NOT_USED']);
        return <<<EOJAVASCRIPT




/**
 * Singleton to handle processing the import
 */
ProcessImport = new function()
{
    /*
     * number of file to process processed
     */
    this.fileCount         = 0;

    /*
     * total files to processs
     */
    this.fileTotal         = {$count};

    /*
     * total records to process
     */
    this.recordCount       = {$recCount};

    /*
     * maximum number of records per file
     */
    this.recordThreshold   = {$sugar_config['import_max_records_per_file']};

    /*
     * submits the form
     */
    this.submit = function()
    {
        document.getElementById("importstepdup").tmp_file.value =
            document.getElementById("importstepdup").tmp_file_base.value + '-' + this.fileCount;
        YAHOO.util.Connect.setForm(document.getElementById("importstepdup"));
        YAHOO.util.Connect.asyncRequest('POST', 'index.php',
            {
                success: function(o) {
                    if (o.responseText.replace(/^\\s+|\\s+\$/g, '') != '') {
                        this.failure(o);
                    }
                    else {
                        var locationStr = "index.php?module=Import"
                            + "&action=Last"
                            + "&current_step=" + document.getElementById("importstepdup").current_step.value
                            + "&type={$type}"
                            + "&import_module={$_REQUEST['import_module']}"
                            + "&has_header=" +  document.getElementById("importstepdup").has_header.value ;
                        if ( ProcessImport.fileCount >= ProcessImport.fileTotal ) {
                        \tYAHOO.SUGAR.MessageBox.updateProgress(1,'{$mod_strings['LBL_IMPORT_COMPLETED']}');
                        \tSUGAR.util.hrefURL(locationStr);
                        }
                        else {
                            document.getElementById("importstepdup").save_map_as.value = '';
                            ProcessImport.fileCount++;
                            ProcessImport.submit();
                        }
                    }
                },
                failure: function(o) {
                \tYAHOO.SUGAR.MessageBox.minWidth = 500;
                \tYAHOO.SUGAR.MessageBox.show({
                    \ttype:  "alert",
                    \ttitle: '{$mod_strings['LBL_IMPORT_ERROR']}',
                    \tmsg:   o.responseText,
                        fn: function() { window.location.reload(true); }
                    });
                }
            }
        );
        var move = 0;
        if ( this.fileTotal > 0 ) {
            move = this.fileCount/this.fileTotal;
        }
        YAHOO.SUGAR.MessageBox.updateProgress( move,
            "{$mod_strings['LBL_IMPORT_RECORDS']} " + ((this.fileCount * this.recordThreshold) + 1)
                        + " {$mod_strings['LBL_IMPORT_RECORDS_TO']} " + Math.min(((this.fileCount+1) * this.recordThreshold),this.recordCount)
                        + " {$mod_strings['LBL_IMPORT_RECORDS_OF']} " + this.recordCount );
    }

    /*
     * begins the form submission process
     */
    this.begin = function()
    {
        datestarted = '{$mod_strings['LBL_IMPORT_STARTED']} ' +
                YAHOO.util.Date.format('{$dateTimeFormat}');
        YAHOO.SUGAR.MessageBox.show({
            title: '{$stepTitle4}',
            msg: datestarted,
            width: 500,
            type: "progress",
            closable:false,
            animEl: 'importnow'
        });
        SUGAR.saveConfigureDupes();
        this.submit();
    }
}

//begin dragdrop code
\tvar enabled_dupes = {$enabled_dupes};
\tvar disabled_dupes = {$disabled_dupes};
\tvar lblEnabled = '{$lblUsed}';
\tvar lblDisabled = '{$lblNotUsed}';


\tSUGAR.enabledDupesTable = new YAHOO.SUGAR.DragDropTable(
\t\t"enabled_div",
\t\t[{key:"label",  label: lblEnabled, width: 225, sortable: false},
\t\t {key:"module", label: lblEnabled, hidden:true}],
\t\tnew YAHOO.util.LocalDataSource(enabled_dupes, {
\t\t\tresponseSchema: {
\t\t\t   resultsList : "dupeVal",
\t\t\t   fields : [{key : "dupeVal"}, {key : "label"}]
\t\t\t}
\t\t}),
\t\t{
\t\t\theight: "300px",
\t\t\tgroup: ["enabled_div", "disabled_div"]
\t\t}
\t);
\tSUGAR.disabledDupesTable = new YAHOO.SUGAR.DragDropTable(
\t\t"disabled_div",
\t\t[{key:"label",  label: lblDisabled, width: 225, sortable: false},
\t\t {key:"module", label: lblDisabled, hidden:true}],
\t\tnew YAHOO.util.LocalDataSource(disabled_dupes, {
\t\t\tresponseSchema: {
\t\t\t   resultsList : "dupeVal",
\t\t\t   fields : [{key : "dupeVal"}, {key : "label"}]
\t\t\t}
\t\t}),
\t\t{
\t\t\theight: "300px",
\t\t \tgroup: ["enabled_div", "disabled_div"]
\t\t }
\t);
\tSUGAR.enabledDupesTable.disableEmptyRows = true;
    SUGAR.disabledDupesTable.disableEmptyRows = true;
    SUGAR.enabledDupesTable.addRow({module: "", label: ""});
    SUGAR.disabledDupesTable.addRow({module: "", label: ""});
\tSUGAR.enabledDupesTable.render();
\tSUGAR.disabledDupesTable.render();


\tSUGAR.saveConfigureDupes = function()
\t{
\t\tvar enabledTable = SUGAR.enabledDupesTable;
\t\tvar dupeVal = [];
\t\tfor(var i=0; i < enabledTable.getRecordSet().getLength(); i++){
\t\t\tvar data = enabledTable.getRecord(i).getData();
\t\t\tif (data.dupeVal && data.dupeVal != '')
\t\t\t    dupeVal[i] = data.dupeVal;
\t\t}
\t\t    YAHOO.util.Dom.get('enabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);

        var disabledTable = SUGAR.disabledDupesTable;
\t\tvar dupeVal = [];
\t\tfor(var i=0; i < disabledTable.getRecordSet().getLength(); i++){
\t\t\tvar data = disabledTable.getRecord(i).getData();
\t\t\tif (data.dupeVal && data.dupeVal != '')
\t\t\t    dupeVal[i] = data.dupeVal;
\t\t}
\t\t\tYAHOO.util.Dom.get('disabled_dupes').value = YAHOO.lang.JSON.stringify(dupeVal);
\t}




document.getElementById('goback').onclick = function(){
    document.getElementById('importstepdup').action.value = 'step3';
    document.getElementById('importstepdup').to_pdf.value = '0';
        var success = function(data) {
\t\t\tvar response = YAHOO.lang.JSON.parse(data.responseText);
\t\t\timportWizardDialogDiv = document.getElementById('importWizardDialogDiv');
\t\t\timportWizardDialogTitle = document.getElementById('importWizardDialogTitle');
\t\t\tsubmitDiv = document.getElementById('submitDiv');
\t\t\timportWizardDialogDiv.innerHTML = response['html'];
\t\t\timportWizardDialogTitle.innerHTML = response['title'];
\t\t\tSUGAR.util.evalScript(response['html']);
\t\t\tsubmitDiv.innerHTML = response['submitContent'];
\t\t\teval(response['script']);

\t\t}

        var formObject = document.getElementById('importstepdup');
\t\tYAHOO.util.Connect.setForm(formObject);
\t\tvar cObj = YAHOO.util.Connect.asyncRequest('POST', "index.php", {success: success, failure: success});
}

document.getElementById('importnow').onclick = function(){
    SUGAR.saveConfigureDupes();

    var form = document.getElementById('importstepdup');
    // Move on to next step
    document.getElementById('importstepdup').action.value = 'Step4';
    ProcessImport.begin();
}


enableQS(false);

EOJAVASCRIPT;
    }
 public function testExcludeIndexesFromDupeCheck()
 {
     //create the bean to test on
     $focus = loadBean('Contacts');
     //create the importDuplicateCheck object and get the list of duplicateCheckIndexes
     $idc = new ImportDuplicateCheck($focus);
     //get the list of importable indexes
     $indexes = $import_indexes = $focus->getIndices();
     //grab any custom indexes if they exist
     if ($focus->hasCustomFields()) {
         $custmIndexes = $focus->db->helper->get_indices($focus->table_name . '_cstm');
         $indexes = array_merge($custmIndexes, $indexes);
     }
     //get list indexes to be displayed
     $dupe_check_indexes = $idc->getDuplicateCheckIndexedFiles();
     //Make sure that the indexes used for dupe checking honors the exclusion array.  At a minimum, all beans will have
     //their id and teamset indexes excluded.
     $this->assertTrue(count($indexes) > count($dupe_check_indexes), 'Indexes specified for exclusion are not getting excluded from getDuplicateCheckIndexedFiles()');
 }