1,137 → 1,8 |
<?php |
|
include_once('includes/common.php'); |
Prolog(); |
|
$display = new template_handler('template'); |
|
$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')); |
$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))); |
|
return $entry_count; |
} |
|
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>"; |
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]; |
} |
} |
|
$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" |
155,14 → 26,12 |
$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'))); |
display_link('telbook_details.php?id=' . $line['person_id'], 'Edit'))); |
$last_person_id = $line['person_id']; |
} |
$display->add_html_text($table->build()); |
$display->add_template('telbook_list_end'); |
} |
$g_display->add_html_text($table->build()); |
$g_display->add_template('telbook_list_end'); |
|
$display->add_template('footer'); |
echo $display; |
Epilog(); |
|
?> |
Property changes: |
Added: svn:mergeinfo |