1,13 → 1,10 |
<?php |
|
include_once('includes/common.php'); |
Prolog(); |
|
$display = new template_handler('template'); |
$id = $_GET['id']; |
|
$display->add_template('header'); |
include('includes/menu.php'); |
|
if(array_key_exists('edit', $_GET)) { |
# person and entries |
$person = array(); |
$table = new Table(array('Type', 'Number', 'Comment')); |
28,12 → 25,12 |
return $entry_count; |
} |
|
if($_GET['edit']) { |
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($_GET['edit'])); |
. " where person_id=$1", array($id)); |
|
$first_line = true; |
while($line = $db->fetch_row()) { |
57,7 → 54,7 |
$person['PERSON_COMMENT'] = ''; |
$person['PERSON_CATEGORY'] = ''; |
} |
$display->add_variables($person); |
$g_display->add_variables($person); |
|
for($i = 0; $i < 5; ++$i) { |
$entry_count = add_entry_inputs($table, $entry_count, '', '', ''); |
72,97 → 69,13 |
. ($line['category_id'] == $person['PERSON_CATEGORY'] ? " selected" : "") |
. ">" . htmlspecialchars($line['category_name']) . "</option>"; |
} |
$display->add_html_variables(array('CATEGORIES' => $categories_list)); |
$g_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)); |
$g_display->add_template('telbook_details_begin'); |
$g_display->add_html_text($table->build()); |
$g_display->add_template('telbook_details_end'); |
|
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']); |
Epilog(); |
|
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]; |
} |
} |
|
$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)); |
} |
} |
} |
|
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"); |
|
$table = new Table(array('Name', 'Category', 'Type', 'Number', '')); |
$table->set_table_class('telbook list'); |
|
$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'); |
} |
|
$display->add_template('footer'); |
echo $display; |
|
?> |
Property changes: |
Added: svn:mergeinfo |