Subversion Repositories general

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1383 → Rev 1385

/asterisk-stats/trunk/telbook_details.php/telbook.php
1,168 → 1,81
<?php
 
include_once('includes/common.php');
Prolog();
 
$display = new template_handler('template');
$id = $_GET['id'];
 
$display->add_template('header');
include('includes/menu.php');
# person and entries
$person = array();
$table = new Table(array('Type', 'Number', 'Comment'));
$table->set_table_class('telbook list');
 
if(array_key_exists('edit', $_GET)) {
# person and entries
$person = array();
$table = new Table(array('Type', 'Number', 'Comment'));
$table->set_table_class('telbook list');
$entry_count = 0;
function add_entry_inputs($table, $entry_count, $entry_title, $entry_value, $entry_comment)
{
++$entry_count;
$table->newrow();
$table->addcell(array('html' => display_input(
'text', 'entry_title-' . $entry_count, $entry_title)));
$table->addcell(array('html' => display_input(
'text', 'entry_value-' . $entry_count, $entry_value)));
$table->addcell(array('html' => display_input(
'text', 'entry_comment-' . $entry_count, $entry_comment)));
 
$entry_count = 0;
function add_entry_inputs($table, $entry_count, $entry_title, $entry_value, $entry_comment)
{
++$entry_count;
$table->newrow();
$table->addcell(array('html' => display_input(
'text', 'entry_title-' . $entry_count, $entry_title)));
$table->addcell(array('html' => display_input(
'text', 'entry_value-' . $entry_count, $entry_value)));
$table->addcell(array('html' => display_input(
'text', 'entry_comment-' . $entry_count, $entry_comment)));
return $entry_count;
}
 
return $entry_count;
}
if($id) {
$db->query_params("select person_id, person_name, person_comment, person_category,"
. " entry_title, entry_value, entry_comment"
. " from telbook_persons p"
. " left join telbook_entries e on p.person_id=e.entry_person"
. " where person_id=$1", array($id));
 
if($_GET['edit']) {
$db->query_params("select person_id, person_name, person_comment, person_category,"
. " entry_title, entry_value, entry_comment"
. " from telbook_persons p"
. " left join telbook_entries e on p.person_id=e.entry_person"
. " where person_id=$1", array($_GET['edit']));
 
$first_line = true;
while($line = $db->fetch_row()) {
if($first_line) {
$person['PERSON_ID'] = $line['person_id'];
$person['PERSON_NAME'] = $line['person_name'];
$person['PERSON_COMMENT'] = $line['person_comment'];
$person['PERSON_CATEGORY'] = $line['person_category'];
$first_line = false;
}
 
if($line['entry_value']) {
$entry_count = add_entry_inputs($table, $entry_count,
$line['entry_title'], $line['entry_value'], $line['entry_comment']);
}
}
}
else {
$person['PERSON_ID'] = '';
$person['PERSON_NAME'] = '';
$person['PERSON_COMMENT'] = '';
$person['PERSON_CATEGORY'] = '';
}
$display->add_variables($person);
 
for($i = 0; $i < 5; ++$i) {
$entry_count = add_entry_inputs($table, $entry_count, '', '', '');
}
 
# categories select box
$db->query("select category_id, category_name from telbook_categories order by category_name");
$categories_list = "\n\t\t\t\t<option value=''>(none)</option>";
$first_line = true;
while($line = $db->fetch_row()) {
$categories_list .= "\n\t\t\t\t<option value='"
. htmlspecialchars($line['category_id']) . "'"
. ($line['category_id'] == $person['PERSON_CATEGORY'] ? " selected" : "")
. ">" . htmlspecialchars($line['category_name']) . "</option>";
}
$display->add_html_variables(array('CATEGORIES' => $categories_list));
 
# show
$display->add_template('telbook_edit_begin');
$display->add_html_text($table->build());
$display->add_template('telbook_edit_end');
}
else if(array_key_exists('delete', $_POST)) {
$id = $_POST['id'];
$db->query_params("delete from telbook_entries where entry_person=$1", array($id));
$db->query_params("delete from telbook_persons where person_id=$1", array($id));
 
header("Location: $PHP_SELF");
$display->add_text('Information deleted successfully');
}
else if(array_key_exists('update', $_POST)) {
$id = $_POST['id'];
$person_name = $_POST['person_name'];
$person_comment = $_POST['person_comment'];
$person_category = ($_POST['person_category'] == '' ? NULL : $_POST['person_category']);
 
if($id) {
$db->query_params("update telbook_persons set"
. " person_name=$2, person_comment=$3, person_category=$4"
. " where person_id=$1",
array($id, $person_name, $person_comment, $person_category));
}
else {
$db->query_params("insert into telbook_persons"
. " (person_name, person_comment, person_category) values ($1, $2, $3)",
array($person_name, $person_comment, $person_category));
 
$db->query("select currval('telbook_persons_person_id_seq')");
if($line = $db->fetch_row_idx()) {
$id = $line[0];
if($first_line) {
$person['PERSON_ID'] = $line['person_id'];
$person['PERSON_NAME'] = $line['person_name'];
$person['PERSON_COMMENT'] = $line['person_comment'];
$person['PERSON_CATEGORY'] = $line['person_category'];
$first_line = false;
}
}
 
$db->query_params("delete from telbook_entries where entry_person=$1", array($id));
foreach($_POST as $key => $value) {
if(substr($key, 0, strlen('entry_title-')) == 'entry_title-') {
$entry_count = substr($key, strlen('entry_title-'));
 
$entry_title = $_POST['entry_title-' . $entry_count];
$entry_value = $_POST['entry_value-' . $entry_count];
$entry_comment = $_POST['entry_comment-' . $entry_count];
 
if($entry_value) {
$db->query_params("insert into telbook_entries"
. " (entry_value, entry_title, entry_person, entry_comment)"
. " values ($1, $2, $3, $4)",
array($entry_value, $entry_title, $id, $entry_comment));
}
if($line['entry_value']) {
$entry_count = add_entry_inputs($table, $entry_count,
$line['entry_title'], $line['entry_value'], $line['entry_comment']);
}
}
 
header("Location: $PHP_SELF");
$display->add_text('Information saved successfully');
}
else {
$db->query("select person_id, person_name, person_comment, category_name,"
. " category_comment, entry_title, entry_value, entry_comment"
. " from telbook_persons p"
. " left join telbook_categories c on p.person_category=c.category_id"
. " left join telbook_entries e on p.person_id=e.entry_person"
. " order by person_name, entry_title, entry_value");
$person['PERSON_ID'] = '';
$person['PERSON_NAME'] = '';
$person['PERSON_COMMENT'] = '';
$person['PERSON_CATEGORY'] = '';
}
$g_display->add_variables($person);
 
$table = new Table(array('Name', 'Category', 'Type', 'Number', ''));
$table->set_table_class('telbook list');
for($i = 0; $i < 5; ++$i) {
$entry_count = add_entry_inputs($table, $entry_count, '', '', '');
}
 
$last_person_id = NULL;
while($line = $db->fetch_row()) {
$table->newrow();
//$same_person = ($line['person_id'] == $last_person_id);
$table->addcell($same_person ? '' : array('text' => $line['person_name'],
'comment' => $line['person_comment']));
$table->addcell($same_person ? '' : array('text' => $line['category_name'],
'comment' => $line['category_comment']));
$table->addcell(array('text' => $line['entry_title'],
'comment' => $line['entry_comment']));
$table->addcell(array('text' => $line['entry_value'],
'comment' => $line['entry_comment']));
$table->addcell($same_person ? '' : array('class' => 'link', 'html' =>
display_link($PHP_SELF . '?edit=' . $line['person_id'], 'Edit')));
$last_person_id = $line['person_id'];
}
$display->add_html_text($table->build());
$display->add_template('telbook_list_end');
# categories select box
$db->query("select category_id, category_name from telbook_categories order by category_name");
$categories_list = "\n\t\t\t\t<option value=''>(none)</option>";
while($line = $db->fetch_row()) {
$categories_list .= "\n\t\t\t\t<option value='"
. htmlspecialchars($line['category_id']) . "'"
. ($line['category_id'] == $person['PERSON_CATEGORY'] ? " selected" : "")
. ">" . htmlspecialchars($line['category_name']) . "</option>";
}
$g_display->add_html_variables(array('CATEGORIES' => $categories_list));
 
$display->add_template('footer');
echo $display;
# show
$g_display->add_template('telbook_details_begin');
$g_display->add_html_text($table->build());
$g_display->add_template('telbook_details_end');
 
Epilog();
 
?>
Property changes:
Added: svn:mergeinfo