phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/class.botts.php, 1.1.1.3


From: nomail
Subject: [Phpgroupware-cvs] property/class.botts.php, 1.1.1.3
Date: Fri, 21 May 2004 16:25:09 -0000

Update of /property
Modified Files:
        Branch: 
          class.botts.php

date: 2004/04/23 21:26:33;  author: sigurdne;  state: Exp;  lines: +778 -778

Log Message:
no message
=====================================================================
Index: property/class.botts.php
diff -u property/class.botts.php:1.1.1.2 property/class.botts.php:1.1.1.3
--- property/class.botts.php:1.1.1.2    Fri Apr 23 20:25:29 2004
+++ property/class.botts.php    Fri Apr 23 21:26:33 2004
@@ -1,778 +1,778 @@
-<?php
-       
/**************************************************************************\
-       * phpGroupWare - property                                               
   *
-       * http://www.phpgroupware.org                                           
   *
-       *                                                                       
   *
-       * Facilities Management                                                 
   *
-       * Written by Sigurd Nes [sigurdne at online.no]                         
   *
-       * 
------------------------------------------------------------------------ *
-       * Copyright 2000 - 2003 Free Software Foundation, Inc                   
   *
-       * This program is part of the GNU project, see http://www.gnu.org/      
   *
-       * 
------------------------------------------------------------------------ *
-       * This program is free software; you can redistribute it and/or modify 
it  *
-       * under the terms of the GNU General Public License as published by the 
   *
-       * Free Software Foundation; either version 2 of the License, or (at 
your   *
-       * option) any later version.                                            
   *
-       
\**************************************************************************/
-
-       class property_botts
-       {
-               var $start;
-               var $query;
-               var $filter;
-               var $sort;
-               var $order;
-               var $cat_id;
-
-               var $public_functions = array
-               (
-                       'read'                          => True,
-                       'read_single'           => True,
-                       'save'                          => True,
-                       'delete'                        => True,
-                       'check_perms'           => True
-               );
-
-               var $soap_functions = array(
-                       'list' => array(
-                               'in'  => 
array('int','int','struct','string','int'),
-                               'out' => array('array')
-                       ),
-                       'read' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array('array')
-                       ),
-                       'save' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       ),
-                       'delete' => array(
-                               'in'  => array('int','struct'),
-                               'out' => array()
-                       )
-               );
-
-               function property_botts($session=False)
-               {
-                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->so                       = 
CreateObject($this->currentapp.'_sotts');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','tts');
-                       $this->config           = 
CreateObject('phpgwapi_config');
-                       $this->dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
-
-                       if ($session)
-                       {
-                               $this->read_sessiondata();
-                               $this->use_session = True;
-                       }
-
-                       $start  = get_var('start',array('POST','GET'));
-                       $query  = get_var('query',array('POST','GET'));
-                       $sort   = get_var('sort',array('POST','GET'));
-                       $order  = get_var('order',array('POST','GET'));
-                       $filter = get_var('filter',array('POST','GET'));
-                       $cat_id = get_var('cat_id',array('POST','GET'));
-                       $district_id    = 
get_var('district_id',array('POST','GET'));
-                       $allrows        = 
get_var('allrows',array('POST','GET'));
-
-                       if ($start)
-                       {
-                               $this->start=$start;
-                       }
-                       else
-                       {
-                               $this->start=0;
-                       }
-
-                       if(isset($query))
-                       {
-                               $this->query = $query;
-                       }
-                       if(isset($filter))
-                       {
-                               $this->filter = $filter;
-                       }
-                       if(isset($sort))
-                       {
-                               $this->sort = $sort;
-                       }
-                       if(isset($order))
-                       {
-                               $this->order = $order;
-                       }
-                       if(isset($cat_id))
-                       {
-                               $this->cat_id = $cat_id;
-                       }
-                       if(isset($district_id))
-                       {
-                               $this->district_id = $district_id;
-                       }
-                       if(isset($allrows))
-                       {
-                               $this->allrows = $allrows;
-                       }
-               }
-
-
-               function save_sessiondata($data)
-               {
-                       if ($this->use_session)
-                       {
-                               
$this->fm_session->appsession('session_data','tts',$data);
-                       }
-               }
-
-               function read_sessiondata()
-               {
-                       $data = 
$this->fm_session->appsession('session_data','tts');
-
-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->sort             = $data['sort'];
-                       $this->order    = $data['order'];
-                       $this->cat_id   = $data['cat_id'];
-                       $this->district_id      = $data['district_id'];
-                       $this->allrows  = $data['allrows'];
-               }
-
-               function filter($data=0)
-               {
-                       if(is_array($data))
-                       {
-                               $format = 
(isset($data['format'])?$data['format']:'');
-                               $selected = 
(isset($data['filter'])?$data['filter']:$data['default']);
-                       }
-
-                       $this->bocommon->xsl_add_file(array('filter_filter'));
-
-                       $filters[0][id]='closed';
-                       $filters[0][name]=lang('Closed');
-                       $filters[1][id]='all';
-                       $filters[1][name]=lang('All');
-
-                       while (is_array($filters) && list(,$filter) = 
each($filters))
-                       {
-                               $sel_filter = '';
-                               if ($filter['id']==$selected)
-                               {
-                                       $sel_filter = 'selected';
-                               }
-
-                               $filter_list[] = array
-                               (
-                                       'id'    => $filter['id'],
-                                       'name'          => $filter['name'],
-                                       'selected'      => $sel_filter
-                               );
-                       }
-
-                       for ($i=0;$i<count($filter_list);$i++)
-                       {
-                               if ($filter_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($filter_list[$i]['selected']);
-                               }
-                       }
-
-                       return $filter_list;
-               }
-
-               function get_status_list($selected)
-               {
-
-                       $filters[0][id]='X';
-                       $filters[0][name]=lang('Closed');
-                       $filters[1][id]='O';
-                       $filters[1][name]=lang('Open');
-
-                       while (is_array($filters) && list(,$filter) = 
each($filters))
-                       {
-                               $sel_filter = '';
-                               if ($filter['id']==$selected)
-                               {
-                                       $sel_filter = 'selected';
-                               }
-
-                               $filter_list[] = array
-                               (
-                                       'id'    => $filter['id'],
-                                       'name'          => $filter['name'],
-                                       'selected'      => $sel_filter
-                               );
-                       }
-
-                       for ($i=0;$i<count($filter_list);$i++)
-                       {
-                               if ($filter_list[$i]['selected'] != 'selected')
-                               {
-                                       unset($filter_list[$i]['selected']);
-                               }
-                       }
-
-                       return $filter_list;
-               }
-
-
-               function get_priority_list($selected='')
-               {
-
-                       if(!$selected)
-                       {
-                               $selected = 
$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['prioritydefault'];
-                       }
-
-                       $priority_comment[1]=' - '.lang('Lowest');
-                       $priority_comment[5]=' - '.lang('Medium');
-                       $priority_comment[10]=' - '.lang('Highest');
-
-                       for ($i=1; $i<=10; $i++)
-                       {
-                               $priorities[$i]['id'] =$i;
-                               $priorities[$i]['name'] =$i . 
$priority_comment[$i];
-                       }
-
-                       while (is_array($priorities) && list(,$priority) = 
each($priorities))
-                       {
-                               $sel_priority = '';
-                               if ($priority['id']==$selected)
-                               {
-                                       $sel_priority = 'selected';
-                               }
-
-                               $priority_list[] = array
-                               (
-                                       'id'    => $priority['id'],
-                                       'name'          => $priority['name'],
-                                       'selected'      => $sel_priority
-                               );
-                       }
-
-                       for ($i=0;$i<count($priority_list);$i++)
-                       {
-                               if ($priority_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($priority_list[$i]['selected']);
-                               }
-                       }
-
-//html_print_r($priority_list);
-                       return $priority_list;
-               }
-
-               function get_category_name($cat_id)
-               {
-                       return $this->so->get_category_name($cat_id);
-               }
-
-               function select_category_list($format='',$selected='')
-               {
-
-                       switch($format)
-                       {
-                               case 'select':
-                                       
$this->bocommon->xsl_add_file(array('cat_select'));
-                                       break;
-                               case 'filter':
-                                       
$this->bocommon->xsl_add_file(array('cat_filter'));
-                                       break;
-                       }
-
-                       $categories= $this->so->select_category_list();
-
-                       while (is_array($categories) && list(,$category) = 
each($categories))
-                       {
-                               $sel_category = '';
-                               if ($category['id']==$selected)
-                               {
-                                       $sel_category = 'selected';
-                               }
-
-                               $category_list[] = array
-                               (
-                                       'cat_id'        => $category['id'],
-                                       'name'          => $category['name'],
-                                       'selected'      => $sel_category
-                               );
-                       }
-
-                       for ($i=0;$i<count($category_list);$i++)
-                       {
-                               if ($category_list[$i]['selected'] != 
'selected')
-                               {
-                                       unset($category_list[$i]['selected']);
-                               }
-                       }
-
-                       return $category_list;
-               }
-
-               function read()
-               {
-                       $tickets = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
-                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => 
$this->district_id,
-                                                                               
        'allrows'=>$this->allrows));
