public function getRelatedSummary($query) { $db = PearDatabase::getInstance(); $relationQuery = preg_replace("/[ \t\n\r]+/", " ", $query); $position = stripos($relationQuery, ' from '); if ($position) { $split = explode(' FROM ', $relationQuery); $mainQuery = ''; for ($i = 1; $i < count($split); $i++) { $mainQuery = $mainQuery . ' FROM ' . $split[$i]; } } // Calculate total working time $result = $db->query('SELECT SUM(vtiger_osstimecontrol.sum_time) AS sumtime' . $mainQuery); $totalTime = $db->getSingleValue($result); // Calculate total working time divided into users $result = $db->query('SELECT SUM(vtiger_osstimecontrol.sum_time) AS sumtime, vtiger_crmentity.smownerid' . $mainQuery . ' GROUP BY vtiger_crmentity.smownerid'); $userTime = []; $count = 1; while ($row = $db->fetch_array($result)) { $smownerid = Vtiger_Functions::getOwnerRecordLabel($row['smownerid']); $userTime[] = ['name' => [$count, $smownerid], 'initial' => [$count, Vtiger_Functions::getInitials($smownerid)], 'data' => [$count, $row['sumtime']]]; $count++; } return ['totalTime' => $totalTime, 'userTime' => $userTime]; }
function getProductsServices(Vtiger_Request $request) { $fromModule = $request->get('fromModule'); $record = $request->get('record'); $mod = $request->get('mod'); if (!in_array($mod, ['Products', 'Services'])) { die('Not supported Module'); } $db = PearDatabase::getInstance(); $limit = 10; $params = []; if (!empty($request->get('limit'))) { $limit = $request->get('limit'); } $currentUser = Users_Record_Model::getCurrentUserModel(); $instance = CRMEntity::getInstance($mod); $securityParameter = $instance->getUserAccessConditionsQuerySR($mod, $currentUser); if ($mod == 'Products') { $sql = 'SELECT vtiger_products.productid, vtiger_products.pscategory, vtiger_products.productname, vtiger_crmentity.smownerid, vtiger_crmentity.shownerid ' . 'FROM vtiger_products ' . 'INNER JOIN vtiger_crmentity ON vtiger_products.productid = vtiger_crmentity.crmid ' . 'INNER JOIN vtiger_seproductsrel ON vtiger_products.productid = vtiger_seproductsrel.productid ' . 'LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id ' . 'LEFT JOIN vtiger_groups ON vtiger_crmentity.smownerid = vtiger_groups.groupid ' . 'WHERE vtiger_crmentity.deleted=0 AND vtiger_products.productid > 0 AND vtiger_seproductsrel.setype = ?'; $params[] = $fromModule; } elseif ($mod == 'Services') { $sql = 'SELECT vtiger_service.serviceid, vtiger_service.pscategory, vtiger_service.servicename, vtiger_crmentity.smownerid, vtiger_crmentity.shownerid ' . 'FROM vtiger_service ' . 'INNER JOIN vtiger_crmentity ON vtiger_service.serviceid = vtiger_crmentity.crmid ' . 'INNER JOIN vtiger_crmentityrel ON (vtiger_crmentityrel.relcrmid = vtiger_crmentity.crmid OR vtiger_crmentityrel.crmid = vtiger_crmentity.crmid)' . 'LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id ' . 'LEFT JOIN vtiger_groups ON vtiger_crmentity.smownerid = vtiger_groups.groupid ' . 'WHERE vtiger_crmentity.deleted=0 AND vtiger_service.serviceid > 0 AND (vtiger_crmentityrel.crmid IN (?) OR vtiger_crmentityrel.relcrmid IN (?))'; $params[] = $record; $params[] = $record; } if ($securityParameter != '') { $sql .= $securityParameter; } $sql .= ' LIMIT ' . $limit; $result = $db->pquery($sql, $params); $returnData = array(); for ($i = 0; $i < $db->num_rows($result); $i++) { $row = $db->query_result_rowdata($result, $i); $shownerid = []; $row['smownerid'] = Vtiger_Functions::getOwnerRecordLabel($row['smownerid']); if ($row['shownerid'] != '') { foreach (explode(",", $row['shownerid']) as $value) { $shownerid[] = Vtiger_Functions::getOwnerRecordLabel($value); } } $row['shownerid'] = $shownerid; $returnData[] = $row; } $showMore = (int) $limit == count($returnData) ? 1 : 0; return ['data' => $returnData, 'showMore' => $showMore]; }
function process($data) { $adb = PearDatabase::getInstance(); $html = ''; if ($data['record'] != '') { $vtEntityDelta = new VTEntityDelta(); $delta = $vtEntityDelta->getEntityDelta($data['module'], $data['record']); if (count($delta) == 0) { return ''; } $tabid = getTabid($data['module']); $html = '<ul>'; foreach ($delta as $fieldName => $values) { if ($fieldName != 'modifiedtime' && in_array($fieldName, array('record_id', 'record_module')) == false && strstr($fieldName, 'label') === false) { $result = $adb->pquery("SELECT uitype,fieldlabel FROM vtiger_field WHERE fieldname = ? AND tabid = ?", array($fieldName, $tabid), true); $fieldlabel = $adb->query_result_raw($result, 0, 'fieldlabel'); $uitype = $adb->query_result_raw($result, 0, 'uitype'); $oldValue = $values['oldValue']; if ($oldValue == '') { $oldValue = 'LBL_NULL_VALUE'; } $currentValue = $values['currentValue']; if ($currentValue == '') { $currentValue = 'LBL_NULL_VALUE'; } if ($uitype == 10 && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') { $oldValue = Vtiger_Functions::getCRMRecordLabel($oldValue); $currentValue = Vtiger_Functions::getCRMRecordLabel($currentValue); } elseif (in_array($uitype, array('53', '52', '77')) && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') { $oldValue = Vtiger_Functions::getOwnerRecordLabel($oldValue); $currentValue = Vtiger_Functions::getOwnerRecordLabel($currentValue); } elseif ($uitype == 56 && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') { $oldValue = $oldValue == 1 ? vtranslate('LBL_YES', $data['module']) : vtranslate('LBL_NO', $data['module']); $currentValue = $currentValue == 1 ? vtranslate('LBL_YES', $data['module']) : vtranslate('LBL_NO', $data['module']); } else { $oldValue = vtranslate($oldValue, $data['module']); $currentValue = vtranslate($currentValue, $data['module']); } $html .= '<li>' . vtranslate('LBL_CHANGED', $data['module']) . ' <strong>' . vtranslate($fieldlabel, $data['module']) . '</strong> ' . vtranslate('LBL_FROM') . ' <i>' . $oldValue . '</i> ' . vtranslate('LBL_TO') . ' <i>' . $currentValue . '</i></li>'; } } $html .= '</ul>'; return $html; } }
function replaceRelVar($fieldId, $tpl, $recordId, $module, $start, $positionLength, $allLength) { $db = PearDatabase::getInstance(); vimport("~~modules/{$module}/{$module}.php"); $IDs = explode('||', $fieldId); $getFieldInfoSql = "SELECT * FROM vtiger_field WHERE fieldid = '" . $IDs[0] . "'"; $getFieldInfoResult = $db->query($getFieldInfoSql, true); $fieldTab = $db->query_result_raw($getFieldInfoResult, 0, 'tablename'); $fieldname = $db->query_result_raw($getFieldInfoResult, 0, 'fieldname'); $fieldColumnName = $db->query_result_raw($getFieldInfoResult, 0, 'columnname'); $tabid = $db->query_result_raw($getFieldInfoResult, 0, 'tabid'); $uitype = $db->query_result_raw($getFieldInfoResult, 0, 'uitype'); $moduleNameResult = $db->pquery("SELECT name FROM vtiger_tab WHERE tabid = ?", array($tabid), true); $fieldModule = $db->query_result_raw($moduleNameResult, 0, 'name'); $moduleInstance = Vtiger_Record_Model::getInstanceById($recordId, $module); $getFieldInfoSql2 = "SELECT * FROM vtiger_field WHERE fieldid = ?"; $getFieldInfoResult2 = $db->pquery($getFieldInfoSql2, array($IDs[1]), true); $rel_id = $moduleInstance->get($db->query_result_raw($getFieldInfoResult2, 0, 'fieldname')); $modObj = CRMEntity::getInstance($fieldModule); $primaryKey = $modObj->tab_name_index[$fieldTab]; $getValueSql = "SELECT {$fieldColumnName} FROM {$fieldTab} WHERE {$primaryKey} = ?;"; $getValueResult = $db->pquery($getValueSql, array($rel_id), true); $finalValue = $db->query_result_raw($getValueResult, 0, $fieldColumnName); if ($uitype == 10 || $uitype == 51 || $uitype == 73 || $uitype == 66 || $uitype == 57) { $finalValue = Vtiger_Functions::getCRMRecordLabel($finalValue); } elseif ($uitype == 15 || $uitype == 16) { $finalValue = vtranslate($finalValue, $module); } elseif ($uitype == 53 || $uitype == 52) { $finalValue = Vtiger_Functions::getOwnerRecordLabel($finalValue); } $tpl = substr_replace($tpl, $finalValue, $start, $allLength + $positionLength); return $tpl; }
function get_details($id, $module, $customerid, $sessionid) { $adb = PearDatabase::getInstance(); $log = vglobal('log'); require_once 'include/utils/utils.php'; require_once 'include/utils/UserInfoUtil.php'; $log->debug("Entering customer portal function get_details .."); $user = new Users(); $userid = getPortalUserid(); $current_user = $user->retrieveCurrentUserInfoFromFile($userid); $isPermitted = check_permission($customerid, $module, $id); if ($isPermitted == false) { return array("#NOT AUTHORIZED#"); } if (!validateSession($customerid, $sessionid)) { return null; } $params = array($id); if ($module == 'Quotes') { $query = "SELECT\n\t\t\tvtiger_quotes.*,vtiger_crmentity.*,vtiger_quotesaddress.*,\n\t\t\tvtiger_quotescf.* FROM vtiger_quotes\n\t\t\tINNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_quotes.quoteid\n\t\t\tINNER JOIN vtiger_quotesaddress\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotesaddress.quoteaddressid\n\t\t\tLEFT JOIN vtiger_quotescf\n\t\t\t\tON vtiger_quotes.quoteid = vtiger_quotescf.quoteid\n\t\t\tWHERE vtiger_quotes.quoteid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'SalesOrder') { $query = "SELECT vtiger_salesorder.*,vtiger_crmentity.*,vtiger_salesorderaddress.*,\n\t\t\tvtiger_salesordercf.* \n\t\t\tFROM vtiger_salesorder\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_salesorder.salesorderid\n\t\t\tINNER JOIN vtiger_salesorderaddress ON vtiger_salesorder.salesorderid = vtiger_salesorderaddress.salesorderaddressid\n\t\t\tLEFT JOIN vtiger_salesordercf ON vtiger_salesorder.salesorderid = vtiger_salesordercf.salesorderid\n\t\t\tWHERE vtiger_salesorder.salesorderid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'Documents') { $result = $adb->pquery('SELECT fieldparams FROM vtiger_field WHERE columnname = ? AND tablename = ?', ['folderid', 'vtiger_notes']); $tree = $adb->query_result($result, 0, 'fieldparams'); $params[] = $tree; $query = "SELECT\n\t\t\tvtiger_notes.*,vtiger_crmentity.*, vtiger_trees_templates_data.label as foldername,vtiger_notescf.*\n\t\t\tFROM vtiger_notes\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_notes.notesid\n\t\t\tLEFT JOIN vtiger_trees_templates_data ON vtiger_trees_templates_data.tree = vtiger_notes.folderid\n\t\t\tLEFT JOIN vtiger_notescf ON vtiger_notescf.notesid = vtiger_notes.notesid\n\t\t\tWHERE vtiger_notes.notesid=(" . generateQuestionMarks($id) . ") AND vtiger_trees_templates_data.templateid = ? AND vtiger_crmentity.deleted=0"; } else { if ($module == 'HelpDesk') { $query = "SELECT\n\t\t\tvtiger_troubletickets.*,vtiger_crmentity.smownerid,vtiger_crmentity.createdtime,vtiger_crmentity.modifiedtime,vtiger_crmentity.attention,\n\t\t\tvtiger_ticketcf.*,vtiger_crmentity.description FROM vtiger_troubletickets\n\t\t\tINNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_troubletickets.ticketid\n\t\t\tINNER JOIN vtiger_ticketcf\n\t\t\t\tON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid\n\t\t\tWHERE (vtiger_troubletickets.ticketid=(" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0)"; } else { if ($module == 'Services') { $result = $adb->pquery('SELECT fieldparams FROM vtiger_field WHERE columnname = ? AND tablename = ?', ['pscategory', 'vtiger_service']); $tree = $adb->query_result($result, 0, 'fieldparams'); $query = "SELECT vtiger_service.*,vtiger_crmentity.*,vtiger_servicecf.*, vtiger_trees_templates_data.label as pscategory\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_service.serviceid AND vtiger_crmentity.deleted = 0\n\t\t\tLEFT JOIN vtiger_servicecf ON vtiger_service.serviceid = vtiger_servicecf.serviceid\n\t\t\tLEFT JOIN vtiger_trees_templates_data ON vtiger_trees_templates_data.tree = vtiger_service.pscategory\n\t\t\tWHERE vtiger_service.serviceid= (" . generateQuestionMarks($id) . ")"; } else { if ($module == 'Contacts') { $query = "SELECT vtiger_contactdetails.*,vtiger_contactaddress.*,vtiger_contactsubdetails.*,vtiger_contactscf.*" . " ,vtiger_crmentity.*,vtiger_customerdetails.*\n\t\t \tFROM vtiger_contactdetails\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactaddress\n\t\t\t\tON vtiger_contactaddress.contactaddressid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactsubdetails\n\t\t\t\tON vtiger_contactsubdetails.contactsubscriptionid = vtiger_contactdetails.contactid\n\t\t\tINNER JOIN vtiger_contactscf\n\t\t\t\tON vtiger_contactscf.contactid = vtiger_contactdetails.contactid\n\t\t\tLEFT JOIN vtiger_customerdetails\n\t\t\t\tON vtiger_customerdetails.customerid = vtiger_contactdetails.contactid\n\t\t\tWHERE vtiger_contactdetails.contactid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'Accounts') { $query = "SELECT vtiger_account.*,vtiger_accountaddress.*,vtiger_accountscf.*,\n\t\t\tvtiger_crmentity.* FROM vtiger_account\n\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\tON vtiger_crmentity.crmid = vtiger_account.accountid\n\t\t\tINNER JOIN vtiger_accountaddress\n\t\t\t\tON vtiger_account.accountid = vtiger_accountaddress.accountaddressid\n\t\t\tINNER JOIN vtiger_accountscf\n\t\t\t\tON vtiger_account.accountid = vtiger_accountscf.accountid" . " WHERE vtiger_account.accountid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'Products') { $query = "SELECT vtiger_products.*,vtiger_productcf.*,vtiger_crmentity.* " . "FROM vtiger_products " . "INNER JOIN vtiger_crmentity " . "ON vtiger_crmentity.crmid = vtiger_products.productid " . "LEFT JOIN vtiger_productcf " . "ON vtiger_productcf.productid = vtiger_products.productid " . "LEFT JOIN vtiger_vendor\n\t\t\tON vtiger_vendor.vendorid = vtiger_products.vendor_id " . "WHERE vtiger_products.productid = (" . generateQuestionMarks($id) . ") AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'Assets') { $query = "SELECT vtiger_assets.*, vtiger_assetscf.*, vtiger_crmentity.*\n\t\tFROM vtiger_assets\n\t\tINNER JOIN vtiger_crmentity\n\t\tON vtiger_assets.assetsid = vtiger_crmentity.crmid\n\t\tINNER JOIN vtiger_assetscf\n\t\tON vtiger_assetscf.assetsid = vtiger_assets.assetsid\n\t\tWHERE vtiger_crmentity.deleted = 0 AND vtiger_assets.assetsid = (" . generateQuestionMarks($id) . ")"; } else { if ($module == 'Project') { $query = "SELECT vtiger_project.*, vtiger_projectcf.*, vtiger_crmentity.*\n\t\t\t\t\tFROM vtiger_project\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_project.projectid\n\t\t\t\t\tLEFT JOIN vtiger_projectcf ON vtiger_projectcf.projectid = vtiger_project.projectid\n\t\t\t\t\tWHERE vtiger_project.projectid = ? AND vtiger_crmentity.deleted = 0"; } else { if ($module == 'ProjectMilestone') { $query = "SELECT vtiger_projectmilestone . * , vtiger_projectmilestonecf . * , vtiger_crmentity . * \n\t\t\t\t\tFROM vtiger_projectmilestone\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_projectmilestone.projectmilestoneid\n\t\t\t\t\tLEFT JOIN vtiger_projectmilestonecf ON vtiger_projectmilestonecf.projectmilestoneid = vtiger_projectmilestone.projectmilestoneid\n\t\t\t\t\tWHERE vtiger_projectmilestone.projectmilestoneid = ? AND vtiger_crmentity.deleted =0"; } else { if ($module == 'ProjectTask') { $query = "SELECT vtiger_projecttask.*, vtiger_projecttaskcf.*, vtiger_crmentity.*\n\t\t\t\t\tFROM vtiger_projecttask\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_projecttask.projecttaskid\n\t\t\t\t\tLEFT JOIN vtiger_projecttaskcf ON vtiger_projecttaskcf.projecttaskid = vtiger_projecttask.projecttaskid\n\t\t\t\t\tWHERE vtiger_projecttask.projecttaskid = ? AND vtiger_crmentity.deleted = 0"; } } } } } } } } } } } } $res = $adb->pquery($query, $params); $fieldquery = "SELECT fieldname,columnname,fieldlabel,blocklabel,uitype FROM vtiger_field\n\t\tINNER JOIN vtiger_blocks on vtiger_blocks.blockid=vtiger_field.block WHERE vtiger_field.tabid = ? AND displaytype in (1,2,4,10)\n\t\tORDER BY vtiger_field.block,vtiger_field.sequence"; $fieldres = $adb->pquery($fieldquery, array(getTabid($module))); $nooffields = $adb->num_rows($fieldres); // Dummy instance to make sure column fields are initialized for futher processing $focus = CRMEntity::getInstance($module); for ($i = 0; $i < $nooffields; $i++) { $columnname = $adb->query_result($fieldres, $i, 'columnname'); $fieldname = $adb->query_result($fieldres, $i, 'fieldname'); $fieldid = $adb->query_result($fieldres, $i, 'fieldid'); $blockid = $adb->query_result($fieldres, $i, 'block'); $uitype = $adb->query_result($fieldres, $i, 'uitype'); $blocklabel = $adb->query_result($fieldres, $i, 'blocklabel'); $blockname = Vtiger_Language_Handler::getTranslatedString($blocklabel, $module, vglobal('default_language')); if ($blocklabel == 'LBL_COMMENTS' || $blocklabel == 'LBL_IMAGE_INFORMATION') { // the comments block of tickets is hardcoded in customer portal,get_ticket_comments is used for it continue; } if ($uitype == 83) { //for taxclass in products and services continue; } $fieldper = getFieldVisibilityPermission($module, $current_user->id, $fieldname); if ($fieldper == '1') { continue; } $fieldlabel = Vtiger_Language_Handler::getTranslatedString($adb->query_result($fieldres, $i, 'fieldlabel'), $module, vglobal('default_language')); $fieldvalue = $adb->query_result($res, 0, $columnname); $output[0][$module][$i]['fieldlabel'] = $fieldlabel; $output[0][$module][$i]['blockname'] = $blockname; if ($columnname == 'title' || $columnname == 'description' || $columnname == 'attention' || $columnname == 'solution') { $fieldvalue = decode_html($fieldvalue); } if ($uitype == 10 && $fieldvalue == 0) { $fieldvalue = ''; } if ($uitype == 71 || $uitype == 72) { $fieldvalue = number_format($fieldvalue, 5, '.', ''); } if ($uitype == 56) { if ($fieldvalue == 1) { $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_YES', $module, vglobal('default_language')); } else { $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_NO', $module, vglobal('default_language')); } } if ($columnname == 'parent_id' || $columnname == 'contactid' || $columnname == 'accountid' || $columnname == 'potentialid' || $fieldname == 'account_id' || $fieldname == 'contact_id' || $columnname == 'linktoaccountscontacts') { $crmid = $fieldvalue; $modulename = getSalesEntityType($crmid); if ($crmid != '' && $modulename != '') { $fieldvalues = getEntityName($modulename, array($crmid)); if ($modulename == 'Contacts') { $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } elseif ($modulename == 'Accounts') { $fieldvalue = '<a href="index.php?module=Accounts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } else { $fieldvalue = $fieldvalues[$crmid]; } } else { $fieldvalue = ''; } } if ($module == 'Quotes') { if ($fieldname == 'subject' && $fieldvalue != '') { $fieldid = $adb->query_result($res, 0, 'quoteid'); $fieldvalue = '<a href="index.php?downloadfile=true&module=Quotes&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>'; } if ($fieldname == 'total') { $sym = getCurrencySymbol($res, 0, 'currency_id'); $fieldvalue = $sym . $fieldvalue; } } if ($module == 'Services') { if ($fieldname == 'pscategory' && $fieldvalue != '') { $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, $module, vglobal('default_language')); } } if ($module == 'Documents') { $fieldid = $adb->query_result($res, 0, 'notesid'); $filename = $fieldvalue; $folderid = $adb->query_result($res, 0, 'folderid'); $filestatus = $adb->query_result($res, 0, 'filestatus'); $filetype = $adb->query_result($res, 0, 'filelocationtype'); if ($fieldname == 'filename') { if ($filestatus == 1) { if ($filetype == 'I') { $fieldvalue = '<a href="index.php?downloadfile=true&folderid=' . $folderid . '&filename=' . $filename . '&module=Documents&action=index&id=' . $fieldid . '" >' . $fieldvalue . '</a>'; } elseif ($filetype == 'E') { $fieldvalue = '<a target="_blank" href="' . $filename . '" onclick = "updateCount(' . $fieldid . ');">' . $filename . '</a>'; } } } if ($fieldname == 'folderid') { $fieldvalue = Vtiger_Language_Handler::getTranslatedString($adb->query_result($res, 0, 'foldername'), $module, vglobal('default_language')); } if ($fieldname == 'filesize') { if ($filetype == 'I') { $fieldvalue = $fieldvalue . ' B'; } elseif ($filetype == 'E') { $fieldvalue = '--'; } } if ($fieldname == 'filelocationtype') { if ($fieldvalue == 'I') { $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_INTERNAL', $module, vglobal('default_language')); } elseif ($fieldvalue == 'E') { $fieldvalue = Vtiger_Language_Handler::getTranslatedString('LBL_EXTERNAL', $module, vglobal('default_language')); } else { $fieldvalue = '---'; } } } if ($columnname == 'product_id') { $fieldvalues = getEntityName('Products', array($fieldvalue)); $fieldvalue = '<a href="index.php?module=Products&action=index&productid=' . $fieldvalue . '">' . $fieldvalues[$fieldvalue] . '</a>'; } if ($module == 'Products') { if ($fieldname == 'vendor_id') { $fieldvalue = get_vendor_name($fieldvalue); } } if ($module == 'Assets') { if ($fieldname == 'account') { $accountid = $adb->query_result($res, 0, 'account'); $accountres = $adb->pquery("select vtiger_account.accountname from vtiger_account where accountid=?", array($accountid)); $accountname = $adb->query_result($accountres, 0, 'accountname'); $fieldvalue = $accountname; } if ($fieldname == 'product') { $productid = $adb->query_result($res, 0, 'product'); $productres = $adb->pquery("select vtiger_products.productname from vtiger_products where productid=?", array($productid)); $productname = $adb->query_result($productres, 0, 'productname'); $fieldvalue = $productname; } if ($fieldname == 'invoiceid') { $invoiceid = $adb->query_result($res, 0, 'invoiceid'); $invoiceres = $adb->pquery("select vtiger_invoice.subject from vtiger_invoice where invoiceid=?", array($invoiceid)); $invoicename = $adb->query_result($invoiceres, 0, 'subject'); $fieldvalue = $invoicename; } } if (in_array($uitype, array('15', '16', '120'))) { $output[0][$module][$i]['orgfieldvalue'] = $fieldvalue; $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, $module, vglobal('default_language')); } if (in_array($uitype, array('10'))) { $fieldvalue = Vtiger_Functions::getCRMRecordLabel($fieldvalue); } if (in_array($uitype, array('53', '52', '77'))) { $fieldvalue = Vtiger_Functions::getOwnerRecordLabel($fieldvalue); } if ($fieldname == 'unit_price') { $sym = getCurrencySymbol($res, 0, 'currency_id'); $fieldvalue = round($fieldvalue, 2); $fieldvalue = $sym . $fieldvalue; } $output[0][$module][$i]['fieldvalue'] = $fieldvalue; } if ($module == 'HelpDesk') { $ticketid = $adb->query_result($res, 0, 'ticketid'); $sc_info = getRelatedServiceContracts($ticketid); if (!empty($sc_info)) { $modulename = 'ServiceContracts'; $blocklable = Vtiger_Language_Handler::getTranslatedString('LBL_SERVICE_CONTRACT_INFORMATION', $modulename, vglobal('default_language')); $j = $i; for ($k = 0; $k < count($sc_info); $k++) { foreach ($sc_info[$k] as $label => $value) { $output[0][$module][$j]['fieldlabel'] = Vtiger_Language_Handler::getTranslatedString($label, $modulename, vglobal('default_language')); $output[0][$module][$j]['fieldvalue'] = $value; $output[0][$module][$j]['blockname'] = $blocklable; $j++; } } } } $log->debug("Existing customer portal function get_details .."); return $output; }
/** Function to get owner name either user or group */ function getOwnerName($id) { return Vtiger_Functions::getOwnerRecordLabel($id); }
public function process($moduleName, $iD, $recordForm, $config) { $db = PearDatabase::getInstance(); $params = []; $hierarchyAll = []; $save = true; $where = ''; $hierarchyCheck = false; if ($iD != 0 && $iD != '' && !array_key_exists('vat_id', $recordForm)) { $recordModel = Vtiger_Record_Model::getInstanceById($iD, $moduleName); $vatId = $recordModel->get('vat_id'); } else { if (array_key_exists('vat_id', $recordForm)) { $vatId = $recordForm['vat_id']; } } if ($iD != 0 && $iD != '' && !array_key_exists('accountname', $recordForm)) { $recordModel = Vtiger_Record_Model::getInstanceById($iD, $moduleName); $accountName = $recordModel->get('accountname'); } else { if (array_key_exists('accountname', $recordForm)) { $accountName = $recordForm['accountname']; } } if ($vatId) { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $hierarchyField = Vtiger_Field_Model::getInstance('account_id', $moduleModel); if ($hierarchyField->isActiveField()) { if (array_key_exists('account_id', $recordForm)) { $hierarchyValue = $recordForm['account_id']; } elseif ($iD != 0 && $iD != '' && !array_key_exists('account_id', $recordForm)) { $recordModel = Vtiger_Record_Model::getInstanceById($iD, $moduleName); $hierarchyValue = $recordModel->get('account_id'); } if ($hierarchyValue) { $hierarchyAll = $this->getHierarchy($hierarchyValue, $moduleName, $iD); } elseif ($iD) { $hierarchyAll = $this->getHierarchy($iD, $moduleName, $iD); } } $params[] = $vatId; $where .= ' vat_id = ?'; } else { $params[] = $accountName; $where .= ' accountname = ?'; } if ($iD != 0 && $iD != '') { $params[] = $iD; $where .= ' AND accountid <> ?'; } if ($hierarchyAll && $vatId) { $hierarchyParams = array_merge($params, array_keys($hierarchyAll)); $hierarchyQuery = 'SELECT accountid,accountname FROM vtiger_account WHERE ' . $where . ' AND accountid IN (' . $db->generateQuestionMarks($hierarchyAll) . ')'; $result = $db->pquery($hierarchyQuery, $hierarchyParams); if ($db->getRowCount($result)) { $hierarchyCheck = true; } while ($row = $db->getRow($result)) { if ($row['accountname'] == $accountName) { $metaData = Vtiger_Functions::getCRMRecordMetadata($row['accountid']); $save = false; $fieldlabel .= '<a target="_blank" href="index.php?module=Accounts&view=Detail&record=' . $row['accountid'] . '">• ' . Vtiger_Functions::getCRMRecordLabel($row['accountid']) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($metaData['smownerid']) . '),<br/>'; } } } if (!$hierarchyCheck) { $sql = "SELECT accountid FROM vtiger_account WHERE {$where};"; $result = $db->pquery($sql, $params); while ($id = $db->getSingleValue($result)) { $metaData = Vtiger_Functions::getCRMRecordMetadata($id); $save = false; $deletedLabel = $metaData['deleted'] ? ' - ' . vtranslate('LBL_RECORD_DELETED', 'DataAccess') : ''; $fieldlabel .= '<a target="_blank" href="index.php?module=Accounts&view=Detail&record=' . $id . '">• ' . Vtiger_Functions::getCRMRecordLabel($id) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($metaData['smownerid']) . ')' . $deletedLabel . ',<br/>'; } } if (!$save) { $permission = Users_Privileges_Model::isPermitted($moduleName, 'DuplicateRecord'); $text = '<div class="marginLeft10">' . vtranslate('LBL_DUPLICATED_FOUND', 'DataAccess') . ': <br/ >' . trim($fieldlabel, ',') . '</div>'; if ($permission) { $title = '<strong>' . vtranslate('LBL_DUPLICTAE_CREATION_CONFIRMATION', 'DataAccess') . '</strong>'; if (!empty($iD)) { $text .= '<form class="form-horizontal"><div class="checkbox"> <label> <input type="checkbox" name="cache"> ' . vtranslate('LBL_DONT_ASK_AGAIN', 'DataAccess') . ' </label> </div></form>'; } if ($recordForm['view'] == 'quick_edit') { $text = '<div class="alert alert-warning" role="alert">' . vtranslate('LBL_DUPLICTAE_QUICK_EDIT_CONFIRMATION', 'DataAccess') . '</div>' . $text; } } return array('save_record' => $save, 'type' => 3, 'info' => ['text' => $text, 'title' => $title, 'type' => $permission ? 1 : 0]); } else { return array('save_record' => true); } }
/** * Function to display the Search Results * @param Vtiger_Request $request */ function showSearchResults(Vtiger_Request $request) { $db = PearDatabase::getInstance(); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $advFilterList = $request->get('advfilterlist'); //used to show the save modify filter option $isAdvanceSearch = false; $matchingRecords = array(); if (is_array($advFilterList) && count($advFilterList) > 0) { $isAdvanceSearch = true; $user = Users_Record_Model::getCurrentUserModel(); $queryGenerator = new QueryGenerator($moduleName, $user); $queryGenerator->setFields(['id']); vimport('~modules/CustomView/CustomView.php'); $customView = new CustomView($moduleName); $dateSpecificConditions = $customView->getStdFilterConditions(); foreach ($advFilterList as $groupindex => $groupcolumns) { $filtercolumns = $groupcolumns['columns']; if (count($filtercolumns) > 0) { $queryGenerator->startGroup(''); foreach ($filtercolumns as $index => $filter) { $nameComponents = explode(':', $filter['columnname']); if (empty($nameComponents[2]) && $nameComponents[1] == 'crmid' && $nameComponents[0] == 'vtiger_crmentity') { $name = $queryGenerator->getSQLColumn('id'); } else { $name = $nameComponents[2]; } if (($nameComponents[4] == 'D' || $nameComponents[4] == 'DT') && in_array($filter['comparator'], $dateSpecificConditions)) { $filter['stdfilter'] = $filter['comparator']; $valueComponents = explode(',', $filter['value']); if ($filter['comparator'] == 'custom') { $filter['startdate'] = DateTimeField::convertToDBFormat($valueComponents[0]); $filter['enddate'] = DateTimeField::convertToDBFormat($valueComponents[1]); } $dateFilterResolvedList = $customView->resolveDateFilterValue($filter); $value[] = $queryGenerator->fixDateTimeValue($name, $dateFilterResolvedList['startdate']); $value[] = $queryGenerator->fixDateTimeValue($name, $dateFilterResolvedList['enddate'], false); $queryGenerator->addCondition($name, $value, 'BETWEEN'); } else { $queryGenerator->addCondition($name, $filter['value'], $filter['comparator']); } $columncondition = $filter['column_condition']; if (!empty($columncondition) && array_key_exists($index + 1, $filtercolumns)) { $queryGenerator->addConditionGlue($columncondition); } } $queryGenerator->endGroup(); $groupConditionGlue = $groupcolumns['condition']; if (!empty($groupConditionGlue)) { $queryGenerator->addConditionGlue($groupConditionGlue); } } } $query = $queryGenerator->getQuery(); //Remove the ordering for now to improve the speed //$query .= ' ORDER BY createdtime DESC'; $result = $db->query($query); while ($row = $db->fetch_array($result)) { $recordInstance = Vtiger_Record_Model::getInstanceById(current($row)); $moduleName = $recordInstance->getModuleName(); $recordInstance->set('permitted', true); $matchingRecords[$moduleName][current($row)] = $recordInstance; } $viewer->assign('SEARCH_MODULE', $moduleName); } else { $searchKey = $request->get('value'); $searchModule = false; if ($request->get('searchModule')) { $searchModule = $request->get('searchModule'); } $viewer->assign('SEARCH_KEY', $searchKey); $viewer->assign('SEARCH_MODULE', $searchModule); $matchingRecords = Vtiger_Record_Model::getSearchResult($searchKey, $searchModule, $request->get('limit')); } $recordsList = $matchingRecordsList = []; if ($matchingRecords[$moduleName]) { $matchingRecordsList[$moduleName] = $matchingRecords[$moduleName]; } foreach ($matchingRecords as $module => $recordModelsList) { $matchingRecordsList[$module] = $recordModelsList; } if ($request->get('html') == 'true') { $viewer->assign('MODULE', $moduleName); $viewer->assign('MATCHING_RECORDS', $matchingRecordsList); $viewer->assign('IS_ADVANCE_SEARCH', $isAdvanceSearch); echo $viewer->view('UnifiedSearchResults.tpl', '', true); } else { foreach ($matchingRecordsList as $module => $modules) { foreach ($modules as $recordID => $recordModel) { $label = decode_html($recordModel->getName()); $label .= ' (' . Vtiger_Functions::getOwnerRecordLabel($recordModel->get('smownerid')) . ')'; if (!$recordModel->get('permitted')) { $label .= ' <span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span>'; } $recordsList[] = ['id' => $recordID, 'module' => $module, 'category' => vtranslate($module, $module), 'label' => $label, 'permitted' => $recordModel->get('permitted')]; } } $response = new Vtiger_Response(); $response->setResult($recordsList); $response->emit(); } }
public function process($ModuleName, $ID, $record_form, $config) { $db = PearDatabase::getInstance(); $ModuleNameID = Vtiger_Functions::getModuleId($ModuleName); $fieldlabel = $sql_ext = ''; $save_record1 = true; $save_record2 = true; $save_record = true; $type = 0; $typeInfo = 'info'; $info = false; if ($ID != 0 && $ID != '' && !array_key_exists($config['what1'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($ID, $ModuleName); $value1 = $Record_Model->get($config['what1']); } else { if (array_key_exists($config['what1'], $record_form)) { $value1 = $record_form[$config['what1']]; } } if ($ID != 0 && $ID != '' && !array_key_exists($config['what2'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($ID, $ModuleName); $value2 = $Record_Model->get($config['what2']); } else { if (array_key_exists($config['what2'], $record_form)) { $value2 = $record_form[$config['what2']]; } } if (!is_array($config['where1'])) { $wheres1[] = $config['where1']; } else { $wheres1 = $config['where1']; } if (!is_array($config['where2'])) { $wheres2[] = $config['where2']; } else { $wheres2 = $config['where2']; } if ($value1 != '') { foreach ($wheres1 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value1); $sql_ext = ''; $spacialCondition = ''; $sqlSpecial = ''; if ($ModuleNameID == $where[2] && $ID != 0 && $ID != '') { $sql_param[] = $ID; $sql_ext = 'AND ' . $index . ' <> ?'; } if ($DestModuleName == 'Leads') { $spacialCondition = ' AND `converted` = 0'; if ('vtiger_crmentity' == $where[0]) { $sqlSpecial = 'INNER JOIN vtiger_leaddetails ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid '; } } $result = $db->pquery("SELECT {$index} FROM {$where[0]} {$sqlSpecial} WHERE {$where[1]} = ? {$sql_ext} {$spacialCondition};", $sql_param, true); $num = $db->num_rows($result); for ($i = 0; $i < $num; $i++) { $id = $db->query_result_raw($result, $i, $index); $metadata = Vtiger_Functions::getCRMRecordMetadata($id); if ($metadata['setype'] == $DestModuleName) { $save_record1 = false; $deletedLabel = $metadata['deleted'] ? ' - ' . vtranslate('LBL_RECORD_DELETED', 'DataAccess') : ''; $fieldlabel .= '<a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '">• ' . Vtiger_Functions::getCRMRecordLabel($id) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($metadata['smownerid']) . ')' . $deletedLabel . ',<br/>'; } } } } if ($value2 != '') { foreach ($wheres2 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value2); $sql_ext = ''; $spacialCondition = ''; $sqlSpecial = ''; if ($ModuleNameID == $where[2] && $ID != 0 && $ID != '') { $sql_param[] = $ID; $sql_ext = 'AND ' . $index . ' <> ?'; } if ($DestModuleName == 'Leads') { $spacialCondition = ' AND `converted` = 0'; if ('vtiger_crmentity' == $where[0]) { $sqlSpecial = 'INNER JOIN vtiger_leaddetails ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid '; } } $result = $db->pquery("SELECT {$index} FROM {$where[0]} WHERE {$where[1]} = ? {$sql_ext};", $sql_param, true); $num = $db->num_rows($result); for ($i = 0; $i < $num; $i++) { $id = $db->query_result_raw($result, $i, $index); $metadata = Vtiger_Functions::getCRMRecordMetadata($id); if ($metadata['setype'] == $DestModuleName) { $save_record2 = false; $deletedLabel = $metadata['deleted'] ? ' - ' . vtranslate('LBL_RECORD_DELETED', 'DataAccess') : ''; $fieldlabel .= '<a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '">• ' . Vtiger_Functions::getCRMRecordLabel($id) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($metadata['smownerid']) . ')' . $deletedLabel . ',<br/>'; } } } } if ($config['locksave'] == 0) { $info = $config['info0']; $type = 2; $save_record = !$save_record1 || !$save_record2 ? false : true; } elseif (!$save_record1 && !$save_record2) { $typeInfo = 'error'; $save_record = false; $info = $config['info2']; } elseif (!$save_record1 || !$save_record2) { $typeInfo = 'error'; $save_record = false; $info = $config['info1']; } if (!$save_record || $info) { return array('save_record' => $save_record, 'type' => $type, 'info' => ['text' => vtranslate($info, 'DataAccess') . ' <br/ >' . trim($fieldlabel, ','), 'ntype' => $typeInfo, 'hide' => false]); } else { return array('save_record' => true); } }
public function getEntity() { $currentUser = Users_Record_Model::getCurrentUserModel(); $db = PearDatabase::getInstance(); $data = $this->getQuery(); $result = $db->pquery($data['query'], $data['params']); $return = []; while ($record = $db->fetch_array($result)) { $item = []; $crmid = $record['activityid']; $activitytype = $record['activitytype']; $item['id'] = $crmid; $item['module'] = $this->getModuleName(); $item['title'] = $record['subject']; $item['url'] = 'index.php?module=' . $this->getModuleName() . '&view=Detail&record=' . $crmid; $item['set'] = $record['activitytype'] == 'Task' ? 'Task' : 'Event'; $item['lok'] = $record['location']; $item['pri'] = $record['priority']; $item['sta'] = $record['status']; $item['vis'] = $record['visibility']; $item['state'] = $record['state']; $item['smownerid'] = Vtiger_Functions::getOwnerRecordLabel($record['smownerid']); //translate $item['labels']['sta'] = vtranslate($record['status'], $this->getModuleName()); $item['labels']['pri'] = vtranslate($record['priority'], $this->getModuleName()); $item['labels']['state'] = vtranslate($record['state'], $this->getModuleName()); //Relation $item['link'] = $record['link']; $item['linkl'] = $record['linklabel']; $item['linkm'] = $record['linkmod']; //Process $item['process'] = $record['process']; $item['procl'] = $record['processlabel']; $item['procm'] = $record['processmod']; if ($record['linkmod'] != 'Accounts' && (!empty($record['link']) || !empty($record['process']))) { $findId = 0; $findMod = ''; if (!empty($record['link'])) { $findId = $record['link']; $findMod = $record['linkmod']; } if (!empty($record['process'])) { $findId = $record['process']; $findMod = $record['processmod']; } $tabInfo = $this->relationAcounts[$findMod]; if ($tabInfo) { $findResult = $db->pquery('SELECT accountid, accountname FROM vtiger_account ' . 'INNER JOIN ' . $tabInfo[0] . ' ON vtiger_account.accountid = ' . $tabInfo[0] . '.' . $tabInfo[2] . ' WHERE ' . $tabInfo[1] . ' = ?;', [$findId]); if ($db->num_rows($findResult) > 0) { $item['accid'] = $db->query_result_raw($findResult, 0, 'accountid'); $item['accname'] = $db->query_result_raw($findResult, 0, 'accountname'); } } } $dateTimeFieldInstance = new DateTimeField($record['date_start'] . ' ' . $record['time_start']); $userDateTimeString = $dateTimeFieldInstance->getFullcalenderDateTimevalue($currentUser); $dateTimeComponents = explode(' ', $userDateTimeString); $dateComponent = $dateTimeComponents[0]; $startTimeFormated = $dateTimeComponents[1]; //Conveting the date format in to Y-m-d . since full calendar expects in the same format $startDateFormated = DateTimeField::__convertToDBFormat($dateComponent, $currentUser->get('date_format')); $dateTimeFieldInstance = new DateTimeField($record['due_date'] . ' ' . $record['time_end']); $userDateTimeString = $dateTimeFieldInstance->getFullcalenderDateTimevalue($currentUser); $dateTimeComponents = explode(' ', $userDateTimeString); $dateComponent = $dateTimeComponents[0]; $endTimeFormated = $dateTimeComponents[1]; //Conveting the date format in to Y-m-d . since full calendar expects in the same format $endDateFormated = DateTimeField::__convertToDBFormat($dateComponent, $currentUser->get('date_format')); $item['start'] = $startDateFormated . ' ' . $startTimeFormated; $item['end'] = $endDateFormated . ' ' . $endTimeFormated; $item['allDay'] = $record['allday'] == 1 ? true : false; $item['className'] = ' userCol_' . $record['smownerid'] . ' calCol_' . $activitytype; $return[] = $item; } return $return; }
public function process($ModuleName, $ID, $record_form, $config) { $db = PearDatabase::getInstance(); $ModuleNameID = Vtiger_Functions::getModuleId($ModuleName); $sql_ext = ''; $save_record1 = true; $save_record2 = true; $save_record = true; $type = 'info'; $info = false; if ($ID != 0 && $ID != '' && !array_key_exists($config['what1'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($ID, $ModuleName); $value1 = $Record_Model->get($config['what1']); } else { if (array_key_exists($config['what1'], $record_form)) { $value1 = $record_form[$config['what1']]; } } if ($ID != 0 && $ID != '' && !array_key_exists($config['what2'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($ID, $ModuleName); $value2 = $Record_Model->get($config['what2']); } else { if (array_key_exists($config['what2'], $record_form)) { $value2 = $record_form[$config['what2']]; } } if (!is_array($config['where1'])) { $wheres1[] = $config['where1']; } else { $wheres1 = $config['where1']; } if (!is_array($config['where2'])) { $wheres2[] = $config['where2']; } else { $wheres2 = $config['where2']; } if ($value1 != '') { foreach ($wheres1 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value1); $sql_ext = ''; if ($ModuleNameID == $where[2] && $ID != 0 && $ID != '') { $sql_param[] = $ID; $sql_ext = 'AND ' . $index . ' <> ?'; } $result = $db->pquery("SELECT {$index} FROM {$where[0]} WHERE {$where[1]} = ? {$sql_ext};", $sql_param, true); for ($i = 0; $i < $db->num_rows($result); $i++) { $save_record1 = false; $id = $db->query_result_raw($result, $i, $index); $result = $db->pquery("SELECT smownerid FROM vtiger_crmentity WHERE crmid = ?", array($id), true); $fieldlabel .= '<a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '">• ' . Vtiger_Functions::getCRMRecordLabel($id) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($db->query_result($result, 0, 'smownerid')) . '),'; } } } if ($value2 != '') { foreach ($wheres2 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value1); $sql_ext = ''; if ($ModuleNameID == $where[2] && $ID != 0 && $ID != '') { $sql_param[] = $ID; $sql_ext = 'AND ' . $index . ' <> ?'; } $result = $db->pquery("SELECT {$index} FROM {$where[0]} WHERE {$where[1]} = ? {$sql_ext};", $sql_param, true); for ($i = 0; $i < $db->num_rows($result); $i++) { $save_record2 = false; $id = $db->query_result_raw($result, $i, $index); $result = $db->pquery("SELECT smownerid FROM vtiger_crmentity WHERE crmid = ?", array($id), true); $fieldlabel .= '<a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '">• ' . Vtiger_Functions::getCRMRecordLabel($id) . '</a> (' . Vtiger_Functions::getOwnerRecordLabel($db->query_result($result, 0, 'smownerid')) . '),'; } } } if ($config['locksave'] == 0 && $ID == '') { $info = $config['info0']; } elseif (!$save_record1 && !$save_record2) { $type = 'error'; $save_record = false; $info = $config['info2']; } elseif (!$save_record1 || !$save_record2) { $type = 'error'; $save_record = false; $info = $config['info1']; } if (!$save_record || $info) { return array('save_record' => $save_record, 'type' => 0, 'info' => array('title' => vtranslate($info, 'DataAccess') . ' <br/ >' . trim($fieldlabel, ','), 'type' => $type, 'hide' => false)); } else { return array('save_record' => true); } }
public function process($moduleName, $iD, $record_form, $config) { $db = PearDatabase::getInstance(); $moduleNameID = Vtiger_Functions::getModuleId($moduleName); $fieldlabel = $sql_ext = ''; $save_record1 = true; $save_record2 = true; $save_record = true; $type = 0; $typeInfo = 'info'; $info = false; if ($iD != 0 && $iD != '' && !array_key_exists($config['what1'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($iD, $moduleName); $value1 = $Record_Model->get($config['what1']); } else { if (array_key_exists($config['what1'], $record_form)) { $value1 = $record_form[$config['what1']]; } } if ($iD != 0 && $iD != '' && !array_key_exists($config['what2'], $record_form)) { $Record_Model = Vtiger_Record_Model::getInstanceById($iD, $moduleName); $value2 = $Record_Model->get($config['what2']); } else { if (array_key_exists($config['what2'], $record_form)) { $value2 = $record_form[$config['what2']]; } } if (!is_array($config['where1'])) { $wheres1[] = $config['where1']; } else { $wheres1 = $config['where1']; } if (!is_array($config['where2'])) { $wheres2[] = $config['where2']; } else { $wheres2 = $config['where2']; } if ($value1 != '') { foreach ($wheres1 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value1); $sql_ext = ''; $spacialCondition = ''; $sqlSpecial = ''; if ($moduleNameID == $where[2] && $iD != 0 && $iD != '') { $sql_param[] = $iD; $sql_ext = 'AND ' . $index . ' <> ?'; } if ($DestModuleName == 'Leads') { $spacialCondition = ' AND `converted` = 0'; if ('vtiger_crmentity' == $where[0]) { $sqlSpecial = 'INNER JOIN vtiger_leaddetails ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid '; } } $result = $db->pquery("SELECT {$index} FROM {$where[0]} {$sqlSpecial} WHERE {$where[1]} = ? {$sql_ext} {$spacialCondition};", $sql_param, true); $num = $db->num_rows($result); for ($i = 0; $i < $num; $i++) { $id = $db->query_result_raw($result, $i, $index); $metadata = Vtiger_Functions::getCRMRecordMetadata($id); if ($metadata['setype'] == $DestModuleName) { $save_record1 = false; $deletedLabel = $metadata['deleted'] ? ' - ' . vtranslate('LBL_RECORD_DELETED', 'DataAccess') : ''; $fieldlabel .= '<li><a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '"><strong>' . Vtiger_Functions::getCRMRecordLabel($id) . '</strong></a> (' . Vtiger_Functions::getOwnerRecordLabel($metadata['smownerid']) . ')' . $deletedLabel . ',</li>'; } } } } if ($value2 != '') { foreach ($wheres2 as $where) { $where = explode('=', $where); $DestModuleName = Vtiger_Functions::getModuleName($where[2]); $ModuleInstance = CRMEntity::getInstance($DestModuleName); $tab_name_index = $ModuleInstance->tab_name_index; $index = $tab_name_index[$where[0]]; $sql_param = array($value2); $sql_ext = ''; $spacialCondition = ''; $sqlSpecial = ''; if ($moduleNameID == $where[2] && $iD != 0 && $iD != '') { $sql_param[] = $iD; $sql_ext = 'AND ' . $index . ' <> ?'; } if ($DestModuleName == 'Leads') { $spacialCondition = ' AND `converted` = 0'; if ('vtiger_crmentity' == $where[0]) { $sqlSpecial = 'INNER JOIN vtiger_leaddetails ON vtiger_crmentity.crmid = vtiger_leaddetails.leadid '; } } $result = $db->pquery("SELECT {$index} FROM {$where[0]} WHERE {$where[1]} = ? {$sql_ext};", $sql_param, true); $num = $db->num_rows($result); for ($i = 0; $i < $num; $i++) { $id = $db->query_result_raw($result, $i, $index); $metadata = Vtiger_Functions::getCRMRecordMetadata($id); if ($metadata['setype'] == $DestModuleName) { $save_record2 = false; $deletedLabel = $metadata['deleted'] ? ' - ' . vtranslate('LBL_RECORD_DELETED', 'DataAccess') : ''; $fieldlabel .= '<li><a target="_blank" href="index.php?module=' . $DestModuleName . '&view=Detail&record=' . $id . '"><strong>' . Vtiger_Functions::getCRMRecordLabel($id) . '</strong></a> (' . Vtiger_Functions::getOwnerRecordLabel($metadata['smownerid']) . ')' . $deletedLabel . ',</li>'; } } } } if ($config['locksave'] == 0) { $info = $config['info0']; $type = 2; $save_record = !$save_record1 || !$save_record2 ? false : true; } elseif (!$save_record1 && !$save_record2) { $typeInfo = 'error'; $save_record = false; $info = $config['info2']; } elseif (!$save_record1 || !$save_record2) { $typeInfo = 'error'; $save_record = false; $info = $config['info1']; } if ($config['locksave'] == 3 && !$save_record) { $type = $config['locksave']; $permission = Users_Privileges_Model::isPermitted($moduleName, 'DuplicateRecord'); $text = '<div class="marginLeft10">' . vtranslate('LBL_DUPLICATED_FOUND', 'DataAccess') . ': <br/ >' . trim($fieldlabel, ',') . '</div>'; if ($permission) { $title = '<strong>' . vtranslate('LBL_DUPLICTAE_CREATION_CONFIRMATION', 'DataAccess') . '</strong>'; if (!empty($iD)) { $text .= '<form class="form-horizontal"><div class="checkbox"> <label> <input type="checkbox" name="cache"> ' . vtranslate('LBL_DONT_ASK_AGAIN', 'DataAccess') . ' </label> </div></form>'; } if ($record_form['view'] == 'quick_edit') { $text = '<div class="alert alert-warning" role="alert">' . vtranslate('LBL_DUPLICTAE_QUICK_EDIT_CONFIRMATION', 'DataAccess') . '</div>' . $text; } } $info = ['text' => $text, 'title' => $title, 'type' => $permission ? 1 : 0]; } if (!$save_record || $info) { return array('save_record' => $save_record, 'type' => $type, 'info' => $info ? $info : ['text' => vtranslate($info, 'DataAccess') . ' <br/ >' . trim($fieldlabel, ','), 'ntype' => $typeInfo, 'hide' => false]); } else { return array('save_record' => true); } }