phpgroupware-cvs
[Top][All Lists]
Advanced

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

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


From: nomail
Subject: [Phpgroupware-cvs] property/class.sotts.php, 1.1.1.3
Date: Fri, 21 May 2004 19:16:41 -0000

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

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

Log Message:
no message
=====================================================================
Index: property/class.sotts.php
diff -u property/class.sotts.php:1.1.1.2 property/class.sotts.php:1.1.1.3
--- property/class.sotts.php:1.1.1.2    Fri Apr 23 20:26:09 2004
+++ property/class.sotts.php    Fri Apr 23 21:26:33 2004
@@ -1,480 +1,480 @@
-<?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_sotts
-       {
-
-               function property_sotts()
-               {
-                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->db                       = $GLOBALS['phpgw']->db;
-                       $this->db2                      = $this->db;
-                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
-                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','tts');
-                       $this->config           = 
CreateObject('phpgwapi_config');
-                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
-                       $this->join                     = $this->bocommon->join;
-                       $this->soadmin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
-                       $this->dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
-                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
-
-               }
-
-               function get_category_name($cat_id)
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
descr FROM fm_tts_category  WHERE id='$cat_id' ");
-
-
-
-                       return stripslashes($dbresult->fields['descr']);
-               }
-
-               function select_category_list()
-               {
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_tts_category  ORDER BY descr ");
-
-                       $i = 0;
-                       while (!$dbresult->EOF)
-                       {
-                               $categories[$i]['id']                           
= $dbresult->fields['id'];
-                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-                       return $categories;
-               }
-
-
-               function read($data)
-               {
-
-                       if(is_array($data))
-                       {
-                               if ($data['start'])
-                               {
-                                       $start=$data['start'];
-                               }
-                               else
-                               {
-                                       $start=0;
-                               }
-                               $filter = 
(isset($data['filter'])?$data['filter']:'open');
-                               $query = 
(isset($data['query'])?$data['query']:'');
-                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
-                               $order = 
(isset($data['order'])?$data['order']:'');
-                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
-                               $district_id = 
(isset($data['district_id'])?$data['district_id']:0);
-                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
-                       }
-
-//html_print_r($data);
-
-/*                     $this->grants   = 
$this->fm_session->appsession('grants_ticket',$this->currentapp);
-
-                       if(!$this->grants)
-                       {
-                               $this->acl2             = 
CreateObject($this->currentapp.'_acl2','##DEFAULT##','##DEFAULT##');
-                               $this->grants           = 
$this->acl2->get_grants($this->currentapp,'.ticket');
-                               
$this->fm_session->appsession('grants_ticket',$this->currentapp,$this->grants);
-                       }
-*/
-                       if ($order)
-                       {
-                               $ordermethod = " order by $order $sort";
-                       }
-                       else
-                       {
-                               $ordermethod = ' order by fm_tts_tickets.id 
DESC';
-                       }
-
-                       $where= 'WHERE';
-
-/*                     $filtermethod = $where . ' ( fm_tts_tickets.user_id=' . 
$this->account;
-                       if (is_array($this->grants))
-                       {
-                               $grants = $this->grants;
-                               while (list($user) = each($grants))
-                               {
-                                       $public_user_list[] = $user;
-                               }
-                               reset($public_user_list);
-                               $filtermethod = " $where ( 
fm_tts_tickets.user_id IN(" . implode(',',$public_user_list) . "))";
-                       }
-
-                       $where= 'AND';
-
-*/
-                       if ($filter == 'closed'):
-                       {
-                               $filtermethod .= " $where 
fm_tts_tickets.status='X'";
-                               $where = 'AND';
-                       }
-                       elseif($filter == ''):
-                       {
-                               $filtermethod .= " $where 
fm_tts_tickets.status='O'";
-                               $where = 'AND';
-                       }
-                       endif;
-
-                       if ($cat_id > 0)
-                       {
-                               $filtermethod .= " $where cat_id='$cat_id' ";
-                               $where = 'AND';
-                       }
-
-                       if ($district_id > 0)
-                       {
-                               $filtermethod .= " $where  
district_id='$district_id' ";
-                               $where = 'AND';
-                       }
-
-                       if($query)
-                       {
-                               if(stristr($query, '.'))
-                               {
-                                       $query=explode(".",$query);
-                                       $querymethod = " $where 
(fm_tts_tickets.loc1='" . $query[0] . "' AND fm_tts_tickets.loc4='" . $query[1] 
. "')";
-                               }
-                               else
-                               {
-                                       $query = ereg_replace("'",'',$query);
-                                       $query = ereg_replace('"','',$query);
-                                       $querymethod = " $where (subject LIKE 
'%$query%' or address LIKE '%$query%' or fm_tts_tickets.location_code LIKE 
'%$query%')";
-                               }
-                       }
-
-                       $sql = "SELECT fm_tts_tickets.*, fm_tts_category.descr 
as category,phpgw_accounts.account_lid as user_lid FROM fm_tts_tickets 
$this->join fm_tts_category on fm_tts_tickets.cat_id=fm_tts_category.id "
-                       . " $this->join phpgw_accounts on 
fm_tts_tickets.user_id=phpgw_accounts.account_id "
-                       . " $this->join fm_location1 on 
fm_tts_tickets.loc1=fm_location1.loc1 "
-                       . " $this->join fm_part_of_town on 
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id $filtermethod 
$querymethod";
-
-//echo $sql;
-                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
-                       $this->total_records = $dbresult2->_numOfRows;
-
-                       $maxmatchs = 15;
-
-                       if(!$allrows)
-                       {
-                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
-
-                       }
-                       else
-                       {
-                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
-                       }
-
-                       $i = 0;
-
-                       while (!$dbresult->EOF)
-                       {
-
-                               $tickets[$i]['id']                              
= $dbresult->fields['id'];
-                               $tickets[$i]['subject']                 = 
$dbresult->fields['subject'];
-                               $tickets[$i]['location_code']   = 
$dbresult->fields['location_code'];
-                               $tickets[$i]['user']                    = 
$dbresult->fields['user_lid'];
-                               $tickets[$i]['address']                 = 
$dbresult->fields['address'];
-                               $tickets[$i]['assignedto']              = 
$dbresult->fields['assignedto'];
-                               $tickets[$i]['status']                  = 
$dbresult->fields['status'];
-                               $tickets[$i]['priority']                = 
$dbresult->fields['priority'];
-                               $tickets[$i]['category']                = 
$dbresult->fields['category'];
-                               $tickets[$i]['group_id']                = 
$dbresult->fields['group_id'];
-                               $tickets[$i]['entry_date']              = 
$dbresult->fields['entry_date'];
-                               $tickets[$i]['finnish_date']    = 
$dbresult->fields['finnish_date'];
-                               $tickets[$i]['finnish_date2']   = 
$dbresult->fields['finnish_date2'];
-
-                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute("select count(*) from fm_tts_views where id='" . 
$dbresult->fields['id']
-                                       . "' and account_id='" . 
$GLOBALS['phpgw_data']['user']['id'] . "'");
-
-                               if (!$dbresult2->fields[0])
-                               {
-                                       $tickets[$i]['new_ticket'] = True;
-                               }
-
-                               $i++;
-                               $dbresult->MoveNext();
-
-                       }
-                       return $tickets;
-               }
-
-               function get_origin_entity_type()
-               {
-                       $sql = "SELECT fm_entity_origin.entity_id, 
fm_entity_origin.cat_id,name"
-                       . " FROM fm_entity_origin $this->join 
fm_entity_category on fm_entity_origin.entity_id=fm_entity_category.entity_id"
-                       . " AND fm_entity_origin.cat_id=fm_entity_category.id "
-                       . " WHERE origin ='tts' and tracking=1 group by 
fm_entity_origin.entity_id, fm_entity_origin.cat_id,name";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i=0;
-                       while (!$dbresult->EOF)
-                       {
-                               
$entity[$i]['entity_id']=$dbresult->fields['entity_id'];
-                               
$entity[$i]['cat_id']=$dbresult->fields['cat_id'];
-                               $entity[$i]['type']='entity';
-                               $uicols[]       = $dbresult->fields['name'];
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-
-                       $entity[$i]['type']='project';
-                       $uicols[]       = lang('project');
-
-                       $this->uicols   = $uicols;
-                       return $entity;
-               }
-
-               function get_child_date($id,$type,$entity_id='',$cat_id='')
-               {
-                       $table= 'fm_' . $type . '_origin';
-                       if($cat_id)
-                       {
-                               $and = " AND entity_id=$entity_id AND 
cat_id=$cat_id";
-                       }
-
-                       $sql = "SELECT * FROM $table  WHERE origin_id='$id' and 
origin ='tts' $and";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i=0;
-                       while (!$dbresult->EOF)
-                       {
-                               $date_info['date_info'][$i]['entry_date']= 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
-                               if($dbresult->fields['cat_id'])
-                               {
-                                       
$date_info['date_info'][$i]['link']=$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$entity_id.'&cat_id='
 . $cat_id . '&id=' . $dbresult->fields['id']);
-                                       
$date_info['date_info'][$i]['descr']=$this->soadmin_entity->read_category_name($entity_id,$cat_id);
-                               }
-                               else
-                               {
-                                       
$date_info['date_info'][$i]['link']=$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.ui'
 . $type . '.view&id=' . $dbresult->fields[$type . '_id']);
-                                       
$date_info['date_info'][$i]['descr']=lang($type);
-                               }
-
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-//html_print_r($date_info);
-                       return $date_info;
-               }
-
-               function read_single($id)
-               {
-                       $sql = "SELECT * FROM fm_tts_tickets WHERE id=$id";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       if (!$dbresult->EOF)
-                       {
-                               $ticket['assignedto']           = 
$dbresult->fields['assignedto'];
-                               $ticket['user_id']                      = 
$dbresult->fields['user_id'];
-                               $ticket['group_id']                     = 
$dbresult->fields['group_id'];
-                               $ticket['status']                       = 
$dbresult->fields['status'];
-                               $ticket['cat_id']                       = 
$dbresult->fields['cat_id'];
-                               $ticket['subject']                      = 
stripslashes($dbresult->fields['subject']);
-                               $ticket['priority']                     = 
$dbresult->fields['priority'];
-                               $ticket['details']                      = 
stripslashes($dbresult->fields['details']);
-                               $ticket['location_code']        = 
$dbresult->fields['location_code'];
-//                             $ticket['contact_phone']        = 
$dbresult->fields['contact_phone'];
-                               $ticket['address']                      = 
$dbresult->fields['address'];
-                               $ticket['tenant_id']            = 
$dbresult->fields['tenant_id'];
-                               $ticket['p_num']                        = 
$dbresult->fields['p_num'];
-                               $ticket['p_entity_id']          = 
$dbresult->fields['p_entity_id'];
-                               $ticket['p_cat_id']                     = 
$dbresult->fields['p_cat_id'];
-                               $ticket['finnish_date']         = 
$dbresult->fields['finnish_date'];
-                               $ticket['finnish_date2']        = 
$dbresult->fields['finnish_date2'];
-
-                               $user_id=(int)$dbresult->fields['user_id'];
-                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT account_firstname,account_lastname FROM 
phpgw_accounts WHERE account_id='$user_id' ");
-
-
-                               $ticket['user_name']    = 
$dbresult->fields['account_firstname'] . " " 
.$dbresult->fields['account_lastname'] ;
-
-                       }
-
-                       $sql = "SELECT * FROM fm_request_origin WHERE 
origin_id='$id' and origin ='tts'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i=0;
-                       while (!$dbresult->EOF)
-                       {
-                               $ticket['request_id'][$i]['id'] = 
$dbresult->fields['request_id'];
-                               $ticket['request_id'][$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-
-                       $sql = "SELECT * FROM fm_project_origin WHERE 
origin_id='$id' and origin ='tts'";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i=0;
-                       while (!$dbresult->EOF)
-                       {
-                               $ticket['project_id'][$i]['id'] = 
$dbresult->fields['project_id'];
-                               $ticket['project_id'][$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
-                               $i++;
-                               $dbresult->MoveNext();
-                       }
-
-                       $sql = "SELECT * FROM fm_entity_origin WHERE 
origin_id='$id' and origin ='tts' ORDER BY entity_id ASC";
-
-                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
-
-                       $i=0;
-                       $j=0;
-                       $entity_id=0;
-                       while (!$dbresult->EOF)
-                       {
-                               if(!$first)
-                               {
-                                       $boadmin_entity         = 
CreateObject($this->currentapp.'_boadmin_entity');
-                                       $entity         = 
$boadmin_entity->read_single($dbresult->fields['entity_id'],false);
-                                       $entity_id      = 
$dbresult->fields['entity_id'];
-                               }
-
-                               if($dbresult->fields['entity_id']==$entity_id)
-                               {
-                                       $ticket['entity'][$i]['name']   = 
$entity['name'];
-                                       
$ticket['entity'][$i]['link_info'][$j]['id']    = $dbresult->fields['id'];
-                                       
$ticket['entity'][$i]['link_info'][$j]['link']  = 
$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$dbresult->fields['entity_id'].'&cat_id='
 . $dbresult->fields['cat_id']);
-                                       
$ticket['entity'][$i]['link_info'][$j]['entry_date']    = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
-                                       $j++;
-                               }
-                               else
-                               {
-                                       $i++;
-                                       $j=0;
-                                       $entity         = 
$boadmin_entity->read_single($dbresult->fields['entity_id'],false);
-                                       $entity_id      = 
$dbresult->fields['entity_id'];
-                                       $ticket['entity'][$i]['name']   = 
$entity['name'];
-                                       
$ticket['entity'][$i]['link_info'][$j]['id']    = $dbresult->fields['id'];
-                                       
$ticket['entity'][$i]['link_info'][$j]['link']  = 
$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$dbresult->fields['entity_id'].'&cat_id='
 . $dbresult->fields['cat_id']);
-                                       
$ticket['entity'][$i]['link_info'][$j]['entry_date']    = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
-                                       $j++;
-                               }
-
-                               $first=True;
-                               $dbresult->MoveNext();
-                       }
-
-
-//html_print_r($ticket);
-//html_print_r($ticket['entity']);
-
-                       return $ticket;
-               }
-
-               function update_view($id='')
-               {
-                       // Have they viewed this ticket before ?
-                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) from fm_tts_views where id='$id' "
-                                       . "and account_id='" . 
$GLOBALS['phpgw_data']['user']['id'] . "'");
-
-
-                       if (! $dbresult->fields[0])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("INSERT into 
fm_tts_views (id,account_id,time) values ('$id','"
-                                       . $GLOBALS['phpgw_data']['user']['id'] 
. "','" . time() . "')");
-                       }
-               }
-
-               function add($ticket)
-               {
-                       while (is_array($ticket['location']) && 
list($input_name,$value) = each($ticket['location']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-
-
-                       while (is_array($ticket['extra']) && 
list($input_name,$value) = each($ticket['extra']))
-                       {
-                               if($value)
-                               {
-                                       $cols[] = $input_name;
-                                       $vals[] = $value;
-                               }
-                       }
-
-                       if($cols)
-                       {
-                               $cols   = "," . implode(",", $cols);
-                               $vals   = ",'" . implode("','", $vals) . "'";
-                       }
-
-                       if($ticket['street_name'])
-                       {
-                               $address[]= $ticket['street_name'];
-                               $address[]= $ticket['street_number'];
-                               $address        = implode(" ", $address);
-                       }
-
-                       if(!$address)
-                       {
-                               $address = $ticket['location_name'];
-                       }
-
-                       $values= array(
-                               $ticket['priority'],
-                               $GLOBALS['phpgw_data']['user']['id'],
-                               $ticket['assignedto'],
-                               $ticket['group_id'],
-                               $this->db->db_addslashes($ticket['subject']),
-                               $ticket['cat_id'],
-                               'O',
-                               $this->db->db_addslashes($ticket['details']),
-                               $ticket['location_code'],
-                               $address,
-                               time(),
-                               $ticket['finnish_date']);
-
-                       $values = $this->bocommon->validate_db_insert($values);
-                       $GLOBALS['phpgw']->db->begintrans();
-
-                       $GLOBALS['phpgw']->db->Execute("INSERT into 
fm_tts_tickets (priority,user_id,"
-                               . 
"assignedto,group_id,subject,cat_id,status,details,location_code,"
-                               . "address,entry_date,finnish_date $cols)"
-                               . "VALUES ($values $vals )");
-
-                       $id = 
$this->db->get_last_insert_id('fm_tts_tickets','id');
-                       if($ticket['extra']['contact_phone'])
-                       {
-                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $ticket['extra']['contact_phone']. "' where 
tenant_id='". $ticket['extra']['tenant_id']. "'");
-                       }
-
-                       if($GLOBALS['phpgw']->db->committrans())
-                       {
-                               $this->historylog->add('O',$id,mktime(),'');
-                               if($ticket['finnish_date'])
-                               {
-                                       
$this->historylog->add('IF',$id,$ticket['finnish_date'],'');
-                               }
-                       }
-
-                       $receipt['message'][0]=array('msg'=>lang('Ticket %1 has 
been saved',$id));
-                       $receipt['id']  = $id;
-                       return $receipt;
-               }
-
-       }
-?>
+<?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_sotts
+       {
+
+               function property_sotts()
+               {
+                       $this->currentapp       = 'property'; 
//$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->db                       = $GLOBALS['phpgw']->db;
+                       $this->db2                      = $this->db;
+                       $this->account          = 
$GLOBALS['phpgw_data']['user']['id'];
+                       $this->historylog       = 
CreateObject($this->currentapp.'_historylog','tts');
+                       $this->config           = 
CreateObject('phpgwapi_config');
+                       $this->bocommon         = 
CreateObject($this->currentapp.'_bocommon');
+                       $this->join                     = $this->bocommon->join;
+                       $this->soadmin_entity   = 
CreateObject($this->currentapp.'_soadmin_entity');
+                       $this->dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $this->fm_session       = 
CreateObject($this->currentapp.'_session');
+
+               }
+
+               function get_category_name($cat_id)
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
descr FROM fm_tts_category  WHERE id='$cat_id' ");
+
+
+
+                       return stripslashes($dbresult->fields['descr']);
+               }
+
+               function select_category_list()
+               {
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT id, 
descr FROM fm_tts_category  ORDER BY descr ");
+
+                       $i = 0;
+                       while (!$dbresult->EOF)
+                       {
+                               $categories[$i]['id']                           
= $dbresult->fields['id'];
+                               $categories[$i]['name']                         
= stripslashes($dbresult->fields['descr']);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+                       return $categories;
+               }
+
+
+               function read($data)
+               {
+
+                       if(is_array($data))
+                       {
+                               if ($data['start'])
+                               {
+                                       $start=$data['start'];
+                               }
+                               else
+                               {
+                                       $start=0;
+                               }
+                               $filter = 
(isset($data['filter'])?$data['filter']:'open');
+                               $query = 
(isset($data['query'])?$data['query']:'');
+                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
+                               $order = 
(isset($data['order'])?$data['order']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
+                               $district_id = 
(isset($data['district_id'])?$data['district_id']:0);
+                               $allrows = 
(isset($data['allrows'])?$data['allrows']:'');
+                       }
+
+//html_print_r($data);
+
+/*                     $this->grants   = 
$this->fm_session->appsession('grants_ticket',$this->currentapp);
+
+                       if(!$this->grants)
+                       {
+                               $this->acl2             = 
CreateObject($this->currentapp.'_acl2','##DEFAULT##','##DEFAULT##');
+                               $this->grants           = 
$this->acl2->get_grants($this->currentapp,'.ticket');
+                               
$this->fm_session->appsession('grants_ticket',$this->currentapp,$this->grants);
+                       }
+*/
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by fm_tts_tickets.id 
DESC';
+                       }
+
+                       $where= 'WHERE';
+
+/*                     $filtermethod = $where . ' ( fm_tts_tickets.user_id=' . 
$this->account;
+                       if (is_array($this->grants))
+                       {
+                               $grants = $this->grants;
+                               while (list($user) = each($grants))
+                               {
+                                       $public_user_list[] = $user;
+                               }
+                               reset($public_user_list);
+                               $filtermethod = " $where ( 
fm_tts_tickets.user_id IN(" . implode(',',$public_user_list) . "))";
+                       }
+
+                       $where= 'AND';
+
+*/
+                       if ($filter == 'closed'):
+                       {
+                               $filtermethod .= " $where 
fm_tts_tickets.status='X'";
+                               $where = 'AND';
+                       }
+                       elseif($filter == ''):
+                       {
+                               $filtermethod .= " $where 
fm_tts_tickets.status='O'";
+                               $where = 'AND';
+                       }
+                       endif;
+
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where cat_id='$cat_id' ";
+                               $where = 'AND';
+                       }
+
+                       if ($district_id > 0)
+                       {
+                               $filtermethod .= " $where  
district_id='$district_id' ";
+                               $where = 'AND';
+                       }
+
+                       if($query)
+                       {
+                               if(stristr($query, '.'))
+                               {
+                                       $query=explode(".",$query);
+                                       $querymethod = " $where 
(fm_tts_tickets.loc1='" . $query[0] . "' AND fm_tts_tickets.loc4='" . $query[1] 
. "')";
+                               }
+                               else
+                               {
+                                       $query = ereg_replace("'",'',$query);
+                                       $query = ereg_replace('"','',$query);
+                                       $querymethod = " $where (subject LIKE 
'%$query%' or address LIKE '%$query%' or fm_tts_tickets.location_code LIKE 
'%$query%')";
+                               }
+                       }
+
+                       $sql = "SELECT fm_tts_tickets.*, fm_tts_category.descr 
as category,phpgw_accounts.account_lid as user_lid FROM fm_tts_tickets 
$this->join fm_tts_category on fm_tts_tickets.cat_id=fm_tts_category.id "
+                       . " $this->join phpgw_accounts on 
fm_tts_tickets.user_id=phpgw_accounts.account_id "
+                       . " $this->join fm_location1 on 
fm_tts_tickets.loc1=fm_location1.loc1 "
+                       . " $this->join fm_part_of_town on 
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id $filtermethod 
$querymethod";
+
+//echo $sql;
+                       $dbresult2 = $GLOBALS['phpgw']->db->Execute($sql);
+                       $this->total_records = $dbresult2->_numOfRows;
+
+                       $maxmatchs = 15;
+
+                       if(!$allrows)
+                       {
+                               $dbresult = 
$GLOBALS['phpgw']->db->SelectLimit($sql . $ordermethod,$maxmatchs,$start);
+
+                       }
+                       else
+                       {
+                               $dbresult = $GLOBALS['phpgw']->db->Execute($sql 
. $ordermethod);
+                       }
+
+                       $i = 0;
+
+                       while (!$dbresult->EOF)
+                       {
+
+                               $tickets[$i]['id']                              
= $dbresult->fields['id'];
+                               $tickets[$i]['subject']                 = 
$dbresult->fields['subject'];
+                               $tickets[$i]['location_code']   = 
$dbresult->fields['location_code'];
+                               $tickets[$i]['user']                    = 
$dbresult->fields['user_lid'];
+                               $tickets[$i]['address']                 = 
$dbresult->fields['address'];
+                               $tickets[$i]['assignedto']              = 
$dbresult->fields['assignedto'];
+                               $tickets[$i]['status']                  = 
$dbresult->fields['status'];
+                               $tickets[$i]['priority']                = 
$dbresult->fields['priority'];
+                               $tickets[$i]['category']                = 
$dbresult->fields['category'];
+                               $tickets[$i]['group_id']                = 
$dbresult->fields['group_id'];
+                               $tickets[$i]['entry_date']              = 
$dbresult->fields['entry_date'];
+                               $tickets[$i]['finnish_date']    = 
$dbresult->fields['finnish_date'];
+                               $tickets[$i]['finnish_date2']   = 
$dbresult->fields['finnish_date2'];
+
+                               $dbresult2 = 
$GLOBALS['phpgw']->db->Execute("select count(*) from fm_tts_views where id='" . 
$dbresult->fields['id']
+                                       . "' and account_id='" . 
$GLOBALS['phpgw_data']['user']['id'] . "'");
+
+                               if (!$dbresult2->fields[0])
+                               {
+                                       $tickets[$i]['new_ticket'] = True;
+                               }
+
+                               $i++;
+                               $dbresult->MoveNext();
+
+                       }
+                       return $tickets;
+               }
+
+               function get_origin_entity_type()
+               {
+                       $sql = "SELECT fm_entity_origin.entity_id, 
fm_entity_origin.cat_id,name"
+                       . " FROM fm_entity_origin $this->join 
fm_entity_category on fm_entity_origin.entity_id=fm_entity_category.entity_id"
+                       . " AND fm_entity_origin.cat_id=fm_entity_category.id "
+                       . " WHERE origin ='tts' and tracking=1 group by 
fm_entity_origin.entity_id, fm_entity_origin.cat_id,name";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i=0;
+                       while (!$dbresult->EOF)
+                       {
+                               
$entity[$i]['entity_id']=$dbresult->fields['entity_id'];
+                               
$entity[$i]['cat_id']=$dbresult->fields['cat_id'];
+                               $entity[$i]['type']='entity';
+                               $uicols[]       = $dbresult->fields['name'];
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+
+                       $entity[$i]['type']='project';
+                       $uicols[]       = lang('project');
+
+                       $this->uicols   = $uicols;
+                       return $entity;
+               }
+
+               function get_child_date($id,$type,$entity_id='',$cat_id='')
+               {
+                       $table= 'fm_' . $type . '_origin';
+                       if($cat_id)
+                       {
+                               $and = " AND entity_id=$entity_id AND 
cat_id=$cat_id";
+                       }
+
+                       $sql = "SELECT * FROM $table  WHERE origin_id='$id' and 
origin ='tts' $and";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i=0;
+                       while (!$dbresult->EOF)
+                       {
+                               $date_info['date_info'][$i]['entry_date']= 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
+                               if($dbresult->fields['cat_id'])
+                               {
+                                       
$date_info['date_info'][$i]['link']=$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$entity_id.'&cat_id='
 . $cat_id . '&id=' . $dbresult->fields['id']);
+                                       
$date_info['date_info'][$i]['descr']=$this->soadmin_entity->read_category_name($entity_id,$cat_id);
+                               }
+                               else
+                               {
+                                       
$date_info['date_info'][$i]['link']=$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.ui'
 . $type . '.view&id=' . $dbresult->fields[$type . '_id']);
+                                       
$date_info['date_info'][$i]['descr']=lang($type);
+                               }
+
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+//html_print_r($date_info);
+                       return $date_info;
+               }
+
+               function read_single($id)
+               {
+                       $sql = "SELECT * FROM fm_tts_tickets WHERE id=$id";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       if (!$dbresult->EOF)
+                       {
+                               $ticket['assignedto']           = 
$dbresult->fields['assignedto'];
+                               $ticket['user_id']                      = 
$dbresult->fields['user_id'];
+                               $ticket['group_id']                     = 
$dbresult->fields['group_id'];
+                               $ticket['status']                       = 
$dbresult->fields['status'];
+                               $ticket['cat_id']                       = 
$dbresult->fields['cat_id'];
+                               $ticket['subject']                      = 
stripslashes($dbresult->fields['subject']);
+                               $ticket['priority']                     = 
$dbresult->fields['priority'];
+                               $ticket['details']                      = 
stripslashes($dbresult->fields['details']);
+                               $ticket['location_code']        = 
$dbresult->fields['location_code'];
+//                             $ticket['contact_phone']        = 
$dbresult->fields['contact_phone'];
+                               $ticket['address']                      = 
$dbresult->fields['address'];
+                               $ticket['tenant_id']            = 
$dbresult->fields['tenant_id'];
+                               $ticket['p_num']                        = 
$dbresult->fields['p_num'];
+                               $ticket['p_entity_id']          = 
$dbresult->fields['p_entity_id'];
+                               $ticket['p_cat_id']                     = 
$dbresult->fields['p_cat_id'];
+                               $ticket['finnish_date']         = 
$dbresult->fields['finnish_date'];
+                               $ticket['finnish_date2']        = 
$dbresult->fields['finnish_date2'];
+
+                               $user_id=(int)$dbresult->fields['user_id'];
+                               $dbresult = 
$GLOBALS['phpgw']->db->Execute("SELECT account_firstname,account_lastname FROM 
phpgw_accounts WHERE account_id='$user_id' ");
+
+
+                               $ticket['user_name']    = 
$dbresult->fields['account_firstname'] . " " 
.$dbresult->fields['account_lastname'] ;
+
+                       }
+
+                       $sql = "SELECT * FROM fm_request_origin WHERE 
origin_id='$id' and origin ='tts'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i=0;
+                       while (!$dbresult->EOF)
+                       {
+                               $ticket['request_id'][$i]['id'] = 
$dbresult->fields['request_id'];
+                               $ticket['request_id'][$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+
+                       $sql = "SELECT * FROM fm_project_origin WHERE 
origin_id='$id' and origin ='tts'";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i=0;
+                       while (!$dbresult->EOF)
+                       {
+                               $ticket['project_id'][$i]['id'] = 
$dbresult->fields['project_id'];
+                               $ticket['project_id'][$i]['entry_date'] = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
+                               $i++;
+                               $dbresult->MoveNext();
+                       }
+
+                       $sql = "SELECT * FROM fm_entity_origin WHERE 
origin_id='$id' and origin ='tts' ORDER BY entity_id ASC";
+
+                       $dbresult = $GLOBALS['phpgw']->db->Execute($sql);
+
+                       $i=0;
+                       $j=0;
+                       $entity_id=0;
+                       while (!$dbresult->EOF)
+                       {
+                               if(!$first)
+                               {
+                                       $boadmin_entity         = 
CreateObject($this->currentapp.'_boadmin_entity');
+                                       $entity         = 
$boadmin_entity->read_single($dbresult->fields['entity_id'],false);
+                                       $entity_id      = 
$dbresult->fields['entity_id'];
+                               }
+
+                               if($dbresult->fields['entity_id']==$entity_id)
+                               {
+                                       $ticket['entity'][$i]['name']   = 
$entity['name'];
+                                       
$ticket['entity'][$i]['link_info'][$j]['id']    = $dbresult->fields['id'];
+                                       
$ticket['entity'][$i]['link_info'][$j]['link']  = 
$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$dbresult->fields['entity_id'].'&cat_id='
 . $dbresult->fields['cat_id']);
+                                       
$ticket['entity'][$i]['link_info'][$j]['entry_date']    = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
+                                       $j++;
+                               }
+                               else
+                               {
+                                       $i++;
+                                       $j=0;
+                                       $entity         = 
$boadmin_entity->read_single($dbresult->fields['entity_id'],false);
+                                       $entity_id      = 
$dbresult->fields['entity_id'];
+                                       $ticket['entity'][$i]['name']   = 
$entity['name'];
+                                       
$ticket['entity'][$i]['link_info'][$j]['id']    = $dbresult->fields['id'];
+                                       
$ticket['entity'][$i]['link_info'][$j]['link']  = 
$this->bocommon->link('/index.php','sid=cookie&op='.$this->currentapp.'.uientity.view&entity_id='.$dbresult->fields['entity_id'].'&cat_id='
 . $dbresult->fields['cat_id']);
+                                       
$ticket['entity'][$i]['link_info'][$j]['entry_date']    = 
$GLOBALS['phpgw']->common->show_date($dbresult->fields['entry_date'],$this->dateformat);
+                                       $j++;
+                               }
+
+                               $first=True;
+                               $dbresult->MoveNext();
+                       }
+
+
+//html_print_r($ticket);
+//html_print_r($ticket['entity']);
+
+                       return $ticket;
+               }
+
+               function update_view($id='')
+               {
+                       // Have they viewed this ticket before ?
+                       $dbresult = $GLOBALS['phpgw']->db->Execute("SELECT 
count(*) from fm_tts_views where id='$id' "
+                                       . "and account_id='" . 
$GLOBALS['phpgw_data']['user']['id'] . "'");
+
+
+                       if (! $dbresult->fields[0])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("INSERT into 
fm_tts_views (id,account_id,time) values ('$id','"
+                                       . $GLOBALS['phpgw_data']['user']['id'] 
. "','" . time() . "')");
+                       }
+               }
+
+               function add($ticket)
+               {
+                       while (is_array($ticket['location']) && 
list($input_name,$value) = each($ticket['location']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+
+
+                       while (is_array($ticket['extra']) && 
list($input_name,$value) = each($ticket['extra']))
+                       {
+                               if($value)
+                               {
+                                       $cols[] = $input_name;
+                                       $vals[] = $value;
+                               }
+                       }
+
+                       if($cols)
+                       {
+                               $cols   = "," . implode(",", $cols);
+                               $vals   = ",'" . implode("','", $vals) . "'";
+                       }
+
+                       if($ticket['street_name'])
+                       {
+                               $address[]= $ticket['street_name'];
+                               $address[]= $ticket['street_number'];
+                               $address        = implode(" ", $address);
+                       }
+
+                       if(!$address)
+                       {
+                               $address = $ticket['location_name'];
+                       }
+
+                       $values= array(
+                               $ticket['priority'],
+                               $GLOBALS['phpgw_data']['user']['id'],
+                               $ticket['assignedto'],
+                               $ticket['group_id'],
+                               $this->db->db_addslashes($ticket['subject']),
+                               $ticket['cat_id'],
+                               'O',
+                               $this->db->db_addslashes($ticket['details']),
+                               $ticket['location_code'],
+                               $address,
+                               time(),
+                               $ticket['finnish_date']);
+
+                       $values = $this->bocommon->validate_db_insert($values);
+                       $GLOBALS['phpgw']->db->begintrans();
+
+                       $GLOBALS['phpgw']->db->Execute("INSERT into 
fm_tts_tickets (priority,user_id,"
+                               . 
"assignedto,group_id,subject,cat_id,status,details,location_code,"
+                               . "address,entry_date,finnish_date $cols)"
+                               . "VALUES ($values $vals )");
+
+                       $id = 
$this->db->get_last_insert_id('fm_tts_tickets','id');
+                       if($ticket['extra']['contact_phone'])
+                       {
+                               $GLOBALS['phpgw']->db->Execute("UPDATE 
fm_tenant set contact_phone='". $ticket['extra']['contact_phone']. "' where 
tenant_id='". $ticket['extra']['tenant_id']. "'");
+                       }
+
+                       if($GLOBALS['phpgw']->db->committrans())
+                       {
+                               $this->historylog->add('O',$id,mktime(),'');
+                               if($ticket['finnish_date'])
+                               {
+                                       
$this->historylog->add('IF',$id,$ticket['finnish_date'],'');
+                               }
+                       }
+
+                       $receipt['message'][0]=array('msg'=>lang('Ticket %1 has 
been saved',$id));
+                       $receipt['id']  = $id;
+                       return $receipt;
+               }
+
+       }
+?>




reply via email to

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