![]() |
Xataface Calendar Module 0.1
Full Calendar for Xataface
|
00001 <?php 00002 class actions_calendar_event_resized { 00003 function handle($params){ 00004 00005 $app = Dataface_Application::getInstance(); 00006 00007 try { 00008 if ( !@$_POST['-calendar-event-id'] ){ 00009 throw new Exception("No calendar event id provided", 500); 00010 } 00011 00012 $record = df_get_record_by_id($_POST['-calendar-event-id']); 00013 if ( !$record ){ 00014 throw new Exception("The specified event could not be found", 404); 00015 00016 } 00017 00018 if ( !$record->checkPermission('edit') ){ 00019 throw new Exception("Failed to move the event because you don't have sufficient permissions.", 400); 00020 00021 } 00022 00023 import('Dataface/Ontology.php'); 00024 00025 Dataface_Ontology::registerType('CalendarEvent', dirname(__FILE__).'/../ontologies/CalendarEvent.php', 'Dataface_Ontology_CalendarEvent'); 00026 $ontology =& Dataface_Ontology::newOntology('CalendarEvent', $record->_table->tablename); 00027 00028 00029 00030 $endAtt = $ontology->getFieldname('end'); 00031 if ( PEAR::isError($endAtt) ) throw new Exception('Failed to find start time field in this event.', 500); 00032 00033 if ( !$record->checkPermission('edit', array('field'=>$endAtt)) ){ 00034 throw new Exception('Failed to move record because you don\'t have permission to change the end time field.', 400); 00035 00036 } 00037 00038 00039 00040 if ( @$_POST['-calendar-day-delta'] ){ 00041 $dateDelta = intval($_POST['-calendar-day-delta']); 00042 $deltaSign = '+'; 00043 if ( $dateDelta<0 ) $deltaSign='-'; 00044 $dateDelta = abs($dateDelta); 00045 00046 00047 00048 $currEnd = $record->strval($endAtt); 00049 $newEnd = date('Y-m-d H:i:s', strtotime($deltaSign.$dateDelta.' day', strtotime($currEnd))); 00050 //echo $deltaSign.$dateDelta.' ('.$newDate.')';exit; 00051 //$record->setValue($dateAtt, $newDate); 00052 $record->setValues(array( 00053 $endAtt=>$newEnd 00054 )); 00055 00056 00057 } 00058 00059 00060 if ( @$_POST['-calendar-minute-delta'] ){ 00061 $minuteDelta = intval($_POST['-calendar-minute-delta']); 00062 $deltaSign = '+'; 00063 if ( $minuteDelta<0 ) $deltaSign = '-'; 00064 $minuteDelta = $deltaSign.(abs($minuteDelta)); 00065 00066 00067 00068 00069 $currEnd = $record->strval($endAtt); 00070 00071 $newEnd = date('Y-m-d H:i:s', strtotime($minuteDelta.' minutes', strtotime($currEnd))); 00072 00073 $record->setValues(array( 00074 $endAtt=>$newEnd 00075 )); 00076 00077 } 00078 00079 //echo $endAtt;exit; 00080 00081 $res = $record->save(null, true); 00082 if ( PEAR::isError($res) ){ 00083 error_log($res->toString()); 00084 throw new Exception("Failed to update event due to an error while saving. Please see server error log for details.", 500); 00085 } 00086 00087 00088 // At this point, presumeably the event has been updated 00089 $this->out(array( 00090 'code'=>200, 00091 'message'=>'Event updated successfully' 00092 )); 00093 exit; 00094 00095 00096 00097 00098 } catch (Exception $ex){ 00099 00100 $this->out(array( 00101 'message'=>$ex->getMessage(), 00102 'code'=>$ex->getCode() 00103 )); 00104 exit; 00105 } 00106 00107 00108 } 00109 00110 00111 function out($params){ 00112 header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"'); 00113 echo json_encode($params); 00114 } 00115 }