phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] api/class.base.php, 1.1.1.1.2.29


From: nomail
Subject: [Phpgroupware-cvs] api/class.base.php, 1.1.1.1.2.29
Date: Thu, 20 May 2004 20:52:06 -0000

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

date: 2004/04/18 08:05:26;  author: jengo;  state: Exp;  lines: +123 -15

Log Message:
Added in support for history rollbacks on an item, in order for an app to 
support this there are some strict guidelines
=====================================================================
No syntax errors detected in -
=====================================================================
Index: api/class.base.php
diff -u api/class.base.php:1.1.1.1.2.28 api/class.base.php:1.1.1.1.2.29
--- api/class.base.php:1.1.1.1.2.28     Fri Apr 16 20:59:48 2004
+++ api/class.base.php  Sun Apr 18 08:05:26 2004
@@ -27,24 +27,28 @@
        /* $Source$ */
 
        $functions             = array();
-       $functions['api_base'] = array(
+       $functions['api_base'] = array
+       (
                'type'         => 'public',
                'abstract'     => 'Main page for everything',
                'discussion'   => 'Default main page'
        );
        
-       $functions['start']    = array(
+       $functions['start']    = array
+       (
                'type'         => 'public',
                'title'        => 'Home',
                'abstract'     => 'Main page for everything',
                'discussion'   => 'Default main page'
        );
 
-       $functions['profile']   = array(
+       $functions['profile']   = array
+       (
                'type'         => 'public',
                'title'        => 'Update profile',
                'abstract'     => 'Update user profile',
-               'params'       => array(
+               'params'       => array
+               (
                        'profile_firstname'         => array('type' => 'any', 
'default' => NOTSET, 'desc' => 'First Name'),
                        'profile_lastname'          => array('type' => 'any', 
'default' => NOTSET, 'desc' => 'Last Name'),
                        'profile_password'          => array('type' => 'any', 
'default' => NOTSET, 'desc' => 'Password'),
@@ -52,49 +56,70 @@
                )
        );
 
-       $functions['about']    = array(
+       $functions['about']    = array
+       (
                'type'         => 'public',
                'title'        => 'About',
                'abstract'     => 'About data for the API.'
        );
 
-       $functions['login']    = array(
+       $functions['login']    = array
+       (
                'type'         => 'public',
                'title'        => 'Login',
                'abstract'     => 'Login to the system.'
        );
 
-       $functions['logout']   = array(
+       $functions['logout']   = array
+       (
                'type'         => 'public',
                'title'        => 'Logout',
                'abstract'     => 'Logout from the system. Will revert user 
back into anonymous session.'
        );
 
-       $functions['config']   = array(
+       $functions['history_rollback'] = array
+       (
+               'type'         => 'public',
+               'title'        => 'History rollback',
+               'abstract'     => 'Used to rollback an item to a previous 
state',
+               'params'       => array
+               (
+                       'location'    => array('type' => 'string', 'default' => 
REQUIRED, 'desc' => 'History location'),
+                       'history_id'  => array('type' => 'number', 'default' => 
REQUIRED, 'desc' => 'History ID number'),
+                       'answer'      => array('type' => 'string', 'default' => 
REQUIRED, 'desc' => 'Answer to the delete widget'),
+               )
+       );
+
+       $functions['config']   = array
+       (
                'type'         => 'public',
                'title'        => 'Configuration',
                'abstract'     => 'Configuration section',
                'discussion'   => 'This is used by all apps to create a generic 
configuration for there application',
-               'params'       => array(
+               'params'       => array
+               (
                        'location'    => array('type'=>'string', 'default' => 
REQUIRED, 'desc' => 'Location for there config'),
                        'form_submit' => array('type'=>'any',    'default' => 
NOTSET,   'desc' => 'Set if the user is submitting'),
                        'new_config'  => array('type'=>'any',    'default' => 
NOTSET,   'desc' => 'Values submitted from the form')
                )
        );
        
-       $functions['prefs']    = array(
+       $functions['prefs']    = array
+       (
                'type'         => 'public',
                'title'        => 'Preferences',
                'abstract'     => 'Preferences section',
                'discussion'   => 'This is used by all apps to present 
preferences choices to users.',
-               'params'       => array(
+               'params'       => array
+               (
                        'appname'     => array('type'=>'string', 'default' => 
REQUIRED, 'desc' => 'app to display prefs for'),
                        'form_submit' => array('type'=>'any',    'default' => 
NOTSET,  'desc' => 'Set if the user is submitting'),
                        'new_prefs'   => array('type'=>'any',    'default' => 
NOTSET,  'desc' => 'Values submitted from the form')
                )
        );
 
-       $GLOBALS['docs']['api']['classes']['api_base'] = array(
+       $GLOBALS['docs']['api']['classes']['api_base'] = array
+       (
                'abstract'  => 'Default class for the api ops',
                'functions' => $functions
        );
@@ -435,7 +460,90 @@
                        $GLOBALS['phpgw']->add_xsl('api.cron');
                        $GLOBALS['phpgw']->finish(false);
                }
-               
+
+               // TODO: Create a way to show the apps "view" screen right 
under the
+               // yesno dialog, it must be transparent to the app
+               function history_rollback()
+               {
+                       $args = new safe_args();
+                       $args->set('location',REQUIRED,'string');
+                       $args->set('history_id',REQUIRED,'number');
+                       $args->set('answer',NOVAR,'any');
+                       $args = $args->get(func_get_args());
+
+                       list($app,$class,$id) = explode('.',$args['location']);
+                       $values               = execMethod($app . '.' . $class 
. '._read',$id);
+
+                       $GLOBALS['phpgw']->add_xsl('api.widgets');
+                       if ($args['answer'] == NOVAR)
+                       {
+                               // Make sure the record exists
+                               if (! is_array($values))
+                               {
+                                       $GLOBALS['msgbox']->add(lang('Record 
not found'),'notice');
+                                       return array();
+                               }
+
+                               $result['dialog'] = array(
+                                       'question' => lang('Are you sure you 
want to rollback the changes on this item ?'),
+                                       'yes_op'   => 
'api.base.history_rollback',
+                                       'no_op'    => 'api.statecache.cancel',
+                                       'current_inputs' => array(
+                                               0 => array(
+                                                       'name'  => 'location',
+                                                       'value' => 
$args['location']
+                                               ),
+                                               1 => array
+                                               (
+                                                       'name'  => 'history_id',
+                                                       'value' => 
$args['history_id']
+                                               )
+                                       )
+                               );
+
+                               $result['action_type'] = 'api_history_rollback';
+                       }
+                       else if ($args['answer'] == 'Yes')
+                       {
+                               // The order here is very important.  We have 
to cycle through all the updates
+                               // durring this period, in case some fields 
where updated in the middle of the
+                               // history set.
+                               $dbresult = 
$GLOBALS['phpgw']->db->execute("SELECT * from phpgw_history where 
history_location='"
+                                       . $args['location'] . "' AND history_id 
> " . $args['history_id']
+                                       . " ORDER BY history_timestamp DESC");
+
+                               while (! $dbresult->EOF)
+                               {
+                                       // If its the first record, we need to 
use the new value
+                                       if ($dbresult->fields['history_action'] 
== 'C')
+                                       {
+                                               $v = 
$dbresult->fields['history_n_value'];
+                                       }
+                                       else
+                                       {
+                                               $v = 
$dbresult->fields['history_o_value'];
+                                       }
+
+                                       
$values[$dbresult->fields['history_field']] = $v;
+                                       $dbresult->movenext();
+                               }
+                               $values['id'] = $id;
+
+                               if (execMethod($app . '.' . $class . 
'._update',$values))
+                               {
+                                       $GLOBALS['msgbox']->add(lang('Item has 
been successfully rolled back'),'notice');
+                               }
+                               else
+                               {
+                                       $GLOBALS['msgbox']->add(lang('There was 
a problem rolling back this item'),'warning');
+                               }
+
+                               return execMethod($app . '.' . $class . 
'.view',$id);
+                       }
+
+                       return $result;
+               }
+
                function prefs()
                {
                        $args = new safe_args();




reply via email to

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