phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/class.history.php, 1.1.2.13


From: nomail
Subject: [Phpgroupware-cvs] api/class.history.php, 1.1.2.13
Date: Fri, 9 Jul 2004 08:44:56 +0200

Update of /api
Modified Files:
        Branch: proposal-branch
          class.history.php

date: 2004/07/09 06:44:56;  author: jengo;  state: Exp;  lines: +69 -25

Log Message:
Created a method to add duplicate keys to a history item, simply create your 
keys like <key>##TOBEREMOVED##<unique_value> and it will be stripped to <key>
=====================================================================
Index: api/class.history.php
diff -u api/class.history.php:1.1.2.12 api/class.history.php:1.1.2.13
--- api/class.history.php:1.1.2.12      Sat May  8 06:00:10 2004
+++ api/class.history.php       Fri Jul  9 06:44:56 2004
@@ -28,13 +28,15 @@
        {
                // These are stock generic types, applications can specify 
there own
                // However, applications should NEVER re-assign the default 
stock ones
-               var $actions = array(
+               var $actions = array
+               (
                        'C' => 'Create',
                        'D' => 'Delete',
                        'U' => 'Update'
                );
-               var $field_desc       = array();
-               var $field_execMethod = array();
+
+               var $field_desc              = array();
+               var $field_execMethod        = array();
                var $account_id;
 
                function api_history()
@@ -60,8 +62,17 @@
                                }
                                else
                                {
-                                       $old_value = 
$dbresult->fields['history_o_value'];
-                                       $new_value = 
$dbresult->fields['history_n_value'];
+                                       if (! isset($old_value) && ! 
isset($new_value))
+                                       {
+                                               $old_value = 
$dbresult->fields['history_o_value'];
+                                               $new_value = 
$dbresult->fields['history_n_value'];
+                                       }
+                               }
+
+                               $field_name = '';
+                               if 
($this->field_desc[$dbresult->fields['history_field']])
+                               {
+                                       $field_name = 
$this->field_desc[$dbresult->fields['history_field']];
                                }
 
                                $owner = 
$GLOBALS['phpgw']->accounts->cross_reference((int)$dbresult->fields['history_owner']);
@@ -69,7 +80,7 @@
                                (
                                        'id'        => 
$dbresult->fields['history_id'],
                                        'owner'     => ($owner ? $owner : 
lang('Unknown')),
-                                       'field'     => 
($this->field_desc[$dbresult->fields['history_field']] ? 
$this->field_desc[$dbresult->fields['history_field']] : 
$dbresult->fields['history_field']),
+                                       'field'     => ($field_name ? 
$field_name : $dbresult->fields['history_field']),
                                        'action'    => 
lang($this->actions[$dbresult->fields['history_action']]),
                                        'new_value' => stripslashes($new_value),
                                        'old_value' => stripslashes($old_value),
@@ -85,18 +96,11 @@
                {
                        $args = new safe_args();
                        $args->set('location',REQUIRED,'string');
-                       $args->set('new_data',REQUIRED,'any');
-                       $args->set('old_data',REQUIRED,'any');
+                       $args->set('new_data',REQUIRED,'array');
+                       $args->set('old_data',REQUIRED,'array');
                        $args->set('action',NOTSET,'any');
                        $args = $args->get(func_get_args());
 
-                       // FIXME: Can safe_args handle this ? (jengo)
-                       if (! is_array($args['old_data']) || ! 
is_array($args['new_data']))
-                       {
-                               $GLOBALS['msgbox']->add(lang('New or old data 
passed to api.history.set is not an array type'), 'debug');
-                               return;
-                       }
-
                        $timestamp = time();
                        $GLOBALS['phpgw']->db->begintrans();
 
@@ -104,10 +108,32 @@
                        {
                                foreach ($args['new_data'] as $key => $value)
                                {
-                                       $GLOBALS['phpgw']->db->Execute("insert 
into phpgw_history 
(history_owner,history_location,history_field,history_action,"
-                                               . 
"history_n_value,history_timestamp) values ('" . $this->account_id . "','"
-                                               . $args['location'] . "','" . 
$key . "','C','" . addslashes($value) . "',"
-                                               . 
$GLOBALS['phpgw']->db->dbtimestamp($timestamp) . ")");
+                                       if (ereg('##TOBEREMOVED##',$key))
+                                       {
+                                               list($key) = 
explode('##TOBEREMOVED##',$key,2);
+                                       }
+
+                                       $GLOBALS['phpgw']->db->Execute("
+                                               INSERT INTO
+                                                       phpgw_history
+                                               (
+                                                       history_owner,
+                                                       history_location,
+                                                       history_field,
+                                                       history_action,
+                                                       history_n_value,
+                                                       history_timestamp
+                                               )
+                                               VALUES
+                                               (
+                                                       '" . $this->account_id 
. "',
+                                                       '" . $args['location'] 
. "',
+                                                       '" . $key . "',
+                                                       'C',
+                                                       '" . addslashes($value) 
. "',
+                                                       " . 
$GLOBALS['phpgw']->db->dbtimestamp($timestamp) . "
+                                               )
+                                       ");
                                }
                        }
                        else
@@ -122,11 +148,29 @@
                                {
                                        if ($args['old_data'][$new_key] != 
$new_value)
                                        {
-                                               
$GLOBALS['phpgw']->db->Execute("insert into phpgw_history 
(history_owner,history_location,history_field,"
-                                                       . 
"history_action,history_o_value,history_n_value,history_timestamp) values ('"
-                                                       . $this->account_id . 
"','" . $args['location'] . "','" . $new_key
-                                                       . "','$action','" . 
addslashes($args['old_data'][$new_key]) . "','" . addslashes($new_value) . "',"
-                                                       . 
$GLOBALS['phpgw']->db->dbtimestamp($timestamp) . ")");
+                                               $GLOBALS['phpgw']->db->Execute("
+                                                       INSERT INTO
+                                                               phpgw_history
+                                                       (
+                                                               history_owner,
+                                                               
history_location,
+                                                               history_field,
+                                                               history_action,
+                                                               history_o_value,
+                                                               history_n_value,
+                                                               
history_timestamp
+                                                       )
+                                                       VALUES
+                                                       ('
+                                                               " . 
$this->account_id . "',
+                                                               '" . 
$args['location'] . "',
+                                                               '" . $new_key . 
"',
+                                                               '" . $action . 
"',
+                                                               '" . 
addslashes($args['old_data'][$new_key]) . "',
+                                                               '" . 
addslashes($new_value) . "',
+                                                               " . 
$GLOBALS['phpgw']->db->dbtimestamp($timestamp) . "
+                                                       )
+                                               ");
                                        }
                                }
                        }




reply via email to

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