bradkenyon Posted July 24, 2007 Share Posted July 24, 2007 I am trying to create an update function for an event calendar. This is something I did not create original. I will list the code for the insert event and delete event, in hopes of someone helping me creating a update event function. i've narrowed it down to this file and the update event function as the one i need to work to get this update setting up and running. any help is appreciated. here is the insert event code function insert_event () { //$app = 'N'; // BUG hardcoded approval & 104 event limit $app = $_POST['D_approved']; if (!validate_event('add')) return false; list($y,$m,$d) = explode("-",$_POST['D_sdate']); $startstamp = mktime(0,0,0,$m,$d,$y); if (($_POST['D_edate'] == '') || (get_timestamp($_POST['D_sdate']) > get_timestamp($_POST['D_edate'])) ) list($y2,$m2,$d2) = explode("-",$_POST['D_sdate']); else list($y2,$m2,$d2) = explode("-",$_POST['D_edate']); $endstamp = mktime(0,0,0,$m2,$d2,$y2); $gid = -1; // group id $eday=0; $next=$_POST['D_frequency']; for($n=0;($n<104) && ($startstamp <= $endstamp);$n++) { $id = db_ins_event($_POST['D_name'], $gid, $_POST['D_category'], $_POST['D_description'], $_POST['D_moreinfo'], $_POST['D_moreurl'], date("Y-m-d",$startstamp), $app); if ($gid == -1) $gid = $id; $eday += $next; $startstamp = mktime(0,0,0,$m,$d+$eday,$y); } $_SESSION['DMSG']->set_notice('New Event has been added.'); return true; } here is the delete event code function delete_event ($id) { if (!isset($id)) { $q = new DB_Q; $q->query(sprintf("SELECT oid FROM d_forms WHERE fid = '%s'",$_POST['D_fid'])); $q->next_record(); $id = $q->f('oid'); } if (!validate_event('del',$id,'')) return false; // BUG: reserved for future use $q = new DB_Q; if ($_POST['D_grouped'] == 'Y') { // update all grouped events with this one $q->query(sprintf("select group_id from events where id = %d",$id)); $q->next_record(); $q->query(sprintf("select id from events where group_id = %d",$q->f('group_id'))); while ($q->next_record()) db_del_event($q->f('id')); } else { db_del_event($id); } $_SESSION['DMSG']->set_notice('Event has been removed.'); return true; } here is the update event code, well...it doesn't work, but what i have tried to put together for it to work - as you can see, i just copied and pasted the delete event function in there and made a couple modifications. function update_event ($id) { //if (!validate_event('upd',$id,'')) return false; // BUG: reserved for future use //$_SESSION['DMSG']->set_notice('Event has been updated.'); //return true; if (!isset($id)) { $q = new DB_Q; $q->query(sprintf("SELECT oid FROM d_forms WHERE fid = '%s'",$_POST['D_fid'])); $q->next_record(); $id = $q->f('oid'); } if (!validate_event('upd',$id,'')) return false; // BUG: reserved for future use $q = new DB_Q; if ($_POST['D_grouped'] == 'Y') { // update all grouped events with this one $q->query(sprintf("select group_id from events where id = %d",$id)); $q->next_record(); $q->query(sprintf("select id from events where group_id = %d",$q->f('group_id'))); while ($q->next_record()) db_upd_event($q->f('id')); } else { //db_del_event($id); echo 'db_del_event(id)'; } $_SESSION['DMSG']->set_notice('Event has been updated.'); return true; } here is the validate event code, just in case you wanted a look at that function validate_event ($op,$id) { $ok = true; switch ($op) { case 'add': if ($_POST['D_sdate'] == '') { $_SESSION['DMSG']->set_error('Error: Must choose an event date.'); $ok = false; } break; case 'upd': case 'del': break; } return $ok; } here is the db_del_event code function db_del_event ($id) { $q = new DB_Q; $q->query(sprintf("delete from events where id = %d", $id)); return true; } here is the del_upd_event code function db_upd_event ($id,$name,$cat,$desc,$more,$url,$sdat,$isap) { $q = new DB_Q; $name = DynamoTextClean($name); $desc = DynamoTextClean($desc); $more = DynamoTextClean($more); $q->query(sprintf("update events set name='%s', cat_id=%d, description='%s', moreinfo='%s', url='%s', sdate='%s', is_approved='%s' where id = %d", addslashes($name), $cat, addslashes($desc), addslashes($more), $url, $sdat, $isap, $id)); return true; } thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.