From 4edd9baad3f44313cc11b9f25a279391b8babab1 Mon Sep 17 00:00:00 2001 From: james Date: Fri, 11 Jun 2010 19:36:50 +0000 Subject: [PATCH] Working schedule event editor for adding, editing and removing events from the schedule. --- admin/schedule.php | 138 ++++++++++++++++++++++++++++++++++------ common.inc.php | 4 +- theme/default/sfiab.css | 25 +++----- 3 files changed, 131 insertions(+), 36 deletions(-) diff --git a/admin/schedule.php b/admin/schedule.php index 2c34c8d..6a4348f 100644 --- a/admin/schedule.php +++ b/admin/schedule.php @@ -29,7 +29,7 @@ $ROWHEIGHT=20; $BORDERSIZE=2; - if($_POST['date']) { + if($_GET['action']=="loadschedule") { $date=$_POST['date']; $starthour=$_POST['starthour']; $endhour=$_POST['endhour']; @@ -74,14 +74,6 @@ echo ""; foreach($locations AS $id=>$name) { echo ""; - /* - if($h==8&&$m==0&&$id==3) { - $height=4; - $pxheight=$height*25; - echo "
"; - echo "
"; - } - */ echo ""; } echo ""; @@ -94,10 +86,21 @@ //now make all our DIV's for the events that are scheduled in the database $x=0; //they will be moved by javascript after the fact - $q=mysql_query("SELECT * FROM schedule WHERE conferences_id='{$conference['id']}' AND date='{$date}'"); + $q=mysql_query("SELECT schedule.*, events.name FROM schedule JOIN events ON schedule.events_id=events.id WHERE schedule.conferences_id='{$conference['id']}' AND date='{$date}'"); + echo mysql_error(); while($r=mysql_fetch_object($q)) { - echo "
id}\">"; - print_r($r); + echo "
id}\" onclick=\"editEvent($r->id)\">"; + echo "
id)\">
\n"; + echo ""; + echo $r->name; + echo ""; + echo "
"; + $starttime=strtotime($r->hour.":".$r->minute); + $endtime=$starttime+$r->duration*60; + echo format_time($starttime); + echo " to "; + echo format_time($endtime); + echo "
"; $js.="eventdivs[$r->id]={hour:$r->hour,minute:$r->minute,location:$r->locations_id,duration:$r->duration};\n"; $x++; @@ -106,6 +109,38 @@ echo $js; echo ""; } + else if($_GET['action']=="loadevent") { + $id=intval($_GET['id']); + $q=mysql_query("SELECT * FROM schedule WHERE id='$id' AND conferences_id='{$conference['id']}'"); + if($r=mysql_fetch_array($q)) { + echo json_encode($r); + } + else + echo json_encode(array("id"=>0)); + exit; + } + else if($_GET['action']=="saveevent") { + $id=intval($_POST['id']); + if(!$id) { + mysql_query("INSERT INTO schedule (conferences_id) VALUES ('{$conference['id']}')"); + $id=mysql_insert_id(); + } + mysql_query("UPDATE schedule SET + date='".mysql_real_escape_string($_POST['date'])."', + hour='".mysql_real_escape_string($_POST['hour'])."', + minute='".mysql_real_escape_string($_POST['minute'])."', + duration='".mysql_real_escape_string($_POST['duration'])."', + events_id='".mysql_real_escape_string($_POST['event_id'])."', + locations_id='".mysql_real_escape_string($_POST['location_id'])."' + WHERE id='$id' AND conferences_id='{$conference['id']}'"); + echo mysql_error(); + exit; + } + else if($_GET['action']=="deleteevent") { + $id=intval($_POST['id']); + mysql_query("DELETE FROM schedule WHERE conferences_id='{$conference['id']}' AND id='{$id}'"); + exit; + } else { send_header("Schedule Management", @@ -118,21 +153,33 @@ $(document).ready(function() { $(".date").datepicker({ dateFormat: 'yy-mm-dd' }); changeDate(); + + /* Setup the editor dialog */ + $("#event_editor_dialog").dialog({ + bgiframe: true, autoOpen: false, + modal: true, resizable: false, + draggable: false, + buttons: { + "": function() { + $(this).dialog("close"); + }, + "": function() { + saveEvent(); + $(this).dialog("close"); + } + } + }); }); function changeDate() { - $("#schedulediv").load("schedule.php",{date:$("#date").val(),starthour:$("#starthour").val(),endhour:$("#endhour").val()},function() { + $("#schedulediv").load("schedule.php?action=loadschedule",{date:$("#date").val(),starthour:$("#starthour").val(),endhour:$("#endhour").val()},function() { placeEvents(); }); } function clickTableCell(t) { var p=$("#"+t.id).offset(); -// alert('You clicked in empty cell : '+t.id+' at top:'+position.top+' left:'+position.left); - $("#scheduleeventeditor").css(p); -// $("#scheduleeventeditor").width(150); -// $("#scheduleeventeditor").height(100); - $("#scheduleeventeditor").show(); + editEvent(null,t.id); } @@ -153,6 +200,58 @@ } ); } + + function editEvent(id,cell) { + if(id) { + var eventobj=eventdivs[id]; + $("#event_editor_dialog").dialog('option','title','Edit Event'); + + $.getJSON("schedule.php?action=loadevent&id="+id,function(json) { + $("#edit_schedule_id").val(json.id); + $("#edit_date").val(json.date); + $("#edit_hour").val(json.hour); + $("#edit_minute").val(json.minute); + $("#edit_duration").val(json.duration); + $("#edit_location").val(json.locations_id); + $("#edit_event").val(json.events_id); + }); + } + else { + $("#event_editor_dialog").dialog('option','title','Create Event'); + var a=cell.split("_"); + + $("#edit_schedule_id").val(0); + $("#edit_date").val($("#date").val()); + $("#edit_hour").val(a[0]); + $("#edit_minute").val(a[1]); + $("#edit_duration").val(60); + $("#edit_location").val(a[2]); + $("#edit_event").val(""); + + } + $("#event_editor_dialog").dialog('option','width',600); + $("#event_editor_dialog").dialog('option','height',400); + $("#event_editor_dialog").dialog('open'); + + } + + function saveEvent() { + var o=$("#edit_event_form").serializeArray(); + //alert(o); + $.post("schedule.php?action=saveevent",o,function() { + changeDate(); + }); + } + function deleteEvent(event,id) { + event.stopPropagation(); + + if(confirmClick('Are you sure you want to delete this event from the schedule?')) { + $.post('schedule.php?action=deleteevent',{id:id},function() { + changeDate(); + }); + } + return false; + }
-
+
+
"; } -function emit_hour_selector($name,$selected="") +function emit_hour_selector($name,$selected="",$extra) { if($selected!="") $selected=(int)$selected; - echo "\n"; echo "\n"; diff --git a/theme/default/sfiab.css b/theme/default/sfiab.css index e845ddd..7a49c34 100644 --- a/theme/default/sfiab.css +++ b/theme/default/sfiab.css @@ -510,7 +510,7 @@ ul.conferencenav li a:hover { .schedule td { border: 1px solid #CCCCCC; - height: 25px; + height: 20px; overflow: auto; } @@ -525,26 +525,21 @@ ul.conferencenav li a:hover { .scheduleevent { position: absolute; - border: 2px solid red; - background: orange; + border: 2px solid #777777; + background: #FFC143; width: 150px; margin:0; width: 148px; z-index: 1000; display: none; overflow: auto; - font-size: 0.75em; + font-size: 0.9em; + text-align: center; + cursor: pointer; } -#scheduleeventeditor { - position: absolute; - top: 100px; - left: 100px; - display: none; - background-color: orange; - border: 2px solid grey; - width: 148px; - height: 95px; - z-index: 1000; - +.scheduleevent_title { + font-weight: bold; + font-size: 1.2em; } +