function get_service_list_values($id, $modulename, $sessionid, $only_mine = 'true') { require_once 'modules/Services/Services.php'; require_once 'include/utils/UserInfoUtil.php'; $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering customer portal Function get_service_list_values"); $check = checkModuleActive($modulename); if ($check == false) { return array("#MODULE INACTIVE#"); } $user = new Users(); $userid = getPortalUserid(); $current_user = $user->retrieveCurrentUserInfoFromFile($userid); //To avoid SQL injection we are type casting as well as bound the id variable $id = (int) vtlib_purify($id); $entity_ids_list = array(); $show_all = show_all($modulename); if (!validateSession($id, $sessionid)) { return null; } if ($only_mine == 'true' || $show_all == 'false') { array_push($entity_ids_list, $id); } else { $contactquery = "SELECT contactid, parentid FROM vtiger_contactdetails " . " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid" . " AND vtiger_crmentity.deleted = 0 " . " WHERE (parentid = (SELECT parentid FROM vtiger_contactdetails WHERE contactid = ?) AND parentid != 0) OR contactid = ?"; $contactres = $adb->pquery($contactquery, array($id, $id)); $no_of_cont = $adb->num_rows($contactres); for ($i = 0; $i < $no_of_cont; $i++) { $cont_id = $adb->query_result($contactres, $i, 'contactid'); $acc_id = $adb->query_result($contactres, $i, 'parentid'); if (!in_array($cont_id, $entity_ids_list)) { $entity_ids_list[] = $cont_id; } if (!in_array($acc_id, $entity_ids_list) && $acc_id != '0') { $entity_ids_list[] = $acc_id; } } } $focus = new Services(); $focus->filterInactiveFields('Services'); foreach ($focus->list_fields as $fieldlabel => $values) { foreach ($values as $table => $fieldname) { $fields_list[$fieldlabel] = $fieldname; } } $fields_list['Related To'] = 'entityid'; $query = array(); $params = array(); $query[] = "select vtiger_service.*," . "case when vtiger_crmentityrel.crmid != vtiger_service.serviceid then vtiger_crmentityrel.crmid else vtiger_crmentityrel.relcrmid end as entityid, " . "'' as setype from vtiger_service " . "inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_service.serviceid " . "left join vtiger_crmentityrel on (vtiger_crmentityrel.relcrmid=vtiger_service.serviceid or vtiger_crmentityrel.crmid=vtiger_service.serviceid) " . "where vtiger_crmentity.deleted = 0 and " . "( vtiger_crmentityrel.crmid in (" . generateQuestionMarks($entity_ids_list) . ") OR " . "(vtiger_crmentityrel.relcrmid in (" . generateQuestionMarks($entity_ids_list) . ") AND vtiger_crmentityrel.module = 'Services')" . ")"; $params[] = array($entity_ids_list, $entity_ids_list); $checkQuotes = checkModuleActive('Quotes'); if ($checkQuotes == true) { $query[] = "select distinct vtiger_service.*,\n\t\t\tvtiger_quotes.accountid as entityid,\n\t\t\t'Accounts' as setype\n\t\t\tfrom vtiger_quotes INNER join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_quotes.quoteid\n\t\t\tleft join vtiger_inventoryproductrel on vtiger_inventoryproductrel.id=vtiger_quotes.quoteid\n\t\t\tleft join vtiger_service on vtiger_service.serviceid = vtiger_inventoryproductrel.productid\n\t\t\twhere vtiger_inventoryproductrel.productid = vtiger_service.serviceid AND vtiger_crmentity.deleted=0 and accountid in (" . generateQuestionMarks($entity_ids_list) . ")"; $params[] = array($entity_ids_list); } $checkInvoices = checkModuleActive('Invoice'); if ($checkInvoices == true) { $query[] = "select distinct vtiger_service.*, vtiger_invoice.accountid as entityid, 'Accounts' as setype\n\t\t\tfrom vtiger_invoice\n\t\t\tINNER join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_invoice.invoiceid\n\t\t\tleft join vtiger_inventoryproductrel on vtiger_inventoryproductrel.id=vtiger_invoice.invoiceid\n\t\t\tleft join vtiger_service on vtiger_service.serviceid = vtiger_inventoryproductrel.productid\n\t\t\twhere vtiger_inventoryproductrel.productid = vtiger_service.serviceid AND vtiger_crmentity.deleted=0 and accountid in (" . generateQuestionMarks($entity_ids_list) . ")"; $params[] = array($entity_ids_list, $entity_ids_list); } $ServicesfieldVisibilityPermissions = array(); foreach ($fields_list as $fieldlabel => $fieldname) { $ServicesfieldVisibilityPermissions[$fieldname] = getFieldVisibilityPermission('Services', $current_user->id, $fieldname); } $fieldValuesToRound = array('unit_price', 'commissionrate'); for ($k = 0; $k < count($query); $k++) { $res[$k] = $adb->pquery($query[$k], $params[$k]); $noofdata[$k] = $adb->num_rows($res[$k]); if ($noofdata[$k] == 0) { $output[$k][$modulename]['data'] = ''; } for ($j = 0; $j < $noofdata[$k]; $j++) { $i = 0; foreach ($fields_list as $fieldlabel => $fieldname) { $fieldper = $ServicesfieldVisibilityPermissions[$fieldname]; if ($fieldper == '1' && $fieldname != 'entityid') { continue; } $output[$k][$modulename]['head'][0][$i]['fielddata'] = Vtiger_Language_Handler::getTranslatedString($fieldlabel, 'Services', vglobal('default_language')); $fieldvalue = $adb->query_result($res[$k], $j, $fieldname); $fieldid = $adb->query_result($res[$k], $j, 'serviceid'); if (in_array($fieldname, $fieldValuesToRound)) { $fieldvalue = round($fieldvalue, 2); } if ($fieldname == 'entityid') { $crmid = $fieldvalue; $module = $adb->query_result($res[$k], $j, 'setype'); if ($module == '') { $module = $adb->query_result($adb->pquery("SELECT setype FROM vtiger_crmentity WHERE crmid = ?", array($crmid)), 0, 'setype'); } if ($crmid != '' && $module != '') { $fieldvalues = getEntityName($module, array($crmid)); if ($module == 'Contacts') { $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } elseif ($module == 'Accounts') { $fieldvalue = '<a href="index.php?module=Accounts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } } else { $fieldvalue = ''; } } if ($fieldname == 'servicename') { $fieldvalue = '<a href="index.php?module=Services&action=index&id=' . $fieldid . '">' . $fieldvalue . '</a>'; } if ($fieldname == 'unit_price') { $sym = getCurrencySymbol($res[$k], $j, 'currency_id'); $fieldvalue = $sym . $fieldvalue; } $output[$k][$modulename]['data'][$j][$i]['fielddata'] = $fieldvalue; $i++; } } } $log->debug("Exiting customerportal function get_product_list_values....."); return $output; }
/** * Change filed for any CRM Entity * * @param arrya $input_array input data * @return string true or false */ function change_entity_field($input_array) { global $adb, $log; $adb->println("Inside customer portal function change_entity_field"); $adb->println($input_array); $contact_id = $input_array['id']; $session_id = $input_array['sessionid']; $module = $input_array['module']; $entity_id = $input_array['entityid']; $field_name = $input_array['fieldname']; $field_value = $input_array['fieldvalue']; global $current_user; $current_user->id = getPortalUserid(); require_once "modules/{$module}/{$module}.php"; if (!validateSession($contact_id, $session_id)) { return null; } $entity = CRMEntity::getInstance($module); if ($entity_id > 0) { $entity->retrieve_entity_info($entity_id, $module); $entity->column_fields[$field_name] = $field_value; if ($module == 'SalesOrder' || $module == 'Invoice' || $module == 'PurchaseOrder' || $module == 'Quotes') { // in ajax save we should not call update related products // function, because this will delete all the existing product values $_REQUEST['ajxaction'] = 'DETAILVIEW'; } $entity->save($module, $entity_id); if ($entity->column_fields["record_id"] == $entity->id) { $adb->println("{$module} from Portal is saved with id => " . $entity->id); return array($entity->id); } } $adb->println("There may be error in saving the {$module}"); return null; }