Xataface 2.0
Xataface Application Framework
actions/history_restore_record.php
Go to the documentation of this file.
00001 <?php
00002 class dataface_actions_history_restore_record {
00003 
00004         function handle(&$params){
00005         
00006                 if ( !@$_POST['history__id'] ) return PEAR::raiseError("No history id specified", DATAFACE_E_ERROR);
00007                 $historyid = $_POST['history__id'];
00008                 if ( !preg_match('/\d+/', $historyid) ) return PEAR::raiseError("Invalid history id provided.", DATAFACE_E_ERROR);
00009                 
00010                 $app =& Dataface_Application::getInstance();
00011                 $record =& $app->getRecord();
00012                 if ( !$record ) return PEAR::raiseError("No record was specified", DATAFACE_E_ERROR);
00013                 
00014                 import("Dataface/HistoryTool.php");
00015                 $ht = new Dataface_HistoryTool();
00016                 $hrecord = $ht->getRecordById($record->_table->tablename, $historyid);
00017                 
00018                 // make sure that this history record matches the current record.
00019                 $keys = array_keys($record->_table->keys());
00020                 if ( $record->strvals($keys) != $hrecord->strvals($keys) ) 
00021                         return PEAR::raiseError("Attempt to restore record history from unmatching history record.", DATAFACE_E_ERROR);
00022                         
00023                 
00024                 // Now that we are convinced that we have the correct record, we can restore it.
00025                 if ( @$_POST['-fieldname'] ) $fieldname = $_POST['-fieldname'];
00026                 else $fieldname = null;
00027                 $res = $ht->restore($record, $historyid, $fieldname);
00028                 
00029                 if ( PEAR::isError($res) ) return $res;
00030                 
00031                 $url = false; //$app->getPreviousUrl(true);
00032                 if ( @$_POST['-locationid'] ) $url = DATAFACE_SITE_HREF.'?'.$app->decodeLocation($_POST['-locationid']);
00033 
00034                 if ( !$url ){
00035                         // If the url is not specified we will just create a url to return
00036                         // to the specified record's history listing.
00037                         $url = $record->getURL('-action=history');
00038                 
00039                 }
00040                 
00041                 if ( $fieldname ){
00042                         $msg = "Field '$fieldname' successfully restored to its value from '".$hrecord->strval('history__modified')."'.";
00043                 } else {
00044                         $msg = "Record successfully restored to its value from '".$hrecord->strval('history__modified')."'.";
00045                 }
00046                 $url .= "&--msg=".urlencode($msg);
00047                 
00048                 $app->redirect($url);
00049                 
00050         }
00051 
00052 }
00053 
00054 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations