1,91 → 1,15 |
<?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)) { |
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'); |
header("Location: telbook_list.php"); |
$g_display->add_text('Information deleted successfully'); |
} |
else if(array_key_exists('update', $_POST)) { |
$id = $_POST['id']; |
128,41 → 52,10 |
} |
} |
|
header("Location: $PHP_SELF"); |
$display->add_text('Information saved successfully'); |
header("Location: telbook_list.php"); |
$g_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'); |
Epilog(); |
|
$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 |