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