Example #1
0
function overwrite_duplicate_records($module, $focus, $autoDupType, $mappedFields)
{
    global $adb;
    global $dup_ow_count;
    global $process_fields;
    //Fix for 6187 : overwriting records during duplicate merge to handle uitype 10
    //handle uitype 10
    foreach ($focus->importable_fields as $fieldname => $uitype) {
        $uitype = $focus->importable_fields[$fieldname];
        if ($uitype == 10) {
            //added to handle security permissions for related modules :: for e.g. Accounts/Contacts in Potentials
            if (method_exists($focus, "add_related_to")) {
                if (!$focus->add_related_to($module, $fieldname)) {
                    if (array_key_exists($fieldname, $focus->required_fields)) {
                        $do_save = 0;
                        $skip_required_count++;
                        continue 2;
                    }
                }
            }
        }
    }
    $where_clause = "";
    $where = get_where_clause($module, $focus->column_fields);
    $sec_parameter = getSecParameterforMerge($module);
    if ($module == "Leads") {
        $sel_qry = "select vtiger_leaddetails.leadid from vtiger_leaddetails\r\n\t\tinner join vtiger_crmentity  on vtiger_crmentity.crmid = vtiger_leaddetails.leadid\r\n\t\tinner join vtiger_leadsubdetails on vtiger_leaddetails.leadid = vtiger_leadsubdetails.leadsubscriptionid\r\n\t\tinner join vtiger_leadaddress on vtiger_leadaddress.leadaddressid = vtiger_leaddetails.leadid\r\n\t\tleft join vtiger_leadscf on vtiger_leadscf.leadid = vtiger_leaddetails.leadid\r\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\r\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\r\n\t\twhere vtiger_crmentity.deleted = 0 AND vtiger_leaddetails.converted = 0 {$where} {$sec_parameter} order by vtiger_leaddetails.leadid ASC";
    } else {
        if ($module == "Accounts") {
            $sel_qry = "SELECT vtiger_account.accountid FROM vtiger_account\r\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_account.accountid\r\n\t\tINNER JOIN vtiger_accountbillads ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid\r\n\t\tINNER JOIN vtiger_accountshipads ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid\r\n\t\tLEFT JOIN vtiger_accountscf ON vtiger_account.accountid = vtiger_accountscf.accountid\r\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\r\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\r\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by vtiger_account.accountid ASC";
        } else {
            if ($module == "Contacts") {
                $sel_qry = "SELECT vtiger_contactdetails.contactid FROM vtiger_contactdetails\r\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid\r\n\t\tINNER JOIN vtiger_contactaddress ON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid\r\n\t\tINNER JOIN vtiger_contactsubdetails ON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\r\n\t\tLEFT JOIN vtiger_contactscf ON vtiger_contactscf.contactid = vtiger_contactdetails.contactid\r\n\t\tLEFT JOIN vtiger_customerdetails ON vtiger_customerdetails.customerid=vtiger_contactdetails.contactid\r\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\r\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\r\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by vtiger_contactdetails.contactid ASC";
            } else {
                if ($module == "Products") {
                    $sel_qry = "SELECT vtiger_products.productid FROM vtiger_products\r\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_products.productid\t\t\r\n\t\tLEFT JOIN vtiger_productcf ON vtiger_productcf.productid = vtiger_products.productid\r\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} order by vtiger_products.productid ASC";
                } else {
                    if ($module == "Vendors") {
                        $sel_qry = "SELECT vtiger_vendor.vendorid FROM vtiger_vendor\r\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_vendor.vendorid\r\n\t\tLEFT JOIN vtiger_vendorcf ON vtiger_vendorcf.vendorid = vtiger_vendor.vendorid\r\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} order by vtiger_vendor.vendorid ASC";
                    } else {
                        $sel_qry = "SELECT {$focus->table_name}.{$focus->table_index} FROM {$focus->table_name}\r\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = {$focus->table_name}.{$focus->table_index}";
                        // Consider custom table join as well.
                        if (isset($focus->customFieldTable)) {
                            $sel_qry .= " INNER JOIN " . $focus->customFieldTable[0] . " ON " . $focus->customFieldTable[0] . '.' . $focus->customFieldTable[1] . " = {$focus->table_name}.{$focus->table_index}";
                        }
                        $sel_qry .= " LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\r\n\t\tLEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id\r\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by {$focus->table_name}.{$focus->table_index} ASC";
                    }
                }
            }
        }
    }
    $result = $adb->query($sel_qry);
    $no_rows = $adb->num_rows($result);
    // now do any special processing for ex., map account with contact and potential
    $focus->process_special_fields();
    $process_fields = 'true';
    $moduleObj = new $module();
    if ($no_rows > 0) {
        for ($i = 0; $i < $no_rows; $i++) {
            $id_field = $moduleObj->table_index;
            $id_value = $adb->query_result($result, $i, $id_field);
            if ($i == 0) {
                $moduleObj->mode = "edit";
                $moduleObj->id = $id_value;
                if ($autoDupType == "merge") {
                    $moduleObj->retrieve_entity_info($id_value, $module);
                    foreach ($mappedFields as $index => $fieldName) {
                        if (!empty($focus->column_fields[$fieldName])) {
                            $moduleObj->column_fields[$fieldName] = $focus->column_fields[$fieldName];
                        }
                    }
                } else {
                    $moduleObj->column_fields = $focus->column_fields;
                }
                $moduleObj->saveentity($module);
            } else {
                DeleteEntity($module, $module, $moduleObj, $id_value, "");
            }
        }
        $dup_ow_count = $dup_ow_count + $no_rows;
        return true;
    } else {
        return false;
    }
}
Example #2
0
    }
    $val = Database::escape_string($val);
    return " {$col} {$ops[$oper]} '{$val}' ";
}
$where_condition = "";
//if there is no search request sent by jqgrid, $where should be empty
$operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
$export_format = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
$search_field = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
$search_oper = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
$search_string = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
$extra_fields = array();
$questionFields = array();
if ($_REQUEST['_search'] == 'true') {
    $where_condition = ' 1 = 1 ';
    $where_condition_in_form = get_where_clause($search_field, $search_oper, $search_string);
    if (!empty($where_condition_in_form)) {
        $where_condition .= ' AND ' . $where_condition_in_form;
    }
    $filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
    // for now
    if (!empty($filters)) {
        switch ($action) {
            case 'get_questions':
                $type = 'question';
                break;
            case 'get_sessions':
                $type = 'session';
                break;
        }
        // Extra field.
function overwrite_duplicate_records($module, $focus)
{
    global $adb;
    global $dup_ow_count;
    global $process_fields;
    $where_clause = "";
    $where = get_where_clause($module, $focus->column_fields);
    $sec_parameter = getSecParameterforMerge($module);
    if ($module == "Leads") {
        $sel_qry = "select vtiger_leaddetails.leadid from vtiger_leaddetails\n\t\tinner join vtiger_crmentity  on vtiger_crmentity.crmid = vtiger_leaddetails.leadid\n\t\tinner join vtiger_leadsubdetails on vtiger_leaddetails.leadid = vtiger_leadsubdetails.leadsubscriptionid\n\t\tinner join vtiger_leadaddress on vtiger_leadaddress.leadaddressid = vtiger_leaddetails.leadid\n\t\tleft join vtiger_leadscf on vtiger_leadscf.leadid = vtiger_leaddetails.leadid\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\n\t\twhere vtiger_crmentity.deleted = 0 AND vtiger_leaddetails.converted = 0 {$where} {$sec_parameter} order by vtiger_leaddetails.leadid ASC";
    } else {
        if ($module == "Accounts") {
            $sel_qry = "SELECT vtiger_account.accountid FROM vtiger_account\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_account.accountid\n\t\tINNER JOIN vtiger_accountbillads ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid\n\t\tINNER JOIN vtiger_accountshipads ON vtiger_account.accountid = vtiger_accountshipads.accountaddressid\n\t\tLEFT JOIN vtiger_accountscf ON vtiger_account.accountid = vtiger_accountscf.accountid\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by vtiger_account.accountid ASC";
        } else {
            if ($module == "Contacts") {
                $sel_qry = "SELECT vtiger_contactdetails.contactid FROM vtiger_contactdetails\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid\n\t\tINNER JOIN vtiger_contactaddress ON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid\n\t\tINNER JOIN vtiger_contactsubdetails ON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\n\t\tLEFT JOIN vtiger_contactscf ON vtiger_contactscf.contactid = vtiger_contactdetails.contactid\n\t\tLEFT JOIN vtiger_customerdetails ON vtiger_customerdetails.customerid=vtiger_contactdetails.contactid\n\t\tLEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by vtiger_contactdetails.contactid ASC";
            } else {
                if ($module == "Products") {
                    $sel_qry = "SELECT vtiger_products.productid FROM vtiger_products\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_products.productid\t\t\n\t\tLEFT JOIN vtiger_productcf ON vtiger_productcf.productid = vtiger_products.productid\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} order by vtiger_products.productid ASC";
                } else {
                    if ($module == "Vendors") {
                        $sel_qry = "SELECT vtiger_vendor.vendorid FROM vtiger_vendor\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_vendor.vendorid\n\t\tLEFT JOIN vtiger_vendorcf ON vtiger_vendorcf.vendorid = vtiger_vendor.vendorid\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} order by vtiger_vendor.vendorid ASC";
                    } else {
                        $sel_qry = "SELECT {$focus->table_name}.{$focus->table_index} FROM {$focus->table_name}\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = {$focus->table_name}.{$focus->table_index}";
                        // Consider custom table join as well.
                        if (isset($focus->customFieldTable)) {
                            $sel_qry .= " INNER JOIN " . $focus->customFieldTable[0] . " ON " . $focus->customFieldTable[0] . '.' . $focus->customFieldTable[1] . " = {$focus->table_name}.{$focus->table_index}";
                        }
                        $sel_qry .= " LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id\n\t\tWHERE vtiger_crmentity.deleted = 0 {$where} {$sec_parameter} order by {$focus->table_name}.{$focus->table_index} ASC";
                    }
                }
            }
        }
    }
    $result = $adb->query($sel_qry);
    $no_rows = $adb->num_rows($result);
    // now do any special processing for ex., map account with contact and potential
    $focus->process_special_fields();
    $process_fields = 'true';
    $moduleObj = new $module();
    if ($no_rows > 0) {
        for ($i = 0; $i < $no_rows; $i++) {
            $id_field = $moduleObj->table_index;
            $id_value = $adb->query_result($result, $i, $id_field);
            if ($i == 0) {
                $moduleObj->mode = "edit";
                $moduleObj->id = $id_value;
                $moduleObj->column_fields = $focus->column_fields;
                $moduleObj->save($module);
            } else {
                DeleteEntity($module, $module, $moduleObj, $id_value, "");
            }
        }
        $dup_ow_count = $dup_ow_count + $no_rows;
        return true;
    } else {
        return false;
    }
}