fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15342] helpdesk: update app


From: sigurdne
Subject: [Fmsystem-commits] [15342] helpdesk: update app
Date: Mon, 27 Jun 2016 18:51:17 +0000 (UTC)

Revision: 15342
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15342
Author:   sigurdne
Date:     2016-06-27 18:51:17 +0000 (Mon, 27 Jun 2016)
Log Message:
-----------
helpdesk: update app

Modified Paths:
--------------
    trunk/helpdesk/inc/class.botts.inc.php
    trunk/helpdesk/inc/class.sotts.inc.php
    trunk/helpdesk/inc/class.uitts.inc.php
    trunk/helpdesk/templates/base/tts.xsl

Added Paths:
-----------
    trunk/helpdesk/js/portico/
    trunk/helpdesk/js/portico/tts.add.js
    trunk/helpdesk/js/portico/tts.index.js
    trunk/helpdesk/js/portico/tts.view.js

Removed Paths:
-------------
    trunk/helpdesk/js/yahoo/

Modified: trunk/helpdesk/inc/class.botts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.botts.inc.php      2016-06-27 18:50:05 UTC (rev 
15341)
+++ trunk/helpdesk/inc/class.botts.inc.php      2016-06-27 18:51:17 UTC (rev 
15342)
@@ -58,9 +58,10 @@
                                'save'                  => true,
                        );
 
-               function __construct($session=false)
+               function __construct()
                {
                        $this->so                                       = 
CreateObject('helpdesk.sotts');
+                       $this->custom                           = & 
$this->so->custom;
                        $this->bocommon                         = 
CreateObject('property.bocommon');
                        $this->historylog                       = & 
$this->so->historylog;
                        $this->config                           = 
CreateObject('phpgwapi.config','helpdesk');
@@ -71,90 +72,115 @@
 
                        $this->config->read();
 
-                       if ($session)
+                       $this->start = phpgw::get_var('start', 'int', 
'REQUEST', 0);
+                       $this->query = phpgw::get_var('query');
+                       $this->sort = phpgw::get_var('sort');
+                       $this->order = phpgw::get_var('order');
+                       $this->status_id = phpgw::get_var('status_id', 
'string');
+                       $this->user_id = phpgw::get_var('user_id', 'int');
+                       $this->reported_by = phpgw::get_var('reported_by', 
'int');
+                       $this->cat_id = phpgw::get_var('cat_id', 'int');
+                       $this->allrows = phpgw::get_var('allrows', 'bool');
+                       $this->start_date = phpgw::get_var('filter_start_date', 
'string');
+                       $this->end_date = phpgw::get_var('filter_end_date', 
'string');
+               }
+
+
+               function column_list( $selected = array() )
+               {
+                       if (!$selected)
                        {
-                               $this->read_sessiondata();
-                               $this->use_session = true;
+                               $selected = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] 
: '';
                        }
+                       $_columns = $this->get_columns();
 
-                       $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');
+                       $columns = array();
+                       foreach ($_columns as $id => $column_info)
+                       {
+                               $columns[] = $column_info;
+                       }
 
+                       $column_list = 
$this->bocommon->select_multi_list($selected, $columns);
+                       return $column_list;
+               }
 
-                       $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 : '';
+               public function get_columns()
+               {
+                       $columns = array();
 
-                       $this->p_num                    = 
phpgw::get_var('p_num');
-               }
+                       $columns['modified_date'] = array(
+                               'id' => 'modified_date',
+                               'name' => lang('modified date'),
+//                                     'sortable'      => true
+                       );
 
