fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [6733] new app: helpdesk


From: Sigurd Nes
Subject: [Fmsystem-commits] [6733] new app: helpdesk
Date: Fri, 07 Jan 2011 08:00:04 +0000

Revision: 6733
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6733
Author:   sigurdne
Date:     2011-01-07 07:59:59 +0000 (Fri, 07 Jan 2011)
Log Message:
-----------
new app: helpdesk

Added Paths:
-----------
    trunk/helpdesk/
    trunk/helpdesk/inc/
    trunk/helpdesk/inc/class.botts.inc.php
    trunk/helpdesk/inc/class.cat_hooks.inc.php
    trunk/helpdesk/inc/class.menu.inc.php
    trunk/helpdesk/inc/class.sotts.inc.php
    trunk/helpdesk/inc/class.uitts.inc.php
    trunk/helpdesk/inc/hook_config.inc.php
    trunk/helpdesk/index.php
    trunk/helpdesk/js/
    trunk/helpdesk/js/yahoo/
    trunk/helpdesk/js/yahoo/tts.add.js
    trunk/helpdesk/js/yahoo/tts.index.js
    trunk/helpdesk/js/yahoo/tts.view.js
    trunk/helpdesk/setup/
    trunk/helpdesk/setup/default_records.inc.php
    trunk/helpdesk/setup/setup.inc.php
    trunk/helpdesk/setup/tables_current.inc.php
    trunk/helpdesk/templates/
    trunk/helpdesk/templates/base/
    trunk/helpdesk/templates/base/app_data.xsl
    trunk/helpdesk/templates/base/columns.xsl
    trunk/helpdesk/templates/base/config.tpl
    trunk/helpdesk/templates/base/files.xsl
    trunk/helpdesk/templates/base/tts.xsl
    trunk/helpdesk/templates/default/
    trunk/helpdesk/templates/portico/
    trunk/helpdesk/templates/portico/css/
    trunk/helpdesk/templates/portico/css/base.css

Added: trunk/helpdesk/inc/class.botts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.botts.inc.php                              (rev 0)
+++ trunk/helpdesk/inc/class.botts.inc.php      2011-01-07 07:59:59 UTC (rev 
6733)
@@ -0,0 +1,979 @@
+<?php
+       /**
+       * phpGroupWare - helpdesk: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package helpdesk
+       * @subpackage helpdesk
+       * @version $Id: class.botts.inc.php 6728 2011-01-04 13:20:59Z sigurdne $
+       */
+
+       /**
+        * Description
+        * @package helpdesk
+        */
+
+       class helpdesk_botts
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+               var $acl_location;
+               var $uicols_related = array();
+               var $start_date;
+               var $end_date;
+               var $fields_updated = false;
+               var $status_id;
+               var $user_id;
+               var $part_of_town_id;
+               var $district_id;
+               var $total_records;
+
+               var $public_functions = array
+                       (
+                               'read'                  => true,
+                               'read_single'   => true,
+                               'save'                  => true,
+                       );
+
+               function helpdesk_botts($session=false)
+               {
+                       $this->so                                       = 
CreateObject('helpdesk.sotts');
+                       $this->bocommon                         = 
CreateObject('property.bocommon');
+                       $this->historylog                       = & 
$this->so->historylog;
+                       $this->config                           = 
CreateObject('phpgwapi.config','helpdesk');
+                       $this->dateformat                       = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $this->cats                                     = 
CreateObject('phpgwapi.categories', -1, 'helpdesk', '.ticket');
+                       $this->cats->supress_info       = true;
+                       $this->acl_location                     = 
$this->so->acl_location;
+
+                       $this->config->read();
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = true;
+                       }
+
+                       $start                                  = 
phpgw::get_var('start', 'int', 'REQUEST', 0);
+                       $query                                  = 
phpgw::get_var('query');
+                       $sort                                   = 
phpgw::get_var('sort');
+                       $order                                  = 
phpgw::get_var('order');
+                       $status_id                              = 
phpgw::get_var('status_id', 'string');
+                       $user_id                                = 
phpgw::get_var('user_id', 'int');
+                       $cat_id                                 = 
phpgw::get_var('cat_id', 'int');
+                       $part_of_town_id                = 
phpgw::get_var('part_of_town_id', 'int');
+                       $district_id                    = 
phpgw::get_var('district_id', 'int');
+                       $allrows                                = 
phpgw::get_var('allrows', 'bool');
+                       $start_date                             = 
phpgw::get_var('start_date', 'string');
+                       $end_date                               = 
phpgw::get_var('end_date', 'string');
+                       $location_code                  = 
phpgw::get_var('location_code');
+
+
+                       $this->start                    = $start                
                                        ? $start                        : 0;
