Example #1
0
 public function deleteRelation($sourceRecordId, $relatedRecordId)
 {
     if ($this->relatedModule->getName() == 'OSSMailView') {
         $db = PearDatabase::getInstance();
         if ($db->delete('vtiger_ossmailview_relation', 'crmid = ? AND ossmailviewid = ?', [$sourceRecordId, $relatedRecordId]) > 0) {
             return true;
         } else {
             return false;
         }
     } else {
         $sourceModule = $this->getParentModuleModel();
         $sourceModuleName = $sourceModule->get('name');
         $destinationModuleName = $this->getRelationModuleModel()->get('name');
         $destinationModuleFocus = CRMEntity::getInstance($destinationModuleName);
         DeleteEntity($destinationModuleName, $sourceModuleName, $destinationModuleFocus, $relatedRecordId, $sourceRecordId);
         return true;
     }
 }
Example #2
0
<?php

require_once 'modules/Memdays/Memdays.php';
require_once 'include/logging.php';
$log = LoggerManager::getLogger('memday_delete');
$focus = new Memdays();
if (!isset($_REQUEST['record'])) {
    die("A record number must be specified to delete the note.");
}
DeleteEntity($_REQUEST['module'], $_REQUEST['return_module'], $focus, $_REQUEST['record'], $_REQUEST['return_id']);
if (isset($_REQUEST['parenttab']) && $_REQUEST['parenttab'] != "") {
    $parenttab = $_REQUEST['parenttab'];
}
redirect("index.php?module=" . $_REQUEST['return_module'] . "&action=" . $_REQUEST['return_action'] . "&record=" . $_REQUEST['return_id'] . "&parenttab={$parenttab}" . "&relmodule=" . $_REQUEST['module']);
Example #3
0
echo "Load time: {$time_elapsed_us}\n";
$num2create = 100;
$_REQUEST['assigntype'] == 'U';
$recs2del = array();
$start = microtime(true);
for ($i = 0; $i < $num2create; $i++) {
    $focus = new Contacts();
    $focus->column_fields['firstname'] = 'firstname' . $i;
    $focus->column_fields['lastname'] = 'lastname' . $i;
    $focus->email_opt_out = 'off';
    $focus->do_not_call = 'off';
    $focus->column_fields['assigned_user_id'] = $current_user->id;
    $focus->save("Contacts");
    $recs2del[] = $focus->id;
    if ($i % 10 == 0) {
        echo $i . "\n";
        foreach ($recs2del as $c) {
            $f2 = new Contacts();
            $f2->retrieve_entity_info($c, 'Contacts');
            DeleteEntity('Contacts', 'Contacts', $f2, $c, $c);
        }
        $recs2del = array();
    }
}
foreach ($recs2del as $c) {
    $f2 = new Contacts();
    $f2->retrieve_entity_info($c, 'Contacts');
    DeleteEntity('Contacts', 'Contacts', $f2, $c, $c);
}
$time_elapsed_us = microtime(true) - $start;
echo "Operation time: {$time_elapsed_us}\n";
Example #4
0
require_once 'include/utils/utils.php';
global $mod_strings, $app_strings, $current_language, $theme;
$image_path = "themes/{$theme}/images/";
require_once 'modules/Vtiger/layout_utils.php';
$req_module = vtlib_purify($_REQUEST['module']);
$focus = CRMEntity::getInstance($req_module);
$return_module = vtlib_purify($_REQUEST['module']);
$delete_idstring = vtlib_purify($_REQUEST['idlist']);
$smarty = new vtigerCRM_Smarty();
$ids_list = array();
$errormsg = '';
if (isset($_REQUEST['del_rec'])) {
    $delete_id_array = explode(",", $delete_idstring, -1);
    foreach ($delete_id_array as $id) {
        if (isPermitted($req_module, 'Delete', $id) == 'yes') {
            DeleteEntity($req_module, $return_module, $focus, $id, "");
        } else {
            $ids_list[] = $id;
        }
    }
    if (count($ids_list) > 0) {
        $ret = getEntityName($req_module, $ids_list);
        if (count($ret) > 0) {
            $errormsg = implode(',', $ret);
        }
        echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
        echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>\n\t\t\t<table border='0' cellpadding='5' cellspacing='0' width='98%'>\n\t\t\t<tbody><tr>\n\t\t\t<td rowspan='2' width='11%'><img src='themes/{$theme}/images/denied.gif'></td>\n\t\t\t<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'>\n\t\t\t\t<span class='genHeaderSmall'>" . $app_strings['LBL_DUP_PERMISSION'] . " {$req_module} {$errormsg}</span></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t<td class='small' align='right' nowrap='nowrap'>\n\t\t\t<a href='javascript:window.location.reload();'>" . $app_strings['LBL_GO_BACK'] . "</a><br>\n\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</tbody></table>\n\t\t\t</div>\n\t\t\t</td></tr></table>";
        exit;
    }
}
include 'include/saveMergeCriteria.php';
Example #5
0
/*********************************************************************************
 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is:  SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * $Header$
 * Description:  Deletes an Account record and then redirects the browser to the 
 * defined return URL.
 ********************************************************************************/
