Files
friendshiptours.org/admin/creditcards.php
2015-11-12 19:58:50 -06:00

86 lines
2.2 KiB
PHP

<?php
include '../php/classes/page.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'))
header('Location: login.php?message=1');
$page->attr('title','Administrate FTI: Credit Cards');
// to make jquery be loaded first
$page->useJSFile('jquery.min.js');
$page->addJSFile('admin.js');
$page->useCSSFile('admin.css');
$page->content('admin/creditcards.php');
$page->layout('admin_layout.php');
$page->menu('admin/menu.php');
# get news posts
$cards = xml_get_from_file($FILES['ccinfo']);
$page->data('creditcards',array_reverse($cards->xpath('creditcard')));
if(isset($_REQUEST['do']))
{
if($_REQUEST['do'] == 'view')
{
# find the credit card
$card = FindCreditCard($cards->xpath('creditcard'), $_GET['id']);
# if the card was found above, send it to the template
if($card)
{
$page->content('admin/creditcards.view.php');
$page->data('card',$card);
}
# card not found, display error
else
$page->addError('That credit card entry does not exist.');
}
else if($_REQUEST['do'] == 'delete')
{
# find the credit card
$card = FindCreditCard($cards->xpath('creditcard'), $_GET['id']);
if($card)
{
$page->content('admin/creditcards.delete.php');
$page->data('card',$card);
}
else
$page->addError('That credit card entry does not exist.');
}
else if($_REQUEST['do'] == 'reallydelete')
{
$cardIdx = FindCreditCard($cards->xpath('creditcard'),$_POST['id'],true);
unset($cards->creditcard[$cardIdx]);
file_put_contents($FILES['ccinfo'],$cards->asXML());
$page->data("creditcards",$cards);
$page->addMessage('Credit card information successfully deleted.');
}
}
$page->process();
############################################################### FindCreditCard #
function FindCreditCard($cards, $cardId, $returnIdx = false)
{
for($c = 0; $c < count($cards); $c++)
{
if((int)$cards[$c]['id'] == (int)$cardId)
if($returnIdx)
return $c;
else
return $cards[$c];
}
return NULL;
}
?>