/asterisk-stats/trunk/includes/display.php |
---|
90,7 → 90,7 |
protected $rowid = 0; |
protected $rows = array(); |
protected $row_styles = array(); |
protected $hdr = array(); |
protected $header_rows = array(); |
#Define an array to store the stylesheet classes for each row |
protected $table_class = ''; |
97,12 → 97,11 |
protected $header_class = ''; |
function __construct($header = array()) { |
$this->hdr = $header; |
array_push($this->header_rows, $header); |
} |
public function destroy() { |
$this->hdr = array(); |
$this->sc = array(); |
$this->header_rows = array(); |
$this->rows = array(); |
} |
114,6 → 113,10 |
$this->rows[] = array(); |
} |
public function add_header_row($row) { |
array_push($this->header_rows, $row); |
} |
public function addcell($data) { |
$key = count($this->rows) - 1; |
if($key < 0) { |
169,14 → 172,19 |
$output = "<$tag>\n"; |
#Display the header |
if($this->hdr) { |
$output .= "\t<thead>\n\t\t<tr>\n"; |
if(count($this->header_rows) > 0) { |
$output .= "\t<thead>\n"; |
foreach($this->hdr as $cell) { |
$output .= $this->build_cell($cell, 'th'); |
foreach($this->header_rows as $row) { |
$output .= "\t\t<tr>\n"; |
foreach($row as $cell) { |
$output .= $this->build_cell($cell, 'th'); |
} |
$output .= "\t\t</tr>\n"; |
} |
$output .= "\t\t</tr>\n\t</thead>\n"; |
$output .= "\t</thead>\n"; |
} |
$output .= "\t<tbody>\n"; |
197,9 → 205,20 |
} |
} |
function display_input($type, $name, $value = '') { |
return '<input type="' . htmlspecialchars($type) . '" name="' |
. htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . "\">"; |
function display_input($type, $name, $value = NULL, $additional = NULL) { |
return '<input type="' . htmlspecialchars($type) . '" name="' . htmlspecialchars($name) . '"' |
. ($value == NULL ? '' : ' value="' . htmlspecialchars($value) . '"') |
. ($additional == NULL ? '' : " $additional") |
. '>'; |
} |
function ellipsis($str, $len) { |
if(strlen($str) <= $len) { |
return htmlspecialchars($str); |
} |
else { |
return (htmlspecialchars(substr($str, 0, $len)) . '…'); |
} |
} |
?> |
/asterisk-stats/trunk/tables.sql |
---|
41,13 → 41,28 |
userfield varchar(255) |
); |
create table telbook_export ( |
export_id serial primary key, |
export_name varchar(255) not null unique, |
export_comment text |
); |
create table telbook_categories ( |
category_id serial primary key, |
category_name varchar(255) not null unique, |
category_export_key integer, |
category_comment text |
); |
create table telbook_categories_export ( |
export_id integer, |
category_id integer, |
category_export_title varchar(255), |
primary key (export_id, category_id), |
foreign key (export_id) references telbook_export(export_id), |
foreign key (category_id) references telbook_categories(category_id) |
); |
create table telbook_persons ( |
person_id serial primary key, |
person_name varchar(255) not null unique, |
67,3 → 82,12 |
foreign key (entry_person) references telbook_persons(person_id) |
); |
create table telbook_entries_export ( |
export_id integer, |
entry_id integer, |
primary key (export_id, entry_id), |
foreign key (export_id) references telbook_export(export_id), |
foreign key (entry_id) references telbook_entries(entry_id) |
); |
/asterisk-stats/trunk/template/telbook_category_details.tpl |
---|
File deleted |
Property changes: |
Deleted: svn:mergeinfo |
/asterisk-stats/trunk/template/telbook_list_end.tpl |
---|
1,8 → 1,9 |
<p><a href="telbook_details.php">New person</a></p> |
<p><a href="telbook_categories_list.php">Categories</a></p> |
<p><a href="telbook_export_list.php">Export Targets</a></p> |
<p>Export into format: |
<ul> |
<li><a href="telbook_export.php?type=panasonic">Panasonik</a></li> |
<li><a href="telbook_export.php?type=panasonic">Panasonic</a></li> |
</ul> |
/asterisk-stats/trunk/template/telbook_export_list_end.tpl |
---|
0,0 → 1,3 |
<p><a href="telbook_export_details.php?edit=">New export target</a></p> |
<p><a href="telbook_list.php">Back to tel. book</a></p> |
/asterisk-stats/trunk/template/telbook_category_details_end.tpl |
---|
0,0 → 1,12 |
</td> |
</tr> |
<tr class="buttons"> |
<td colspan=2> |
<input type=reset name="reset" value="Reset"> |
<input type=submit name=update value="Update"> |
<input type=submit name=delete value="Delete"> |
</td> |
</tr> |
</table> |
</form> |
/asterisk-stats/trunk/template/telbook_export_details.tpl |
---|
0,0 → 1,21 |
<form method="POST" action="telbook_export_update.php"> |
<input type=hidden name=id value="${EXPORT_ID}"> |
<table class="telbook edit"> |
<tr> |
<th>Name</th> |
<td><input type=text name=export_name value="${EXPORT_NAME}"></td> |
</tr> |
<tr> |
<th>Comment</th> |
<td><textarea name=export_comment>${EXPORT_COMMENT}</textarea></td> |
</tr> |
<tr class="buttons"> |
<td colspan=2> |
<input type=reset name="reset" value="Reset"> |
<input type=submit name=update value="Update"> |
<input type=submit name=delete value="Delete"> |
</td> |
</tr> |
</table> |
</form> |
/asterisk-stats/trunk/template/telbook_category_details_begin.tpl |
---|
0,0 → 1,13 |
<form method="POST" action="telbook_categories_update.php"> |
<input type=hidden name=id value="${CATEGORY_ID}"> |
<table class="telbook edit"> |
<tr> |
<th>Name</th> |
<td><input type=text name=category_name value="${CATEGORY_NAME}"></td> |
</tr> |
<tr> |
<th>Comment</th> |
<td><textarea name=category_comment>${CATEGORY_COMMENT}</textarea></td> |
</tr> |
<tr> |
<td colspan=2> |
/asterisk-stats/trunk/telbook_list.php |
---|
8,7 → 8,8 |
. " 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"); |
. " order by upper(person_name), person_name," |
. " upper(entry_title), entry_title, upper(entry_value), entry_value"); |
$table = new Table(array('Name', 'Category', 'Type', 'Number', '', '')); |
$table->set_table_class('telbook list'); |
/asterisk-stats/trunk/telbook_export_list.php |
---|
0,0 → 1,24 |
<?php |
include_once('includes/common.php'); |
Prolog(); |
$db->query("select export_id, export_name, export_comment" |
. " from telbook_export order by upper(export_name), export_name"); |
$table = new Table(array('Name', 'Comment', '')); |
$table->set_table_class('telbook list export_list'); |
while($line = $db->fetch_row()) { |
$table->newrow(); |
$table->addcell($line['export_name']); |
$table->addcell($line['export_comment']); |
$table->addcell(array('class' => 'link', 'html' => |
display_link('telbook_export_details.php?id=' . $line['export_id'], 'Edit'))); |
} |
$g_display->add_html_text($table->build()); |
$g_display->add_template('telbook_export_list_end'); |
Epilog(); |
?> |
/asterisk-stats/trunk/telbook_categories_list.php |
---|
3,10 → 3,10 |
include_once('includes/common.php'); |
Prolog(); |
$db->query("select category_id, category_name, category_comment, category_export_key" |
. " from telbook_categories order by category_name"); |
$db->query("select category_id, category_name, category_comment" |
. " from telbook_categories order by upper(category_name), category_name"); |
$table = new Table(array('Name', 'Comment', 'Export Key', '')); |
$table = new Table(array('Name', 'Comment', '')); |
$table->set_table_class('telbook list category_list'); |
while($line = $db->fetch_row()) { |
13,7 → 13,6 |
$table->newrow(); |
$table->addcell($line['category_name']); |
$table->addcell($line['category_comment']); |
$table->addcell($line['category_export_key']); |
$table->addcell(array('class' => 'link', 'html' => |
display_link('telbook_categories_details.php?id=' . $line['category_id'], 'Edit'))); |
} |
/asterisk-stats/trunk/telbook_update.php |
---|
6,6 → 6,8 |
if(array_key_exists('delete', $_POST)) { |
$id = $_POST['id']; |
$db->begin_transaction(); |
$db->query_params("delete from telbook_entries_export where entry_id" |
. " = (select entry_id from telbook_entries where entry_person=$1)", array($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)); |
$db->commit_transaction(); |
13,7 → 15,7 |
header("Location: telbook_list.php"); |
$g_display->add_text('Information deleted successfully'); |
} |
else if(array_key_exists('update', $_POST)) { |
elseif(array_key_exists('update', $_POST)) { |
$id = $_POST['id']; |
$person_name = $_POST['person_name']; |
$person_comment = $_POST['person_comment']; |
38,7 → 40,12 |
} |
} |
$db->query_params("delete from telbook_entries_export where entry_id" |
. " = (select entry_id from telbook_entries where entry_person=$1)", array($id)); |
$db->query_params("delete from telbook_entries where entry_person=$1", array($id)); |
# save entries |
$entries_id = array(); |
foreach($_POST as $key => $value) { |
if(substr($key, 0, strlen('entry_title-')) == 'entry_title-') { |
$entry_count = substr($key, strlen('entry_title-')); |
52,10 → 59,35 |
. " (entry_value, entry_title, entry_person, entry_comment)" |
. " values ($1, $2, $3, $4)", |
array($entry_value, $entry_title, $id, $entry_comment)); |
$db->query("select currval('telbook_entries_entry_id_seq')"); |
if($line = $db->fetch_row_idx()) { |
$entries_id[$entry_count] = $line[0]; |
} |
} |
} |
} |
# save entries export targets |
foreach($_POST as $key => $value) { |
if(substr($key, 0, strlen('entry_export-')) == 'entry_export-') { |
$substr_len = strlen('entry_export-'); |
$pos = strpos($key, '-', $substr_len); |
if($pos) { |
$entry_count = substr($key, $substr_len, $pos - $substr_len); |
$export_id = substr($key, $pos+1); |
$entry_id = $entries_id[$entry_count]; |
if($export_id && $entry_id) { |
$db->query_params("insert into telbook_entries_export" |
. " (export_id, entry_id)" |
. " values ($1, $2)", |
array($export_id, $entry_id)); |
} |
} |
} |
} |
$db->commit_transaction(); |
header("Location: telbook_list.php"); |
/asterisk-stats/trunk/telbook_export_update.php |
---|
0,0 → 1,40 |
<?php |
include_once('includes/common.php'); |
Prolog(); |
if(array_key_exists('delete', $_POST)) { |
$id = $_POST['id']; |
$db->begin_transaction(); |
$db->query_params("delete from telbook_categories_export where export_id=$1", array($id)); |
$db->query_params("delete from telbook_entries_export where export_id=$1", array($id)); |
$db->query_params("delete from telbook_export where export_id=$1", array($id)); |
$db->commit_transaction(); |
header("Location: telbook_export_list.php"); |
$g_display->add_text('Information deleted successfully'); |
} |
elseif(array_key_exists('update', $_POST)) { |
$id = $_POST['id']; |
$export_name = $_POST['export_name']; |
$export_comment = $_POST['export_comment']; |
if($id) { |
$db->query_params("update telbook_export set" |
. " export_name=$2, export_comment=$3" |
. " where export_id=$1", |
array($id, $export_name, $export_comment)); |
} |
else { |
$db->query_params("insert into telbook_export" |
. " (export_name, export_comment) values ($1, $2)", |
array($export_name, $export_comment)); |
} |
header("Location: telbook_export_list.php"); |
$g_display->add_text('Information saved successfully'); |
} |
Epilog(); |
?> |
/asterisk-stats/trunk/telbook_details.php |
---|
5,63 → 5,126 |
$id = $_GET['id']; |
# 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'], |
)); |
} |
# person and entries |
$person = array(); |
$table = new Table(array('Type', 'Number', 'Comment')); |
$person = NULL; |
$table = new Table(array( |
array('text' => 'Type', 'rowspan' => 2), |
array('text' => 'Number', 'rowspan' => 2), |
array('text' => 'Comment', 'rowspan' => 2), |
array('text' => 'Export', 'colspan' => count($export_targets)), |
)); |
$table->add_header_row($export_header); |
$table->set_table_class('telbook list'); |
$entry_count = 0; |
function add_entry_inputs($table, $entry_count, $entry_title, $entry_value, $entry_comment) |
function add_entry_inputs($table, $entry_count, $entry) |
{ |
global $export_targets; |
++$entry_count; |
$table->newrow(); |
$table->addcell(array('html' => display_input( |
'text', 'entry_title-' . $entry_count, $entry_title))); |
'text', 'entry_title-' . $entry_count, $entry['title']))); |
$table->addcell(array('html' => display_input( |
'text', 'entry_value-' . $entry_count, $entry_value))); |
'text', 'entry_value-' . $entry_count, $entry['value']))); |
$table->addcell(array('html' => display_input( |
'text', 'entry_comment-' . $entry_count, $entry_comment))); |
'text', 'entry_comment-' . $entry_count, $entry['comment']))); |
foreach($export_targets as $target) { |
$table->addcell(array('html' => display_input( |
'checkbox', 'entry_export-' . $entry_count . '-' . $target['export_id'], |
NULL, |
($entry['export'][$target['export_id']] ? 'checked' : NULL)))); |
} |
return $entry_count; |
} |
if($id) { |
$db->query_params("select person_id, person_name, person_comment, person_category," |
. " entry_title, entry_value, entry_comment" |
. " e.entry_id, entry_title, entry_value, entry_comment, export_id" |
. " from telbook_persons p" |
. " left join telbook_entries e on p.person_id=e.entry_person" |
. " where person_id=$1", array($id)); |
. " left join telbook_entries_export ex on e.entry_id=ex.entry_id" |
. " where person_id=$1" |
. " order by upper(person_name), person_name, upper(entry_title), entry_title, export_id", |
array($id)); |
$first_line = true; |
$entry = NULL; |
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($person == NULL) { |
$person = array( |
'PERSON_ID' => $line['person_id'], |
'PERSON_NAME' => $line['person_name'], |
'PERSON_COMMENT' => $line['person_comment'], |
'PERSON_CATEGORY' => $line['person_category'], |
); |
} |
if($line['entry_value']) { |
$entry_count = add_entry_inputs($table, $entry_count, |
$line['entry_title'], $line['entry_value'], $line['entry_comment']); |
if($entry != NULL && $entry['id'] != $line['entry_id']) { |
$entry_count = add_entry_inputs($table, $entry_count, $entry); |
$entry = NULL; |
} |
if($entry == NULL) { |
$entry = array( |
'id' => $line['entry_id'], |
'title' => $line['entry_title'], |
'value' => $line['entry_value'], |
'comment' => $line['entry_comment'], |
'export' => array(), |
); |
} |
$entry['export'][$line['export_id']] = true; |
} |
} |
# show the last one |
if($entry != NULL) { |
$entry_count = add_entry_inputs($table, $entry_count, $entry); |
} |
} |
else { |
$person['PERSON_ID'] = ''; |
$person['PERSON_NAME'] = ''; |
$person['PERSON_COMMENT'] = ''; |
$person['PERSON_CATEGORY'] = ''; |
$person = array( |
'PERSON_ID' => '', |
'PERSON_NAME' => '', |
'PERSON_COMMENT' => '', |
'PERSON_CATEGORY' => '', |
); |
} |
$g_display->add_variables($person); |
for($i = 0; $i < 5; ++$i) { |
$entry_count = add_entry_inputs($table, $entry_count, '', '', ''); |
$entry_count = add_entry_inputs($table, $entry_count, array( |
'id' => '', |
'title' => '', |
'value' => '', |
'comment' => '', |
'export' => array(), |
)); |
} |
# categories select box |
$db->query("select category_id, category_name from telbook_categories order by category_name"); |
$db->query("select category_id, category_name from telbook_categories" |
. " order by upper(category_name), 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='" |
/asterisk-stats/trunk/originate_form.php |
---|
10,7 → 10,8 |
$db->query_params("select entry_title, entry_value, person_name" |
. " from telbook_entries join telbook_persons on person_id=entry_person" |
. " where entry_title=$1" |
. " order by person_name, entry_title, entry_value", |
. " order by upper(person_name), person_name," |
. " upper(entry_title), entry_title, upper(entry_value), entry_value", |
array($g_config['originate_src'])); |
$src_list = ""; |
/asterisk-stats/trunk/telbook_export_details.php |
---|
0,0 → 1,31 |
<?php |
include_once('includes/common.php'); |
Prolog(); |
$id = $_GET['id']; |
$export = array(); |
if($id) { |
$db->query_params("select export_id, export_name, export_comment" |
. " from telbook_export" |
. " where export_id=$1", array($id)); |
if($line = $db->fetch_row()) { |
$export['EXPORT_ID'] = $line['export_id']; |
$export['EXPORT_NAME'] = $line['export_name']; |
$export['EXPORT_COMMENT'] = $line['export_comment']; |
} |
} |
else { |
$export['EXPORT_ID'] = ''; |
$export['EXPORT_NAME'] = ''; |
$export['EXPORT_COMMENT'] = ''; |
} |
$g_display->add_variables($export); |
$g_display->add_template('telbook_export_details'); |
Epilog(); |
?> |
/asterisk-stats/trunk/telbook_categories_update.php |
---|
5,29 → 5,58 |
if(array_key_exists('delete', $_POST)) { |
$id = $_POST['id']; |
$db->begin_transaction(); |
$db->query_params("update telbook_persons set person_category=NULL" |
. " where person_category=$1", array($id)); |
$db->query_params("delete from telbook_categories_export where category_id=$1", array($id)); |
$db->query_params("delete from telbook_categories where category_id=$1", array($id)); |
$db->commit_transaction(); |
header("Location: telbook_categories_list.php"); |
$g_display->add_text('Information deleted successfully'); |
} |
else if(array_key_exists('update', $_POST)) { |
$id = $_POST['id']; |
$category_name = $_POST['category_name']; |
$category_comment = $_POST['category_comment']; |
$category_export_key = ($_POST['category_export_key'] ? $_POST['category_export_key'] : NULL); |
elseif(array_key_exists('update', $_POST)) { |
$id = $_POST['id']; |
$category_name = $_POST['category_name']; |
$category_comment = $_POST['category_comment']; |
$db->begin_transaction(); |
if($id) { |
$db->query_params("update telbook_categories set" |
. " category_name=$2, category_comment=$3, category_export_key=$4" |
. " category_name=$2, category_comment=$3" |
. " where category_id=$1", |
array($id, $category_name, $category_comment, $category_export_key)); |
array($id, $category_name, $category_comment)); |
} |
else { |
$db->query_params("insert into telbook_categories" |
. " (category_name, category_comment, category_export_key) values ($1, $2, $3)", |
array($category_name, $category_comment, $category_export_key)); |
. " (category_name, category_comment) values ($1, $2)", |
array($category_name, $category_comment)); |
$db->query("select currval('telbook_categories_category_id_seq')"); |
if($line = $db->fetch_row_idx()) { |
$id = $line[0]; |
} |
} |
$db->query_params("delete from telbook_categories_export where category_id=$1", array($id)); |
# save entries |
foreach($_POST as $key => $value) { |
if(substr($key, 0, strlen('export_title-')) == 'export_title-') { |
$export_id = substr($key, strlen('export_title-')); |
if($value) { |
$db->query_params("insert into telbook_categories_export" |
. " (export_id, category_id, category_export_title)" |
. " values ($1, $2, $3)", |
array($export_id, $id, $value)); |
} |
} |
} |
$db->commit_transaction(); |
header("Location: telbook_categories_list.php"); |
$g_display->add_text('Information saved successfully'); |
} |
/asterisk-stats/trunk/telbook_categories_details.php |
---|
7,7 → 7,7 |
$category = array(); |
if($id) { |
$db->query_params("select category_id, category_name, category_comment, category_export_key" |
$db->query_params("select category_id, category_name, category_comment" |
. " from telbook_categories" |
. " where category_id=$1", array($id)); |
15,7 → 15,6 |
$category['CATEGORY_ID'] = $line['category_id']; |
$category['CATEGORY_NAME'] = $line['category_name']; |
$category['CATEGORY_COMMENT'] = $line['category_comment']; |
$category['CATEGORY_EXPORT_KEY'] = $line['category_export_key']; |
} |
} |
else { |
22,12 → 21,28 |
$category['CATEGORY_ID'] = ''; |
$category['CATEGORY_NAME'] = ''; |
$category['CATEGORY_COMMENT'] = ''; |
$category['CATEGORY_EXPORT_KEY'] = ''; |
} |
$g_display->add_variables($category); |
$g_display->add_template('telbook_category_details'); |
# export targets |
$table = new Table(array('Export Target', 'Export Title')); |
$db->query_params("select ex.export_id, export_name, export_comment," |
. " ce.category_id, ce.category_export_title" |
. " from telbook_export ex" |
. " left join telbook_categories_export ce on ce.export_id=ex.export_id and ce.category_id=$1" |
. " order by upper(export_name), export_name, category_id", array($id)); |
while($line = $db->fetch_row()) { |
$table->newrow(); |
$table->addcell($line['export_name']); |
$table->addcell(array('html' => display_input( |
'text', 'export_title-' . $line['export_id'], $line['category_export_title']))); |
} |
# show |
$g_display->add_template('telbook_category_details_begin'); |
$g_display->add_html_text($table->build()); |
$g_display->add_template('telbook_category_details_end'); |
Epilog(); |
?> |