3,34 → 3,14 |
include_once('includes/common.php'); |
Prolog('Tel. Book Persons'); |
|
# export targets |
$export_targets = array(); |
$export_header = array(); |
$db->query("select export_id, export_name, export_comment from telbook_export" |
. " order by upper(export_name), export_name"); |
while($line = $db->fetch_row()) { |
array_push($export_targets, array( |
'export_id' => $line['export_id'], |
'export_name' => $line['export_name'], |
'export_comment' => $line['export_comment'], |
)); |
array_push($export_header, array( |
'html' => ellipsis($line['export_name'], 1), |
'comment' => $line['export_name'], |
)); |
} |
|
function add_person($table, $person) |
{ |
global $export_targets; |
|
if(!$person) return; |
|
$new_person = true; |
$first_line = true; |
foreach($person['entries'] as $entry) { |
$table->newrow(); |
|
if($new_person) { |
if($first_line) { |
$table->addcell(array( |
'text' => $person['person_name'], |
'comment' => $person['person_comment'], |
52,11 → 32,7 |
'comment' => $entry['entry_comment'], |
)); |
|
foreach($export_targets as $target) { |
$table->addcell($entry['export'][$target['export_id']] ? 'x' : ''); |
} |
|
if($new_person) { |
if($first_line) { |
$table->addcell(array( |
'class' => 'link', |
'html' => display_link('telbook_details.php?id=' |
71,34 → 47,22 |
. $entry['entry_value'], 'Call'), |
)); |
|
$new_person = false; |
$first_line = false; |
} |
} |
|
$db->query("select person_id, person_name, person_comment, category_name," |
. " category_comment, e.entry_id, entry_title, entry_value, entry_comment, export_id" |
. " 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" |
. " left join telbook_entries_export ex on e.entry_id=ex.entry_id" |
. " order by upper(person_name), person_name," |
. " upper(entry_title), entry_title, upper(entry_value), entry_value, export_id"); |
. " upper(entry_title), entry_title, upper(entry_value), entry_value"); |
|
$table = new Table(array( |
array('text' => 'Name', 'rowspan' => 2), |
array('text' => 'Category', 'rowspan' => 2), |
array('text' => 'Type', 'rowspan' => 2), |
array('text' => 'Number', 'rowspan' => 2), |
array('text' => 'Export', 'colspan' => count($export_targets)), |
array('text' => '', 'rowspan' => 2), |
array('text' => '', 'rowspan' => 2), |
)); |
$table->add_header_row($export_header); |
$table = new Table(array('Name', 'Category', 'Type', 'Number', '', '')); |
$table->set_table_class('telbook list'); |
|
$person = NULL; |
$entry = NULL; |
$export = NULL; |
while($line = $db->fetch_row()) { |
if($person == NULL || $line['person_id'] != $person['person_id']) { |
add_person($table, $person); |
110,23 → 74,13 |
'category_comment' => $line['category_comment'], |
'entries' => array(), |
); |
$entry = NULL; |
} |
|
if($entry == NULL || $entry['entry_id'] != $line['entry_id']) { |
$export = array(); |
$entry = array( |
'entry_id' => $line['entry_id'], |
'entry_title' => $line['entry_title'], |
'entry_value' => $line['entry_value'], |
'entry_comment' => $line['entry_comment'], |
'export' => $export, |
); |
array_push($person['entries'], $entry); |
$entry_num = count($person['entries'])-1; |
} |
|
$person['entries'][$entry_num]['export'][$line['export_id']] = true; |
array_push($person['entries'], array( |
'entry_title' => $line['entry_title'], |
'entry_value' => $line['entry_value'], |
'entry_comment' => $line['entry_comment'], |
)); |
} |
add_person($table, $person); |
|