Location: PHPKode > projects > Informium > admin/topic.php
<?

//
// Copyright (c) 2002, Cameron McKay
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions 
// are met:

// * Redistributions of source code must retain the above copyright 
//   notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright 
//   notice, this list of conditions and the following disclaimer in the 
//   documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

//
// Informium -- Advanced News Script
//
// Topic Administration Script (topic.php)
//
// Author: Cameron McKay
// Note:   Allows for the manipulation of topics.
//

// Import CONF.
require_once('../conf/inf-conf.php');

// Import TOPIC and XHTML class.
require_once("$CONF[local_path]/class/topic-class.php");
require_once("$CONF[local_path]/class/xhtml-class.php");

// Make new TOPIC and XHTML objects.
$topic = new topic();
$xhtml = new xhtml();

// For Header.
if ($form)        $option = $form;
if ($dropdown)    $option = $dropdown;
if ($exec)        $option = $exec; 

// Header.
$xhtml->header(ucfirst($option) . ' Topic');

// Import common menu.
require_once("$CONF[local_path]/admin/common-menu.php");

// Determine course of action.
if (!strcmp($form, 'add'))
	// Present the user with an add form.
	$topic->form();

else if (!strcmp($form, 'edit'))
	// Present the user with an edit form.
	$topic->form($topic_id);

else if (!strcmp($dropdown, 'edit')) {
	// Present the user with a dropdown menu of all topics.
	$topic->dropdown('edit');

} else if (!strcmp($dropdown, 'delete')) {
	// Present the user with a dropdown menu of all topics.
	$topic->dropdown('delete');

} else if (!strcmp($exec, 'add')) {

	// Import USER class, if needed.
	require_once("$CONF[local_path]/class/user-class.php");

	// Make a new USER objects.
	$user = new user();

	// Check user's access level.
	$access = $user->info(0, 'access');

	// Respond to user.
	$xhtml->table_start('normal', $CONF[table_size]);

	// If they have an access level greater than 3, than we can add topics.
	if ($access > 3) {

		// Add the topic to the database.
		$topic_id = $topic->add($topic_name, $image_id);

		// If the post_id is less than 0, then we're missing a field.
		if ($topic_id < 0) {

			echo "One or more fields are missing.<br />\n";
			echo "<br />\n";
			echo "Return to <a href='$CONF[www_address]/admin/topic.php?form=add'>Add a New Topic</a>.\n";

		// If it's greater than 0, than we're fine.
		} else if ($topic_id > 0) {

			echo "Topic <b><i>#</i>$topic_id</b> added.<br />\n";
			echo "<br />\n";
			echo "Return to <a href='$CONF[www_address]/admin/admin.php'>Main Menu</a>.\n";

		}

	// Otherwise warn them.
	} else {

			echo "You are not permitted to add topics.<br />\n";
			echo "<br />\n";
			echo "Return to <a href='$CONF[www_address]/admin/admin.php'>Main Menu</a>.\n";

	}
	
	// End the table.
	$xhtml->table_end();

} else if (!strcmp($exec, 'edit') || !strcmp($exec, 'delete')) {

	// Import USER class, if needed.
	require_once("$CONF[local_path]/class/user-class.php");

	// Make a new USER objects.
	$user = new user();

	// Check user's access level.
	$list = $user->info(0);

	// Respond to user.
	$xhtml->table_start('normal', $CONF[table_size]);

	// If they have an access level greater than 3, than we can edit or delete topics.
	if ($list[access] > 3) {
		
		if (!strcmp($exec, 'edit')) {
			// Update the topic in the database.
			$topic_id = $topic->edit($topic_id, $topic_name, $image_id);

		} else if (!strcmp($exec, 'delete')) {
			// Delete the topic in the database.
			$topic->delete($topic_id);

		}

		echo "Topic <b><i>#</i>$topic_id</b> edited or deleted.<br />\n";
		echo "<br />\n";
		echo "Return to <a href='$CONF[www_address]/admin/topic.php?dropdown=edit'>Edit an Existing Topic</a>.<br />\n";
		echo "Return to <a href='$CONF[www_address]/admin/topic.php?dropdown=delete'>Delete an Existing Topic</a>.<br />\n";
		echo "Return to <a href='$CONF[www_address]/admin/admin.php'>Main Menu</a>.\n";

	} else {

		echo "You are not permitted to edit or delete topics.<br />\n";
		echo "<br />\n";
		echo "Return to <a href='$CONF[www_address]/admin/admin.php'>Main Menu</a>.\n";
 
	}	
 
     // End the table.
     $xhtml->table_end();

} 

// Footer.
$xhtml->footer();

?>
Return current item: Informium