+                       $columns['status'] = array(
+                               'id' => 'status',
+                               'name' => lang('status')
+                       );
+                       $columns['user'] = array(
+                               'id' => 'user',
+                               'name' => lang('user')
+                       );
+                       $columns['assignedto'] = array
+                               (
+                               'id' => 'assignedto',
+                               'name' => lang('assignedto')
+                       );
 
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
+                       $columns['billable_hours'] = array(
+                               'id' => 'billable_hours',
+                               'name' => lang('billable hours')
+                       );
+
+                       foreach ($this->uicols_related as $related)
                        {
-                               
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts',$data);
+                               $columns[$related] = array
+                                       (
+                                       'id' => $related,
+                                       'name' => ltrim(lang(str_replace('_', ' 
', $related)), '!')
+                               );
                        }
-               }
 
-               function read_sessiondata()
-               {
-                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts');
+                       if ($this->show_finnish_date)
+                       {
+                               $columns['finnish_date'] = array(
+                                       'id' => 'finnish_date',
+                                       'name' => lang('finnish_date')
+                               );
+                               $columns['delay'] = array(
+                                       'id' => 'delay',
+                                       'name' => lang('delay')
+                               );
+                       }
 
-                       $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']:'';
+                       $custom_cols = $this->get_custom_cols();
+
+                       foreach ($custom_cols as $custom_col)
+                       {
+                               $columns[$custom_col['column_name']] = array(
+                                       'id' => $custom_col['column_name'],
+                                       'name' => $custom_col['input_text'],
+                                       'datatype' => $custom_col['datatype'],
+                               );
+                               if (($custom_col['datatype'] == 'LB' || 
$custom_col['datatype'] == 'CH' || $custom_col['datatype'] == 'R') && 
$custom_col['choice'])
+                               {
+                                       $this->custom_filters[] = 
$custom_col['column_name'];
+                               }
+                       }
+                       return $columns;
                }
 
-               function column_list($selected = 
array(),$type_id='',$allrows='')
+               function get_custom_cols()
                {
-                       if(!$selected)
+                       static $custom_cols = array();
+
+                       if ($custom_cols)
                        {
-                               $selected = 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['ticket_columns'] 
: '';
+                               return $custom_cols;
                        }
-                       $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;
+                       $custom_cols = $this->custom->find('helpdesk', 
'.ticket', 0, '', 'ASC', 'attrib_sort', true, true);
+                       return $custom_cols;
                }
 
                function filter($data=0)
@@ -286,45 +312,80 @@
                        return $related;
                }
 
-               function read($start_date='', $end_date='', $dry_run = '', 
$download = '')
+               function get_custom_filters()
                {
+                       static $custom_filters = array();
+
+                       if ($custom_filters)
+                       {
+                               return $custom_filters;
+                       }
+
+                       $custom_cols = $this->get_custom_cols();
+                       foreach ($custom_cols as $custom_col)
+                       {
+                               if (($custom_col['datatype'] == 'LB' || 
$custom_col['datatype'] == 'CH' || $custom_col['datatype'] == 'R') && 
$custom_col['choice'])
+                               {
+                                       $custom_filters[] = 
$custom_col['column_name'];
+                               }
+                       }
+                       return $custom_filters;
+               }
+
+               function read( $data = array() )
+               {
                        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);
+                       $interlink = CreateObject('property.interlink');
+                       $data['start_date'] = 
$this->bocommon->date_to_timestamp($data['start_date']);
+                       $data['end_date'] = 
$this->bocommon->date_to_timestamp($data['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));
+                       $custom_filtermethod = array();
+                       foreach ($this->get_custom_filters() as $custom_filter)
+                       {
+                               if ($_REQUEST[$custom_filter]) //just testing..
+                               {
+                                       $custom_filtermethod[$custom_filter] = 
phpgw::get_var($custom_filter, 'int');
+                               }
+                       }
 
+                       $data['custom_filtermethod'] = $custom_filtermethod;
+
+                       $tickets = $this->so->read($data);
+
                        $this->total_records = $this->so->total_records;
-                       $entity = $this->get_origin_entity_type();
-                       $contacts       = CreateObject('property.sogeneric');
-                       $contacts->get_location_info('vendor',false);
+                       $this->sum_budget = $this->so->sum_budget;
+                       $this->sum_actual_cost = $this->so->sum_actual_cost;
+                       $this->sum_difference = $this->so->sum_difference;
 
-                       $custom                 = 
createObject('property.custom_fields');
-                       $vendor_data['attributes'] = 
$custom->find('helpdesk','.vendor', 0, '', 'ASC', 'attrib_sort', true, true);
+                       $custom_status = $this->so->get_custom_status();
+                       $closed_status = array('X');
+                       foreach ($custom_status as $custom)
+                       {
+                               if ($custom['closed'])
+                               {
+                                       $closed_status[] = "C{$custom['id']}";
+                               }
+                       }
 
                        foreach ($tickets as & $ticket)
                        {
-                               if(!isset($category_name[$ticket['cat_id']]))
+                               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']];
+                               $ticket['category'] = 
$category_name[$ticket['cat_id']];
 
-                               if(!$ticket['subject'])
+                               if (!$ticket['subject'])
                                {
                                        $ticket['subject'] = 
$category_name[$ticket['cat_id']];
                                }
 
-                               if(!isset($account[$ticket['user_id']]))
+
+                               if (!isset($account[$ticket['user_id']]))
                                {
                                        $ticket['user'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
                                        $account[$ticket['user_id']] = 
$ticket['user'];
@@ -334,9 +395,9 @@
                                        $ticket['user'] = 
$account[$ticket['user_id']];
                                }
 
-                               if($ticket['assignedto'])
+                               if ($ticket['assignedto'])
                                {
-                                       
if(!isset($account[$ticket['assignedto']]))
+                                       if 
(!isset($account[$ticket['assignedto']]))
                                        {
                                                $ticket['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
                                                $account[$ticket['assignedto']] 
= $ticket['assignedto'];
@@ -348,7 +409,7 @@
                                }
                                else
                                {
-                                       
if(!isset($account[$ticket['group_id']]))
+                                       if 
(!isset($account[$ticket['group_id']]))
                                        {
                                                $ticket['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
                                                $account[$ticket['group_id']] = 
$ticket['assignedto'];
@@ -359,61 +420,20 @@
                                        }
                                }
 
-                               $ticket['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['entry_date'],$this->dateformat);
-
-                               if($ticket['finnish_date2'])
+                               $ticket['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['entry_date'], $this->dateformat);
+                               $ticket['modified_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['modified_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['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):'');
+                               $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;
                }
 
@@ -976,4 +996,64 @@
                        $this->fields_updated = $this->so->fields_updated;      
        
                        return $receipt;
                }
+
+               public function get_reported_by( $selected = 0 )
+               {
+                       $values = $this->so->get_reported_by();
+
+                       foreach ($values as &$entry)
+                       {
+                               $entry['selected'] = $entry['id'] == $selected 
? 1 : 0;
+                       }
+                       return $values;
+               }
+               public function get_attributes( $values )
+               {
+                       $values['attributes'] = $this->get_custom_cols();
+                       $values = $this->custom->prepare($values, 'helpdesk', 
'.ticket', false);
+                       return $values;
+               }
+               function get_group_list( $selected = 0 )
+               {
+                       $query = '';
+                       $group_list = $this->bocommon->get_group_list('select', 
$selected, $start = -1, $sort = 'ASC', $order = 'account_firstname', $query, 
$offset = -1);
+                       $_candidates = array();
+                       if 
(isset($this->config->config_data['fmtts_assign_group_candidates']) && 
is_array($this->config->config_data['fmtts_assign_group_candidates']))
+                       {
+                               foreach 
($this->config->config_data['fmtts_assign_group_candidates'] as 
$group_candidate)
+                               {
+                                       if ($group_candidate)
+                                       {
+                                               $_candidates[] = 
$group_candidate;
+                                       }
+                               }
+                       }
+
+                       if ($_candidates)
+                       {
+                               if ($selected)
+                               {
+                                       if (!in_array($selected, $_candidates))
+                                       {
+                                               $_candidates[] = $selected;
+                                       }
+                               }
+
+                               $values = array();
+                               foreach ($group_list as $group)
+                               {
+                                       if (in_array($group['id'], 
$_candidates))
+                                       {
+                                               $values[] = $group;
+                                       }
+                               }
+
+                               return $values;
+                       }
+                       else
+                       {
+                               return $group_list;
+                       }
+               }
+
        }

Modified: trunk/helpdesk/inc/class.sotts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.sotts.inc.php      2016-06-27 18:50:05 UTC (rev 
15341)
+++ trunk/helpdesk/inc/class.sotts.inc.php      2016-06-27 18:51:17 UTC (rev 
15342)
@@ -67,6 +67,7 @@
                        $this->join             = & $this->db->join;
                        $this->left_join        = & $this->db->left_join;
                        $this->dateformat       = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $this->custom           = 
createObject('property.custom_fields');
                }
 
 
@@ -112,7 +113,6 @@
                        $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;
@@ -201,7 +201,7 @@
                                        }
                                        unset($user);
                                        reset($public_user_list);
-                                       $filtermethod .= " $where 
((phpgw_helpdesk_tickets.user_id IN(" . implode(',', $public_user_list) . ")";
+                                       $filtermethod .= " $where 
(phpgw_helpdesk_tickets.user_id IN(" . implode(',', $public_user_list) . ")";
                                        $where = 'AND';
                                }
 
@@ -329,12 +329,6 @@
                                $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();
@@ -343,35 +337,13 @@
                                $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 . ')';
-                               }
+                               $querymethod = " $where subject $this->like 
'%$query%'";
+
                        }
 
                        $sql = "SELECT DISTINCT phpgw_helpdesk_tickets.* , 
phpgw_helpdesk_views.id as view {$result_order_field} FROM 
phpgw_helpdesk_tickets"
@@ -380,6 +352,7 @@
                                . " $filtermethod $querymethod";
 
                        $sql2 = "SELECT count(*) as cnt FROM ({$sql}) as t";
+                       _debug_array($sql2);
                        $this->db->query($sql2,__LINE__,__FILE__);
                        $this->db->next_record();
                        $this->total_records = $this->db->f('cnt');
@@ -412,11 +385,7 @@
                                                (
                                                        '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'),
@@ -985,8 +954,8 @@
                        {
                                $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__);
+                               $_history_id = 
$this->db->get_last_insert_id('phpgw_history_log','history_id');
+                               $this->db->query("UPDATE phpgw_history_log SET 
publish = 1 WHERE history_id = $_history_id",__LINE__,__FILE__);
                                unset($_history_id);
                        }
 
@@ -1196,4 +1165,24 @@
                                return false;
                        }
                }
+
+               public function get_reported_by()
+               {
+                       $values = array();
+                       $sql = "SELECT DISTINCT user_id as id , 
account_lastname, account_firstname FROM phpgw_helpdesk_tickets"
+                               . " {$this->join} phpgw_accounts ON 
phpgw_helpdesk_tickets.user_id = phpgw_accounts.account_id"
+                               . " ORDER BY account_lastname ASC";
+
+                       $this->db->query($sql, __LINE__, __FILE__);
+
+                       while ($this->db->next_record())
+                       {
+                               $values[] = array(
+                                       'id' => $this->db->f('id'),
+                                       'name' => 
$this->db->f('account_lastname', true) . ', ' . 
$this->db->f('account_firstname', true)
+                               );
+                       }
+
+                       return $values;
+               }
        }

Modified: trunk/helpdesk/inc/class.uitts.inc.php
===================================================================
--- trunk/helpdesk/inc/class.uitts.inc.php      2016-06-27 18:50:05 UTC (rev 
15341)
+++ trunk/helpdesk/inc/class.uitts.inc.php      2016-06-27 18:51:17 UTC (rev 
15342)
@@ -32,9 +32,9 @@
         * @package helpdesk
         */
 
-       phpgw::import_class('phpgwapi.yui');
+       phpgw::import_class('phpgwapi.uicommon_jquery');
 
-       class helpdesk_uitts
+       class helpdesk_uitts extends phpgwapi_uicommon_jquery
        {
                var $public_functions = array
                        (
@@ -63,6 +63,8 @@
 
                public function __construct()
                {
+                       parent::__construct();
+
                        $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
'helpdesk::helpdesk';
                        if($this->tenant_id     = 
$GLOBALS['phpgw']->session->appsession('tenant_id','helpdesk'))
                        {
@@ -73,7 +75,6 @@
 
                        $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;
@@ -124,23 +125,89 @@
                        $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()
+               /**
+                * Fetch data from $this->bo based on parametres
+                * @return array
+                */
+               public function query()
                {
-                       $data = array
+                       $search = phpgw::get_var('search');
+                       $order = phpgw::get_var('order');
+                       $draw = phpgw::get_var('draw', 'int');
+                       $columns = phpgw::get_var('columns');
+                       $export = phpgw::get_var('export', 'bool');
+
+                       $params = array(
+                               'start' => phpgw::get_var('start', 'int', 
'REQUEST', 0),
+                               'results' => phpgw::get_var('length', 'int', 
'REQUEST', 0),
+                               'query' => $search['value'],
+                               'order' => 
$columns[$order[0]['column']]['data'],
+                               'sort' => $order[0]['dir'],
+                               'dir' => $order[0]['dir'],
+                               'cat_id' => phpgw::get_var('cat_id', 'int', 
'REQUEST', 0),
+                               'allrows' => phpgw::get_var('length', 'int') == 
-1 || $export,
+                               'status_id' => $this->bo->status_id,
+                               'user_id' => $this->bo->user_id,
+                               'reported_by' => $this->bo->reported_by,
+                               'cat_id' => $this->bo->cat_id,
+                               'vendor_id' => $this->bo->vendor_id,
+                               'district_id' => $this->bo->district_id,
+                               'part_of_town_id' => $this->bo->part_of_town_id,
+                               'allrows' => $this->bo->allrows,
+                               'start_date' => $this->bo->start_date,
+                               'end_date' => $this->bo->end_date,
+                               'location_code' => $this->bo->location_code,
+                               'p_num' => $this->bo->p_num,
+                               'building_part' => $this->bo->building_part,
+                               'b_account' => $this->bo->b_account,
+                               'ecodimb' => $this->bo->ecodimb,
+                               'branch_id' => phpgw::get_var('branch_id'),
+                               'order_dim1' => phpgw::get_var('order_dim1'),
+                       );
+
+                       $values = $this->bo->read($params);
+
+                       if ($values)
+                       {
+                               $status = array();
+                               $status['X'] = lang('closed');
+                               $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['C'] = lang('closed');
+
+                               $custom_status = $this->bo->get_custom_status();
+
+                               foreach ($custom_status as $custom)
+                               {
+                                       $status["C{$custom['id']}"] = 
$custom['name'];
+                               }
+
+                               foreach ($values as &$entry)
+                               {
+                                       $entry['status'] = 
$status[$entry['status']];
+                               }
+                       }
+
+                       if ($export)
+                       {
+                               return $values;
+                       }
+//_debug_array($values);
+                       $result_data = array('results' => $values);
+
+                       $result_data['total_records'] = 
$this->bo->total_records;
+                       $result_data['sum_budget'] = $this->bo->sum_budget;
+                       $result_data['sum_actual_cost'] = 
$this->bo->sum_actual_cost;
+                       $result_data['sum_difference'] = 
$this->bo->sum_difference;
+                       $result_data['draw'] = $draw;
+
+                       $link_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);
+                               'menuaction' => 'helpdesk.uitts.view',
+                       );
+
+                       array_walk($result_data['results'], array($this, 
'_add_links'), $link_data);
+//                     _debug_array($result_data);
+                       return $this->jquery_results($result_data);
                }
 
                function _print()
@@ -351,1970 +418,1350 @@
                }
 
 
-               function index()
+               private function _get_fields()
                {
-                       if($this->tenant_id)
-                       {
-                               //                              
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.index2'));
-                       }
+                       $this->bo->get_origin_entity_type();
+                       $uicols_related = $this->bo->uicols_related;
 
-                       if(!$this->acl_read)
-                       {
-                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=> 1, 'acl_location'=> $this->acl_location));
-                       }
+                       $uicols = array();
 
-                       $this->save_sessiondata();
-                       $dry_run = false;
-                       $second_display = phpgw::get_var('second_display', 
'bool');
+                       $uicols['name'][] = 'id';
+                       $uicols['descr'][] = lang('id');
+                       $uicols['name'][] = 'priority';
+                       $uicols['descr'][] = lang('priority');
+                       $uicols['name'][] = 'subject';
+                       $uicols['descr'][] = lang('subject');
+                       $uicols['name'][] = 'entry_date';
+                       $uicols['descr'][] = lang('entry date');
 
-                       $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);
+                       $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();
+                       $columns = $this->bo->get_columns();
 
-                       if ($default_category && !$second_display && 
!$this->district_id)
+                       foreach ($custom_cols as $col)
                        {
-                               $this->bo->district_id  = $default_category;
-                               $this->district_id              = 
$default_category;
+                               $uicols['name'][] = $col;
+                               $uicols['descr'][] = $columns[$col]['name'];
                        }
 
-                       if ($default_status && !$second_display)
-                       {
-                               $this->bo->status_id    = $default_status;
-                               $this->status_id                = 
$default_status;
-                       }
+                       $uicols['name'][] = 'link_view';
+                       $uicols['descr'][] = lang('link view');
+                       $uicols['name'][] = 'lang_view_statustext';
+                       $uicols['descr'][] = lang('lang view statustext');
+                       $uicols['name'][] = 'text_view';
+                       $uicols['descr'][] = lang('text view');
 
-                       $bgcolor_array[1]       = '#da7a7a';
-                       $bgcolor_array[2]       = '#dababa';
-                       $bgcolor_array[3]       = '#dadada';
+                       $count_uicols_name = count($uicols['name']);
 
-                       $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' )
+                       $fields = array();
+                       for ($k = 0; $k < $count_uicols_name; $k++)
                        {
-                               $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
-                                       )
+                               $params = array(
+                                       'key' => $uicols['name'][$k],
+                                       'label' => $uicols['descr'][$k],
+                                       'sortable' => false,
+                                       'hidden' => ($uicols['input_type'][$k] 
== 'hidden') ? true : false
                                );
 
-                               $datatable['config']['allow_allrows'] = true;
+                               if (isset($uicols_related) && 
in_array($uicols['name'][$k], $uicols_related))
+                               {
+                                       $params['formatter'] = 
'JqueryPortico.formatLinkRelated';
+                               }
 
-                               $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}'";
+                               if ($uicols['datatype'][$k] == 'link')
+                               {
+                                       $params['formatter'] = 
'JqueryPortico.formatLinkGeneric';
+                               }
 
-                               $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'])
+                               if ($uicols['name'][$k] == 'id')
                                {
-                                       array_unshift 
($values_combo_box[1],array 
('id'=>'O2','name'=>$this->bo->config->config_data['tts_lang_open']));
+                                       $params['formatter'] = 
'JqueryPortico.formatTtsIdLink';
                                }
-                               $default_value = array 
('id'=>'','name'=>lang('Open'));
-                               array_unshift 
($values_combo_box[1],$default_value);
 
-                               if(!$this->_simple)
+                               if ($uicols['name'][$k] == 'entry_date')
                                {
-                                       $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);
+                                       $params['formatter'] = 
'JqueryPortico.formatLink';
+                               }
 
-                                       $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])
-                                                                       ),
-                                                               )
-                                                       )
-                                               )
-                                       );
+                               if ($uicols['name'][$k] == 'location_code')
+                               {
+                                       $params['formatter'] = 
'JqueryPortico.searchLinkTts';
                                }
-                               else
+                               if ($uicols['name'][$k] == 'estimate')
                                {
-                                       $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])
-                                                                       )
-                                                               )
-                                                       )
-                                               )
-                                       );                              
+                                       $params['formatter'] = 
'JqueryPortico.FormatterAmount0';
                                }
-                               $dry_run = true;
-                       }
-
-                       $ticket_list = array();
-                       //                      if(!$dry_run)
+                               if ($uicols['name'][$k] == 'actual_cost')
                                {
-                                       $ticket_list = 
$this->bo->read($start_date, $end_date,'',$dry_run);
+                                       $params['formatter'] = 
'JqueryPortico.FormatterAmount0';
                                }
+                               if ($uicols['name'][$k] == 'difference')
+                               {
+                                       $params['formatter'] = 
'JqueryPortico.FormatterAmount0';
+                               }
+                               if ($uicols['name'][$k] == 'address' || 
$uicols['name'][$k] == 'id' || $uicols['name'][$k] == 'priority')
+                               {
+                                       $params['sortable'] = true;
+                               }
+                               if ($uicols['name'][$k] == 'priority' || 
$uicols['name'][$k] == 'id' || $uicols['name'][$k] == 'assignedto' || 
$uicols['name'][$k] == 'finnish_date' || $uicols['name'][$k] == 'user' || 
$uicols['name'][$k] == 'entry_date' || $uicols['name'][$k] == 'order_id' || 
$uicols['name'][$k] == 'modified_date')
+                               {
+                                       $params['sortable'] = true;
+                               }
+                               if ($uicols['name'][$k] == 'text_view' || 
$uicols['name'][$k] == 'bgcolor' || $uicols['name'][$k] == 'link_view' || 
$uicols['name'][$k] == 'lang_view_statustext' || $uicols['name'][$k] == 
'hidden_id')
+                               {
+                                       $params['hidden'] = true;
+                               }
 
-                       $this->bo->get_origin_entity_type();
-                       $uicols_related = $this->bo->uicols_related;
-                       //_debug_array($uicols_related);
-                       $uicols = array();
+                               $fields[] = $params;
+                       }
+                       return $fields;
+               }
 
