Xataface 2.0
Xataface Application Framework
actions/ajax_save.php
Go to the documentation of this file.
00001 <?php
00025 class dataface_actions_ajax_save  {
00026 
00027         function handle($params){
00028         
00029                 
00030                 $app = Dataface_Application::getInstance();
00031                 $query = $app->getQuery();
00032                 try {
00033                 
00034                         if ( !@$_POST['--record_id'] ){
00035                                 throw new Exception("No record ID specified");
00036                         }
00037                         
00038                         $record = df_get_record_by_id($_POST['--record_id']);
00039                         if ( !$record ) throw new Exception("Record could not be found.", 404);
00040                         
00041                         $vals = array();
00042                         foreach ($query as $k=>$v){
00043                                 if ( $k and $k{0} != '-' ) $vals[$k] = $v;
00044                         }
00045                         
00046                         $record->setValues($vals);
00047                         //print_r($record->getPermissions());exit;
00048                         if ( !$record->checkPermission('ajax_save') ){
00049                                 throw new Exception("Permission Denied", 502);
00050                         }
00051                         if ( $record->recordChanged() ){
00052                                 $res = $record->save(null, true);
00053                                 if ( PEAR::isError($res) ){
00054                                         error_log($res->getMessage(), $res->getCode());
00055                                         throw new Exception("Failed to save record due to a server error.  See log for details.");
00056                                 }
00057                                 $msg = 'Successfully saved record.';
00058                         } else {
00059                                 $msg = 'Record is unchanged.';
00060                         }
00061                         
00062                         $this->out(array(
00063                                 'code' => 200,
00064                                 'message' => $msg,
00065                                 'recordId' => $record->getId()
00066                         ));
00067                 
00068                 } catch (Exception $ex){
00069                         $this->out(array(
00070                                 'code' => $ex->getCode(),
00071                                 'message' => $ex->getMessage()
00072                         ));
00073                 
00074                 }
00075                 
00076         }
00077         
00078         
00079         function out($params){
00080                 header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"');
00081                 $out = json_encode($params);
00082                 header('Content-Length: '.strlen($out));
00083                 header('Connection: close');
00084                 echo $out;
00085                 flush();
00086         }
00087 
00088 }
 All Data Structures Namespaces Files Functions Variables Enumerations