Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1380 → Rev 1381

/asterisk-stats/trunk/telbook_categories.php
0,0 → 1,88
<?php
 
include_once('includes/config.php');
include_once('includes/display.php');
include_once('includes/functions.php');
include_once('includes/db.php');
 
$display = new template_handler('template');
 
$display->add_template('header');
include('includes/menu.php');
 
if(array_key_exists('edit', $_GET)) {
$category = array();
 
if($_GET['edit']) {
$db->query_params("select category_id, category_name, category_comment, category_export_key"
. " from telbook_categories"
. " where category_id=$1", array($_GET['edit']));
 
if($line = $db->fetch_row()) {
$category['CATEGORY_ID'] = $line['category_id'];
$category['CATEGORY_NAME'] = $line['category_name'];
$category['CATEGORY_COMMENT'] = $line['category_comment'];
$category['CATEGORY_EXPORT_KEY'] = $line['category_export_key'];
}
}
else {
$category['CATEGORY_ID'] = '';
$category['CATEGORY_NAME'] = '';
$category['CATEGORY_COMMENT'] = '';
$category['CATEGORY_EXPORT_KEY'] = '';
}
$display->add_variables($category);
 
$display->add_template('telbook_category_edit');
}
else if(array_key_exists('delete', $_POST)) {
$id = $_POST['id'];
$db->query_params("delete from telbook_categories where category_id=$1", array($id));
 
header("Location: $PHP_SELF");
$display->add_text('Information deleted successfully');
}
else if(array_key_exists('update', $_POST)) {
$id = $_POST['id'];
$category_name = $_POST['category_name'];
$category_comment = $_POST['category_comment'];
$category_export_key = ($_POST['category_export_key'] ? $_POST['category_export_key'] : NULL);
 
if($id) {
$db->query_params("update telbook_categories set"
. " category_name=$2, category_comment=$3, category_export_key=$4"
. " where category_id=$1",
array($id, $category_name, $category_comment, $category_export_key));
}
else {
$db->query_params("insert into telbook_categories"
. " (category_name, category_comment, category_export_key) values ($1, $2, $3)",
array($category_name, $category_comment, $category_export_key));
}
 
header("Location: $PHP_SELF");
$display->add_text('Information saved successfully');
}
else {
$db->query("select category_id, category_name, category_comment, category_export_key"
. " from telbook_categories order by category_name");
 
$table = new Table(array('Name', 'Comment', 'Export Key', ''));
$table->set_table_class('telbook list category_list');
 
while($line = $db->fetch_row()) {
$table->newrow();
$table->addcell($line['category_name']);
$table->addcell($line['category_comment']);
$table->addcell($line['category_export_key']);
$table->addcell(array('class' => 'link', 'html' =>
display_link($PHP_SELF . '?edit=' . $line['category_id'], 'Edit')));
}
$display->add_html_text($table->build());
$display->add_template('telbook_category_list_end');
}
 
$display->add_template('footer');
echo $display;
 
?>