initial commit

This commit is contained in:
Ben Ramey
2017-03-02 21:57:21 -06:00
commit fd8ad64063
22097 changed files with 1960930 additions and 0 deletions

View File

@@ -0,0 +1,235 @@
<?php
#################################################################################
# #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# This file contains: #
# Functions that govern adding/editing/deleting, etc of schedule items #
# #
#################################################################################
######################################################## FUNCTION: schedule_add #
function schedule_add($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']);
# the new id will be one more than the highest id so far
$new_id = 0;
foreach($schedules as $schedule)
{
if($schedule['id'] > $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 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<seminar_schedule>";
$closing_tags = "\n</seminar_schedule>";
# 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 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<seminar_schedule>";
$closing_tags = "\n</seminar_schedule>";
# 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 = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<seminar_schedule>";
$closing_tags = "\n</seminar_schedule>";
# 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 = "
<seminar id='{$data['id']}'>
<internal_link>{$data['internal_link']}</internal_link>
<title>{$data['title']}</title>
<level>{$data['level']}</level>
<startdate>{$data['startdate']}</startdate>
<enddate>{$data['enddate']}</enddate>
<duration>{$data['duration']}</duration>
<venue>{$data['venue']}</venue>
<participants>{$data['participants']}</participants>
<registration_deadline>{$data['registration_deadline']}</registration_deadline>
<price>{$data['price']}</price>
</seminar>";
return($xml);
}