-                       $uicols['name'][] = 'priority';
-                       $uicols['name'][] = 'id';
-                       $uicols['name'][] = 'bgcolor';
-                       $uicols['name'][] = 'subject';
-                       $uicols['name'][] = 'assignedto';
-                       $uicols['name'][] = 'entry_date';
-                       $uicols['name'][] = 'status';
+               private function _get_filters()
+               {
+                       $values_combo_box = array();
+                       $combos = array();
 
-                       if( $this->acl->check('.ticket.order', PHPGW_ACL_READ, 
'helpdesk') )
-                       {
-                               $uicols['name'][] = 'order_id';
-                               $uicols['name'][] = 'vendor';
-                       }
+                       $values_combo_box[3] = $this->bo->filter(array('format' 
=> $group_filters, 'filter' => $this->status_id,
+                               'default' => 'O'));
 
-                       if( $this->acl->check('.ticket.order', PHPGW_ACL_ADD, 
'helpdesk') )
+                       if 
(isset($this->bo->config->config_data['tts_lang_open']) && 
$this->bo->config->config_data['tts_lang_open'])
                        {
-                               $uicols['name'][] = 'estimate';
-                               $uicols['name'][] = 'actual_cost';
+                               array_unshift($values_combo_box[3], array('id' 
=> 'O2', 'name' => $this->bo->config->config_data['tts_lang_open']));
                        }
+                       $default_value = array('id' => '', 'name' => 
lang('Open'));
+                       array_unshift($values_combo_box[3], $default_value);
 
-/*
-                       foreach($uicols_related as $related)
+                       $combos[] = array('type' => 'filter',
+                               'name' => 'status_id',
+                               'extra' => $code,
+                               'text' => lang('status'),
+                               'list' => $values_combo_box[3]
+                       );
+
+                       if(!$this->simple)
                        {
-                               $uicols['name'][] = $related;                   
-                       }
-*/
-                       if( $this->_show_finnish_date )
-                       {
-                               $uicols['name'][] = 'finnish_date';
-                               $uicols['name'][] = 'delay';
-                       }
+                               $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);
 
-                       $uicols['name'][] = 'child_date';
-                       $uicols['name'][] = 'link_view';
-                       $uicols['name'][] = 'lang_view_statustext';
-                       $uicols['name'][] = 'text_view';
+                               $_categories = array();
+                               foreach ($values_combo_box[0]['cat_list'] as 
$_category)
+                               {
+                                       $_categories[] = array('id' => 
$_category['cat_id'], 'name' => $_category['name']);
+                               }
 
-                       $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();
+                               $combos[] = array('type' => 'filter',
+                                       'name' => 'cat_id',
+                                       'extra' => '',
+                                       'text' => lang('category'),
+                                       'list' => $_categories
+                               );
 
-                       foreach ($custom_cols as $col)
-                       {
-                               //                      $uicols['input_type'][] 
= 'text';
-                               $uicols['name'][]                       = $col;
-                               //                      $uicols['descr'][]      
        = lang(str_replace('_', ' ', $col));
-                               //                      $uicols['statustext'][] 
= $col;
-                       }
+                               $filter_tts_assigned_to_me = 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_assigned_to_me'];
 
+                               $values_combo_box[4] = 
$this->bocommon->get_user_list_right2('filter', PHPGW_ACL_EDIT, $this->user_id, 
$this->acl_location);
+                               array_unshift($values_combo_box[4], array(
+                                       'id' => -1 * 
$GLOBALS['phpgw_info']['user']['account_id'],
+                                       'name' => lang('my assigned tickets'),
+                                       'selected'      => ((int)$this->user_id 
< 0  || (int)$filter_tts_assigned_to_me == 1) ? 1 : 0));
 
-                       $count_uicols_name = count($uicols['name']);
+                               array_unshift($values_combo_box[4], array('id' 
=> '', 'name' => lang('assigned to')));
+                               $combos[] = array('type' => 'filter',
+                                       'name' => 'user_id',
+                                       'extra' => '',
+                                       'text' => lang('assigned to'),
+                                       'list' => $values_combo_box[4]
+                               );
 
+                               $values_combo_box[5] = 
$this->bo->get_reported_by($this->reported_by);
+                               array_unshift($values_combo_box[5], array('id' 
=> $GLOBALS['phpgw_info']['user']['account_id'],
+                                       'name' => lang('my submitted 
tickets')));
+                               array_unshift($values_combo_box[5], array('id' 
=> '', 'name' => lang('reported by')));
+                               $combos[] = array('type' => 'filter',
+                                       'name' => 'reported_by',
+                                       'extra' => '',
+                                       'text' => lang('reported by'),
+                                       'list' => $values_combo_box[5]
+                               );
+                       }
 
-                       $j = 0;
-                       $k = 0;
-                       if(is_array($ticket_list))
+                       $attrib_data = $this->bo->get_custom_cols();
+                       if ($attrib_data)
                        {
-                               $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)
+                               foreach ($attrib_data as $attrib)
                                {
-                                       $status["C{$custom['id']}"] = array
-                                               (
-                                                       'status'                
        => $custom['name'],
+                                       $_filter_data = array();
+                                       if (($attrib['datatype'] == 'LB' || 
$attrib['datatype'] == 'CH' || $attrib['datatype'] == 'R') && $attrib['choice'])
+                                       {
+
+                                               $_filter_data[] = array
+                                                       (
+                                                       'id' => '',
+                                                       'name' => 
lang('select') . " {$attrib['input_text']}"
                                                );
-                               }
 
-                               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))
+                                               $_selected = 
phpgw::get_var($attrib['column_name']);
+                                               foreach ($attrib['choice'] as 
$choice)
                                                {
-                                                       
$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
+                                                       $_filter_data[] = 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';
+                                                               'id' => 
$choice['id'],
+                                                               'name' => 
htmlspecialchars($choice['value'], ENT_QUOTES, 'UTF-8'),
+                                                               'selected' => 
$choice['id'] == $_selected ? 1 : 0
+                                                       );
                                                }
 
-                                               $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++;
-                                               }
+                                               $combos[] = array('type' => 
'filter',
+                                                       'name' => 
$attrib['column_name'],
+                                                       'extra' => '',
+                                                       'text' => 
$attrib['input_text'],
+                                                       'list' => $_filter_data
+                                               );
                                        }
-
-                                       $j++;
                                }
                        }
 
-                       $parameters = array
-                               (
-                                       'parameter' => array
-                                       (
-                                               array
-                                               (
-                                                       'name'          => 'id',
-                                                       'source'        => 'id'
+                       return $combos;
+               }
+
+               function index()
+               {
+                       if (!$this->acl_read)
+                       {
+                               phpgw::no_access();
+                               return;
+                       }
+
+                       if (phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+                               return $this->query();
+                       }
+
+                       phpgwapi_jquery::load_widget('numberformat');
+                       self::add_javascript('phpgwapi', 'jquery', 
'editable/jquery.jeditable.js');
+                       self::add_javascript('phpgwapi', 'jquery', 
'editable/jquery.dataTables.editable.js');
+                       self::add_javascript('helpdesk', 'portico', 
'tts.index.js');
+
+                       $start_date = urldecode($this->start_date);
+                       $end_date = urldecode($this->end_date);
+
+                       
$GLOBALS['phpgw']->jqcal->add_listener('filter_start_date');
+                       
$GLOBALS['phpgw']->jqcal->add_listener('filter_end_date');
+
+                       $appname = lang('helpdesk');
+                       $function_msg = lang('list ticket');
+
+                       $data = array(
+                               'datatable_name' => $appname . ': ' . 
$function_msg,
+                               'form' => array(
+                                       'toolbar' => array(
+                                               'item' => array(
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('columns'),
+                                                               'href' => '#',
+                                                               'class' => '',
+                                                               'onclick' => 
"JqueryPortico.openPopup({menuaction:'helpdesk.uitts.columns'}, 
{closeAction:'reload'})"
+                                                       ),
+                                                       array
+                                                               (
+                                                               'type' => 
'date-picker',
+                                                               'id' => 
'start_date',
+                                                               'name' => 
'start_date',
+                                                               'value' => 
$start_date,
+                                                               'text' => 
lang('from')
+                                                       ),
+                                                       array
+                                                               (
+                                                               'type' => 
'date-picker',
+                                                               'id' => 
'end_date',
+                                                               'name' => 
'end_date',
+                                                               'value' => 
$end_date,
+                                                               'text' => 
lang('to')
+                                                       )
                                                ),
-                                       )
-                               );
+                                       ),
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 'helpdesk.uitts.index',
+                                               'phpgw_return_as' => 'json')),
+                                       'download' => 
self::link(array('menuaction' => 'helpdesk.uitts.download',
+                                               'export' => true, 'allrows' => 
true)),
+                                       'allrows' => true,
+                                       'new_item' => 
self::link(array('menuaction' => 'helpdesk.uitts.add')),
+                                       'editor_action' => 
self::link(array('menuaction' => 'helpdesk.uitts.edit_survey_title')),
+                                       'field' => $this->_get_fields(),
+                                       'query' => phpgw::get_var('query')
+                               )
+                       );
 
-                       if($this->acl_read)
+                       $filters = $this->_get_filters();
+
+                       foreach ($filters as $filter)
                        {
-                               $datatable['rowactions']['action'][] = array
+                               array_unshift($data['form']['toolbar']['item'], 
$filter);
+                       }
+
+                       $parameters = array(
+                               'parameter' => array(
+                                       array(
+                                               'name' => 'id',
+                                               'source' => 'id'
+                                       ),
+                               )
+                       );
+
+                       $data['datatable']['actions'][] = array
+                               (
+                               'my_name' => 'view_survey',
+                               'text' => lang('view'),
+                               'action' => 
$GLOBALS['phpgw']->link('/index.php', 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
-                                       );
+                                       'menuaction' => 'helpdesk.uitts.view'
+                               )),
+                               'parameters' => json_encode($parameters)
+                       );
 
-                               $datatable['rowactions']['action'][] = array
+                       $data['datatable']['actions'][] = array
+                               (
+                               'my_name' => 'print',
+                               'statustext' => lang('print the ticket'),
+                               'text' => lang('print view'),
+                               'action' => 
$GLOBALS['phpgw']->link('/index.php', 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
-                                       );
+                                       'menuaction' => 'helpdesk.uitts._print',
+                                       'target' => '_blank'
+                               )),
+                               'parameters' => json_encode($parameters)
+                       );
 
 
-                               $jasper = execMethod('property.sojasper.read', 
array('location_id' => $GLOBALS['phpgw']->locations->get_id('helpdesk', 
$this->acl_location)));
+                       $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)
+                       foreach ($jasper as $report)
                        {
-                               $datatable['rowactions']['action'][] = array
+                               $data['datatable']['actions'][] = 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
+                                       'my_name' => 'edit',
+                                       'text' => lang('open JasperReport %1 in 
new window', $report['title']),
+                                       'action' => 
$GLOBALS['phpgw']->link('/index.php', array
                                                (
-                                                       'menuaction'    => 
'helpdesk.uitts.delete'
-                                               )),
-                                               'parameters'    => $parameters
-                                       );
+                                               'menuaction' => 
'helpdesk.uijasper.view',
+                                               'jasper_id' => $report['id'],
+                                               'target' => '_blank'
+                                       )),
+                                       'parameters' => json_encode($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)
+                       if ($this->acl_delete)
                        {
-
-                               unset($status['C']);
-                               foreach ($status as $status_code => 
$status_info)
-                               {
-                                       $datatable['rowactions']['action'][] = 
array
+                               $data['datatable']['actions'][] = 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
                                                (
-                                                       '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
-                                               );
-                               }
+                                               'menuaction' => 
'helpdesk.uitts.delete'
+                                       )),
+                                       'parameters' => json_encode($parameters)
+                               );
                        }
 
-                       if($this->acl_add)
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'])
 && 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'] == 
'yes' && $this->acl_edit)
                        {
-                               $datatable['rowactions']['action'][] = array
+                               $status['X'] = array
                                        (
-                                               'my_name'                       
=> 'add',
-                                               'statustext'    => lang('Add 
new ticket'),
-                                               'text'                  => 
lang('add'),
-                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',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'),
+                               );
+
+                               $custom_status = $this->bo->get_custom_status();
+
+                               foreach ($custom_status as $custom)
+                               {
+                                       $status["C{$custom['id']}"] = array
                                                (
-                                                       'menuaction'    => 
'helpdesk.uitts.add'
-                                               ))
+                                               'status' => $custom['name'],
                                        );
-                       }
+                               }
 
-                       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')
+                               foreach ($status as $status_code => 
$status_info)
                                {
-                                       
$datatable['headers']['header'][$i]['sortable']         = true;
-                                       
$datatable['headers']['header'][$i]['sort_field']   = $uicols['name'][$i];
+                                       $data['datatable']['actions'][] = array
+                                               (
+                                               'my_name' => 'status',
+                                               'statustext' => 
$status_info['status'],
+                                               'text' => lang('change to') . ' 
status:  ' . $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 property.js.
+                                               )),
+                                               'parameters' => 
json_encode($parameters)
+                                       );
                                }
-                               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";
+                               $_priorities = $this->bo->get_priority_list();
 
-                       // 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 )
+                               foreach ($_priorities as $_priority_info)
                                {
-                                       $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;
+                                       $data['datatable']['actions'][] = array
+                                               (
+                                               'my_name' => 'priority',
+                                               'statustext' => 
$_priority_info['name'],
+                                               'text' => lang('change to') . ' 
' . lang('priority') . ':  ' . $_priority_info['name'],
+                                               'confirm_msg' => lang('do you 
really want to change the priority to %1', $_priority_info['name']),
+                                               'action' => 
$GLOBALS['phpgw']->link('/index.php', array
+                                                       (
+                                                       'menuaction' => 
'helpdesk.uitts.edit_priority',
+                                                       'edit_status' => true,
+                                                       'new_priority' => 
$_priority_info['id'],
+                                                       '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 property.js.
+                                               )),
+                                               'parameters' => 
json_encode($parameters)
+                                       );
                                }
                        }
 
