[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/HelpDesk/ -> HelpDesk.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the
   5   * License. You may obtain a copy of txhe License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  include_once ('config.php');
  16  require_once ('include/logging.php');
  17  require_once ('include/database/PearDatabase.php');
  18  require_once ('data/SugarBean.php');
  19  require_once ('data/CRMEntity.php');
  20  require_once ('include/utils/utils.php');
  21  require_once ('user_privileges/default_module_view.php');
  22  
  23  class HelpDesk extends CRMEntity {
  24      var $log;
  25      var $db;
  26  
  27      var $tab_name = Array('vtiger_crmentity','vtiger_troubletickets','vtiger_ticketcf');
  28      var $tab_name_index = Array('vtiger_crmentity'=>'crmid','vtiger_troubletickets'=>'ticketid','vtiger_seticketsrel'=>'ticketid','vtiger_ticketcf'=>'ticketid','vtiger_ticketcomments'=>'ticketid','vtiger_attachments'=>'attachmentsid');
  29      var $column_fields = Array();
  30  
  31      var $sortby_fields = Array('title','status','priority','crmid','firstname','smownerid');
  32  
  33      var $list_fields = Array(
  34                      'Ticket ID'=>Array('crmentity'=>'crmid'),
  35                      'Subject'=>Array('troubletickets'=>'title'),                  
  36                      'Related to'=>Array('troubletickets'=>'parent_id'),                  
  37                      'Status'=>Array('troubletickets'=>'status'),
  38                      'Priority'=>Array('troubletickets'=>'priority'),
  39                      'Assigned To'=>Array('crmentity','smownerid')
  40                  );
  41  
  42      var $list_fields_name = Array(
  43                      'Ticket ID'=>'',
  44                      'Subject'=>'ticket_title',                  
  45                      'Related to'=>'parent_id',                  
  46                      'Status'=>'ticketstatus',
  47                      'Priority'=>'ticketpriorities',
  48                      'Assigned To'=>'assigned_user_id'
  49                       );
  50  
  51      var $list_link_field= 'ticket_title';
  52              
  53      var $range_fields = Array(
  54                          'ticketid',
  55                      'title',
  56                          'firstname',
  57                          'lastname',
  58                          'parent_id',
  59                          'productid',
  60                          'productname',
  61                          'priority',
  62                          'severity',
  63                          'status',
  64                          'category',
  65                      'description',
  66                      'solution',
  67                      'modifiedtime',
  68                      'createdtime'
  69                  );
  70      var $search_fields = Array(
  71          'Ticket ID' => Array('vtiger_crmentity'=>'crmid'),
  72          'Subject' => Array('vtiger_troubletickets'=>'title')
  73          );
  74      var $search_fields_name = Array(
  75          'Ticket ID' => '',
  76          'Subject'=>'ticket_title',
  77          );
  78  
  79      //Added these variables which are used as default order by and sortorder in ListView
  80      var $default_order_by = 'crmid';
  81      var $default_sort_order = 'DESC';
  82  
  83      /**    Constructor which will set the column_fields in this object
  84       */
  85  	function HelpDesk() 
  86      {
  87          $this->log =LoggerManager::getLogger('helpdesk');
  88          $this->log->debug("Entering HelpDesk() method ...");
  89          $this->db = new PearDatabase();
  90          $this->column_fields = getColumnFields('HelpDesk');
  91          $this->log->debug("Exiting HelpDesk method ...");
  92      }
  93  
  94  
  95  	function save_module($module)
  96      {
  97          //Inserting into Ticket Comment Table
  98          $this->insertIntoTicketCommentTable("vtiger_ticketcomments",'HelpDesk');
  99  
 100          //Inserting into vtiger_seticketsrel table
 101          
 102          if(isset($this->column_fields['parent_id']) && $this->column_fields['parent_id'] != '')
 103          {
 104              $this->insertIntoEntityTable('vtiger_seticketsrel', 'HelpDesk');
 105          }
 106          elseif($this->column_fields['parent_id']=='' && $insertion_mode=="edit")
 107          {
 108              $this->deleteRelation('vtiger_seticketsrel');
 109          }
 110  
 111          //Inserting into vtiger_attachments
 112          $this->insertIntoAttachment($this->id,'HelpDesk');
 113                  
 114      }    
 115  
 116      /** Function to insert values in vtiger_ticketcomments  for the specified tablename and  module
 117          * @param $table_name -- table name:: Type varchar
 118          * @param $module -- module:: Type varchar
 119        */    
 120  	function insertIntoTicketCommentTable($table_name, $module)
 121      {
 122          global $log;
 123          $log->info("in insertIntoTicketCommentTable  ".$table_name."    module is  ".$module);
 124              global $adb;
 125          global $current_user;
 126  
 127              $current_time = $adb->formatDate(date('YmdHis'));
 128          if($this->column_fields['assigned_user_id'] != '')
 129              $ownertype = 'user';
 130          else
 131              $ownertype = 'customer';
 132  
 133          if($this->column_fields['comments'] != '')
 134              $comment = $this->column_fields['comments'];
 135          else
 136              $comment = $_REQUEST['comments'];
 137  
 138          if($comment != '')
 139          {
 140              $comment = addslashes($comment);
 141              $sql = "insert into vtiger_ticketcomments values('',".$this->id.",'".$comment."','".$current_user->id."','".$ownertype."',".$current_time.")";    
 142                  $adb->query($sql);
 143          }
 144      }
 145  
 146  
 147      /**
 148       *      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.
 149       *      @param int $id  - entity id to which the vtiger_files to be uploaded
 150       *      @param string $module  - the current module name
 151      */
 152  	function insertIntoAttachment($id,$module)
 153      {
 154          global $log, $adb;
 155          $log->debug("Entering into insertIntoAttachment($id,$module) method.");
 156          
 157          $file_saved = false;
 158  
 159          foreach($_FILES as $fileindex => $files)
 160          {
 161              if($files['name'] != '' && $files['size'] > 0)
 162              {
 163                  $file_saved = $this->uploadAndSaveFile($id,$module,$files);
 164              }
 165          }
 166  
 167          $log->debug("Exiting from insertIntoAttachment($id,$module) method.");
 168      }
 169      
 170      
 171      /**    Function used to get the sort order for HelpDesk listview
 172       *    @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. 
 173       */
 174  	function getSortOrder()
 175      {
 176          global $log;
 177                  $log->debug("Entering getSortOrder() method ...");    
 178          if(isset($_REQUEST['sorder'])) 
 179              $sorder = $_REQUEST['sorder'];
 180          else
 181              $sorder = (($_SESSION['HELPDESK_SORT_ORDER'] != '')?($_SESSION['HELPDESK_SORT_ORDER']):($this->default_sort_order));
 182          $log->debug("Exiting getSortOrder() method ...");
 183          return $sorder;
 184      }
 185  
 186      /**    Function used to get the order by value for HelpDesk listview
 187       *    @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. 
 188       */
 189  	function getOrderBy()
 190      {
 191          global $log;
 192                  $log->debug("Entering getOrderBy() method ...");
 193          if (isset($_REQUEST['order_by'])) 
 194              $order_by = $_REQUEST['order_by'];
 195          else
 196              $order_by = (($_SESSION['HELPDESK_ORDER_BY'] != '')?($_SESSION['HELPDESK_ORDER_BY']):($this->default_order_by));
 197          $log->debug("Exiting getOrderBy method ...");
 198          return $order_by;
 199      }    
 200  
 201      /**     Function to form the query to get the list of activities
 202           *      @param  int $id - ticket id
 203       *    @return array - return an array which will be returned from the function GetRelatedList
 204          **/
 205  	function get_activities($id)
 206      {
 207          global $log, $singlepane_view;
 208          $log->debug("Entering get_activities(".$id.") method ...");
 209          global $mod_strings;
 210          global $app_strings;
 211          require_once ('modules/Calendar/Activity.php');
 212          $focus = new Activity();
 213  
 214          $button = '';
 215  
 216          if($singlepane_view == 'true')
 217              $returnset = '&return_module=HelpDesk&return_action=DetailView&return_id='.$id;
 218          else
 219              $returnset = '&return_module=HelpDesk&return_action=CallRelatedList&return_id='.$id;
 220  
 221          $query = "SELECT vtiger_activity.*, vtiger_crmentity.crmid, vtiger_recurringevents.recurringtype, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_users.user_name 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 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_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_crmentity.crmid left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname where vtiger_seactivityrel.crmid=".$id." and (activitytype='Task' or activitytype='Call' or activitytype='Meeting') AND ( vtiger_activity.status is NULL OR vtiger_activity.status != 'Completed' ) and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus != 'Held')";
 222          $log->debug("Exiting get_activities method ...");
 223          
 224          return GetRelatedList('HelpDesk','Calendar',$focus,$query,$button,$returnset);
 225      }
 226  
 227      /**     Function to get the Ticket History information as in array format
 228       *    @param int $ticketid - ticket id
 229       *    @return array - return an array with title and the ticket history informations in the following format
 230                              array(    
 231                                  header=>array('0'=>'title'),
 232                                  entries=>array('0'=>'info1','1'=>'info2',etc.,)
 233                                   )
 234       */
 235  	function get_ticket_history($ticketid)
 236      {
 237          global $log, $adb;
 238          $log->debug("Entering into get_ticket_history($ticketid) method ...");
 239  
 240          $query="select title,update_log from vtiger_troubletickets where ticketid=".$ticketid;
 241          $result=$adb->query($query);
 242          $update_log = $adb->query_result($result,0,"update_log");
 243  
 244          $splitval = split('--//--',trim($update_log,'--//--'));
 245  
 246          $header[] = $adb->query_result($result,0,"title");
 247  
 248          $return_value = Array('header'=>$header,'entries'=>$splitval);
 249  
 250          $log->debug("Exiting from get_ticket_history($ticketid) method ...");
 251  
 252          return $return_value;
 253      }
 254  
 255      /**    Function to form the query to get the list of attachments and notes
 256       *    @param  int $id - ticket id
 257           *      @return array - return an array which will be returned from the function getAttachmentsAndNotes
 258      **/
 259  	function get_attachments($id)
 260      {
 261          global $log;
 262          $log->debug("Entering get_attachments(".$id.") method ...");
 263          $query = "select vtiger_notes.title,'Notes      '  ActivityType, vtiger_notes.filename,
 264          vtiger_attachments.type  FileType,crm2.modifiedtime lastmodified,
 265          vtiger_seattachmentsrel.attachmentsid attachmentsid, vtiger_notes.notesid crmid,
 266              crm2.createdtime, vtiger_notes.notecontent description, vtiger_users.user_name
 267          from vtiger_notes
 268              inner join vtiger_senotesrel on vtiger_senotesrel.notesid= vtiger_notes.notesid
 269              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_senotesrel.crmid
 270              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_notes.notesid and crm2.deleted=0
 271              left join vtiger_seattachmentsrel  on vtiger_seattachmentsrel.crmid =vtiger_notes.notesid
 272              left join vtiger_attachments on vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
 273              inner join vtiger_users on crm2.smcreatorid= vtiger_users.id
 274          where vtiger_crmentity.crmid=".$id;
 275  
 276          $query .= ' union all ';
 277  
 278          $query .= "select vtiger_attachments.description title ,'Attachments'  ActivityType,
 279          vtiger_attachments.name filename, vtiger_attachments.type FileType,crm2.modifiedtime lastmodified,
 280          vtiger_attachments.attachmentsid attachmentsid, vtiger_seattachmentsrel.attachmentsid crmid,
 281              crm2.createdtime, vtiger_attachments.description, vtiger_users.user_name
 282          from vtiger_attachments
 283              inner join vtiger_seattachmentsrel on vtiger_seattachmentsrel.attachmentsid= vtiger_attachments.attachmentsid
 284              inner join vtiger_crmentity on vtiger_crmentity.crmid= vtiger_seattachmentsrel.crmid
 285              inner join vtiger_crmentity crm2 on crm2.crmid=vtiger_attachments.attachmentsid
 286              left join vtiger_users on crm2.smcreatorid= vtiger_users.id
 287          where vtiger_crmentity.crmid=".$id;    
 288          $log->debug("Exiting get_attachments method ...");
 289          return getAttachmentsAndNotes('HelpDesk',$query,$id);
 290      }
 291  
 292      /**    Function to get the ticket comments as a array
 293       *    @param  int   $ticketid - ticketid
 294       *    @return array $output - array(    
 295                          [$i][comments]    => comments
 296                          [$i][owner]       => name of the user or customer who made the comment
 297                          [$i][createdtime] => the comment created time
 298                           ) 
 299                  where $i = 0,1,..n which are all made for the ticket
 300      **/
 301  	function get_ticket_comments_list($ticketid)
 302      {
 303          global $log;
 304          $log->debug("Entering get_ticket_comments_list(".$ticketid.") method ...");
 305           $sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid." order by createdtime DESC";
 306           $result = $this->db->query($sql);
 307           $noofrows = $this->db->num_rows($result);
 308           for($i=0;$i<$noofrows;$i++)
 309           {
 310               $ownerid = $this->db->query_result($result,$i,"ownerid");
 311               $ownertype = $this->db->query_result($result,$i,"ownertype");
 312               if($ownertype == 'user')
 313                   $name = getUserName($ownerid);
 314               elseif($ownertype == 'customer')
 315               {
 316                   $sql1 = 'select * from vtiger_portalinfo where id='.$ownerid;
 317                   $name = $this->db->query_result($this->db->query($sql1),0,'user_name');
 318               }
 319  
 320               $output[$i]['comments'] = nl2br($this->db->query_result($result,$i,"comments"));
 321               $output[$i]['owner'] = $name;
 322               $output[$i]['createdtime'] = $this->db->query_result($result,$i,"createdtime");
 323           }
 324          $log->debug("Exiting get_ticket_comments_list method ...");
 325           return $output;
 326       }
 327          
 328      /**    Function to form the query which will give the list of tickets based on customername and id ie., contactname and contactid
 329       *    @param  string $user_name - name of the customer ie., contact name
 330       *    @param  int    $id     - contact id 
 331       *     @return array  - return an array which will be returned from the function process_list_query
 332      **/
 333  	function get_user_tickets_list($user_name,$id,$where='',$match='')
 334      {
 335          global $log;
 336          $log->debug("Entering get_user_tickets_list(".$user_name.",".$id.",".$where.",".$match.") method ...");
 337  
 338          $this->db->println("where ==> ".$where);
 339  
 340          $query = "select vtiger_crmentity.crmid, vtiger_troubletickets.*, vtiger_crmentity.smownerid, vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_products.productid, vtiger_products.productname, vtiger_ticketcf.* from vtiger_troubletickets inner join vtiger_ticketcf on vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.ticketid left join vtiger_contactdetails on vtiger_troubletickets.parent_id=vtiger_contactdetails.contactid left join vtiger_products on vtiger_products.productid = vtiger_troubletickets.product_id left join vtiger_users on vtiger_crmentity.smownerid=vtiger_users.id  where vtiger_crmentity.deleted=0 and vtiger_contactdetails.email='".$user_name."' and vtiger_troubletickets.parent_id = '".$id."'";
 341  
 342          if(trim($where) != '')
 343          {
 344              if($match == 'all' || $match == '')
 345              {
 346                  $join = " and ";
 347              }
 348              elseif($match == 'any')
 349              {
 350                  $join = " or ";
 351              }
 352              $where = explode("&&&",$where);
 353              $count = count($where);
 354              $count --;
 355              $where_conditions = "";
 356              foreach($where as $key => $value)
 357              {
 358                  $this->db->println('key : '.$key.'...........value : '.$value);
 359                  $val = explode(" = ",$value);
 360                  $this->db->println('val0 : '.$val[0].'...........val1 : '.$val[1]);
 361                  if($val[0] == 'vtiger_troubletickets.title')
 362                  {
 363                      $where_conditions .= $val[0]."  ".$val[1];
 364                      if($count != $key)     $where_conditions .= $join;
 365                  }
 366                  elseif($val[1] != '' && $val[1] != 'Any')
 367                  {
 368                      $where_conditions .= $val[0]." = ".$val[1];
 369                      if($count != $key)    $where_conditions .= $join;
 370                  }
 371              }
 372              if($where_conditions != '')
 373                  $where_conditions = " and ( ".$where_conditions." ) ";
 374  
 375              $query .= $where_conditions;
 376              $this->db->println("where condition for customer portal tickets search : ".$where_conditions);
 377          }
 378  
 379          $query .= " order by vtiger_crmentity.crmid desc";
 380          $log->debug("Exiting get_user_tickets_list method ...");
 381          return $this->process_list_query($query);
 382      }
 383  
 384      /**    Function to process the list query and return the result with number of rows
 385       *    @param  string $query - query 
 386       *    @return array  $response - array(    list           => array(   
 387                                              $i => array(key => val)   
 388                                             ),
 389                              row_count      => '',
 390                              next_offset    => '',
 391                              previous_offset    =>''         
 392                          )
 393          where $i=0,1,..n & key = ticketid, title, firstname, ..etc(range_fields) & val = value of the key from db retrieved row 
 394      **/
 395  	function process_list_query($query)
 396      {
 397          global $log;
 398          $log->debug("Entering process_list_query(".$query.") method ...");
 399        
 400             $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: ");
 401          $list = Array();
 402              $rows_found =  $this->db->getRowCount($result);
 403              if($rows_found != 0)
 404              {
 405              $ticket = Array();
 406              for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index))
 407              {
 408                          foreach($this->range_fields as $columnName)
 409                          {
 410                              if (isset($row[$columnName])) 
 411                      {
 412                                  $ticket[$columnName] = $row[$columnName];
 413                                  }
 414                                     else     
 415                          {   
 416                                      $ticket[$columnName] = "";
 417                              }   
 418                       }    
 419                              $list[] = $ticket;
 420                      }
 421              }   
 422  
 423          $response = Array();
 424              $response['list'] = $list;
 425              $response['row_count'] = $rows_found;
 426              $response['next_offset'] = $next_offset;
 427              $response['previous_offset'] = $previous_offset;
 428  
 429          $log->debug("Exiting process_list_query method ...");
 430              return $response;
 431      }
 432  
 433      /**    Function to get the HelpDesk field labels in caps letters without space
 434       *    @return array $mergeflds - array(    key => val    )    where   key=0,1,2..n & val = ASSIGNEDTO,RELATEDTO, .,etc
 435      **/
 436  	function getColumnNames_Hd()
 437      {
 438          global $log,$current_user;
 439          $log->debug("Entering getColumnNames_Hd() method ...");
 440          require('user_privileges/user_privileges_'.$current_user->id.'.php');
 441          if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0)
 442          {
 443              $sql1 = "select fieldlabel from vtiger_field where tabid=13 and block <> 30 ";
 444          }else
 445          {
 446              $profileList = getCurrentUserProfileList();
 447              $sql1 = "select 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.displaytype in (1,2,4) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_profile2field.profileid in ".$profileList;
 448          }
 449          $result = $this->db->query($sql1);
 450          $numRows = $this->db->num_rows($result);
 451          for($i=0; $i < $numRows;$i++)
 452          {
 453              $custom_fields[$i] = $this->db->query_result($result,$i,"fieldlabel");
 454              $custom_fields[$i] = ereg_replace(" ","",$custom_fields[$i]);
 455              $custom_fields[$i] = strtoupper($custom_fields[$i]);
 456          }
 457          $mergeflds = $custom_fields;
 458          $log->debug("Exiting getColumnNames_Hd method ...");
 459          return $mergeflds;
 460      }
 461  
 462      /**     Function to get the list of comments for the given ticket id
 463       *      @param  int  $ticketid - Ticket id
 464       *      @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.
 465      **/
 466  	function getCommentInformation($ticketid)
 467      {
 468          global $log;
 469          $log->debug("Entering getCommentInformation(".$ticketid.") method ...");
 470          global $adb;
 471          global $mod_strings;
 472          $sql = "select * from vtiger_ticketcomments where ticketid=".$ticketid;
 473          $result = $adb->query($sql);
 474          $noofrows = $adb->num_rows($result);
 475  
 476          if($noofrows == 0)
 477          {
 478              $log->debug("Exiting getCommentInformation method ...");
 479              return '';
 480          }
 481  
 482          $list .= '<div style="overflow: auto;height:200px;width:100%;">';
 483          for($i=0;$i<$noofrows;$i++)
 484          {
 485              if($adb->query_result($result,$i,'comments') != '')
 486              {
 487                  //this div is to display the comment
 488                  $list .= '<div valign="top" style="width:99%;padding-top:10px;" class="dataField">';
 489                  $list .= make_clickable(nl2br($adb->query_result($result,$i,'comments')));
 490  
 491                  $list .= '</div>';
 492  
 493                  //this div is to display the author and time
 494                  $list .= '<div valign="top" style="width:99%;border-bottom:1px dotted #CCCCCC;padding-bottom:5px;" class="dataLabel"><font color=darkred>';
 495                  $list .= $mod_strings['LBL_AUTHOR'].' : ';
 496  
 497                  if($adb->query_result($result,$i,'ownertype') == 'user')
 498                      $list .= getUserName($adb->query_result($result,$i,'ownerid'));
 499                  else
 500                      $list .= $this->getCustomerName($ticketid);
 501  
 502                  $list .= ' on '.$adb->query_result($result,$i,'createdtime').' &nbsp;';
 503  
 504                  $list .= '</font></div>';
 505              }
 506          }
 507          $list .= '</div>';
 508  
 509          $log->debug("Exiting getCommentInformation method ...");
 510          return $list;
 511      }
 512  
 513      /**     Function to get the Customer Name who has made comment to the ticket from the customer portal
 514       *      @param  int    $id   - Ticket id
 515       *      @return string $customername - The contact name
 516      **/
 517  	function getCustomerName($id)
 518      {
 519          global $log;
 520          $log->debug("Entering getCustomerName(".$id.") method ...");
 521              global $adb;
 522              $sql = "select * from vtiger_portalinfo inner join vtiger_troubletickets on vtiger_troubletickets.parent_id = vtiger_portalinfo.id where vtiger_troubletickets.ticketid=".$id;
 523              $result = $adb->query($sql);
 524              $customername = $adb->query_result($result,0,'user_name');
 525          $log->debug("Exiting getCustomerName method ...");
 526              return $customername;
 527      }
 528      
 529      /**    Function used to get the Activity History
 530       *    @param    int    $id - ticket id to which we want to display the activity history
 531       *    @return  array    - return an array which will be returned from the function getHistory
 532       */
 533  	function get_history($id)
 534      {
 535          global $log;
 536          $log->debug("Entering get_history(".$id.") method ...");
 537          $query = "SELECT vtiger_activity.activityid, vtiger_activity.subject, vtiger_activity.status, vtiger_activity.eventstatus, vtiger_activity.date_start, vtiger_activity.due_date,
 538          vtiger_activity.activitytype, vtiger_troubletickets.ticketid, vtiger_troubletickets.title, vtiger_crmentity.modifiedtime,
 539          vtiger_crmentity.createdtime, vtiger_crmentity.description, vtiger_users.user_name
 540                  from vtiger_activity
 541                  inner join vtiger_seactivityrel on vtiger_seactivityrel.activityid= vtiger_activity.activityid
 542                  inner join vtiger_troubletickets on vtiger_troubletickets.ticketid = vtiger_seactivityrel.crmid
 543                  inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid
 544                  left join vtiger_activitygrouprelation on vtiger_activitygrouprelation.activityid=vtiger_activity.activityid
 545                                  left join vtiger_groups on vtiger_groups.groupname=vtiger_activitygrouprelation.groupname
 546                  inner join vtiger_users on vtiger_crmentity.smcreatorid= vtiger_users.id
 547                  where (vtiger_activity.activitytype = 'Meeting' or vtiger_activity.activitytype='Call' or vtiger_activity.activitytype='Task')
 548                  and (vtiger_activity.status = 'Completed' or vtiger_activity.status = 'Deferred' or (vtiger_activity.eventstatus = 'Held' and vtiger_activity.eventstatus != ''))
 549                  and vtiger_seactivityrel.crmid=".$id;
 550          //Don't add order by, because, for security, one more condition will be added with this query in include/RelatedListView.php
 551          $log->debug("Entering get_history method ...");
 552          return getHistory('HelpDesk',$query,$id);
 553      }
 554  
 555      /** Function to get the update ticket history for the specified ticketid
 556        * @param $id -- $ticketid:: Type Integer 
 557       */    
 558  	function constructUpdateLog($focus, $mode, $assigned_group_name, $assigntype)
 559      {
 560          global $adb;
 561          global $current_user;
 562  
 563          if($mode != 'edit')//this will be updated when we create new ticket
 564          {
 565              $updatelog = " Ticket created. Assigned to ";
 566  
 567              if($assigned_group_name != '' && $assigntype == 'T')
 568              {
 569                  $updatelog .= " group ".$assigned_group_name;
 570              }
 571              elseif($focus->column_fields['assigned_user_id'] != '')
 572              {
 573                  $updatelog .= " user ".getUserName($focus->column_fields['assigned_user_id']);
 574              }
 575              else
 576              {
 577                  $updatelog .= " user ".getUserName($current_user->id);
 578              }
 579  
 580              $fldvalue = date("l dS F Y h:i:s A").' by '.$current_user->user_name;
 581              $updatelog .= " -- ".$fldvalue."--//--";
 582          }
 583          else
 584          {
 585              $ticketid = $focus->id;
 586  
 587              //First retrieve the existing information
 588              $tktresult = $adb->query("select * from vtiger_troubletickets where ticketid='".$ticketid."'");
 589              $crmresult = $adb->query("select * from vtiger_crmentity where crmid='".$ticketid."'");
 590  
 591              $updatelog = $adb->query_result($tktresult,0,"update_log");
 592  
 593              $old_user_id = $adb->query_result($crmresult,0,"smownerid");
 594              $old_status = $adb->query_result($tktresult,0,"status");
 595              $old_priority = $adb->query_result($tktresult,0,"priority");
 596              $old_severity = $adb->query_result($tktresult,0,"severity");
 597              $old_category = $adb->query_result($tktresult,0,"category");
 598  
 599              //Assigned to change log
 600              if($assigned_group_name != '' && $assigntype == 'T')
 601              {
 602                  $group_info = getGroupName($ticketid,'HelpDesk');
 603                  $group_name = $group_info[0];
 604                  if($group_name != $assigned_group_name)
 605                      $updatelog .= ' Transferred to group '.$assigned_group_name.'\.';
 606              }
 607              elseif($focus->column_fields['assigned_user_id'] != $old_user_id)
 608              {
 609                  $user_name = getUserName($focus->column_fields['assigned_user_id']);
 610                  $updatelog .= ' Transferred to user '.$user_name.'\.';
 611              }
 612              //Status change log
 613              if($old_status != $focus->column_fields['ticketstatus'])
 614              {
 615                  $updatelog .= ' Status Changed to '.$focus->column_fields['ticketstatus'].'\.';
 616              }
 617              //Priority change log
 618              if($old_priority != $focus->column_fields['ticketpriorities'])
 619              {
 620                  $updatelog .= ' Priority Changed to '.$focus->column_fields['ticketpriorities'].'\.';
 621              }
 622              //Severity change log
 623              if($old_severity != $focus->column_fields['ticketseverities'])
 624              {
 625                  $updatelog .= ' Severity Changed to '.$focus->column_fields['ticketseverities'].'\.';
 626              }
 627              //Category change log
 628              if($old_category != $focus->column_fields['ticketcategories'])
 629              {
 630                  $updatelog .= ' Category Changed to '.$focus->column_fields['ticketcategories'].'\.';
 631              }
 632  
 633              $updatelog .= ' -- '.date("l dS F Y h:i:s A").' by '.$current_user->user_name.'--//--';
 634          }
 635          return $updatelog;
 636      }
 637  
 638  
 639  
 640  }
 641  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7