-                       $this->total_records = $this->so->total_records;
-                       $entity = $this->so->get_origin_entity_type();
-
-                       $this->uicols=$this->so->uicols;
-                       for ($i=0; $i<count($tickets); $i++)
-                       {
-                               if($tickets[$i]['assignedto'])
-                               {
-                                       $tickets[$i]['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($tickets[$i]['assignedto']);
-                               }
-                               else
-                               {
-                                       $tickets[$i]['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($tickets[$i]['group_id']);
-                               }
-
-                               $tickets[$i]['timestampopened'] = 
$GLOBALS['phpgw']->common->show_date($tickets[$i]['entry_date'],$this->dateformat);
-
-                               if($tickets[$i]['finnish_date2'])
-                               {
-                                       
$tickets[$i]['delay']=($tickets[$i]['finnish_date2']-$tickets[$i]['finnish_date'])/(24*3600);
-                                       
$tickets[$i]['finnish_date']=$tickets[$i]['finnish_date2'];
-                               }
-                               $tickets[$i]['finnish_date'] = 
(isset($tickets[$i]['finnish_date'])?$GLOBALS['phpgw']->common->show_date($tickets[$i]['finnish_date'],$this->dateformat):'');
-
-                               if ($tickets[$i]['status'] == 'X')
-                               {
-                                       $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$tickets[$i]['id']);
-                                       $tickets[$i]['timestampclosed'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
-                               }
-                               if ($tickets[$i]['new_ticket'])
-                               {
-                                       $tickets[$i]['new_ticket'] = 
lang('New');
-                               }
-
-                               for ($j=0;$j<count($entity);$j++)
-                               {
-                                       $tickets[$i]['child_date'][$j] = 
$this->so->get_child_date($tickets[$i]['id'],$entity[$j]['type'],$entity[$j]['entity_id'],$entity[$j]['cat_id']);
-                               }
-                       }
-
-//html_print_r($tickets);
-                       return $tickets;
-               }
-
-               function read_single($id)
-               {
-
-                       $this->so->update_view($id);
-
-                       $ticket = $this->so->read_single($id);
-
-                       $ticket['user_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
-                       $ticket['group_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
-
-
-                       if($ticket['finnish_date2'])
-                       {
-                               
$ticket['finnish_date']=$ticket['finnish_date2'];
-                       }
-
-                       if($ticket['finnish_date'])
-                       {
-                               $ticket['finnish_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['finnish_date'],$this->dateformat);
-                       }
-
-                       if($ticket['location_code'])
-                       {
-                               $solocation     = 
CreateObject($this->currentapp.'_solocation');
-                               $ticket['location_data'] = 
$solocation->read_single($ticket['location_code']);
-                       }
-
-                       if($ticket['p_num'])
-                       {
-                               $soadmin_entity = 
CreateObject($this->currentapp.'_soadmin_entity');
-                               $category = 
$soadmin_entity->read_single_category($ticket['p_entity_id'],$ticket['p_cat_id']);
-
-                               
$ticket['p'][$ticket['p_entity_id']]['p_num']=$ticket['p_num'];
-                               
$ticket['p'][$ticket['p_entity_id']]['p_entity_id']=$ticket['p_entity_id'];
-                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_id']=$ticket['p_cat_id'];
-                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_name'] = $category['name'];
-                       }
-
-
-                       if($ticket['tenant_id']>0)
-                       {
-                               
$tenant_data=$this->bocommon->read_single_tenant($ticket['tenant_id']);
-                               $ticket['location_data']['tenant_id']= 
$ticket['tenant_id'];
-                               $ticket['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
-                               $ticket['location_data']['last_name']   = 
$tenant_data['last_name'];
-                               $ticket['location_data']['first_name']  = 
$tenant_data['first_name'];
-                       }
-                       else
-                       {
-                               unset($ticket['location_data']['tenant_id']);
-                               
unset($ticket['location_data']['contact_phone']);
-                               unset($ticket['location_data']['last_name']);
-                               unset($ticket['location_data']['first_name']);
-                       }
-
-
-                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
-                       $ticket['timestampopened'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
-                       // Figure out when it was opened and last closed
-
-                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','ASC',$id);
-                       $ticket['last_opened'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime']);
-
-                       if($ticket['status']=='X')
-                       {
-
-                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
-                               $ticket['timestampclosed']= 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
-                       }
-
-
-
-                       $status_text = array(
-                               'R' => 'Re-opened',
-                               'X' => 'Closed',
-                               'O' => 'Opened',
-                               'A' => 'Re-assigned',
-                               'G' => 'Re-assigned group',
-                               'P' => 'Priority changed',
-                               'T' => 'Category changed',
-                               'S' => 'Subject changed',
-                               'B' => 'Billing rate',
-                               'H' => 'Billing hours',
-                               'F' => 'finnish date'
-                       );
-
-                       $ticket['status_name'] = 
lang($status_text[$ticket['status']]);
-                       
$ticket['assignedto_name']=$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
-                       
$ticket['user_lid']=$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
-                       
$ticket['category_name']=ucfirst($this->get_category_name($ticket['cat_id']));
-
-                       return $ticket;
-               }
-
-               function read_additional_notes($id)
-               {
-                       $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
-                       $i=1;
-                       while (is_array($history_array) && list(,$value) = 
each($history_array))
-                       {
-                               $additional_notes[] = array
-                               (
-                                       'value_count'   => $i,
-                                       'value_date'    => 
$GLOBALS['phpgw']->common->show_date($value['datetime']),
-                                       'value_user'    => $value['owner'],
-                                       'value_note'    => 
stripslashes(stripslashes($value['new_value'])),
-                                       );
-                               $i++;
-                       }
-
-                       return $additional_notes;
-               }
-
-
-               function read_record_history($id)
-               {
-                       $history_array = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
-                       $i=0;
-                       while (is_array($history_array) && list(,$value) = 
each($history_array))
-                       {
-
-                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
-                               $record_history[$i]['value_user']       = 
$value['owner'];
-
-                               switch ($value['status'])
-                               {
-                                       case 'R': $type = lang('Re-opened'); 
break;
-                                       case 'X': $type = lang('Closed');    
break;
-                                       case 'O': $type = lang('Opened');    
break;
-                                       case 'A': $type = lang('Re-assigned'); 
break;
-                                       case 'G': $type = lang('Re-assigned 
group'); break;
-                                       case 'P': $type = lang('Priority 
changed'); break;
-                                       case 'T': $type = lang('Category 
changed'); break;
-                                       case 'S': $type = lang('Subject 
changed'); break;
-                                       case 'H': $type = lang('Billable hours 
changed'); break;
-                                       case 'B': $type = lang('Billable rate 
changed'); break;
-                                       case 'F': $type = lang('finnish date 
changed'); break;
-                                       case 'IF': $type = lang('Initial 
finnish date'); break;
-                                       default: break;
-                               }
-
-                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
-                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
-
-
-                               $record_history[$i]['value_action']     = 
$type?$type:'';
-                               unset($type);
-                               if ($value['status'] == 'A' || $value['status'] 
== 'G')
-                               {
-                                       if ((int)$value['new_value']>0)
-                                       {
-                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
-                                       }
-                                       else
-                                       {
-                                               
$record_history[$i]['value_new_value']  = lang('None');
-
-                                       }
-                               }
-                               else if ($value['status'] == 'T')
-                               {
-                                       $record_history[$i]['value_new_value']  
= $this->get_category_name($value['new_value']);
-                               }
-                               else if (($value['status'] == 'F') || 
($value['status'] =='IF'))
-                               {
-                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->common->show_date($value['new_value'],$this->dateformat);
-                               }
-                               else if ($value['status'] != 'O' && 
$value['new_value'])
-                               {
-                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
-                               }
-                               else
-                               {
-                                       $record_history[$i]['value_new_value']  
= '';
-                               }
-
-                               $i++;
-                       }
-
-                       return $record_history;
-               }
-
-               function add($ticket)
-               {
-                       while (is_array($ticket['location']) && list(,$value) = 
each($ticket['location']))
-                       {
-                               if($value)
-                               {
-                                       $location[] = $value;
-                               }
-                       }
-
-                       $ticket['finnish_date'] = 
$this->bocommon->date_to_timestamp($ticket['finnish_date']);
-                       $ticket['location_code']=implode("-", $location);
-
-                       $receipt = $this->so->add($ticket);
-
-                       $this->config->read_repository();
-
-                       if ($this->config->config_data['mailnotification'])
-                       {
-                               $receipt = 
$this->mail_ticket($receipt['id'],$fields_updated,$receipt,$ticket['location_code']);
-
-                       }
-
-                       return $receipt;
-               }
-
-
-               function 
mail_ticket($id,$fields_updated,$receipt=0,$location_code='')
-               {
-                       $this->config->read_repository();
-                       $this->send                     = 
CreateObject('phpgwapi_send');
-
-                       $members = array();
-
-                       $ticket = $this->so->read_single($id);
-
-                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
-                       $timestampopened = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
-
-                       if($ticket['status']=='X')
-                       {
-                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
-                               $timestampclosed = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
-                       }
-
-                       $history_2 = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
-                       $m=count($history_2)-1;
-                       $ticket['status']=$history_2[$m]['status'];
-
-                       $stat = $ticket['status'];
-                       $status = array(
-                               'R' => 'Re-opened',
-                               'X' => 'Closed',
-                               'O' => 'Opened',
-                               'A' => 'Re-assigned',
-                               'G' => 'Re-assigned group',
-                               'P' => 'Priority changed',
-                               'T' => 'Category changed',
-                               'S' => 'Subject changed',
-                               'B' => 'Billing rate',
-                               'H' => 'Billing hours',
-                               'F' => 'finnish date changed'
-                       );
-
-
-                       $group_name= 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
-
-                       // build subject
-                       $ticket['subject'] = '['.lang('Ticket').' #'.$id.'] : ' 
. $location_code .' ' .$this->get_category_name($ticket['cat_id']);
-
-
-               //      $prefs_user = 
$GLOBALS['phpgw']->preferences->create_email_preferences($ticket['user_id']);
-                       $prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$ticket['user_id']);
-
-                       $from_address=$prefs_user['email'];
-
-       //-----------from--------
-
-                       $current_user_id=$GLOBALS['phpgw_data']['user']['id'];
-
-                       $current_user_firstname = 
$GLOBALS['phpgw_info']['user']['firstname'];
-
-                       $current_user_lastname  
=$GLOBALS['phpgw_info']['user']['lastname'];
-
-                       $current_user_name= $user_firstname . " " 
.$user_lastname ;
-
-//                     $current_prefs_user = 
$GLOBALS['phpgw']->preferences->create_email_preferences($current_user_id);
-                       $current_prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$current_user_id);
-                       $current_user_address=$current_prefs_user['email'];
-
-                       $headers = "Return-Path: <". $current_user_address 
.">\r\n";
-                       $headers .= "From: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
-                       $headers .= "Bcc: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
-                       $headers .= "Content-type: text/html; 
charset=iso-8859-1\r\n";
-                       $headers .= "MIME-Version: 1.0\r\n";
-
-       //-----------from--------
-               // build body
-                       $body  = '';
-                       $body .= lang('Ticket').' #'.$id."\n";
-                       $body .= lang('Date Opened').': '.$timestampopened."\n";
-                       $body .= lang('Category').': '. 
$this->get_category_name($ticket['cat_id']) ."\n";
-//                     $body .= lang('Subject').': '. $ticket['subject'] ."\n";
-                       $body .= lang('Location').': '. 
$ticket['location_code'] ."\n";
-                       $body .= lang('Address').': '. $ticket['address'] ."\n";
-                       $body .= lang('Assigned To').': 
'.$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto'])."\n";
-                       $body .= lang('Priority').': '.$ticket['priority']."\n";
-                       if($group_name)
-                       {
-                               $body .= lang('Group').': '. $group_name ."\n";
-                       }
-                       $body .= lang('Opened By').': '. $ticket['user_name'] 
."\n\n";
-                       $body .= lang('First Note Added').":\n";
-                       $body .= 
stripslashes(strip_tags($ticket['details']))."\n\n";
-
-                       
/**************************************************************\
-                       * Display additional notes                              
       *
-                       
\**************************************************************/
-                       if($fields_updated)
-                       {
-                               $i=1;
-
-                               $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
-                               while (is_array($history_array) && 
list(,$value) = each($history_array))
-                               {
-                                       $body .= lang('Date') . ': 
'.$GLOBALS['phpgw']->common->show_date($value['datetime'])."\n";
-                                       $body .= lang('User') . ': 
'.$value['owner']."\n";
-                                       $body .=lang('Note').': '. 
nl2br(stripslashes($value['new_value']))."\n\n";
-                                       $i++;
-                               }
-                               $ticket['subject'].= "-" .$i;
-                       }
-
-                       
/**************************************************************\
-                       * Display record history                                
       *
-                       
\**************************************************************/
-
-                       if($timestampclosed)
-                       {
-                               $body .= lang('Date Closed').': 
'.$timestampclosed."\n\n";
-                       }
-
-                       if ($this->config->config_data['groupnotification'])
-                       {
-                               // select group recipients
-                               $members  = 
$GLOBALS['phpgw']->accounts->member($ticket['group_id']);
-                       }
-
-                       if ($this->config->config_data['ownernotification'])
-                       {
-                               // add owner to recipients
-                               $members[] = array('account_id' => 
$ticket['user_id'], 'account_name' => 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']));
-                       }
-
-                       if ($this->config->config_data['assignednotification'])
-                       {
-                               // add assigned to recipients
-                               $members[] = array('account_id' => 
$ticket['assignedto'], 'account_name' => 
$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']));
-                       }
-
-                       $error = Array();
-                       $toarray = Array();
-                       $i=0;
-                       for ($i=0;$i<count($members);$i++)
-                       {
-                               if ($members[$i]['account_id'])
-                               {
-                       //              $prefs = 
$GLOBALS['phpgw']->preferences->create_email_preferences($members[$i]['account_id']);
-                                       $prefs = 
$this->bocommon->create_preferences($this->currentapp,$members[$i]['account_id']);
-                                       if (strlen($prefs['email'])> 
(strlen($members[$i]['account_name'])+1))
-                                       {
-                                               $toarray[$prefs['email']] = 
$prefs['email'];
-                                       }
-                                       else
-                                       {
-                                               $receipt['error'][] = 
array('msg'=> lang('Your message could not be sent!'));
-                                               $receipt['error'][] = 
array('msg'=>lang('This user has not defined an email address !') . ' : ' . 
$members[$i]['account_name']);
-                                       }
-                               }
-                       }
-
-                       if(count($toarray) > 1)
-                       {
-                               $to = implode(',',$toarray);
-                       }
-                       else
-                       {
-                               $to = current($toarray);
-                       }
-
-                       $mail_method= 
$this->config->config_data['fmwrkorder_mail'];
-//                     echo 'mail_method: '.$mail_method .'<BR>';
-
-                       if ($mail_method=='smtp'):
-                       {
-                               $rc = $this->send->msg('email', $to, 
$ticket['subject'], stripslashes($body), '', $cc, 
$bcc,$current_user_address,$current_user_name,'txt');
-                       }
-                       elseif ($mail_method=='sendmail'):
-                       {
-                               $rc=    
@mail($to,$ticket['subject'],stripslashes($body), $headers);
-                       }
-                       else:
-                       {
-                               $receipt['error'][] = array('msg'=> 
lang('Mailing method is not chosen! (admin section)'));
-                       }
-                       endif;
-
-               //      $rc=1;
-                       if (!$rc)
-                       {
-                               $receipt['error'][] = array('msg'=> lang('Your 
message could not be sent by mail!'));
-                               $receipt['error'][] = array('msg'=> lang('The 
mail server returned'));
-                               $receipt['error'][] = array('msg'=> 'From :' . 
$current_user_name . '<' . $current_user_address .'>');
-                               $receipt['error'][] = array('msg'=> 'to: '.$to);
-                               $receipt['error'][] = array('msg'=> 'subject: 
'.$ticket['subject']);
-                               $receipt['error'][] = array('msg'=> $body );
-       //                      $receipt['error'][] = array('msg'=> 'cc: ' . 
$cc);
-       //                      $receipt['error'][] = array('msg'=> 'bcc: 
'.$bcc);
-                               $receipt['error'][] = array('msg'=> 'group: 
'.$group_name);
-                               $receipt['error'][] = array('msg'=> 'err_code: 
'.$this->send->err['code']);
-                               $receipt['error'][] = array('msg'=> 'err_msg: 
'. htmlspecialchars($this->send->err['msg']));
-                               $receipt['error'][] = array('msg'=> 'err_desc: 
'. $GLOBALS['phpgw']->err['desc']);
-                       }
-
-//html_print_r($receipt);
-                       return $receipt;
-               }
-
-
-               function delete($id)
-               {
-                       $this->so->delete($id);
-               }
-       }
-?>
+<?php
+       
/**************************************************************************\
+       * phpGroupWare - property                                               
   *
+       * http://www.phpgroupware.org                                           
   *
+       *                                                                       
   *
+       * Facilities Management                                                 
   *
+       * Written by Sigurd Nes [sigurdne at online.no]                         
   *
+       * 
------------------------------------------------------------------------ *
+       * Copyright 2000 - 2003 Free Software Foundation, Inc                   
   *
+       * This program is part of the GNU project, see http://www.gnu.org/      
   *
+       * 
------------------------------------------------------------------------ *
+       * This program is free software; you can redistribute it and/or modify 
it  *
+       * under the terms of the GNU General Public License as published by the 
   *
+       * Free Software Foundation; either version 2 of the License, or (at 
your   *
+       * option) any later version.                                            
   *
+       
\**************************************************************************/
+
+       class property_botts
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+
+               var $public_functions = array
+               (
+                       'read'                          => True,
+                       'read_single'           => True,
+                       'save'                          => True,
+                       'delete'                        => True,
+                       'check_perms'           => True
+               );
+
+               var $soap_functions = array(
+                       'list' => array(
+                               'in'  => 
array('int','int','struct','string','int'),
+                               'out' => array('array')
+                       ),
+                       'read' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array('array')
+                       ),
+                       'save' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       ),
+                       'delete' => array(
+                               'in'  => array('int','struct'),
+                               'out' => array()
+                       )
+               );
+
+               function property_botts($session=False)
+               {
+                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->so                       = 
CreateObject($this->currentapp.'_sotts');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','tts');
+                       $this->config           = 
CreateObject('phpgwapi_config');
+                       $this->dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata();
+                               $this->use_session = True;
+                       }
+
+                       $start  = get_var('start',array('POST','GET'));
+                       $query  = get_var('query',array('POST','GET'));
+                       $sort   = get_var('sort',array('POST','GET'));
+                       $order  = get_var('order',array('POST','GET'));
+                       $filter = get_var('filter',array('POST','GET'));
+                       $cat_id = get_var('cat_id',array('POST','GET'));
+                       $district_id    = 
get_var('district_id',array('POST','GET'));
+                       $allrows        = 
get_var('allrows',array('POST','GET'));
+
+                       if ($start)
+                       {
+                               $this->start=$start;
+                       }
+                       else
+                       {
+                               $this->start=0;
+                       }
+
+                       if(isset($query))
+                       {
+                               $this->query = $query;
+                       }
+                       if(isset($filter))
+                       {
+                               $this->filter = $filter;
+                       }
+                       if(isset($sort))
+                       {
+                               $this->sort = $sort;
+                       }
+                       if(isset($order))
+                       {
+                               $this->order = $order;
+                       }
+                       if(isset($cat_id))
+                       {
+                               $this->cat_id = $cat_id;
+                       }
+                       if(isset($district_id))
+                       {
+                               $this->district_id = $district_id;
+                       }
+                       if(isset($allrows))
+                       {
+                               $this->allrows = $allrows;
+                       }
+               }
+
+
+               function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$this->fm_session->appsession('session_data','tts',$data);
+                       }
+               }
+
+               function read_sessiondata()
+               {
+                       $data = 
$this->fm_session->appsession('session_data','tts');
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->district_id      = $data['district_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function filter($data=0)
+               {
+                       if(is_array($data))
+                       {
+                               $format = 
(isset($data['format'])?$data['format']:'');
+                               $selected = 
(isset($data['filter'])?$data['filter']:$data['default']);
+                       }
+
+                       $this->bocommon->xsl_add_file(array('filter_filter'));
+
+                       $filters[0][id]='closed';
+                       $filters[0][name]=lang('Closed');
+                       $filters[1][id]='all';
+                       $filters[1][name]=lang('All');
+
+                       while (is_array($filters) && list(,$filter) = 
each($filters))
+                       {
+                               $sel_filter = '';
+                               if ($filter['id']==$selected)
+                               {
+                                       $sel_filter = 'selected';
+                               }
+
+                               $filter_list[] = array
+                               (
+                                       'id'    => $filter['id'],
+                                       'name'          => $filter['name'],
+                                       'selected'      => $sel_filter
+                               );
+                       }
+
+                       for ($i=0;$i<count($filter_list);$i++)
+                       {
+                               if ($filter_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($filter_list[$i]['selected']);
+                               }
+                       }
+
+                       return $filter_list;
+               }
+
+               function get_status_list($selected)
+               {
+
+                       $filters[0][id]='X';
+                       $filters[0][name]=lang('Closed');
+                       $filters[1][id]='O';
+                       $filters[1][name]=lang('Open');
+
+                       while (is_array($filters) && list(,$filter) = 
each($filters))
+                       {
+                               $sel_filter = '';
+                               if ($filter['id']==$selected)
+                               {
+                                       $sel_filter = 'selected';
+                               }
+
+                               $filter_list[] = array
+                               (
+                                       'id'    => $filter['id'],
+                                       'name'          => $filter['name'],
+                                       'selected'      => $sel_filter
+                               );
+                       }
+
+                       for ($i=0;$i<count($filter_list);$i++)
+                       {
+                               if ($filter_list[$i]['selected'] != 'selected')
+                               {
+                                       unset($filter_list[$i]['selected']);
+                               }
+                       }
+
+                       return $filter_list;
+               }
+
+
+               function get_priority_list($selected='')
+               {
+
+                       if(!$selected)
+                       {
+                               $selected = 
$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['prioritydefault'];
+                       }
+
+                       $priority_comment[1]=' - '.lang('Lowest');
+                       $priority_comment[5]=' - '.lang('Medium');
+                       $priority_comment[10]=' - '.lang('Highest');
+
+                       for ($i=1; $i<=10; $i++)
+                       {
+                               $priorities[$i]['id'] =$i;
+                               $priorities[$i]['name'] =$i . 
$priority_comment[$i];
+                       }
+
+                       while (is_array($priorities) && list(,$priority) = 
each($priorities))
+                       {
+                               $sel_priority = '';
+                               if ($priority['id']==$selected)
+                               {
+                                       $sel_priority = 'selected';
+                               }
+
+                               $priority_list[] = array
+                               (
+                                       'id'    => $priority['id'],
+                                       'name'          => $priority['name'],
+                                       'selected'      => $sel_priority
+                               );
+                       }
+
+                       for ($i=0;$i<count($priority_list);$i++)
+                       {
+                               if ($priority_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($priority_list[$i]['selected']);
+                               }
+                       }
+
+//html_print_r($priority_list);
+                       return $priority_list;
+               }
+
+               function get_category_name($cat_id)
+               {
+                       return $this->so->get_category_name($cat_id);
+               }
+
+               function select_category_list($format='',$selected='')
+               {
+
+                       switch($format)
+                       {
+                               case 'select':
+                                       
$this->bocommon->xsl_add_file(array('cat_select'));
+                                       break;
+                               case 'filter':
+                                       
$this->bocommon->xsl_add_file(array('cat_filter'));
+                                       break;
+                       }
+
+                       $categories= $this->so->select_category_list();
+
+                       while (is_array($categories) && list(,$category) = 
each($categories))
+                       {
+                               $sel_category = '';
+                               if ($category['id']==$selected)
+                               {
+                                       $sel_category = 'selected';
+                               }
+
+                               $category_list[] = array
+                               (
+                                       'cat_id'        => $category['id'],
+                                       'name'          => $category['name'],
+                                       'selected'      => $sel_category
+                               );
+                       }
+
+                       for ($i=0;$i<count($category_list);$i++)
+                       {
+                               if ($category_list[$i]['selected'] != 
'selected')
+                               {
+                                       unset($category_list[$i]['selected']);
+                               }
+                       }
+
+                       return $category_list;
+               }
+
+               function read()
+               {
+                       $tickets = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                                                                               
        'filter' => $this->filter,'cat_id' => $this->cat_id,'district_id' => 
$this->district_id,
+                                                                               
        'allrows'=>$this->allrows));
+                       $this->total_records = $this->so->total_records;
+                       $entity = $this->so->get_origin_entity_type();
+
+                       $this->uicols=$this->so->uicols;
+                       for ($i=0; $i<count($tickets); $i++)
+                       {
+                               if($tickets[$i]['assignedto'])
+                               {
+                                       $tickets[$i]['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($tickets[$i]['assignedto']);
+                               }
+                               else
+                               {
+                                       $tickets[$i]['assignedto'] = 
$GLOBALS['phpgw']->accounts->id2name($tickets[$i]['group_id']);
+                               }
+
+                               $tickets[$i]['timestampopened'] = 
$GLOBALS['phpgw']->common->show_date($tickets[$i]['entry_date'],$this->dateformat);
+
+                               if($tickets[$i]['finnish_date2'])
+                               {
+                                       
$tickets[$i]['delay']=($tickets[$i]['finnish_date2']-$tickets[$i]['finnish_date'])/(24*3600);
+                                       
$tickets[$i]['finnish_date']=$tickets[$i]['finnish_date2'];
+                               }
+                               $tickets[$i]['finnish_date'] = 
(isset($tickets[$i]['finnish_date'])?$GLOBALS['phpgw']->common->show_date($tickets[$i]['finnish_date'],$this->dateformat):'');
+
+                               if ($tickets[$i]['status'] == 'X')
+                               {
+                                       $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$tickets[$i]['id']);
+                                       $tickets[$i]['timestampclosed'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                               }
+                               if ($tickets[$i]['new_ticket'])
+                               {
+                                       $tickets[$i]['new_ticket'] = 
lang('New');
+                               }
+
+                               for ($j=0;$j<count($entity);$j++)
+                               {
+                                       $tickets[$i]['child_date'][$j] = 
$this->so->get_child_date($tickets[$i]['id'],$entity[$j]['type'],$entity[$j]['entity_id'],$entity[$j]['cat_id']);
+                               }
+                       }
+
+//html_print_r($tickets);
+                       return $tickets;
+               }
+
+               function read_single($id)
+               {
+
+                       $this->so->update_view($id);
+
+                       $ticket = $this->so->read_single($id);
+
+                       $ticket['user_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                       $ticket['group_lid'] = 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+
+
+                       if($ticket['finnish_date2'])
+                       {
+                               
$ticket['finnish_date']=$ticket['finnish_date2'];
+                       }
+
+                       if($ticket['finnish_date'])
+                       {
+                               $ticket['finnish_date'] = 
$GLOBALS['phpgw']->common->show_date($ticket['finnish_date'],$this->dateformat);
+                       }
+
+                       if($ticket['location_code'])
+                       {
+                               $solocation     = 
CreateObject($this->currentapp.'_solocation');
+                               $ticket['location_data'] = 
$solocation->read_single($ticket['location_code']);
+                       }
+
+                       if($ticket['p_num'])
+                       {
+                               $soadmin_entity = 
CreateObject($this->currentapp.'_soadmin_entity');
+                               $category = 
$soadmin_entity->read_single_category($ticket['p_entity_id'],$ticket['p_cat_id']);
+
+                               
$ticket['p'][$ticket['p_entity_id']]['p_num']=$ticket['p_num'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_entity_id']=$ticket['p_entity_id'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_id']=$ticket['p_cat_id'];
+                               
$ticket['p'][$ticket['p_entity_id']]['p_cat_name'] = $category['name'];
+                       }
+
+
+                       if($ticket['tenant_id']>0)
+                       {
+                               
$tenant_data=$this->bocommon->read_single_tenant($ticket['tenant_id']);
+                               $ticket['location_data']['tenant_id']= 
$ticket['tenant_id'];
+                               $ticket['location_data']['contact_phone']= 
$tenant_data['contact_phone'];
+                               $ticket['location_data']['last_name']   = 
$tenant_data['last_name'];
+                               $ticket['location_data']['first_name']  = 
$tenant_data['first_name'];
+                       }
+                       else
+                       {
+                               unset($ticket['location_data']['tenant_id']);
+                               
unset($ticket['location_data']['contact_phone']);
+                               unset($ticket['location_data']['last_name']);
+                               unset($ticket['location_data']['first_name']);
+                       }
+
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
+                       $ticket['timestampopened'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       // Figure out when it was opened and last closed
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','ASC',$id);
+                       $ticket['last_opened'] = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime']);
+
+                       if($ticket['status']=='X')
+                       {
+
+                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
+                               $ticket['timestampclosed']= 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       }
+
+
+
+                       $status_text = array(
+                               'R' => 'Re-opened',
+                               'X' => 'Closed',
+                               'O' => 'Opened',
+                               'A' => 'Re-assigned',
+                               'G' => 'Re-assigned group',
+                               'P' => 'Priority changed',
+                               'T' => 'Category changed',
+                               'S' => 'Subject changed',
+                               'B' => 'Billing rate',
+                               'H' => 'Billing hours',
+                               'F' => 'finnish date'
+                       );
+
+                       $ticket['status_name'] = 
lang($status_text[$ticket['status']]);
+                       
$ticket['assignedto_name']=$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']);
+                       
$ticket['user_lid']=$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']);
+                       
$ticket['category_name']=ucfirst($this->get_category_name($ticket['cat_id']));
+
+                       return $ticket;
+               }
+
+               function read_additional_notes($id)
+               {
+                       $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
+                       $i=1;
+                       while (is_array($history_array) && list(,$value) = 
each($history_array))
+                       {
+                               $additional_notes[] = array
+                               (
+                                       'value_count'   => $i,
+                                       'value_date'    => 
$GLOBALS['phpgw']->common->show_date($value['datetime']),
+                                       'value_user'    => $value['owner'],
+                                       'value_note'    => 
stripslashes(stripslashes($value['new_value'])),
+                                       );
+                               $i++;
+                       }
+
+                       return $additional_notes;
+               }
+
+
+               function read_record_history($id)
+               {
+                       $history_array = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
+                       $i=0;
+                       while (is_array($history_array) && list(,$value) = 
each($history_array))
+                       {
+
+                               $record_history[$i]['value_date']       = 
$GLOBALS['phpgw']->common->show_date($value['datetime']);
+                               $record_history[$i]['value_user']       = 
$value['owner'];
+
+                               switch ($value['status'])
+                               {
+                                       case 'R': $type = lang('Re-opened'); 
break;
+                                       case 'X': $type = lang('Closed');    
break;
+                                       case 'O': $type = lang('Opened');    
break;
+                                       case 'A': $type = lang('Re-assigned'); 
break;
+                                       case 'G': $type = lang('Re-assigned 
group'); break;
+                                       case 'P': $type = lang('Priority 
changed'); break;
+                                       case 'T': $type = lang('Category 
changed'); break;
+                                       case 'S': $type = lang('Subject 
changed'); break;
+                                       case 'H': $type = lang('Billable hours 
changed'); break;
+                                       case 'B': $type = lang('Billable rate 
changed'); break;
+                                       case 'F': $type = lang('finnish date 
changed'); break;
+                                       case 'IF': $type = lang('Initial 
finnish date'); break;
+                                       default: break;
+                               }
+
+                               
if($value['new_value']=='O'){$value['new_value']=lang('Opened');}
+                               
if($value['new_value']=='X'){$value['new_value']=lang('Closed');}
+
+
+                               $record_history[$i]['value_action']     = 
$type?$type:'';
+                               unset($type);
+                               if ($value['status'] == 'A' || $value['status'] 
== 'G')
+                               {
+                                       if ((int)$value['new_value']>0)
+                                       {
+                                               
$record_history[$i]['value_new_value']  = 
$GLOBALS['phpgw']->accounts->id2name($value['new_value']);
+                                       }
+                                       else
+                                       {
+                                               
$record_history[$i]['value_new_value']  = lang('None');
+
+                                       }
+                               }
+                               else if ($value['status'] == 'T')
+                               {
+                                       $record_history[$i]['value_new_value']  
= $this->get_category_name($value['new_value']);
+                               }
+                               else if (($value['status'] == 'F') || 
($value['status'] =='IF'))
+                               {
+                                       $record_history[$i]['value_new_value']  
= $GLOBALS['phpgw']->common->show_date($value['new_value'],$this->dateformat);
+                               }
+                               else if ($value['status'] != 'O' && 
$value['new_value'])
+                               {
+                                       $record_history[$i]['value_new_value']  
= $value['new_value'];
+                               }
+                               else
+                               {
+                                       $record_history[$i]['value_new_value']  
= '';
+                               }
+
+                               $i++;
+                       }
+
+                       return $record_history;
+               }
+
+               function add($ticket)
+               {
+                       while (is_array($ticket['location']) && list(,$value) = 
each($ticket['location']))
+                       {
+                               if($value)
+                               {
+                                       $location[] = $value;
+                               }
+                       }
+
+                       $ticket['finnish_date'] = 
$this->bocommon->date_to_timestamp($ticket['finnish_date']);
+                       $ticket['location_code']=implode("-", $location);
+
+                       $receipt = $this->so->add($ticket);
+
+                       $this->config->read_repository();
+
+                       if ($this->config->config_data['mailnotification'])
+                       {
+                               $receipt = 
$this->mail_ticket($receipt['id'],$fields_updated,$receipt,$ticket['location_code']);
+
+                       }
+
+                       return $receipt;
+               }
+
+
+               function 
mail_ticket($id,$fields_updated,$receipt=0,$location_code='')
+               {
+                       $this->config->read_repository();
+                       $this->send                     = 
CreateObject('phpgwapi_send');
+
+                       $members = array();
+
+                       $ticket = $this->so->read_single($id);
+
+                       $history_values = 
$this->historylog->return_array(array(),array('O'),'history_timestamp','DESC',$id);
+                       $timestampopened = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+
+                       if($ticket['status']=='X')
+                       {
+                               $history_values = 
$this->historylog->return_array(array(),array('X'),'history_timestamp','DESC',$id);
+                               $timestampclosed = 
$GLOBALS['phpgw']->common->show_date($history_values[0]['datetime'],$this->dateformat);
+                       }
+
+                       $history_2 = 
$this->historylog->return_array(array('C','O'),array(),'','',$id);
+                       $m=count($history_2)-1;
+                       $ticket['status']=$history_2[$m]['status'];
+
+                       $stat = $ticket['status'];
+                       $status = array(
+                               'R' => 'Re-opened',
+                               'X' => 'Closed',
+                               'O' => 'Opened',
+                               'A' => 'Re-assigned',
+                               'G' => 'Re-assigned group',
+                               'P' => 'Priority changed',
+                               'T' => 'Category changed',
+                               'S' => 'Subject changed',
+                               'B' => 'Billing rate',
+                               'H' => 'Billing hours',
+                               'F' => 'finnish date changed'
+                       );
+
+
+                       $group_name= 
$GLOBALS['phpgw']->accounts->id2name($ticket['group_id']);
+
+                       // build subject
+                       $ticket['subject'] = '['.lang('Ticket').' #'.$id.'] : ' 
. $location_code .' ' .$this->get_category_name($ticket['cat_id']);
+
+
+               //      $prefs_user = 
$GLOBALS['phpgw']->preferences->create_email_preferences($ticket['user_id']);
+                       $prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$ticket['user_id']);
+
+                       $from_address=$prefs_user['email'];
+
+       //-----------from--------
+
+                       $current_user_id=$GLOBALS['phpgw_data']['user']['id'];
+
+                       $current_user_firstname = 
$GLOBALS['phpgw_info']['user']['firstname'];
+
+                       $current_user_lastname  
=$GLOBALS['phpgw_info']['user']['lastname'];
+
+                       $current_user_name= $user_firstname . " " 
.$user_lastname ;
+
+//                     $current_prefs_user = 
$GLOBALS['phpgw']->preferences->create_email_preferences($current_user_id);
+                       $current_prefs_user = 
$this->bocommon->create_preferences($this->currentapp,$current_user_id);
+                       $current_user_address=$current_prefs_user['email'];
+
+                       $headers = "Return-Path: <". $current_user_address 
.">\r\n";
+                       $headers .= "From: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
+                       $headers .= "Bcc: " . $current_user_name . "<" . 
$current_user_address .">\r\n";
+                       $headers .= "Content-type: text/html; 
charset=iso-8859-1\r\n";
+                       $headers .= "MIME-Version: 1.0\r\n";
+
+       //-----------from--------
+               // build body
+                       $body  = '';
+                       $body .= lang('Ticket').' #'.$id."\n";
+                       $body .= lang('Date Opened').': '.$timestampopened."\n";
+                       $body .= lang('Category').': '. 
$this->get_category_name($ticket['cat_id']) ."\n";
+//                     $body .= lang('Subject').': '. $ticket['subject'] ."\n";
+                       $body .= lang('Location').': '. 
$ticket['location_code'] ."\n";
+                       $body .= lang('Address').': '. $ticket['address'] ."\n";
+                       $body .= lang('Assigned To').': 
'.$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto'])."\n";
+                       $body .= lang('Priority').': '.$ticket['priority']."\n";
+                       if($group_name)
+                       {
+                               $body .= lang('Group').': '. $group_name ."\n";
+                       }
+                       $body .= lang('Opened By').': '. $ticket['user_name'] 
."\n\n";
+                       $body .= lang('First Note Added').":\n";
+                       $body .= 
stripslashes(strip_tags($ticket['details']))."\n\n";
+
+                       
/**************************************************************\
+                       * Display additional notes                              
       *
+                       
\**************************************************************/
+                       if($fields_updated)
+                       {
+                               $i=1;
+
+                               $history_array = 
$this->historylog->return_array(array(),array('C'),'','',$id);
+                               while (is_array($history_array) && 
list(,$value) = each($history_array))
+                               {
+                                       $body .= lang('Date') . ': 
'.$GLOBALS['phpgw']->common->show_date($value['datetime'])."\n";
+                                       $body .= lang('User') . ': 
'.$value['owner']."\n";
+                                       $body .=lang('Note').': '. 
nl2br(stripslashes($value['new_value']))."\n\n";
+                                       $i++;
+                               }
+                               $ticket['subject'].= "-" .$i;
+                       }
+
+                       
/**************************************************************\
+                       * Display record history                                
       *
+                       
\**************************************************************/
+
+                       if($timestampclosed)
+                       {
+                               $body .= lang('Date Closed').': 
'.$timestampclosed."\n\n";
+                       }
+
+                       if ($this->config->config_data['groupnotification'])
+                       {
+                               // select group recipients
+                               $members  = 
$GLOBALS['phpgw']->accounts->member($ticket['group_id']);
+                       }
+
+                       if ($this->config->config_data['ownernotification'])
+                       {
+                               // add owner to recipients
+                               $members[] = array('account_id' => 
$ticket['user_id'], 'account_name' => 
$GLOBALS['phpgw']->accounts->id2name($ticket['user_id']));
+                       }
+
+                       if ($this->config->config_data['assignednotification'])
+                       {
+                               // add assigned to recipients
+                               $members[] = array('account_id' => 
$ticket['assignedto'], 'account_name' => 
$GLOBALS['phpgw']->accounts->id2name($ticket['assignedto']));
+                       }
+
+                       $error = Array();
+                       $toarray = Array();
+                       $i=0;
+                       for ($i=0;$i<count($members);$i++)
+                       {
+                               if ($members[$i]['account_id'])
+                               {
+                       //              $prefs = 
$GLOBALS['phpgw']->preferences->create_email_preferences($members[$i]['account_id']);
+                                       $prefs = 
$this->bocommon->create_preferences($this->currentapp,$members[$i]['account_id']);
+                                       if (strlen($prefs['email'])> 
(strlen($members[$i]['account_name'])+1))
+                                       {
+                                               $toarray[$prefs['email']] = 
$prefs['email'];
+                                       }
+                                       else
+                                       {
+                                               $receipt['error'][] = 
array('msg'=> lang('Your message could not be sent!'));
+                                               $receipt['error'][] = 
array('msg'=>lang('This user has not defined an email address !') . ' : ' . 
$members[$i]['account_name']);
+                                       }
+                               }
+                       }
+
+                       if(count($toarray) > 1)
+                       {
+                               $to = implode(',',$toarray);
+                       }
+                       else
+                       {
+                               $to = current($toarray);
+                       }
+
+                       $mail_method= 
$this->config->config_data['fmwrkorder_mail'];
+//                     echo 'mail_method: '.$mail_method .'<BR>';
+
+                       if ($mail_method=='smtp'):
+                       {
+                               $rc = $this->send->msg('email', $to, 
$ticket['subject'], stripslashes($body), '', $cc, 
$bcc,$current_user_address,$current_user_name,'txt');
+                       }
+                       elseif ($mail_method=='sendmail'):
+                       {
+                               $rc=    
@mail($to,$ticket['subject'],stripslashes($body), $headers);
+                       }
+                       else:
+                       {
+                               $receipt['error'][] = array('msg'=> 
lang('Mailing method is not chosen! (admin section)'));
+                       }
+                       endif;
+
+               //      $rc=1;
+                       if (!$rc)
+                       {
+                               $receipt['error'][] = array('msg'=> lang('Your 
message could not be sent by mail!'));
+                               $receipt['error'][] = array('msg'=> lang('The 
mail server returned'));
+                               $receipt['error'][] = array('msg'=> 'From :' . 
$current_user_name . '<' . $current_user_address .'>');
+                               $receipt['error'][] = array('msg'=> 'to: '.$to);
+                               $receipt['error'][] = array('msg'=> 'subject: 
'.$ticket['subject']);
+                               $receipt['error'][] = array('msg'=> $body );
+       //                      $receipt['error'][] = array('msg'=> 'cc: ' . 
$cc);
+       //                      $receipt['error'][] = array('msg'=> 'bcc: 
'.$bcc);
+                               $receipt['error'][] = array('msg'=> 'group: 
'.$group_name);
+                               $receipt['error'][] = array('msg'=> 'err_code: 
'.$this->send->err['code']);
+                               $receipt['error'][] = array('msg'=> 'err_msg: 
'. htmlspecialchars($this->send->err['msg']));
+                               $receipt['error'][] = array('msg'=> 'err_desc: 
'. $GLOBALS['phpgw']->err['desc']);
+                       }
+
+//html_print_r($receipt);
+                       return $receipt;
+               }
+
+
+               function delete($id)
+               {
+                       $this->so->delete($id);
+               }
+       }
+?>




reply via email to

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