-                       // 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']))
+                       if (count($data['datatable']['actions']) < 10)
                        {
-                               $json ['rights'] = 
$datatable['rowactions']['action'];
+                               $data['datatable']['group_buttons'] = false;
                        }
 
-                       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' );
+                       self::render_template_xsl('datatable_jquery', $data);
                }
 
-
                function add()
                {
-                       if(!$this->acl_add)
+                       if (!$this->acl_add)
                        {
-                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=> 2, 'acl_location'=> $this->acl_location));
+                               phpgw::no_access();
                        }
-                       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');
+                       $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'));
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'helpdesk.uitts.index'));
                        }
 
+                       $values_attribute = phpgw::get_var('values_attribute');
+
                        //------------------- start ticket from other location
-                       $bypass                 = phpgw::get_var('bypass', 
'bool');
-                       if(isset($_POST) && $_POST && isset($bypass) && $bypass)
+                       $bypass = phpgw::get_var('bypass', 'bool');
+//                     if(isset($_POST) && $_POST && isset($bypass) && $bypass)
+                       if ($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');
+                               $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));
-                               }
+                               $origin = phpgw::get_var('origin');
+                               $origin_id = phpgw::get_var('origin_id', 'int');
                        }
 
-                       if(isset($values['origin']) && $values['origin'])
+                       if (isset($values['origin']) && $values['origin'])
                        {
-                               $origin         = $values['origin'];
-                               $origin_id      = $values['origin_id'];
+                               $origin = $values['origin'];
+                               $origin_id = $values['origin_id'];
                        }
 
-                       $interlink      = CreateObject('property.interlink');
+                       $interlink = CreateObject('property.interlink');
 
-                       if(isset($origin) && $origin)
+                       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
+                               $values['origin_data'][0]['location'] = $origin;
+                               $values['origin_data'][0]['descr'] = 
$interlink->get_location_name($origin);
+                               $values['origin_data'][0]['data'][] = array
                                        (
-                                               'id'    => $origin_id,
-                                               'link'  => 
$interlink->get_relation_link(array('location' => $origin), $origin_id),
-                                       );
+                                       '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');
+                               $insert_record = 
$GLOBALS['phpgw']->session->appsession('insert_record', 'helpdesk');
 
-                               if(isset($insert_record_entity) && 
is_array($insert_record_entity))
+                               $insert_record_entity = 
$GLOBALS['phpgw']->session->appsession('insert_record_values' . 
$this->acl_location, 'helpdesk');
+
+                               if (isset($insert_record_entity) && 
is_array($insert_record_entity))
                                {
-                                       for 
($j=0;$j<count($insert_record_entity);$j++)
+                                       for ($j = 0; $j < 
count($insert_record_entity); $j++)
                                        {
-                                               
$insert_record['extra'][$insert_record_entity[$j]]      = 
$insert_record_entity[$j];
+                                               
$insert_record['extra'][$insert_record_entity[$j]] = $insert_record_entity[$j];
                                        }
                                }
 
-                               $values = 
$this->bocommon->collect_locationdata($values,$insert_record);
+                               $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'])
+                               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 !'));
+                                       $receipt['error'][] = array('msg' => 
lang('Please enter a title !'));
                                }
 
-                               if(!$values['cat_id'])
+                               if (!$values['cat_id'])
                                {
-                                       
$receipt['error'][]=array('msg'=>lang('Please select a category !'));
+                                       $receipt['error'][] = array('msg' => 
lang('Please select a category !'));
                                }
 
-                               if(!isset($values['details']) || 
!$values['details'])
+                               if (!isset($values['details']) || 
!$values['details'])
                                {
-                                       
$receipt['error'][]=array('msg'=>lang('Please give som 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']))
+                               if (isset($values_attribute) && 
is_array($values_attribute))
                                {
-//                                     
$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)
+                                       foreach ($values_attribute as 
&$attribute)
                                        {
-                                               
$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 )
+                                               if ($attribute['nullable'] != 1 
&& (!$attribute['value'] && !$values['extra'][$attribute['name']]))
                                                {
-                                                       $values['assignedto'] = 
$_responsible;
+                                                       $receipt['error'][] = 
array('msg' => lang('Please enter value for attribute %1', 
$attribute['input_text']));
                                                }
-                                               else
+
+                                               if (isset($attribute['value']) 
&& $attribute['value'] && $attribute['datatype'] == 'I' && 
!ctype_digit($attribute['value']))
                                                {
-                                                       $values['group_id'] = 
$_responsible;
+                                                       $receipt['error'][] = 
array('msg' => lang('Please enter integer for attribute %1', 
$attribute['input_text']));
                                                }
+
+                                               if (isset($attribute['value']) 
&& $attribute['value'] && $attribute['datatype'] == 'V' && 
strlen($attribute['value']) > $attribute['precision'])
+                                               {
+                                                       $receipt['error'][] = 
array('msg' => lang('Max length for attribute %1 is: %2', 
"\"{$attribute['input_text']}\"", $attribute['precision']));
+                                                       $attribute['value'] = 
substr($attribute['value'], 0, $attribute['precision']);
+                                               }
                                        }
-                                       unset($_responsible);
                                }
 
-                               if(!isset($values['priority']) || 
!$values['priority'])
+
+                               if (!$values['assignedto'] && 
!$values['group_id'])
                                {
+                                       $receipt['error'][] = array('msg' => 
lang('Please select a person or a group to handle the ticket !'));
+                               }
+
+                               if (!isset($values['priority']) || 
!$values['priority'])
+                               {
                                        $_priority = 
$this->bo->get_priority_list();
                                        $values['priority'] = count($_priority);
                                        unset($_priority);
                                }
 
-                               if(!isset($receipt['error']))
+                               if (isset($values_attribute) && 
is_array($values_attribute))
                                {
-                                       $receipt = $this->bo->add($values);
+                                       foreach ($values_attribute as 
$attribute)
+                                       {
+                                               if ($attribute['nullable'] != 1 
&& (!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                               {
+                                                       $receipt['error'][] = 
array('msg' => lang('Please enter value for attribute %1', 
$attribute['input_text']));
+                                               }
+                                       }
+                               }
 
+                               if (!isset($receipt['error']))
+                               {
+                                       $receipt = $this->bo->add($values, 
$values_attribute);
+
                                        //------------ files
-                                       $values['file_name'] = @str_replace(' 
','_',$_FILES['file']['name']);
+                                       $values['file_name'] = @str_replace(' 
', '_', $_FILES['file']['name']);
 
-                                       if($values['file_name'] && 
$receipt['id'])
+                                       if ($values['file_name'] && 
$receipt['id'])
                                        {
-                                               $bofiles        = 
CreateObject('property.bofiles','/helpdesk');
-                                               $to_file = $bofiles->fakebase . 
"/{$receipt['id']}/{$values['file_name']}";
+                                               $bofiles = 
CreateObject('property.bofiles');
+                                               $to_file = $bofiles->fakebase . 
'/helpdesk/' . $receipt['id'] . '/' . $values['file_name'];
 
-                                               
if($bofiles->vfs->file_exists(array(
-                                                       'string' => $to_file,
-                                                       'relatives' => 
array(RELATIVE_NONE)
-                                               )))
+                                               if 
($bofiles->vfs->file_exists(array(
+                                                               'string' => 
$to_file,
+                                                               'relatives' => 
array(RELATIVE_NONE)
+                                                       )))
                                                {
-                                                       
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
+                                                       $receipt['error'][] = 
array('msg' => lang('This file already exists !'));
                                                }
                                                else
                                                {
-                                                       
$bofiles->create_document_dir("fmticket/{$receipt['id']}");
+                                                       
$bofiles->create_document_dir("helpdesk/{$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))))
+                                                       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 !'));
+                                                               
$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','');
+                                       
$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'));
+                                               
$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'));             
                     
+                                               
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'helpdesk.uitts.view',
+                                                       'id' => $receipt['id'], 
'tab' => 'general'));
                                        }
                                }
-                               else
+                       }
+
+                       /* Preserve attribute values from post */
+                       if (isset($receipt['error']) && 
(isset($values_attribute) && is_array($values_attribute)))
+                       {
+                               $values = 
$this->bocommon->preserve_attribute_values($values, $values_attribute);
+                       }
+
+                       $values = $this->bo->get_attributes($values);
+
+                       if (isset($values['attributes']) && 
is_array($values['attributes']))
+                       {
+                               foreach ($values['attributes'] as & $attribute)
                                {
-                                       if(isset($values['location']) && 
$values['location'])
+                                       if ($attribute['history'] == true)
                                        {
-                                               $location_code=implode("-", 
$values['location']);
-                                               $values['extra']['view'] = true;
-//                                             $values['location_data'] = 
$bolocation->read_single($location_code, $values['extra']);
+                                               $link_history_data = array
+                                                       (
+                                                       'menuaction' => 
'property.uiproject.attrib_history',
+                                                       'attrib_id' => 
$attribute['id'],
+                                                       'id' => $id,
+                                                       'edit' => true
+                                               );
+
+                                               $attribute['link_history'] = 
$GLOBALS['phpgw']->link('/index.php', $link_history_data);
                                        }
-                                       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']:'')
-                       ));
-*/
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_me_as_contact'])
 && 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_me_as_contact'] 
== 1)
+                       {
+                               $ticket['contact_id'] = 
$GLOBALS['phpgw']->accounts->get($this->account)->person_id;
+                       }
+                       $contact_data = 
$this->bocommon->initiate_ui_contact_lookup(array(
+                               'contact_id' => $ticket['contact_id'],
+                               'field' => 'contact',
+                               'type' => 'form'));
 
-                       
$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'
+                       );
 
-                       $link_data = array
-                               (
-                                       'menuaction'    => 'helpdesk.uitts.add'
-                               );
-
-                       if(!isset($values['assignedto']))
+                       if (!isset($values['assignedto']))
                        {
-                               $values['assignedto']= 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault']:'');
+                               $values['assignedto'] = 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['assigntodefault'] 
: '');
                        }
-                       if(!isset($values['group_id']))
+                       if (!isset($values['group_id']))
                        {
-                               $values['group_id']= 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault'])?$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault']:'');
+                               $values['group_id'] = 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault'])
 ? $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['groupdefault'] : 
'');
                        }
 
-                       if(!isset($values['cat_id']))
+                       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']:'');
+                               $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):'');
+                       $msgbox_data = (isset($receipt) ? 
$this->bocommon->msgbox_data($receipt) : '');
 
 
-                       if(!$this->_simple && $this->_show_finnish_date)
+                       if (!$this->simple && $this->show_finnish_date)
                        {
-                               $jscal = CreateObject('phpgwapi.jscalendar');
-                               $jscal->add_listener('values_finnish_date');
+                               
$GLOBALS['phpgw']->jqcal->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:''),
+                       $membership = 
$GLOBALS['phpgw']->accounts->membership($this->account);
+                       $my_groups = array();
+                       foreach ($membership as $group_id => $group)
+                       {
+                               $my_groups[$group_id] = $group->firstname;
+                       }
 
-                                       '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),
+                       $tabs = array();
+                       $tabs['add'] = array('label' => lang('Add'), 'link' => 
'#add');
+                       $active_tab = 'add';
 
-                                       '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]',
+                       $data = array(
+                               'my_groups' => json_encode($my_groups),
+                               'custom_attributes' => array('attributes' => 
$values['attributes']),
+                               'lookup_functions' => 
isset($values['lookup_functions']) ? $values['lookup_functions'] : '',
+                               'contact_data' => $contact_data,
+                               'simple' => $this->simple,
+                               'show_finnish_date' => $this->show_finnish_date,
+                               'value_origin' => isset($values['origin_data']) 
? $values['origin_data'] : '',
+                               'value_origin_type' => (isset($origin) ? 
$origin : ''),
+                               'value_origin_id' => (isset($origin_id) ? 
$origin_id : ''),
+                               'msgbox_data' => 
$GLOBALS['phpgw']->common->msgbox($msgbox_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),
+                               'disable_userassign_on_add' => 
isset($this->bo->config->config_data['tts_disable_userassign_on_add']) ? 
$this->bo->config->config_data['tts_disable_userassign_on_add'] : '',
+                               'lang_no_group' => lang('No group'),
+                               'group_list' => 
$this->bo->get_group_list($values['group_id']),
+                               'select_group_name' => 'values[group_id]',
+                               'lang_priority_statustext' => lang('Select the 
priority the selection belongs to.'),
+                               'select_priority_name' => 'values[priority]',
+                               'priority_list' => array('options' => 
$this->bo->get_priority_list((isset($values['priority']) ? $values['priority'] 
: ''))),
+                               'status_list' => array('options' => 
$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'] : ''),
+                               'tts_mandatory_title' => 
$this->bo->config->config_data['tts_mandatory_title'],
+                               'value_finnish_date' => 
(isset($values['finnish_date']) ? $values['finnish_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, 'required' => true)),
+                               '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'] : ''),
+                               'tabs' => 
phpgwapi_jquery::tabview_generate($tabs, $active_tab)
+                       );
 
-                                       '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');
+                       $appname = lang('helpdesk');
+                       $function_msg = lang('add ticket');
 
-                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'tts.add', 'helpdesk' );
+                       self::add_javascript('helpdesk', 'portico', 
'tts.add.js');
+                       phpgwapi_jquery::formvalidator_generate(array('date', 
'security','file'));
+                       $this->_insert_custom_js();
                        $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));
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files', 'attributes_form'));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('add' => $data));
                }
 
