86 lines
2.2 KiB
PHP
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: Passports');
|
|
// to make jquery be loaded first
|
|
$page->useJSFile('jquery.min.js');
|
|
$page->addJSFile('admin.js');
|
|
$page->useCSSFile('admin.css');
|
|
|
|
$page->content('admin/passports.php');
|
|
$page->layout('admin_layout.php');
|
|
$page->menu('admin/menu.php');
|
|
|
|
# get passports
|
|
$passports = xml_get_from_file($FILES['passportinfo']);
|
|
$page->data('passports',array_reverse($passports->xpath('passport')));
|
|
|
|
if(isset($_REQUEST['do']))
|
|
{
|
|
if($_REQUEST['do'] == 'view')
|
|
{
|
|
# find the passport
|
|
$passport = FindItemById($passports->xpath('passport'), $_GET['id']);
|
|
|
|
# if the passport was found above, send it to the template
|
|
if($passport)
|
|
{
|
|
$page->content('admin/passports.view.php');
|
|
$page->data('passport',$passport);
|
|
}
|
|
# passport not found, display error
|
|
else
|
|
$page->addError('That passport does not exist.');
|
|
}
|
|
else if($_REQUEST['do'] == 'delete')
|
|
{
|
|
# find the passport
|
|
$passport = FindItemById($passports->xpath('passport'), $_GET['id']);
|
|
|
|
if($passport)
|
|
{
|
|
$page->content('admin/passports.delete.php');
|
|
$page->data('passport',$passport);
|
|
}
|
|
else
|
|
$page->addError('That passport does not exist.');
|
|
}
|
|
else if($_REQUEST['do'] == 'reallydelete')
|
|
{
|
|
$passportIdx = FindItemById($passports->xpath('passport'),$_POST['id'],true);
|
|
unset($passports->passport[$passportIdx]);
|
|
file_put_contents($FILES['passportinfo'],$passports->asXML());
|
|
|
|
$page->data("passports",$passports->xpath('passport'));
|
|
$page->addMessage('Passport information successfully deleted.');
|
|
}
|
|
}
|
|
|
|
$page->process();
|
|
|
|
################################################################# FindItemById #
|
|
function FindItemById($items, $itemId, $returnIdx = false)
|
|
{
|
|
for($c = 0; $c < count($items); $c++)
|
|
{
|
|
if((int)$items[$c]['id'] == (int)$itemId)
|
|
if($returnIdx)
|
|
return $c;
|
|
else
|
|
return $items[$c];
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
?>
|