'crmid','vtiger_troubletickets'=>'ticketid','vtiger_ticketcf'=>'ticketid','vtiger_ticketcomments'=>'ticketid'); /** * Mandatory table for supporting custom fields. */ var $customFieldTable = Array('vtiger_ticketcf', 'ticketid'); var $column_fields = Array(); //Pavani: Assign value to entity_table var $entity_table = "vtiger_crmentity"; var $sortby_fields = Array('title','status','priority','crmid','firstname','smownerid'); var $list_fields = Array( //Module Sequence Numbering //'Ticket ID'=>Array('crmentity'=>'crmid'), 'Ticket No'=>Array('troubletickets'=>'ticket_no'), // END 'Subject'=>Array('troubletickets'=>'title'), 'Related to'=>Array('troubletickets'=>'parent_id'), 'Status'=>Array('troubletickets'=>'status'), 'Priority'=>Array('troubletickets'=>'priority'), 'Assigned To'=>Array('crmentity','smownerid') ); var $list_fields_name = Array( 'Ticket No'=>'ticket_no', 'Subject'=>'ticket_title', 'Related to'=>'parent_id', 'Status'=>'ticketstatus', 'Priority'=>'ticketpriorities', 'Assigned To'=>'assigned_user_id' ); var $list_link_field= 'ticket_title'; var $range_fields = Array( 'ticketid', 'title', 'firstname', 'lastname', 'parent_id', 'productid', 'productname', 'priority', 'severity', 'status', 'category', 'description', 'solution', 'modifiedtime', 'createdtime' ); var $search_fields = Array( //'Ticket ID' => Array('vtiger_crmentity'=>'crmid'), 'Ticket No' =>Array('vtiger_troubletickets'=>'ticket_no'), 'Title' => Array('vtiger_troubletickets'=>'title') ); var $search_fields_name = Array( 'Ticket No' => 'ticket_no', 'Title'=>'ticket_title', ); //Specify Required fields var $required_fields = array(); // Used when enabling/disabling the mandatory fields for the module. // Refers to vtiger_field.fieldname values. var $mandatory_fields = Array('assigned_user_id', 'createdtime', 'modifiedtime', 'ticket_title', 'update_log'); //Added these variables which are used as default order by and sortorder in ListView var $default_order_by = 'title'; var $default_sort_order = 'DESC'; //var $groupTable = Array('vtiger_ticketgrouprelation','ticketid'); /** Constructor which will set the column_fields in this object */ function HelpDesk() { $this->log =LoggerManager::getLogger('helpdesk'); $this->log->debug("Entering HelpDesk() method ..."); $this->db = PearDatabase::getInstance(); $this->column_fields = getColumnFields('HelpDesk'); $this->log->debug("Exiting HelpDesk method ..."); } function save_module($module) { //Inserting into Ticket Comment Table $this->insertIntoTicketCommentTable("vtiger_ticketcomments",'HelpDesk'); //Inserting into vtiger_attachments $this->insertIntoAttachment($this->id,'HelpDesk'); $return_action = $_REQUEST['return_action']; $for_module = $_REQUEST['return_module']; $for_crmid = $_REQUEST['return_id']; if ($return_action && $for_module && $for_crmid) { if ($for_module != 'Accounts' && $for_module != 'Contacts' && $for_module != 'Products') { $on_focus = CRMEntity::getInstance($for_module); $on_focus->save_related_module($for_module, $for_crmid, $module, $this->id); } } } /** Function to insert values in vtiger_ticketcomments for the specified tablename and module * @param $table_name -- table name:: Type varchar * @param $module -- module:: Type varchar */ function insertIntoTicketCommentTable($table_name, $module) { global $log; $log->info("in insertIntoTicketCommentTable ".$table_name." module is ".$module); global $adb; global $current_user; $current_time = $adb->formatDate(date('YmdHis'), true); if($this->column_fields['assigned_user_id'] != '') $ownertype = 'user'; else $ownertype = 'customer'; if($this->column_fields['comments'] != '') $comment = $this->column_fields['comments']; else $comment = $_REQUEST['comments']; if($comment != '') { $sql = "insert into vtiger_ticketcomments values(?,?,?,?,?,?)"; $params = array('', $this->id, from_html($comment), $current_user->id, $ownertype, $current_time); $adb->pquery($sql, $params); } } /** * This function is used to add the vtiger_attachments. This will call the function uploadAndSaveFile which will upload the attachment into the server and save that attachment information in the database. * @param int $id - entity id to which the vtiger_files to be uploaded * @param string $module - the current module name */ function insertIntoAttachment($id,$module) { global $log, $adb; $log->debug("Entering into insertIntoAttachment($id,$module) method."); $file_saved = false; foreach($_FILES as $fileindex => $files) { if($files['name'] != '' && $files['size'] > 0) { $files['original_name'] = vtlib_purify($_REQUEST[$fileindex.'_hidden']); $file_saved = $this->uploadAndSaveFile($id,$module,$files); } } $log->debug("Exiting from insertIntoAttachment($id,$module) method."); } /** Function used to get the sort order for HelpDesk listview * @return string $sorder - first check the $_REQUEST['sorder'] if request value is empty then check in the $_SESSION['HELPDESK_SORT_ORDER'] if this session value is empty then default sort order will be returned. */ function getSortOrder() { global $log; $log->debug("Entering getSortOrder() method ..."); if(isset($_REQUEST['sorder'])) $sorder = $this->db->sql_escape_string($_REQUEST['sorder']); else $sorder = (($_SESSION['HELPDESK_SORT_ORDER'] != '')?($_SESSION['HELPDESK_SORT_ORDER']):($this->default_sort_order)); $log->debug("Exiting getSortOrder() method ..."); return $sorder; } /** Function used to get the order by value for HelpDesk listview * @return string $order_by - first check the $_REQUEST['order_by'] if request value is empty then check in the $_SESSION['HELPDESK_ORDER_BY'] if this session value is empty then default order by will be returned. */ function getOrderBy() { global $log; $log->debug("Entering getOrderBy() method ..."); $use_default_order_by = ''; if(PerformancePrefs::getBoolean('LISTVIEW_DEFAULT_SORTING', true)) { $use_default_order_by = $this->default_order_by; } if (isset($_REQUEST['order_by'])) $order_by = $this->db->sql_escape_string($_REQUEST['order_by']); else $order_by = (($_SESSION['HELPDESK_ORDER_BY'] != '')?($_SESSION['HELPDESK_ORDER_BY']):($use_default_order_by)); $log->debug("Exiting getOrderBy method ..."); return $order_by; } /** Function to form the query to get the list of activities * @param int $id - ticket id * @return array - return an array which will be returned from the function GetRelatedList **/ function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) { global $log, $singlepane_view,$currentModule,$current_user; $log->debug("Entering get_activities(".$id.") method ..."); $this_module = $currentModule; $related_module = vtlib_getModuleNameById($rel_tab_id); require_once("modules/$related_module/Activity.php"); $other = new Activity(); vtlib_setup_modulevars($related_module, $other); $singular_modname = vtlib_toSingular($related_module); $parenttab = getParentTab(); if($singlepane_view == 'true') $returnset = '&return_module='.$this_module.'&return_action=DetailView&return_id='.$id; else $returnset = '&return_module='.$this_module.'&return_action=CallRelatedList&return_id='.$id; $button = ''; $button .= ''; if($actions) { if(is_string($actions)) $actions = explode(',', strtoupper($actions)); if(in_array('ADD', $actions) && isPermitted($related_module,1, '') == 'yes') { $button .= " "; $button .= ""; } } $query = "SELECT case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as user_name," . " vtiger_activity.*, vtiger_cntactivityrel.contactid, vtiger_contactdetails.lastname, vtiger_contactdetails.firstname," . " vtiger_crmentity.crmid, vtiger_recurringevents.recurringtype, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime," . " vtiger_seactivityrel.crmid as parent_id " . " from vtiger_activity inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid=vtiger_activity.activityid" . " inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid" . " left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid = vtiger_activity.activityid " . " left join vtiger_contactdetails on vtiger_contactdetails.contactid = vtiger_cntactivityrel.contactid" . " left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=vtiger_activity.activityid" . " left join vtiger_users on vtiger_users.id=vtiger_crmentity.smownerid" . " left join vtiger_groups on vtiger_groups.groupid=vtiger_crmentity.smownerid" . " where vtiger_seactivityrel.crmid=".$id." and vtiger_crmentity.deleted=0 and (activitytype NOT IN ('Emails'))" . " AND ( vtiger_activity.status is NULL OR vtiger_activity.status != 'Completed' )" . " and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus != 'Held') "; $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); if($return_value == null) $return_value = Array(); $return_value['CUSTOM_BUTTON'] = $button; $log->debug("Exiting get_activities method ..."); return $return_value; } /** Function to get the Ticket History information as in array format * @param int $ticketid - ticket id * @return array - return an array with title and the ticket history informations in the following format array( header=>array('0'=>'title'), entries=>array('0'=>'info1','1'=>'info2',etc.,) ) */ function get_ticket_history($ticketid) { global $log, $adb; $log->debug("Entering into get_ticket_history($ticketid) method ..."); $query="select title,update_log from vtiger_troubletickets where ticketid=?"; $result=$adb->pquery($query, array($ticketid)); $update_log = $adb->query_result($result,0,"update_log"); $splitval = split('--//--',trim($update_log,'--//--')); $header[] = $adb->query_result($result,0,"title"); $return_value = Array('header'=>$header,'entries'=>$splitval); $log->debug("Exiting from get_ticket_history($ticketid) method ..."); return $return_value; } /** Function to get the ticket comments as a array * @param int $ticketid - ticketid * @return array $output - array( [$i][comments] => comments [$i][owner] => name of the user or customer who made the comment [$i][createdtime] => the comment created time ) where $i = 0,1,..n which are all made for the ticket **/ function get_ticket_comments_list($ticketid) { global $log; $log->debug("Entering get_ticket_comments_list(".$ticketid.") method ..."); $sql = "select * from vtiger_ticketcomments where ticketid=? order by createdtime DESC"; $result = $this->db->pquery($sql, array($ticketid)); $noofrows = $this->db->num_rows($result); for($i=0;$i<$noofrows;$i++) { $ownerid = $this->db->query_result($result,$i,"ownerid"); $ownertype = $this->db->query_result($result,$i,"ownertype"); if($ownertype == 'user') $name = getUserName($ownerid); elseif($ownertype == 'customer') { $sql1 = 'select * from vtiger_portalinfo where id=?'; $name = $this->db->query_result($this->db->pquery($sql1, array($ownerid)),0,'user_name'); } $output[$i]['comments'] = nl2br($this->db->query_result($result,$i,"comments")); $output[$i]['owner'] = $name; $output[$i]['createdtime'] = $this->db->query_result($result,$i,"createdtime"); } $log->debug("Exiting get_ticket_comments_list method ..."); return $output; } /** Function to process the list query and return the result with number of rows * @param string $query - query * @return array $response - array( list => array( $i => array(key => val) ), row_count => '', next_offset => '', previous_offset =>'' ) where $i=0,1,..n & key = ticketid, title, firstname, ..etc(range_fields) & val = value of the key from db retrieved row **/ function process_list_query($query) { global $log; $log->debug("Entering process_list_query(".$query.") method ..."); $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); $list = Array(); $rows_found = $this->db->getRowCount($result); if($rows_found != 0) { $ticket = Array(); for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) { foreach($this->range_fields as $columnName) { if (isset($row[$columnName])) { $ticket[$columnName] = $row[$columnName]; } else { $ticket[$columnName] = ""; } } $list[] = $ticket; } } $response = Array(); $response['list'] = $list; $response['row_count'] = $rows_found; $response['next_offset'] = $next_offset; $response['previous_offset'] = $previous_offset; $log->debug("Exiting process_list_query method ..."); return $response; } /** Function to get the HelpDesk field labels in caps letters without space * @return array $mergeflds - array( key => val ) where key=0,1,2..n & val = ASSIGNEDTO,RELATEDTO, .,etc **/ function getColumnNames_Hd() { global $log,$current_user; $log->debug("Entering getColumnNames_Hd() method ..."); require('user_privileges/user_privileges_'.$current_user->id.'.php'); if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { $sql1 = "select fieldlabel from vtiger_field where tabid=13 and block <> 30 and vtiger_field.uitype <> '61' and vtiger_field.presence in (0,2)"; $params1 = array(); }else { $profileList = getCurrentUserProfileList(); $sql1 = "select vtiger_field.fieldid,fieldlabel from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=13 and vtiger_field.block <> 30 and vtiger_field.uitype <> '61' and vtiger_field.displaytype in (1,2,3,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; $params1 = array(); if (count($profileList) > 0) { $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .") group by fieldid"; array_push($params1, $profileList); } } $result = $this->db->pquery($sql1, $params1); $numRows = $this->db->num_rows($result); for($i=0; $i < $numRows;$i++) { $custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel"); $custom_fields[$i] = preg_replace("/\s+/","",$custom_fields[$i]); $custom_fields[$i] = strtoupper($custom_fields[$i]); } $mergeflds = $custom_fields; $log->debug("Exiting getColumnNames_Hd method ..."); return $mergeflds; } /** Function to get the list of comments for the given ticket id * @param int $ticketid - Ticket id * @return list $list - return the list of comments and comment informations as a html output where as these comments and comments informations will be formed in div tag. **/ function getCommentInformation($ticketid) { global $log; $log->debug("Entering getCommentInformation(".$ticketid.") method ..."); global $adb; global $mod_strings, $default_charset; $sql = "select * from vtiger_ticketcomments where ticketid=?"; $result = $adb->pquery($sql, array($ticketid)); $noofrows = $adb->num_rows($result); //In ajax save we should not add this div if($_REQUEST['action'] != 'HelpDeskAjax') { $list .= '