fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [15399] Syncromind: merge 15340:15398 from trunk


From: sigurdne
Subject: [Fmsystem-commits] [15399] Syncromind: merge 15340:15398 from trunk
Date: Mon, 1 Aug 2016 13:31:53 +0000 (UTC)

Revision: 15399
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15399
Author:   sigurdne
Date:     2016-08-01 13:31:53 +0000 (Mon, 01 Aug 2016)
Log Message:
-----------
Syncromind: merge 15340:15398 from trunk

Modified Paths:
--------------
    branches/dev-syncromind-2/booking/inc/class.sobooking.inc.php
    branches/dev-syncromind-2/booking/inc/class.socommon.inc.php
    branches/dev-syncromind-2/booking/inc/class.soevent.inc.php
    branches/dev-syncromind-2/booking/inc/class.uiapplication.inc.php
    branches/dev-syncromind-2/booking/inc/class.uibooking.inc.php
    branches/dev-syncromind-2/controller/inc/class.socase.inc.php
    branches/dev-syncromind-2/controller/inc/class.socheck_item.inc.php
    branches/dev-syncromind-2/controller/inc/class.socheck_list.inc.php
    branches/dev-syncromind-2/controller/inc/class.socommon.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol_group.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol_group_list.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol_item.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol_item_list.inc.php
    branches/dev-syncromind-2/controller/inc/class.socontrol_item_option.inc.php
    branches/dev-syncromind-2/controller/inc/class.sodocument.inc.php
    branches/dev-syncromind-2/controller/inc/class.soprocedure.inc.php
    branches/dev-syncromind-2/controller/inc/class.uicontrol.inc.php
    branches/dev-syncromind-2/controller/inc/class.uicontrol_group.inc.php
    branches/dev-syncromind-2/controller/inc/class.uicontrol_item.inc.php
    branches/dev-syncromind-2/controller/inc/class.uidocument.inc.php
    branches/dev-syncromind-2/controller/inc/class.uiprocedure.inc.php
    branches/dev-syncromind-2/controller/inc/model/class.model.inc.php
    branches/dev-syncromind-2/helpdesk/inc/class.botts.inc.php
    branches/dev-syncromind-2/helpdesk/inc/class.menu.inc.php
    branches/dev-syncromind-2/helpdesk/inc/class.sotts.inc.php
    branches/dev-syncromind-2/helpdesk/inc/class.uitts.inc.php
    branches/dev-syncromind-2/helpdesk/setup/setup.inc.php
    branches/dev-syncromind-2/helpdesk/setup/tables_current.inc.php
    branches/dev-syncromind-2/helpdesk/templates/base/tts.xsl
    branches/dev-syncromind-2/phpgwapi/inc/class.jquery.inc.php
    branches/dev-syncromind-2/phpgwapi/inc/class.translation.inc.php
    branches/dev-syncromind-2/phpgwapi/setup/setup.inc.php
    branches/dev-syncromind-2/phpgwapi/setup/tables_current.inc.php
    branches/dev-syncromind-2/phpgwapi/setup/tables_update.inc.php
    branches/dev-syncromind-2/phpgwapi/templates/bkbooking/navbar.inc.php
    branches/dev-syncromind-2/phpgwapi/templates/portico/head.inc.php
    branches/dev-syncromind-2/phpgwapi/templates/portico/navbar.inc.php
    branches/dev-syncromind-2/phpgwapi/templates/portico/navbar.tpl
    branches/dev-syncromind-2/property/inc/class.botts.inc.php
    branches/dev-syncromind-2/property/inc/class.sojasper.inc.php
    branches/dev-syncromind-2/property/inc/class.uientity.inc.php
    branches/dev-syncromind-2/property/inc/class.uiimport.inc.php
    branches/dev-syncromind-2/property/inc/class.uitts.inc.php
    branches/dev-syncromind-2/property/js/portico/tts.view.js
    branches/dev-syncromind-2/property/templates/base/tts.xsl
    branches/dev-syncromind-2/rental/inc/class.soadjustment.inc.php
    branches/dev-syncromind-2/rental/inc/class.soapplication.inc.php
    branches/dev-syncromind-2/rental/inc/class.socontract.inc.php
    branches/dev-syncromind-2/rental/inc/class.sonotification.inc.php
    branches/dev-syncromind-2/rental/inc/class.soparty.inc.php
    branches/dev-syncromind-2/rental/inc/class.uiapplication.inc.php
    branches/dev-syncromind-2/rental/inc/class.uibilling.inc.php
    branches/dev-syncromind-2/rental/inc/class.uicomposite.inc.php
    branches/dev-syncromind-2/rental/inc/class.uicontract.inc.php
    branches/dev-syncromind-2/rental/inc/model/class.application.inc.php
    branches/dev-syncromind-2/rental/inc/model/class.contract.inc.php
    branches/dev-syncromind-2/rental/js/rental/contract.edit.js
    branches/dev-syncromind-2/rental/js/rental/contract.index.js
    branches/dev-syncromind-2/rental/setup/phpgw_no.lang
    branches/dev-syncromind-2/rental/setup/setup.inc.php
    branches/dev-syncromind-2/rental/setup/tables_current.inc.php
    branches/dev-syncromind-2/rental/setup/tables_update.inc.php
    branches/dev-syncromind-2/rental/templates/base/application.xsl

Added Paths:
-----------
    branches/dev-syncromind-2/helpdesk/inc/hook_settings.inc.php
    branches/dev-syncromind-2/helpdesk/js/portico/
    branches/dev-syncromind-2/helpdesk/setup/phpgw_no.lang
    branches/dev-syncromind-2/helpdesk/setup/tables_update.inc.php
    branches/dev-syncromind-2/phpgwapi/js/jquery/jqTree/
    branches/dev-syncromind-2/phpgwapi/templates/portico/js/jqtree_jsmenu.js

Removed Paths:
-------------
    branches/dev-syncromind-2/helpdesk/js/yahoo/

Property Changed:
----------------
    branches/dev-syncromind-2/
    branches/dev-syncromind-2/booking/


Property changes on: branches/dev-syncromind-2
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/dev-syncromind:13653
/branches/stavangerkommune:12743-12875,12986
/trunk:14934-14935,15165-15215,15218-15220,15222-15304,15306-15337,15339
   + /branches/dev-syncromind:13653
/branches/stavangerkommune:12743-12875,12986
/trunk:14934-14935,15165-15215,15218-15220,15222-15304,15306-15337,15339,15341-15398


Property changes on: branches/dev-syncromind-2/booking
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/stavangerkommune/booking:9468-12740,12743-12875,12986
/trunk/booking:14937-15027,15165-15215,15253-15304,15306-15337
   + /branches/stavangerkommune/booking:9468-12740,12743-12875,12986
/trunk/booking:14937-15027,15165-15215,15253-15304,15306-15337,15341-15398

Modified: branches/dev-syncromind-2/booking/inc/class.sobooking.inc.php
===================================================================
--- branches/dev-syncromind-2/booking/inc/class.sobooking.inc.php       
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/booking/inc/class.sobooking.inc.php       
2016-08-01 13:31:53 UTC (rev 15399)
@@ -435,6 +435,9 @@
                {
                        $db = $this->db;
                        $db->transaction_begin();
+                       $table_name = $this->table_name . '_cost';
+                       $sql = "DELETE FROM $table_name WHERE booking_id = 
($id)";
+                       $db->query($sql, __LINE__, __FILE__);
                        $table_name = $this->table_name . '_resource';
                        $sql = "DELETE FROM $table_name WHERE booking_id = 
($id)";
                        $db->query($sql, __LINE__, __FILE__);

Modified: branches/dev-syncromind-2/booking/inc/class.socommon.inc.php
===================================================================
--- branches/dev-syncromind-2/booking/inc/class.socommon.inc.php        
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/booking/inc/class.socommon.inc.php        
2016-08-01 13:31:53 UTC (rev 15399)
@@ -31,7 +31,9 @@
                );
                protected
                        $cols,
-                       $auto_fields;
+                       $auto_fields,
+                       $global_lock = false;
+
                protected static $AUTO_FIELD_ACTIONS = array('add' => true, 
'update' => true);
 
                public function __construct( $table_name, $fields )
@@ -291,7 +293,7 @@
                {
                        if (!$id)
                        {
-                               return null;
+                               return array();
                        }
                        $row = array();
                        $pk_params = $this->primary_key_conditions($id);
@@ -641,7 +643,15 @@
                {
                        $values = 
$this->marshal_field_values($this->get_table_values($entry, __FUNCTION__));
 
-                       $this->db->transaction_begin();
+                       if ($this->db->get_transaction())
+                       {
+                               $this->global_lock = true;
+                       }
+                       else
+                       {
+                               $this->db->transaction_begin();
+                       }
+
                        $this->db->query('INSERT INTO ' . $this->table_name . ' 
(' . join(',', array_keys($values)) . ') VALUES(' . join(',', $values) . ')', 
__LINE__, __FILE__);
                        $id = $this->db->get_last_insert_id($this->table_name, 
'id');
                        foreach ($this->fields as $field => $params)
@@ -701,7 +711,10 @@
                                }
                        }
 