-
-               function get_vendor_email($vendor_id = 0)
+               function view()
                {
-                       if(!$vendor_id)
+                       if (!$this->acl_read)
                        {
-                               $vendor_id = phpgw::get_var('vendor_id', 'int', 
'GET', 0);
+                               phpgw::no_access();
                        }
-                       $vendor_email = 
execMethod('property.sowo_hour.get_email', $vendor_id);
 
-                       $content_email = array();
-                       foreach($vendor_email as $_entry )
-                       {                               
-                               $content_email[] = array
-                                       (
+                       $id = phpgw::get_var('id', 'int', 'GET');
 
-                                               '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').'">'
-                                       );
-                       }
+                       $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');
 
-                       if( phpgw::get_var('phpgw_return_as') == 'json' )
-                       {
+                       $values_attribute = phpgw::get_var('values_attribute');
 
-                               if(count($content_email))
-                               {
-                                       return json_encode($content_email);
-                               }
-                               else
-                               {
-                                       return "";
-                               }
-                       }
-                       return $content_email;
-               }
-
-               function view()
-               {
-                       if(!$this->acl_read)
+                       $receipt = 
$GLOBALS['phpgw']->session->appsession('receipt', 'helpdesk');
+                       $GLOBALS['phpgw']->session->appsession('receipt', 
'helpdesk', '');
+                       if (!$receipt)
                        {
-                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
+                               $receipt = array();
                        }
 
-                       $id = phpgw::get_var('id', 'int', 'GET');
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files', 'attributes_form',
+                               'datatable_inline'));
 
-                       if($this->tenant_id)
-                       {
-                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uitts.view2', 'id' => $id ));
-                       }
+                       $historylog     = & $this->bo->historylog;
 
-//                     $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 (isset($values['save']))
                        {
-                               if(!$this->acl_edit)
+                               if (!$this->acl_edit)
                                {
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=>4, 'acl_location'=> $this->acl_location));
+                                       phpgw::no_access();
                                }
 
-                               $insert_record = 
$GLOBALS['phpgw']->session->appsession('insert_record','helpdesk');
-                               $insert_record_entity = 
$GLOBALS['phpgw']->session->appsession('insert_record_entity','helpdesk');
+                               $insert_record = 
$GLOBALS['phpgw']->session->appsession('insert_record', 'helpdesk');
+                               $insert_record_entity = 
$GLOBALS['phpgw']->session->appsession('insert_record_values' . 
$this->acl_location, 'helpdesk');
 
-                               if(isset($insert_record_entity) && 
is_array($insert_record_entity))
+                               if (isset($insert_record_entity) && 
is_array($insert_record_entity))
                                {
-                                       for 
($j=0;$j<count($insert_record_entity);$j++)
+                                       for ($j = 0; $j < 
count($insert_record_entity); $j++)
                                        {
-                                               
$insert_record['extra'][$insert_record_entity[$j]]      = 
$insert_record_entity[$j];
+                                               
$insert_record['extra'][$insert_record_entity[$j]] = $insert_record_entity[$j];
                                        }
                                }
 
-                               $values = 
$this->bocommon->collect_locationdata($values,$insert_record);
+                               $values = 
$this->bocommon->collect_locationdata($values, $insert_record);
 
-                               if(isset($values['budget']) && 
$values['budget'] && !ctype_digit($values['budget']))
+                               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 !'));
+                                       $receipt['error'][] = array('msg' => 
lang('budget') . ': ' . lang('Please enter an integer !'));
                                }
 
-                               if(isset($values['takeover']) && 
$values['takeover'])
+                               if (isset($values_attribute) && 
is_array($values_attribute))
                                {
-                                       $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)
-                                       )))
+                                       foreach ($values_attribute as 
&$attribute)
                                        {
-                                               
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
-                                       }
-                                       else
-                                       {
-                                               
$bofiles->create_document_dir("fmticket/{$id}");
-                                               $bofiles->vfs->override_acl = 1;
+                                               if ($attribute['nullable'] != 1 
&& (!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                               {
+                                                       $receipt['error'][] = 
array('msg' => lang('Please enter value for attribute %1', 
$attribute['input_text']));
+                                               }
 
-                                               if(!$bofiles->vfs->cp (array (
-                                                       'from'  => 
$_FILES['file']['tmp_name'],
-                                                       'to'    => $to_file,
-                                                       'relatives'     => 
array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                                               if (isset($attribute['value']) 
&& $attribute['value'] && $attribute['datatype'] == 'I' && 
!ctype_digit($attribute['value']))
                                                {
-                                                       
$receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
+                                                       $receipt['error'][] = 
array('msg' => lang('Please enter integer for attribute %1', 
$attribute['input_text']));
                                                }
-                                               $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 (isset($attribute['value']) 
&& $attribute['value'] && $attribute['datatype'] == 'V' && 
strlen($attribute['value']) > $attribute['precision'])
+                                               {
+                                                       $receipt['error'][] = 
array('msg' => lang('Max length for attribute %1 is: %2', 
$attribute['input_text'], $attribute['precision']));
+                                                       $attribute['value'] = 
substr($attribute['value'], 0, $attribute['precision']);
+                                               }
                                        }
                                }
-                       }
 
-                       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 ($access_order)
                                {
-                                       
if($GLOBALS['phpgw']->acl->check(".entity.{$entry['id']}", PHPGW_ACL_ADD, 
'helpdesk'))
+                                       //test for budget
+                                       $_ticket = $this->bo->read_single($id);
+                                       if (!$_ticket['budget'] && 
((isset($values['order_id']) && $values['order_id']) && 
(!isset($values['budget']) || !$values['budget'])))
                                        {
-                                               $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++;
+                                               $receipt['error'][] = 
array('msg' => lang('budget') . ': ' . lang('Missing value'));
                                        }
-                               }
-                       }
+                                       unset($_ticket);
 
-                       //_debug_array($link_entity);
+                                       $sogeneric = 
CreateObject('property.sogeneric');
+                                       
$sogeneric->get_location_info('ticket_status', false);
+                                       $status_data = 
$sogeneric->read_single(array('id' => (int)ltrim($values['status'], 'C')), 
array());
 
-                       $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']) )
+                                       if (isset($status_data['actual_cost']) 
&& $status_data['actual_cost'])
                                        {
-                                               $prefs2 = 
$this->bocommon->create_preferences('helpdesk', $prefs['approval_from']);
-
-                                               if(isset($prefs2['email']))
+                                               if (!$values['actual_cost'] || 
!abs($values['actual_cost']) > 0)
                                                {
-                                                       $supervisor_email[] = 
array
-                                                               (
-                                                                       'id'    
  => $prefs['approval_from'],
-                                                                       
'address' => $prefs2['email'],
-                                                               );
-                                                       $supervisor_email = 
array_reverse($supervisor_email);
+                                                       $receipt['error'][] = 
array('msg' => lang('actual cost') . ': ' . lang('Missing value'));
                                                }
-                                               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))
+                                               else if 
(!is_numeric($values['actual_cost']))
                                                {
-                                                       $vendor_email[] = 
$_temp;
+                                                       $receipt['error'][] = 
array('msg' => lang('budget') . ': ' . lang('Please enter a numeric value'));
                                                }
-                                               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']))
+                               if (isset($values['takeover']) && 
$values['takeover'])
                                {
-                                       $organisation = 
$this->bo->config->config_data['org_name'];
+                                       $values['assignedto'] = $this->account;
                                }
+                               /*
+                                 if(isset($values_attribute) && 
is_array($values_attribute))
+                                 {
+                                 foreach ($values_attribute as $attribute )
+                                 {
+                                 if($attribute['nullable'] != 1 && 
(!$attribute['value'] && !$values['extra'][$attribute['name']]))
+                                 {
+                                 $receipt['error'][]=array('msg'=>lang('Please 
enter value for attribute %1', $attribute['input_text']));
+                                 }
+                                 }
+                                 }
+                                */
+                               $receipt = $this->bo->update_ticket($values, 
$id, $receipt, $values_attribute);
 
-                               if(isset($values['on_behalf_of_assigned']) && 
$values['on_behalf_of_assigned'] && isset($ticket['assignedto_name']))
+                               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
+                                       ) || 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_notify_me'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_notify_me'] 
== 1 && $this->bo->fields_updated
+                                       )
+                               )
                                {
-                                       $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);
+                                       $receipt = $this->bo->mail_ticket($id, 
$this->bo->fields_updated, $receipt, '', false, isset($values['send_mail']) && 
$values['send_mail'] ? true : false);
                                }
-                               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)
+                               //--------- files
+                               $bofiles = CreateObject('property.bofiles');
+                               if (isset($values['file_action']) && 
is_array($values['file_action']))
                                {
-                                       $location .= "{$address_entry['text']}: 
{$address_entry['value']} <br>";
+                                       
$bofiles->delete_file("/helpdesk/{$id}/", $values);
                                }
 
-                               $location = rtrim($location, '<br>');
+                               $values['file_name'] = str_replace(' ', '_', 
$_FILES['file']['name']);
 
-                               $order_description = $ticket['order_descr'];
-
-                               if(isset($contact_data['value_contact_name']) 
&& $contact_data['value_contact_name'])
+                               if ($values['file_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'];
-                               }
+                                       $to_file = $bofiles->fakebase . 
'/helpdesk/' . $id . '/' . $values['file_name'];
 
-                               $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($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))
+                                       if ($bofiles->vfs->file_exists(array(
+                                                       'string' => $to_file,
+                                                       'relatives' => 
Array(RELATIVE_NONE)
+                                               )))
                                        {
-                                               $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                                               $receipt['error'][] = 
array('msg' => lang('This file already exists !'));
                                        }
-
-                                       $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'])
+                                       else
                                        {
-                                               $cc = 
$contact_data['value_contact_email'];
-                                       }
+                                               
$bofiles->create_document_dir("helpdesk/{$id}");
+                                               $bofiles->vfs->override_acl = 1;
 
-                                       $_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);
+                                               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;
                                        }
                                }
-                               else
+
+                               //---------end files
+                               if (phpgw::get_var('notify_client_by_sms', 
'bool') && isset($values['response_text']) && $values['response_text'] && 
phpgw::get_var('to_sms_phone'))
                                {
-                                       
$receipt['error'][]=array('msg'=>lang('SMTP server is not set! (admin 
section)'));
+                                       $to_sms_phone = 
phpgw::get_var('to_sms_phone');
+                                       //                      
$ticket['contact_phone'] = $to_sms_phone;
+
+                                       $sms = CreateObject('sms.sms');
+                                       $sms->websend2pv($this->account, 
$to_sms_phone, $values['response_text']);
+                                       $historylog->add('MS', $id, 
"{$to_sms_phone}::{$values['response_text']}");
                                }
                        }
 
-                       // start approval
-                       if (isset($values['approval']) && $values['approval']  
&& $this->bo->config->config_data['workorder_approval'])
+                       /* Preserve attribute values from post */
+                       if (isset($receipt['error']) && 
(isset($values_attribute) && is_array($values_attribute)))
                        {
-                               
$coordinator_name=$GLOBALS['phpgw_info']['user']['fullname'];
-                               
$coordinator_email=$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['email'];
+                               $values = 
$this->bocommon->preserve_attribute_values($values, $values_attribute);
+                       }
 
-                               $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>';
+                       $ticket = $this->bo->read_single($id, $values);
 
-                               if 
(isset($GLOBALS['phpgw_info']['server']['smtp_server']) && 
$GLOBALS['phpgw_info']['server']['smtp_server'])
+                       if (isset($ticket['attributes']) && 
is_array($ticket['attributes']))
+                       {
+                               foreach ($ticket['attributes'] as & $attribute)
                                {
-                                       if (!is_object($GLOBALS['phpgw']->send))
+                                       if ($attribute['history'] == true)
                                        {
-                                               $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
-                                       }
-
-                                       $action_params = array
-                                               (
-                                                       'appname'               
        => 'helpdesk',
-                                                       'location'              
        => '.ticket',
-                                                       'id'                    
        => $id,
-                                                       'responsible'           
=> '',
-                                                       'responsible_type'  => 
'user',
-                                                       'action'                
        => 'approval',
-                                                       'remark'                
        => '',
-                                                       'deadline'              
        => ''
+                                               $link_history_data = array
+                                                       (
+                                                       'menuaction' => 
'property.uiproject.attrib_history',
+                                                       'attrib_id' => 
$attribute['id'],
+                                                       'id' => $id,
+                                                       'edit' => true
                                                );
-                                       $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);
+                                               $attribute['link_history'] = 
$GLOBALS['phpgw']->link('/index.php', $link_history_data);
                                        }
                                }
-                               else
-                               {
-                                       
$receipt['error'][]=array('msg'=>lang('SMTP server is not set! (admin 
section)'));
-                               }
                        }
 
