<?php
/*
Location Controller
Also used as the template for new pages
new -> add -> display
edit -> update -> display
delete -> confirm -> deleted
display
*/
require 'sql.php';
class page extends pageParent {
public $template = 'location.html'; // default page
public function execute(){
//Does the user have permission to be here?
if (!$this->isEditor()){
$this->setError('You need to be logged in and have Editor properties for this story.', __LINE__,__FILE__);
return;
}
//Do we have a story id?
if(!isset($_REQUEST['storyid'])){
$this->setError('Strange... No Story ID found. That should not happen.', __LINE__, __FILE__);
return;
}
$this->setStory();
switch($this->op) {
case 'new':
// display new form only
return;
case 'add':
// sanity check the data and enter
$loc['loctitle'] = addslashes($_REQUEST['loctitle']);
$loc['locdesc'] = addslashes($_REQUEST['locdesc']);
$loc['locview'] = addslashes($_REQUEST['locview']);
$loc['storyid'] = $_REQUEST['storyid'];
if (!isset($_REQUEST['graphic'])) {
$loc['graphic'] = '';
} else {
$loc['graphic'] = $_REQUEST['graphic'];
}
$loc['createdby'] = session::get('uid');
if ($success = sql::insertLocation($loc)) {
$loc['locid'] = $success;
// woot - add it to the diplay data and we're ready to rock
$this->data = $this->data + $loc;
return;
}
$this->setError('Strange Programming Error occured. My bad.', __LINE__, __FILE__);
$this->op = 'new';
return;
case 'edit':
// internal sanity check - right story/location combo?
// display edit form only
return;
case 'update':
// internal sanity check - right story/location combo?
return;
case 'delete':
// Do they have a chapterid AND a storyid
if (!isset($_REQUEST['chapterid']) && !isset($_REQUEST['storyid'])){
$this->setError('This functionality requires Story Id and Chapter Id.');
return;
}
// Get the count
if (0 < sql::countScenesByLocation($_REQUEST['chapterid'],$_REQUEST['locid'])) {
$this->setError('Cannot delete a location which has scenes assigned to it.');
$this->data['scenes'] = sql::getScenesByLocation($_REQUEST['chapterid'],$_REQUEST['locid']);
return;
}
$this->data['chapterid'] = $_REQUEST['chapterid'];
return;
// display confirmation
return;
case 'confirm':
// check for confirmation
return;
case 'display':
}
}
}
?>