phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/inc/class.historylog.inc.php, 1.2


From: nomail
Subject: [Phpgroupware-cvs] property/inc/class.historylog.inc.php, 1.2
Date: Wed, 2 Jun 2004 20:54:28 +0200

Update of /property/inc
Added Files:
        Branch: 
          class.historylog.inc.php

date: 2004/06/02 18:54:28;  author: sigurdne;  state: Exp;  lines: +137 -0

Log Message:
no message
=====================================================================
<?php
        
/**************************************************************************\
        * phpGroupWare API - Record history logging                             
   *
        * This file written by Joseph Engo <address@hidden>                *
        * Copyright (C) 2001 Joseph Engo                                        
   *
        * 
-------------------------------------------------------------------------*
        * This library is part of the phpGroupWare API                          
   *
        * http://www.phpgroupware.org/api                                       
   *
        * 
------------------------------------------------------------------------ *
        * This library is free software; you can redistribute it and/or modify 
it  *
        * under the terms of the GNU Lesser General Public License as published 
by *
        * the Free Software Foundation; either version 2.1 of the License,      
   *
        * or any later version.                                                 
   *
        * This library is distributed in the hope that it will be useful, but   
   *
        * WITHOUT ANY WARRANTY; without even the implied warranty of            
   *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  
   *
        * See the GNU Lesser General Public License for more details.           
   *
        * You should have received a copy of the GNU Lesser General Public 
License *
        * along with this library; if not, write to the Free Software 
Foundation,  *
        * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA         
   *
        
\**************************************************************************/

        /* $Id: class.historylog.inc.php,v 1.2 2004/06/02 18:54:28 sigurdne Exp 
$ */

        class historylog
        {
                var $db;
                var $appname;
                var $table;
                var $types = array(
                        'C' => 'Created',
                        'D' => 'Deleted',
                        'E' => 'Edited'
                );
                var $alternate_handlers = array();

                function historylog($appname)
                {
                        if (! $appname)
                        {
                                $appname = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
                        }

                        switch($appname)
                        {
                                case 'request':
                                        $this->table='fm_request_history';
                                        break;
                                case 'workorder':
                                        $this->table='fm_workorder_history';
                                        break;
                                case 'project':
                                        $this->table='fm_project_history';
                                        break;
                                case 'tts':
                                        $this->table='fm_tts_history';
                                        break;
                                case 'drawing':
                                        $this->table='fm_drawing_history';
                                        break;
                                case 'document':
                                        $this->table='fm_document_history';
                                        break;
                        }


                        $this->appname = $appname;
                        $this->db      = $GLOBALS['phpgw']->db;
                }

                function delete($record_id)
                {
                        $this->db->query("delete from $this->table where 
history_record_id='$record_id' and "
                                . "history_appname='" . $this->appname . 
"'",__LINE__,__FILE__);
                }

                function add($status,$record_id,$new_value)
                {
                        $this->db->query("insert into $this->table 
(history_record_id,"
                                . 
"history_appname,history_owner,history_status,history_new_value,history_timestamp)
 "
                                . "values ('$record_id','" . $this->appname . 
"','"
                                . $GLOBALS['phpgw_info']['user']['account_id'] 
. "','$status','"
                                . addslashes($new_value) . "','" . 
$this->db->to_timestamp(time())
                                . "')",__LINE__,__FILE__);
                }

                // array $filter_out
                function return_array($filter_out,$only_show,$_orderby = 
'',$sort = '', $record_id)
                {

                        if (! $sort || ! $_orderby)
                        {
                                $orderby = 'order by 
history_timestamp,history_id';
                        }
                        else
                        {
                                $orderby = "order by $_orderby $sort";
                        }

                        while (is_array($filter_out) && list(,$_filter) = 
each($filter_out))
                        {
                                $filtered[] = "history_status != '$_filter'";
                        }

                        if (is_array($filtered))
                        {
                                $filter = ' and ' . implode(' and ',$filtered);
                        }

                        while (is_array($only_show) && list(,$_filter) = 
each($only_show))
                        {
                                $_only_show[] = "history_status='$_filter'";
                        }

                        if (is_array($_only_show))
                        {
                                $only_show_filter = ' and (' . implode(' or 
',$_only_show) . ')';
                        }

                        $this->db->query("select * from $this->table where 
history_appname='"
                                . $this->appname . "' and 
history_record_id='$record_id' $filter $only_show_filter "
                                . "$orderby",__LINE__,__FILE__);
                        while ($this->db->next_record())
                        {
                                $return_values[] = array(
                                        'id'         => 
$this->db->f('history_id'),
                                        'record_id'  => 
$this->db->f('history_record_id'),
                                        'owner'      => 
$GLOBALS['phpgw']->accounts->id2name($this->db->f('history_owner')),
//                                      'status'     => 
lang($this->types[$this->db->f('history_status')]),
                                        'status'     => ereg_replace(' 
','',$this->db->f('history_status')),
                                        'new_value'  => 
$this->db->f('history_new_value'),
                                        'datetime'   => 
$this->db->from_timestamp($this->db->f('history_timestamp'))
                                );
                        }
                        return $return_values;
                }
        }




reply via email to

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