function get_project_tickets($id, $module, $customerid, $sessionid) { require_once 'modules/HelpDesk/HelpDesk.php'; require_once 'include/utils/UserInfoUtil.php'; $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering customer portal function get_project_tickets .."); $check = checkModuleActive($module); if ($check == false) { return array("#MODULE INACTIVE#"); } if (!validateSession($customerid, $sessionid)) { return null; } $user = new Users(); $userid = getPortalUserid(); $current_user = $user->retrieveCurrentUserInfoFromFile($userid); $focus = new HelpDesk(); $focus->filterInactiveFields('HelpDesk'); $TicketsfieldVisibilityByColumn = array(); $fields_list = array(); foreach ($focus->list_fields as $fieldlabel => $values) { foreach ($values as $table => $fieldname) { $fields_list[$fieldlabel] = $fieldname; $TicketsfieldVisibilityByColumn[$fieldname] = getColumnVisibilityPermission($current_user->id, $fieldname, 'HelpDesk'); } } $query = "SELECT vtiger_troubletickets.*, vtiger_crmentity.smownerid FROM vtiger_troubletickets\n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid\n\t\tINNER JOIN vtiger_crmentityrel ON (vtiger_crmentityrel.relcrmid = vtiger_crmentity.crmid OR vtiger_crmentityrel.crmid = vtiger_crmentity.crmid)\n\t\tWHERE vtiger_crmentity.deleted = 0 AND (vtiger_crmentityrel.crmid = ? OR vtiger_crmentityrel.relcrmid = ?)"; $params = array($id, $id); $res = $adb->pquery($query, $params); $noofdata = $adb->num_rows($res); for ($j = 0; $j < $noofdata; $j++) { $i = 0; foreach ($fields_list as $fieldlabel => $fieldname) { $fieldper = $TicketsfieldVisibilityByColumn[$fieldname]; //in troubletickets the list_fields has columns so we call this API if ($fieldper == '1') { continue; } $output[0][$module]['head'][0][$i]['fielddata'] = Vtiger_Language_Handler::getTranslatedString($fieldlabel, 'HelpDesk', vglobal('default_language')); $fieldvalue = $adb->query_result($res, $j, $fieldname); $ticketid = $adb->query_result($res, $j, 'ticketid'); if ($fieldname == 'title') { $fieldvalue = '<a href="index.php?module=HelpDesk&action=index&fun=detail&ticketid=' . $ticketid . '">' . $fieldvalue . '</a>'; } if ($fieldname == 'parent_id' || $fieldname == 'contact_id') { $crmid = $fieldvalue; $entitymodule = getSalesEntityType($crmid); if ($crmid != '' && $entitymodule != '') { $fieldvalues = getEntityName($entitymodule, array($crmid)); if ($entitymodule == 'Contacts') { $fieldvalue = '<a href="index.php?module=Contacts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } elseif ($entitymodule == 'Accounts') { $fieldvalue = '<a href="index.php?module=Accounts&action=index&id=' . $crmid . '">' . $fieldvalues[$crmid] . '</a>'; } } else { $fieldvalue = ''; } } if ($fieldname == 'smownerid') { $fieldvalue = getOwnerName($fieldvalue); } if ($fieldlabel == 'Status') { $fieldvalue = Vtiger_Language_Handler::getTranslatedString($fieldvalue, 'HelpDesk', vglobal('default_language')); } $output[1][$module]['data'][$j][$i]['fielddata'] = $fieldvalue; $i++; } } $log->debug("Exiting customerportal function get_project_tickets .."); return $output; }
/** function to get a list of tickets and to search tickets * @param array $input_array - array which contains the following values => int $id - Customer ie., Contact id int $only_mine - if true it will display only tickets related to contact otherwise displays tickets related to account it belongs and all the contacts that are under the same account int $where - used for searching tickets string $match - used for matching tickets * return array $result - This function will call get_KBase_details and return that array */ function get_tickets_list($input_array) { require_once 'modules/HelpDesk/HelpDesk.php'; require_once 'include/utils/UserInfoUtil.php'; global $adb, $log; global $current_user; require_once 'modules/Users/Users.php'; $log->debug("Entering customer portal function get_ticket_list"); $user = new Users(); $userid = getPortalUserid(); $show_all = show_all('HelpDesk'); $current_user = $user->retrieveCurrentUserInfoFromFile($userid); $id = $input_array['id']; $only_mine = $input_array['onlymine']; $where = $input_array['where']; //addslashes is already added with where condition fields in portal itself $match = $input_array['match']; $sessionid = $input_array['sessionid']; if (!validateSession($id, $sessionid)) { return null; } // Prepare where conditions based on search query $join_type = ''; $where_conditions = ''; if (trim($where) != '') { if ($match == 'all' || $match == '') { $join_type = " AND "; } elseif ($match == 'any') { $join_type = " OR "; } $where = explode("&&&", $where); $where_conditions = implode($join_type, $where); } $entity_ids_list = array(); if ($only_mine == 'true' || $show_all == 'false') { array_push($entity_ids_list, $id); } else { $contactquery = "SELECT contactid, accountid FROM vtiger_contactdetails " . " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_contactdetails.contactid" . " AND vtiger_crmentity.deleted = 0 " . " WHERE (accountid = (SELECT accountid FROM vtiger_contactdetails WHERE contactid = ?) AND accountid != 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, 'accountid'); 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 HelpDesk(); $focus->filterInactiveFields('HelpDesk'); foreach ($focus->list_fields as $fieldlabel => $values) { foreach ($values as $table => $fieldname) { $fields_list[$fieldlabel] = $fieldname; } } $query = "SELECT vtiger_troubletickets.*, vtiger_crmentity.smownerid,vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime, '' AS setype\n\t\tFROM vtiger_troubletickets \n\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid AND vtiger_crmentity.deleted = 0\n\t\tWHERE vtiger_troubletickets.parent_id IN (" . generateQuestionMarks($entity_ids_list) . ")"; // Add conditions if there are any search parameters if ($join_type != '' && $where_conditions != '') { $query .= " AND (" . $where_conditions . ")"; } $params = array($entity_ids_list); $TicketsfieldVisibilityByColumn = array(); foreach ($fields_list as $fieldlabel => $fieldname) { $TicketsfieldVisibilityByColumn[$fieldname] = getColumnVisibilityPermission($current_user->id, $fieldname, 'HelpDesk'); } $res = $adb->pquery($query, $params); $noofdata = $adb->num_rows($res); for ($j = 0; $j < $noofdata; $j++) { $i = 0; foreach ($fields_list as $fieldlabel => $fieldname) { $fieldper = $TicketsfieldVisibilityByColumn[$fieldname]; //in troubletickets the list_fields has columns so we call this API if ($fieldper == '1') { continue; } $output[0]['head'][0][$i]['fielddata'] = $fieldlabel; $fieldvalue = $adb->query_result($res, $j, $fieldname); $ticketid = $adb->query_result($res, $j, 'ticketid'); if ($fieldname == 'title') { $fieldvalue = '<a href="index.php?module=HelpDesk&action=index&fun=detail&ticketid=' . $ticketid . '">' . $fieldvalue . '</a>'; } if ($fieldname == 'parent_id') { $crmid = $fieldvalue; $module = getSalesEntityType($crmid); 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 == 'smownerid') { $fieldvalue = getOwnerName($fieldvalue); } $output[1]['data'][$j][$i]['fielddata'] = $fieldvalue; $i++; } } $log->debug("Exiting customer portal function get_ticket_list"); return $output; }