+                       $this->query                    = 
isset($_REQUEST['query'])             ? $query                        : 
$this->query;
+                       $this->sort                             = 
isset($_REQUEST['sort'])                      ? $sort                         : 
$this->sort;
+                       $this->order                    = 
isset($_REQUEST['order'])             ? $order                        : 
$this->order;
+                       $this->cat_id                   = 
isset($_REQUEST['cat_id'])            ? $cat_id                       :  
$this->cat_id;
+                       $this->status_id                = 
isset($_REQUEST['status_id'])         ? $status_id            : 
$this->status_id;
+                       $this->user_id                  = 
isset($_REQUEST['user_id'])           ? $user_id                      : 
$this->user_id;;
+                       $this->part_of_town_id  = 
isset($_REQUEST['part_of_town_id'])? $part_of_town_id : $this->part_of_town_id;
+                       $this->district_id              = 
isset($_REQUEST['district_id'])       ? $district_id          : 
$this->district_id;
+                       $this->allrows                  = isset($allrows) && 
$allrows           ? $allrows                      : '';
+                       $this->start_date               = 
isset($_REQUEST['start_date'])        ? $start_date           : 
$this->start_date;
+                       $this->end_date                 = 
isset($_REQUEST['end_date'])          ? $end_date                     : 
$this->end_date;
+                       $this->location_code    = isset($location_code) && 
$location_code ? $location_code : '';
+
+                       $this->p_num                    = 
phpgw::get_var('p_num');
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts');
+
+                       $this->start            = 
isset($data['start'])?$data['start']:'';
+                       $this->query            = 
isset($data['query'])?$data['query']:'';
+                       $this->user_id          = 
isset($data['user_id'])?$data['user_id']:'';
+                       $this->sort                     = 
isset($data['sort'])?$data['sort']:'';
+                       $this->order            = 
isset($data['order'])?$data['order']:'';
+                       $this->status_id        = 
isset($data['status_id'])?$data['status_id']:'';
+                       $this->cat_id           = 
isset($data['cat_id'])?$data['cat_id']:'';
+                       $this->district_id      = 
isset($data['district_id'])?$data['district_id']:'';
+                       $this->allrows          = 
isset($data['allrows'])?$data['allrows']:'';
+                       $this->start_date       = 
isset($data['start_date'])?$data['start_date']:'';
+                       $this->end_date         = 
isset($data['end_date'])?$data['end_date']:'';
+               }
+
+               function column_list($selected = 
array(),$type_id='',$allrows='')
+               {
+                       if(!$selected)
+                       {
+                               $selected = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] 
: '';
+                       }
+                       $filter = array('list' => ''); // translates to "list 
IS NULL"
+                       $columns = array();
+                       $columns[] = array
+                               (
+                                       'id' => 'billable_hours',
+                                       'name'=> lang('billable hours')
+                               );
+                       $columns[] = array
+                               (
+                                       'id' => 'district',
+                                       'name'=> lang('district')
+                               );
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+                       return $column_list;
+               }
+
+               function filter($data=0)
+               {
+                       if(is_array($data))
+                       {
+                               $format = 
(isset($data['format'])?$data['format']:'');
+                               $selected = 
(isset($data['filter'])?$data['filter']:$data['default']);
+                       }
+
+                       switch($format)
+                       {
+                       case 'select':
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_select'));
+                               break;
+                       case 'filter':
+                               
$GLOBALS['phpgw']->xslttpl->add_file(array('filter_filter'));
+                               break;
+                       }
+
+                       $_filters[0]['id']='all';
+                       $_filters[0]['name']=lang('All');
+
+                       $filters = $this->_get_status_list(true);
+
+                       $filters = array_merge($_filters,$filters);
+
+                       return $this->bocommon->select_list($selected,$filters);
+               }
+
+               function get_status_list($selected)
+               {
+                       $status = $this->_get_status_list();
+                       return $this->bocommon->select_list($selected,$status);
+               }
+
+               function _get_status_list($leave_out_open = '')
+               {
+                       $i = 0;
+                       $status[$i]['id']='X';
+                       $status[$i]['name']=lang('Closed');
+                       $i++;
+
+                       if(!$leave_out_open)
+                       {
+                               $status[$i]['id']='O';
+                               $status[$i]['name']= 
isset($this->config->config_data['tts_lang_open']) && 
$this->config->config_data['tts_lang_open'] ? 
$this->config->config_data['tts_lang_open'] : lang('Open');
+                               $i++;
+                       }
+
+                       $custom_status  = $this->so->get_custom_status();
+                       foreach($custom_status as $custom)
+                       {
+                               $status[$i] = array
+                                       (
+                                               'id'                    => 
"C{$custom['id']}",
+                                               'name'                  => 
$custom['name']
+                                       );
+                               $i++;
+                       }
+
+                       return $status;
+               }
+
+               function get_status_text()
+               {
+                       $status_text = array(
+                               'R' => lang('Re-opened'),
+                               'X' => lang('Closed'),
+                               'O' => lang('Opened'),
+                               'A' => lang('Re-assigned'),
+                               'G' => lang('Re-assigned group'),
+                               'P' => lang('Priority changed'),
+                               'T' => lang('Category changed'),
+                               'S' => lang('Subject changed'),
+                               'B' => lang('Billing rate'),
+                               'H' => lang('Billing hours'),
+                               'F' => lang('finnish date'),
+                               'SC' => lang('Status changed'),
+                               'M' => lang('Sent by email to'),
+                               'AC'=> lang('actual cost changed'),
+                       );
+
+                       $custom_status  = $this->so->get_custom_status();
+                       foreach($custom_status as $custom)
+                       {
+                               $status_text["C{$custom['id']}"] = 
$custom['name'];
+                       }
+
+                       return $status_text;
+               }
+
+
+               function get_priority_list($selected='')
+               {
+
+                       $prioritylevels = 
isset($this->config->config_data['prioritylevels']) && 
$this->config->config_data['prioritylevels'] ? 
$this->config->config_data['prioritylevels'] : 3;
+
+                       if(!$selected)
+                       {
+                               $selected = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['prioritydefault'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['prioritydefault'] 
: $prioritylevels;
+                       }
+
+                       $priority_comment[$prioritylevels]=' - '.lang('Lowest');
+                       //                      $priority_comment[2]=' - 
'.lang('Medium');
+                       $priority_comment[1]=' - '.lang('Highest');
+
+                       $priorities = array();
+                       for ($i=1; $i<= $prioritylevels; $i++)
+                       {
+                               $priorities[$i]['id'] =$i;
+                               $priorities[$i]['name'] =$i . 
(isset($priority_comment[$i])?$priority_comment[$i]:'');
+                       }
+
+                       return 
$this->bocommon->select_list($selected,$priorities);
+               }
+
+               function get_category_name($cat_id)
+               {
+                       $category = $this->cats->return_single($cat_id);
+                       return $category[0]['name'];
+               }
+
+
+               function get_origin_entity_type()
+               {
+                       $related = $this->so->get_origin_entity_type();
+                       $this->uicols_related = $this->so->uicols_related;
+                       return $related;
+               }
+
+               function read($start_date='', $end_date='', $dry_run = '', 
$download = '')
+               {
+                       static $category_name = array();
+                       static $account = array();
+                       static $vendor_cache = array();
+
+                       $interlink      = CreateObject('property.interlink');
+                       $start_date     = 
$this->bocommon->date_to_timestamp($start_date);
+                       $end_date       = 
$this->bocommon->date_to_timestamp($end_date);
+
+                       $tickets = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                               'status_id' => $this->status_id,'cat_id' => 
$this->cat_id,'district_id' => $this->district_id,
+                               'start_date'=>$start_date,'end_date'=>$end_date,
+                               'allrows'=>$this->allrows,'user_id' => 
$this->user_id, 'dry_run' => $dry_run,
+                               'location_code' => $this->location_code, 
'p_num' => $this->p_num));
+
+                       $this->total_records = $this->so->total_records;
+                       $entity = $this->get_origin_entity_type();
+                       $contacts       = CreateObject('property.sogeneric');
+                       $contacts->get_location_info('vendor',false);
+
+                       $custom                 = 
createObject('property.custom_fields');
+                       $vendor_data['attributes'] = 
$custom->find('helpdesk','.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+
+                       foreach ($tickets as & $ticket)
+                       {
+                               if(!isset($category_name[$ticket['cat_id']]))
+                               {
+                                       $category_name[$ticket['cat_id']] = 
$this->get_category_name($ticket['cat_id']);
+                               }
+
+                               $ticket['category']     = 
$category_name[$ticket['cat_id']];
+
+                               if(!$ticket['subject'])
+                               {
+                                       $ticket['subject'] = 
$category_name[$ticket['cat_id']];
+                               }
+
+                               if(!isset($account[$ticket['user_id']]))
+                               {
+                                       $ticket['user'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                                       $account[$ticket['user_id']] = 
$ticket['user'];
+                               }
+                               else
+                               {
+                                       $ticket['user'] = 
$account[$ticket['user_id']];
+                               }
+
+                               if($ticket['assignedto'])
+                               {
+                                       
if(!isset($account[$ticket['assignedto']]))
+                                       {
+                                               $ticket['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
+                                               $account[$ticket['assignedto']] 
= $ticket['assignedto'];
+                                       }
+                                       else
+                                       {
+                                               $ticket['assignedto'] = 
$account[$ticket['assignedto']];
+                                       }
+                               }
+                               else
+                               {
+                                       
if(!isset($account[$ticket['group_id']]))
+                                       {
+                                               $ticket['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+                                               $account[$ticket['group_id']] = 
$ticket['assignedto'];
+                                       }
+                                       else
+                                       {
+                                               $ticket['assignedto'] = 
$account[$ticket['group_id']];
+                                       }
+                               }
+
+                               $ticket['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['entry_date'],$this->dateformat);
+
+                               if($ticket['finnish_date2'])
+                               {
+                                       $ticket['delay'] = 
round(($ticket['finnish_date2']-$ticket['finnish_date'])/(24*3600));
+                                       
$ticket['finnish_date']=$ticket['finnish_date2'];
+                               }
+                               $ticket['finnish_date'] = 
(isset($ticket['finnish_date']) && $ticket['finnish_date'] ? 
$GLOBALS['phpgw']->common->show_date($ticket['finnish_date'],$this->dateformat):'');
+
+                               if ($ticket['status'] == 'X')
+                               {
+                                       $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$ticket['id']);
+                                       $ticket['timestampclosed'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                               }
+                               if ($ticket['new_ticket'])
+                               {
+                                       $ticket['new_ticket'] = '*';
+                               }
+
+                               if(isset($entity) && is_array($entity))
+                               {
+                                       for ($j=0;$j<count($entity);$j++)
+                                       {
+                                               $ticket['child_date'][$j] = 
$interlink->get_child_date('helpdesk', '.ticket', $entity[$j]['type'], 
$ticket['id'], 
isset($entity[$j]['entity_id'])?$entity[$j]['entity_id']:'',isset($entity[$j]['cat_id'])?$entity[$j]['cat_id']:'');
+                                               
if($ticket['child_date'][$j]['date_info'] && !$download)
+                                               {
+                                                       
$ticket['child_date'][$j]['statustext'] = 
$interlink->get_relation_info(array('location' => $entity[$j]['type']), 
$ticket['child_date'][$j]['date_info'][0]['target_id']);
+                                               }
+                                       }
+                               }
+                               if( $ticket['vendor_id'])
+                               {
+                                       
if(isset($vendor_cache[$ticket['vendor_id']]))
+                                       {
+                                               $ticket['vendor'] = 
$vendor_cache[$ticket['vendor_id']];
+                                       }
+                                       else
+                                       {
+                                               $vendor_data    = 
$contacts->read_single(array('id' => $ticket['vendor_id']),$vendor_data);
+                                               if($vendor_data)
+                                               {
+                                                       
foreach($vendor_data['attributes'] as $attribute)
+                                                       {
+                                                               
if($attribute['name']=='org_name')
+                                                               {
+                                                                       
$vendor_cache[$ticket['vendor_id']]=$attribute['value'];
+                                                                       
$ticket['vendor'] = $attribute['value'];
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
+                       return $tickets;
+               }
+
+               function read_single($id)
+               {
+                       $this->so->update_view($id);
+
+                       $ticket = $this->so->read_single($id);
+
+                       $ticket['user_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                       $ticket['group_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+
+                       $interlink      = CreateObject('property.interlink');
+                       $ticket['origin'] = 
$interlink->get_relation('helpdesk', '.ticket', $id, 'origin');
+                       $ticket['target'] = 
$interlink->get_relation('helpdesk', '.ticket', $id, 'target');
+                       //_debug_array($ticket);
+                       if(isset($ticket['finnish_date2']) && 
$ticket['finnish_date2'])
+                       {
+                               
$ticket['finnish_date']=$ticket['finnish_date2'];
+                       }
+
+                       if($ticket['finnish_date'])
+                       {
+                               $ticket['finnish_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['finnish_date'],$this->dateformat);
+                       }
+
+                       if($ticket['location_code'])
+                       {
+                               $solocation     = 
CreateObject('helpdesk.solocation');
+                               $ticket['location_data'] = 
$solocation->read_single($ticket['location_code']);
+                       }
+                       //_debug_array($ticket['location_data']);
+                       if($ticket['p_num'])
+                       {
+                               $soadmin_entity = 
CreateObject('helpdesk.soadmin_entity');
+                               $category = 
$soadmin_entity->read_single_category($ticket['p_entity_id'],$ticket['p_cat_id']);
+
+                               
$ticket['p'][$ticket['p_entity_id']]['p_num']=$ticket['p_num'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_entity_id']=$ticket['p_entity_id'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_id']=$ticket['p_cat_id'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+
+                       if($ticket['tenant_id']>0)
+                       {
+                               
$tenant_data=$this->bocommon->read_single_tenant($ticket['tenant_id']);
+                               $ticket['location_data']['tenant_id']= 
$ticket['tenant_id'];
+                               $ticket['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
+                               $ticket['location_data']['last_name']   = 
$tenant_data['last_name'];
+                               $ticket['location_data']['first_name']  = 
$tenant_data['first_name'];
+                       }
+                       else
+                       {
+                               unset($ticket['location_data']['tenant_id']);
+                               
unset($ticket['location_data']['contact_phone']);
+                               unset($ticket['location_data']['last_name']);
+                               unset($ticket['location_data']['first_name']);
+                       }
+
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
+                       $ticket['timestamp'] = $history_values[0]['datetime'];
+                       $ticket['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       // Figure out when it was opened and last closed
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','ASC',$id);
+                       $ticket['last_opened'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime']);
+
+                       if($ticket['status']=='X')
+                       {
+
+                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
+                               $ticket['timestampclosed']= 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       }
+
+                       $status_text = $this->get_status_text();
+
+                       $ticket['status_name'] = 
$status_text[$ticket['status']];
+                       
$ticket['user_lid']=$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                       
$ticket['category_name']=ucfirst($this->get_category_name($ticket['cat_id']));
+
+                       $vfs = CreateObject('phpgwapi.vfs');
+                       $vfs->override_acl = 1;
+
+                       $ticket['files'] = $vfs->ls (array(
+                               'string' => "/helpdesk/{$id}",
+                               'relatives' => array(RELATIVE_NONE)));
+
+                       $vfs->override_acl = 0;
+
+                       $j      = count($ticket['files']);
+                       for ($i=0;$i<$j;$i++)
+                       {
+                               
$ticket['files'][$i]['file_name']=urlencode($ticket['files'][$i]['name']);
+                       }
+
+                       if(!isset($ticket['files'][0]['file_id']) || 
!$ticket['files'][0]['file_id'])
+                       {
+                               unset($ticket['files']);
+                       }
+                       return $ticket;
+               }
+
+               function read_additional_notes($id)
+               {
+                       $additional_notes = array();
+                       $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
+
+                       $i=2;
+                       foreach ($history_array as $value)
+                       {
+                               $additional_notes[] = array
+                                       (
+                                               'value_id'              => 
$value['id'],
+                                               'value_count'   => $i,
+                                               'value_date'    => 
$GLOBALS['phpgw']->common->show_date($value['datetime']),
+                                               'value_user'    => 
$value['owner'],
+                                               'value_note'    => 
stripslashes($value['new_value']),
+                                               'value_publish' => 
$value['publish'],
+                                       );
+                               $i++;
+                       }
+                       return $additional_notes;
+               }
+
+
+               function read_record_history($id)
+               {
+                       $history_array = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
+
+                       $status_text = $this->get_status_text();
+                       $record_history = array();
+                       $i=0;
+
+                       foreach ($history_array as $value)
+                       {
+                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
+                               $record_history[$i]['value_user']       = 
$value['owner'];
+
+                               switch ($value['status'])
+                               {
+                               case 'R': $type = lang('Re-opened'); break;
+                               case 'X': $type = lang('Closed');    break;
+                               case 'O': $type = lang('Opened');    break;
+                               case 'A': $type = lang('Re-assigned'); break;
+                               case 'G': $type = lang('Re-assigned group'); 
break;
+                               case 'P': $type = lang('Priority changed'); 
break;
+                               case 'T': $type = lang('Category changed'); 
break;
+                               case 'S': $type = lang('Subject changed'); 
break;
+                               case 'H': $type = lang('Billable hours 
changed'); break;
+                               case 'B': $type = lang('Budget changed'); break;
+//                             case 'B': $type = lang('Billable rate 
changed'); break;
+                               case 'F': $type = lang('finnish date changed'); 
break;
+                               case 'IF': $type = lang('Initial finnish 
date'); break;
+                               case 'L': $type = lang('Location changed'); 
break;
+                               case 'AC': $type = lang('actual cost changed'); 
break;
+                               case 'M':
+                                       $type = lang('Sent by email to');
+                                       $this->order_sent_adress = 
$value['new_value']; // in case we want to resend the order as an reminder
+                                       break;
+                               default:
+                                       // nothing
+                               }
+
+               //              if ( $value['status'] == 'X' || 
$value['status'] == 'R' || (strlen($value['status']) == 2 && 
substr($value['new_value'], 0, 1) == 'C') ) // if custom status
+                               if ( $value['status'] == 'X' || 
$value['status'] == 'R' || preg_match('/^C/i', $value['status']) || ( 
$value['status'] == 'R' && preg_match('/^C/i', $value['new_value']))) // if 
custom status
+                               {
+                                       switch ($value['status'])
+                                       {
+                                       case 'R': 
+                                               $type = lang('Re-opened');
+                                               break;
+                                       case 'X':
+                                               $type = lang('Closed');
+                                               break;
+                                       default:
+                                               $type = lang('Status changed');
+                                       }
+                                       $value['new_value'] = 
$status_text[$value['new_value']];
+                                       $value['old_value'] = 
$status_text[$value['old_value']];
+                               }
+
+                               $record_history[$i]['value_action']     = 
$type?$type:'';
+                               unset($type);
+                               if ($value['status'] == 'A' || $value['status'] 
== 'G')
+                               {
+                                       if ((int)$value['new_value']>0)
+                                       {
+                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+                                               
$record_history[$i]['value_old_value'] = $value['old_value'] ? 
$GLOBALS['phpgw']->accounts->id2name($value['old_value']) : '';
+                                       }
+                                       else
+                                       {
+                                               
$record_history[$i]['value_new_value']  = lang('None');
+                                               
$record_history[$i]['value_old_value']  = lang('None');
+                                       }
+                               }
+                               else if ($value['status'] == 'T')
+                               {
+                                       $record_history[$i]['value_new_value']  
= $this->get_category_name($value['new_value']);
+                                       $record_history[$i]['value_old_value']  
= $this->get_category_name($value['old_value']);
+                               }
+                               else if (($value['status'] == 'F') || 
($value['status'] =='IF'))
+                               {
+                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->common->show_date($value['new_value'],$this->dateformat);
+                               }
+                               else if ($value['status'] != 'O' && 
$value['new_value'])
+                               {
+                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
+                                       $record_history[$i]['value_old_value']  
= $value['old_value'];
+                               }
+                               else
+                               {
+                                       $record_history[$i]['value_new_value']  
= '';
+                               }
+
+                               $i++;
+                       }
+
+                       return $record_history;
+               }
+
+               function add($ticket)
+               {
+                       if((!isset($ticket['location_code']) || ! 
$ticket['location_code']) && isset($ticket['location']) && 
is_array($ticket['location']))
+                       {
+                               while (is_array($ticket['location']) && 
list(,$value) = each($ticket['location']))
+                               {
+                                       if($value)
+                                       {
+                                               $location[] = $value;
+                                       }
+                               }
+                               $ticket['location_code']=implode("-", 
$location);
+                       }
+
+                       $ticket['finnish_date'] = 
$this->bocommon->date_to_timestamp($ticket['finnish_date']);
+
+                       $receipt = $this->so->add($ticket);
+
+                       $this->config->read();
+
+                       if ( (isset($ticket['send_mail']) && 
$ticket['send_mail']) 
+                               || 
(isset($this->config->config_data['mailnotification'])
+                               && 
$this->config->config_data['mailnotification'])
+                       )
+                       {
+                               $receipt_mail = 
$this->mail_ticket($receipt['id'],false,$receipt,$ticket['location_code']);
+                       }
+
+                       $criteria = array
+                               (
+                                       'appname'       => 'helpdesk',
+                                       'location'      => $this->acl_location,
+                                       'allrows'       => true
+                               );
+
+                       $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
+
+                       foreach ( $custom_functions as $entry )
+                       {
+                               // prevent path traversal
+                               if ( preg_match('/\.\./', $entry['file_name']) )
+                               {
+                                       continue;
+                               }
+
+                               $file = PHPGW_SERVER_ROOT . 
"/helpdesk/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+                               if ( $entry['active'] && is_file($file) )
+                               {
+                                       require_once $file;
+                               }
+                       }
+
+                       if(isset($receipt_mail) && is_array($receipt_mail))
+                       {
+                               $receipt = array_merge($receipt, $receipt_mail);
+                       }
+                       return $receipt;
+               }
+
+
+               function get_address_element($location_code = '')
+               {
+                       $address_element = array();
+                       if($location_code)
+                       {
+                               $solocation             = 
CreateObject('helpdesk.solocation');
+                               $custom = 
createObject('helpdesk.custom_fields');
+                               $location_data          = 
$solocation->read_single($location_code);
+
+                               $location_types = 
execMethod('helpdesk.soadmin_location.select_location_type');
+                               $type_id=count(explode('-',$location_code));
+
+                               for ($i=1; $i<$type_id+1; $i++)
+                               {
+                                       $address_element[] = array
+                                               (
+                                                       'text' => 
$location_types[($i-1)]['name'],
+                                                       'value'=> 
$location_data["loc{$i}"] . '  ' . $location_data["loc{$i}_name"]
+                                               );
+                               }
+
+                               $fm_location_cols = 
$custom->find('helpdesk','.location.' . $type_id, 0, '', 'ASC', 'attrib_sort', 
true, true);
+                               $i=0;
+                               foreach($fm_location_cols as $location_entry)
+                               {
+                                       if($location_entry['lookup_form'])
+                                       {
+                                               $address_element[] = array
+                                                       (
+                                                               'text' => 
$location_entry['input_text'],
+                                                               'value'=> 
$location_data[$location_entry['column_name']]
+                                                       );
+                                       }
+                                       $i++;
+                               }
+                       }
+                       return $address_element;
+               }
+
+               function mail_ticket($id, $fields_updated, $receipt = 
array(),$location_code='', $get_message = false)
+               {
+                       $this->send                     = 
CreateObject('phpgwapi.send');
+
+                       $ticket = $this->so->read_single($id);
+
+                       $address_element = 
$this->get_address_element($ticket['location_code']);
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
+                       $entry_date = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+
+                       if($ticket['status']=='X')
+                       {
+                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
+                               $timestampclosed = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       }
+
+                       $history_2 = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
+                       $m=count($history_2)-1;
+                       $ticket['status']=$history_2[$m]['status'];
+
+                       $group_name= 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+
+                       // build subject
+                       $subject = '['.lang('Ticket').' #'.$id.'] : ' . 
$location_code .' ' .$this->get_category_name($ticket['cat_id']) . '; ' 
.$ticket['subject'];
+
+                       $prefs_user = 
$this->bocommon->create_preferences('helpdesk',$ticket['user_id']);
+
+                       $from_address=$prefs_user['email'];
+
+                       //-----------from--------
+
+                       $current_prefs_user = 
$this->bocommon->create_preferences('helpdesk',$GLOBALS['phpgw_info']['user']['account_id']);
+                       $current_user_address = 
"{$GLOBALS['phpgw_info']['user']['fullname']}<{$current_prefs_user['email']}>";
+
+                       //-----------from--------
+                       // build body
+                       $body  = '';
+                       $body .= '<a href ="http://' . 
$GLOBALS['phpgw_info']['server']['hostname'] . 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'helpdesk.uitts.view', 'id' => $id)).'">' . lang('Ticket').' #' .$id 
.'</a>'."\n";
+                       $body .= lang('Date Opened').': '.$entry_date."\n";
+                       $body .= lang('Category').': '. 
$this->get_category_name($ticket['cat_id']) ."\n";
+//                     $body .= lang('Subject').': '. $ticket['subject'] ."\n";
+                       $body .= lang('Location').': '. 
$ticket['location_code'] ."\n";
+                       $body .= lang('Address').': '. $ticket['address'] ."\n";
+                       if (isset($address_element) AND 
is_array($address_element))
+                       {
+                               foreach($address_element as $address_entry)
+                               {
+                                       $body .= $address_entry['text'].': '. 
$address_entry['value'] ."\n";
+                               }
+                       }
+
+                       if($ticket['tenant_id'])
+                       {
+                               
$tenant_data=$this->bocommon->read_single_tenant($ticket['tenant_id']);
+                               $body .= lang('Tenant').': '. 
$tenant_data['first_name'] . ' ' .$tenant_data['last_name'] ."\n";
+
+                               if($tenant_data['contact_phone'])
+                               {
+                                       $body .= lang('Contact phone').': '. 
$tenant_data['contact_phone'] ."\n";
+
+                               }
+                       }
+                       $body .= lang('Assigned To').': 
'.$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto'])."\n";
+                       $body .= lang('Priority').': '.$ticket['priority']."\n";
+                       if($group_name)
+                       {
+                               $body .= lang('Group').': '. $group_name ."\n";
+                       }
+                       $body .= lang('Opened By').': '. $ticket['user_name'] 
."\n\n";
+                       $body .= lang('First Note Added').":\n";
+                       $body .= 
stripslashes(strip_tags($ticket['details']))."\n\n";
+
+                       
/**************************************************************\
+                        * Display additional notes                             
        *
+                        
\**************************************************************/
+                       if($fields_updated)
+                       {
+                               $i=1;
+
+                               $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
+
+                               foreach($history_array as $value)
+                               {
+                                       $body .= lang('Date') . ': 
'.$GLOBALS['phpgw']->common->show_date($value['datetime'])."\n";
+                                       $body .= lang('User') . ': 
'.$value['owner']."\n";
+                                       $body .=lang('Note').': '. 
nl2br(stripslashes($value['new_value']))."\n\n";
+                                       $i++;
+                               }
+                               $subject.= "-" .$i;
+                       }
+                       
/**************************************************************\
+                        * Display record history                               
        *
+                        
\**************************************************************/
+
+                       if($timestampclosed)
+                       {
+                               $body .= lang('Date Closed').': 
'.$timestampclosed."\n\n";
+                       }
+
+
+                       if($get_message)
+                       {
+                               return array('subject' => $subject, 'body' => 
$body);
+                       }
+
+                       $members = array();
+
+                       if( 
isset($this->config->config_data['groupnotification']) && 
$this->config->config_data['groupnotification'] && $ticket['group_id'] )
+                       {
+                               $members_gross = 
$GLOBALS['phpgw']->accounts->member($ticket['group_id'], true);
+                               foreach($members_gross as $user)
+                               {
+                                       $members[$user['account_id']] = 
$user['account_name'];
+                               }
+                               unset($members_gross);
+                       }
+
+                       
$GLOBALS['phpgw']->preferences->set_account_id($ticket['user_id'], true);
+                       if( 
(isset($GLOBALS['phpgw']->preferences->data['helpdesk']['tts_notify_me'])
+                                       && 
($GLOBALS['phpgw']->preferences->data['helpdesk']['tts_notify_me'] == 1)
+                               )
+                               || 
($this->config->config_data['ownernotification'] && $ticket['user_id']))
+                       {
+                               // add owner to recipients
+                               $members[$ticket['user_id']] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                       }
+
+                       
$GLOBALS['phpgw']->preferences->set_account_id($ticket['assignedto'], true);
+                       if( 
(isset($GLOBALS['phpgw']->preferences->data['helpdesk']['tts_notify_me'])
+                                       && 
($GLOBALS['phpgw']->preferences->data['helpdesk']['tts_notify_me'] == 1)
+                               )
+                               || 
($this->config->config_data['assignednotification'] && $ticket['assignedto'])
+                       )
+                       {
+                               // add assigned to recipients
+                               $members[$ticket['assignedto']] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
+                       }
+
+                       $error = array();
+                       $toarray = array();
+
+                       $validator = 
CreateObject('phpgwapi.EmailAddressValidator');
+
+                       foreach($members as $account_id => $account_name)
+                       {
+                               $prefs = 
$this->bocommon->create_preferences('helpdesk',$account_id);
+                               if(!isset($prefs['tts_notify_me'])      || 
$prefs['tts_notify_me'] == 1)
+                               {
+                                       if 
($validator->check_email_address($prefs['email']))
+                                       {
+                                               // Email address is technically 
valid
+                                               // avoid problems with the 
delimiter in the send class
+                                               if(strpos($account_name,','))
+                                               {
+                                                       $_account_name = 
explode(',', $account_name);
+                                                       $account_name = 
ltrim($_account_name[1]) . ' ' . $_account_name[0];
+                                               }
+
+                                               $toarray[] = 
"{$account_name}<{$prefs['email']}>";
+                                       }
+                                       else
+                                       {
+                                               $receipt['error'][] = 
array('msg'=> lang('Your message could not be sent!'));
+                                               $receipt['error'][] = 
array('msg'=>lang('This user has not defined an email address !') . ' : ' . 
$account_name);
+                                       }
+                               }
+                       }
+
+                       if($toarray)
+                       {
+                               $to = implode(';',$toarray);
+                               $body = nl2br($body);
+
+                               if 
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) && 
$GLOBALS['phpgw_info']['server']['smtp_server'])
+                               {
+                                       try
+                                       {
+                                               $rc = $this->send->msg('email', 
$to, $subject, stripslashes($body), '', $cc, 
$bcc,$current_user_address,$GLOBALS['phpgw_info']['user']['fullname'],'html');
+                                       }
+                                       catch (phpmailerException $e)
+                                       {
+                                               $receipt['error'][] = 
array('msg' => $e->getMessage());
+                                       }
+                               }
+                               else
+                               {
+                                       $receipt['error'][] = 
array('msg'=>lang('SMTP server is not set! (admin section)'));
+                               }
+                       }
+
+                       if (!$rc && 
($this->config->config_data['groupnotification'] || 
$this->config->config_data['ownernotification'] || 
$this->config->config_data['groupnotification']))
+                       {
+                               $receipt['error'][] = array('msg'=> lang('Your 
message could not be sent by mail!'));
+                               $receipt['error'][] = array('msg'=> lang('The 
mail server returned'));
+                               $receipt['error'][] = array('msg'=> "From : 
{$current_user_address}");
+                               $receipt['error'][] = array('msg'=> 'to: '.$to);
+                               $receipt['error'][] = array('msg'=> 'subject: 
'.$subject);
+                               $receipt['error'][] = array('msg'=> $body );
+       //                      $receipt['error'][] = array('msg'=> 'cc: ' . 
$cc);
+       //                      $receipt['error'][] = array('msg'=> 'bcc: 
'.$bcc);
+                               $receipt['error'][] = array('msg'=> 'group: 
'.$group_name);
+                               $receipt['error'][] = array('msg'=> 'err_code: 
'.$this->send->err['code']);
+                               $receipt['error'][] = array('msg'=> 'err_msg: 
'. htmlspecialchars($this->send->err['msg']));
+                               $receipt['error'][] = array('msg'=> 'err_desc: 
'. $this->send->err['desc']);
+                       }
+
+                       //_debug_array($receipt);
+                       return $receipt;
+               }
+
+               function delete($id)
+               {
+                       return $this->so->delete($id);
+               }
+
+               /**
+                * Get a list of user(admin)-configured status
+                *
+                * @return array with list of custom status
+                */
+
+               public function get_custom_status()
+               {
+                       return $this->so->get_custom_status();
+               }
+
+               public function update_status($data, $id = 0)
+               {
+                       $receipt        = $this->so->update_status($data, $id);
+                       $this->fields_updated = $this->so->fields_updated;
+                       return $receipt;
+               }
+
+               public function update_ticket($data, $id)
+               {
+                       $receipt        = $this->so->update_ticket($data, $id);
+                       $this->fields_updated = $this->so->fields_updated;      
        
+                       return $receipt;
+               }
+       }

Added: trunk/helpdesk/inc/class.cat_hooks.inc.php
===================================================================
--- trunk/helpdesk/inc/class.cat_hooks.inc.php                          (rev 0)
+++ trunk/helpdesk/inc/class.cat_hooks.inc.php  2011-01-07 07:59:59 UTC (rev 
6733)
@@ -0,0 +1,91 @@
+<?php
+       /**
+       * phpGroupWare - helpdesk: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package helpdesk
+       * @subpackage entity
+       * @version $Id: class.cat_hooks.inc.php 6701 2010-12-25 10:51:59Z 
sigurdne $
+       */
+
+       /**
+       * hook management for categories
+       * @package helpdesk
+       */
+       class helpdesk_cat_hooks
+       {
+               
+               /**
+                * Handle a new category being added, create location to hold 
ACL-data
+                */
+               function cat_add($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
+
+                       $location = '';
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = $location_info['location'];
+                       }
+                       
$GLOBALS['phpgw']->locations->add("{$location}.category.{$data['cat_id']}", 
$data['cat_name'], 'helpdesk');
+
+               }
+
+               /**
+                * Handle a category being deleted, remove the location 
+                */
+               function cat_delete($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = 
"{$location_info['location']}.category.{$data['cat_id']}";
+                               
$GLOBALS['phpgw']->locations->delete('helpdesk', $location, false);
+                       }
+               }
+
+               /**
+                * Handle a category being edited, update the location info
+                */
+               function cat_edit($data)
+               {
+                       if ( isset($data['cat_owner']) && $data['cat_owner'] != 
-1 )
+                       {
+                               return false; //nothing needed to be done, we 
only care about global cats
+                       }
+
+                       if($data['location_id'])
+                       {
+                               $location_info = 
$GLOBALS['phpgw']->locations->get_name($data['location_id']);
+                               $location = 
"{$location_info['location']}.category.{$data['cat_id']}";
+                               
$GLOBALS['phpgw']->locations->update_description($location, $data['cat_name'], 
'helpdesk');
+                       }
+               }
+       }

Added: trunk/helpdesk/inc/class.menu.inc.php
===================================================================
--- trunk/helpdesk/inc/class.menu.inc.php                               (rev 0)
+++ trunk/helpdesk/inc/class.menu.inc.php       2011-01-07 07:59:59 UTC (rev 
6733)
@@ -0,0 +1,147 @@
+<?php
+       /**
+        * helpdesk - Menus
+        *
+        * @author Dave Hall <address@hidden>
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2007,2008 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+        * @package helpdesk
+        * @version $Id: class.menu.inc.php 6711 2010-12-28 15:15:42Z sigurdne $
+        */
+
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU General Public License as published by
+          the Free Software Foundation, either version 2 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU General Public License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
+
+       /**
+        * Menus
+        *
+        * @package helpdesk
+        */
+       class helpdesk_menu
+       {
+               /**
+                * Get the menus for the helpdesk
+                *
+                * @return array available menus for the current user
+                */
+               public function get_menu($type='')
+               {
+                       $incoming_app = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
'helpdesk';
+                       $acl = & $GLOBALS['phpgw']->acl;
+                       $menus = array();
+
+
+                       $menus['navbar'] = array
+                               (
+                                       'helpdesk' => array
+                                       (
+                                               'text'  => lang('helpdesk'),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
"helpdesk.uitts.index") ),
+                                               'image' => array('helpdesk', 
'navbar'),
+                                               'order' => 35,
+                                               'group' => 'facilities 
management'
+                                       ),
+                               );
+
+                       $menus['toolbar'] = array();
+
+
+                       if ( $GLOBALS['phpgw']->acl->check('run', 
phpgwapi_acl::READ, 'admin')
+                               || $GLOBALS['phpgw']->acl->check('admin', 
phpgwapi_acl::ADD, 'helpdesk'))
+                       {
+
+                               $menus['admin'] = array
+                                       (
+                                               'index' => array
+                                               (
+                                                       'text'  => 
lang('Configuration'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uiconfig.index', 'appname' => 'helpdesk') )
+                                               ),
+                                               'ticket_cats'   => array
+                                               (
+                                                       'text'  => lang('Ticket 
Categories'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'admin.uicategories.index', 'appname' => 'helpdesk', 'location' => '.ticket', 
'global_cats' => 'true', 'menu_selection' => 'admin::helpdesk::ticket_cats') )
+                                               ),
+                                               'ticket_status' => array
+                                               (
+                                                       'text'  => lang('Ticket 
status'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'helpdesk_status') )
+                                               ),
+                                               'acl'   => array
+                                               (
+                                                       'text'  => 
lang('Configure Access Permissions'),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'helpdesk') )
+                                               )
+                                       );
+                       }
+
+                       if ( 
isset($GLOBALS['phpgw_info']['user']['apps']['preferences']) )
+                       {
+                               $menus['preferences'] = array
+                                       (
+                                               array
+                                               (
+                                                       'text'  => 
$GLOBALS['phpgw']->translation->translate('Preferences', array(), true),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/preferences/preferences.php', array('appname' => 
'helpdesk', 'type'=> 'user') )
+                                               ),
+                                               array
+                                               (
+                                                       'text'  => 
$GLOBALS['phpgw']->translation->translate('Grant Access', array(), true),
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'helpdesk.uiadmin.aclprefs', 'acl_app'=> 'helpdesk'))
+                                               )
+                                       );
+
+                               $menus['toolbar'][] = array
+                                       (
+                                               'text'  => 
$GLOBALS['phpgw']->translation->translate('Preferences', array(), true),
+                                               'url'   => 
$GLOBALS['phpgw']->link('/preferences/preferences.php', array('appname'      => 
'helpdesk')),
+                                               'image' => array('helpdesk', 
'preferences')
+                                       );
+                       }
+
+                       $menus['navigation'] = array();
+
+
+                       if ( $acl->check('.ticket',PHPGW_ACL_READ, 'helpdesk') )
+                       {
+                               $menus['navigation']['helpdesk'] = array
+                                       (
+                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index')),
+                                               'text'  => lang('inbox'),
+                                               'image'         => 
array('helpdesk', 'helpdesk')
+                                       );
+                       }
+
+                       if ( $acl->check('.ticket.order',PHPGW_ACL_ADD, 
'helpdesk') )
+                       {
+                               $menus['navigation']['helpdesk']['children'] = 
array
+                                       (
+                                               'order_template' => array
+                                               (       
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'order_template') ),
+                                                       'text'  => lang('order 
template'),
+                                                       'image'         => 
array('helpdesk', 'helpdesk')
+                                               )
+                                       );
+                       }
+
+
+                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
$incoming_app;
+                       return $menus;
+               }
+       }

Added: trunk/helpdesk/inc/class.sotts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.sotts.inc.php                              (rev 0)
+++ trunk/helpdesk/inc/class.sotts.inc.php      2011-01-07 07:59:59 UTC (rev 
6733)
@@ -0,0 +1,1179 @@
+<?php
+       /**
+       * phpGroupWare - helpdesk: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package helpdesk
+       * @subpackage helpdesk
+       * @version $Id: class.sotts.inc.php 6701 2010-12-25 10:51:59Z sigurdne $
+       */
+
+       phpgw::import_class('phpgwapi.datetime');
+
+       /**
+        * Description
+        * @package helpdesk
+        */
+
+       class helpdesk_sotts
+       {
+               var $uicols_related = array();
+               var $acl_location = '.ticket';
+
+               public $soap_functions = array
+                       (
+                               'read' => array(
+                                       'in'  => array('array'),
+                                       'out' => array('array')
+                               )
+                       );
+
+
+               public $xmlrpc_methods = array
+                       (
+                               array
+                               (
+                                       'name'       => 'read',
+                                       'decription' => 'Get list of tickets'
+                               )
+                       );
+
+
+               function __construct()
+               {
+                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->historylog       = 
CreateObject('phpgwapi.historylog','helpdesk');
+                       $this->db                       = & 
$GLOBALS['phpgw']->db;
+                       $this->like             = & $this->db->like;
+                       $this->join             = & $this->db->join;
+                       $this->left_join        = & $this->db->left_join;
+                       $this->dateformat       = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+               }
+
+
+               function list_methods($_type='xmlrpc')
+               {
+                       /*
+                         This handles introspection or discovery by the logged 
in client,
+                         in which case the input might be an array.  The 
server always calls
+                         this function to fill the server dispatch map using a 
string.
+                        */
+                       if (is_array($_type))
+                       {
+                               $_type = $_type['type'] ? $_type['type'] : 
$_type[0];
+                       }
+                       switch($_type)
+                       {
+                       case 'xmlrpc':
+                               $xml_functions = array(
+                                       'read' => array(
+                                               'function'  => 'read',
+                                               'signature' => 
array(array(xmlrpcArray,xmlrpcArray)),
+                                               'docstring' => 'Get list of 
tickets'
+                                       ),
+                               );
+                               return $xml_functions;
+                               break;
+                       case 'soap':
+                               return $this->soap_functions;
+                               break;
+                       default:
+                               return array();
+                               break;
+                       }
+               }
+
+               function read($data)
+               {
+                       $start                  = isset($data['start']) && 
$data['start'] ? $data['start']:0;
+                       $status_id              = isset($data['status_id']) && 
$data['status_id'] ? $data['status_id']:'O'; //O='Open'
+                       $user_id                = isset($data['user_id']) && 
$data['user_id'] ? (int)$data['user_id']: 0;
+                       $owner_id               = 
isset($data['owner_id'])?$data['owner_id']:'';
+                       $query                  = 
isset($data['query'])?$data['query']:'';
+                       $sort                   = isset($data['sort']) && 
$data['sort'] ? $data['sort']:'DESC';
+                       $order                  = 
isset($data['order'])?$data['order']:'';
+                       $cat_id                 = isset($data['cat_id']) && 
$data['cat_id'] ? $data['cat_id']:0;
+                       $district_id    = isset($data['district_id']) && 
$data['district_id'] ? $data['district_id']:0;
+                       $allrows                = 
isset($data['allrows'])?$data['allrows']:'';
+                       $start_date             = isset($data['start_date']) && 
$data['start_date'] ? (int)$data['start_date'] : 0;
+                       $end_date               = isset($data['end_date']) && 
$data['end_date'] ? (int)$data['end_date'] : 0;
+                       $dry_run                = isset($data['dry_run']) ? 
$data['dry_run'] : '';
+                       $new                    = isset($data['new']) ? 
$data['new'] : '';
+                       $location_code  = isset($data['location_code']) ? 
$data['location_code'] : '';
+                       $p_num                  = isset($data['p_num']) ? 
$data['p_num'] : '';
+
+                       $this->grants   = 
$GLOBALS['phpgw']->session->appsession('grants_ticket','helpdesk');
+
+                       if(!$this->grants)
+                       {
+                               $this->grants   = 
$GLOBALS['phpgw']->acl->get_grants('helpdesk','.ticket');
+                               
$GLOBALS['phpgw']->session->appsession('grants_ticket','helpdesk',$this->grants);
+                       }
+
+                       $result_order_field = '';
+                       if ($order)
+                       {
+                               if( $order == 'assignedto' )
+                               {
+                                       $result_order_field = 
',account_lastname';
+                                       $order_join = "LEFT OUTER JOIN 
phpgw_accounts ON phpgw_helpdesk_tickets.assignedto=phpgw_accounts.account_id";
+                                       $order = 'account_lastname';
+                               }
+                               else if( $order == 'user' )
+                               {
+                                       $result_order_field = 
',account_lastname';
+                                       $order_join = "LEFT OUTER JOIN 
phpgw_accounts ON phpgw_helpdesk_tickets.user_id=phpgw_accounts.account_id";
+                                       $order = 'account_lastname';
+                               }
+                               else
+                               {
+                                       $order_join = '';
+                               }
+
+                               $ordermethod = " ORDER BY $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' ORDER BY 
phpgw_helpdesk_tickets.id DESC';
+                       }
+
+                       $filtermethod = '';
+
+                       $categories = 
$GLOBALS['phpgw']->locations->get_subs('helpdesk', '.ticket.category');
+
+                       $grant_category = array();
+                       foreach ($categories as $location)
+                       {
+                               if ($GLOBALS['phpgw']->acl->check($location, 
PHPGW_ACL_READ, 'helpdesk'))
+                               {
+                                       $category = explode('.',$location);
+                                       $grant_category[] = $category[3];
+                               }
+                       }
+
+                       $grant_category[] = -1;//If no one found - not breaking 
the query
+
+                       $where= 'WHERE';
+
+                       $GLOBALS['phpgw']->config->read();
+
+                       
if(isset($GLOBALS['phpgw']->config->config_data['acl_at_tts_category']) && 
$GLOBALS['phpgw']->config->config_data['acl_at_tts_category'])
+                       {
+                               $filtermethod = " WHERE 
phpgw_helpdesk_tickets.cat_id IN (" . implode(",", $grant_category) . ")";
+                               $where= 'AND';
+                       }
+
+                       
if(isset($GLOBALS['phpgw']->config->config_data['acl_at_location']) && 
$GLOBALS['phpgw']->config->config_data['acl_at_location'])
+                       {
+                               $access_location = 
execMethod('property.socommon.get_location_list', PHPGW_ACL_READ);
+                               if($access_location)
+                               {
+                                       $filtermethod .= " $where 
phpgw_helpdesk_tickets.loc1 in ('" . implode("','", $access_location) . "')";
+                                       $where= 'AND';
+                               }
+                       }
+
+                       if (is_array($this->grants))
+                       {
+                               $grants = & $this->grants;
+                               foreach($grants as $user => $right)
+                               {
+                                       $public_user_list[] = $user;
+                               }
+                               reset($public_user_list);
+                               $filtermethod .= " $where ( 
phpgw_helpdesk_tickets.user_id IN(" . implode(',',$public_user_list) . "))";
+                               $where= 'AND';
+                       }
+
+                       if($tenant_id = 
$GLOBALS['phpgw']->session->appsession('tenant_id','helpdesk'))
+                       {
+                               $filtermethod .= $where . ' 
phpgw_helpdesk_tickets.tenant_id=' . $tenant_id;
+                               $where = 'AND';
+                       }
+
+                       if ($status_id == 'X')
+                       {
+                               $closed = '';
+                               $this->db->query('SELECT * from 
phpgw_helpdesk_status',__LINE__,__FILE__);
+
+                               while ($this->db->next_record())
+                               {
+                                       if( $this->db->f('closed'))
+                                       {
+                                               $closed .= " OR 
phpgw_helpdesk_tickets.status = 'C" . $this->db->f('id') . "'";
+                                       }
+                               }
+
+                               $filtermethod .= " $where ( 
(phpgw_helpdesk_tickets.status='X'{$closed})";
+                               $where = 'AND';
+
+//                             $filtermethod .= " $where ( 
phpgw_helpdesk_tickets.status='X'";
+//                             $where = 'AND';
+                       }
+                       else if ($status_id == 'O2') // explicite 'open'
+                       {
+                               $filtermethod .= " $where ( 
phpgw_helpdesk_tickets.status='O'";
+                               $where = 'AND';
+                       }
+                       else if($status_id == 'O')
+                       {
+                               $open = '';
+                               $this->db->query('SELECT * from 
phpgw_helpdesk_status',__LINE__,__FILE__);
+
+                               while ($this->db->next_record())
+                               {
+                                       if( ! $this->db->f('closed'))
+                                       {
+                                               $open .= " OR 
phpgw_helpdesk_tickets.status = 'C" . $this->db->f('id') . "'";
+                                       }
+                               }
+
+                               $filtermethod .= " $where ( 
(phpgw_helpdesk_tickets.status='O'{$open})";
+                               $where = 'AND';
+                       }
+                       else if($status_id == 'all')
+                       {
+                               $filtermethod .= "{$where} (1=1";//nothing
+                               $where = 'AND';
+                       }
+                       else if(is_array($status_id) && count($status_id))
+                       {
+                               $or = '';
+                               $filtermethod .= "{$where} ((";
+
+                               foreach ($status_id as $value)
+                               {
+                                       if($value)
+                                       {
+                                               $filtermethod .= "{$or} 
phpgw_helpdesk_tickets.status = '{$value}'";                                    
+                                               $or = ' OR';
+                                       }
+                               }
+
+                               $filtermethod .= ')';
+
+                               $where = 'AND';
+                       }
+                       else
+                       {
+                               $filtermethod .= " $where 
(phpgw_helpdesk_tickets.status='{$status_id}'";
+                               $where = 'AND';
+                       }
+
+                       if($new)
+                       {
+                               $filtermethod .= " OR phpgw_helpdesk_views.id 
IS NULL )";
+                       }
+                       else
+                       {
+                               $filtermethod .= ')';
+                       }
+
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where cat_id=" . 
(int)$cat_id;
+                               $where = 'AND';
+                       }
+
+                       if ($user_id > 0)
+                       {
+                               $filtermethod .= " {$where} 
(assignedto={$user_id}";
+                               $where = 'AND';
+
+                               $membership = 
$GLOBALS['phpgw']->accounts->membership($user_id);
+                               $filtermethod .= ' OR (assignedto IS NULL AND 
group_id IN (' . implode(',',array_keys($membership)) . ')))'; 
+                       }
+
+                       if ($owner_id > 0)
+                       {
+                               $filtermethod .= " $where 
phpgw_helpdesk_tickets.user_id=" . (int)$owner_id;
+                               $where = 'AND';
+                       }
+
+                       if ($district_id > 0)
+                       {
+                               $filtermethod .= " $where  district_id=" 
.(int)$district_id;
+                               $where = 'AND';
+                       }
+
+                       if ($start_date)
+                       {
+                               $end_date       = $end_date + 3600 * 16 + 
phpgwapi_datetime::user_timezone();
+                               $start_date     = $start_date - 3600 * 8 + 
phpgwapi_datetime::user_timezone();
+                               $filtermethod .= " $where 
phpgw_helpdesk_tickets.entry_date >= $start_date AND 
phpgw_helpdesk_tickets.entry_date <= $end_date ";
+                               $where= 'AND';
+                       }
+
+                       if ($location_code)
+                       {
+                               $filtermethod .= " $where 
phpgw_helpdesk_tickets.location_code {$this->like} '{$location_code}%'";
+                               $where= 'AND';
+                       }
+
+                       $querymethod = '';
+                       if($query)
+                       {
+                               $query = $this->db->db_addslashes($query);
+                               $query = str_replace(",",'.',$query);
+                               if(stristr($query, '.') && !$p_num)
+                               {
+                                       $query=explode(".",$query);
+                                       $querymethod = " $where 
(phpgw_helpdesk_tickets.loc1='" . $query[0] . "' AND 
phpgw_helpdesk_tickets.loc4='" . $query[1] . "')";
+                               }
+                               else if(stristr($query, '.') && $p_num)
+                               {
+                                       $query=explode(".",$query);
+                                       $querymethod = " $where 
(phpgw_helpdesk_tickets.p_entity_id='" . (int)$query[1] . "' AND 
phpgw_helpdesk_tickets.p_cat_id='" . (int)$query[2] . "' AND 
phpgw_helpdesk_tickets.p_num='" . (int)$query[3] . "')";
+                               }
+                               else
+                               {
+                                       $querymethod = " $where (subject 
$this->like '%$query%'"
+                                               . " OR address $this->like 
'%$query%' "
+                                               . " OR fm_location1.loc1_name 
$this->like '%$query%'"
+                                               . " OR 
phpgw_helpdesk_tickets.location_code $this->like '%$query%'"
+                                               . " OR 
phpgw_helpdesk_tickets.order_id =" . (int)$query . ')';
+                               }
+                       }
+
+                       $sql = "SELECT DISTINCT phpgw_helpdesk_tickets.* , 
phpgw_helpdesk_views.id as view {$result_order_field} FROM 
phpgw_helpdesk_tickets"
+                               . " $order_join"
+                               . " LEFT OUTER JOIN phpgw_helpdesk_views ON 
(phpgw_helpdesk_tickets.id = phpgw_helpdesk_views.id AND 
phpgw_helpdesk_views.account_id='{$this->account}')"
+                               . " $filtermethod $querymethod";
+
+                       $sql2 = "SELECT count(*) as cnt FROM ({$sql}) as t";
+                       $this->db->query($sql2,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $this->total_records = $this->db->f('cnt');
+                       unset($sql2);
+
+                       $tickets = array();
+                       if(!$dry_run)
+                       {
+                               if(!$allrows)
+                               {
+                                       $this->db->limit_query($sql . 
$ordermethod,$start,__LINE__,__FILE__);
+                               }
+                               else
+                               {
+                                       if($this->total_records > 200)
+                                       {
+                                               $_fetch_single = true;
+                                       }
+                                       else
+                                       {
+                                               $_fetch_single = false;
+                                       }
+                                       $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__, false, $_fetch_single );
+                                       unset($_fetch_single);
+                               }
+
+                               while ($this->db->next_record())
+                               {
+                                       $tickets[]= array
+                                               (
+                                                       'id'                    
        => (int) $this->db->f('id'),
+                                                       'subject'               
        => $this->db->f('subject',true),
+                                                       'loc1_name'             
        => $this->db->f('loc1_name',true),
+                                                       'location_code'         
=> $this->db->f('location_code'),
+                                                       'district'              
        => $this->db->f('district',true),
+                                                       'user_id'               
        => $this->db->f('user_id'),
+                                                       'address'               
        => $this->db->f('address',true),
+                                                       'assignedto'            
=> $this->db->f('assignedto'),
+                                                       'status'                
        => $this->db->f('status'),
+                                                       'priority'              
        => $this->db->f('priority'),
+                                                       'cat_id'                
        => $this->db->f('cat_id'),
+                                                       'group_id'              
        => $this->db->f('group_id'),
+                                                       'entry_date'            
=> $this->db->f('entry_date'),
+                                                       'finnish_date'          
=> $this->db->f('finnish_date'),
+                                                       'finnish_date2'         
=> $this->db->f('finnish_date2'),
+                                                       'order_id'              
        => $this->db->f('order_id'),
+                                                       'vendor_id'             
        => $this->db->f('vendor_id'),
+                                                       'actual_cost'           
=> $this->db->f('actual_cost'),
+                                                       'estimate'              
        => $this->db->f('budget'),
+                                                       'new_ticket'            
=> $this->db->f('view') ? false : true,
+                                                       'billable_hours'        
=> $this->db->f('billable_hours'),
+                                               );
+                               }
+/*                     
+                               foreach ($tickets as &$ticket)
+                               {
+                                       $this->db->query("SELECT count(*) as 
hits FROM phpgw_helpdesk_views where id={$ticket['id']}"
+                                               . " AND 
account_id='{$this->account}'",__LINE__,__FILE__);
+                                       $this->db->next_record();
+
+                                       if(! $this->db->f('hits'))
+                                       {
+                                               $ticket['new_ticket'] = true;
+                                       }
+                               }
+ */
+                       }
+
+                       return $tickets;
+               }
+
+               function get_origin_entity_type()
+               {
+                       $sql = "SELECT entity_id, id as cat_id,name"
+                               . " FROM fm_entity_category "
+                               . " WHERE tracking=1 ORDER by entity_id,cat_id";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       $i=0;
+                       while ($this->db->next_record())
+                       {
+                               
$entity[$i]['entity_id']=$this->db->f('entity_id');
+                               $entity[$i]['cat_id']=$this->db->f('cat_id');
+                               
$entity[$i]['type']=".entity.{$this->db->f('entity_id')}.{$this->db->f('cat_id')}";
+                               $uicols[]       =  str_replace(' ', '_', 
$this->db->f('name',true));
+                               $i++;
+                       }
+
+                       $entity[$i]['type']='.project';
+                       $uicols[]       = 'project';
+
+                       $this->uicols_related   = $uicols;
+                       return $entity;
+               }
+
+               function read_single($id)
+               {
+                       $id = (int) $id;
+                       $sql = "SELECT * FROM phpgw_helpdesk_tickets WHERE id = 
{$id}";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       if ($this->db->next_record())
+                       {
+                               $ticket['assignedto']           = 
$this->db->f('assignedto');
+                               $ticket['user_id']                      = 
$this->db->f('user_id');
+                               $ticket['group_id']                     = 
$this->db->f('group_id');
+                               $ticket['status']                       = 
$this->db->f('status');
+                               $ticket['cat_id']                       = 
$this->db->f('cat_id');
+                               $ticket['subject']                      = 
$this->db->f('subject', true);
+                               $ticket['priority']                     = 
$this->db->f('priority');
+                               $ticket['details']                      = 
htmlspecialchars ($this->db->f('details', true));
+                               $ticket['location_code']        = 
$this->db->f('location_code');
+                               $ticket['contact_phone']        = 
$this->db->f('contact_phone');
+                               $ticket['contact_email']        = 
$this->db->f('contact_email',true);
+                               $ticket['address']                      = 
$this->db->f('address', true);
+                               $ticket['tenant_id']            = 
$this->db->f('tenant_id');
+                               $ticket['p_num']                        = 
$this->db->f('p_num');
+                               $ticket['p_entity_id']          = 
$this->db->f('p_entity_id');
+                               $ticket['p_cat_id']                     = 
$this->db->f('p_cat_id');
+                               $ticket['finnish_date']         = 
$this->db->f('finnish_date');
+                               $ticket['finnish_date2']        = 
$this->db->f('finnish_date2');
+                               $ticket['contact_id']           = 
$this->db->f('contact_id');
+                               $ticket['order_id']                     = 
$this->db->f('order_id');
+                               $ticket['vendor_id']            = 
$this->db->f('vendor_id');
+                               $ticket['b_account_id']         = 
$this->db->f('b_account_id');
+                               $ticket['order_descr']          = 
$this->db->f('order_descr', true);
+                               $ticket['ecodimb']                      = 
$this->db->f('ecodimb');
+                               $ticket['budget']                       = 
$this->db->f('budget');
+                               $ticket['actual_cost']          = 
$this->db->f('actual_cost');
+                               $ticket['order_cat_id']         = 
$this->db->f('order_cat_id');
+                               $ticket['building_part']        = 
$this->db->f('building_part',true);
+                               $ticket['order_dim1']           = 
$this->db->f('order_dim1');
+                               $ticket['publish_note']         = 
$this->db->f('publish_note');
+                               $ticket['billable_hours']       = 
$this->db->f('billable_hours');
+
+                               $user_id=(int)$this->db->f('user_id');
+
+                               $ticket['user_name']    = 
$GLOBALS['phpgw']->accounts->get($user_id)->__toString();
+                               if ($ticket['assignedto'] > 0)
+                               {
+                                       $ticket['assignedto_name']      = 
$GLOBALS['phpgw']->accounts->get($ticket['assignedto'])->__toString();
+                               }
+                       }
+
+                       return $ticket;
+               }
+
+               function update_view($id='')
+               {
+                       // Have they viewed this ticket before ?
+                       $id = (int) $id;
+                       $this->db->query("SELECT count(*) as cnt FROM 
phpgw_helpdesk_views where id={$id}"
+                               . " AND account_id='" . 
$GLOBALS['phpgw_info']['user']['account_id'] . "'",__LINE__,__FILE__);
+                       $this->db->next_record();
+
+                       if (! $this->db->f('cnt'))
+                       {
+                               $this->db->query("INSERT INTO 
phpgw_helpdesk_views (id,account_id,time) values ({$id},'"
+                                       . 
$GLOBALS['phpgw_info']['user']['account_id'] . "','" . time() . 
"')",__LINE__,__FILE__);
+                       }
+               }
+
+               function add($ticket)
+               {
+                       if(isset($ticket['location']) && 
is_array($ticket['location']))
+                       {
+                               foreach ($ticket['location'] as $input_name => 
$value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $cols[] = $input_name;
+                                               $vals[] = $value;
+                                       }
+                               }
+                       }
+
+                       if(isset($ticket['extra']) && 
is_array($ticket['extra']))
+                       {
+                               foreach ($ticket['extra'] as $input_name => 
$value)
+                               {
+                                       if(isset($value) && $value)
+                                       {
+                                               $cols[] = $input_name;
+                                               $vals[] = $value;
+                                       }
+                               }
+                       }
+
+                       if($cols)
+                       {
+                               $cols   = "," . implode(",", $cols);
+                               $vals   = ",'" . implode("','", $vals) . "'";
+                       }
+
+                       $address = '';
+                       if(isset($ticket['street_name']) && 
$ticket['street_name'])
+                       {
+                               $address[]= $ticket['street_name'];
+                               $address[]= $ticket['street_number'];
+                               $address        = 
$this->db->db_addslashes(implode(" ", $address));
+                       }
+
+                       if(!$address)
+                       {
+                               $address = 
$this->db->db_addslashes($ticket['location_name']);
+                       }
+
+                       $values= array
+                               (
+                                       
isset($ticket['priority'])?$ticket['priority']:0,
+                                       
$GLOBALS['phpgw_info']['user']['account_id'],
+                                       $ticket['assignedto'],
+                                       $ticket['group_id'],
+                                       
$this->db->db_addslashes($ticket['subject']),
+                                       $ticket['cat_id'],
+                                       $ticket['status'],
+                                       
$this->db->db_addslashes($ticket['details']),
+                                       $ticket['location_code'],
+                                       $address,
+                                       time(),
+                                       $ticket['finnish_date'],
+                                       $ticket['contact_id'],
+                                       1
+                               );
+
+                       $values = $this->db->validate_insert($values);
+                       $this->db->transaction_begin();
+
+                       $this->db->query("insert into phpgw_helpdesk_tickets 
(priority,user_id,"
+                               . 
"assignedto,group_id,subject,cat_id,status,details,location_code,"
+                               . 
"address,entry_date,finnish_date,contact_id,publish_note $cols)"
+                               . "VALUES ($values $vals )",__LINE__,__FILE__);
+
+                       $id = 
$this->db->get_last_insert_id('phpgw_helpdesk_tickets','id');
+                       if(isset($ticket['extra']['contact_phone']) && 
$ticket['extra']['contact_phone'] && isset($ticket['extra']['tenant_id']) && 
$ticket['extra']['tenant_id'])
+                       {
+                               $this->db->query("update fm_tenant set 
contact_phone='". $ticket['extra']['contact_phone']. "' where id='". 
$ticket['extra']['tenant_id']. "'",__LINE__,__FILE__);
+                       }
+
+                       if(isset($ticket['origin']) && 
is_array($ticket['origin']))
+                       {
+                               if($ticket['origin'][0]['data'][0]['id'])
+                               {
+                                       $interlink_data = array
+                                               (
+                                                       'location1_id'          
=> $GLOBALS['phpgw']->locations->get_id('helpdesk', 
$ticket['origin'][0]['location']),
+                                                       'location1_item_id' => 
$ticket['origin'][0]['data'][0]['id'],
+                                                       'location2_id'          
=> $GLOBALS['phpgw']->locations->get_id('helpdesk', '.ticket'),                 
+                                                       'location2_item_id' => 
$id,
+                                                       'account_id'            
=> $this->account
+                                               );
+
+                                       $interlink      = 
CreateObject('helpdesk.interlink');
+                                       
$interlink->add($interlink_data,$this->db);
+                               }
+                       }
+
+                       if($this->db->transaction_commit())
+                       {
+                               $this->historylog->add('O',$id, time(),'');
+                               if($ticket['finnish_date'])
+                               {
+                                       
$this->historylog->add('IF',$id,$ticket['finnish_date'],'');
+                               }
+                       }
+
+                       $receipt['message'][]=array('msg'=>lang('Ticket %1 has 
been saved',$id));
+                       $receipt['id']  = $id;
+                       return $receipt;
+               }
+
+               /**
+                * Get a list of user(admin)-configured status
+                *
+                * @return array with list of custom status
+                */
+
+               public function get_custom_status()
+               {
+                       $sql = "SELECT * FROM phpgw_helpdesk_status ORDER BY 
sorting ASC";
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       $status= array();
+                       while ($this->db->next_record())
+                       {
+                               $status[] = array
+                                       (
+                                               'id'    => $this->db->f('id'),
+                                               'name'  => $this->db->f('name', 
true),
+                                               'color' => $this->db->f('color')
+                                       );
+                       }
+                       return $status;
+               }
+               function update_status($ticket,$id = 0)
+               {
+                       $id = (int) $id;
+                       $receipt = array();
+                       // DB Content is fresher than http posted value.
+                       $this->db->query("select * from phpgw_helpdesk_tickets 
where id='$id'",__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $old_status             = $this->db->f('status');
+
+                       $this->db->transaction_begin();
+
+                       /*
+                        ** phpgw_phpgw_helpdesk_append.append_type - Defs
+                        ** R - Reopen ticket
+                        ** X - Ticket closed
+                        ** O - Ticket opened
+                        ** C - Comment appended
+                        ** A - Ticket assignment
+                        ** G - Ticket group assignment
+                        ** P - Priority change
+                        ** T - Category change
+                        ** S - Subject change
+                        ** B - Budget
+                        ** H - Billing hours
+                        ** F - finnish date
+                        ** C% - Status changed
+                        ** L - Location changed
+                        ** M - Mail sent to vendor
+                        */
+
+                       if ($old_status != $ticket['status'])
+                       {
+                               $check_old_custom = (int) trim($old_status,'C');
+                               $this->db->query("SELECT * from 
phpgw_helpdesk_status WHERE id = {$check_old_custom}",__LINE__,__FILE__);
+                               $this->db->next_record();
+                               $this->fields_updated = true;
+                               if($old_status=='X' || $this->db->f('closed'))
+                               {
+                                       $new_status = $ticket['status'];
+                                       
$this->historylog->add('R',$id,$ticket['status'],$old_status);
+
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$new_status}' WHERE id= 
{$id}",__LINE__,__FILE__);
+                               }
+                               else
+                               {
+                                       
$this->historylog->add($ticket['status'],$id,$ticket['status'],$old_status);
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$ticket['status']}' WHERE 
id={$id}",__LINE__,__FILE__);
+                               }
+                               $this->check_pending_action($ticket, $id);
+                       }
+
+                       $this->db->transaction_commit();
+
+                       if ($this->fields_updated)
+                       {
+                               $receipt['message'][]= array('msg' => 
lang('Ticket %1 has been updated',$id));
+                       }
+
+                       return $receipt;
+
+               }
+
+               function update_ticket($ticket,$id = 0)
+               {
+                       $id = (int) $id;
+                       $receipt = array();
+                       // DB Content is fresher than http posted value.
+                       $this->db->query("select * from phpgw_helpdesk_tickets 
where id='$id'",__LINE__,__FILE__);
+                       $this->db->next_record();
+
+                       $location_code  = $this->db->f('location_code');
+                       $oldlocation_code       = $this->db->f('location_code');
+                       $oldfinnish_date        = $this->db->f('finnish_date');
+                       $oldfinnish_date2       = $this->db->f('finnish_date2');
+                       $oldassigned            = $this->db->f('assignedto');
+                       $oldgroup_id            = $this->db->f('group_id');
+                       $oldpriority            = $this->db->f('priority');
+                       $oldcat_id                      = 
$this->db->f('cat_id');
+                       $old_status             = $this->db->f('status');
+                       $old_budget             = $this->db->f('budget');
+                       $old_billable_hours     = 
$this->db->f('billable_hours');
+                       //      $old_billable_rate      = 
$this->db->f('billable_rate');
+                       $old_subject            = $this->db->f('subject');
+                       $old_contact_id         = $this->db->f('contact_id');
+                       $old_actual_cost        = $this->db->f('actual_cost');
+                       $old_order_cat_id       = $this->db->f('order_cat_id');
+                       $old_building_part      = 
$this->db->f('building_part',true);
+                       $old_order_dim1         = 
(int)$this->db->f('order_dim1');
+
+
+                       if($oldcat_id ==0){$oldcat_id ='';}
+                       if($old_order_cat_id ==0){$old_order_cat_id ='';}
+                               if($oldassigned ==0){$oldassigned ='';}
+                                       if($oldgroup_id ==0){$oldgroup_id ='';}
+
+                                               // Figure out and last note
+
+                                               $history_values = 
$this->historylog->return_array(array(),array('C'),'history_timestamp','DESC',$id);
+                       $old_note = $history_values[0]['new_value'];
+
+                       if(!$old_note)
+                       {
+                               $old_note = $this->db->f('details');
+                       }
+
+
+                       $this->db->transaction_begin();
+
+                       /*
+                        ** phpgw_phpgw_helpdesk_append.append_type - Defs
+                        ** R - Reopen ticket
+                        ** X - Ticket closed
+                        ** O - Ticket opened
+                        ** C - Comment appended
+                        ** A - Ticket assignment
+                        ** G - Ticket group assignment
+                        ** P - Priority change
+                        ** T - Category change
+                        ** S - Subject change
+                        ** B - Budget change
+                        ** H - Billing hours
+                        ** F - finnish date
+                        ** C% - Status change
+                        ** L - Location changed
+                        ** M - Mail sent to vendor
+                        */
+
+                       $this->db->query("UPDATE phpgw_helpdesk_tickets SET 
publish_note = NULL WHERE id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("UPDATE phpgw_history_log SET publish 
= NULL WHERE history_record_id = {$id}",__LINE__,__FILE__);
+                       if(isset($ticket['publish_note']))
+                       {
+                               foreach ($ticket['publish_note'] as 
$publish_info)
+                               {
+                                       $note = explode('_', $publish_info);
+                                       if(!$note[1])
+                                       {
+                                               $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET publish_note = 1 WHERE id = 
{$note[0]}",__LINE__,__FILE__);
+                                       }
+                                       else
+                                       {
+                                               $this->db->query("UPDATE 
phpgw_history_log SET publish = 1 WHERE history_id = 
{$note[1]}",__LINE__,__FILE__);
+                                       }
+                               }
+                       }
+
+                       $finnish_date   = (isset($ticket['finnish_date']) ? 
phpgwapi_datetime::date_to_timestamp($ticket['finnish_date']):'');
+
+                       if ($oldfinnish_date && isset($ticket['finnish_date']) 
&& $ticket['finnish_date'])
+                       {
+                               $this->db->query("update phpgw_helpdesk_tickets 
set finnish_date2='" . $finnish_date
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                       }
+                       else if(!$oldfinnish_date && 
isset($ticket['finnish_date']) && $ticket['finnish_date'])
+                       {
+                               $this->db->query("update phpgw_helpdesk_tickets 
set finnish_date='" . $finnish_date
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                       }
+
+                       if($oldfinnish_date2>0)
+                       {
+                               $oldfinnish_date = $oldfinnish_date2;
+                       }
+                       if(isset($ticket['finnish_date']) && 
$ticket['finnish_date'])
+                       {
+                               if ($oldfinnish_date != $finnish_date)
+                               {
+                                       $this->fields_updated = true;
+                                       
$this->historylog->add('F',$id,$finnish_date,$oldfinnish_date);
+                               }
+                       }
+
+                       if (isset($ticket['status']) && ($old_status != 
$ticket['status']))
+                       {
+                               $check_old_custom = (int) trim($old_status,'C');
+                               $this->db->query("SELECT * from 
phpgw_helpdesk_status WHERE id = {$check_old_custom}",__LINE__,__FILE__);
+                               $this->db->next_record();
+                               $this->fields_updated = true;
+                               if($old_status=='X' || $this->db->f('closed'))
+                               {
+                                       $new_status = $ticket['status'];
+                                       
$this->historylog->add('R',$id,$ticket['status'],$old_status);
+
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$new_status}' WHERE id= 
{$id}",__LINE__,__FILE__);
+                               }
+                               else
+                               {
+                                       
$this->historylog->add($ticket['status'],$id,$ticket['status'],$old_status);
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$ticket['status']}' WHERE 
id={$id}",__LINE__,__FILE__);
+                               }
+                               $this->check_pending_action($ticket, $id);
+                       }
+
+                       if (($oldassigned != $ticket['assignedto']) && 
$ticket['assignedto'] != 'ignore')
+                       {
+                               $this->fields_updated = true;
+
+                               $value_set=array('assignedto'   => 
$ticket['assignedto']);
+                               $value_set      = 
$this->db->validate_update($value_set);
+
+                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('A',$id,$ticket['assignedto'],$oldassigned);
+                       }
+
+                       if (($oldgroup_id != $ticket['group_id']) && 
$ticket['group_id'] != 'ignore')
+                       {
+                               $this->fields_updated = true;
+
+                               $value_set=array('group_id'     => 
$ticket['group_id']);
+                               $value_set      = 
$this->db->validate_update($value_set);
+
+                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('G',$id,$ticket['group_id'],$oldgroup_id);
+                       }
+
+                       if ($oldpriority != $ticket['priority'])
+                       {
+                               $this->fields_updated = true;
+                               $this->db->query("update phpgw_helpdesk_tickets 
set priority='" . $ticket['priority']
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('P',$id,$ticket['priority'],$oldpriority);
+                       }
+
+                       if ($old_contact_id != $ticket['contact_id'])
+                       {
+                               $contact_id  = (int) $ticket['contact_id'];
+                               $this->fields_updated = true;
+                               $this->db->query("update phpgw_helpdesk_tickets 
set contact_id={$contact_id} WHERE id=$id",__LINE__,__FILE__);
+                       }
+
+                       if (($oldcat_id != $ticket['cat_id']) && 
$ticket['cat_id'] != 'ignore')
+                       {
+                               $this->fields_updated = true;
+                               $this->db->query("update phpgw_helpdesk_tickets 
set cat_id='" . $ticket['cat_id']
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('T',$id,$ticket['cat_id'],$oldcat_id);
+                       }
+
+                       if ($old_budget != $ticket['budget'])
+                       {
+                               $this->fields_updated = true;
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
set budget='" . (int)$ticket['budget']
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('B',$id,$ticket['budget'],$old_budget);
+                       }
+       /*
+                       if ($old_billable_rate != $ticket['billable_rate'])
+                       {
+                               $this->fields_updated = true;
+                               $this->db->query("update phpgw_helpdesk_tickets 
set billable_rate='" . $ticket['billable_rate']
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('B',$id,$ticket['billable_rate'],$old_billable_rate);
+                       }
+        */
+                       if ($old_subject != $ticket['subject'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET subject='" . $ticket['subject']
+                                       . "' where id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('S',$id,$ticket['subject'],$old_subject);
+                               $receipt['message'][]= array('msg' => 
lang('Subject has been updated'));
+                       }
+
+                       if($ticket['billable_hours'])
+                       {
+                               $ticket['billable_hours'] = 
str_replace(',','.', $ticket['billable_hours']);
+                       }
+                       if ((float)$old_billable_hours != 
(float)$ticket['billable_hours'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET billable_hours='{$ticket['billable_hours']}'"
+                                       . " WHERE 
id='{$id}'",__LINE__,__FILE__);
+                               
$this->historylog->add('H',$id,$ticket['billable_hours'],$old_billable_hours);
+                               $receipt['message'][]= array('msg' => 
lang('billable hours has been updated'));
+                       }
+
+                       if ((int)$old_actual_cost != 
(int)$ticket['actual_cost'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET actual_cost='" . (float)$ticket['actual_cost']
+                                       . "' WHERE id='$id'",__LINE__,__FILE__);
+                               
$this->historylog->add('AC',$id,(float)$ticket['actual_cost'] , 
$old_actual_cost);
+                               $receipt['message'][]= array('msg' => 
lang('actual_cost has been updated'));
+                       }
+
+                       if ((int)$old_order_cat_id != 
(int)$ticket['order_cat_id'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET order_cat_id='" . (int)$ticket['order_cat_id']
+                                       . "' WHERE id='$id'",__LINE__,__FILE__);
+                               $receipt['message'][]= array('msg' => 
lang('order category has been updated'));
+                               $this->fields_updated = true;
+                       }
+
+                       if ((int)$old_order_dim1 != (int)$ticket['order_dim1'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET order_dim1='" . (int)$ticket['order_dim1']
+                                       . "' WHERE id='$id'",__LINE__,__FILE__);
+                               $receipt['message'][]= array('msg' => 
lang('order_dim1 has been updated'));
+                               $this->fields_updated = true;
+                       }
+
+                       if ($old_building_part != $ticket['building_part'])
+                       {
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET building_part='" . $ticket['building_part']
+                                       . "' WHERE id='$id'",__LINE__,__FILE__);
+                               $receipt['message'][]= array('msg' => 
lang('building part has been updated'));
+                               $this->fields_updated = true;
+                       }
+
+                       if (($old_note != $ticket['note']) && $ticket['note'])
+                       {
+                               $this->fields_updated = true;
+                               
$this->historylog->add('C',$id,$ticket['note'],$old_note);
+                               $_history_id = 
$this->db->get_last_insert_id('phpgw_helpdesk_history','history_id');
+                               $this->db->query("UPDATE phpgw_helpdesk_history 
SET publish = 1 WHERE history_id = $_history_id",__LINE__,__FILE__);
+                               unset($_history_id);
+                       }
+
+                       if(isset($ticket['location']) && $ticket['location'])
+                       {
+                               $ticket['location_code'] = implode('-', 
$ticket['location']);
+                       }
+
+                       if (isset($ticket['location_code']) && 
$ticket['location_code'] && ($oldlocation_code != $ticket['location_code']))
+                       {
+                               $interlink      = 
CreateObject('helpdesk.interlink');
+                               if( $interlink->get_relation('helpdesk', 
'.ticket', $id, 'origin') || $interlink->get_relation('helpdesk', '.ticket', 
$id, 'target'))
+                               {
+                                       $receipt['message'][]= array('msg' => 
lang('location could not be changed'));
+                               }
+                               else
+                               {
+                                       $value_set      = array();
+
+                                       if(isset($ticket['street_name']) && 
$ticket['street_name'])
+                                       {
+                                               $address[]= 
$ticket['street_name'];
+                                               $address[]= 
$ticket['street_number'];
+                                               $value_set['address'] = 
$this->db->db_addslashes(implode(" ", $address));
+                                       }
+
+                                       if(!isset($address) || !$address)
+                                       {
+                                               $address = 
isset($ticket['location_name']) ? 
$this->db->db_addslashes($ticket['location_name']) : '';
+                                               if($address)
+                                               {
+                                                       $value_set['address'] = 
$address;
+                                               }
+                                       }
+
+                                       if (isset($ticket['location_code']) && 
$ticket['location_code'])
+                                       {
+                                               $value_set['location_code'] = 
$ticket['location_code'];
+                                       }
+
+                                       $admin_location = 
CreateObject('helpdesk.soadmin_location');
+                                       $admin_location->read(false);
+
+                                       // Delete old values for location - in 
case of moving up in the hierarchy
+                                       $metadata = 
$this->db->metadata('phpgw_helpdesk_tickets');
+                                       for ($i = 1;$i < 
$admin_location->total_records + 1; $i++)
+                                       {
+                                               if(isset($metadata["loc{$i}"]))
+                                               {
+                                                       $value_set["loc{$i}"]   
= false;
+                                               }
+                                       }
+
+                                       if(isset($ticket['location']) && 
is_array($ticket['location']))
+                                       {
+                                               foreach ($ticket['location'] as 
$column => $value)
+                                               {
+                                                       $value_set[$column]     
= $value;
+                                               }
+                                       }
+
+                                       if(isset($ticket['extra']) && 
is_array($ticket['extra']))
+                                       {
+                                               foreach ($ticket['extra'] as 
$column => $value)
+                                               {
+                                                       $value_set[$column]     
= $value;
+                                               }
+                                       }
+
+                                       $value_set      = 
$this->db->validate_update($value_set);
+
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET $value_set WHERE id={$id}",__LINE__,__FILE__);
+
+                                       
$this->historylog->add('L',$id,$ticket['location_code'],$oldlocation_code);
+                                       $receipt['message'][]= array('msg' => 
lang('Location has been updated'));
+                               }
+                               unset($interlink);
+                       }
+
+
+                       if(isset($ticket['make_order']) && 
$ticket['make_order'])
+                       {
+                               $order_id = 
execMethod('property.socommon.increment_id', 'helpdesk');
+                               if($order_id)
+                               {
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET order_id = {$order_id} WHERE 
id={$id}",__LINE__,__FILE__);
+                                       $this->db->query("INSERT INTO fm_orders 
(id, type) VALUES ({$order_id}, 'helpdesk')",__LINE__,__FILE__);
+                               }
+                       }
+
+                       $value_set                                      = 
array();
+                       $value_set['vendor_id']         = $ticket['vendor_id'];
+                       $value_set['b_account_id']      = 
$ticket['b_account_id'];
+                       $value_set['order_descr']       = 
$this->db->db_addslashes($ticket['order_descr']);
+                       $value_set['ecodimb']           = $ticket['ecodimb'];
+                       $value_set['budget']            = $ticket['budget'];
+                       $value_set                                      = 
$this->db->validate_update($value_set);
+                       $this->db->query("UPDATE phpgw_helpdesk_tickets SET 
$value_set WHERE id={$id}",__LINE__,__FILE__);
+
+                       $this->db->transaction_commit();
+
+                       if (isset($this->fields_updated))
+                       {
+                               $receipt['message'][]= array('msg' => 
lang('Ticket has been updated'));
+
+                               $criteria = array
+                                       (
+                                               'appname'       => 'helpdesk',
+                                               'location'      => 
$this->acl_location,
+                                               'allrows'       => true
+                                       );
+
+                               $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
+
+                               foreach ( $custom_functions as $entry )
+                               {
+                                       // prevent path traversal
+                                       if ( preg_match('/\.\./', 
$entry['file_name']) )
+                                       {
+                                               continue;
+                                       }
+
+                                       $file = PHPGW_SERVER_ROOT . 
"/helpdesk/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+                                       if ( $entry['active'] && is_file($file) 
)
+                                       {
+                                               require_once $file;
+                                       }
+                               }
+                       }
+                       return $receipt;
+               }
+
+               function check_pending_action($ticket,$id)
+               {
+                       $status = (int)trim($ticket['status'], 'C');
+                       $this->db->query("SELECT * FROM phpgw_helpdesk_status 
WHERE id = '{$status}'");
+
+                       $this->db->next_record();
+
+                       if ($this->db->f('approved') )
+                       {
+                               $action_params = array
+                                       (
+                                               'appname'                       
=> 'helpdesk',
+                                               'location'                      
=> '.ticket',
+                                               'id'                            
=> $id,
+                                               'responsible'           => 
$this->account,
+                                               'responsible_type'  => 'user',
+                                               'action'                        
=> 'approval',
+                                               'remark'                        
=> '',
+                                               'deadline'                      
=> ''
+                                       );
+
+                               
execMethod('helpdesk.sopending_action.close_pending_action', $action_params);
+                               unset($action_params);
+                       }
+                       if ($this->db->f('in_progress') )
+                       {
+                               $action_params = array
+                                       (
+                                               'appname'                       
=> 'helpdesk',
+                                               'location'                      
=> '.ticket',
+                                               'id'                            
=> $id,
+                                               'responsible'           => 
$ticket['vendor_id'],
+                                               'responsible_type'  => 'vendor',
+                                               'action'                        
=> 'remind',
+                                               'remark'                        
=> '',
+                                               'deadline'                      
=> ''
+                                       );
+
+                               
execMethod('helpdesk.sopending_action.close_pending_action', $action_params);
+                               unset($action_params);
+                       }
+
+                       if ($this->db->f('delivered') )
+                       {
+                               //close
+                       }
+               }
+
+               function delete($id)
+               {
+                       $id = (int)$id;
+
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('helpdesk', '.ticket');
+
+                       if ( !$location_id )
+                       {
+                               throw new Exception("phpgwapi_locations::get_id 
('helpdesk', '.ticket') returned 0");
+                       }
+
+                       $this->db->transaction_begin(); 
+
+                       $this->db->query("DELETE FROM fm_action_pending WHERE 
location_id = {$location_id} AND item_id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_interlink WHERE 
location1_id = {$location_id} AND location1_item_id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_interlink WHERE 
location2_id = {$location_id} AND location2_item_id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_helpdesk_history 
WHERE history_record_id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_helpdesk_views 
WHERE id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_helpdesk_tickets 
WHERE id = {$id}",__LINE__,__FILE__);
+
+                       if($this->db->transaction_commit())
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               }
+       }

Added: trunk/helpdesk/inc/class.uitts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.uitts.inc.php                              (rev 0)
+++ trunk/helpdesk/inc/class.uitts.inc.php      2011-01-07 07:59:59 UTC (rev 
6733)
@@ -0,0 +1,2330 @@
+<?php
+       /**
+       * phpGroupWare - helpdesk: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare is free software; you can redistribute it and/or modify
+       * it under the terms of the GNU General Public License as published by
+       * the Free Software Foundation; either version 2 of the License, or
+       * (at your option) any later version.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+       * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+       * @package helpdesk
+       * @subpackage helpdesk
+       * @version $Id: class.uitts.inc.php 6705 2010-12-26 23:10:55Z sigurdne $
+       */
+
+       /**
+        * Description
+        * @package helpdesk
+        */
+
+       phpgw::import_class('phpgwapi.yui');
+
+       class helpdesk_uitts
+       {
+               var $public_functions = array
+                       (
+                               'index'                         => true,
+                               'view'                          => true,
+                               'add'                           => true,
+                               'delete'                        => true,
+                               'download'                      => true,
+                               'view_file'                     => true,
+                               'edit_status'           => true,
+                               'get_vendor_email'      => true,
+                               '_print'                        => true,
+                               'columns'                       => true
+                       );
+
+               /**
+                * @var boolean $_simple use simplified interface
+                */
+               protected $_simple = false;
+               protected $_show_finnish_date = false;
+               protected $_category_acl = false;
+               var $part_of_town_id;
+               var $status;
+               var $filter;
+               var $user_filter;
+
+               public function __construct()
+               {
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
'helpdesk::helpdesk';
+                       if($this->tenant_id     = 
$GLOBALS['phpgw']->session->appsession('tenant_id','helpdesk'))
+                       {
+                               //                      
$GLOBALS['phpgw_info']['flags']['noframework'] = true;
+                               $GLOBALS['phpgw_info']['flags']['noheader'] = 
true;
+                               $GLOBALS['phpgw_info']['flags']['nofooter'] = 
true;
+                       }
+
+                       $this->account                          = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = true;
+                       $this->nextmatchs                       = 
CreateObject('phpgwapi.nextmatchs');
+                       $this->bo                                       = 
CreateObject('helpdesk.botts',true);
+                       $this->bocommon                         = & 
$this->bo->bocommon;
+                       $this->cats                                     = & 
$this->bo->cats;
+                       $this->acl                                      = & 
$GLOBALS['phpgw']->acl;
+                       $this->acl_location                     = 
$this->bo->acl_location;
+                       $this->acl_read                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_READ, 'helpdesk');
+                       $this->acl_add                          = 
$this->acl->check($this->acl_location, PHPGW_ACL_ADD, 'helpdesk');
+                       $this->acl_edit                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_EDIT, 'helpdesk');
+                       $this->acl_delete                       = 
$this->acl->check($this->acl_location, PHPGW_ACL_DELETE, 'helpdesk');
+                       $this->acl_manage                       = 
$this->acl->check($this->acl_location, PHPGW_ACL_PRIVATE, 'helpdesk'); // manage
+                       $this->bo->acl_location         = $this->acl_location;
+
+                       $this->start                            = 
$this->bo->start;
+                       $this->query                            = 
$this->bo->query;
+                       $this->sort                                     = 
$this->bo->sort;
+                       $this->order                            = 
$this->bo->order;
+                       $this->status_id                        = 
$this->bo->status_id;
+                       $this->user_id                          = 
$this->bo->user_id;
+                       $this->cat_id                           = 
$this->bo->cat_id;
+                       $this->district_id                      = 
$this->bo->district_id;
+                       $this->allrows                          = 
$this->bo->allrows;
+                       $this->start_date                       = 
$this->bo->start_date;
+                       $this->end_date                         = 
$this->bo->end_date;
+                       $this->location_code            = 
$this->bo->location_code;
+                       $this->p_num                            = 
$this->bo->p_num;
+                       $user_groups =  
$GLOBALS['phpgw']->accounts->membership($this->account);
+                       $simple_group = 
isset($this->bo->config->config_data['fmttssimple_group']) ? 
$this->bo->config->config_data['fmttssimple_group'] : array();
+                       foreach ( $user_groups as $group => $dummy)
+                       {
+                               if ( in_array($group, $simple_group))
+                               {
+                                       $this->_simple = true;
+                                       break;
+                               }
+                       }
+
+                       reset($user_groups);
+                       $group_finnish_date = 
isset($this->bo->config->config_data['fmtts_group_finnish_date']) ? 
$this->bo->config->config_data['fmtts_group_finnish_date'] : array();
+                       foreach ( $user_groups as $group => $dummy)
+                       {
+                               if ( in_array($group, $group_finnish_date))
+                               {
+                                       $this->_show_finnish_date = true;
+                                       break;
+                               }
+                       }
+
+                       $this->_category_acl = 
isset($this->bo->config->config_data['acl_at_tts_category']) ? 
$this->bo->config->config_data['acl_at_tts_category'] : false;
+               }
+
+               function save_sessiondata()
+               {
+                       $data = array
+                               (
+                                       'start'                 => $this->start,
+                                       'query'                 => $this->query,
+                                       'sort'                  => $this->sort,
+                                       'order'                 => $this->order,
+                                       'status_id'             => 
$this->status_id,
+                                       'user_id'               => 
$this->user_id,
+                                       'cat_id'                => 
$this->cat_id,
+                                       'district_id'   => $this->district_id,
+                                       'allrows'               => 
$this->allrows,
+                                       'start_date'    => $this->start_date,
+                                       'end_date'              => 
$this->end_date
+                               );
+                       $this->bo->save_sessiondata($data);
+               }
+
+               function _print()
+               {
+                       if(!$this->acl_read)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+                       }
+
+                       $GLOBALS['phpgw_info']['flags']['noheader'] = true;
+                       $GLOBALS['phpgw_info']['flags']['nofooter'] = true;
+                       $GLOBALS['phpgw_info']['flags']['xslt_app'] = false;
+                       $id     = phpgw::get_var('id', 'int');
+
+                       $ticket = $this->bo->mail_ticket($id, 
$fields_updated=true, $receipt = array(),$location_code='', $get_message = 
true);
+
+                       $html = 
"<html><head><title>{$ticket['subject']}</title></head>";
+                       $html .= "<body>";
+                       $html .= $ticket['subject'] . '</br></br>';
+                       $html .= nl2br($ticket['body']);
+                       $html .= "</body></html>";
+
+                       echo $html;
+               }
+
+               function download()
+               {
+                       $start_date     = urldecode($this->start_date);
+                       $end_date       = urldecode($this->end_date);
+
+                       $this->bo->allrows = true;
+                       $list = $this->bo->read($start_date,$end_date,'', 
$download = true);
+
+                       $custom_status  = $this->bo->get_custom_status();
+
+                       $status = array();
+                       $status['O'] = 
isset($this->bo->config->config_data['tts_lang_open']) && 
$this->bo->config->config_data['tts_lang_open'] ? 
$this->bo->config->config_data['tts_lang_open'] : lang('Open');
+                       $status['X'] = lang('Closed');
+                       foreach($custom_status as $custom)
+                       {
+                               $status["C{$custom['id']}"] = $custom['name'];
+                       }
+
+                       foreach($list as &$entry)
+                       {
+                               $entry['status'] = $status[$entry['status']];
+
+                               if (isset($entry['child_date']) AND 
is_array($entry['child_date']))
+                               {
+                                       $j=0;
+                                       foreach($entry['child_date'] as $date)
+                                       {
+                                               
if($date['date_info'][0]['descr'])
+                                               {
+                                                       $entry["date_{$j}"]     
                = $date['date_info'][0]['entry_date'];
+                                                       $name_temp["date_{$j}"] 
        = true;
+                                                       
$descr_temp["date_{$j}"]        = $date['date_info'][0]['descr'];
+                                               }
+                                               $j++;
+                                       }
+                                       unset($entry['child_date']);
+                               }
+                       }
+
+                       $name   = array();
+                       $name[] = 'priority';
+                       $name[] = 'id';
+                       $name[] = 'category';
+                       $name[] = 'subject';
+                       $name[] = 'user';
+                       $name[] = 'assignedto';
+                       $name[] = 'entry_date';
+                       $name[] = 'status';
+
+                       if( $this->acl->check('.ticket.order', PHPGW_ACL_READ, 
'helpdesk') )
+                       {
+                               $name[] = 'order_id';
+                               $name[] = 'vendor';
+                       }
+
+                       if( $this->acl->check('.ticket.order', PHPGW_ACL_ADD, 
'helpdesk') )
+                       {
+                               $name[] = 'estimate';
+                               $name[] = 'actual_cost';
+                       }
+
+                       $uicols_related = $this->bo->uicols_related;
+
+                       foreach($uicols_related as $related)
+                       {
+                               //                                      $name[] 
= $related;
+                       }
+
+                       $descr = array();
+                       foreach($name as $_entry)
+                       {
+                               //                              $descr[] = 
str_replace('_', ' ', $_entry);
+                               $descr[] = lang(str_replace('_', ' ', $_entry));
+                       }
+
+                       foreach($name_temp as $_key => $_name)
+                       {
+                               array_push($name,$_key);                        
+                       }
+
+
+                       foreach($descr_temp as $_key => $_name)
+                       {
+                               array_push($descr,$_name);                      
+                       }
+
+                       $name[] = 'finnish_date';
+                       $name[] = 'delay';
+
+                       array_push($descr,lang('finnish date'),lang('delay'));
+
+
+                       $custom_cols = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] 
: array();
+
+                       foreach ($custom_cols as $col)
+                       {
+                               $name[]                 = $col;
+                               $descr[]                = lang(str_replace('_', 
' ', $col));
+                       }
+
+                       $this->bocommon->download($list,$name,$descr);
+               }
+
+               function edit_status()
+               {
+                       if(!$this->acl_edit)
+                       {
+                               return lang('sorry - insufficient rights');
+                       }
+
+
+                       $new_status = phpgw::get_var('new_status', 'string', 
'GET');
+                       $id             = phpgw::get_var('id', 'int');
+                       $receipt        = 
$this->bo->update_status(array('status'=>$new_status),$id);
+                       if 
(isset($this->bo->config->config_data['mailnotification']) && 
$this->bo->config->config_data['mailnotification'])
+                       {
+                               $receipt = $this->bo->mail_ticket($id, 
$this->bo->fields_updated, $receipt);
+                       }
+                       //      
$GLOBALS['phpgw']->session->appsession('receipt','helpdesk',$receipt);
+                       return "id ".$id." ".lang('Status has been changed');
+               }
+
+               function delete()
+               {
+                       if(!$this->acl_delete)
+                       {
+                               return lang('sorry - insufficient rights');
+                       }
+
+                       $id = phpgw::get_var('id', 'int');
+                       if( $this->bo->delete($id) )
+                       {
+                               return lang('ticket %1 has been deleted', $id);
+                       }
+                       else
+                       {
+                               return lang('delete failed');                   
+                       }
+               }
+
+               function columns()
+               {
+                       $receipt = array();
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('columns'));
+
+                       $GLOBALS['phpgw_info']['flags']['noframework'] = true;
+                       $GLOBALS['phpgw_info']['flags']['nofooter'] = true;
+
+                       $values                 = phpgw::get_var('values');
+
+                       
$GLOBALS['phpgw']->preferences->set_account_id($this->account, true);
+
+                       if (isset($values['save']) && $values['save'])
+                       {
+                               
$GLOBALS['phpgw']->preferences->add('helpdesk','ticket_columns', 
$values['columns'],'user');
+                               
$GLOBALS['phpgw']->preferences->save_repository();
+                               $receipt['message'][] = array('msg' => 
lang('columns is updated'));
+                       }
+
+                       $function_msg   = lang('Select Column');
+
+                       $link_data = array
+                               (
+                                       'menuaction'    => 
'helpdesk.uitts.columns',
+                               );
+
+                       $selected = isset($values['columns']) && 
$values['columns'] ? $values['columns'] : array();
+                       $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox_data($receipt);
+
+                       $data = array
+                               (
+                                       'msgbox_data'           => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                                       'column_list'           => 
$this->bo->column_list($selected , $this->type_id, $allrows=true),
+                                       'function_msg'          => 
$function_msg,
+                                       'form_action'           => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
+                                       'lang_columns'          => 
lang('columns'),
+                                       'lang_none'                     => 
lang('None'),
+                                       'lang_save'                     => 
lang('save'),
+                               );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
$function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('columns' => $data));
+               }
+
+
+               function index()
+               {
+                       if($this->tenant_id)
+                       {
+                               //                              
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index2'));
+                       }
+
+                       if(!$this->acl_read)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
+                       }
+
+                       $this->save_sessiondata();
+                       $dry_run = false;
+                       $second_display = phpgw::get_var('second_display', 
'bool');
+
+                       $default_category       = 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['default_district'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['default_district']:'');
+                       //FIXME: differentiate mainsreen and helpdesk if this 
should be used.
+                       $default_status         = 
'';//isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status']:'';
+                       $start_date             = urldecode($this->start_date);
+                       $end_date                       = 
urldecode($this->end_date);
+
+                       if ($default_category && !$second_display && 
!$this->district_id)
+                       {
+                               $this->bo->district_id  = $default_category;
+                               $this->district_id              = 
$default_category;
+                       }
+
+                       if ($default_status && !$second_display)
+                       {
+                               $this->bo->status_id    = $default_status;
+                               $this->status_id                = 
$default_status;
+                       }
+
+                       $bgcolor_array[1]       = '#da7a7a';
+                       $bgcolor_array[2]       = '#dababa';
+                       $bgcolor_array[3]       = '#dadada';
+
+                       $lookup                 = phpgw::get_var('lookup', 
'bool');
+                       $from                   = phpgw::get_var('from');
+                       $start_date     = 
urldecode(phpgw::get_var('start_date'));
+                       $end_date               = 
urldecode(phpgw::get_var('end_date'));
+                       $allrows                = phpgw::get_var('allrows', 
'bool');
+
+                       $datatable = array();
+
+                       if( phpgw::get_var('phpgw_return_as') != 'json' )
+                       {
+                               $datatable['menu']                              
        = $this->bocommon->get_menu();
+                               $datatable['config']['base_url'] = 
$GLOBALS['phpgw']->link('/index.php', array
+                                       (
+                                               'menuaction'            => 
'helpdesk.uitts.index',
+                                               'query'                         
=> $this->query,
+                                               'district_id'           => 
$this->district_id,
+                                               'part_of_town_id'       => 
$this->part_of_town_id,
+                                               'cat_id'                        
=> $this->cat_id,
+                                               'status_id'                     
=> $this->status_id,
+                                               'p_num'                         
=> $this->p_num
+                                       )
+                               );
+
+                               $datatable['config']['allow_allrows'] = true;
+
+                               $datatable['config']['base_java_url'] = 
"menuaction:'helpdesk.uitts.index',"
+                                       ."second_display:1,"
+                                       ."sort: '{$this->sort}',"
+                                       ."order: '{$this->order}',"
+                                       ."cat_id:'{$this->cat_id}',"
+                                       ."status_id: '{$this->status_id}',"
+                                       ."user_id: '{$this->user_id}',"
+                                       ."query: '{$this->query}',"
+                                       ."p_num: '{$this->p_num}',"
+                                       ."district_id: '{$this->district_id}',"
+                                       ."start_date: '{$start_date}',"
+                                       ."end_date: '{$end_date}',"
+                                       ."location_code: 
'{$this->location_code}',"
+                                       ."allrows:'{$this->allrows}'";
+
+                               $link_data = array
+                                       (
+                                               'menuaction'    => 
'helpdesk.uitts.index',
+                                               'second_display'=> true,
+                                               'sort'                  => 
$this->sort,
+                                               'order'                 => 
$this->order,
+                                               'cat_id'                => 
$this->cat_id,
+                                               'status_id'             => 
$this->status_id,
+                                               'user_id'               => 
$this->user_id,
+                                               'query'                 => 
$this->query,
+                                               'district_id'   => 
$this->district_id,
+                                               'start_date'    => $start_date,
+                                               'end_date'              => 
$end_date,
+                                               'location_code' => 
$this->location_code,
+                                               'allrows'               => 
$this->allrows
+                                       );
+
+                               $group_filters = 'select';
+
+                               $values_combo_box = array();
+
+                               $values_combo_box[1]  = 
$this->bo->filter(array('format' => $group_filters, 'filter'=> 
$this->status_id,'default' => 'O'));
+
+                               
if(isset($this->bo->config->config_data['tts_lang_open']) && 
$this->bo->config->config_data['tts_lang_open'])
+                               {
+                                       array_unshift 
($values_combo_box[1],array 
('id'=>'O2','name'=>$this->bo->config->config_data['tts_lang_open']));
+                               }
+                               $default_value = array 
('id'=>'','name'=>lang('Open'));
+                               array_unshift 
($values_combo_box[1],$default_value);
+
+                               if(!$this->_simple)
+                               {
+                                       $values_combo_box[0] = 
$this->cats->formatted_xslt_list(array('format'=>'filter','selected' => 
$this->cat_id,'globals' => true,'use_acl' => $this->_category_acl));
+                                       $default_value = array 
('cat_id'=>'','name'=> lang('no category'));
+                                       array_unshift 
($values_combo_box[0]['cat_list'],$default_value);
+
+                                       $values_combo_box[2]  = 
$this->bocommon->get_user_list_right2('filter_',PHPGW_ACL_EDIT,$this->user_id,$this->acl_location);
+                                       array_unshift 
($values_combo_box[2],array('id'=>$GLOBALS['phpgw_info']['user']['account_id'],'name'=>lang('mine
 tickets')));
+                                       $default_value = 
array('id'=>'','name'=>lang('no user'));
+                                       array_unshift 
($values_combo_box[2],$default_value);
+
+                                       $datatable['actions']['form'] = array
+                                               (
+                                                       array
+                                                       (
+                                                               'action'        
=> $GLOBALS['phpgw']->link('/index.php',
+                                                               array
+                                                               (
+                                                                       
'menuaction'            => 'helpdesk.uitts.index',
+                                                                       
'second_display'       => $second_display,
+                                                                       
'district_id'       => $this->district_id,
+                                                                       
'part_of_town_id'   => $this->part_of_town_id,
+                                                                       
'cat_id'                => $this->cat_id,
+                                                                       
'status'                        => $this->status
+                                                               )
+                                                       ),
+                                                       'fields'        => array
+                                                       (
+                                                               'field' => array
+                                                               (
+                                                                       array
+                                                                       ( 
//boton       CATEGORY
+                                                                               
'id' => 'btn_cat_id',
+                                                                               
'name' => 'cat_id',
+                                                                               
'value' => lang('Category'),
+                                                                               
'type' => 'button',
+                                                                               
'style' => 'filter',
+                                                                               
'tab_index' => 1
+                                                                       ),
+                                                                       array
+                                                                       ( 
//boton       HOUR CATEGORY
+                                                                               
'id' => 'btn_status_id',
+                                                                               
'name' => 'status_id',
+                                                                               
'value' => lang('Status'),
+                                                                               
'type' => 'button',
+                                                                               
'style' => 'filter',
+                                                                               
'tab_index' => 3
+                                                                       ),
+                                                                       array
+                                                                       ( 
//boton       USER
+                                                                               
//      'id' => 'btn_user_id',
+                                                                               
'id' => 'sel_user_id', // testing traditional listbox for long list
+                                                                               
'name' => 'user_id',
+                                                                               
'value' => lang('User'),
+                                                                               
'type' => 'select',
+                                                                               
'style' => 'filter',
+                                                                               
'values' => $values_combo_box[2],
+                                                                               
'onchange'=> 'onChangeSelect();',
+                                                                               
'tab_index' => 4
+                                                                       ),
+                                                                       array
+                                                                       (//for 
link "columns", next to Export button
+                                                                               
'type' => 'link',
+                                                                               
'id' => 'btn_columns',
+                                                                               
'url' => "Javascript:window.open('".$GLOBALS['phpgw']->link('/index.php',
+                                                                               
array
+                                                                               
(
+                                                                               
        'menuaction' => 'helpdesk.uitts.columns'
+                                                                               
)
+                                                                       
)."','','width=300,height=600,scrollbars=1')",
+                                                                       'value' 
=> lang('columns'),
+                                                                       
'tab_index' => 10
+                                                               ),
+                                                               array
+                                                               (
+                                                                       'type'  
=> 'button',
+                                                                       'id'    
=> 'btn_export',
+                                                                       'value' 
=> lang('download'),
+                                                                       
'tab_index' => 9
+                                                               ),
+                                                               array
+                                                               (
+                                                                       'type'  
=> 'button',
+                                                                       'id'    
=> 'btn_new',
+                                                                       'value' 
=> lang('add'),
+                                                                       
'tab_index' => 8
+                                                               ),
+                                                               array
+                                                               ( //hidden 
start_date
+                                                                       'type' 
=> 'hidden',
+                                                                       'id' => 
'start_date',
+                                                                       'value' 
=> $start_date
+                                                               ),
+                                                               array
+                                                               ( //hidden 
end_date
+                                                                       'type' 
=> 'hidden',
+                                                                       'id' => 
'end_date',
+                                                                       'value' 
=> $end_date
+                                                               ),
+                                                               array
+                                                               (//for link 
"None",
+                                                                       
'type'=> 'label_date'
+                                                               ),
+                                                               array
+                                                               (//for link 
"Date search",
+                                                                       
'type'=> 'link',
+                                                                       'id'  
=> 'btn_data_search',
+                                                                       'url' 
=> "Javascript:window.open('".$GLOBALS['phpgw']->link('/index.php',
+                                                                       array
+                                                                       (
+                                                                               
'menuaction' => 
'property.uiproject.date_search'))."','','width=350,height=250')",
+                                                                               
'value' => lang('Date search'),
+                                                                               
'tab_index' => 7
+                                                                       ),
+                                                                       array
+                                                                       ( 
//boton     SEARCH
+                                                                               
'id' => 'btn_search',
+                                                                               
'name' => 'search',
+                                                                               
'value'    => lang('search'),
+                                                                               
'type' => 'button',
+                                                                               
'tab_index' => 6
+                                                                       ),
+                                                                       array
+                                                                       ( // 
TEXT INPUT
+                                                                               
'name'     => 'query',
+                                                                               
'id'     => 'txt_query',
+                                                                               
'value'    => $this->query,
+                                                                               
'type' => 'text',
+                                                                               
'onkeypress' => 'return pulsar(event)',
+                                                                               
'size'    => 28,
+                                                                               
'tab_index' => 5
+                                                                       )
+                                                               ),
+                                                               'hidden_value' 
=> array
+                                                               (
+                                                                       array
+                                                                       ( //div 
values  combo_box_0
+                                                                               
'id' => 'values_combo_box_0',
+                                                                               
'value' => $this->bocommon->select2String($values_combo_box[0]['cat_list'], 
'cat_id') //i.e.  id,value/id,vale/
+                                                                       ),
+                                                                       array
+                                                                       ( //div 
values  combo_box_1
+                                                                               
'id' => 'values_combo_box_1',
+                                                                               
'value' => $this->bocommon->select2String($values_combo_box[1])
+                                                                       ),
+                                                                       array
+                                                                       ( //div 
values  combo_box_2
+                                                                               
'id' => 'values_combo_box_2',
+                                                                               
'value' => $this->bocommon->select2String($values_combo_box[2])
+                                                                       ),
+                                                               )
+                                                       )
+                                               )
+                                       );
+                               }
+                               else
+                               {
+                                       $datatable['actions']['form'] = array
+                                               (
+                                                       array
+                                                       (
+                                                               'action'        
=> $GLOBALS['phpgw']->link('/index.php',
+                                                               array
+                                                               (
+                                                                       
'menuaction'            => 'helpdesk.uitts.index',
+                                                                       
'second_display'       => $second_display,
+                                                                       
'status'                        => $this->status
+                                                               )
+                                                       ),
+                                                       'fields'        => array
+                                                       (
+                                                               'field' => array
+                                                               (
+                                                                       array
+                                                                       ( 
//boton       HOUR CATEGORY
+                                                                               
'id' => 'btn_status_id',
+                                                                               
'name' => 'status_id',
+                                                                               
'value' => lang('Status'),
+                                                                               
'type' => 'button',
+                                                                               
'style' => 'filter',
+                                                                               
'tab_index' => 3
+                                                                       ),
+                                                                       array
+                                                                       (
+                                                                               
'type'  => 'button',
+                                                                               
'id'    => 'btn_new',
+                                                                               
'value' => lang('add'),
+                                                                               
'tab_index' => 8
+                                                                       ),
+                                                                       array
+                                                                       ( 
//boton     SEARCH
+                                                                               
'id' => 'btn_search',
+                                                                               
'name' => 'search',
+                                                                               
'value'    => lang('search'),
+                                                                               
'type' => 'button',
+                                                                               
'tab_index' => 6
+                                                                       ),
+                                                                       array
+                                                                       ( // 
TEXT INPUT
+                                                                               
'name'     => 'query',
+                                                                               
'id'     => 'txt_query',
+                                                                               
'value'    => '',//$query,
+                                                                               
'type' => 'text',
+                                                                               
'onkeypress' => 'return pulsar(event)',
+                                                                               
'size'    => 28,
+                                                                               
'tab_index' => 5
+                                                                       )
+                                                               ),
+                                                               'hidden_value' 
=> array
+                                                               (
+                                                                       array
+                                                                       ( //div 
values  combo_box_0
+                                                                               
'id' => 'values_combo_box_0',
+                                                                               
'value' => $this->bocommon->select2String($values_combo_box[2])
+                                                                       )
+                                                               )
+                                                       )
+                                               )
+                                       );                              
+                               }
+                               $dry_run = true;
+                       }
+
+                       $ticket_list = array();
+                       //                      if(!$dry_run)
+                               {
+                                       $ticket_list = 
$this->bo->read($start_date, $end_date,'',$dry_run);
+                               }
+
+                       $this->bo->get_origin_entity_type();
+                       $uicols_related = $this->bo->uicols_related;
+                       //_debug_array($uicols_related);
+                       $uicols = array();
+
+                       $uicols['name'][] = 'priority';
+                       $uicols['name'][] = 'id';
+                       $uicols['name'][] = 'bgcolor';
+                       $uicols['name'][] = 'subject';
+                       $uicols['name'][] = 'assignedto';
+                       $uicols['name'][] = 'entry_date';
+                       $uicols['name'][] = 'status';
+
+                       if( $this->acl->check('.ticket.order', PHPGW_ACL_READ, 
'helpdesk') )
+                       {
+                               $uicols['name'][] = 'order_id';
+                               $uicols['name'][] = 'vendor';
+                       }
+
+                       if( $this->acl->check('.ticket.order', PHPGW_ACL_ADD, 
'helpdesk') )
+                       {
+                               $uicols['name'][] = 'estimate';
+                               $uicols['name'][] = 'actual_cost';
+                       }
+
+/*
+                       foreach($uicols_related as $related)
+                       {
+                               $uicols['name'][] = $related;                   
+                       }
+*/
+                       if( $this->_show_finnish_date )
+                       {
+                               $uicols['name'][] = 'finnish_date';
+                               $uicols['name'][] = 'delay';
+                       }
+
+                       $uicols['name'][] = 'child_date';
+                       $uicols['name'][] = 'link_view';
+                       $uicols['name'][] = 'lang_view_statustext';
+                       $uicols['name'][] = 'text_view';
+
+                       $custom_cols = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] 
? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] : 
array();
+
+                       foreach ($custom_cols as $col)
+                       {
+                               //                      $uicols['input_type'][] 
= 'text';
+                               $uicols['name'][]                       = $col;
+                               //                      $uicols['descr'][]      
        = lang(str_replace('_', ' ', $col));
+                               //                      $uicols['statustext'][] 
= $col;
+                       }
+
+
+                       $count_uicols_name = count($uicols['name']);
+
+
+                       $j = 0;
+                       $k = 0;
+                       if(is_array($ticket_list))
+                       {
+                               $status['X'] = array
+                                       (
+                                               'status'                        
=> lang('closed'),
+                                       );
+                               $status['O'] = array
+                                       (
+                                               'status'                        
=> isset($this->bo->config->config_data['tts_lang_open']) && 
$this->bo->config->config_data['tts_lang_open'] ? 
$this->bo->config->config_data['tts_lang_open'] : lang('Open'),
+                                       );
+                               $status['C'] = array
+                                       (
+                                               'status'                        
=> lang('closed'),
+                                       );
+
+                               $custom_status  = 
$this->bo->get_custom_status();
+
+                               foreach($custom_status as $custom)
+                               {
+                                       $status["C{$custom['id']}"] = array
+                                               (
+                                                       'status'                
        => $custom['name'],
+                                               );
+                               }
+
+                               foreach($ticket_list as $ticket)
+                               {
+                                       for ($k=0;$k<$count_uicols_name;$k++)
+                                       {
+                                               if($uicols['name'][$k] == 
'status' && array_key_exists($ticket[$uicols['name'][$k]],$status))
+                                               {
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['name']             = 
$uicols['name'][$k];
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['value']    = 
$status[$ticket[$uicols['name'][$k]]]['status'];
+                                               }
+                                               else
+                                               {
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['name']             = 
$uicols['name'][$k];
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['value']    = 
$ticket[$uicols['name'][$k]];
+                                               }
+                                               if($uicols['name'][$k] == 'id' 
|| $uicols['name'][$k] == 'entry_date')
+                                               {
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['format']   = 'link';
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['link']             =       
$GLOBALS['phpgw']->link('/index.php',array
+                                                               (
+                                                                       
'menuaction'    => 'helpdesk.uitts.view',
+                                                                       'id'    
                => $ticket['id']
+                                                               ));
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['value']    = 
$ticket[$uicols['name'][$k]] .  $ticket['new_ticket'];
+                                                       
$datatable['rows']['row'][$j]['column'][$k]['target']   = '_blank';
+                                               }
+
+                                               $n = 0;
+                                               foreach($uicols_related as 
$related)
+                                               {
+                                                       if($uicols['name'][$k] 
== $related)
+                                                       {
+                                                               
$datatable['rows']['row'][$j]['column'][$k]['format']   = 'link';
+                                                               
$datatable['rows']['row'][$j]['column'][$k]['link']             = 
$ticket['child_date'][$n]['date_info'][0]['link'];
+                                                               
$datatable['rows']['row'][$j]['column'][$k]['value']    = 
$ticket['child_date'][$n]['date_info'][0]['entry_date'];
+                                                               
$datatable['rows']['row'][$j]['column'][$k]['statustext']       = 
$ticket['child_date'][$n]['statustext'];
+                                                               
$datatable['rows']['row'][$j]['column'][$k]['target']   = '_blank';
+
+                                                       }
+                                                       $n++;
+                                               }
+                                       }
+
+                                       $j++;
+                               }
+                       }
+
+                       $parameters = array
+                               (
+                                       'parameter' => array
+                                       (
+                                               array
+                                               (
+                                                       'name'          => 'id',
+                                                       'source'        => 'id'
+                                               ),
+                                       )
+                               );
+
+                       if($this->acl_read)
+                       {
+                               $datatable['rowactions']['action'][] = array
+                                       (
+                                               'my_name'                       
=> 'view',
+                                               'statustext'    => lang('view 
the ticket'),
+                                               'text'                  => 
lang('view'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'helpdesk.uitts.view'
+                                               )),
+                                               'parameters'    => $parameters
+                                       );
+
+                               $datatable['rowactions']['action'][] = array
+                                       (
+                                               'my_name'                       
=> 'print',
+                                               'statustext'    => lang('print 
the ticket'),
+                                               'text'                  => 
lang('print view'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'helpdesk.uitts._print',
+                                                       'target'                
=> '_blank'
+                                               )),
+                                               'parameters'    => $parameters
+                                       );
+
+
+                               $jasper = execMethod('property.sojasper.read', 
array('location_id' => $GLOBALS['phpgw']->locations->get_id('helpdesk', 
$this->acl_location)));
+
+                               foreach ($jasper as $report)
+                               {
+                                       $datatable['rowactions']['action'][] = 
array
+                                               (
+                                                       'my_name'               
=> 'edit',
+                                                       'text'                  
=> lang('open JasperReport %1 in new window', $report['title']),
+                                                       'action'                
=> $GLOBALS['phpgw']->link('/index.php',array
+                                                       (
+                                                               'menuaction'    
=> 'property.uijasper.view',
+                                                               'jasper_id'     
                => $report['id'],
+                                                               'target'        
        => '_blank'
+                                                       )),
+                                                       'parameters'            
        => $parameters
+                                               );
+                               }
+                       }
+                       if($this->acl_delete)
+                       {
+                               $datatable['rowactions']['action'][] = array
+                                       (
+                                               'my_name'                       
=> 'delete',
+                                               'statustext'    => lang('delete 
the ticket'),
+                                               'text'                  => 
lang('delete'),
+                                               'confirm_msg'   => lang('do you 
really want to delete this ticket'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'helpdesk.uitts.delete'
+                                               )),
+                                               'parameters'    => $parameters
+                                       );
+                       }
+
+                       
if(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'])
+                               && 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'] == 
'yes'
+                               && $this->acl_edit)
+                       {
+
+                               unset($status['C']);
+                               foreach ($status as $status_code => 
$status_info)
+                               {
+                                       $datatable['rowactions']['action'][] = 
array
+                                               (
+                                                       'my_name'               
=> 'status',
+                                                       'statustext'    => 
$status_info['status'],
+                                                       'text'                  
=> lang('change to') . ':  ' .$status_info['status'],
+                                                       'confirm_msg'   => 
lang('do you really want to change the status to %1',$status_info['status']),
+                                                       'action'                
=> $GLOBALS['phpgw']->link('/index.php',array
+                                                       (
+                                                               'menuaction'    
        => 'helpdesk.uitts.edit_status',
+                                                               'edit_status'   
        => true,
+                                                               'new_status'    
        => $status_code,
+                                                               
'second_display'        => true,
+                                                               'sort'          
                => $this->sort,
+                                                               'order'         
                => $this->order,
+                                                               'cat_id'        
                => $this->cat_id,
+                                                               'filter'        
                => $this->filter,
+                                                               'user_filter'   
        => $this->user_filter,
+                                                               'query'         
                => $this->query,
+                                                               'district_id'   
        => $this->district_id,
+                                                               'allrows'       
                => $this->allrows,
+                                                               'delete'        
                => 'dummy'// FIXME to trigger the json in helpdesk.js.
+                                                       )),
+                                                       'parameters'    => 
$parameters
+                                               );
+                               }
+                       }
+
+                       if($this->acl_add)
+                       {
+                               $datatable['rowactions']['action'][] = array
+                                       (
+                                               'my_name'                       
=> 'add',
+                                               'statustext'    => lang('Add 
new ticket'),
+                                               'text'                  => 
lang('add'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'helpdesk.uitts.add'
+                                               ))
+                                       );
+                       }
+
+                       unset($parameters);
+                       for ($i=0;$i<$count_uicols_name;$i++)
+                       {
+                               //              
if($uicols['input_type'][$i]!='hidden')
+                       {
+                               
$datatable['headers']['header'][$i]['formatter']                = 
!isset($uicols['formatter'][$i]) || $uicols['formatter'][$i]==''?  '""' : 
$uicols['formatter'][$i];
+                               $datatable['headers']['header'][$i]['name']     
                = $uicols['name'][$i];
+                               $datatable['headers']['header'][$i]['text']     
                = lang(str_replace('_', ' ', $uicols['name'][$i]));
+                               $datatable['headers']['header'][$i]['visible']  
                = true;
+                               $datatable['headers']['header'][$i]['sortable'] 
                = false;
+                               if($uicols['name'][$i]=='priority' || 
$uicols['name'][$i]=='id' || $uicols['name'][$i]=='assignedto' || 
$uicols['name'][$i]=='finnish_date'|| $uicols['name'][$i]=='user'|| 
$uicols['name'][$i]=='entry_date' || $uicols['name'][$i]=='order_id')
+                               {
+                                       
$datatable['headers']['header'][$i]['sortable']         = true;
+                                       
$datatable['headers']['header'][$i]['sort_field']   = $uicols['name'][$i];
+                               }
+                               if($uicols['name'][$i]=='text_view' || 
$uicols['name'][$i]=='bgcolor' || $uicols['name'][$i]=='child_date' || 
$uicols['name'][$i]== 'link_view' || 
$uicols['name'][$i]=='lang_view_statustext')
+                               {
+                                       
$datatable['headers']['header'][$i]['visible']          = false;
+                                       
$datatable['headers']['header'][$i]['format']           = 'hidden';
+                               }
+                       }
+                       }
+
+                       //path for helpdesk.js
+                       $datatable['property_js'] = 
$GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
+
+                       // Pagination and sort values
+                       $datatable['pagination']['records_start']       = 
(int)$this->bo->start;
+                       $datatable['pagination']['records_limit']       = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                       if($dry_run)
+                       {
+                               $datatable['pagination']['records_returned'] = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];           
         
+                       }
+                       else
+                       {
+                               $datatable['pagination']['records_returned']= 
count($ticket_list);
+                       }
+                       $datatable['pagination']['records_total']       = 
$this->bo->total_records;
+
+                       $datatable['sorting']['order']  = 
phpgw::get_var('order', 'string'); // Column
+
+                       $appname                                                
= lang('helpdesk');
+                       $function_msg                                   = 
lang('list ticket');
+
+                       if ( (phpgw::get_var("start")== "") && 
(phpgw::get_var("order",'string')== ""))
+                       {
+                               $datatable['sorting']['order']                  
= 'entry_date'; // name key Column in myColumnDef
+                               $datatable['sorting']['sort']                   
= 'desc'; // ASC / DESC
+                       }
+                       else
+                       {
+                               $datatable['sorting']['order']                  
= phpgw::get_var('order', 'string'); // name of column of Database
+                               $datatable['sorting']['sort']                   
= phpgw::get_var('sort', 'string'); // ASC / DESC
+                       }
+
+                       //-- BEGIN----------------------------- JSON CODE 
------------------------------
+                       //values for Pagination
+                       $json = array
+                               (
+                                       'recordsReturned'       => 
$datatable['pagination']['records_returned'],
+                                       'totalRecords'          => 
(int)$datatable['pagination']['records_total'],
+                                       'startIndex'            => 
$datatable['pagination']['records_start'],
+                                       'sort'                          => 
$datatable['sorting']['order'],
+                                       'dir'                           => 
$datatable['sorting']['sort'],
+                                       'records'                       => 
array()
+                               );
+
+                       // values for datatable
+                       if(isset($datatable['rows']['row']) && 
is_array($datatable['rows']['row']))
+                       {
+                               foreach( $datatable['rows']['row'] as $row )
+                               {
+                                       $json_row = array();
+                                       foreach( $row['column'] as $column)
+                                       {
+                                               if(isset($column['format']) && 
$column['format']== "link" && isset($column['java_link']) && 
$column['java_link']==true)
+                                               {
+                                                       
$json_row[$column['name']] = "<a href='#' id='".$column['link']."' 
onclick='javascript:filter_data(this.id);'>" .$column['value']."</a>";
+                                               }
+                                               else 
if(isset($column['format']) && $column['format']== "link")
+                                               {
+                                                       
$json_row[$column['name']] = "<a href='".$column['link']."' title = 
'{$column['statustext']}'>" .$column['value']."</a>";
+                                               }
+                                               else
+                                               {
+                                                       
$json_row[$column['name']] = $column['value'];
+                                               }
+
+                                               if($column['name'] == 
'priority')
+                                               {
+                                                       $_value = 
$column['value'];//str_repeat("||", abs(6 - 2*$column['value'])) . 
$column['value'];
+                                                       
$json_row[$column['name']] = $_value;
+                                                       switch($column['value'])
+                                                       {
+                                                       case 1:
+                                                               
$json_row[$column['name']] = "<div 
style='background-color:".$bgcolor_array[1].";'>".$_value."</div>";
+                                                               break;
+                                                       case 2:
+                                                               
$json_row[$column['name']] = "<div 
style='background-color:".$bgcolor_array[2].";'>".$_value."</div>";
+                                                               break;
+                                                       case 3:
+                                                               
$json_row[$column['name']] = "<div 
style='background-color:".$bgcolor_array[3].";'>".$_value."</div>";
+                                                               break;
+                                                       }
+                                                       unset($_value);
+
+                                               }
+                                       }
+                                       $json['records'][] = $json_row;
+                               }
+                       }
+
+                       // values for control select
+                       $opt_cb_depend =  
$this->bocommon->select_part_of_town('filter_',$this->part_of_town_id,$this->district_id);
+                       $default_value = array ('id'=>'','name'=>'!no part of 
town');
+                       array_unshift ($opt_cb_depend,$default_value);
+                       $json['hidden']['dependent'][] = array ( 'id' => 
$this->part_of_town_id,
+                               'value' => 
$this->bocommon->select2String($opt_cb_depend)
+                       );
+                       // right in datatable
+                       if(isset($datatable['rowactions']['action']) && 
is_array($datatable['rowactions']['action']))
+                       {
+                               $json ['rights'] = 
$datatable['rowactions']['action'];
+                       }
+
+                       if( phpgw::get_var('phpgw_return_as') == 'json' )
+                       {
+                               return $json;
+                       }
+
+
+                       $datatable['json_data'] = json_encode($json);
+                       //-------------------- JSON CODE ----------------------
+
+                       // Prepare template variables and process XSLT
+                       $template_vars = array();
+                       $template_vars['datatable'] = $datatable;
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
$template_vars);
+
+                       if ( !isset($GLOBALS['phpgw']->css) || 
!is_object($GLOBALS['phpgw']->css) )
+                       {
+                               $GLOBALS['phpgw']->css = 
createObject('phpgwapi.css');
+                       }
+
+                       phpgwapi_yui::load_widget('dragdrop');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('menu');
+                       phpgwapi_yui::load_widget('connection');
+                       phpgwapi_yui::load_widget('loader');
+                       phpgwapi_yui::load_widget('paginator');
+
+                       // Prepare CSS Style
+                       $GLOBALS['phpgw']->css->validate_file('datatable');
+                       $GLOBALS['phpgw']->css->validate_file('helpdesk');
+                       
$GLOBALS['phpgw']->css->add_external_file('helpdesk/templates/base/css/helpdesk.css');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
+                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('helpdesk') . ' - ' . $appname . ': ' . $function_msg;
+
+                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'tts.index' , 'helpdesk' );
+               }
+
+
+               function add()
+               {
+                       if(!$this->acl_add)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=> 2, 'acl_location'=> $this->acl_location));
+                       }
+                       if($this->tenant_id)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.add2'));
+                       }
+
+//                     $bolocation             = 
CreateObject('helpdesk.bolocation');
+
+                       $values         = phpgw::get_var('values');
+                       $values['contact_id']           = 
phpgw::get_var('contact', 'int', 'POST');
+                       if ((isset($values['cancel']) && $values['cancel']))
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index'));
+                       }
+
+                       //------------------- start ticket from other location
+                       $bypass                 = phpgw::get_var('bypass', 
'bool');
+                       if(isset($_POST) && $_POST && isset($bypass) && $bypass)
+                       {
+                               $boadmin_entity         = 
CreateObject('helpdesk.boadmin_entity');
+                               $location_code          = 
phpgw::get_var('location_code');
+                               $values['descr']        = 
phpgw::get_var('descr');
+                               $p_entity_id            = 
phpgw::get_var('p_entity_id', 'int');
+                               $p_cat_id                       = 
phpgw::get_var('p_cat_id', 'int');
+                               $values['p'][$p_entity_id]['p_entity_id']       
= $p_entity_id;
+                               $values['p'][$p_entity_id]['p_cat_id']          
= $p_cat_id;
+                               $values['p'][$p_entity_id]['p_num']             
= phpgw::get_var('p_num');
+
+                               $origin         = phpgw::get_var('origin');
+                               $origin_id      = phpgw::get_var('origin_id', 
'int');
+
+                               if($p_entity_id && $p_cat_id)
+                               {
+                                       $entity_category = 
$boadmin_entity->read_single_category($p_entity_id,$p_cat_id);
+                                       
$values['p'][$p_entity_id]['p_cat_name'] = $entity_category['name'];
+                               }
+
+                               if($location_code)
+                               {
+//                                     $values['location_data'] = 
$bolocation->read_single($location_code,array('tenant_id'=>$tenant_id,'p_num'=>$p_num,
 'view' => true));
+                               }
+                       }
+
+                       if(isset($values['origin']) && $values['origin'])
+                       {
+                               $origin         = $values['origin'];
+                               $origin_id      = $values['origin_id'];
+                       }
+
+                       $interlink      = CreateObject('property.interlink');
+
+                       if(isset($origin) && $origin)
+                       {
+                               unset($values['origin']);
+                               unset($values['origin_id']);
+                               $values['origin'][0]['location']= $origin;
+                               $values['origin'][0]['descr']= 
$interlink->get_location_name($origin);
+                               $values['origin'][0]['data'][]= array
+                                       (
+                                               'id'    => $origin_id,
+                                               'link'  => 
$interlink->get_relation_link(array('location' => $origin), $origin_id),
+                                       );
+                       }
+                       //_debug_array($insert_record);
+                       if ((isset($values['save']) && $values['save']) || 
(isset($values['apply']) && $values['apply']))
+                       {
+                               $insert_record = 
$GLOBALS['phpgw']->session->appsession('insert_record','helpdesk');
+                               $insert_record_entity = 
$GLOBALS['phpgw']->session->appsession('insert_record_entity','helpdesk');
+
+                               if(isset($insert_record_entity) && 
is_array($insert_record_entity))
+                               {
+                                       for 
($j=0;$j<count($insert_record_entity);$j++)
+                                       {
+                                               
$insert_record['extra'][$insert_record_entity[$j]]      = 
$insert_record_entity[$j];
+                                       }
+                               }
+
+                               $values = 
$this->bocommon->collect_locationdata($values,$insert_record);
+
+
+                               if(!$values['subject'] && 
isset($this->bo->config->config_data['tts_mandatory_title']) && 
$this->bo->config->config_data['tts_mandatory_title'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Please enter a title !'));
+                               }
+
+                               if(!$values['cat_id'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Please select a category !'));
+                               }
+
+                               if(!isset($values['details']) || 
!$values['details'])
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('Please give som details !'));
+                               }
+
+                               if((!isset($values['location']['loc1']) || 
!$values['location']['loc1']) && (!isset($values['extra']['p_num']) || 
!$values['extra']['p_num']))
+                               {
+//                                     
$receipt['error'][]=array('msg'=>lang('Please select a location - or an 
entity!'));
+                               }
+
+                               if(!$values['assignedto'] && 
!$values['group_id'])
+                               {
+                                       $_responsible = 
execMethod('property.boresponsible.get_responsible', $values);
+                                       if(!$_responsible)
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('Please select a person or a group to 
handle the ticket !'));
+                                       }
+                                       else
+                                       {
+                                               if( 
$GLOBALS['phpgw']->accounts->get($_responsible)->type == 
phpgwapi_account::TYPE_USER )
+                                               {
+                                                       $values['assignedto'] = 
$_responsible;
+                                               }
+                                               else
+                                               {
+                                                       $values['group_id'] = 
$_responsible;
+                                               }
+                                       }
+                                       unset($_responsible);
+                               }
+
+                               if(!isset($values['priority']) || 
!$values['priority'])
+                               {
+                                       $_priority = 
$this->bo->get_priority_list();
+                                       $values['priority'] = count($_priority);
+                                       unset($_priority);
+                               }
+
+                               if(!isset($receipt['error']))
+                               {
+                                       $receipt = $this->bo->add($values);
+
+                                       //------------ files
+                                       $values['file_name'] = @str_replace(' 
','_',$_FILES['file']['name']);
+
+                                       if($values['file_name'] && 
$receipt['id'])
+                                       {
+                                               $bofiles        = 
CreateObject('property.bofiles','/helpdesk');
+                                               $to_file = $bofiles->fakebase . 
"/{$receipt['id']}/{$values['file_name']}";
+
+                                               
if($bofiles->vfs->file_exists(array(
+                                                       'string' => $to_file,
+                                                       'relatives' => 
array(RELATIVE_NONE)
+                                               )))
+                                               {
+                                                       
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
+                                               }
+                                               else
+                                               {
+                                                       
$bofiles->create_document_dir("fmticket/{$receipt['id']}");
+                                                       
$bofiles->vfs->override_acl = 1;
+
+                                                       
if(!$bofiles->vfs->cp(array (
+                                                               'from'  => 
$_FILES['file']['tmp_name'],
+                                                               'to'    => 
$to_file,
+                                                               'relatives'     
=> array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                                                       {
+                                                               
$receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
+                                                       }
+                                                       
$bofiles->vfs->override_acl = 0;
+                                               }
+                                       }
+                                       //--------------end files
+                                       
$GLOBALS['phpgw']->session->appsession('receipt','helpdesk',$receipt);
+                                       
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts','');
+
+                                       if ((isset($values['save']) && 
$values['save']))
+                                       {
+                                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index'));
+                                       }
+                                       else
+                                       {
+                                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.view', 'id' => $receipt['id'], 'tab' =>'general'));             
                     
+                                       }
+                               }
+                               else
+                               {
+                                       if(isset($values['location']) && 
$values['location'])
+                                       {
+                                               $location_code=implode("-", 
$values['location']);
+                                               $values['extra']['view'] = true;
+//                                             $values['location_data'] = 
$bolocation->read_single($location_code, $values['extra']);
+                                       }
+                                       if(isset($values['extra']['p_num']) && 
$values['extra']['p_num'])
+                                       {
+                                               
$values['p'][$values['extra']['p_entity_id']]['p_num']=$values['extra']['p_num'];
+                                               
$values['p'][$values['extra']['p_entity_id']]['p_entity_id']=$values['extra']['p_entity_id'];
+                                               
$values['p'][$values['extra']['p_entity_id']]['p_cat_id']=$values['extra']['p_cat_id'];
+                                               
$values['p'][$values['extra']['p_entity_id']]['p_cat_name']=phpgw::get_var('entity_cat_name_'.$values['extra']['p_entity_id'],
 'string', 'POST');
+                                       }
+                               }
+                       }
+
+/*
+                       $location_data=$bolocation->initiate_ui_location(array(
+                               'values'        => 
(isset($values['location_data'])?$values['location_data']:''),
+                               'type_id'       => -1, // calculated from 
location_types
+                               'no_link'       => false, // disable lookup 
links for location type less than type_id
+                               'tenant'        => true,
+                               'lookup_type'   => 'form',
+                               'lookup_entity' => 
$this->bocommon->get_lookup_entity('ticket'),
+                               'entity_data'   => 
(isset($values['p'])?$values['p']:'')
+                       ));
+*/
+
+                       
$contact_data=$this->bocommon->initiate_ui_contact_lookup(array(
+                               'contact_id'            => 
$ticket['contact_id'],
+                               'field'                         => 'contact',
+                               'type'                          => 'form'));
+
+                       $link_data = array
+                               (
+                                       'menuaction'    => 'helpdesk.uitts.add'
+                               );
+
+                       if(!isset($values['assignedto']))
+                       {
+                               $values['assignedto']= 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault']:'');
+                       }
+                       if(!isset($values['group_id']))
+                       {
+                               $values['group_id']= 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault']:'');
+                       }
+
+                       if(!isset($values['cat_id']))
+                       {
+                               $this->cat_id = 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_category'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_category']:'');
+                       }
+                       else
+                       {
+                               $this->cat_id = $values['cat_id'];
+                       }
+
+                       $msgbox_data = 
(isset($receipt)?$this->bocommon->msgbox_data($receipt):'');
+
+
+                       if(!$this->_simple && $this->_show_finnish_date)
+                       {
+                               $jscal = CreateObject('phpgwapi.jscalendar');
+                               $jscal->add_listener('values_finnish_date');
+                       }
+
+                       $data = array
+                               (
+                                       'contact_data'                          
        => $contact_data,
+                                       'simple'                                
                => $this->_simple,
+                                       'show_finnish_date'                     
        => $this->_show_finnish_date,
+                                       'value_origin'                          
        => isset($values['origin']) ? $values['origin'] : '',
+                                       'value_origin_type'                     
        => (isset($origin)?$origin:''),
+                                       'value_origin_id'                       
        => (isset($origin_id)?$origin_id:''),
+
+                                       'msgbox_data'                           
        => $GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                                       'location_data'                         
        => $location_data,
+                                       'lang_no_user'                          
        => lang('Select user'),
+                                       'lang_user_statustext'                  
=> lang('Select the user the selection belongs to. To do not use a user select 
NO USER'),
+                                       'select_user_name'                      
        => 'values[assignedto]',
+                                       'user_list'                             
                => 
$this->bocommon->get_user_list_right2('select',4,$values['assignedto'],$this->acl_location),
+
+                                       'lang_no_group'                         
        => lang('No group'),
+                                       'group_list'                            
        => 
$this->bocommon->get_group_list('select',$values['group_id'],$start=-1,$sort='ASC',$order='account_firstname',$query='',$offset=-1),
+                                       'select_group_name'                     
        => 'values[group_id]',
+
+                                       'lang_priority_statustext'              
=> lang('Select the priority the selection belongs to.'),
+                                       'select_priority_name'                  
=> 'values[priority]',
+                                       'priority_list'                         
        => 
$this->bo->get_priority_list((isset($values['priority'])?$values['priority']:'')),
+
+                                       'status_list'                           
        => $this->bo->get_status_list('O'),
+
+                                       'form_action'                           
        => $GLOBALS['phpgw']->link('/index.php',$link_data),
+
+                                       'lang_details'                          
        => lang('Details'),
+                                       'lang_category'                         
        => lang('category'),
+                                       'lang_save'                             
                => lang('save'),
+                                       'lang_cancel'                           
        => lang('cancel'),
+                                       'lang_send'                             
                => lang('send'),
+                                       'value_details'                         
        => (isset($values['details'])?$values['details']:''),
+                                       'value_subject'                         
        => (isset($values['subject'])?$values['subject']:''),
+
+                                       'value_finnish_date'                    
=> (isset($values['finnish_date'])?$values['finnish_date']:''),
+                                       'img_cal'                               
                => $GLOBALS['phpgw']->common->image('phpgwapi','cal'),
+                                       'lang_datetitle'                        
        => lang('Select date'),
+                                       'lang_finnish_date_statustext'  => 
lang('Select the estimated date for closing the task'),
+
+                                       'lang_cancel_statustext'                
=> lang('Back to the ticket list'),
+                                       'lang_send_statustext'                  
=> lang('Save the entry and return to list'),
+                                       'lang_save_statustext'                  
=> lang('Save the ticket'),
+                                       'lang_no_cat'                           
        => lang('no category'),
+                                       'lang_town_statustext'                  
=> lang('Select the part of town the building belongs to. To do not use a part 
of town -  select NO PART OF TOWN'),
+                                       'lang_part_of_town'                     
        => lang('Part of town'),
+                                       'lang_no_part_of_town'                  
=> lang('No part of town'),
+                                       'cat_select'                            
        => $this->cats->formatted_xslt_list(array('select_name' => 
'values[cat_id]','selected' => $this->cat_id,'use_acl' => 
$this->_category_acl)),
+                                       'pref_send_mail'                        
        => 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_user_mailnotification']:''),
+                                       'fileupload'                            
        => 
(isset($this->bo->config->config_data['fmttsfileupload'])?$this->bo->config->config_data['fmttsfileupload']:''),
+                               );
+
+                       //_debug_array($data);
+                       $appname                                        = 
lang('helpdesk');
+                       $function_msg                                   = 
lang('add ticket');
+
+                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'tts.add', 'helpdesk' );
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('helpdesk') . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('tts','files'));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('add' 
=> $data));
+               }
+
+
+               function get_vendor_email($vendor_id = 0)
+               {
+                       if(!$vendor_id)
+                       {
+                               $vendor_id = phpgw::get_var('vendor_id', 'int', 
'GET', 0);
+                       }
+                       $vendor_email = 
execMethod('property.sowo_hour.get_email', $vendor_id);
+
+                       $content_email = array();
+                       foreach($vendor_email as $_entry )
+                       {                               
+                               $content_email[] = array
+                                       (
+
+                                               'value_email'           => 
$_entry['email'],
+                                               'value_select'          => 
'<input type="checkbox" name="values[vendor_email][]" 
value="'.$_entry['email'].'" title="'.lang('The address to which this order 
will be sendt').'">'
+                                       );
+                       }
+
+                       if( phpgw::get_var('phpgw_return_as') == 'json' )
+                       {
+
+                               if(count($content_email))
+                               {
+                                       return json_encode($content_email);
+                               }
+                               else
+                               {
+                                       return "";
+                               }
+                       }
+                       return $content_email;
+               }
+
+               function view()
+               {
+                       if(!$this->acl_read)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
+                       }
+
+                       $id = phpgw::get_var('id', 'int', 'GET');
+
+                       if($this->tenant_id)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.view2', 'id' => $id ));
+                       }
+
+//                     $bolocation     = CreateObject('helpdesk.bolocation');
+
+                       $values = phpgw::get_var('values');
+                       $values['contact_id']           = 
phpgw::get_var('contact', 'int', 'POST');
+                       $values['ecodimb']                      = 
phpgw::get_var('ecodimb');
+                       $values['vendor_id']            = 
phpgw::get_var('vendor_id', 'int', 'POST');
+                       $values['vendor_name']          = 
phpgw::get_var('vendor_name', 'string', 'POST');
+                       $values['b_account_id']         = 
phpgw::get_var('b_account_id', 'int', 'POST');
+                       $values['b_account_name']       = 
phpgw::get_var('b_account_name', 'string', 'POST');
+
+                       $receipt = 
$GLOBALS['phpgw']->session->appsession('receipt','helpdesk');
+                       
$GLOBALS['phpgw']->session->appsession('receipt','helpdesk','');
+
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files'));
+
+                       if(isset($values['save']))
+                       {
+                               if(!$this->acl_edit)
+                               {
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=>4, 'acl_location'=> $this->acl_location));
+                               }
+
+                               $insert_record = 
$GLOBALS['phpgw']->session->appsession('insert_record','helpdesk');
+                               $insert_record_entity = 
$GLOBALS['phpgw']->session->appsession('insert_record_entity','helpdesk');
+
+                               if(isset($insert_record_entity) && 
is_array($insert_record_entity))
+                               {
+                                       for 
($j=0;$j<count($insert_record_entity);$j++)
+                                       {
+                                               
$insert_record['extra'][$insert_record_entity[$j]]      = 
$insert_record_entity[$j];
+                                       }
+                               }
+
+                               $values = 
$this->bocommon->collect_locationdata($values,$insert_record);
+
+                               if(isset($values['budget']) && 
$values['budget'] && !ctype_digit($values['budget']))
+                               {
+                                       $values['budget'] = 
(int)$values['budget'];
+                                       
$receipt['error'][]=array('msg'=>lang('budget') . ': ' . lang('Please enter an 
integer !'));
+                               }
+
+                               if(isset($values['takeover']) && 
$values['takeover'])
+                               {
+                                       $values['assignedto'] = $this->account;
+                               }
+                               $receipt = 
$this->bo->update_ticket($values,$id);
+
+                               if ( (isset($values['send_mail']) && 
$values['send_mail']) 
+                                       || 
(isset($this->bo->config->config_data['mailnotification'])
+                                       && 
$this->bo->config->config_data['mailnotification']
+                                       && $this->bo->fields_updated
+                               ))
+                               {
+                                       $receipt = $this->bo->mail_ticket($id, 
$this->bo->fields_updated, $receipt);
+                               }
+
+                               //--------- files
+                               $bofiles        = 
CreateObject('property.bofiles', '/helpdesk');
+                               if(isset($values['file_action']) && 
is_array($values['file_action']))
+                               {
+                                       $bofiles->delete_file("/{$id}/", 
$values);
+                               }
+
+                               $values['file_name']=str_replace(' 
','_',$_FILES['file']['name']);
+
+                               if($values['file_name'])
+                               {
+                                       $to_file = $bofiles->fakebase . 
"/{$id}/{$values['file_name']}";
+
+                                       if($bofiles->vfs->file_exists(array(
+                                               'string' => $to_file,
+                                               'relatives' => 
Array(RELATIVE_NONE)
+                                       )))
+                                       {
+                                               
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
+                                       }
+                                       else
+                                       {
+                                               
$bofiles->create_document_dir("fmticket/{$id}");
+                                               $bofiles->vfs->override_acl = 1;
+
+                                               if(!$bofiles->vfs->cp (array (
+                                                       'from'  => 
$_FILES['file']['tmp_name'],
+                                                       'to'    => $to_file,
+                                                       'relatives'     => 
array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                                               {
+                                                       
$receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
+                                               }
+                                               $bofiles->vfs->override_acl = 0;
+                                       }
+                               }
+                               //                      
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index'));
+                       }
+                       //---------end files
+                       $ticket = $this->bo->read_single($id);
+
+                       $order_link                             = '';
+                       $add_to_project_link    = '';
+                       $request_link                   ='';
+
+                       if($GLOBALS['phpgw']->acl->check('.project.request', 
PHPGW_ACL_ADD, 'helpdesk'))
+                       {
+                               $request_link_data = array
+                                       (
+                                               'menuaction'            => 
'property.uirequest.edit',
+                                               'bypass'                        
=> true,
+                                               'location_code'         => 
$ticket['location_code'],
+                                               'p_num'                         
=> $ticket['p_num'],
+                                               'p_entity_id'           => 
$ticket['p_entity_id'],
+                                               'p_cat_id'                      
=> $ticket['p_cat_id'],
+                                               'tenant_id'                     
=> $ticket['tenant_id'],
+                                               'origin'                        
=> '.ticket',
+                                               'origin_id'                     
=> $id
+                                       );
+
+                               $request_link                   = 
$GLOBALS['phpgw']->link('/index.php',$request_link_data);
+                       }
+
+                       if($GLOBALS['phpgw']->acl->check('.project', 
PHPGW_ACL_ADD, 'helpdesk'))
+                       {
+                               $order_link_data = array
+                                       (
+                                               'menuaction'            => 
'property.uiproject.edit',
+                                               'bypass'                        
=> true,
+                                               'location_code'         => 
$ticket['location_code'],
+                                               'p_num'                         
=> $ticket['p_num'],
+                                               'p_entity_id'           => 
$ticket['p_entity_id'],
+                                               'p_cat_id'                      
=> $ticket['p_cat_id'],
+                                               'tenant_id'                     
=> $ticket['tenant_id'],
+                                               'origin'                        
=> '.ticket',
+                                               'origin_id'                     
=> $id
+                                       );
+
+                               $add_to_project_link_data = array
+                                       (
+                                               'menuaction'            => 
'property.uiproject.index',
+                                               'from'                          
=> 'workorder',
+                                               'lookup'                        
=> true,
+                                               'query'                         
=> isset($ticket['location_data']['loc1']) ? $ticket['location_data']['loc1'] : 
'',
+                       //                      'p_num'                         
=> $ticket['p_num'],
+                       //                      'p_entity_id'           => 
$ticket['p_entity_id'],
+                       //                      'p_cat_id'                      
=> $ticket['p_cat_id'],
+                                               'tenant_id'                     
=> $ticket['tenant_id'],
+                                               'origin'                        
=> '.ticket',
+                                               'origin_id'                     
=> $id
+                                       );
+
+                               $order_link                             = 
$GLOBALS['phpgw']->link('/index.php',$order_link_data);
+                               $add_to_project_link    = 
$GLOBALS['phpgw']->link('/index.php',$add_to_project_link_data);
+
+                       }
+
+                       $form_link = array
+                               (
+                                       'menuaction'    => 
'helpdesk.uitts.view',
+                                       'id'            => $id
+                               );
+
+
+                       if($ticket['origin'] || $ticket['target'])
+                       {
+                               $lookup_type    = 'view';
+                               $type_id                = 
count(explode('-',$ticket['location_data']['location_code']));
+                       }
+                       else
+                       {
+                               $lookup_type    = 'form';
+                               $type_id                = -1;
+                       }
+
+/*
+                       $location_data=$bolocation->initiate_ui_location(array(
+                               'values'        => $ticket['location_data'],
+                               'type_id'       => $type_id,
+                               'no_link'       => false, // disable lookup 
links for location type less than type_id
+                               'tenant'        => 
(isset($ticket['location_data']['tenant_id'])?$ticket['location_data']['tenant_id']:''),
+                               'lookup_type'   => $lookup_type,
+                               'lookup_entity' => 
$this->bocommon->get_lookup_entity('ticket'),
+                               'entity_data'   => 
(isset($ticket['p'])?$ticket['p']:'')
+                       ));
+                       unset($type_id);
+*/
+                       
$contact_data=$this->bocommon->initiate_ui_contact_lookup(array(
+                               'contact_id'            => 
$ticket['contact_id'],
+                               'field'                         => 'contact',
+                               'type'                          => 'form'));
+
+
+                       if($ticket['contact_phone'])
+                       {
+                               for 
($i=0;$i<count($location_data['location']);$i++)
+                               {
+                                       
if($location_data['location'][$i]['input_name'] == 'contact_phone')
+                                       {
+                                               
unset($location_data['location'][$i]['value']);
+                                       }
+                               }
+                       }
+
+                       if ($ticket['cat_id'])
+                       {
+                               $this->cat_id = $ticket['cat_id'];
+                       }
+
+                       $start_entity   = 
$this->bocommon->get_start_entity('ticket');
+
+                       $link_entity = array();
+                       if (isset($start_entity) AND is_array($start_entity))
+                       {
+                               $i=0;
+                               foreach($start_entity as $entry)
+                               {
+                                       
if($GLOBALS['phpgw']->acl->check(".entity.{$entry['id']}", PHPGW_ACL_ADD, 
'helpdesk'))
+                                       {
+                                               $link_entity[$i]['link'] = 
$GLOBALS['phpgw']->link('/index.php',array
+                                                       (
+                                                               'menuaction'    
        => 'helpdesk.uientity.edit',
+                                                               'bypass'        
        => true,
+                                                               'location_code' 
        => $ticket['location_code'],
+                                                               'entity_id'     
        => $entry['id'],
+                                                               'p_num'         
        => $ticket['p_num'],
+                                                               'p_entity_id'   
        => $ticket['p_entity_id'],
+                                                               'p_cat_id'      
        => $ticket['p_cat_id'],
+                                                               'tenant_id'     
        => $ticket['tenant_id'],
+                                                               'origin'        
        => '.ticket',
+                                                               'origin_id'     
        => $id
+                                                       ));
+                                               $link_entity[$i]['name']        
= $entry['name'];
+                                               $i++;
+                                       }
+                               }
+                       }
+
+                       //_debug_array($link_entity);
+
+                       $link_file_data = array
+                               (
+                                       'menuaction'    => 
'helpdesk.uitts.view_file',
+                                       'id'            => $id
+                               );
+
+                       if(!$this->_simple && $this->_show_finnish_date)
+                       {
+                               $jscal = CreateObject('phpgwapi.jscalendar');
+                               $jscal->add_listener('values_finnish_date');
+                       }
+
+                       // -------- start order section
+                       $order_read                     = 
$this->acl->check('.ticket.order', PHPGW_ACL_READ, 'helpdesk');
+                       $order_add                              = 
$this->acl->check('.ticket.order', PHPGW_ACL_ADD, 'helpdesk');
+                       $order_edit                     = 
$this->acl->check('.ticket.order', PHPGW_ACL_EDIT, 'helpdesk');
+
+                       $access_order = false;
+                       if($order_add || $order_edit)
+                       {
+                               $access_order = true;
+                       }
+
+                       if($access_order)
+                       {
+                               
$vendor_data=$this->bocommon->initiate_ui_vendorlookup(array(
+                                       'vendor_id'                     => 
$ticket['vendor_id'],
+                                       'vendor_name'           => 
$ticket['vendor_name']));
+
+                               
$b_account_data=$this->bocommon->initiate_ui_budget_account_lookup(array
+                                       (
+                                               'b_account_id'          => 
$ticket['b_account_id'] ? $ticket['b_account_id'] : $ticket['b_account_id'],
+                                               'b_account_name'        => 
$ticket['b_account_name'],
+                                               'disabled'                      
=> false
+                                       )
+                               );
+
+                               
$ecodimb_data=$this->bocommon->initiate_ecodimb_lookup(array
+                                       (
+                                               'ecodimb'                       
=> $ticket['ecodimb'] ? $ticket['ecodimb'] : $ticket['ecodimb'],
+                                               'ecodimb_descr'         => 
$ticket['ecodimb_descr'],
+                                               'disabled'                      
=> false
+                                       )
+                               );
+
+                               // approval
+                               $supervisor_id = 0;
+
+                               if ( 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['approval_from'])
+                                       && 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['approval_from'] )
+                               {
+                                       $supervisor_id = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['approval_from'];
+                               }
+
+                               $need_approval = 
isset($this->bo->config->config_data['workorder_approval']) ? 
$this->bo->config->config_data['workorder_approval'] : '';
+
+                               $supervisor_email = array();
+                               if ($supervisor_id && $need_approval)
+                               {
+                                       $prefs = 
$this->bocommon->create_preferences('helpdesk',$supervisor_id);
+                                       $supervisor_email[] = array
+                                               (
+                                                       'id'      => 
$supervisor_id,
+                                                       'address' => 
$prefs['email'],
+                                               );
+                                       if ( isset($prefs['approval_from']) )
+                                       {
+                                               $prefs2 = 
$this->bocommon->create_preferences('helpdesk', $prefs['approval_from']);
+
+                                               if(isset($prefs2['email']))
+                                               {
+                                                       $supervisor_email[] = 
array
+                                                               (
+                                                                       'id'    
  => $prefs['approval_from'],
+                                                                       
'address' => $prefs2['email'],
+                                                               );
+                                                       $supervisor_email = 
array_reverse($supervisor_email);
+                                               }
+                                               unset($prefs2);
+                                       }
+                                       unset($prefs);
+                               }
+                               // approval                                     
+                       }
+
+                       $vendor_email = array();
+                       $validator = 
CreateObject('phpgwapi.EmailAddressValidator');                    
+                       if(isset($values['vendor_email']) && 
is_array($values['vendor_email']))
+                       {
+                               foreach ($values['vendor_email'] as $_temp)
+                               {
+                                       if($_temp)
+                                       {
+                                               
if($validator->check_email_address($_temp))
+                                               {
+                                                       $vendor_email[] = 
$_temp;
+                                               }
+                                               else
+                                               {
+                                                       
$receipt['error'][]=array('msg'=>lang('%1 is not a valid address',$_temp));     
                        
+                                               }
+                                       }
+                               }
+                       }
+                       unset($_temp);
+
+                       if($vendor_email)
+                       {
+                               $historylog     = 
CreateObject('helpdesk.historylog','tts');
+
+                               $subject = lang(workorder).": 
{$ticket['order_id']}";
+
+                               $organisation = '';
+                               $contact_name = '';
+                               $contact_email = '';
+                               $contact_phone = '';
+
+                               
if(isset($this->bo->config->config_data['org_name']))
+                               {
+                                       $organisation = 
$this->bo->config->config_data['org_name'];
+                               }
+
+                               if(isset($values['on_behalf_of_assigned']) && 
$values['on_behalf_of_assigned'] && isset($ticket['assignedto_name']))
+                               {
+                                       $user_name = $ticket['assignedto_name'];
+                                       
$GLOBALS['phpgw']->preferences->set_account_id($ticket['assignedto'], true);
+                                       
$GLOBALS['phpgw_info']['user']['preferences'] = 
$GLOBALS['phpgw']->preferences->data;
+                                       $_behalf_alert = lang('this order is 
sent by %1 on behalf of %2',$GLOBALS['phpgw_info']['user']['fullname'], 
$user_name);
+                                       
$historylog->add('C',$id,$_behalf_alert);
+                                       unset($_behalf_alert);
+                               }
+                               else
+                               {
+                                       $user_name = 
$GLOBALS['phpgw_info']['user']['fullname'];                                
+                               }
+                               $ressursnr = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ressursnr'];
+                               $location = lang('Address'). ": 
{$ticket['address']}<br>";
+
+                               $address_element = 
$this->bo->get_address_element($ticket['location_code']);
+
+                               foreach($address_element as $address_entry)
+                               {
+                                       $location .= "{$address_entry['text']}: 
{$address_entry['value']} <br>";
+                               }
+
+                               $location = rtrim($location, '<br>');
+
+                               $order_description = $ticket['order_descr'];
+
+                               if(isset($contact_data['value_contact_name']) 
&& $contact_data['value_contact_name'])
+                               {
+                                       $contact_name = 
$contact_data['value_contact_name'];
+                               }
+                               if(isset($contact_data['value_contact_email']) 
&& $contact_data['value_contact_email'])
+                               {
+                                       $contact_email = "<a 
href='mailto:{$contact_data['value_contact_email']}'>{$contact_data['value_contact_email']}</a>";
+                               }
+                               if(isset($contact_data['value_contact_tel']) && 
$contact_data['value_contact_tel'])
+                               {
+                                       $contact_phone = 
$contact_data['value_contact_tel'];
+                               }
+
+                               $order_id = $ticket['order_id'];
+
+                               $user_phone = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['cellphone'];
+                               $user_email = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['email'];
+                               $order_email_template = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['order_email_template'];
+
+                               $body = nl2br(str_replace(array
+                                       (
+                                               '__organisation__',
+                                               '__user_name__',
+                                               '__user_phone__',
+                                               '__user_email__',
+                                               '__ressursnr__',
+                                               '__location__',
+                                               '__order_description__',
+                                               '__contact_name__',
+                                               '__contact_email__',
+                                               '__contact_phone__',
+                                               '__order_id__',
+                                               '[b]',
+                                               '[/b]'
+                                       ),array
+                                       (
+                                               $organisation,
+                                               $user_name,
+                                               $user_phone,
+                                               $user_email,
+                                               $ressursnr,
+                                               $location,
+                                               $order_description,
+                                               $contact_name,
+                                               $contact_email,
+                                               $contact_phone,
+                                               $order_id,
+                                               '<b>',
+                                               '</b>'
+                                       ),$order_email_template));
+
+                               if(isset($values['file_attach']) && 
is_array($values['file_attach']))
+                               {
+//                                     $bofiles        = 
CreateObject('helpdesk.bofiles' '/helpdesk');
+                                       $attachments = 
$bofiles->get_attachments("/{$id}/", $values['file_attach']);
+                                       $attachment_log = ' ' . 
lang('attachments') . ' : ' . implode(', ',$values['file_attach']);
+                               }
+                               if 
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) && 
$GLOBALS['phpgw_info']['server']['smtp_server'])
+                               {
+                                       if (!is_object($GLOBALS['phpgw']->send))
+                                       {
+                                               $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                                       }
+
+                                       $coordinator_name = 
$GLOBALS['phpgw_info']['user']['fullname'];
+                                       $coordinator_email = 
"{$coordinator_name}<{$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['email']}>";
+                                       $cc = '';
+                                       $bcc = $coordinator_email;
+                                       
if(isset($contact_data['value_contact_email']) && 
$contact_data['value_contact_email'])
+                                       {
+                                               $cc = 
$contact_data['value_contact_email'];
+                                       }
+
+                                       $_to = implode(';',$vendor_email);
+
+                                       $rcpt = 
$GLOBALS['phpgw']->send->msg('email', $_to, $subject, stripslashes($body), '', 
$cc, $bcc, $coordinator_email, $coordinator_name, 'html', '', $attachments , 
true);
+                                       if($rcpt)
+                                       {
+                                               
$receipt['message'][]=array('msg'=>lang('%1 is notified',$_address));
+                                               
$historylog->add('M',$id,"{$_to}{$attachment_log}");
+                                               
$receipt['message'][]=array('msg'=>lang('Workorder is sent by email!'));
+                                               $action_params = array
+                                                       (
+                                                               'appname'       
                => 'helpdesk',
+                                                               'location'      
                => '.ticket',
+                                                               'id'            
                => $id,
+                                                               'responsible'   
        => $values['vendor_id'],
+                                                               
'responsible_type'  => 'vendor',
+                                                               'action'        
                => 'remind',
+                                                               'remark'        
                => '',
+                                                               'deadline'      
                => ''
+                                                       );
+
+                                               $reminds = 
execMethod('helpdesk.sopending_action.set_pending_action', $action_params);
+                                       }
+                               }
+                               else
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('SMTP server is not set! (admin 
section)'));
+                               }
+                       }
+
+                       // start approval
+                       if (isset($values['approval']) && $values['approval']  
&& $this->bo->config->config_data['workorder_approval'])
+                       {
+                               
$coordinator_name=$GLOBALS['phpgw_info']['user']['fullname'];
+                               
$coordinator_email=$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['email'];
+
+                               $subject = lang(Approval).": 
".$ticket['order_id'];
+                               $message = '<a href ="http://' . 
$GLOBALS['phpgw_info']['server']['hostname'] . 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'helpdesk.uitts.view', 'id'=> $id)).'">' . lang('Workorder %1 needs 
approval',$ticket['order_id']) .'</a>';
+
+                               if 
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) && 
$GLOBALS['phpgw_info']['server']['smtp_server'])
+                               {
+                                       if (!is_object($GLOBALS['phpgw']->send))
+                                       {
+                                               $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                                       }
+
+                                       $action_params = array
+                                               (
+                                                       'appname'               
        => 'helpdesk',
+                                                       'location'              
        => '.ticket',
+                                                       'id'                    
        => $id,
+                                                       'responsible'           
=> '',
+                                                       'responsible_type'  => 
'user',
+                                                       'action'                
        => 'approval',
+                                                       'remark'                
        => '',
+                                                       'deadline'              
        => ''
+                                               );
+                                       $bcc = '';//$coordinator_email;
+                                       foreach ($values['approval'] as 
$_account_id => $_address)
+                                       {
+                                               $action_params['responsible'] = 
$_account_id;
+                                               $rcpt = 
$GLOBALS['phpgw']->send->msg('email', $_address, $subject, 
stripslashes($message), '', $cc, $bcc, $coordinator_email, $coordinator_name, 
'html');
+                                               if($rcpt)
+                                               {
+                                                       
$receipt['message'][]=array('msg'=>lang('%1 is notified',$_address));
+                                               }
+
+                                               
execMethod('helpdesk.sopending_action.set_pending_action', $action_params);
+                                       }
+                               }
+                               else
+                               {
+                                       
$receipt['error'][]=array('msg'=>lang('SMTP server is not set! (admin 
section)'));
+                               }
+                       }
+
+                       // end approval
+
+                       // -------- end order section
+
+
+
+                       $additional_notes = 
$this->bo->read_additional_notes($id);
+                       $record_history = $this->bo->read_record_history($id);
+
+                       $notes = array
+                               (
+                                       array
+                                       (
+                                               'value_id'              =>'', 
//not from historytable
+                                               'value_count'   => 1,
+                                               'value_date'    => 
$GLOBALS['phpgw']->common->show_date($ticket['timestamp']),
+                                               'value_user'    => 
$ticket['user_name'],
+                                               'value_note'    => 
$ticket['details'],
+                                               'value_publish' => 
$ticket['publish_note']
+                                       )
+                               );
+
+                       $additional_notes = 
array_merge($notes,$additional_notes);
+
+                       if(isset($values['order_text']) && $ticket['order_id'])
+                       {
+                               foreach($values['order_text'] as $_text)
+                               {
+                                       $ticket['order_descr'] .= "\n$_text";
+                               }
+                       }
+
+                       $note_def = array
+                               (
+                                       array('key' => 'value_count',   
'label'=>'#',           'sortable'=>true,'resizeable'=>true),
+                                       array('key' => 'value_date',    
'label'=>lang('Date'),'sortable'=>true,'resizeable'=>true),
+                                       array('key' => 'value_user',    
'label'=>lang('User'),'sortable'=>true,'resizeable'=>true),
+                                       array('key' => 'value_note',    
'label'=>lang('Note'),'sortable'=>true,'resizeable'=>true)
+                               );
+
+                       if($access_order)
+                       {
+                               $note_def[] = array('key' => 
'order_text','label'=>lang('order 
text'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter');
+                               foreach($additional_notes as &$note)
+                               {
+                                       $note['order_text'] = '<input 
type="checkbox" name="values[order_text][]" value="'.$note['value_note'].'" 
title="'.lang('Check to add text to order').'">';
+
+                               }
+                       }
+
+                       $note_def[] = array('key' => 
'publish_note','label'=>lang('publish 
text'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter');
+                       foreach($additional_notes as &$note)
+                       {
+                               $note['value_note'] = 
nl2br($note['value_note']);
+                               $_checked = $note['value_publish'] ? 'checked' 
: '';
+                               $note['publish_note'] = "<input type='checkbox' 
{$_checked}  name='values[publish_note][]' value='{$id}_{$note['value_id']}' 
title='".lang('Check to publish text at frontend')."'>";
+                       }
+
+
+                       //_debug_Array($additional_notes);die();
+                       //---datatable 
settings---------------------------------------------------      
+                       $datavalues[0] = array
+                               (
+                                       'name'                                  
=> "0",
+                                       'values'                                
=> json_encode($additional_notes),
+                                       'total_records'                 => 
count($additional_notes),
+                                       'is_paginator'                  => 0,
+                                       'footer'                                
=> 0
+                               );                                      
+                       $myColumnDefs[0] = array
+                               (
+                                       'name'          => "0",
+                                       'values'        =>      
json_encode($note_def)
+                               );              
+                       $datavalues[1] = array
+                               (
+                                       'name'                                  
=> "1",
+                                       'values'                                
=> json_encode($record_history),
+                                       'total_records'                 => 
count($record_history),
+                                       'is_paginator'                  => 0,
+                                       'footer'                                
=> 0
+                               );                                      
+                       $myColumnDefs[1] = array
+                               (
+                                       'name'          => "1",
+                                       'values'        =>      
json_encode(array(      array('key' => 'value_date',    'label'=>lang('Date'),  
'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 'value_user',    
'label'=>lang('User'),  'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 'value_action',  
'label'=>lang('Action'),        'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 
'value_old_value','label'=>lang('old value'),    
'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 
'value_new_value','label'=>lang('New 
value'),'sortable'=>true,'resizeable'=>true)))
+                               );      
+
+
+                       $link_to_files = 
(isset($this->bo->config->config_data['files_url'])?$this->bo->config->config_data['files_url']:'');
+
+                       $link_view_file = 
$GLOBALS['phpgw']->link('/index.php',$link_file_data);
+
+                       for($z=0; $z<count($ticket['files']); $z++)
+                       {                               
+                               if ($link_to_files != '')
+                               {
+                                       $content_files[$z]['file_name'] = '<a 
href="'.$link_to_files.'/'.$ticket['files'][$z]['directory'].'/'.$ticket['files'][$z]['file_name'].'"
 target="_blank" title="'.lang('click to view file').'" 
style="cursor:help">'.$ticket['files'][$z]['name'].'</a>';
+                               }
+                               else
+                               {
+                                       $content_files[$z]['file_name'] = '<a 
href="'.$link_view_file.'&amp;file_name='.$ticket['files'][$z]['file_name'].'" 
target="_blank" title="'.lang('click to view 
file').'">'.$ticket['files'][$z]['name'].'</a>';
+                               }                               
+                               $content_files[$z]['delete_file'] = '<input 
type="checkbox" name="values[file_action][]" 
value="'.$ticket['files'][$z]['name'].'" title="'.lang('Check to delete 
file').'">';
+                               $content_files[$z]['attach_file'] = '<input 
type="checkbox" name="values[file_attach][]" 
value="'.$ticket['files'][$z]['name'].'" title="'.lang('Check to attach 
file').'">';
+                       }                                                       
+
+                       $datavalues[2] = array
+                               (
+                                       'name'                                  
=> "2",
+                                       'values'                                
=> json_encode($content_files),
+                                       'total_records'                 => 
count($content_files),
+                                       'permission'                    => "''",
+                                       'is_paginator'                  => 0,
+                                       'footer'                                
=> 0
+                               );
+
+                       $attach_file_def = array
+                               (
+                                       array('key' => 
'file_name','label'=>lang('Filename'),'sortable'=>false,'resizeable'=>true),
+                                       array('key' => 
'delete_file','label'=>lang('Delete 
file'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter'),
+                               );
+
+                       if(isset($ticket['order_id']) && $ticket['order_id'])
+                       {
+                               $attach_file_def[] = array('key' => 
'attach_file','label'=>lang('attach 
file'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter');
+                       }
+
+                       $myColumnDefs[2] = array
+                               (
+                                       'name'          => "2",
+                                       'values'        =>      
json_encode($attach_file_def)
+                               );
+
+
+                       $myColumnDefs[3] = array
+                               (
+                                       'name'          => "3",
+                                       'values'        =>      
json_encode(array(      array('key' => 'value_email',   'label'=>lang('email'), 
'sortable'=>true,'resizeable'=>true),
+                                                                               
                                array('key' => 
'value_select','label'=>lang('select'),'sortable'=>false,'resizeable'=>true)))
+                               );      
+
+
+                       $content_email = 
$this->get_vendor_email(isset($ticket['vendor_id'])?$ticket['vendor_id']:0);
+
+                       $datavalues[3] = array
+                               (
+                                       'name'                                  
=> "3",
+                                       'values'                                
=> json_encode($content_email),
+                                       'total_records'                 => 
count($content_email),
+                                       'permission'                    => "''",
+                                       'is_paginator'                  => 0,
+                                       'footer'                                
=> 0
+                               );
+
+
+                       
//----------------------------------------------datatable settings--------      
                
+                       $msgbox_data = $this->bocommon->msgbox_data($receipt);

@@ Diff output truncated at 153600 characters. @@



reply via email to

[Prev in Thread] Current Thread [Next in Thread]