global $currentModule;
$focus = CRMEntity::getInstance($currentModule);
global $mod_strings;
require_once 'include/logging.php';
$log = LoggerManager::getLogger('product_delete');
//Added to fix 4600
$url = getBasic_Advance_SearchURL();
if (!isset($_REQUEST['record'])) {
    die($mod_strings['ERR_DELETE_RECORD']);
}
DeleteEntity(vtlib_purify($_REQUEST['module']), vtlib_purify($_REQUEST['return_module']), $focus, vtlib_purify($_REQUEST['record']), vtlib_purify($_REQUEST['return_id']));
header("Location: index.php?module=" . vtlib_purify($_REQUEST['return_module']) . "&action=" . vtlib_purify($_REQUEST['return_action']) . "&record=" . vtlib_purify($_REQUEST['return_id']) . "&relmodule=" . vtlib_purify($_REQUEST['module']) . $url);
        setObjectValuesFromRequest($focus);
        $focus->save($module);
        $rec_values = $focus->column_fields;
        // Remove the id of primary record from the list of records to be deleted.
        $del_value = explode(",", $recordids, -1);
        $offset = array_search($merge_id, $del_value);
        unset($del_value[$offset]);
        // Transfer the related lists of the records to be deleted, to the primary record's related list
        if (method_exists($focus, 'transferRelatedRecords')) {
            $focus->transferRelatedRecords($module, $del_value, $merge_id);
        } else {
            transferRelatedRecords($module, $del_value, $merge_id);
        }
        // Delete the records by id specified in the list
        foreach ($del_value as $value) {
            DeleteEntity(vtlib_purify($_REQUEST['module']), vtlib_purify($_REQUEST['return_module']), $focus, $value, "");
        }
    }
    ?>
	<script>
		window.self.close();window.opener.location.href=window.opener.location.href;
	</script>
<?php 
} elseif ($mode == 'mergefields') {
    $idstring = vtlib_purify($_REQUEST['passurl']);
    $parent_tab = getParentTab();
    $exploded_id = explode(",", $idstring, -1);
    $record_count = count($exploded_id);
    $smarty = new vtigerCRM_Smarty();
    $smarty->assign("EDIT_DUPLICATE", "");
    if ($record_count == 2) {
Example #7
0
 public function deleteRelation($sourceRecordId, $relatedRecordId)
 {
     $sourceModule = $this->getParentModuleModel();
     $sourceModuleName = $sourceModule->get('name');
     $destinationModuleName = $this->getRelationModuleModel()->get('name');
     $destinationModuleFocus = CRMEntity::getInstance($destinationModuleName);
     DeleteEntity($destinationModuleName, $sourceModuleName, $destinationModuleFocus, $relatedRecordId, $sourceRecordId);
     return true;
 }
Example #8
0
$viewid = vtlib_purify($_REQUEST['viewname']);
$returnmodule = vtlib_purify($_REQUEST['return_module']);
$return_action = vtlib_purify($_REQUEST['return_action']);
$excludedRecords = vtlib_purify($_REQUEST['excludedRecords']);
$rstart = '';
//Added to fix 4600
$url = getBasic_Advance_SearchURL();
//split the string and store in an array
$storearray = getSelectedRecords($_REQUEST, $returnmodule, $idlist, $excludedRecords);
$storearray = array_filter($storearray);
$ids_list = array();
$errormsg = '';
foreach ($storearray as $id) {
    if (isPermitted($returnmodule, 'Delete', $id) == 'yes') {
        $focus = CRMEntity::getInstance($returnmodule);
        DeleteEntity($returnmodule, $returnmodule, $focus, $id, '');
    } else {
        $ids_list[] = $id;
    }
}
if (count($ids_list) > 0) {
    $ret = getEntityName($returnmodule, $ids_list);
    if (count($ret) > 0) {
        $errormsg = implode(',', $ret);
    }
}
if (isset($_REQUEST['smodule']) && $_REQUEST['smodule'] != '') {
    $smod = "&smodule=" . vtlib_purify($_REQUEST['smodule']);
}
if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') {
    $rstart = "&start=" . vtlib_purify($_REQUEST['start']);
 public function delete($id)
 {
     global $adb;
     $error = false;
     $adb->startTransaction();
     DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id, $returnid);
     $error = $adb->hasFailedTransaction();
     $adb->completeTransaction();
     return !$error;
 }
Example #10
0
        // First, save the primary record
        $focus->mode = "edit";
        setObjectValuesFromRequest($focus);
        $focus->save($module);
        $rec_values = $focus->column_fields;
        // Remove the id of primary record from the list of records to be deleted.
        $del_value = explode(",", $recordids, -1);
        $offset = array_search($merge_id, $del_value);
        unset($del_value[$offset]);
        // Transfer the related lists of the records to be deleted, to the primary record's related list
        if (method_exists($focus, 'transferRelatedRecords')) {
            $focus->transferRelatedRecords($module, $del_value, $merge_id);
        }
        // Delete the records by id specified in the list
        foreach ($del_value as $value) {
            DeleteEntity($_REQUEST['module'], $_REQUEST['return_module'], $focus, $value, "");
        }
    }
    ?>
	<script>
		window.self.close();window.opener.location.href=window.opener.location.href;
	</script>
