$new_id) { $new_id = $schedule['id']; } } $new_id++; # the internal link file name for thiscourse is just the filename # without the .xml ending on it $seminar_file_name = str_replace('.xml','',$data['seminar']); # format the dates correctly $data['startday'] = implode(',',$data['startday']); $data['startdate'] = "{$data['startday']}.{$data['startmonth']}.{$data['startyear']}"; $data['endday'] = implode(',',$data['endday']); $data['enddate'] = "{$data['endday']}.{$data['endmonth']}.{$data['endyear']}"; $data['registration_deadline'] = "{$data['regday']}.{$data['regmonth']}.{$data['regyear']}"; # create the new schedule's xml array $schedules[] = array( 'id' => $new_id, 'internal_link' => 'seminars/'.$seminar_file_name, 'title' => $data['title'], 'level' => $data['level'], 'startdate' => $data['startdate'], 'enddate' => $data['enddate'], 'duration' => $data['duration'], 'venue' => $data['venue'], 'participants' => $data['participants'], 'registration_deadline' => $data['registration_deadline'], 'price' => $data['price'] ); # opening and closing tags for the new schedules file $opening_tags = "\n"; $closing_tags = "\n"; # open the old file and truncate it to write the new one $handle = fopen($_CONFIG['schedules_file'],'w'); fwrite($handle,$opening_tags); # now, write an entry for each schedule, including the new one foreach($schedules as $schedule) { $xml = schedule_create_xml($schedule); fwrite($handle,$xml); } fwrite($handle,$closing_tags); fclose($handle); # make a message to the user to let him know the schedule # was added successfully if(!err_exist()) { mesg_make("Schedule '{$data['title']}' successfully added."); } } ##################################################### FUNCTION: schedule_delete # function schedule_delete($data) { global $_CONFIG; # gather all the current schedules from xml file $schedules = xml_parse_file($_CONFIG['schedules_file']); $schedules = xml_force_array($schedules['seminar_schedule']['seminar']); $deleted_schedule = ''; # opening and closing tags for the new schedules file $opening_tags = "\n"; $closing_tags = "\n"; # open the old file and truncate it to write the new one $handle = fopen($_CONFIG['schedules_file'],'w'); fwrite($handle,$opening_tags); # now, write an entry for each schedule, including the new one foreach($schedules as $schedule) { # skip adding this schedule to the new file if it is # the schedule we are looking to delete if($schedule['id'] == $data['delete_id']) { # get title of this deleted schedule so show it in the # message to the user $deleted_schedule = $schedule['title']; continue; } $xml = schedule_create_xml($schedule); fwrite($handle,$xml); } fwrite($handle,$closing_tags); fclose($handle); # make a message to the user to let him know the schedule # was added successfully if(!err_exist()) { mesg_make("Schedule '$deleted_schedule' successfully deleted."); } } ####################################################### FUNCTION: schedule_edit # function schedule_edit($data) { global $_CONFIG,$_DOC_ROOT; # we have to get the specific title of thecourse we are adding $seminar_title = xml_parse_file($_DOC_ROOT.'/data/pages/'.$data['seminar']); $data['title'] = $seminar_title['page']['en']['name']; # gather all the current schedules from xml file $schedules = xml_parse_file($_CONFIG['schedules_file']); $schedules = xml_force_array($schedules['seminar_schedule']['seminar']); # opening and closing tags for the new schedules file $opening_tags = "\n"; $closing_tags = "\n"; # open the old file and truncate it to write the new one $handle = fopen($_CONFIG['schedules_file'],'w'); fwrite($handle,$opening_tags); # now, write an entry for each schedule, including the new one foreach($schedules as $schedule) { # pause for a moment when we come across the schedule # that we are editing so that we can update it's data if($schedule['id'] == $data['edit_id']) { # step through all the form data and update # the schedule array with the edited data foreach($data as $key => $value) { # there are form elements that aren't part of the # xml document, so only update the schedule array # with the form elements that are also xml elements if(array_key_exists($key,$schedule)) { $schedule[$key] = $value; } } } $xml = schedule_create_xml($schedule); fwrite($handle,$xml); } fwrite($handle,$closing_tags); fclose($handle); # make a message to the user to let him know the schedule # was added successfully if(!err_exist()) { mesg_make("Schedule '{$data['title']}' successfully edited."); } } ######################################################## FUNCTION: schedule_get # function schedule_get($schedule_id) { global $_CONFIG; # gather all the current schedules from xml file $schedules = xml_parse_file($_CONFIG['schedules_file']); $schedules = xml_force_array($schedules['seminar_schedule']['seminar']); # look for the schedule with the id we are looking for # if we find it, return the schedule array foreach($schedules as $schedule) { if($schedule['id'] == $schedule_id) { return($schedule); } } } ################################################# FUNCTION: schedule_create_xml # function schedule_create_xml($data) { # I think slashes are being automatically added by php to # the stuff passed via a post request. This will make # sure any text that the user entered are stripped before # we add them to the xml document foreach($data as $key => $value) { $data[$key] = stripslashes($value); } $xml = " {$data['internal_link']} {$data['title']} {$data['level']} {$data['startdate']} {$data['enddate']} {$data['duration']} {$data['venue']} {$data['participants']} {$data['registration_deadline']} {$data['price']} "; return($xml); }