-                       $this->db->transaction_commit();
+                       if (!$this->global_lock)
+                       {
+                               $this->db->transaction_commit();
+                       }
 
                        $receipt['id'] = $id;
                        $receipt['message'][] = array('msg' => lang('Entity %1 
has been saved', $receipt['id']));

Modified: branches/dev-syncromind-2/booking/inc/class.soevent.inc.php
===================================================================
--- branches/dev-syncromind-2/booking/inc/class.soevent.inc.php 2016-08-01 
13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/booking/inc/class.soevent.inc.php 2016-08-01 
13:31:53 UTC (rev 15399)
@@ -116,6 +116,7 @@
 
                function get_ordered_comments( $id )
                {
+                       $id = (int) $id;
                        $results = array();
                        $this->db->query("select time,author,comment,type from 
bb_event_comment where event_id=($id) order by time desc", __LINE__, __FILE__);
                        while ($this->db->next_record())
@@ -130,6 +131,7 @@
 
                function get_ordered_costs( $id )
                {
+                       $id = (int) $id;
                        $results = array();
                        $this->db->query("SELECT * FROM bb_event_cost WHERE 
event_id=($id) ORDER BY time DESC", __LINE__, __FILE__);
                        while ($this->db->next_record())
@@ -177,6 +179,7 @@
 
                function get_contact_mail( $id, $type )
                {
+                       $id = (int) $id;
                        $mail = array();
                        if ($type == 'allocation')
                        {

Modified: branches/dev-syncromind-2/booking/inc/class.uiapplication.inc.php
===================================================================
--- branches/dev-syncromind-2/booking/inc/class.uiapplication.inc.php   
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/booking/inc/class.uiapplication.inc.php   
2016-08-01 13:31:53 UTC (rev 15399)
@@ -665,7 +665,7 @@
                                                }
                                                catch 
(booking_unauthorized_exception $e)
                                                {
-                                                       
phpgwapi_cache::message_set(lang('Could not add object due to insufficient 
permissions'));
+                                                       
phpgwapi_cache::message_set(lang('Could not add object due to insufficient 
permissions'),'error');
                                                }
                                        }
 
@@ -1082,7 +1082,7 @@
                                                        if ($old_file['name'] 
== $files['name']['name'])
                                                        {
                                                                $file_exist = 
true;
-                                                               
phpgwapi_cache::message_set(lang('file exists'));
+                                                               
phpgwapi_cache::message_set(lang('file exists'),'error');
                                                                break;
                                                        }
                                                }
@@ -1104,7 +1104,7 @@
                                                }
                                                catch 
(booking_unauthorized_exception $e)
                                                {
-                                                       
phpgwapi_cache::message_set(lang('Could not add object due to insufficient 
permissions'));
+                                                       
phpgwapi_cache::message_set(lang('Could not add object due to insufficient 
permissions'),'error');
                                                }
                                        }
 

Modified: branches/dev-syncromind-2/booking/inc/class.uibooking.inc.php
===================================================================
--- branches/dev-syncromind-2/booking/inc/class.uibooking.inc.php       
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/booking/inc/class.uibooking.inc.php       
2016-08-01 13:31:53 UTC (rev 15399)
@@ -918,7 +918,8 @@
                                        }
                                        if ($step == 3)
                                        {
-                                               
$this->redirect(array('menuaction' => 'booking.uimassbooking.schedule', 'id' => 
$allocation['building_id']));
+                                               $building_id = 
$booking['building_id'] ? $booking['building_id'] : $allocation['building_id'];
+                                               
$this->redirect(array('menuaction' => 'booking.uimassbooking.schedule', 'id' => 
$building_id));
                                        }
                                }
                        }

Modified: branches/dev-syncromind-2/controller/inc/class.socase.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socase.inc.php       
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socase.inc.php       
2016-08-01 13:31:53 UTC (rev 15399)
@@ -51,7 +51,7 @@
                        return self::$so;
                }
 
-               function get_query( string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count )
+               function get_query( string $sort_field, bool $ascending, string 
$search_for, string $search_type, array $filters, bool $return_count )
                {
 
                }

Modified: branches/dev-syncromind-2/controller/inc/class.socheck_item.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socheck_item.inc.php 
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socheck_item.inc.php 
2016-08-01 13:31:53 UTC (rev 15399)
@@ -497,7 +497,7 @@
                  }
                 */
 
-               function get_query( string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count )
+               function get_query( string $sort_field, bool $ascending, string 
$search_for, string $search_type, array $filters, bool $return_count )
                {
 
                }

Modified: branches/dev-syncromind-2/controller/inc/class.socheck_list.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socheck_list.inc.php 
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socheck_list.inc.php 
2016-08-01 13:31:53 UTC (rev 15399)
@@ -715,7 +715,7 @@
                        return array("location_code" => $location_code, 
"check_lists_array" => $check_lists_array);
                }
 
-               function get_query( string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count )
+               function get_query( string $sort_field, bool $ascending, string 
$search_for, string $search_type, array $filters, bool $return_count )
                {
                        $current_time = time();
                        $buffer_in_days = 3600 * 24 * 7 * 5;

Modified: branches/dev-syncromind-2/controller/inc/class.socommon.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socommon.inc.php     
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socommon.inc.php     
2016-08-01 13:31:53 UTC (rev 15399)
@@ -92,11 +92,11 @@
                {
                        if ($type == 'bool')
                        {
-                               return (boolean)$value;
+                               return (bool)$value;
                        }
                        else if ($type == 'boolean')
                        {
-                               return (boolean)$value;
+                               return (bool)$value;
                        }
                        else if ($type == 'int')
                        {
@@ -150,7 +150,7 @@
                 */
                public function get_single( int $id )
                {
-                       $objects = $this->get(null, null, null, null, null, 
null, array($this->get_id_field_name() => $id));
+                       $objects = $this->get(0, 0, '', false, '', '', 
array($this->get_id_field_name() => $id));
                        if (count($objects) > 0)
                        {
                                $keys = array_keys($objects);
@@ -173,7 +173,7 @@
                 * @param $start_index int with index of first object.
                 * @param $num_of_objects int with max number of objects to 
return.
                 * @param $sort_field string representing the object field to 
sort on.
-                * @param $ascending boolean true for ascending sort on sort 
field, false
+                * @param $ascending bool true for ascending sort on sort 
field, false
                 * for descending.
                 * @param $search_for string with free text search query.
                 * @param $search_type string with the query type.
@@ -181,7 +181,7 @@
                 * @return array of objects. May return an empty
                 * array, never null. The array keys are the respective index 
numbers.
                 */
-               public function get( int $start_index, int $num_of_objects, 
string $sort_field, boolean $ascending, string $search_for, string 
$search_type, array $filters )
+               public function get( int $start_index, int $num_of_objects, 
string $sort_field, bool $ascending, string $search_for, string $search_type, 
array $filters )
                {
                        $results = array();   // Array to store result objects
                        $map = array(); // Array to hold number of records per 
target object
@@ -309,7 +309,7 @@
                 */
                public function get_count( string $search_for, string 
$search_type, array $filters )
                {
-                       return $this->get_query_count($this->get_query(null, 
null, $search_for, $search_type, $filters, true));
+                       return $this->get_query_count($this->get_query('', 
false, $search_for, $search_type, $filters, true));
                }
 
                /**
@@ -326,16 +326,16 @@
                 * @param $start_index int with index of first object.
                 * @param $num_of_objects int with max number of objects to 
return.
                 * @param $sort_field string representing the object field to 
sort on.
-                * @param $ascending boolean true for ascending sort on sort 
field, false
+                * @param $ascending bool true for ascending sort on sort 
field, false
                 * for descending.
                 * @param $search_for string with free text search query.
                 * @param $search_type string with the query type.
                 * @param $filters array with key => value of filters.
-                * @param $return_count boolean telling to return only the 
count of the
+                * @param $return_count bool telling to return only the count 
of the
                 * matching objects, or the objects themself.
                 * @return string with SQL.
                 */
-               protected abstract function get_query( string $sort_field, 
boolean $ascending, string $search_for, string $search_type, array $filters, 
boolean $return_count );
+               protected abstract function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count );
 
                protected abstract function populate( int $object_id, &$object 
);
 

Modified: branches/dev-syncromind-2/controller/inc/class.socontrol.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socontrol.inc.php    
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socontrol.inc.php    
2016-08-01 13:31:53 UTC (rev 15399)
@@ -84,7 +84,7 @@
                 * Update the database values for an existing control object.
                 *
                 * @param $control the control to be updated
-                * @return boolean true if successful, false otherwise
+                * @return bool true if successful, false otherwise
                 */
                function update( $control )
                {
@@ -1151,7 +1151,8 @@
                                . " FROM controller_control_component_list"
                                . " {$this->db->join} controller_control ON 
controller_control.id = controller_control_component_list.control_id"
                                . " {$this->db->left_join} 
controller_control_serie ON (controller_control_component_list.id = 
controller_control_serie.control_relation_id AND 
controller_control_serie.control_relation_type = 'component')"
-                               . " WHERE location_id = {$location_id} AND 
component_id = {$component_id}";
+                               . " WHERE location_id = {$location_id} AND 
component_id = {$component_id}"
+                               . " ORDER BY repeat_type, repeat_interval";
 //                     _debug_array($sql);
                        $this->db->query($sql, __LINE__, __FILE__);
 
@@ -1220,7 +1221,7 @@
                        return $ret;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
                        $clauses = array('1=1');
 

Modified: branches/dev-syncromind-2/controller/inc/class.socontrol_group.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socontrol_group.inc.php      
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socontrol_group.inc.php      
2016-08-01 13:31:53 UTC (rev 15399)
@@ -262,7 +262,7 @@
                        return $ret;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
                        $clauses = array('1=1');
                        if ($search_for)

Modified: 
branches/dev-syncromind-2/controller/inc/class.socontrol_group_list.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socontrol_group_list.inc.php 
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socontrol_group_list.inc.php 
2016-08-01 13:31:53 UTC (rev 15399)
@@ -88,7 +88,7 @@
                 * Update the database values for an existing 
control_group_list object.
                 *
                 * @param $control_group_list the control_group_list to be 
updated
-                * @return boolean true if successful, false otherwise
+                * @return bool true if successful, false otherwise
                 */
                function update( $control_group_list )
                {
@@ -240,7 +240,7 @@
                        return $control_group_list;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
 
                }

Modified: branches/dev-syncromind-2/controller/inc/class.socontrol_item.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socontrol_item.inc.php       
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socontrol_item.inc.php       
2016-08-01 13:31:53 UTC (rev 15399)
@@ -95,7 +95,7 @@
                 * Update the database values for an existing control item 
object.
                 *
                 * @param $control item object to be updated
-                * @return boolean true if successful, false otherwise
+                * @return bool true if successful, false otherwise
                 */
                function update( $control_item )
                {
@@ -237,7 +237,7 @@
                        {
                                $control_item = new 
controller_control_item($this->unmarshal($this->db->f('id'), 'int'));
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'bool'));
                                
$control_item->set_type($this->unmarshal($this->db->f('type', true), 'string'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
@@ -269,7 +269,7 @@
                        return $ret;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
 
                        $clauses = array('1=1');
@@ -367,7 +367,7 @@
                                $control_item = new 
controller_control_item((int)$control_item_id);
 
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'bool'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
                                
$control_item->set_control_group_id($this->unmarshal($this->db->f('control_group_id'),
 'int'));
@@ -425,7 +425,7 @@
                                //create check_item and add to return array
                                $control_item = new 
controller_control_item($this->unmarshal($this->db->f('id'), 'int'));
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required', true), 
'bool'));
                                
$control_item->set_type($this->unmarshal($this->db->f('type', true), 'string'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));

Modified: 
branches/dev-syncromind-2/controller/inc/class.socontrol_item_list.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.socontrol_item_list.inc.php  
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.socontrol_item_list.inc.php  
2016-08-01 13:31:53 UTC (rev 15399)
@@ -178,7 +178,7 @@
                        {
                                $control_item = new 
controller_control_item($this->unmarshal($this->db->f('id'), 'int'));
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 'bool'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
                                
$control_item->set_control_group_id($this->unmarshal($this->db->f('control_group_id'),
 'int'));
@@ -213,7 +213,7 @@
                        {
                                $control_item = new 
controller_control_item($this->unmarshal($this->db->f('id'), 'int'));
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 'bool'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
                                
$control_item->set_control_group_id($this->unmarshal($this->db->f('control_group_id'),
 'int'));
@@ -261,7 +261,7 @@
                        {
                                $control_item = new 
controller_control_item($this->unmarshal($this->db->f('id'), 'int'));
                                
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 
'boolean'));
+                               
$control_item->set_required($this->unmarshal($this->db->f('required'), 'bool'));
                                
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
                                
$control_item->set_control_group_id($this->unmarshal($this->db->f('control_group_id'),
 'int'));
@@ -329,7 +329,7 @@
 
                                        $control_item = new 
controller_control_item($this->unmarshal($this->db->f('ci_id'), 'int'));
                                        
$control_item->set_title($this->unmarshal($this->db->f('title', true), 
'string'));
-                                       
$control_item->set_required($this->unmarshal($this->db->f('required'), 
'boolean'));
+                                       
$control_item->set_required($this->unmarshal($this->db->f('required'), 'bool'));
                                        
$control_item->set_what_to_do($this->unmarshal($this->db->f('what_to_do', 
true), 'string'));
                                        
$control_item->set_how_to_do($this->unmarshal($this->db->f('how_to_do', true), 
'string'));
                                        
$control_item->set_control_group_id($this->unmarshal($this->db->f('control_group_id'),
 'int'));
@@ -433,7 +433,7 @@
 
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
 
                }

Modified: 
branches/dev-syncromind-2/controller/inc/class.socontrol_item_option.inc.php
===================================================================
--- 
branches/dev-syncromind-2/controller/inc/class.socontrol_item_option.inc.php    
    2016-08-01 13:24:09 UTC (rev 15398)
+++ 
branches/dev-syncromind-2/controller/inc/class.socontrol_item_option.inc.php    
    2016-08-01 13:31:53 UTC (rev 15399)
@@ -136,7 +136,7 @@
 
                }
 
-               function get_query( string $sort_field, boolean $ascending, 
string $search_for, string $search_type, array $filters, boolean $return_count )
+               function get_query( string $sort_field, bool $ascending, string 
$search_for, string $search_type, array $filters, bool $return_count )
                {
                        
                }

Modified: branches/dev-syncromind-2/controller/inc/class.sodocument.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.sodocument.inc.php   
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.sodocument.inc.php   
2016-08-01 13:31:53 UTC (rev 15399)
@@ -70,7 +70,7 @@
                        return $ret;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
 
                        $clauses = array('1=1');
@@ -313,6 +313,12 @@
                        $path .= "/{$name}";
                        $file = array('string' => $path, RELATIVE_NONE);
 
+                       return $vfs->cp(array(
+                                                       'from' => 
$temporary_name,
+                                                       'to' => $path,
+                                                       'relatives' => 
array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))
+                               );
+/*
                        return $vfs->write
                                        (
                                        array
@@ -322,6 +328,7 @@
                                                'content' => 
file_get_contents($temporary_name)
                                        )
                        );
+ */
                }
 
                public function read_document_from_vfs( string $document_type, 
$id, $name )
@@ -352,10 +359,8 @@
                        $vfs = CreateObject('phpgwapi.vfs');
                        $vfs->override_acl = 1;
 
-                       return $vfs->rm
-                                       (
-                                       array
-                                               (
+                       return $vfs->rm(
+                                       array(
                                                'string' => $path,
                                                RELATIVE_NONE
                                        )
@@ -364,6 +369,7 @@
 
                public function delete_document( $id )
                {
+                       $id = (int)$id;
                        $sql = "DELETE FROM controller_document WHERE id = 
{$id}";
 
                        $result = $this->db->query($sql, __LINE__, __FILE__);

Modified: branches/dev-syncromind-2/controller/inc/class.soprocedure.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.soprocedure.inc.php  
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.soprocedure.inc.php  
2016-08-01 13:31:53 UTC (rev 15399)
@@ -107,7 +107,7 @@
                 * Update the database values for an existing activity object.
                 *
                 * @param $activity the activity to be updated
-                * @return boolean true if successful, false otherwise
+                * @return bool true if successful, false otherwise
                 */
                function update( $procedure )
                {
@@ -454,7 +454,7 @@
                        return $ret;
                }
 
-               protected function get_query( string $sort_field, boolean 
$ascending, string $search_for, string $search_type, array $filters, boolean 
$return_count )
+               protected function get_query( string $sort_field, bool 
$ascending, string $search_for, string $search_type, array $filters, bool 
$return_count )
                {
                        $clauses = array('1=1');
                        if ($search_for)

Modified: branches/dev-syncromind-2/controller/inc/class.uicontrol.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.uicontrol.inc.php    
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.uicontrol.inc.php    
2016-08-01 13:31:53 UTC (rev 15399)
@@ -903,6 +903,8 @@
                                'allrows' => phpgw::get_var('length', 'int') == 
-1,
                        );
 
+                       $filters = array();
+                       $search_type = '';
 
                        $ctrl_area = phpgw::get_var('control_areas');
                        if (isset($ctrl_area) && $ctrl_area > 0)

Modified: branches/dev-syncromind-2/controller/inc/class.uicontrol_group.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.uicontrol_group.inc.php      
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.uicontrol_group.inc.php      
2016-08-01 13:31:53 UTC (rev 15399)
@@ -374,7 +374,7 @@
                                $building_part_options = 
$this->so->get_building_part_select_array($control_group->get_building_part_id());
 
                                $control_group_array = 
$control_group->toArray();
-                               $control_items_array = 
$this->so_control_item->get(null, null, 
'controller_control_item.control_area_id', true, null, null, array(
+                               $control_items_array = 
$this->so_control_item->get(0, 0, 'controller_control_item.control_area_id', 
true, '', '', array(
                                        'available' => 'yes'));
 
                                $control_items = array();
@@ -488,7 +488,7 @@
                                $building_part_options = 
$this->so->get_building_part_select_array($control_group->get_building_part_id());
 
                                $control_group_array = 
$control_group->toArray();
-                               $control_items_array = 
$this->so_control_item->get(null, null, 
'controller_control_item.control_area_id', true, null, null, array(
+                               $control_items_array = 
$this->so_control_item->get(0, 0, 'controller_control_item.control_area_id', 
true, '', '', array(
                                        'available' => 'yes'));
 
                                $control_items = array();
@@ -760,7 +760,9 @@
                        // YUI variables for paging and sorting
                        $start_index = $params['start'];
                        $num_of_objects = $params['results'] > 0 ? 
$params['results'] : null;
-                       $sort_field = $params['order'];
+                       $sort_field = ($params['order']) ? $params['order'] : 
'';
+                       $filters = array();
+                       $search_type = '';
 
                        $ctrl_area = phpgw::get_var('control_areas');
                        if (isset($ctrl_area) && $ctrl_area > 0)

Modified: branches/dev-syncromind-2/controller/inc/class.uicontrol_item.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.uicontrol_item.inc.php       
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.uicontrol_item.inc.php       
2016-08-01 13:31:53 UTC (rev 15399)
@@ -425,7 +425,8 @@
                        $num_of_objects = $params['results'] > 0 ? 
$params['results'] : null;
                        $sort_field = $params['order'];
 
-
+                       $search_type = '';
+                       $filters = array();
                        $ctrl_area = phpgw::get_var('control_areas');
                        if (isset($ctrl_area) && $ctrl_area > 0)
                        {

Modified: branches/dev-syncromind-2/controller/inc/class.uidocument.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.uidocument.inc.php   
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.uidocument.inc.php   
2016-08-01 13:31:53 UTC (rev 15399)
@@ -280,13 +280,16 @@
                                        else
                                        {
                                                // Handle failure on storing 
document
-                                               $this->redirect($document, 
$document_propeties, '', '');
+                                               $this->redirect($document, 
$document_properties, '', '');
                                        }
                                }
                                else
                                {
+                                               
$GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 
'controller.uidocument.show',
+                                                       'procedure_id' => 
$procedure->get_id(),
+                                                       'tab' => 'documents'));
                                        //Handle vfs failure to store document
-                                       $this->redirect($document, 
$document_propeties, '', '');
+//                                     $this->redirect($document, 
$document_properties, '', '');
                                }
                        }
                }
@@ -464,7 +467,7 @@
                                        $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox($msgbox_data);
                                }
 
-                               $documents = $this->so->get(null, null, null, 
null, null, null, array(
+                               $documents = $this->so->get(0, 0, '', false, 
'', '', array(
                                        'procedure_id' => $procedure_id,
                                        'type' => $document_type));
 

Modified: branches/dev-syncromind-2/controller/inc/class.uiprocedure.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/class.uiprocedure.inc.php  
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/class.uiprocedure.inc.php  
2016-08-01 13:31:53 UTC (rev 15399)
@@ -681,7 +681,8 @@
 
                        $start_index = $params['start'];
                        $num_of_objects = $params['results'] > 0 ? 
$params['results'] : null;
-                       $sort_field = $params['order'];
+                       $sort_field = ($params['order']) ? $params['order'] : 
'';
+                       $filters = array();
 
                        $ctrl_area = phpgw::get_var('control_areas');
                        if (isset($ctrl_area) && $ctrl_area > 0)
@@ -690,7 +691,7 @@
                        }
                        $sort_ascending = $params['sort'] == 'desc' ? false : 
true;
                        // Form variables
-                       $search_type = phpgw::get_var('search_option');
+                       $search_type = phpgw::get_var('search_option', 
'string', 'REQUEST', '');
                        // Create an empty result set
                        $result_objects = array();
                        $result_count = 0;

Modified: branches/dev-syncromind-2/controller/inc/model/class.model.inc.php
===================================================================
--- branches/dev-syncromind-2/controller/inc/model/class.model.inc.php  
2016-08-01 13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/controller/inc/model/class.model.inc.php  
2016-08-01 13:31:53 UTC (rev 15399)
@@ -38,7 +38,7 @@
                protected $field_of_responsibility_name;
                protected $permission_array;
 
-               public function __construct( int $id )
+               public function __construct( $id )
                {
                        $this->id = (int)$id;
                }
@@ -83,7 +83,7 @@
                 * in order to validate against the standard database rules.  
The subclasses can in addition
                 * add their own specific validation logic.
                 *
-                * @return boolean true if the object is valid, false otherwise
+                * @return bool true if the object is valid, false otherwise
                 */
                public function validates()
                {

Modified: branches/dev-syncromind-2/helpdesk/inc/class.botts.inc.php
===================================================================
--- branches/dev-syncromind-2/helpdesk/inc/class.botts.inc.php  2016-08-01 
13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/helpdesk/inc/class.botts.inc.php  2016-08-01 
13:31:53 UTC (rev 15399)
@@ -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('assigned to')
+                       );
 
-               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;
                }
 
@@ -970,10 +990,125 @@
                        return $receipt;
                }
 
-               public function update_ticket($data, $id)
+               public function update_priority( $data, $id = 0 )
                {
-                       $receipt        = $this->so->update_ticket($data, $id);
-                       $this->fields_updated = $this->so->fields_updated;      
        
+                       $receipt = $this->so->update_priority($data, $id);
+                       $this->fields_updated = $this->so->fields_updated;
                        return $receipt;
                }
+
+               public function update_ticket( &$data, $id, $receipt = array(), 
$values_attribute = array() )
+               {
+                       if ($values_attribute && is_array($values_attribute))
+                       {
+                               $values_attribute = 
$this->custom->convert_attribute_save($values_attribute);
+                       }
+
+                       $criteria = array
+                               (
+                               'appname' => 'helpdesk',
+                               'location' => $this->acl_location,
+                               'allrows' => true
+                       );
+
+                       $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
+
+                       foreach ($custom_functions as $entry)
+                       {
+                               // prevent path traversal
+                               if (preg_match('/\.\./', $entry['file_name']))
+                               {
+                                       continue;
+                               }
+
+                               $file = PHPGW_SERVER_ROOT . 
"/helpdesk/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+                               if ($entry['active'] && is_file($file) && 
!$entry['client_side'] && $entry['pre_commit'])
+                               {
+                                       require $file;
+                               }
+                       }
+
+                       $receipt = $this->so->update_ticket($data, $id, 
$receipt, $values_attribute, $this->simple);
+                       $this->fields_updated = $this->so->fields_updated;
+
+
+                       reset($custom_functions);
+
+                       foreach ($custom_functions as $entry)
+                       {
+                               // prevent path traversal
+                               if (preg_match('/\.\./', $entry['file_name']))
+                               {
+                                       continue;
+                               }
+
+                               $file = PHPGW_SERVER_ROOT . 
"/helpdesk/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
+                               if ($entry['active'] && is_file($file) && 
!$entry['client_side'] && !$entry['pre_commit'])
+                               {
+                                       require $file;
+                               }
+                       }
+
+                       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: branches/dev-syncromind-2/helpdesk/inc/class.menu.inc.php
===================================================================
--- branches/dev-syncromind-2/helpdesk/inc/class.menu.inc.php   2016-08-01 
13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/helpdesk/inc/class.menu.inc.php   2016-08-01 
13:31:53 UTC (rev 15399)
@@ -116,7 +116,7 @@
 
                        $menus['navigation'] = array();
 
-
+/*
                        if ( $acl->check('.ticket',PHPGW_ACL_READ, 'helpdesk') )
                        {
                                $menus['navigation']['helpdesk'] = array
@@ -126,21 +126,7 @@
                                                'image'         => 
array('helpdesk', 'helpdesk')
                                        );
                        }
-
-                       if ( $acl->check('.ticket.order',PHPGW_ACL_ADD, 
'helpdesk') )
-                       {
-                               $menus['navigation']['helpdesk']['children'] = 
array
-                                       (
-                                               'order_template' => array
-                                               (       
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'property.uigeneric.index', 'type' => 'order_template') ),
-                                                       'text'  => lang('order 
template'),
-                                                       'image'         => 
array('helpdesk', 'helpdesk')
-                                               )
-                                       );
-                       }
-
-
+*/
                        $GLOBALS['phpgw_info']['flags']['currentapp'] = 
$incoming_app;
                        return $menus;
                }

Modified: branches/dev-syncromind-2/helpdesk/inc/class.sotts.inc.php
===================================================================
--- branches/dev-syncromind-2/helpdesk/inc/class.sotts.inc.php  2016-08-01 
13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/helpdesk/inc/class.sotts.inc.php  2016-08-01 
13:31:53 UTC (rev 15399)
@@ -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;
@@ -131,19 +131,14 @@
                        {
                                if( $order == 'assignedto' )
                                {
-//                                     $result_order_field = 
',account_lastname';
-//                                     $order_join = "LEFT OUTER JOIN 
phpgw_accounts ON phpgw_helpdesk_tickets.assignedto=phpgw_accounts.account_id";
-//                                     $order = 'account_lastname';
+                                       $result_order_field = 
',account_lastname';
+                                       $order = 'account_lastname';
                                }
                                else if( $order == 'user' )
                                {
                                        $result_order_field = 
',account_lastname';
                                        $order = 'account_lastname';
                                }
-                               else
-                               {
-                                       $order_join = '';
-                               }
 
                                $ordermethod = " ORDER BY $order $sort";
                        }
@@ -201,7 +196,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 +324,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 +332,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 +347,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,17 +380,14 @@
                                                (
                                                        'id'                    
        => (int) $this->db->f('id'),
                                                        'subject'               
        => $this->db->f('subject',true),
-                                                       'loc1_name'             
        => $this->db->f('loc1_name',true),
-                                                       'location_code'         
=> $this->db->f('location_code'),
-                                                       'district'              
        => $this->db->f('district',true),
                                                        'user_id'               
        => $this->db->f('user_id'),
-                                                       'address'               
        => $this->db->f('address',true),
                                                        'assignedto'            
=> $this->db->f('assignedto'),
                                                        'status'                
        => $this->db->f('status'),
                                                        'priority'              
        => $this->db->f('priority'),
                                                        'cat_id'                
        => $this->db->f('cat_id'),
                                                        'group_id'              
        => $this->db->f('group_id'),
                                                        'entry_date'            
=> $this->db->f('entry_date'),
+                                                       'modified_date'         
=> $this->db->f('modified_date'),
                                                        'finnish_date'          
=> $this->db->f('finnish_date'),
                                                        'finnish_date2'         
=> $this->db->f('finnish_date2'),
                                                        'order_id'              
        => $this->db->f('order_id'),
@@ -433,19 +398,6 @@
                                                        'billable_hours'        
=> $this->db->f('billable_hours'),
                                                );
                                }
-/*                     
-                               foreach ($tickets as &$ticket)
-                               {
-                                       $this->db->query("SELECT count(*) as 
hits FROM phpgw_helpdesk_views where id={$ticket['id']}"
-                                               . " AND 
account_id='{$this->account}'",__LINE__,__FILE__);
-                                       $this->db->next_record();
-
-                                       if(! $this->db->f('hits'))
-                                       {
-                                               $ticket['new_ticket'] = true;
-                                       }
-                               }
- */
                        }
 
                        return $tickets;
@@ -516,6 +468,7 @@
                                $ticket['order_dim1']           = 
$this->db->f('order_dim1');
                                $ticket['publish_note']         = 
$this->db->f('publish_note');
                                $ticket['billable_hours']       = 
$this->db->f('billable_hours');
+                               $ticket['modified_date'] = 
$this->db->f('modified_date');
 
                                $user_id=(int)$this->db->f('user_id');
 
@@ -602,6 +555,7 @@
                                        $ticket['location_code'],
                                        $address,
                                        time(),
+                                       time(),
                                        $ticket['finnish_date'],
                                        $ticket['contact_id'],
                                        1
@@ -612,7 +566,7 @@
 
                        $this->db->query("insert into phpgw_helpdesk_tickets 
(priority,user_id,"
                                . 
"assignedto,group_id,subject,cat_id,status,details,location_code,"
-                               . 
"address,entry_date,finnish_date,contact_id,publish_note $cols)"
+                               . 
"address,entry_date,modified_date,finnish_date,contact_id,publish_note $cols)"
                                . "VALUES ($values $vals )",__LINE__,__FILE__);
 
                        $id = 
$this->db->get_last_insert_id('phpgw_helpdesk_tickets','id');
@@ -731,6 +685,7 @@
 
                        if ($this->fields_updated)
                        {
+                               $this->db->query('UPDATE phpgw_helpdesk_tickets 
SET modified_date= ' . time() . " WHERE id={$id}", __LINE__, __FILE__);
                                $receipt['message'][]= array('msg' => 
lang('Ticket %1 has been updated',$id));
                        }
 
@@ -738,383 +693,426 @@
 
                }
 
-               function update_ticket($ticket,$id = 0)
+               function update_priority( $ticket, $id = 0 )
                {
-                       $id = (int) $id;
+                       $id = (int)$id;
                        $receipt = array();
+                       $this->fields_updated = false;
+
+                       $this->db->query("SELECT priority FROM 
phpgw_helpdesk_tickets WHERE id={$id}", __LINE__, __FILE__);
+                       $this->db->next_record();
+                       $oldpriority = $this->db->f('priority');
+
+                       $this->db->transaction_begin();
+
+                       if ($oldpriority != $ticket['priority'])
+                       {
+                               $this->fields_updated = true;
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
set priority='" . $ticket['priority']
+                                       . "' WHERE id={$id}", __LINE__, 
__FILE__);
+                               $this->historylog->add('P', $id, 
$ticket['priority'], $oldpriority);
+                       }
+
+                       if ($this->fields_updated)
+                       {
+                               $this->db->query('UPDATE phpgw_helpdesk_tickets 
SET modified_date= ' . time() . " WHERE id={$id}", __LINE__, __FILE__);
+                               $receipt['message'][] = array('msg' => 
lang('Ticket %1 has been updated', $id));
+                       }
+
+                       $this->db->transaction_commit();
+
+                       return $receipt;
+               }
+
+               function update_ticket( &$ticket, $id = 0, $receipt = array(), 
$values_attribute = array(), $simple = false )
+               {
+                       $this->fields_updated = array();
+                       $id = (int)$id;
+                       $ticket['id'] = $id;
                        // DB Content is fresher than http posted value.
-                       $this->db->query("select * from phpgw_helpdesk_tickets 
where id='$id'",__LINE__,__FILE__);
+                       $this->db->query("SELECT * FROM phpgw_helpdesk_tickets 
WHERE id='$id'", __LINE__, __FILE__);
                        $this->db->next_record();
 
-                       $location_code  = $this->db->f('location_code');
-                       $oldlocation_code       = $this->db->f('location_code');
-                       $oldfinnish_date        = $this->db->f('finnish_date');
-                       $oldfinnish_date2       = $this->db->f('finnish_date2');
-                       $oldassigned            = $this->db->f('assignedto');
-                       $oldgroup_id            = $this->db->f('group_id');
-                       $oldpriority            = $this->db->f('priority');
-                       $oldcat_id                      = 
$this->db->f('cat_id');
-                       $old_status             = $this->db->f('status');
-                       $old_budget             = $this->db->f('budget');
-                       $old_billable_hours     = 
$this->db->f('billable_hours');
+                       $location_code = $this->db->f('location_code');
+                       $oldlocation_code = $this->db->f('location_code');
+                       $oldfinnish_date = $this->db->f('finnish_date');
+                       $oldfinnish_date2 = $this->db->f('finnish_date2');
+                       $oldassigned = $this->db->f('assignedto');
+                       $oldgroup_id = $this->db->f('group_id');
+                       $oldpriority = $this->db->f('priority');
+                       $oldcat_id = $this->db->f('cat_id');
+                       $old_status = $this->db->f('status');
+                       $ticket['old_status'] = $old_status; // used for custom 
functions
+                       //      $old_budget                     = 
$this->db->f('budget');
+                       $old_billable_hours = 
(float)$this->db->f('billable_hours');
                        //      $old_billable_rate      = 
$this->db->f('billable_rate');
-                       $old_subject            = $this->db->f('subject');
-                       $old_contact_id         = $this->db->f('contact_id');
-                       $old_actual_cost        = $this->db->f('actual_cost');
-                       $old_order_cat_id       = $this->db->f('order_cat_id');
-                       $old_building_part      = 
$this->db->f('building_part',true);
-                       $old_order_dim1         = 
(int)$this->db->f('order_dim1');
+                       $old_subject = $this->db->f('subject');
+                       $old_contact_id = $this->db->f('contact_id');
+                       $old_order_cat_id = $this->db->f('order_cat_id');
+                       $old_building_part = $this->db->f('building_part', 
true);
+                       $old_order_dim1 = (int)$this->db->f('order_dim1');
 
 
-                       if($oldcat_id ==0){$oldcat_id ='';}
-                       if($old_order_cat_id ==0){$old_order_cat_id ='';}
-                               if($oldassigned ==0){$oldassigned ='';}
-                                       if($oldgroup_id ==0){$oldgroup_id ='';}
+                       if ($oldcat_id == 0)
+                       {
+                               $oldcat_id = '';
+                       }
+                       if ($old_order_cat_id == 0)
+                       {
+                               $old_order_cat_id = '';
+                       }
+                       if ($oldassigned == 0)
+                       {
+                               $oldassigned = '';
+                       }
+                       if ($oldgroup_id == 0)
+                       {
+                               $oldgroup_id = '';
+                       }
 
-                                               // Figure out and last note
+                       // Figure out and last note
 
-                                               $history_values = 
$this->historylog->return_array(array(),array('C'),'history_timestamp','DESC',$id);
+                       $history_values = 
$this->historylog->return_array(array(), array('C'), 'history_timestamp', 
'DESC', $id);
                        $old_note = $history_values[0]['new_value'];
 
-                       if(!$old_note)
+                       if (!$old_note)
                        {
                                $old_note = $this->db->f('details');
                        }
 
-
                        $this->db->transaction_begin();
 
                        /*
-                        ** phpgw_phpgw_helpdesk_append.append_type - Defs
-                        ** R - Reopen ticket
-                        ** X - Ticket closed
-                        ** O - Ticket opened
-                        ** C - Comment appended
-                        ** A - Ticket assignment
-                        ** G - Ticket group assignment
-                        ** P - Priority change
-                        ** T - Category change
-                        ** S - Subject change
-                        ** B - Budget change
-                        ** H - Billing hours
-                        ** F - finnish date
-                        ** C% - Status change
-                        ** L - Location changed
-                        ** M - Mail sent to vendor
+                        * * phpgw_fm_tts_append.append_type - Defs
+                        * * R - Reopen ticket
+                        * * X - Ticket closed
+                        * * O - Ticket opened
+                        * * C - Comment appended
+                        * * A - Ticket assignment
+                        * * G - Ticket group assignment
+                        * * P - Priority change
+                        * * T - Category change
+                        * * S - Subject change
+                        * * B - Budget change
+                        * *    AC - actual cost changed
+                        * * H - Billing hours
+                        * * F - finnish date
+                        * * C% - Status change
+                        * * L - Location changed
+                        * * M - Mail sent to vendor
                         */
 
-                       $this->db->query("UPDATE phpgw_helpdesk_tickets SET 
publish_note = NULL WHERE id = {$id}",__LINE__,__FILE__);
-                       $this->db->query("UPDATE phpgw_history_log SET publish 
= NULL WHERE history_record_id = {$id}",__LINE__,__FILE__);
-                       if(isset($ticket['publish_note']))
+                       if (!$simple)
                        {
-                               foreach ($ticket['publish_note'] as 
$publish_info)
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET publish_note = NULL WHERE id = {$id}", __LINE__, __FILE__);
+                               $this->db->query("UPDATE phpgw_history_log SET 
publish = NULL WHERE history_record_id = {$id}", __LINE__, __FILE__);
+                               if (isset($ticket['publish_note']))
                                {
-                                       $note = explode('_', $publish_info);
-                                       if(!$note[1])
+                                       foreach ($ticket['publish_note'] as 
$publish_info)
                                        {
-                                               $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET publish_note = 1 WHERE id = 
{$note[0]}",__LINE__,__FILE__);
+                                               $note = explode('_', 
$publish_info);
+                                               if (!$note[1])
+                                               {
+                                                       
$this->db->query("UPDATE phpgw_helpdesk_tickets SET publish_note = 1 WHERE id = 
{$note[0]}", __LINE__, __FILE__);
+                                               }
+                                               else
+                                               {
+                                                       
$this->db->query("UPDATE phpgw_history_log SET publish = 1 WHERE history_id = 
{$note[1]}", __LINE__, __FILE__);
+                                               }
                                        }
-                                       else
-                                       {
-                                               $this->db->query("UPDATE 
phpgw_history_log SET publish = 1 WHERE history_id = 
{$note[1]}",__LINE__,__FILE__);
-                                       }
                                }
                        }
 
-                       $finnish_date   = (isset($ticket['finnish_date']) ? 
phpgwapi_datetime::date_to_timestamp($ticket['finnish_date']):'');
+                       if (($old_note != $ticket['note']) && $ticket['note'])
+                       {
+                               $this->fields_updated[] = 'note';
+                               $this->historylog->add('C', $id, 
$ticket['note'], $old_note);
+                               $_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);
+                       }
 
+                       if (isset($this->fields_updated) && 
$this->fields_updated && $simple)
+                       {
+                               $receipt['message'][] = array('msg' => 
lang('Ticket1 has been updated'));
+                               $this->db->transaction_commit();
+                               return $receipt;
+                       }
+
+                       $finnish_date = (isset($ticket['finnish_date']) ? 
phpgwapi_datetime::date_to_timestamp($ticket['finnish_date']) : '');
+
                        if ($oldfinnish_date && isset($ticket['finnish_date']) 
&& $ticket['finnish_date'])
                        {
                                $this->db->query("update phpgw_helpdesk_tickets 
set finnish_date2='" . $finnish_date
-                                       . "' where id='$id'",__LINE__,__FILE__);
+                                       . "' where id='$id'", __LINE__, 
__FILE__);
                        }
-                       else if(!$oldfinnish_date && 
isset($ticket['finnish_date']) && $ticket['finnish_date'])
+                       else if (!$oldfinnish_date && 
isset($ticket['finnish_date']) && $ticket['finnish_date'])
                        {
                                $this->db->query("update phpgw_helpdesk_tickets 
set finnish_date='" . $finnish_date
-                                       . "' where id='$id'",__LINE__,__FILE__);
+                                       . "' where id='$id'", __LINE__, 
__FILE__);
                        }
 
-                       if($oldfinnish_date2>0)
+                       if ($oldfinnish_date2 > 0)
                        {
                                $oldfinnish_date = $oldfinnish_date2;
                        }
-                       if(isset($ticket['finnish_date']) && 
$ticket['finnish_date'])
+                       if (isset($ticket['finnish_date']) && 
$ticket['finnish_date'])
                        {
                                if ($oldfinnish_date != $finnish_date)
                                {
-                                       $this->fields_updated = true;
-                                       
$this->historylog->add('F',$id,$finnish_date,$oldfinnish_date);
+                                       $this->fields_updated[] = 
'finnish_date';
+                                       $this->historylog->add('F', $id, 
$finnish_date, $oldfinnish_date);
                                }
                        }
 
                        if (isset($ticket['status']) && ($old_status != 
$ticket['status']))
                        {
-                               $check_old_custom = (int) trim($old_status,'C');
-                               $this->db->query("SELECT * from 
phpgw_helpdesk_status WHERE id = {$check_old_custom}",__LINE__,__FILE__);
+                               $check_old_custom = (int)trim($old_status, 'C');
+                               $this->db->query("SELECT * from 
phpgw_helpdesk_status WHERE id = {$check_old_custom}", __LINE__, __FILE__);
                                $this->db->next_record();
-                               $this->fields_updated = true;
-                               if($old_status=='X' || $this->db->f('closed'))
+                               $old_closed = $this->db->f('closed');
+                               $this->fields_updated[] = 'status';
+                               if ($old_status == 'X' || $old_closed)
                                {
                                        $new_status = $ticket['status'];
-                                       
$this->historylog->add('R',$id,$ticket['status'],$old_status);
+                                       $this->historylog->add('R', $id, 
$ticket['status'], $old_status);
 
-                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$new_status}' WHERE id= 
{$id}",__LINE__,__FILE__);
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$new_status}' WHERE id= {$id}", __LINE__, 
__FILE__);
                                }
                                else
                                {
-                                       
$this->historylog->add($ticket['status'],$id,$ticket['status'],$old_status);
-                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$ticket['status']}' WHERE 
id={$id}",__LINE__,__FILE__);
+                                       
$this->historylog->add($ticket['status'], $id, $ticket['status'], $old_status);
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET status='{$ticket['status']}' WHERE id={$id}", 
__LINE__, __FILE__);
                                }
                                $this->check_pending_action($ticket, $id);
+
+                               //Close cases at related
+                               $check_new_custom = 
(int)trim($ticket['status'], 'C');
+                               $this->db->query("SELECT closed from 
phpgw_helpdesk_status WHERE id = {$check_new_custom}", __LINE__, __FILE__);
+                               $this->db->next_record();
+
+                               if (($this->db->f('closed') || 
$ticket['status'] == 'X') && ($old_status != 'X' && !$old_closed))
+                               {
+                                       $location_id = 
$GLOBALS['phpgw']->locations->get_id('helpdesk', '.ticket');
+                                       // at controller
+                                       if 
(isset($GLOBALS['phpgw_info']['user']['apps']['controller']))
+                                       {
+                                               $controller = 
CreateObject('controller.uicase');
+                                               
$controller->updateStatusForCases($location_id, $id, 1);
+                                       }
+                                       // at request
+                                       
execMethod('property.sorequest.update_status_from_related', array(
+                                               'location_id' => $location_id,
+                                               'id' => $id,
+                                               'status' => 'closed')
+                                       );
+                               }
                        }
 
-                       if (($oldassigned != $ticket['assignedto']) && 
$ticket['assignedto'] != 'ignore')
+                       if ($ticket['assignedto'] && ( ($oldassigned != 
$ticket['assignedto']) && $ticket['assignedto'] != 'ignore'))
                        {
-                               $this->fields_updated = true;
+                               $this->fields_updated[] = 'assignedto';
 
-                               $value_set=array('assignedto'   => 
$ticket['assignedto']);
-                               $value_set      = 
$this->db->validate_update($value_set);
+                               $value_set = array('assignedto' => 
$ticket['assignedto']);
+                               $value_set = 
$this->db->validate_update($value_set);
 
-                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('A',$id,$ticket['assignedto'],$oldassigned);
+                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'", __LINE__, __FILE__);
+                               $this->historylog->add('A', $id, 
$ticket['assignedto'], $oldassigned);
                        }
 
                        if (($oldgroup_id != $ticket['group_id']) && 
$ticket['group_id'] != 'ignore')
                        {
-                               $this->fields_updated = true;
+                               $this->fields_updated[] = 'group_id';
 
-                               $value_set=array('group_id'     => 
$ticket['group_id']);
-                               $value_set      = 
$this->db->validate_update($value_set);
+                               $value_set = array('group_id' => 
$ticket['group_id']);
+                               $value_set = 
$this->db->validate_update($value_set);
 
-                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('G',$id,$ticket['group_id'],$oldgroup_id);
+                               $this->db->query("update phpgw_helpdesk_tickets 
set $value_set where id='$id'", __LINE__, __FILE__);
+                               $this->historylog->add('G', $id, 
$ticket['group_id'], $oldgroup_id);
                        }
 
                        if ($oldpriority != $ticket['priority'])
                        {
-                               $this->fields_updated = true;
+                               $this->fields_updated[] = 'priority';
                                $this->db->query("update phpgw_helpdesk_tickets 
set priority='" . $ticket['priority']
-                                       . "' where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('P',$id,$ticket['priority'],$oldpriority);
+                                       . "' where id='$id'", __LINE__, 
__FILE__);
+                               $this->historylog->add('P', $id, 
$ticket['priority'], $oldpriority);
                        }
 
                        if ($old_contact_id != $ticket['contact_id'])
                        {
-                               $contact_id  = (int) $ticket['contact_id'];
-                               $this->fields_updated = true;
-                               $this->db->query("update phpgw_helpdesk_tickets 
set contact_id={$contact_id} WHERE id=$id",__LINE__,__FILE__);
+                               $contact_id = (int)$ticket['contact_id'];
+                               $this->fields_updated[] = 'contact_id';
+                               $this->db->query("update phpgw_helpdesk_tickets 
set contact_id={$contact_id} WHERE id=$id", __LINE__, __FILE__);
                        }
 
-                       if (($oldcat_id != $ticket['cat_id']) && 
$ticket['cat_id'] != 'ignore')
+                       if ($ticket['cat_id'] && ( ($oldcat_id != 
$ticket['cat_id']) && $ticket['cat_id'] != 'ignore'))
                        {
-                               $this->fields_updated = true;
+                               $this->fields_updated[] = 'cat_id';
                                $this->db->query("update phpgw_helpdesk_tickets 
set cat_id='" . $ticket['cat_id']
-                                       . "' where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('T',$id,$ticket['cat_id'],$oldcat_id);
+                                       . "' where id='$id'", __LINE__, 
__FILE__);
+                               $this->historylog->add('T', $id, 
$ticket['cat_id'], $oldcat_id);
                        }
 
-                       if ($old_budget != $ticket['budget'])
-                       {
-                               $this->fields_updated = true;
-                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
set budget='" . (int)$ticket['budget']
-                                       . "' where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('B',$id,$ticket['budget'],$old_budget);
-                       }
-       /*
-                       if ($old_billable_rate != $ticket['billable_rate'])
-                       {
-                               $this->fields_updated = true;
-                               $this->db->query("update phpgw_helpdesk_tickets 
set billable_rate='" . $ticket['billable_rate']
-                                       . "' where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('B',$id,$ticket['billable_rate'],$old_billable_rate);
-                       }
-        */
+                       /*
+                         if ($old_billable_rate != $ticket['billable_rate'])
+                         {
+                         $this->fields_updated[] = 'billable_rate';
+                         $this->db->query("update phpgw_helpdesk_tickets set 
billable_rate='" . $ticket['billable_rate']
+                         . "' where id='$id'",__LINE__,__FILE__);
+                         
$this->historylog->add('B',$id,$ticket['billable_rate'],$old_billable_rate);
+                         }
+                        */
                        if ($old_subject != $ticket['subject'])
                        {
                                $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET subject='" . $ticket['subject']
-                                       . "' where id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('S',$id,$ticket['subject'],$old_subject);
-                               $receipt['message'][]= array('msg' => 
lang('Subject has been updated'));
+                                       . "' where id='$id'", __LINE__, 
__FILE__);
+                               $this->historylog->add('S', $id, 
$ticket['subject'], $old_subject);
+                               $receipt['message'][] = array('msg' => 
lang('Subject has been updated'));
                        }
 
-                       if($ticket['billable_hours'])
+                       if ($ticket['billable_hours'])
                        {
-                               $ticket['billable_hours'] = 
str_replace(',','.', $ticket['billable_hours']);
-                       }
-                       if ((float)$old_billable_hours != 
(float)$ticket['billable_hours'])
-                       {
+                               $ticket['billable_hours'] = 
(float)str_replace(',', '.', $ticket['billable_hours']);
+                               $ticket['billable_hours'] += 
(float)$old_billable_hours;
+//                     }
+//                     if ((float)$old_billable_hours != 
$ticket['billable_hours'])
+//                     {
                                $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET billable_hours='{$ticket['billable_hours']}'"
-                                       . " WHERE 
id='{$id}'",__LINE__,__FILE__);
-                               
$this->historylog->add('H',$id,$ticket['billable_hours'],$old_billable_hours);
-                               $receipt['message'][]= array('msg' => 
lang('billable hours has been updated'));
+                                       . " WHERE id='{$id}'", __LINE__, 
__FILE__);
+                               $this->historylog->add('H', $id, 
$ticket['billable_hours'], $old_billable_hours);
+                               $receipt['message'][] = array('msg' => 
lang('billable hours has been updated'));
                        }
 
-                       if ((int)$old_actual_cost != 
(int)$ticket['actual_cost'])
+                       if (isset($ticket['location']) && $ticket['location'])
                        {
-                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET actual_cost='" . (float)$ticket['actual_cost']
-                                       . "' WHERE id='$id'",__LINE__,__FILE__);
-                               
$this->historylog->add('AC',$id,(float)$ticket['actual_cost'] , 
$old_actual_cost);
-                               $receipt['message'][]= array('msg' => 
lang('actual_cost has been updated'));
-                       }
-
-                       if ((int)$old_order_cat_id != 
(int)$ticket['order_cat_id'])
-                       {
-                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET order_cat_id='" . (int)$ticket['order_cat_id']
-                                       . "' WHERE id='$id'",__LINE__,__FILE__);
-                               $receipt['message'][]= array('msg' => 
lang('order category has been updated'));
-                               $this->fields_updated = true;
-                       }
-
-                       if ((int)$old_order_dim1 != (int)$ticket['order_dim1'])
-                       {
-                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET order_dim1='" . (int)$ticket['order_dim1']
-                                       . "' WHERE id='$id'",__LINE__,__FILE__);
-                               $receipt['message'][]= array('msg' => 
lang('order_dim1 has been updated'));
-                               $this->fields_updated = true;
-                       }
-
-                       if ($old_building_part != $ticket['building_part'])
-                       {
-                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET building_part='" . $ticket['building_part']
-                                       . "' WHERE id='$id'",__LINE__,__FILE__);
-                               $receipt['message'][]= array('msg' => 
lang('building part has been updated'));
-                               $this->fields_updated = true;
-                       }
-
-                       if (($old_note != $ticket['note']) && $ticket['note'])
-                       {
-                               $this->fields_updated = true;
-                               
$this->historylog->add('C',$id,$ticket['note'],$old_note);
-                               $_history_id = 
$this->db->get_last_insert_id('phpgw_helpdesk_history','history_id');
-                               $this->db->query("UPDATE phpgw_helpdesk_history 
SET publish = 1 WHERE history_id = $_history_id",__LINE__,__FILE__);
-                               unset($_history_id);
-                       }
-
-                       if(isset($ticket['location']) && $ticket['location'])
-                       {
                                $ticket['location_code'] = implode('-', 
$ticket['location']);
                        }
 
                        if (isset($ticket['location_code']) && 
$ticket['location_code'] && ($oldlocation_code != $ticket['location_code']))
                        {
-                               $interlink      = 
CreateObject('helpdesk.interlink');
-                               if( $interlink->get_relation('helpdesk', 
'.ticket', $id, 'origin') || $interlink->get_relation('helpdesk', '.ticket', 
$id, 'target'))
+                               $interlink = CreateObject('property.interlink');
+                               if ($interlink->get_relation('helpdesk', 
'.ticket', $id, 'origin') || $interlink->get_relation('helpdesk', '.ticket', 
$id, 'target'))
                                {
-                                       $receipt['message'][]= array('msg' => 
lang('location could not be changed'));
+                                       $receipt['message'][] = array('msg' => 
lang('location could not be changed'));
                                }
                                else
                                {
-                                       $value_set      = array();
+                                       $value_set = array();
 
-                                       if(isset($ticket['street_name']) && 
$ticket['street_name'])
+                                       $_address = array();
+                                       if (isset($ticket['street_name']) && 
$ticket['street_name'])
                                        {
-                                               $address[]= 
$ticket['street_name'];
-                                               $address[]= 
$ticket['street_number'];
-                                               $value_set['address'] = 
$this->db->db_addslashes(implode(" ", $address));
+                                               $_address[] = 
"{$ticket['street_name']} {$ticket['street_number']}";
                                        }
 
-                                       if(!isset($address) || !$address)
+                                       if (isset($ticket['location_name']) && 
$ticket['location_name'])
                                        {
-                                               $address = 
isset($ticket['location_name']) ? 
$this->db->db_addslashes($ticket['location_name']) : '';
-                                               if($address)
+                                               $_address[] = 
$ticket['location_name'];
+                                       }
+
+                                       if (isset($ticket['additional_info']) 
&& $ticket['additional_info'])
+                                       {
+                                               foreach 
($ticket['additional_info'] as $key => $value)
                                                {
-                                                       $value_set['address'] = 
$address;
+                                                       if ($value)
+                                                       {
+                                                               $_address[] = 
"{$key}|{$value}";
+                                                       }
                                                }
                                        }
 
+
+                                       if (isset($ticket['extra']['p_num']) && 
$ticket['extra']['p_num'] && $ticket['extra']['p_entity_id'] && 
$ticket['extra']['p_cat_id'])
+                                       {
+                                               $entity = 
CreateObject('property.soadmin_entity');
+                                               $entity_category = 
$entity->read_single_category($ticket['extra']['p_entity_id'], 
$ticket['extra']['p_cat_id']);
+                                       }
+
+                                       if (isset($entity_category) && 
$entity_category)
+                                       {
+                                               $_address[] = 
"{$entity_category['name']}::{$ticket['extra']['p_num']}";
+                                       }
+
+                                       $address = 
$this->db->db_addslashes(implode('::', $_address));
+
+                                       unset($_address);
+
+                                       $value_set['address'] = $address;
+
                                        if (isset($ticket['location_code']) && 
$ticket['location_code'])
                                        {
                                                $value_set['location_code'] = 
$ticket['location_code'];
                                        }
 
-                                       $admin_location = 
CreateObject('helpdesk.soadmin_location');
+                                       $admin_location = 
CreateObject('property.soadmin_location');
                                        $admin_location->read(false);
 
                                        // Delete old values for location - in 
case of moving up in the hierarchy
                                        $metadata = 
$this->db->metadata('phpgw_helpdesk_tickets');
-                                       for ($i = 1;$i < 
$admin_location->total_records + 1; $i++)
+                                       for ($i = 1; $i < 
$admin_location->total_records + 1; $i++)
                                        {
-                                               if(isset($metadata["loc{$i}"]))
+                                               if (isset($metadata["loc{$i}"]))
                                                {
-                                                       $value_set["loc{$i}"]   
= false;
+                                                       $value_set["loc{$i}"] = 
false;
                                                }
                                        }
 
-                                       if(isset($ticket['location']) && 
is_array($ticket['location']))
+                                       if (isset($ticket['location']) && 
is_array($ticket['location']))
                                        {
                                                foreach ($ticket['location'] as 
$column => $value)
                                                {
-                                                       $value_set[$column]     
= $value;
+                                                       $value_set[$column] = 
$value;
                                                }
                                        }
 
-                                       if(isset($ticket['extra']) && 
is_array($ticket['extra']))
-                                       {
-                                               foreach ($ticket['extra'] as 
$column => $value)
-                                               {
-                                                       $value_set[$column]     
= $value;
-                                               }
-                                       }
 
-                                       $value_set      = 
$this->db->validate_update($value_set);
+                                       $value_set = 
$this->db->validate_update($value_set);
 
-                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET $value_set WHERE id={$id}",__LINE__,__FILE__);
+                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET $value_set WHERE id={$id}", __LINE__, __FILE__);
 
-                                       
$this->historylog->add('L',$id,$ticket['location_code'],$oldlocation_code);
-                                       $receipt['message'][]= array('msg' => 
lang('Location has been updated'));
+                                       $this->historylog->add('L', $id, 
$ticket['location_code'], $oldlocation_code);
+                                       $receipt['message'][] = array('msg' => 
lang('Location has been updated'));
                                }
                                unset($interlink);
                        }
 
+                       $value_set = array();
 
-                       if(isset($ticket['make_order']) && 
$ticket['make_order'])
+                       $data_attribute = 
$this->custom->prepare_for_db('phpgw_helpdesk_tickets', $values_attribute);
+
+                       if (isset($data_attribute['value_set']))
                        {
-                               $order_id = 
execMethod('property.socommon.increment_id', 'helpdesk');
-                               if($order_id)
+                               foreach ($data_attribute['value_set'] as 
$input_name => $value)
                                {
-                                       $this->db->query("UPDATE 
phpgw_helpdesk_tickets SET order_id = {$order_id} WHERE 
id={$id}",__LINE__,__FILE__);
-                                       $this->db->query("INSERT INTO fm_orders 
(id, type) VALUES ({$order_id}, 'helpdesk')",__LINE__,__FILE__);
+                                       $value_set[$input_name] = $value;
                                }
                        }
 
-                       $value_set                                      = 
array();
-                       $value_set['vendor_id']         = $ticket['vendor_id'];
-                       $value_set['b_account_id']      = 
$ticket['b_account_id'];
-                       $value_set['order_descr']       = 
$this->db->db_addslashes($ticket['order_descr']);
-                       $value_set['ecodimb']           = $ticket['ecodimb'];
-                       $value_set['budget']            = $ticket['budget'];
-                       $value_set                                      = 
$this->db->validate_update($value_set);
-                       $this->db->query("UPDATE phpgw_helpdesk_tickets SET 
$value_set WHERE id={$id}",__LINE__,__FILE__);
+                       $value_set['modified_date'] = time();
 
-                       $this->db->transaction_commit();
+                       $value_set = $this->db->validate_update($value_set);
+                       $this->db->query("UPDATE phpgw_helpdesk_tickets SET 
$value_set WHERE id={$id}", __LINE__, __FILE__);
 
-                       if (isset($this->fields_updated))
+                       $value_set = array();
+
+                       if (isset($ticket['extra']) && 
is_array($ticket['extra']) && $ticket['extra'])
                        {
-                               $receipt['message'][]= array('msg' => 
lang('Ticket has been updated'));
+                               foreach ($ticket['extra'] as $column => $value)
+                               {
+                                       $value_set[$column] = $value;
+                               }
 
-                               $criteria = array
-                                       (
-                                               'appname'       => 'helpdesk',
-                                               'location'      => 
$this->acl_location,
-                                               'allrows'       => true
-                                       );
+                               $value_set = 
$this->db->validate_update($value_set);
 
-                               $custom_functions = 
$GLOBALS['phpgw']->custom_functions->find($criteria);
+                               $this->db->query("UPDATE phpgw_helpdesk_tickets 
SET $value_set WHERE id={$id}", __LINE__, __FILE__);
+                       }
 
-                               foreach ( $custom_functions as $entry )
-                               {
-                                       // prevent path traversal
-                                       if ( preg_match('/\.\./', 
$entry['file_name']) )
-                                       {
-                                               continue;
-                                       }
+                       $this->db->transaction_commit();
 
-                                       $file = PHPGW_SERVER_ROOT . 
"/helpdesk/inc/custom/{$GLOBALS['phpgw_info']['user']['domain']}/{$entry['file_name']}";
-                                       if ( $entry['active'] && is_file($file) 
)
-                                       {
-                                               require_once $file;
-                                       }
-                               }
+                       if (isset($this->fields_updated) && 
$this->fields_updated)
+                       {
+                               $receipt['message'][] = array('msg' => 
lang('Ticket has been updated'));
                        }
                        return $receipt;
                }
@@ -1183,7 +1181,7 @@
                        $this->db->query("DELETE FROM fm_action_pending WHERE 
location_id = {$location_id} AND item_id = {$id}",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM phpgw_interlink WHERE 
location1_id = {$location_id} AND location1_item_id = {$id}",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM phpgw_interlink WHERE 
location2_id = {$location_id} AND location2_item_id = {$id}",__LINE__,__FILE__);
-                       $this->db->query("DELETE FROM phpgw_helpdesk_history 
WHERE history_record_id = {$id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM phpgw_history_log WHERE 
history_record_id = {$id}",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM phpgw_helpdesk_views 
WHERE id = {$id}",__LINE__,__FILE__);
                        $this->db->query("DELETE FROM phpgw_helpdesk_tickets 
WHERE id = {$id}",__LINE__,__FILE__);
 
@@ -1196,4 +1194,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: branches/dev-syncromind-2/helpdesk/inc/class.uitts.inc.php
===================================================================
--- branches/dev-syncromind-2/helpdesk/inc/class.uitts.inc.php  2016-08-01 
13:24:09 UTC (rev 15398)
+++ branches/dev-syncromind-2/helpdesk/inc/class.uitts.inc.php  2016-08-01 
13:31:53 UTC (rev 15399)
@@ -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
                        (
@@ -45,9 +45,12 @@
                                'download'                      => true,
                                'view_file'                     => true,
                                'edit_status'           => true,
+                               'edit_priority' => true,
                                'get_vendor_email'      => true,
                                '_print'                        => true,
-                               'columns'                       => true
+                               'columns'                       => true,
+                               'update_data'           => true,
+                               'upload_clip'           => true
                        );
 
                /**
@@ -63,6 +66,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 +78,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 +128,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()
@@ -288,6 +358,28 @@
                        return "id ".$id." ".lang('Status has been changed');
                }
 
+               function edit_priority()
+               {
+                       if (!$this->acl_edit)
+                       {
+                               return lang('sorry - insufficient rights');
+                       }
+
+                       $new_priority = phpgw::get_var('new_priority', 'int');
+                       $id = phpgw::get_var('id', 'int');
+
+//                     $ticket = $this->bo->read_single($id);
+
+                       $receipt = $this->bo->update_priority(array('priority' 
=> $new_priority), $id);
+                       if 
((isset($this->bo->config->config_data['mailnotification']) && 
$this->bo->config->config_data['mailnotification']) || 
(isset($GLOBALS['phpgw_info']['user']['preferences']['property']['tts_notify_me'])
 && $GLOBALS['phpgw_info']['user']['preferences']['property']['tts_notify_me'] 
== 1 && $this->bo->fields_updated
+                               )
+                       )
+                       {
+                               $receipt = $this->bo->mail_ticket($id, 
$this->bo->fields_updated, $receipt);
+                       }
+                       return "id {$id} " . lang('priority has been changed');
+               }
+
                function delete()
                {
                        if(!$this->acl_delete)
@@ -351,1970 +443,1472 @@
                }
 
 
-               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('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
+                       foreach ($jasper as $report)
+                       {
+                               $data['datatable']['actions'][] = array
+                                       (
+                                       'my_name' => 'edit',
+                                       'text' => lang('open JasperReport %1 in 
new window', $report['title']),
+                                       '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'    
=> 'property.uijasper.view',
-                                                               'jasper_id'     
                => $report['id'],
-                                                               'target'        
        => '_blank'
-                                                       )),
-                                                       'parameters'            
        => $parameters
-                                               );
-                               }
+                                               'menuaction' => 
'helpdesk.uijasper.view',
+                                               'jasper_id' => $report['id'],
+                                               'target' => '_blank'
+                                       )),
+                                       'parameters' => json_encode($parameters)
+                               );
                        }
-                       if($this->acl_delete)
+
+                       if ($this->acl_delete)
                        {
-                               $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' => 'delete',
+                                       'statustext' => lang('delete the 
ticket'),
+                                       'text' => lang('delete'),
+                                       'confirm_msg' => lang('do you really 
want to delete this ticket'),
+                                       'action' => 
$GLOBALS['phpgw']->link('/index.php', array
                                                (
-                                                       'menuaction'    => 
'helpdesk.uitts.delete'
-                                               )),
-                                               'parameters'    => $parameters
-                                       );
+                                               'menuaction' => 
'helpdesk.uitts.delete'
+                                       )),
+                                       '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 
(isset($GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'])
 && 
$GLOBALS['phpgw_info']['user']['preferences']['helpdesk']['tts_status_link'] == 
'yes' && $this->acl_edit)
                        {
+                               $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'),
+                               );
 
-                               unset($status['C']);
-                               foreach ($status as $status_code => 
$status_info)
+                               $custom_status = $this->bo->get_custom_status();
+
+                               foreach ($custom_status as $custom)
                                {
-                                       $datatable['rowactions']['action'][] = 
array
+                                       $status["C{$custom['id']}"] = 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
-                                               );
+                                               'status' => $custom['name'],
+                                       );
                                }
-                       }
 
-                       if($this->acl_add)
-                       {
-                               $datatable['rowactions']['action'][] = array
-                                       (
-                                               'my_name'                       
=> 'add',
-                                               'statustext'    => lang('Add 
new ticket'),
-                                               'text'                  => 
lang('add'),
-                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                               foreach ($status as $status_code => 
$status_info)
+                               {
+                                       $data['datatable']['actions'][] = array
                                                (
-                                                       'menuaction'    => 
'helpdesk.uitts.add'
-                                               ))
+                                               '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)
                                        );
-                       }
+                               }
 
-                       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')
+                               $_priorities = $this->bo->get_priority_list();
+
+                               foreach ($_priorities as $_priority_info)
                                {
-                                       
$datatable['headers']['header'][$i]['sortable']         = true;
-                                       
$datatable['headers']['header'][$i]['sort_field']   = $uicols['name'][$i];
+                                       $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)
+                                       );
                                }
-                               if($uicols['name'][$i]=='text_view' || 
$uicols['name'][$i]=='bgcolor' || $uicols['name'][$i]=='child_date' || 
$uicols['name'][$i]== 'link_view' || 
$uicols['name'][$i]=='lang_view_statustext')
-                               {
-                                       
$datatable['headers']['header'][$i]['visible']          = false;
-                                       
$datatable['headers']['header'][$i]['format']           = 'hidden';
-                               }
                        }
-                       }
 
-                       //path for helpdesk.js
-                       $datatable['property_js'] = 
$GLOBALS['phpgw_info']['server']['webserver_url']."/property/js/yahoo/property.js";
-
-                       // Pagination and sort values
-                       $datatable['pagination']['records_start']       = 
(int)$this->bo->start;
-                       $datatable['pagination']['records_limit']       = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-                       if($dry_run)
+                       if (count($data['datatable']['actions']) < 10)
                        {
-                               $datatable['pagination']['records_returned'] = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];           
         
+                               $data['datatable']['group_buttons'] = false;
                        }
-                       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
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('helpdesk') . ': ' . $function_msg;
 
-                       $appname                                                
= lang('helpdesk');
-                       $function_msg                                   = 
lang('list ticket');
+                       self::render_template_xsl('datatable_jquery', $data);
+               }
 
-                       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
-                       }
+               function upload_clip()
+               {
+                       $id = phpgw::get_var('id', 'POST', 'int');
+                       $ret = array(
+                               'status' => 'error',
+                               'message'=> lang('No data')
+                       );
 
-                       //-- 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']))
+                       if($_POST['pasted_image'])
                        {
-                               foreach( $datatable['rows']['row'] as $row )
+                               $_ticket = $this->bo->read_single($id);
+                               $bofiles = 
CreateObject('property.bofiles','/helpdesk');
+                               $img = $_POST['pasted_image'];
+                               $img = str_replace('data:image/png;base64,', 
'', $img);
+                               $img = str_replace(' ', '+', $img);
+                               $data = base64_decode($img);
+                               $file = '/tmp/' . uniqid() . '.png';
+                               if (file_put_contents($file, $data))
                                {
-                                       $json_row = array();
-                                       foreach( $row['column'] as $column)
+                                       $to_file = 
"{$bofiles->fakebase}/{$id}/" .  str_replace(' ', '_', $_ticket['subject']) . 
'_' . ( (int)count($_ticket['files']) +1 ) . '.png';
+                                       $bofiles->create_document_dir("{$id}");
+                                       $bofiles->vfs->override_acl = 1;
+
+                                       $ret = array(
+                                               'status' => 'ok',
+                                               'message'=> 'Ok'
+                                       );
+                                       if (!$bofiles->vfs->cp(array(
+                                                       'from' => $file,
+                                                       'to' => $to_file,
+                                                       'relatives' => 
array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))))
                                        {
-                                               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'];
-                                               }
+                                               $ret = array(
+                                                       'status' => 'error',
+                                                       'message'=> 
lang('Failed to upload file !')
+                                               );
 
-                                               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;
+                                       $bofiles->vfs->override_acl = 0;
                                }
                        }
-
-                       // values for control select
-                       $opt_cb_depend =  
$this->bocommon->select_part_of_town('filter_',$this->part_of_town_id,$this->district_id);
-                       $default_value = array ('id'=>'','name'=>'!no part of 
town');
-                       array_unshift ($opt_cb_depend,$default_value);
-                       $json['hidden']['dependent'][] = array ( 'id' => 
$this->part_of_town_id,
-                               'value' => 
$this->bocommon->select2String($opt_cb_depend)
-                       );
-                       // right in datatable
-                       if(isset($datatable['rowactions']['action']) && 
is_array($datatable['rowactions']['action']))
-                       {
-                               $json ['rights'] = 
$datatable['rowactions']['action'];
-                       }
-
-                       if( phpgw::get_var('phpgw_return_as') == 'json' )
-                       {
-                               return $json;
-                       }
-
-
-                       $datatable['json_data'] = json_encode($json);
-                       //-------------------- JSON CODE ----------------------
-
-                       // Prepare template variables and process XSLT
-                       $template_vars = array();
-                       $template_vars['datatable'] = $datatable;
-                       
$GLOBALS['phpgw']->xslttpl->add_file(array('datatable'));
-                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
$template_vars);
-
-                       if ( !isset($GLOBALS['phpgw']->css) || 
!is_object($GLOBALS['phpgw']->css) )
-                       {
-                               $GLOBALS['phpgw']->css = 
createObject('phpgwapi.css');
-                       }
-
-                       phpgwapi_yui::load_widget('dragdrop');
-                       phpgwapi_yui::load_widget('datatable');
-                       phpgwapi_yui::load_widget('menu');
-                       phpgwapi_yui::load_widget('connection');
-                       phpgwapi_yui::load_widget('loader');
-                       phpgwapi_yui::load_widget('paginator');
-
-                       // Prepare CSS Style
-                       $GLOBALS['phpgw']->css->validate_file('datatable');
-                       $GLOBALS['phpgw']->css->validate_file('helpdesk');
-                       
$GLOBALS['phpgw']->css->add_external_file('helpdesk/templates/base/css/helpdesk.css');
-                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/datatable/assets/skins/sam/datatable.css');
-                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/paginator/assets/skins/sam/paginator.css');
-                       
$GLOBALS['phpgw']->css->add_external_file('phpgwapi/js/yahoo/container/assets/skins/sam/container.css');
-
-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('helpdesk') . ' - ' . $appname . ': ' . $function_msg;
-
-                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'tts.index' , 'helpdesk' );
+                       return $ret;
                }
 
-
                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'])
+                                       $bofiles = 
CreateObject('property.bofiles','/helpdesk');
+                                       if ($values['file_name'] && 
$receipt['id'])
                                        {
-                                               $bofiles        = 
CreateObject('property.bofiles','/helpdesk');
-                                               $to_file = $bofiles->fakebase . 
"/{$receipt['id']}/{$values['file_name']}";
+                                               $to_file = 
"{$bofiles->fakebase}/{$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("{$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;
                                                }
                                        }
+
+                                       if($_POST['pasted_image'])
+                                       {
+                                               $img = $_POST['pasted_image'];
+                                               $img = 
str_replace('data:image/png;base64,', '', $img);
+                                               $img = str_replace(' ', '+', 
$img);
+                                               $data = base64_decode($img);
+                                               $file = '/tmp/' . uniqid() . 
'.png';
+                                               if (file_put_contents($file, 
$data))
+                                               {
+                                                       $to_file = 
"{$bofiles->fakebase}/{$receipt['id']}/" .  str_replace(' ', '_', 
$values['subject']) . '.png';
+                                                       
$bofiles->create_document_dir("{$receipt['id']}");
+                                                       
$bofiles->vfs->override_acl = 1;
+
+                                                       if 
(!$bofiles->vfs->cp(array(
+                                                                       'from' 
=> $file,
+                                                                       'to' => 
$to_file,
+                                                                       
'relatives' => array(RELATIVE_NONE | VFS_REAL, RELATIVE_ALL))))
+                                                       {
+                                                               
$receipt['error'][] = array('msg' => lang('Failed to upload file !'));
+                                                       }
+                                                       
$bofiles->vfs->override_acl = 0;
+                                               }
+                                       }
+
                                        //--------------end files
-                                       
$GLOBALS['phpgw']->session->appsession('receipt','helpdesk',$receipt);
-                                       
$GLOBALS['phpgw']->session->appsession('session_data','fm_tts','');
+                                       
$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_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' => 
true,//(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']:'')),
+                       //_debug_array($data);
+                       $function_msg = lang('add ticket');
 
-                                       'status_list'                           
        => $this->bo->get_status_list('O'),
+                       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') . ': ' . $function_msg;
+                       $GLOBALS['phpgw']->xslttpl->add_file(array('tts', 
'files', 'attributes_form'));
+                       $GLOBALS['phpgw']->xslttpl->set_var('phpgw', 
array('add' => $data));
+               }
 
-                                       'form_action'                           
        => $GLOBALS['phpgw']->link('/index.php',$link_data),
+               function update_data()
+               {
+                       $action = phpgw::get_var('action', 'string', 'GET');
+                       switch ($action)
+                       {
+                               case 'get_vendor':
+                                       return 
$this->bocommon->get_vendor_email();
+                                       break;
+                               case 'get_files':
+                                       return $this->get_files();
+                                       break;
+                               default:
+                       }
+               }
 
-                                       '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']:''),
+               function get_files()
+               {
+                       $id = phpgw::get_var('id', 'int');
 
-                                       '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'),
+                       if (!$this->acl_read)
+                       {
+                               return;
+                       }
 
-                                       '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']:''),
-                               );
+                       $link_file_data = array
+                               (

@@ Diff output truncated at 153600 characters. @@



reply via email to

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