-                       // end approval
 
-                       // -------- end order section
+                       $form_link = array(
+                               'menuaction' => 'helpdesk.uitts.view',
+                               'id' => $id
+                       );
 
+                       $contact_data = 
$this->bocommon->initiate_ui_contact_lookup(array(
+                               'contact_id' => $ticket['contact_id'],
+                               'field' => 'contact',
+                               'type' => 'form'));
 
 
+                       if ($ticket['cat_id'])
+                       {
+                               $this->cat_id = $ticket['cat_id'];
+                       }
+
+                       $link_file_data = array(
+                               'menuaction' => 'helpdesk.uitts.view_file',
+                               'id' => $id
+                       );
+
+                       if ($this->show_finnish_date)
+                       {
+                               
$GLOBALS['phpgw']->jqcal->add_listener('values_finnish_date');
+                       }
+
                        $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']
-                                       )
-                               );
+                       $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);
+                       $additional_notes = array_merge($notes, 
$additional_notes);
 
-                       if(isset($values['order_text']) && $ticket['order_id'])
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['yui_table_nowrap'])
 && $GLOBALS['phpgw_info']['user']['preferences']['common']['yui_table_nowrap'])
                        {
-                               foreach($values['order_text'] as $_text)
+                               foreach ($additional_notes as &$_note)
                                {
-                                       $ticket['order_descr'] .= "\n$_text";
+                                       $_note['value_note'] = 
wordwrap($_note['value_note'], 40);
                                }
                        }
+                       unset($_note);
 
-                       $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)
-                               );
+                       $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)
+                       foreach ($additional_notes as &$note)
                        {
-                               $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')."'>";
                        }
 
+                       $datatable_def = array();
 
+                       $datatable_def[] = array(
+                               'container' => 'datatable-container_0',
+                               'requestUrl' => "''",
+                               'ColumnDefs' => $note_def,
+                               'data' => json_encode($additional_notes),
+                               'config' => array(
+                                       array('disableFilter' => true),
+                                       array('disablePagination' => true)
+                               )
+                       );
+
                        //_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)))
-                               );      
+                       //---datatable 
settings---------------------------------------------------
 
+                       $datatable_def[] = array(
+                               'container' => 'datatable-container_1',
+                               'requestUrl' => "''",
+                               'ColumnDefs' => 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)),
+                               'data' => json_encode($record_history),
+                               'config' => array(
+                                       array('disableFilter' => true),
+                                       array('disablePagination' => true)
+                               )
+                       );
 
-                       $link_view_file = 
$GLOBALS['phpgw']->link('/index.php',$link_file_data);
 
-                       for($z=0; $z<count($ticket['files']); $z++)
-                       {                               
-                               $content_files[$z]['file_name'] = '<a 
href="'.$link_view_file.'&amp;file_id='.$ticket['files'][$z]['file_id'].'" 
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]['file_id'].'" title="'.lang('Check to delete 
file').'">';
-                               $content_files[$z]['attach_file'] = '<input 
type="checkbox" name="values[file_attach][]" 
value="'.$ticket['files'][$z]['file_id'].'" title="'.lang('Check to attach 
file').'">';
-                       }                                                       
+                       $link_view_file = $GLOBALS['phpgw']->link('/index.php', 
$link_file_data);
 
-                       $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'])
+                       for ($z = 0; $z < count($ticket['files']); $z++)
                        {
-                               $attach_file_def[] = array('key' => 
'attach_file','label'=>lang('attach 
file'),'sortable'=>false,'resizeable'=>true,'formatter'=>'FormatterCenter');
+                               $content_files[$z]['file_name'] = '<a href="' . 
$link_view_file . '&amp;file_id=' . $ticket['files'][$z]['file_id'] . '" 
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]['file_id'] . '" title="' . lang('Check to delete file') . 
'">';
+                               $content_files[$z]['attach_file'] = '<input 
type="checkbox" name="values[file_attach][]" value="' . 
$ticket['files'][$z]['file_id'] . '" title="' . lang('Check to attach file') . 
'">';
                        }
 
-                       $myColumnDefs[2] = array
-                               (
-                                       'name'          => "2",
-                                       'values'        =>      
json_encode($attach_file_def)
-                               );
 
+                       $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'),
+                       );
 
-                       $myColumnDefs[3] = array
+                       $datatable_def[] = 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)))
-                               );      
+                               'container' => 'datatable-container_2',
+                               'requestUrl' => "''",
+                               'ColumnDefs' => $attach_file_def,
+                               'data' => json_encode($content_files),
+                               'config' => array(
+                                       array('disableFilter' => true),
+                                       array('disablePagination' => true)
+                               )
+                       );
 
+                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('helpdesk', $this->acl_location);
+                       $notify_info = 
execMethod('property.notify.get_jquery_table_def', array(
+                               'location_id' => $location_id,
+                               'location_item_id' => $id,
+                               'count' => 6,//count($datatable_def),
+                               'requestUrl' => 
json_encode(self::link(array('menuaction' => 'property.notify.update_data',
+                                               'location_id' => $location_id, 
'location_item_id' => $id, 'action' => 'refresh_notify_contact',
+                                               'phpgw_return_as' => 'json'))),
+                               )
+                       );
 
-                       $content_email = 
$this->get_vendor_email(isset($ticket['vendor_id'])?$ticket['vendor_id']:0);
-
-                       $datavalues[3] = array
+                       $datatable_def[] = array
                                (
-                                       'name'                                  
=> "3",
-                                       'values'                                
=> json_encode($content_email),
-                                       'total_records'                 => 
count($content_email),
-                                       'permission'                    => "''",
-                                       'is_paginator'                  => 0,
-                                       'footer'                                
=> 0
-                               );
+                               'container' => 'datatable-container_6',
+                               'requestUrl' => 
json_encode(self::link(array('menuaction' => 'property.notify.update_data',
+                                               'location_id' => $location_id, 
'location_item_id' => $id, 'action' => 'refresh_notify_contact',
+                                               'phpgw_return_as' => 'json'))),
+                               'ColumnDefs' => 
$notify_info['column_defs']['values'],
+                               'data' => json_encode(array()),
+                               'tabletools' => $notify_info['tabletools'],
+                               'config' => array(
+                                       array('disableFilter' => true),
+                                       array('disablePagination' => true)
+                               )
+                       );
 
+                       
//----------------------------------------------datatable settings--------
 
-                       
//----------------------------------------------datatable settings--------      
                
+//_debug_array($supervisor_email);die();
                        $msgbox_data = $this->bocommon->msgbox_data($receipt);
-                       $cat_select     = 
$this->cats->formatted_xslt_list(array('select_name' => 
'values[cat_id]','selected' => $this->cat_id,'use_acl' => 
$this->_category_acl));
-                       $this->cats->set_appname('helpdesk','.project');
-                       $order_catetory = 
$this->cats->formatted_xslt_list(array('select_name' => 
'values[cat_id]','selected' => $ticket['order_cat_id']));
-                       $data = array
-                               (
-                                       'access_order'                          
        => $access_order,
-                                       'currency'                              
                => 
$GLOBALS['phpgw_info']['user']['preferences']['common']['currency'],
-                                       'value_order_id'                        
        => $ticket['order_id'],
-                                       'value_order_descr'                     
        => $ticket['order_descr'],
-                                       'vendor_data'                           
        => $vendor_data,
-                                       'b_account_data'                        
        => $b_account_data,
-                                       'ecodimb_data'                          
        => $ecodimb_data,
-                                       'value_budget'                          
        => $ticket['budget'],
-                                       'value_actual_cost'                     
        => $ticket['actual_cost'],
-                                       'need_approval'                         
        => $need_approval,
-                                       'value_approval_mail_address'   => 
$supervisor_email,
-       //                              'vendor_email'                          
        => $vendor_email,
+                       $cat_select = 
$this->cats->formatted_xslt_list(array('select_name' => 'values[cat_id]',
+                               'selected' => $this->cat_id, 'use_acl' => 
$this->_category_acl, 'required' => true));
 
-                                       'contact_data'                          
        => $contact_data,
-                                       'lookup_type'                           
        => $lookup_type,
-                                       'simple'                                
                => $this->_simple,
-                                       'show_finnish_date'                     
        => $this->_show_finnish_date,
-                                       'tabs'                                  
                => self::_generate_tabs(true),
-                                       'td_count'                              
                => '""',
-                                       'base_java_url'                         
        => "{menuaction:'helpdesk.uitts.get_vendor_email'}",
-                                       'property_js'                           
        => 
json_encode($GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property2.js"),
-                                       'datatable'                             
                => $datavalues,
-                                       'myColumnDefs'                          
        => $myColumnDefs,
+                       $_ticket_cat_found = false;
+                       if (isset($cat_select['cat_list']) && 
is_array($cat_select['cat_list']))
+                       {
+                               foreach ($cat_select['cat_list'] as 
$cat_list_entry)
+                               {
+                                       if ($cat_list_entry['cat_id'] == 
$ticket['cat_id'])
+                                       {
+                                               $_ticket_cat_found = true;
+                                               break;
+                                       }
+                               }
+                       }
 
-                                       'value_origin'                          
        => $ticket['origin'],
-                                       'value_target'                          
        => $ticket['target'],
-                                       'value_finnish_date'                    
=> $ticket['finnish_date'],
-                                       'img_cal'                               
                => $GLOBALS['phpgw']->common->image('phpgwapi','cal'),
-                                       'lang_datetitle'                        
        => lang('Select date'),
+                       if (!$_ticket_cat_found)
+                       {
+                               $category = 
$this->cats->return_single($ticket['cat_id']);
+//_debug_array($category);
 
-                                       'link_entity'                           
        => $link_entity,
-                                       'msgbox_data'                           
        => $GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               array_unshift($cat_select['cat_list'], array
+                                       (
+                                       'cat_id' => $category[0]['id'],
+                                       'name' => $category[0]['name'],
+                                       'description' => 
$category[0]['description'],
+                                       'selected' => true,
+                                       )
+                               );
+                               $cat_select['disabled'] = true;
+                               $cat_select['hidden_value'] = $ticket['cat_id'];
+//_debug_array($cat_select);die();
+                       }
 
-                                       'location_data'                         
        => $location_data,
 
-                                       'status_name'                           
        => 'values[status]',
-                                       'value_status'                          
        => $ticket['status'],
-                                       'status_list'                           
        => $this->bo->get_status_list($ticket['status']),
+//                     $this->cats->set_appname('property','.project');
+//                     $order_catetory = 
$this->cats->formatted_xslt_list(array('select_name' => 
'values[order_cat_id]','selected' => $ticket['order_cat_id']));
 
-                                       '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]',
-                                       'value_assignedto_id'                   
=> $ticket['assignedto'],
-                                       'user_list'                             
                => 
$this->bocommon->get_user_list_right2('select',4,$ticket['assignedto'],$this->acl_location),
 
-                                       'lang_no_group'                         
        => lang('No group'),
-                                       'group_list'                            
        => 
$this->bocommon->get_group_list('select',$ticket['group_id'],$start=-1,$sort='ASC',$order='account_firstname',$query='',$offset=-1),
-                                       'select_group_name'                     
        => 'values[group_id]',
-                                       'value_group_id'                        
        => $ticket['group_id'],
+                       $membership = 
$GLOBALS['phpgw']->accounts->membership($this->account);
+                       $my_groups = array();
+                       foreach ($membership as $group_id => $group)
+                       {
+                               $my_groups[$group_id] = $group->firstname;
+                       }
 
-                                       'lang_takeover'                         
        => (isset($values['assignedto']) && $values['assignedto'] != 
$this->account)  || (!isset($values['assignedto']) || !$values['assignedto']) ? 
lang('take over') : '',
+                       phpgwapi_jquery::formvalidator_generate(array('date', 
'security',
+                               'file'));
 
-                                       'value_priority'                        
        => $ticket['priority'],
-                                       'lang_priority_statustext'              
=> lang('Select the priority the selection belongs to.'),
-                                       'select_priority_name'                  
=> 'values[priority]',
-                                       'priority_list'                         
        => $this->bo->get_priority_list($ticket['priority']),
+                       $tabs = array();
+                       $tabs['general'] = array('label' => lang('General'), 
'link' => '#general');
+                       $tabs['notify'] = array('label' => lang('Notify'), 
'link' => '#notify');
+                       $tabs['history'] = array('label' => lang('History'), 
'link' => '#history');
+                       $active_tab = 'general';
 
-                                       'lang_no_cat'                           
        => lang('no category'),
-                                       'value_cat_id'                          
        => $this->cat_id,
-                                       'cat_select'                            
        => $cat_select,
+                       $data = array(
+                               'datatable_def' => $datatable_def,
+                               'my_groups' => json_encode($my_groups),
+                               'custom_attributes' => array('attributes' => 
$ticket['attributes']),
+                               'lookup_functions' => 
isset($ticket['lookup_functions']) ? $ticket['lookup_functions'] : '',
+                               'send_response' => 
isset($this->bo->config->config_data['tts_send_response']) ? 
$this->bo->config->config_data['tts_send_response'] : '',
+                               'value_sms_phone' => $ticket['contact_phone'],
+                               'value_budget' => $ticket['budget'],
+                               'value_actual_cost' => $ticket['actual_cost'],
+                               'contact_data' => $contact_data,
+                               'show_finnish_date' => $this->show_finnish_date,
+                               'tabs' => self::_generate_tabs(true),
+                               'base_java_url' => 
"{menuaction:'helpdesk.uitts.update_data',id:{$id}}",
+                               'location_item_id' => $id,
+                               'value_origin' => $ticket['origin'],
+                               'value_target' => $ticket['target'],
+                               'value_finnish_date' => $ticket['finnish_date'],
+                               'msgbox_data' => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               'value_status' => $ticket['status'],
+                               'status_list' => array('options' => 
$this->bo->get_status_list($ticket['status'])),
+                               '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]',
+                               'value_assignedto_id' => $ticket['assignedto'],
+                               'user_list' => 
$this->bocommon->get_user_list_right2('select', 4, $ticket['assignedto'], 
$this->acl_location),
+                               'lang_no_group' => lang('No group'),
+                               'group_list' => 
$this->bo->get_group_list($ticket['group_id']),
+                               'select_group_name' => 'values[group_id]',
+                               'value_group_id' => $ticket['group_id'],
+                               'lang_takeover' => 
(isset($values['assignedto']) && $values['assignedto'] != $this->account) || 
(!isset($values['assignedto']) || !$values['assignedto']) ? lang('take over') : 
'',
+                               'value_priority' => $ticket['priority'],
+                               'lang_priority_statustext' => lang('Select the 
priority the selection belongs to.'),
+                               'select_priority_name' => 'values[priority]',
+                               'priority_list' => array('options' => 
$this->bo->get_priority_list($ticket['priority'])),
+                               'lang_no_cat' => lang('no category'),
+                               'value_cat_id' => $this->cat_id,
+                               'cat_select' => $cat_select,
+                               'value_category_name' => 
$ticket['category_name'],
+                               'form_action' => 
$GLOBALS['phpgw']->link('/index.php', $form_link),
+                               'done_action' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'helpdesk.uitts.index')),
+                               'value_subject' => $ticket['subject'],
+                               'value_id' => '[ #' . $id . ' ] - ',
+                               'value_details' => $ticket['details'],
+                               'value_opendate' => $ticket['entry_date'],
+                               'value_assignedfrom' => $ticket['user_name'],
+                               'value_assignedto_name' => 
isset($ticket['assignedto_name']) ? $ticket['assignedto_name'] : '',
+                               'show_billable_hours' => 
isset($this->bo->config->config_data['show_billable_hours']) ? 
$this->bo->config->config_data['show_billable_hours'] : '',
+                               'value_billable_hours' => 
$ticket['billable_hours'],
+                               'additional_notes' => $additional_notes,
+                               'record_history' => $record_history,
+                               'contact_phone' => $ticket['contact_phone'],
+                               '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'] : '',
+                               'multiple_uploader' => true,
+                               'fileuploader_action' => 
"{menuaction:'property.fileuploader.add',upload_target:'helpdesk.botts.addfiles',id:'{$id}'}",
+                               'link_view_file' => 
$GLOBALS['phpgw']->link('/index.php', $link_file_data),
+                               'link_to_files' => 
isset($this->bo->config->config_data['files_url']) ? 
$this->bo->config->config_data['files_url'] : '',
+                               'files' => isset($ticket['files']) ? 
$ticket['files'] : '',
+                               'lang_filename' => lang('Filename'),
+                               'lang_file_action' => lang('Delete file'),
+                               'lang_view_file_statustext' => lang('click to 
view file'),
+                               'lang_file_action_statustext' => lang('Check to 
delete file'),
+                               'lang_upload_file' => lang('Upload file'),
+                               'lang_file_statustext' => lang('Select file to 
upload'),
+                               'textareacols' => 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'] ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'] : 60,
+                               'textarearows' => 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'] ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'] : 6,
+//                                     'order_cat_list'                        
        => $order_catetory,
+                               'building_part_list' => array('options' => 
$this->bocommon->select_category_list(array(
+                                               'type' => 'building_part', 
'selected' => $ticket['building_part'], 'order' => 'id',
+                                               'id_in_name' => 'num', 'filter' 
=> $_filter_buildingpart))),
+                               'order_dim1_list' => array('options' => 
$this->bocommon->select_category_list(array(
+                                               'type' => 'order_dim1', 
'selected' => $ticket['order_dim1'], 'order' => 'id',
+                                               'id_in_name' => 'num'))),
+                               'tax_code_list' => array('options' => 
$this->bocommon->select_category_list(array(
+                                               'type' => 'tax', 'selected' => 
$ticket['tax_code'], 'order' => 'id',
+                                               'id_in_name' => 'num'))),
+                               'tabs' => 
phpgwapi_jquery::tabview_generate($tabs, $active_tab),
+                       );
 
-                                       'value_category_name'                   
=> $ticket['category_name'],
+                       phpgwapi_jquery::load_widget('numberformat');
+                       phpgwapi_jquery::load_widget('autocomplete');
+                       self::add_javascript('helpdesk', 'portico', 
'tts.view.js');
 
-                                       'form_action'                           
        => $GLOBALS['phpgw']->link('/index.php',$form_link),
-                                       'done_action'                           
        => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=>'helpdesk.uitts.index')),