<?php 
} elseif ($mode == 'mergefields') {
    $idstring = vtlib_purify($_REQUEST['passurl']);
    $parent_tab = getParentTab();
    $exploded_id = explode(",", $idstring, -1);
    $record_count = count($exploded_id);
    $smarty = new vtigerCRM_Smarty();
    $smarty->assign("EDIT_DUPLICATE", "");
    if ($record_count == 2) {
Example #11
0
<?php

/*+**********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is:  vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 ************************************************************************************/
global $currentModule;
$focus = CRMEntity::getInstance($currentModule);
$focus->id = $_REQUEST['record'];
$focus->retrieve_entity_info($_REQUEST['record'], $currentModule);
if (!$focus->permissiontoedit()) {
    $log->debug("You don't have permission to deleted");
    echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
    echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>\n\n        <table border='0' cellpadding='5' cellspacing='0' width='98%'>\n        <tbody><tr>\n        <td rowspan='2' width='11%'><img src='" . vtiger_imageurl('denied.gif', $theme) . "' ></td>\n        <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span clas\n        s='genHeaderSmall'>{$app_strings['LBL_PERMISSION']}</span></td>\n        </tr>\n        <tr>\n        <td class='small' align='right' nowrap='nowrap'>\n        <a href='javascript:window.history.back();'>{$app_strings['LBL_GO_BACK']}</a><br>\n        </td>\n        </tr>\n        </tbody></table>\n        </div>";
    echo "</td></tr></table>";
    exit;
}
$record = vtlib_purify($_REQUEST['record']);
$module = vtlib_purify($_REQUEST['module']);
$return_module = vtlib_purify($_REQUEST['return_module']);
$return_action = vtlib_purify($_REQUEST['return_action']);
$return_id = vtlib_purify($_REQUEST['return_id']);
$parenttab = getParentTab();
//Added to fix 4600
$url = getBasic_Advance_SearchURL();
DeleteEntity($currentModule, $return_module, $focus, $record, $return_id);
header("Location: index.php?module={$return_module}&action={$return_action}&record={$return_id}&parenttab={$parenttab}&relmodule={$module}" . $url);
Example #12
0
<?php

/*********************************************************************************
 * The content of this file is subject to the Calendar4You Free license.
 * ("License"); You may not use this file except in compliance with the License
 * The Initial Developer of the Original Code is IT-Solutions4You s.r.o.
 * Portions created by IT-Solutions4You s.r.o. are Copyright(C) IT-Solutions4You s.r.o.
 * All Rights Reserved.
 ********************************************************************************/
require_once "modules/Calendar4You/Calendar4You.php";
require_once "modules/Calendar4You/CalendarUtils.php";
global $currentModule, $current_user;
$Calendar4You = new Calendar4You();
$Calendar4You->GetDefPermission($current_user->id);
$delete_permissions = $Calendar4You->CheckPermissions("DELETE", $_REQUEST['record']);
if (!$delete_permissions) {
    NOPermissionDiv();
}
$currentModule = 'Calendar';
$focus = CRMEntity::getInstance($currentModule);
require_once 'include/logging.php';
$log = LoggerManager::getLogger('task_delete');
$url = getBasic_Advance_SearchURL();
if (!isset($_REQUEST['record'])) {
    die($mod_strings['ERR_DELETE_RECORD']);
}
DeleteEntity('Calendar', $_REQUEST['return_module'], $focus, $_REQUEST['record'], $_REQUEST['return_id']);
$parenttab = getParentTab();
header("Location: index.php?module=" . vtlib_purify($_REQUEST['return_module']) . "&action=" . vtlib_purify($_REQUEST['return_action']) . "&record=" . vtlib_purify($_REQUEST['return_id']) . "&parenttab=" . $parenttab . "&relmodule=" . vtlib_purify($_REQUEST['module']) . $url);
Example #13
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;
    }
}
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;
    }
}