initial commit
This commit is contained in:
24
production/admin/index.php
Normal file
24
production/admin/index.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
$page->content('admin/index.php');
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
?>
|
||||
38
production/admin/login.php
Normal file
38
production/admin/login.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# validate the login info if the user is trying to login
|
||||
if(isset($_POST['login']))
|
||||
{
|
||||
if($page->user()->login($_POST['username'],$_POST['password']))
|
||||
{
|
||||
$page->addMessage('Login successful.');
|
||||
$page->content("admin/index.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Invalid username/password combination. Please try again.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
}
|
||||
# if the user is already logged in
|
||||
else if($page->user()->check_role('admin'))
|
||||
$page->content('admin/index.php');
|
||||
else
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
?>
|
||||
18
production/admin/logout.php
Normal file
18
production/admin/logout.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# log the user out
|
||||
$page->user()->logout();
|
||||
$page->addMessage('Logout successful.');
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
?>
|
||||
314
production/admin/missionandtravel.php
Normal file
314
production/admin/missionandtravel.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
include 'functions/func_file.php';
|
||||
include 'functions/func_xml.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the page element parameter that we want to edit
|
||||
# if it doesn't exist, we just display the list of options
|
||||
# below
|
||||
$what_to_edit = isset($_REQUEST['what']) ? $_REQUEST['what'] : null;
|
||||
|
||||
# gather the appropriate data to send to the template
|
||||
# and show the right template based on what page data we're editing
|
||||
switch($what_to_edit)
|
||||
{
|
||||
case 'shorttermopportunities':
|
||||
work_shorttermopportunities();
|
||||
break;
|
||||
case 'travelinfo':
|
||||
work_travelinfo();
|
||||
break;
|
||||
default:
|
||||
$page->content('admin/missionandtravel.php');
|
||||
}
|
||||
}
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area: Mission and Travel');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
|
||||
$page->process();
|
||||
|
||||
######################################## FUNCTION: work_shorttermopportunities #
|
||||
function work_shorttermopportunities()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/missionandtravel/shorttermopportunities.xml';
|
||||
$opps = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the opportunity data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($opps->opportunity[$c]['id'] != $_GET['which'])
|
||||
&& isset($opps->opportunity[$c]))
|
||||
$c++;
|
||||
$page->data('opportunity',$opps->opportunity[$c]);
|
||||
}
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/'.$do.'.php');
|
||||
}
|
||||
# add the opportunity and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if(isset($_POST['title']))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $opps->opportunity[count($opps->opportunity) - 1]['id'];
|
||||
if(is_null($last_id))
|
||||
$last_id = 0;
|
||||
|
||||
$new_opportunity = $opps->addChild('opportunity');
|
||||
$new_opportunity->addChild('title',$_POST['title']);
|
||||
$new_opportunity->addChild('description',$_POST['description']);
|
||||
$new_opportunity->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$opps->asXML());
|
||||
|
||||
$page->addMessage('Short term opportunity successfully added.');
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('You cannot leave the title blank.');
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/add.php');
|
||||
}
|
||||
}
|
||||
# edit the opportunity and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the opportunity with the right id
|
||||
$opp_found = null;
|
||||
$c = 0;
|
||||
while(is_null($opp_found) && isset($opps->opportunity[$c]))
|
||||
{
|
||||
if((int)$opps->opportunity[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$opp_found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# make sure we found the one and didn't just stop at the last one!
|
||||
if(is_null($opp_found))
|
||||
{
|
||||
$page->addError('Short term opportunity was not found. No deletion has occurred!');
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
return;
|
||||
}
|
||||
elseif(!empty($_POST['title']))
|
||||
{
|
||||
$opps->opportunity[$c]->title = $_POST['title'];
|
||||
$opps->opportunity[$c]->description = $_POST['description'];
|
||||
|
||||
file_put_contents($file_path,$opps->asXML());
|
||||
$page->addMessage('Short term opportunity successfully edited.');
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('You cannot leave the title blank.');
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/edit.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified opportunity
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the opportunity with the right id
|
||||
$opp_found = null;
|
||||
$c = 0;
|
||||
while(is_null($opp_found) && isset($opps->opportunity[$c]))
|
||||
{
|
||||
if((int)$opps->opportunity[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$opp_found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# make sure we found the one and didn't just stop at the last one!
|
||||
if(is_null($opp_found))
|
||||
{
|
||||
$page->addError('Short term opportunity was not found. No deletion has occurred!');
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
return;
|
||||
}
|
||||
|
||||
unset($opps->opportunity[$c]);
|
||||
file_put_contents($file_path,$opps->asXML());
|
||||
$page->addMessage('Short term opportunity successfully deleted.');
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
}
|
||||
# display the list of opps
|
||||
else
|
||||
{
|
||||
$page->data('opps',$opps);
|
||||
$page->content('admin/missionandtravel/shorttermopportunities/list.php');
|
||||
}
|
||||
}
|
||||
|
||||
#################################################### FUNCTION: work_travelinfo #
|
||||
function work_travelinfo()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/missionandtravel/travelinfo.xml';
|
||||
$infos = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the information data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($infos->information[$c]['id'] != $_GET['which'])
|
||||
&& isset($infos->information[$c]))
|
||||
$c++;
|
||||
$page->data('information',$infos->information[$c]);
|
||||
}
|
||||
$page->content('admin/missionandtravel/travelinfo/'.$do.'.php');
|
||||
}
|
||||
# add the information and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if(isset($_POST['title']))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $infos->information[count($infos->information) - 1]['id'];
|
||||
if(is_null($last_id))
|
||||
$last_id = 0;
|
||||
|
||||
$new_information = $infos->addChild('information');
|
||||
$new_information->addChild('title',$_POST['title']);
|
||||
$new_information->addChild('description',$_POST['description']);
|
||||
$new_information->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$infos->asXML());
|
||||
|
||||
$page->addMessage('Travel info successfully added.');
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('You cannot leave the title blank.');
|
||||
$page->content('admin/missionandtravel/travelinfo/add.php');
|
||||
}
|
||||
}
|
||||
# edit the information and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the information with the right id
|
||||
$info_found = null;
|
||||
$c = 0;
|
||||
while(is_null($info_found) && isset($infos->information[$c]))
|
||||
{
|
||||
if((int)$infos->information[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$info_found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# make sure we found the one and didn't just stop at the last one!
|
||||
if(is_null($info_found))
|
||||
{
|
||||
$page->addError('Travel info was not found. No deletion has occurred!');
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
return;
|
||||
}
|
||||
elseif(!empty($_POST['title']))
|
||||
{
|
||||
$infos->information[$c]->title = $_POST['title'];
|
||||
$infos->information[$c]->description = $_POST['description'];
|
||||
|
||||
file_put_contents($file_path,$infos->asXML());
|
||||
$page->addMessage('Travel info successfully edited.');
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('You cannot leave the title blank.');
|
||||
$page->content('admin/missionandtravel/travelinfo/edit.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified information
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the information with the right id
|
||||
$info_found = null;
|
||||
$c = 0;
|
||||
while(is_null($info_found) && isset($infos->information[$c]))
|
||||
{
|
||||
if((int)$infos->information[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$info_found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# make sure we found the one and didn't just stop at the last one!
|
||||
if(is_null($info_found))
|
||||
{
|
||||
$page->addError('Travel info was not found. No deletion has occurred!');
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
return;
|
||||
}
|
||||
|
||||
unset($infos->information[$c]);
|
||||
file_put_contents($file_path,$infos->asXML());
|
||||
$page->addMessage('Travel info successfully deleted.');
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
}
|
||||
# display the list of infos
|
||||
else
|
||||
{
|
||||
$page->data('infos',$infos);
|
||||
$page->content('admin/missionandtravel/travelinfo/list.php');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
587
production/admin/photosandvideos.php
Normal file
587
production/admin/photosandvideos.php
Normal file
@@ -0,0 +1,587 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
include 'functions/func_file.php';
|
||||
include 'functions/func_filesystem.php';
|
||||
include 'functions/func_xml.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the page element parameter that we want to edit
|
||||
# if it doesn't exist, we just display the list of options
|
||||
# below
|
||||
$what_to_edit = isset($_REQUEST['what']) ? $_REQUEST['what'] : null;
|
||||
|
||||
# gather the appropriate data to send to the template
|
||||
# and show the right template based on what page data we're editing
|
||||
switch($what_to_edit)
|
||||
{
|
||||
case 'photos':
|
||||
work_photos();
|
||||
break;
|
||||
case 'videos':
|
||||
work_videos();
|
||||
break;
|
||||
default:
|
||||
$page->content('admin/photosandvideos.php');
|
||||
}
|
||||
}
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area: Photos and Videos');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
###################################################### FUNCTION: work_toolsfor #
|
||||
function work_photos()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT."/site/data/photosandvideos/albums.xml";
|
||||
$albums = xml_get_from_file($file_path);
|
||||
$photos = array();
|
||||
# get a list of all the photos in each album
|
||||
foreach($albums->album as $album)
|
||||
{
|
||||
$album_photos = filesys_get_wanted_children($DOCROOT.'/site/data/photosandvideos/albums/'.$album->imagefolder,'folder',"/^thumb_.*\.(jpg|JPG)$/");
|
||||
foreach($album_photos as $photo)
|
||||
$photos[(int)$album['id']][] = str_replace('thumb_','',$photo);
|
||||
}
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# take the appropriate action according to what we are "doing"
|
||||
if($do == 'addalbum' || $do == 'addphoto')
|
||||
{
|
||||
$page->data('albums',$albums);
|
||||
$page->content("admin/photosandvideos/photos/$do.php");
|
||||
}
|
||||
else if($do == 'deletealbum' || $do == 'editalbum')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
if($found)
|
||||
{
|
||||
$page->data('album',$albums->album[$c]);
|
||||
$page->content("admin/photosandvideos/photos/$do.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('No such album exists.');
|
||||
$page->content('admin/photosandvideos/photos/list.php');
|
||||
}
|
||||
}
|
||||
else if($do == 'deletephoto')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['album'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
if($found)
|
||||
{
|
||||
$page->data('album',$albums->album[$c]);
|
||||
$page->data('photo',$_GET['which']);
|
||||
$page->content("admin/photosandvideos/photos/deletephoto.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('No such album exists.');
|
||||
$page->content('admin/photosandvideos/photos/list.php');
|
||||
}
|
||||
}
|
||||
# add the album and return to the list
|
||||
else if($do == 'doaddalbum')
|
||||
{
|
||||
$last_id = $albums->album[count($albums->album) - 1]['id'];
|
||||
$new_album = $albums->addChild('album');
|
||||
$new_album->addAttribute('id',$last_id + 1);
|
||||
$new_album->addChild('name',$_POST['name']);
|
||||
$new_album->addChild('subalbumof',$_POST['subalbumof']);
|
||||
$new_album->addChild('subalbums');
|
||||
|
||||
$folder_name = preg_replace("/[^A-Za-z0-9]+/",'_',$new_album->name);
|
||||
$new_album->addChild('imagefolder',$folder_name);
|
||||
|
||||
if(file_put_contents($file_path,$albums->asXML()))
|
||||
{
|
||||
mkdir($DOCROOT.'/site/data/photosandvideos/albums/'.$folder_name);
|
||||
$page->addMessage('Album added successfully.');
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not add album.');
|
||||
$page->content("admin/photosandvideos/photos/addalbum.php");
|
||||
}
|
||||
}
|
||||
else if($do == 'doaddphoto')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
if($found)
|
||||
{
|
||||
# make sure the files gets uploaded and moved correctly
|
||||
if($new_photos = file_process_upload('file',$DOCROOT.'/site/data/photosandvideos/albums/'.$albums->album[$c]->imagefolder))
|
||||
{
|
||||
if(!is_array($new_photos))
|
||||
$new_photos = array($new_photos);
|
||||
|
||||
$photo_path = $DOCROOT.'/site/data/photosandvideos/albums/'.$albums->album[$c]->imagefolder;
|
||||
|
||||
foreach($new_photos as $new_photo)
|
||||
{
|
||||
// Get new dimensions
|
||||
list($width, $height) = getimagesize($photo_path."/$new_photo");
|
||||
$ratio_orig = $width/$height;
|
||||
# max widths and heights for thumbnail images and small images
|
||||
$thumb_w = 100;
|
||||
$thumb_h = 100;
|
||||
$small_w = 400;
|
||||
$small_h = 400;
|
||||
|
||||
# get right width/heigh for thumbnail
|
||||
if ($thumb_w/$thumb_h > $ratio_orig) {
|
||||
$thumb_w = $thumb_h*$ratio_orig;
|
||||
} else {
|
||||
$thumb_h = $thumb_w/$ratio_orig;
|
||||
}
|
||||
#get right width/height for small image
|
||||
if ($small_w/$small_h > $ratio_orig) {
|
||||
$small_w = $small_h*$ratio_orig;
|
||||
} else {
|
||||
$small_h = $small_w/$ratio_orig;
|
||||
}
|
||||
|
||||
// Resample
|
||||
$thumb_img = imagecreatetruecolor($thumb_w, $thumb_h);
|
||||
$small_img = imagecreatetruecolor($small_w, $small_h);
|
||||
$original = imagecreatefromjpeg($photo_path."/$new_photo");
|
||||
imagecopyresampled($thumb_img, $original, 0, 0, 0, 0, $thumb_w, $thumb_h, $width, $height);
|
||||
imagecopyresampled($small_img, $original, 0, 0, 0, 0, $small_w, $small_h, $width, $height);
|
||||
|
||||
// Output
|
||||
imagejpeg($thumb_img, $photo_path."/thumb_$new_photo", 100);
|
||||
imagejpeg($small_img, $photo_path."/small_$new_photo", 100);
|
||||
|
||||
# get the update set of photos in this album
|
||||
if(!isset($photos[(int)$albums->album[$c]['id']]))
|
||||
$photos[(int)$albums->album[$c]['id']] = array();
|
||||
array_push($photos[(int)$albums->album[$c]['id']],$new_photo);
|
||||
}
|
||||
$page->addMessage('Photo successfully added.');
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the photo. Please try again.');
|
||||
$page->content("admin/photosandvideos/photos/addphoto.php");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Album does not exist.');
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
}
|
||||
# edit the article and return to the list
|
||||
else if($do == 'doeditalbum')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
if(empty($_POST['name']))
|
||||
{
|
||||
$page->addError('You cannot leave the album name blank.');
|
||||
$page->data('album',$albums->album[$c]);
|
||||
$page->content("admin/photosandvideos/photos/deletealbum.php");
|
||||
}
|
||||
else if($found)
|
||||
{
|
||||
# do the following of the new name is different than the old
|
||||
if((string)$albums->album[$c]->name != $_POST['name'])
|
||||
{
|
||||
# update the folder with the new name
|
||||
$old_folder_name = (string)$albums->album[$c]->imagefolder;
|
||||
$new_folder_name = preg_replace("/[^A-Za-z0-9]+/",'_',$_POST['name']);
|
||||
$albums->album[$c]->imagefolder = $new_folder_name;
|
||||
# rename the folder
|
||||
rename($DOCROOT.'/site/data/photosandvideos/albums/'.$old_folder_name,
|
||||
$DOCROOT.'/site/data/photosandvideos/albums/'.$new_folder_name);
|
||||
# update the name
|
||||
$albums->album[$c]->name = $_POST['name'];
|
||||
}
|
||||
|
||||
# if the album has been placed under a different parent album
|
||||
# has been updated
|
||||
if((int)$albums->album[$c]->subalbumof != $_POST['subalbumof'])
|
||||
{
|
||||
$previous_parent_id = $albums->album[$c]->subalbumof;
|
||||
|
||||
# find the previous parent
|
||||
for($k = 0; $k < count($albums->album); $k++)
|
||||
{
|
||||
if((int)$albums->album[$k]['id'] == $previous_parent_id)
|
||||
{
|
||||
# now find the subalbum entry that is now invalid and delete it
|
||||
for($j = 0; $j < count($albums->album[$k]->subalbums->subalbum); $j++)
|
||||
{
|
||||
if((int)$albums->album[$k]->subalbums->subalbum[$j] == (int)$albums->album[$c]['id'])
|
||||
{
|
||||
unset($albums->album[$k]->subalbums->subalbum[$j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
# find the new parent and add a new subalbum entry
|
||||
for($k = 0; $k < count($albums->album); $k++)
|
||||
{
|
||||
if((int)$albums->album[$k]['id'] == $_POST['subalbumof'])
|
||||
{
|
||||
$albums->album[$k]->subalbums->addChild('subalbum',$albums->album[$c]['id']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$albums->album[$c]->subalbumof = $_POST['subalbumof'];
|
||||
}
|
||||
|
||||
file_put_contents($file_path,$albums->asXML());
|
||||
|
||||
$page->addMessage('Album successfully updated.');
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Album does not exist.');
|
||||
$page->contents("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
}
|
||||
# perform the deletion of a file from a album
|
||||
else if($do == 'dodeletephoto')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['album'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# if we can unlink the file
|
||||
if($found)
|
||||
{
|
||||
$photo_path = $DOCROOT.'/site/data/photosandvideos/albums/'.$albums->album[$c]->imagefolder.'/';
|
||||
if(unlink($photo_path.$_POST['which']))
|
||||
{
|
||||
unlink($photo_path.'thumb_'.$_POST['which']);
|
||||
unlink($photo_path.'small_'.$_POST['which']);
|
||||
# remove the photo from the photos array
|
||||
$key = array_search($_POST['which'],$photos[(int)$albums->album[$c]['id']]);
|
||||
unset($photos[(int)$albums->album[$c]['id']][$key]);
|
||||
|
||||
$page->addMessage('Photo successfully deleted.');
|
||||
}
|
||||
else
|
||||
$page->addError('Could not delete photo.');
|
||||
}
|
||||
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
# perform the deletion of the specified article
|
||||
else if($do == 'dodeletealbum')
|
||||
{
|
||||
# find the album with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($albums->album[$c]))
|
||||
{
|
||||
if((int)$albums->album[$c]['id'] == $_REQUEST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
if($found)
|
||||
{
|
||||
# delete each of the files in this album
|
||||
$photo_path = $DOCROOT.'/site/data/photosandvideos/albums/'.$albums->album[$c]->imagefolder.'/';
|
||||
foreach($photos[(int)$albums->album[$c]['id']] as $file)
|
||||
{
|
||||
unlink($photo_path.$file);
|
||||
unlink($photo_path.'thumb_'.$file);
|
||||
unlink($photo_path.'small_'.$file);
|
||||
}
|
||||
# delete the folder
|
||||
rmdir($DOCROOT.'/site/data/photosandvideos/albums/'.$albums->album[$c]->imagefolder);
|
||||
# if we can successfully unset the album, then print a success message
|
||||
unset($albums->album[$c]);
|
||||
if(!isset($albums->album[$c]))
|
||||
{
|
||||
$page->addMessage('Album successfully deleted.');
|
||||
file_put_contents($file_path,$albums->asXML());
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete this album.');
|
||||
}
|
||||
}
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
# display the list of book albums
|
||||
else
|
||||
{
|
||||
$page->content("admin/photosandvideos/photos/list.php");
|
||||
}
|
||||
$page->data('photos',$photos);
|
||||
$page->data('albums',$albums);
|
||||
}
|
||||
######################################################## FUNCTION: work_videos #
|
||||
function work_videos()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/photosandvideos/videos.xml';
|
||||
$videos = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the video data
|
||||
if($do != 'add')
|
||||
{
|
||||
# find the video with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($videos->video[$c]))
|
||||
{
|
||||
if((int)$videos->video[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
$page->data('video',$videos->video[$c]);
|
||||
}
|
||||
$page->content('admin/photosandvideos/videos/'.$do.'.php');
|
||||
}
|
||||
# add the video and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_file = file_process_upload('videofile',$DOCROOT.'/site/data/photosandvideos/videos'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $videos->video[count($videos->video) - 1]['id'];
|
||||
|
||||
$new_name = isset($_POST['name']) ? $_POST['name'] : $_FILES['videofile']['name'];
|
||||
$new_video = $videos->addChild('video');
|
||||
$new_video->addChild('name',$new_name);
|
||||
$new_video->addChild('file',$new_file);
|
||||
# try to save the image file, otherwise set the new image to the default
|
||||
if(!empty($_FILES['imagefile']['tmp_name']))
|
||||
if($new_imagefile = file_process_upload('imagefile',$DOCROOT.'/site/graphics/photosandvideos/video_thumbs'))
|
||||
$new_video->addChild('image',$new_imagefile);
|
||||
else
|
||||
$new_video->addChild('image','default.jpg');
|
||||
$new_video->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$videos->asXML());
|
||||
|
||||
$page->addMessage('Video successfully added.');
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the video file. Please try again.');
|
||||
$page->content('admin/photosandvideos/videos/add.php');
|
||||
}
|
||||
}
|
||||
# edit the video and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the video with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($videos->video[$c]))
|
||||
{
|
||||
if((int)$videos->video[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
# don't try anything if we couldn't find the video with the right id
|
||||
if(is_null($found))
|
||||
{
|
||||
$page->addError('Video was not found.');
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
return;
|
||||
}
|
||||
# if a new file is specified then delete the old one and replace
|
||||
# the new one
|
||||
else if(!empty($_FILES['videofile']['name']))
|
||||
{
|
||||
# delete old file
|
||||
unlink($DOCROOT.'/site/data/photosandvideos/videos/'.$videos->video[$c]->file);
|
||||
# try to upload the new file
|
||||
if($new_file = file_process_upload('videofile',$DOCROOT.'/site/data/photosandvideos/videos'))
|
||||
{
|
||||
$videos->video[$c]->name = isset($_POST['name']) ? $_POST['name'] : $_FILES['videofile']['name'];
|
||||
$videos->video[$c]->file = $new_file;
|
||||
|
||||
# if the image file is being updated too
|
||||
if($_FILES['imagefile']['name'] !== '')
|
||||
{
|
||||
if((string)$videos->video[$c]->image !== 'default.jpg')
|
||||
unlink($DOCROOT.'/site/graphics/photosandvideos/video_thumbs/'.$videos->video[$c]->image);
|
||||
if($new_imagefile = file_process_upload('file',$DOCROOT.'/site/graphics/photosandvideos/video_thumbs'))
|
||||
$videos->video[$c]->image = $new_imagefile;
|
||||
else
|
||||
$videos->video[$c]->image = 'default.jpg';
|
||||
}
|
||||
|
||||
file_put_contents($file_path,$videos->asXML());
|
||||
$page->addMessage('Video successfully edited.');
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the video file. Please try again.');
|
||||
$page->content('admin/photosandvideos/videos/edit.php');
|
||||
}
|
||||
}
|
||||
# if no new file is uploaded
|
||||
else
|
||||
{
|
||||
if($_POST['name'] !== '')
|
||||
$videos->video[$c]->name = $_POST['name'];
|
||||
# if the image file is being updated too
|
||||
if(!empty($_FILES['imagefile']['name']))
|
||||
{
|
||||
if((string)$videos->video[$c]->image !== 'default.jpg')
|
||||
unlink($DOCROOT.'/site/graphics/photosandvideos/video_thumbs/'.$videos->video[$c]->image);
|
||||
if($new_imagefile = file_process_upload('imagefile',$DOCROOT.'/site/graphics/photosandvideos/video_thumbs'))
|
||||
$videos->video[$c]->image = $new_imagefile;
|
||||
else
|
||||
$videos->video[$c]->image = 'default.jpg';
|
||||
}
|
||||
|
||||
file_put_contents($file_path,$videos->asXML());
|
||||
$page->addMessage('Video successfully edited.');
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified video
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the video with the right id
|
||||
$found = null;
|
||||
$c = 0;
|
||||
while(is_null($found) && isset($videos->video[$c]))
|
||||
{
|
||||
if((int)$videos->video[$c]['id'] == $_POST['which'])
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/photosandvideos/videos/'.$videos->video[$c]->file;
|
||||
if(unlink($file_name))
|
||||
{
|
||||
# delete the thumbnail image
|
||||
unlink($DOCROOT.'/site/graphics/photosandvideos/video_thumbs/'.$videos->video[$c]->image);
|
||||
unset($videos->video[$c]);
|
||||
file_put_contents($file_path,$videos->asXML());
|
||||
$page->addMessage('Video successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete video.');
|
||||
}
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
}
|
||||
# display the list of videos
|
||||
else
|
||||
{
|
||||
$page->data('videos',$videos);
|
||||
$page->content('admin/photosandvideos/videos/list.php');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
447
production/admin/prayerrequests.php
Normal file
447
production/admin/prayerrequests.php
Normal file
@@ -0,0 +1,447 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
include 'functions/func_file.php';
|
||||
include 'functions/func_xml.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the page element parameter that we want to edit
|
||||
# if it doesn't exist, we just display the list of options
|
||||
# below
|
||||
$what_to_edit = isset($_REQUEST['what']) ? $_REQUEST['what'] : null;
|
||||
|
||||
# gather the appropriate data to send to the template
|
||||
# and show the right template based on what page data we're editing
|
||||
switch($what_to_edit)
|
||||
{
|
||||
case 'missionarymoments':
|
||||
work_missionarymoments();
|
||||
break;
|
||||
case 'emailupdates':
|
||||
work_emailupdates();
|
||||
break;
|
||||
case 'prayerletters':
|
||||
work_prayerletters();
|
||||
break;
|
||||
default:
|
||||
$page->content('admin/prayerrequests.php');
|
||||
}
|
||||
}
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area: Prayer Requests');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
############################################# FUNCTION: work_missionarymoments #
|
||||
function work_missionarymoments()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/missionarymoments.xml';
|
||||
$moments = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the moment data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($moments->moment[$c]['id'] != $_GET['which'])
|
||||
&& isset($moments->moment[$c]))
|
||||
$c++;
|
||||
$page->data('moment',$moments->moment[$c]);
|
||||
}
|
||||
$page->content('admin/missionarymoments/'.$do.'.php');
|
||||
}
|
||||
# add the moment and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/missionarymoments'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $moments->moment[count($moments->moment) - 1]['id'];
|
||||
|
||||
$new_title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$new_moment = $moments->addChild('moment');
|
||||
$new_moment->addChild('title',$new_title);
|
||||
$new_moment->addChild('date',$_POST['date']);
|
||||
$new_moment->addChild('file',$new_link);
|
||||
$new_moment->addChild('summary',$_POST['summary']);
|
||||
$new_moment->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$moments->asXML());
|
||||
|
||||
$page->addMessage('Missionary moment successfully added.');
|
||||
$page->data('moments',$moments);
|
||||
$page->content('admin/missionarymoments/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/missionarymoments/add.php');
|
||||
}
|
||||
}
|
||||
# edit the moment and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the moment with the right id
|
||||
$c = 0;
|
||||
while(isset($moments->moment[$c])
|
||||
&& ($moments->moment[$c]['id'] != $_POST['which']))
|
||||
$c++;
|
||||
|
||||
# if a new file is specified then delete the old one and replace
|
||||
# the new one
|
||||
if($_FILES['file']['name'] !== '')
|
||||
{
|
||||
# delete old file
|
||||
unlink($DOCROOT.'/site/data/missionarymoments/'.$moments->moment[$c]->file);
|
||||
# try to upload the new file
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/missionarymoments'))
|
||||
{
|
||||
$moments->moment[$c]->title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$moments->moment[$c]->file = $new_link;
|
||||
$moments->moment[$c]->date = $_POST['date'];
|
||||
$moments->moment[$c]->summary = $_POST['summary'];
|
||||
|
||||
file_put_contents($file_path,$moments->asXML());
|
||||
$page->addMessage('Missionary moment successfully edited.');
|
||||
$page->data('moments',$moments);
|
||||
$page->content('admin/missionarymoments/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/missionarymoments/edit.php');
|
||||
}
|
||||
}
|
||||
# if no new file is uploaded
|
||||
else
|
||||
{
|
||||
if($_POST['title'] !== '')
|
||||
$moments->moment[$c]->title = $_POST['title'];
|
||||
|
||||
$moments->moment[$c]->date = $_POST['date'];
|
||||
$moments->moment[$c]->summary = $_POST['summary'];
|
||||
|
||||
file_put_contents($file_path,$moments->asXML());
|
||||
$page->addMessage('Missionary moment successfully edited.');
|
||||
$page->data('moments',$moments);
|
||||
$page->content('admin/missionarymoments/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified moment
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the moment with the right id
|
||||
$c = 0;
|
||||
while(($moments->moment[$c]['id'] != $_POST['which'])
|
||||
&& isset($moments->moment[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/missionarymoments/'.$moments->moment[$c]->file;
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($moments->moment[$c]);
|
||||
file_put_contents($file_path,$moments->asXML());
|
||||
$page->addMessage('Missionary moment successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete missionary moment.');
|
||||
}
|
||||
$page->data('moments',$moments);
|
||||
$page->content('admin/missionarymoments/list.php');
|
||||
}
|
||||
# display the list of moments
|
||||
else
|
||||
{
|
||||
$page->data('moments',$moments);
|
||||
$page->content('admin/missionarymoments/list.php');
|
||||
}
|
||||
}
|
||||
################################################## FUNCTION: work_emailupdates #
|
||||
function work_emailupdates()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/prayerrequests/emailupdates.xml';
|
||||
$updates = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the update data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($updates->emailupdate[$c]['id'] != $_GET['which'])
|
||||
&& isset($updates->emailupdate[$c]))
|
||||
$c++;
|
||||
$page->data('update',$updates->emailupdate[$c]);
|
||||
}
|
||||
$page->content('admin/prayerrequests/emailupdates/'.$do.'.php');
|
||||
}
|
||||
# add the update and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/prayerrequests/emailupdates'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $updates->emailupdate[count($updates->emailupdate) - 1]['id'];
|
||||
|
||||
$new_title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$new_update = $updates->addChild('emailupdate');
|
||||
$new_update->addChild('title',$new_title);
|
||||
$new_update->addChild('date',$_POST['date']);
|
||||
$new_update->addChild('file',$new_link);
|
||||
$new_update->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$updates->asXML());
|
||||
|
||||
$page->addMessage('E-mail update successfully added.');
|
||||
$page->data('updates',$updates);
|
||||
$page->content('admin/prayerrequests/emailupdates/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/prayerrequests/emailupdates/add.php');
|
||||
}
|
||||
}
|
||||
# edit the update and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the update with the right id
|
||||
$c = 0;
|
||||
while(isset($updates->emailupdate[$c])
|
||||
&& ($updates->emailupdate[$c]['id'] != $_POST['which']))
|
||||
$c++;
|
||||
|
||||
# if a new file is specified then delete the old one and replace
|
||||
# the new one
|
||||
if($_FILES['file']['name'] !== '')
|
||||
{
|
||||
# delete old file
|
||||
unlink($DOCROOT.'/site/data/prayerrequests/emailupdates/'.$updates->emailupdate[$c]->file);
|
||||
# try to upload the new file
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/prayerrequests/emailupdates'))
|
||||
{
|
||||
$updates->emailupdate[$c]->title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$updates->emailupdate[$c]->file = $new_link;
|
||||
$updates->emailupdate[$c]->date = $_POST['date'];
|
||||
|
||||
file_put_contents($file_path,$updates->asXML());
|
||||
$page->addMessage('Update successfully edited.');
|
||||
$page->data('updates',$updates);
|
||||
$page->content('admin/prayerrequests/emailupdates/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/prayerrequests/emailupdates/edit.php');
|
||||
}
|
||||
}
|
||||
# if no new file is uploaded
|
||||
else
|
||||
{
|
||||
if($_POST['title'] !== '')
|
||||
$updates->emailupdate[$c]->title = $_POST['title'];
|
||||
|
||||
$updates->emailupdate[$c]->date = $_POST['date'];
|
||||
|
||||
file_put_contents($file_path,$updates->asXML());
|
||||
$page->addMessage('Update successfully edited.');
|
||||
$page->data('updates',$updates);
|
||||
$page->content('admin/prayerrequests/emailupdates/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified update
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the update with the right id
|
||||
$c = 0;
|
||||
while(($updates->emailupdate[$c]['id'] != $_POST['which'])
|
||||
&& isset($updates->emailupdate[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/prayerrequests/emailupdates/'.$updates->emailupdate[$c]->file;
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($updates->emailupdate[$c]);
|
||||
file_put_contents($file_path,$updates->asXML());
|
||||
$page->addMessage('Update successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete update.');
|
||||
}
|
||||
$page->data('updates',$updates);
|
||||
$page->content('admin/prayerrequests/emailupdates/list.php');
|
||||
}
|
||||
# display the list of updates
|
||||
else
|
||||
{
|
||||
$page->data('updates',$updates);
|
||||
$page->content('admin/prayerrequests/emailupdates/list.php');
|
||||
}
|
||||
}
|
||||
################################################# FUNCTION: work_prayerletters #
|
||||
function work_prayerletters()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/prayerrequests/prayerletters.xml';
|
||||
$letters = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the letter data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($letters->prayerletter[$c]['id'] != $_GET['which'])
|
||||
&& isset($letters->prayerletter[$c]))
|
||||
$c++;
|
||||
$page->data('letter',$letters->prayerletter[$c]);
|
||||
}
|
||||
$page->content('admin/prayerrequests/prayerletters/'.$do.'.php');
|
||||
}
|
||||
# add the letter and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/prayerrequests/prayerletters'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $letters->prayerletter[count($letters->prayerletter) - 1]['id'];
|
||||
|
||||
$new_title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$new_letter = $letters->addChild('prayerletter');
|
||||
$new_letter->addChild('title',$new_title);
|
||||
$new_letter->addChild('date',$_POST['date']);
|
||||
$new_letter->addChild('file',$new_link);
|
||||
$new_letter->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$letters->asXML());
|
||||
|
||||
$page->addMessage('Prayer letter successfully added.');
|
||||
$page->data('letters',$letters);
|
||||
$page->content('admin/prayerrequests/prayerletters/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/prayerrequests/prayerletters/add.php');
|
||||
}
|
||||
}
|
||||
# edit the letter and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the letter with the right id
|
||||
$c = 0;
|
||||
while(isset($letters->prayerletter[$c])
|
||||
&& ($letters->prayerletter[$c]['id'] != $_POST['which']))
|
||||
$c++;
|
||||
|
||||
# if a new file is specified then delete the old one and replace
|
||||
# the new one
|
||||
if($_FILES['file']['name'] !== '')
|
||||
{
|
||||
# delete old file
|
||||
unlink($DOCROOT.'/site/data/prayerrequests/prayerletters/'.$letters->prayerletter[$c]->file);
|
||||
# try to upload the new file
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/prayerrequests/prayerletters'))
|
||||
{
|
||||
$letters->prayerletter[$c]->title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$letters->prayerletter[$c]->file = $new_link;
|
||||
$letters->prayerletter[$c]->date = $_POST['date'];
|
||||
|
||||
file_put_contents($file_path,$letters->asXML());
|
||||
$page->addMessage('Prayer letter successfully edited.');
|
||||
$page->data('letters',$letters);
|
||||
$page->content('admin/prayerrequests/prayerletters/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/prayerrequests/prayerletters/edit.php');
|
||||
}
|
||||
}
|
||||
# if no new file is uploaded
|
||||
else
|
||||
{
|
||||
if($_POST['title'] !== '')
|
||||
$letters->prayerletter[$c]->title = $_POST['title'];
|
||||
|
||||
$letters->prayerletter[$c]->date = $_POST['date'];
|
||||
|
||||
file_put_contents($file_path,$letters->asXML());
|
||||
$page->addMessage('Prayer letter successfully edited.');
|
||||
$page->data('letters',$letters);
|
||||
$page->content('admin/prayerrequests/prayerletters/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified letter
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the letter with the right id
|
||||
$c = 0;
|
||||
while(($letters->prayerletter[$c]['id'] != $_POST['which'])
|
||||
&& isset($letters->prayerletter[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/prayerrequests/prayerletters/'.$letters->prayerletter[$c]->file;
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($letters->prayerletter[$c]);
|
||||
file_put_contents($file_path,$letters->asXML());
|
||||
$page->addMessage('Prayer letter successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete letter.');
|
||||
}
|
||||
$page->data('letters',$letters);
|
||||
$page->content('admin/prayerrequests/prayerletters/list.php');
|
||||
}
|
||||
# display the list of letters
|
||||
else
|
||||
{
|
||||
$page->data('letters',$letters);
|
||||
$page->content('admin/prayerrequests/prayerletters/list.php');
|
||||
}
|
||||
}
|
||||
?>
|
||||
764
production/admin/resources.php
Normal file
764
production/admin/resources.php
Normal file
@@ -0,0 +1,764 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
include 'functions/func_file.php';
|
||||
include 'functions/func_xml.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
# get the page element parameter that we want to edit
|
||||
# if it doesn't exist, we just display the list of options
|
||||
# below
|
||||
$what_to_edit = isset($_REQUEST['what']) ? $_REQUEST['what'] : null;
|
||||
|
||||
# gather the appropriate data to send to the template
|
||||
# and show the right template based on what page data we're editing
|
||||
switch($what_to_edit)
|
||||
{
|
||||
case 'articles':
|
||||
work_articles();
|
||||
break;
|
||||
case 'books':
|
||||
work_books();
|
||||
break;
|
||||
case 'onleadership':
|
||||
work_onleadership();
|
||||
break;
|
||||
case 'teachingoutlines':
|
||||
work_teachingoutlines();
|
||||
break;
|
||||
case 'toolsforministry':
|
||||
work_toolsfor('ministry');
|
||||
break;
|
||||
case 'toolsforpersonal':
|
||||
work_toolsfor('personal');
|
||||
break;
|
||||
default:
|
||||
$page->content('admin/resources.php');
|
||||
}
|
||||
}
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area: Resources');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
###################################################### FUNCTION: work_articles #
|
||||
function work_articles()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/resources/articles.xml';
|
||||
$articles = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'edit' || $do == 'delete')
|
||||
{
|
||||
# if we are editing or deleting, the template needs the article data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($articles->article[$c]['id'] != $_GET['which'])
|
||||
&& isset($articles->article[$c]))
|
||||
$c++;
|
||||
$page->data('article',$articles->article[$c]);
|
||||
}
|
||||
$page->content('admin/resources/articles/'.$do.'.php');
|
||||
}
|
||||
# add the article and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/articles'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $articles->article[count($articles->article) - 1]['id'];
|
||||
|
||||
$new_title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$new_article = $articles->addChild('article');
|
||||
$new_article->addChild('title',$new_title);
|
||||
$new_article->addChild('link',$new_link);
|
||||
$new_article->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$articles->asXML());
|
||||
|
||||
$page->addMessage('Article successfully added.');
|
||||
$page->data('articles',$articles);
|
||||
$page->content('admin/resources/articles/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/resources/articles/add.php');
|
||||
}
|
||||
}
|
||||
# edit the article and return to the list
|
||||
else if($do == 'doedit')
|
||||
{
|
||||
# find the article with the right id
|
||||
$c = 0;
|
||||
while(isset($articles->article[$c])
|
||||
&& ($articles->article[$c]['id'] != $_POST['which']))
|
||||
$c++;
|
||||
|
||||
# if a new file is specified then delete the old one and replace
|
||||
# the new one
|
||||
if($_FILES['file']['name'] !== '')
|
||||
{
|
||||
# delete old file
|
||||
unlink($DOCROOT.'/site/data/resources/articles/'.$articles->article[$c]->link);
|
||||
# try to upload the new file
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/articles'))
|
||||
{
|
||||
$articles->article[$c]->title = isset($_POST['title']) ? $_POST['title'] : $_FILES['file']['name'];
|
||||
$articles->article[$c]->link = $new_link;
|
||||
|
||||
file_put_contents($file_path,$articles->asXML());
|
||||
$page->addMessage('Article successfully edited.');
|
||||
$page->data('articles',$articles);
|
||||
$page->content('admin/resources/articles/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/resources/articles/edit.php');
|
||||
}
|
||||
}
|
||||
# if no new file is uploaded
|
||||
else
|
||||
{
|
||||
if($_POST['title'] !== '')
|
||||
$articles->article[$c]->title = $_POST['title'];
|
||||
|
||||
file_put_contents($file_path,$articles->asXML());
|
||||
$page->addMessage('Article successfully edited.');
|
||||
$page->data('articles',$articles);
|
||||
$page->content('admin/resources/articles/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified article
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the article with the right id
|
||||
$c = 0;
|
||||
while(($articles->article[$c]['id'] != $_POST['which'])
|
||||
&& isset($articles->article[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/resources/articles/'.$articles->article[$c]->link;
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($articles->article[$c]);
|
||||
file_put_contents($file_path,$articles->asXML());
|
||||
$page->addMessage('Article successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete article.');
|
||||
}
|
||||
$page->data('articles',$articles);
|
||||
$page->content('admin/resources/articles/list.php');
|
||||
}
|
||||
# display the list of articles
|
||||
else
|
||||
{
|
||||
$page->data('articles',$articles);
|
||||
$page->content('admin/resources/articles/list.php');
|
||||
}
|
||||
}
|
||||
######################################################### FUNCTION: work_books #
|
||||
function work_books()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/resources/books.xml';
|
||||
$categories = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# take the appropriate action according to what we are "doing"
|
||||
if($do == 'addcat')
|
||||
$page->content('admin/resources/books/addcat.php');
|
||||
else if($do == 'addfile')
|
||||
{
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/addfile.php');
|
||||
}
|
||||
else if($do == 'deletecat' || $do == 'editcat')
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_GET['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->content('admin/resources/books/'.$do.'.php');
|
||||
}
|
||||
else if($do == 'deletefile')
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_GET['cat'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->data('file',$_GET['which']);
|
||||
$page->content('admin/resources/books/deletefile.php');
|
||||
}
|
||||
# add the category and return to the list
|
||||
else if($do == 'doaddcat')
|
||||
{
|
||||
$last_id = $categories->category[count($categories->category) - 1]['id'];
|
||||
$new_cat = $categories->addChild('category');
|
||||
$new_cat->addAttribute('id',$last_id + 1);
|
||||
$new_cat->addChild('name',$_POST['name']);
|
||||
|
||||
if(file_put_contents($file_path,$categories->asXML()))
|
||||
{
|
||||
$page->addMessage('Category added successfully.');
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not add category.');
|
||||
$page->content('admin/resources/books/addcat.php');
|
||||
}
|
||||
}
|
||||
else if($do == 'doaddfile')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/books'))
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
$new_file = $categories->category[$c]->addChild('file',$new_link);
|
||||
|
||||
if(file_put_contents($file_path,$categories->asXML()))
|
||||
{
|
||||
$page->addMessage('File successfully added.');
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/resources/books/addfile.php');
|
||||
}
|
||||
$page->data('categories',$categories);
|
||||
}
|
||||
# edit the article and return to the list
|
||||
else if($do == 'doeditcat')
|
||||
{
|
||||
# find the article with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
if(empty($_POST['name']))
|
||||
{
|
||||
$page->addError('You cannot leave the category name blank.');
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->content('admin/books/deletecat.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$categories->category[$c]->name = $_POST['name'];
|
||||
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
|
||||
$page->addMessage('Category successfully updated.');
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of a file from a category
|
||||
else if($do == 'dodeletefile')
|
||||
{
|
||||
# find the category with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['cat'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
# if we can unlink the file
|
||||
if(unlink($DOCROOT.'/site/data/resources/books/'.$_POST['which']))
|
||||
{
|
||||
# find the file in the category and delete it
|
||||
$k = 0;
|
||||
while(($categories->category[$c]->file[$k] != $_POST['which'])
|
||||
&& isset($categories->category[$c]->file[$k]))
|
||||
$k++;
|
||||
|
||||
# make sure we only delete the file if it's found
|
||||
if($categories->category[$c]->file[$k] == $_POST['which'])
|
||||
unset($categories->category[$c]->file[$k]);
|
||||
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
$page->addMessage('File successfully deleted.');
|
||||
}
|
||||
else
|
||||
$page->addError('Could not delete file.');
|
||||
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
# perform the deletion of the specified article
|
||||
else if($do == 'dodeletecat')
|
||||
{
|
||||
# find the category with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
# delete each of the files in this category
|
||||
foreach($categories->category[$c]->file as $file)
|
||||
{
|
||||
if(!unlink($DOCROOT.'/site/data/resources/books/'.$file))
|
||||
$page->addError('File could not be deleted: '.$file);
|
||||
}
|
||||
# if we can successfully unset the category, then print a success message
|
||||
unset($categories->category[$c]);
|
||||
if(!isset($categories->category[$c]))
|
||||
{
|
||||
$page->addMessage('Category successfully deleted.');
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete this category.');
|
||||
}
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
# display the list of book categories
|
||||
else
|
||||
{
|
||||
$page->data('categories',$categories);
|
||||
$page->content('admin/resources/books/list.php');
|
||||
}
|
||||
}
|
||||
################################################## FUNCTION: work_onleadership #
|
||||
function work_onleadership()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/resources/onleadership.xml';
|
||||
$files = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'delete')
|
||||
{
|
||||
# if we are deleting, the template needs the file data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($files->file[$c]['id'] != $_GET['which'])
|
||||
&& isset($files->file[$c]))
|
||||
$c++;
|
||||
$page->data('file',$files->file[$c]);
|
||||
}
|
||||
$page->content('admin/resources/onleadership/'.$do.'.php');
|
||||
}
|
||||
# add the file and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/onleadership'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $files->file[count($files->file) - 1]['id'];
|
||||
|
||||
$new_file = $files->addChild('file',$new_link);
|
||||
$new_file->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$files->asXML());
|
||||
|
||||
$page->addMessage('File successfully added.');
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/onleadership/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/resources/onleadership/add.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified file
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the file with the right id
|
||||
$c = 0;
|
||||
while(($files->file[$c]['id'] != $_POST['which'])
|
||||
&& isset($files->file[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/resources/onleadership/'.$files->file[$c];
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($files->file[$c]);
|
||||
file_put_contents($file_path,$files->asXML());
|
||||
$page->addMessage('File successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete file.');
|
||||
}
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/onleadership/list.php');
|
||||
}
|
||||
# display the list of files
|
||||
else
|
||||
{
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/onleadership/list.php');
|
||||
}
|
||||
}
|
||||
############################################## FUNCTION: work_teachingoutlines #
|
||||
function work_teachingoutlines()
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT.'/site/data/resources/teachingoutlines.xml';
|
||||
$files = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# add, edit and delete just display a form or other template page
|
||||
# so we can just lump them all together here
|
||||
if($do == 'add' || $do == 'delete')
|
||||
{
|
||||
# if we are deleting, the template needs the file data
|
||||
if($do != 'add')
|
||||
{
|
||||
$c = 0;
|
||||
while(($files->file[$c]['id'] != $_GET['which'])
|
||||
&& isset($files->file[$c]))
|
||||
$c++;
|
||||
$page->data('file',$files->file[$c]);
|
||||
}
|
||||
$page->content('admin/resources/teachingoutlines/'.$do.'.php');
|
||||
}
|
||||
# add the file and return to the list
|
||||
else if($do == 'doadd')
|
||||
{
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/teachingoutlines'))
|
||||
{
|
||||
# get the last id from the file
|
||||
$last_id = $files->file[count($files->file) - 1]['id'];
|
||||
|
||||
$new_file = $files->addChild('file',$new_link);
|
||||
$new_file->addAttribute('id',$last_id + 1);
|
||||
|
||||
file_put_contents($file_path,$files->asXML());
|
||||
|
||||
$page->addMessage('File successfully added.');
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/teachingoutlines/list.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content('admin/resources/teachingoutlines/add.php');
|
||||
}
|
||||
}
|
||||
# perform the deletion of the specified file
|
||||
else if($do == 'dodelete')
|
||||
{
|
||||
# find the file with the right id
|
||||
$c = 0;
|
||||
while(($files->file[$c]['id'] != $_POST['which'])
|
||||
&& isset($files->file[$c]))
|
||||
$c++;
|
||||
|
||||
$file_name = $DOCROOT.'/site/data/resources/teachingoutlines/'.$files->file[$c];
|
||||
if(unlink($file_name))
|
||||
{
|
||||
unset($files->file[$c]);
|
||||
file_put_contents($file_path,$files->asXML());
|
||||
$page->addMessage('File successfully deleted.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete file.');
|
||||
}
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/teachingoutlines/list.php');
|
||||
}
|
||||
# display the list of files
|
||||
else
|
||||
{
|
||||
$page->data('files',$files);
|
||||
$page->content('admin/resources/teachingoutlines/list.php');
|
||||
}
|
||||
}
|
||||
###################################################### FUNCTION: work_toolsfor #
|
||||
function work_toolsfor($type)
|
||||
{
|
||||
global $DOCROOT, $page;
|
||||
$file_path = $DOCROOT."/site/data/resources/toolsfor$type.xml";
|
||||
$categories = xml_get_from_file($file_path);
|
||||
|
||||
# get commands from get, if there is nothing there, get
|
||||
# them from the post
|
||||
$do = isset($_REQUEST['do']) ? $_REQUEST['do'] : null;
|
||||
$which = isset($_REQUEST['which']) ? $_REQUEST['which'] : null;
|
||||
|
||||
# take the appropriate action according to what we are "doing"
|
||||
if($do == 'addcat')
|
||||
$page->content("admin/resources/toolsfor$type/addcat.php");
|
||||
else if($do == 'addfile')
|
||||
{
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/addfile.php");
|
||||
}
|
||||
else if($do == 'deletecat' || $do == 'editcat')
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_GET['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
if($do == 'editcat')
|
||||
$page->data('categories',$categories);
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->content("admin/resources/toolsfor$type/$do.php");
|
||||
}
|
||||
else if($do == 'deletefile')
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_GET['cat'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->data('file',$_GET['which']);
|
||||
$page->content("admin/resources/toolsfor$type/deletefile.php");
|
||||
}
|
||||
# add the category and return to the list
|
||||
else if($do == 'doaddcat')
|
||||
{
|
||||
$last_id = $categories->category[count($categories->category) - 1]['id'];
|
||||
$new_cat = $categories->addChild('category');
|
||||
$new_cat->addAttribute('id',$last_id + 1);
|
||||
$new_cat->addChild('name',$_POST['name']);
|
||||
$new_cat->addChild('subcategoryof',$_POST['subcategoryof']);
|
||||
$new_cat->addChild('subcategories');
|
||||
|
||||
$folder_name = preg_replace("/[^A-Za-z0-9]+/",'_',$new_cat->name);
|
||||
$new_cat->addChild('folder',$folder_name);
|
||||
|
||||
if(file_put_contents($file_path,$categories->asXML()))
|
||||
{
|
||||
mkdir($DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$folder_name);
|
||||
$page->addMessage('Category added successfully.');
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not add category.');
|
||||
$page->content("admin/resources/toolsfor$type/addcat.php");
|
||||
}
|
||||
}
|
||||
else if($do == 'doaddfile')
|
||||
{
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
# make sure the file gets uploaded and moved correctly
|
||||
if($new_link = file_process_upload('file',$DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$categories->category[$c]->folder))
|
||||
{
|
||||
$new_file = $categories->category[$c]->addChild('file',$new_link);
|
||||
|
||||
if(file_put_contents($file_path,$categories->asXML()))
|
||||
{
|
||||
$page->addMessage('File successfully added.');
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('An error occurred while uploading the file. Please try again.');
|
||||
$page->content("admin/resources/toolsfor$type/addfile.php");
|
||||
}
|
||||
$page->data('categories',$categories);
|
||||
}
|
||||
# edit the article and return to the list
|
||||
else if($do == 'doeditcat')
|
||||
{
|
||||
# find the article with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
if(empty($_POST['name']))
|
||||
{
|
||||
$page->addError('You cannot leave the category name blank.');
|
||||
$page->data('category',$categories->category[$c]);
|
||||
$page->content("admin/resources/toolsfor'.$type.'/deletecat.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
# do the following of the new name is different than the old
|
||||
if((string)$categories->category[$c]->name != $_POST['name'])
|
||||
{
|
||||
# update the folder with the new name
|
||||
$old_folder_name = (string)$categories->category[$c]->folder;
|
||||
$new_folder_name = preg_replace("/[^A-Za-z0-9]+/",'_',$_POST['name']);
|
||||
$categories->category[$c]->folder = $new_folder_name;
|
||||
# rename the folder
|
||||
rename($DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$old_folder_name,
|
||||
$DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$new_folder_name);
|
||||
# update the name
|
||||
$categories->category[$c]->name = $_POST['name'];
|
||||
}
|
||||
|
||||
# if the category has been placed under a different parent category
|
||||
# has been updated
|
||||
if((int)$categories->category[$c]->subcategoryof != $_POST['subcategoryof'])
|
||||
{
|
||||
$previous_parent_id = $categories->category[$c]->subcategoryof;
|
||||
|
||||
# find the previous parent
|
||||
for($k = 0; $k < count($categories->category); $k++)
|
||||
{
|
||||
if((int)$categories->category[$k]['id'] == $previous_parent_id)
|
||||
{
|
||||
# now find the subcategory entry that is now invalid and delete it
|
||||
for($j = 0; $j < count($categories->category[$k]->subcategories->subcategory); $j++)
|
||||
{
|
||||
if((int)$categories->category[$k]->subcategories->subcategory[$j] == (int)$categories->category[$c]['id'])
|
||||
{
|
||||
unset($categories->category[$k]->subcategories->subcategory[$j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
# find the new parent and add a new subcategory entry
|
||||
for($k = 0; $k < count($categories->category); $k++)
|
||||
{
|
||||
if((int)$categories->category[$k]['id'] == $_POST['subcategoryof'])
|
||||
{
|
||||
$categories->category[$k]->subcategories->addChild('subcategory',$categories->category[$c]['id']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$categories->category[$c]->subcategoryof = $_POST['subcategoryof'];
|
||||
}
|
||||
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
|
||||
$page->addMessage('Category successfully updated.');
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
}
|
||||
# perform the deletion of a file from a category
|
||||
else if($do == 'dodeletefile')
|
||||
{
|
||||
# find the category with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['cat'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
# if we can unlink the file
|
||||
if(unlink($DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$categories->category[$c]->folder.'/'.$_POST['which']))
|
||||
{
|
||||
# find the file in the category and delete it
|
||||
$k = 0;
|
||||
while(($categories->category[$c]->file[$k] != $_POST['which'])
|
||||
&& isset($categories->category[$c]->file[$k]))
|
||||
$k++;
|
||||
|
||||
# make sure we only delete the file if it's found
|
||||
if($categories->category[$c]->file[$k] == $_POST['which'])
|
||||
unset($categories->category[$c]->file[$k]);
|
||||
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
$page->addMessage('File successfully deleted.');
|
||||
}
|
||||
else
|
||||
$page->addError('Could not delete file.');
|
||||
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
# perform the deletion of the specified article
|
||||
else if($do == 'dodeletecat')
|
||||
{
|
||||
# find the category with the right id
|
||||
$c = 0;
|
||||
while(($categories->category[$c]['id'] != $_POST['which'])
|
||||
&& isset($categories->category[$c]))
|
||||
$c++;
|
||||
|
||||
# delete each of the files in this category
|
||||
foreach($categories->category[$c]->file as $file)
|
||||
{
|
||||
if(!unlink($DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$categories->category[$c]->folder.'/'.$file))
|
||||
$page->addError('File could not be deleted: '.$file);
|
||||
}
|
||||
# delete the folder
|
||||
rmdir($DOCROOT.'/site/data/resources/toolsfor'.$type.'/'.$categories->category[$c]->folder);
|
||||
# if we can successfully unset the category, then print a success message
|
||||
unset($categories->category[$c]);
|
||||
if(!isset($categories->category[$c]))
|
||||
{
|
||||
$page->addMessage('Category successfully deleted.');
|
||||
file_put_contents($file_path,$categories->asXML());
|
||||
}
|
||||
else
|
||||
{
|
||||
$page->addError('Could not delete this category.');
|
||||
}
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
# display the list of book categories
|
||||
else
|
||||
{
|
||||
$page->data('categories',$categories);
|
||||
$page->content("admin/resources/toolsfor$type/list.php");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
24
production/admin/whoweare.php
Normal file
24
production/admin/whoweare.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
include '../php/classes/page.php';
|
||||
$page = new Page();
|
||||
$page->init_user();
|
||||
|
||||
# make sure the user is logged in before he has access to the
|
||||
# admin section
|
||||
if(!$page->user()->check_role('admin'))
|
||||
{
|
||||
$page->addMessage('You must login to use the administrator pages.');
|
||||
$page->display('menu',false);
|
||||
$page->content('admin/login.php');
|
||||
}
|
||||
else
|
||||
$page->content('admin/whoweare.php');
|
||||
|
||||
$page->attr('title','Discipling the Nations: Administrator Area: Who We Are');
|
||||
$page->menu('admin/menu.php');
|
||||
$page->addCSSFile('admin.css');
|
||||
|
||||
$page->process();
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user