-                                       'value_subject'                         
        => $ticket['subject'],
-
-                                       'value_id'                              
                => '[ #'. $id . ' ] - ',
-
-                                       'value_details'                         
        => $ticket['details'],
-
-                                       'value_opendate'                        
        => $ticket['entry_date'],
-                                       'value_assignedfrom'                    
=> $ticket['user_name'],
-                                       'value_assignedto_name'                 
=> isset($ticket['assignedto_name'])?$ticket['assignedto_name']:'',
-                                       'show_billable_hours'                   
=> isset($this->bo->config->config_data['show_billable_hours']) ? 
$this->bo->config->config_data['show_billable_hours'] : '',
-                                       'value_billable_hours'                  
=> $ticket['billable_hours'],
-
-                                       'additional_notes'                      
        => $additional_notes,
-                                       'record_history'                        
        => $record_history,
-                                       'request_link'                          
        => $request_link,
-                                       'order_link'                            
        => $order_link,
-                                       'add_to_project_link'                   
=> $add_to_project_link,
-
-               //                      'lang_name'                             
                => lang('name'),
-                                       'contact_phone'                         
        => $ticket['contact_phone'],
-                                       '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']:'',
-                                       'link_view_file'                        
        => $GLOBALS['phpgw']->link('/index.php',$link_file_data),
-                                       'link_to_files'                         
        => 
isset($this->bo->config->config_data['files_url'])?$this->bo->config->config_data['files_url']:'',
-                                       'files'                                 
                => isset($ticket['files'])?$ticket['files']:'',
-                                       'lang_filename'                         
        => lang('Filename'),
-                                       'lang_file_action'                      
        => lang('Delete file'),
-                                       'lang_view_file_statustext'             
=> lang('click to view file'),
-                                       'lang_file_action_statustext'   => 
lang('Check to delete file'),
-                                       'lang_upload_file'                      
        => lang('Upload file'),
-                                       'lang_file_statustext'                  
=> lang('Select file to upload'),
-                                       'textareacols'                          
        => 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'] ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textareacols'] : 60,
-                                       'textarearows'                          
        => 
isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'])
 && $GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'] ? 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['textarearows'] : 6,
-                                       'order_cat_list'                        
        => $order_catetory,
-                                       'building_part_list'                    
=> array('status_list' => $this->bocommon->select_category_list(array('type'=> 
'building_part','selected' =>$ticket['building_part'], 'order' => 'id', 
'id_in_name' => 'num' ))),
-                                       'order_dim1_list'                       
        => array('status_list' => 
$this->bocommon->select_category_list(array('type'=> 'order_dim1','selected' 
=>$ticket['order_dim1'], 'order' => 'id', 'id_in_name' => 'num' ))),
-                               );
-
-                       //---datatable settings--------------------
-                       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('tabview');
-                       phpgwapi_yui::load_widget('paginator');
-                       phpgwapi_yui::load_widget('animation');
-
-                       $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']->js->validate_file( 'yahoo', 
'tts.view', 'helpdesk' );
+                       $this->_insert_custom_js();
                        //-----------------------datatable settings---
-
                        //_debug_array($data);die();
 
-                       $appname                = lang('helpdesk');
-                       $function_msg   = lang('view ticket detail');
+                       $appname = lang('helpdesk');
+                       $function_msg = lang('view ticket detail');
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('helpdesk') . ' - ' . $appname . ': ' . $function_msg;
-                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('view' => $data));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('view' => $data));
                }
 
                function view_file()
                {
                        if(!$this->acl_read)
                        {
-                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'helpdesk.uilocation.stop', 'perm'=>1, 'acl_location'=> $this->acl_location));
+                               phpgw::no_access();
                        }
 
-                       ExecMethod('property.bofiles.get_file', 
phpgw::get_var('file_id', 'int'));
+                       ExecMethod('helpdesk.bofiles.get_file', 
phpgw::get_var('file_id', 'int'));
                }
 
-               protected function _generate_tabs($history='')
+               protected function _generate_tabs( $history = '' )
                {
-                       if(!$tab = phpgw::get_var('tab'))
+                       if (!$tab = phpgw::get_var('tab'))
                        {
                                $tab = 'general';
                        }
 
-                       $tabs = array
+                       $tabs = array(
+                               'general' => array('label' => lang('general'), 
'link' => '#general'),
+                               'notify' => array('label' => lang('notify'), 
'link' => '#notify')
+                       );
+
+                       if ($history)
+                       {
+                               $tabs['history'] = array('label' => 
lang('history'), 'link' => '#history');
+                       }
+
+                       return phpgwapi_jquery::tabview_generate($tabs, $tab, 
'ticket_tabview');
+               }
+
+               /**
+                *
+                */
+               private function _insert_custom_js()
+               {
+                       $criteria = array
                                (
-                                       'general'               => 
array('label' => lang('general'), 'link' => '#general')
-                               );
+                               'appname' => 'helpdesk',
+                               'location' => $this->acl_location,
+                               'allrows' => true
+                       );
 
-                       if($history)
+                       if (!$custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria))
                        {
-                               $tabs['history']        = array('label' => 
lang('history'), 'link' => '#history');
+                               return false;
                        }
 
-                       phpgwapi_yui::tabview_setup('ticket_tabview');
+                       $js_found = false;
 
-                       return  phpgwapi_yui::tabview_generate($tabs, $tab);
+                       foreach ($custom_functions as $entry)
+                       {
+                               // prevent path traversal
+                               if (preg_match('/\.\./', $entry['file_name']))
+                               {
+                                       continue;
+                               }
+
+                               $file = PHPGW_SERVER_ROOT . 
"/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+
+                               if ($entry['active'] && $entry['client_side'] 
&& is_file($file))
+                               {
+                                       
$GLOBALS['phpgw']->js->add_external_file("/property/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}");
+                                       $js_found = true;
+                               }
+                       }
+
+                       if ($js_found)
+                       {
+                               phpgw::import_class('phpgwapi.jquery');
+                               phpgwapi_jquery::load_widget('core');
+                       }
                }
 
        }

Added: trunk/helpdesk/js/portico/tts.add.js
===================================================================
--- trunk/helpdesk/js/portico/tts.add.js                                (rev 0)
+++ trunk/helpdesk/js/portico/tts.add.js        2016-06-27 18:51:17 UTC (rev 
15342)
@@ -0,0 +1,79 @@
+this.confirm_session = function (action)
+{
+       if (action == 'save' || action == 'apply')
+       {
+               conf = {
+                       modules: 'location, date, security, file',
+                       validateOnBlur: false,
+                       scrollToTopOnError: true,
+                       errorMessagePosition: 'top',
+                       language: validateLanguage
+               };
+               var test = $('form').isValid(validateLanguage, conf);
+               if (!test)
+               {
+                       return;
+               }
+       }
+
+       var oArgs = {menuaction: 'property.bocommon.confirm_session'};
+       var strURL = phpGWLink('index.php', oArgs, true);
+
+       $.ajax({
+               type: 'POST',
+               dataType: 'json',
+               url: strURL,
+               success: function (data)
+               {
+                       if (data != null)
+                       {
+                               if (data['sessionExpired'] == true)
+                               {
+                                       window.alert('sessionExpired - please 
log in');
+                                       JqueryPortico.lightboxlogin();//defined 
in common.js
+                               }
+                               else
+                               {
+                                       document.getElementById(action).value = 
1;
+                                       try
+                                       {
+                                               validate_submit();
+                                       }
+                                       catch (e)
+                                       {
+                                               document.form.submit();
+                                       }
+                               }
+                       }
+               },
+               failure: function (o)
+               {
+                       window.alert('failure - try again - once');
+               },
+               timeout: 5000
+       });
+};
+$(document).ready(function ()
+{
+
+       $('#group_id').attr("data-validation", 
"assigned").attr("data-validation-error-msg", lang['Please select a person or a 
group to handle the ticket !']);
+       $('#user_id').attr("data-validation", 
"assigned").attr("data-validation-error-msg", lang['Please select a person or a 
group to handle the ticket !']);
+});
+
+$.formUtils.addValidator({
+       name: 'assigned',
+       validatorFunction: function (value, $el, config, languaje, $form)
+       {
+               var v = false;
+               var group_id = $('#group_id').val();
+               var user_id = $('#user_id').val();
+               if (group_id != "" || user_id != "")
+               {
+                       v = true;
+               }
+               return v;
+       },
+       errorMessage: 'Assigned is required',
+       errorMessageKey: ''
+});
+

Added: trunk/helpdesk/js/portico/tts.index.js
===================================================================
--- trunk/helpdesk/js/portico/tts.index.js                              (rev 0)
+++ trunk/helpdesk/js/portico/tts.index.js      2016-06-27 18:51:17 UTC (rev 
15342)
@@ -0,0 +1,53 @@
+
+
+$(document).ready(function ()
+{
+
+       $("#datatable-container").on("click", "tr", function ()
+       {
+
+               $('td', this).removeClass('priority1');
+               $('td', this).removeClass('priority2');
+               $('td', this).removeClass('priority3');
+
+       });
+
+});
+
+JqueryPortico.formatLinkRelated = function (key, oData)
+{
+
+       if (!oData['child_date'])
+       {
+               return '';
+       }
+
+       var child_date = oData['child_date'][key];
+       var date_info = child_date.date_info;
+       if (!date_info.length)
+       {
+               return '';
+       }
+
+       var name = date_info[0]['entry_date'];
+       var link = date_info[0]['link'];
+       var title = child_date['statustext']['statustext'] || '';
+
+
+       return '<a href="' + link + '" title="' + title + '">' + name + '</a>';
+};
+
+JqueryPortico.formatTtsIdLink = function (key, oData)
+{
+
+       var name = oData[key] + oData['new_ticket'];
+       var link = oData['link'];
+       return '<a href="' + link + '">' + name + '</a>';
+};
+
+JqueryPortico.searchLinkTts = function (key, oData)
+{
+
+       var name = oData[key];
+       return '<a id="' + name + '" onclick="searchData(this.id);">' + name + 
'</a>';
+};

Added: trunk/helpdesk/js/portico/tts.view.js
===================================================================
--- trunk/helpdesk/js/portico/tts.view.js                               (rev 0)
+++ trunk/helpdesk/js/portico/tts.view.js       2016-06-27 18:51:17 UTC (rev 
15342)
@@ -0,0 +1,112 @@
+
+var FormatterCenter = function (key, oData)
+{
+
+       return "<center>" + oData[key] + "</center>";
+};
+
+this.confirm_session = function (action)
+{
+       if (action == 'save' || action == 'apply')
+       {
+               conf = {
+                       modules: 'date, security, file',
+                       validateOnBlur: false,
+                       scrollToTopOnError: true,
+                       errorMessagePosition: 'top',
+                       language: validateLanguage
+               };
+               var test = $('form').isValid(validateLanguage, conf);
+               if (!test)
+               {
+                       return;
+               }
+       }
+
+       var oArgs = {menuaction: 'property.bocommon.confirm_session'};
+       var strURL = phpGWLink('index.php', oArgs, true);
+
+       $.ajax({
+               type: 'POST',
+               dataType: 'json',
+               url: strURL,
+               success: function (data)
+               {
+                       if (data != null)
+                       {
+                               if (data['sessionExpired'] == true)
+                               {
+                                       window.alert('sessionExpired - please 
log in');
+                                       JqueryPortico.lightboxlogin();//defined 
in common.js
+                               }
+                               else
+                               {
+                                       document.getElementById(action).value = 
1;
+                                       try
+                                       {
+                                               validate_submit();
+                                       }
+                                       catch (e)
+                                       {
+                                               document.form.submit();
+                                       }
+                               }
+                       }
+               },
+               failure: function (o)
+               {
+                       window.alert('failure - try again - once');
+               },
+               timeout: 5000
+       });
+};
+
+
+function SmsCountKeyUp(maxChar)
+{
+       var msg = document.getElementsByName("values[response_text]")[0];
+       var left = document.forms.form.charNumberLeftOutput;
+       var smsLenLeft = maxChar - msg.value.length;
+       if (smsLenLeft >= 0)
+       {
+               left.value = smsLenLeft;
+       }
+       else
+       {
+               var msgMaxLen = maxChar;
+               left.value = 0;
+               msg.value = msg.value.substring(0, msgMaxLen);
+       }
+}
+
+function SmsCountKeyDown(maxChar)
+{
+       var msg = document.getElementsByName("values[response_text]")[0];
+       var left = document.forms.form.charNumberLeftOutput;
+       var smsLenLeft = maxChar - msg.value.length;
+       if (smsLenLeft >= 0)
+       {
+               left.value = smsLenLeft;
+       }
+       else
+       {
+               var msgMaxLen = maxChar;
+               left.value = 0;
+               msg.value = msg.value.substring(0, msgMaxLen);
+       }
+}
+
+
+this.fileuploader = function ()
+{
+       var sUrl = phpGWLink('index.php', fileuploader_action);
+       TINY.box.show({iframe: sUrl, boxid: "frameless", width: 750, height: 
450, fixed: false, maskid: "darkmask", maskopacity: 40, mask: true, animate: 
true, close: true}); //refresh_files is called after upload
+};
+
+this.refresh_files = function ()
+{
+       base_java_url['action'] = 'get_files';
+       var oArgs = base_java_url;
+       var strURL = phpGWLink('index.php', oArgs, true);
+       JqueryPortico.updateinlineTableHelper(oTable2, strURL);
+};

Modified: trunk/helpdesk/templates/base/tts.xsl
===================================================================
--- trunk/helpdesk/templates/base/tts.xsl       2016-06-27 18:50:05 UTC (rev 
15341)
+++ trunk/helpdesk/templates/base/tts.xsl       2016-06-27 18:51:17 UTC (rev 
15342)
@@ -1,1071 +1,871 @@
-<!-- $Id: tts.xsl 6705 2010-12-26 23:10:55Z sigurdne $ -->
 
-       <xsl:template name="app_data">
-               <xsl:choose>
-                       <xsl:when test="add">
-                               <xsl:apply-templates select="add"/>
-                       </xsl:when>
-                       <xsl:when test="view">
-                               <xsl:apply-templates select="view"/>
-                       </xsl:when>
-               </xsl:choose>
-       </xsl:template>
+<!-- $Id: tts.xsl 15283 2016-06-14 09:21:39Z sigurdne $ -->
 
+<xsl:template match="data">
+       <xsl:choose>
+               <xsl:when test="add">
+                       <xsl:apply-templates select="add"/>
+               </xsl:when>
+               <xsl:when test="view">
+                       <xsl:apply-templates select="view"/>
+               </xsl:when>
+       </xsl:choose>
+       <xsl:call-template name="jquery_phpgw_i18n"/>
+</xsl:template>
 
-
 <!-- add -->
+<xsl:template xmlns:php="http://php.net/xsl"; match="add">
+       <script type="text/javascript">
+               self.name="first_Window";
+               <xsl:value-of select="lookup_functions"/>
+               var my_groups = <xsl:value-of select="my_groups"/>;
+               var lang = <xsl:value-of select="php:function('js_lang', 
'Please select a person or a group to handle the ticket !')"/>;
+       </script>
 
-       <xsl:template match="add" xmlns:php="http://php.net/xsl";>
+       <dl>
                <xsl:choose>
                        <xsl:when test="msgbox_data != ''">
-                               <tr>
-                                       <td align="left" colspan="3">
-                                               <xsl:call-template 
name="msgbox"/>
-                                       </td>
-                               </tr>
+                               <dt>
+                                       <xsl:call-template name="msgbox"/>
+                               </dt>
                        </xsl:when>
                </xsl:choose>
-               <xsl:variable name="form_action"><xsl:value-of 
select="form_action"/></xsl:variable>
-               <form ENCTYPE="multipart/form-data" name="form" method="post" 
action="{$form_action}">
-                       <div class="yui-navset" id="ticket_tabview">
-                               <div class="yui-content">
+       </dl>
+       <xsl:variable name="form_action">
+               <xsl:value-of select="form_action"/>
+       </xsl:variable>
+       <form class="pure-form pure-form-aligned"  
ENCTYPE="multipart/form-data" id="form" name="form" method="post" 
action="{$form_action}">
+               <div id="tab-content">
+                       <xsl:value-of disable-output-escaping="yes" 
select="tabs"/>
+                       <div id="add">
+                               <fieldset>
+                                       <xsl:for-each select="value_origin">
+                                               <div class="pure-control-group">
+                                                       <label>
+                                                               <xsl:value-of 
select="descr"/>
+                                                       </label>
+                                                       <div 
class="pure-custom">
+                                                               <xsl:for-each 
select="data">
+                                                                       <div>
+                                                                               
<xsl:variable name="link_request">
+                                                                               
        <xsl:value-of select="//link_request"/>&amp;id=<xsl:value-of 
select="id"/>
+                                                                               
</xsl:variable>
+                                                                               
<a href="{link}" title="{//lang_origin_statustext}">
+                                                                               
        <xsl:value-of select="id"/>
+                                                                               
</a>
+                                                                               
<xsl:text> </xsl:text>
+                                                                       </div>
+                                                               </xsl:for-each>
+                                                       </div>
+                                               </div>
+                                       </xsl:for-each>
+                                       <input type="hidden" 
name="values[origin]" value="{value_origin_type}"/>
+                                       <input type="hidden" 
name="values[origin_id]" value="{value_origin_id}"/>
+                                       <div class="pure-control-group">
+                                               <label>
+                                                       <xsl:value-of 
select="php:function('lang', 'category')"/>
+                                               </label>
+                                               <xsl:call-template 
name="categories"/>
+                                       </div>
+                                       <xsl:choose>
+                                               <xsl:when test="simple !='1'">
+                                                       <div 
class="pure-control-group">
+                                                               <label>
+                                                                       
<xsl:value-of select="php:function('lang', 'Group')"/>
+                                                               </label>
 
-                                       <table cellpadding="2" cellspacing="2" 
width="80%" align="center">
+                                                               
<xsl:call-template name="group_select"/>
+                                                       </div>
+                                                       <xsl:choose>
+                                                               <xsl:when 
test="disable_userassign_on_add !='1'">
+                                                                       <div 
class="pure-control-group">
+                                                                               
<label>
+                                                                               
        <xsl:value-of select="php:function('lang', 'Assign to')"/>
+                                                                               
</label>
 
-                                               <xsl:for-each 
select="value_origin" >
-                                                       <tr>
-                                                               <td valign 
="top">
-                                                                       
<xsl:value-of select="descr"/>
-                                                               </td>
-                                                               <td>
-                                                                       <table> 
                                                
-                                                                               
<xsl:for-each select="data">
-                                                                               
        <tr>
-                                                                               
                <td align="left" >
-                                                                               
                        <xsl:variable name="link_request"><xsl:value-of 
select="//link_request"/>&amp;id=<xsl:value-of select="id"/></xsl:variable>
-                                                                               
                        <a href="{link}"  
title="{//lang_origin_statustext}"><xsl:value-of select="id"/></a>
-                                                                               
                        <xsl:text> </xsl:text>
-                                                                               
                </td>
-                                                                               
        </tr>
-                                                                               
</xsl:for-each>
-                                                                       </table>
-                                                               </td>
-                                                       </tr>
-                                               </xsl:for-each>
-                                               <input type="hidden" 
name="values[origin]" value="{value_origin_type}"></input>
-                                               <input type="hidden" 
name="values[origin_id]" value="{value_origin_id}"></input>
-
-<!--
-                                               <xsl:call-template 
name="location_form"/>
--->
-                                               <tr>
-                                                       <td>
-                                                               <xsl:value-of 
select="lang_category"/>
-                                                       </td>
-                                                       <td>
-                                                               
<xsl:call-template name="categories"/>
-                                                       </td>
-                                               </tr>
-
-                                               <xsl:choose>
-                                                       <xsl:when test="simple 
!='1'">
-                                                               <tr>
-                                                                       <td 
valign="top">
-                                                                               
<xsl:value-of select="php:function('lang', 'Group')" />                         
                        
-                                                                       </td>
-                                                                       <td>
-                                                                               
<xsl:call-template name="group_select"/>
-                                                                       </td>
-                                                               </tr>
-                                                               <tr>
-                                                                       <td 
valign="top">
-                                                                               
<xsl:value-of select="php:function('lang', 'Assign to')" />                     
                                
-                                                                       </td>
-                                                                       <td>
                                                                                
<xsl:call-template name="user_id_select"/>
-                                                                       </td>
-                                                               </tr>
-                                                               
<xsl:call-template name="contact_form"/>        
-                                                               <tr>
-                                                                       <td>
-                                                                               
<xsl:value-of select="php:function('lang', 'Send e-mail')" />                   
                                
-                                                                       </td>
-                                                                       <td>
-                                                                               
<input type="checkbox" name="values[send_mail]" value="1" >

@@ Diff output truncated at 153600 characters. @@



reply via email to

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