Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1380 → Rev 1381

/asterisk-stats/trunk/import/panasonic.sh
0,0 → 1,6
# persons
cat panasonic.txt | awk "BEGIN {FS=\",\"} \$0 \!~ \"^;\" { n=substr(\$1, 2, length(\$1)-2); i=index(n, \"/\"); if(i > 0) { t=substr(n, i+1); n=substr(n, 1, i-1); } printf(\"insert into telbook_persons (person_name,person_category) select '%s', category_id from telbook_categories where category_export_key=%s;\\n\", n, \$2); }"
 
# entries
cat panasonic.txt | awk "BEGIN {FS=\",\"} \$0 \!~ \"^;\" { n=substr(\$1, 2, length(\$1)-2); i=index(n, \"/\"); if(i > 0) { t=substr(n, i+1); n=substr(n, 1, i-1); } printf(\"insert into telbook_entries (entry_value,entry_title,entry_person) select '%s', '%s', person_id from telbook_persons where person_name='%s';\\n\", \$3, t, n); }"
 
/asterisk-stats/trunk/telbook_categories.php
0,0 → 1,88
<?php
 
include_once('includes/config.php');
include_once('includes/display.php');
include_once('includes/functions.php');
include_once('includes/db.php');
 
$display = new template_handler('template');
 
$display->add_template('header');
include('includes/menu.php');
 
if(array_key_exists('edit', $_GET)) {
$category = array();
 
if($_GET['edit']) {
$db->query_params("select category_id, category_name, category_comment, category_export_key"
. " from telbook_categories"
. " where category_id=$1", array($_GET['edit']));
 
if($line = $db->fetch_row()) {
$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 {
$category['CATEGORY_ID'] = '';
$category['CATEGORY_NAME'] = '';
$category['CATEGORY_COMMENT'] = '';
$category['CATEGORY_EXPORT_KEY'] = '';
}
$display->add_variables($category);
 
$display->add_template('telbook_category_edit');
}
else if(array_key_exists('delete', $_POST)) {
$id = $_POST['id'];
$db->query_params("delete from telbook_categories where category_id=$1", array($id));
 
header("Location: $PHP_SELF");
$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);
 
if($id) {
$db->query_params("update telbook_categories set"
. " category_name=$2, category_comment=$3, category_export_key=$4"
. " where category_id=$1",
array($id, $category_name, $category_comment, $category_export_key));
}
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));
}
 
header("Location: $PHP_SELF");
$display->add_text('Information saved successfully');
}
else {
$db->query("select category_id, category_name, category_comment, category_export_key"
. " from telbook_categories order by category_name");
 
$table = new Table(array('Name', 'Comment', 'Export Key', ''));
$table->set_table_class('telbook list category_list');
 
while($line = $db->fetch_row()) {
$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($PHP_SELF . '?edit=' . $line['category_id'], 'Edit')));
}
$display->add_html_text($table->build());
$display->add_template('telbook_category_list_end');
}
 
$display->add_template('footer');
echo $display;
 
?>
/asterisk-stats/trunk/template/telbook_edit_end.tpl
0,0 → 1,10
<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_list_end.tpl
0,0 → 1,3
<p><a href="telbook_categories.php?edit=">New category</a></p>
<p><a href="telbook.php">Back to tel. book</a></p>
 
/asterisk-stats/trunk/template/telbook_list_end.tpl
0,0 → 1,8
<p><a href="telbook.php?edit=">New person</a></p>
<p><a href="telbook_categories.php">Categories</a></p>
 
<p>Export into format:
<ul>
<li><a href="telbook_export.php?type=panasonic">Panasonik</a></li>
</ul>
 
/asterisk-stats/trunk/template/telbook_category_edit.tpl
0,0 → 1,25
<form method="POST" action="telbook_categories.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>
<th>Export Key</th>
<td><input type=text name=category_export_key value="${CATEGORY_EXPORT_KEY}"></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/menu.tpl
3,5 → 3,6
<td><a href=..>Up</a></td>
<td><a href=${HREF_HOME}>Summary</a></td>
<td><a href=${HREF_CDR}>Search</a></td>
<td><a href=${HREF_TELBOOK}>Tel. Book</a></td>
</tr>
</table>
/asterisk-stats/trunk/template/cdr.tpl
1,4 → 1,4
<form method="${CDR_METHOD}" action="${CDR_ACTION}">
<form method="GET" action="index.php">
<input type=hidden name=m value=cdr>
<input type=hidden name=s>
<table class="stat cdr search">
47,3 → 47,5
<td><input type=submit value="Show CDR"></td>
</tr>
</table>
</form>
 
/asterisk-stats/trunk/template/telbook_edit_begin.tpl
0,0 → 1,18
<form method="POST" action="telbook.php">
<input type=hidden name=id value="${PERSON_ID}">
<table class="telbook edit">
<tr>
<th>Name</th>
<td><input type=text name=person_name value="${PERSON_NAME}"></td>
</tr>
<tr>
<th>Comment</th>
<td><textarea name=person_comment>${PERSON_COMMENT}</textarea></td>
</tr>
<tr>
<th>Category</th>
<td>
<select name=person_category>${CATEGORIES}
</select>
</td>
</tr>
/asterisk-stats/trunk/astweb.css
65,14 → 65,14
font-size: 8pt;
}
 
table.stat tr:hover td {
background-color: #AAAAAA;
}
 
table.cdr td.link {
border: none;
}
 
table.stat tr:hover td {
background-color: #AAAAAA;
}
 
table.calls {
width: 300px;
}
103,3 → 103,23
background-color: #FFFFFF;
}
 
table.telbook th {
color: #FFFFFF;
background-color: #6876F8;
font-weight: bold;
font-size: 10pt;
padding: 5px;
}
 
table.telbook td {
border: 1px solid #AAAAAA;
text-align: right;
padding: 5px;
vertical-align: text-bottom;
font-size: 8pt;
}
 
table.telbook tr.buttons td {
border: none;
}
 
/asterisk-stats/trunk/index.php
19,17 → 19,8
 
$display = new template_handler('template');
$display->add_template('header');
$display->add_template('menu');
include('includes/menu.php');
 
$pg_globals = array('AST_STYLESHEET' => $site_style,
'AST_SITETITLE' => $site_title,
'AST_DATETIME' => date('Y-m-d H:i:s'),
'HREF_HOME' => $PHP_SELF,
'HREF_CDR' => $PHP_SELF.'?m=cdr',
'HREF_CDR_LIST' => $PHP_SELF.'?m=cdr&list');
$display->add_variables($pg_globals);
 
switch($_GET['m']) {
case 'cdr':
include('includes/cdr.php');
/asterisk-stats/trunk/TODO
0,0 → 1,2
* transactions (telbook person save & delete)
* check input (telbook)
/asterisk-stats/trunk/telbook.php
0,0 → 1,171
<?php
 
include_once('includes/config.php');
include_once('includes/display.php');
include_once('includes/functions.php');
include_once('includes/db.php');
 
$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");
$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"
. " 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;
 
?>
/asterisk-stats/trunk/includes/cdr.php
153,7 → 153,7
display_link($PHP_SELF . '?m=cdr&' . ($active ? 'active' : 'detail')
. '=' . $line['acctid'], 'Details')));
}
$display->add_text($cdr->build());
$display->add_html_text($cdr->build());
// summary
if($active) {
177,10 → 177,9
$cdr->newrow();
$cdr->addcell(array('tag' => 'th', 'text' => 'Bill Seconds'));
$cdr->addcell(Duration($line['bill']));
$display->add_text($cdr->build());
$display->add_html_text($cdr->build());
}
else {
$display->add_variables(array('CDR_METHOD' => 'GET', 'CDR_ACTION' => $PHP_SELF));
$display->add_template('cdr');
}
?>
/asterisk-stats/trunk/includes/menu.php
0,0 → 1,15
<?php
 
$display->add_template('menu');
 
$display->add_variables(array(
'AST_STYLESHEET' => $site_style,
'AST_SITETITLE' => $site_title,
'AST_DATETIME' => date('Y-m-d H:i:s'),
'HREF_HOME' => 'index.php',
'HREF_CDR' => 'index.php?m=cdr',
'HREF_CDR_LIST' => 'index.php?m=cdr&list',
'HREF_TELBOOK' => 'telbook.php',
));
 
?>
/asterisk-stats/trunk/includes/display.php
1,7 → 1,6
<?php
 
class template_handler {
private $data = array();
private $files = array();
private $vars = array();
private $root;
15,21 → 14,37
}
 
function add_text($text) {
array_push($this->files, array('TEXT' => $text));
array_push($this->files, array('TEXT' => htmlspecialchars($text), "WITH_VARIABLES" => false));
}
 
function add_html_text($text) {
array_push($this->files, array('TEXT' => $text, "WITH_VARIABLES" => false));
}
 
function add_html_text_with_variables($text) {
array_push($this->files, array('TEXT' => $text, "WITH_VARIABLES" => true));
}
 
function __toString() {
$form = '';
 
foreach($this->files as $f) {
if(array_key_exists('FILE', $f)) {
$this->data = array_merge($this->data, file($this->root.'/'.$f['FILE'].'.tpl'));
$file_data = file($this->root.'/'.$f['FILE'].'.tpl');
 
foreach($file_data as $l) {
$form .= $this->replace_variables($l);
}
}
if(array_key_exists('TEXT', $f)) {
array_push($this->data, $f['TEXT']."\n");
if($f['WITH_VARIABLES']) {
$form .= $this->replace_variables($f['TEXT']);
}
else {
$form .= $f['TEXT'];
}
}
}
foreach($this->data as $l) {
$form = $form.$this->replace_variables($l);
}
 
return $form;
}
49,6 → 64,14
 
function add_variables($args) {
if(is_array($args)) {
foreach($args as $key => $value) {
$this->vars[$key] = htmlspecialchars($value);
}
}
}
 
function add_html_variables($args) {
if(is_array($args)) {
$this->vars = array_merge($this->vars, $args);
}
}
59,22 → 82,9
$label = $url;
}
 
return '<A HREF="'.$url.'">'.$label.'</a>';
return '<A HREF="' . htmlspecialchars($url) . '">' . htmlspecialchars($label) . '</a>';
}
 
function s_text($text) {
if(is_array($text)) {
for($i=0;$i<sizeof($text);$i++) {
$text[$i] = ereg_replace('<', '&lt;', $text[$i]);
$text[$i] = ereg_replace('>', '&gt;', $text[$i]);
}
} else {
$text = ereg_replace('<', '&lt;', $text);
}
 
return $text;
}
 
class Table {
#Define somewhere to store the rows
protected $rowid = 0;
122,9 → 132,33
return $this->build();
}
 
private function build_cell($cell, $default_tag) {
if(!is_array($cell)) $cell = array('text' => $cell);
 
$tag = $cell['tag'] ? htmlspecialchars($cell['tag']) : $default_tag;
 
$output = "\t\t\t<" . $tag;
if($cell['class']) {
$output .= ' class="' . htmlspecialchars($cell['class']) . '"';
}
if($cell['comment']) {
$output .= " title=\"" . htmlspecialchars($cell['comment']) . "\"";
}
 
if($cell['text']) {
$html = htmlspecialchars($cell['text']);
}
else {
$html = $cell['html'];
}
if(!$html) $html = '&nbsp;';
 
return ($output . ">" . $html . "</" . $tag . ">\n");
}
 
public function build() {
$tag = "table";
if($this->table_class) $tag .= " class=\"$this->table_class\"";
if($this->table_class) $tag .= " class=\"" . htmlspecialchars($this->table_class) . "\"";
 
$output = "<$tag>\n";
 
133,23 → 167,7
$output .= "\t<thead>\n\t\t<tr>\n";
 
foreach($this->hdr as $cell) {
if(!is_array($cell)) $cell = array('text' => $cell);
 
$tag = $cell['tag'] ? $cell['tag'] : 'th';
 
$output .= "\t\t\t<" . $tag;
if($cell['class']) {
$output .= " class=\"$class\"";
}
 
if($cell['text']) {
$html = s_text($cell['text']);
}
else {
$html = $cell['html'];
}
 
$output .= ">" . $html . "</" . $tag . ">\n";
$output .= $this->build_cell($cell, 'th');
}
 
$output .= "\t\t</tr>\n\t</thead>\n";
161,22 → 179,7
$output .= "\t\t<tr>\n";
 
foreach($row as $cell) {
$tag = $cell['tag'] ? $cell['tag'] : 'td';
 
$output .= "\t\t\t<" . $tag;
if($cell['class']) {
$output .= ' class="' . $cell['class'] . '"';
}
 
if($cell['text']) {
$html = s_text($cell['text']);
}
else {
$html = $cell['html'];
}
if(!$html) $html = '&nbsp;';
 
$output .= ">" . $html . "</" . $tag . ">\n";
$output .= $this->build_cell($cell, 'td');
}
 
$output .= "\t\t</tr>\n";
188,46 → 191,9
}
}
 
function Form($method, $action, $text) {
$form = '<form method="'.$method.'" action="'.$action.'">'."\n";
$form .= $text;
$form .= "</form>\n";
return $form;
function display_input($type, $name, $value = '') {
return '<input type="' . htmlspecialchars($type) . '" name="'
. htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . "\">";
}
 
function Input($type,$name,$value = '') {
return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'">'."\n";
}
 
function Combo($name, $data, $default) {
if(is_array($data)) {
$output = '<SELECT NAME="'.$name."\">\n";
foreach($data as $options) {
$output .= "\t<OPTION ";
if(is_array($options)) {
$op = array_values($options);
if($default == $op[0]) {
$output .= 'SELECTED ';
}
$output .= 'value="'.$op[0].'">';
if($op[1] == '') {
$output .= $op[0];
} else {
$output .= $op[1];
}
$output .= '</OPTION>'."\n";
} else {
if($options == $default) {
$output .= 'SELECTED ';
}
$output .= 'value="'.$options.'">1'.$options;
}
$output .= "</option>\n";
}
$output .= '</SELECT>'."\n";
}
 
return $output;
}
 
?>
/asterisk-stats/trunk/telbook_export.php
0,0 → 1,39
<?php
 
include_once('includes/config.php');
include_once('includes/display.php');
include_once('includes/functions.php');
include_once('includes/db.php');
 
if($_GET['type'] == 'panasonic') {
$db->query("select person_name, category_export_key, entry_title, entry_value"
. " 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");
 
header("Content-Type: text/plain");
echo "; Panasonic Communications Co., Ltd. Phonebook DECT Version 2.00\n";
 
$keys = array();
 
while($line = $db->fetch_row()) {
if($line[entry_value]) {
$key_base = $line['person_name'] .
($line['entry_title'] ? "/" . $line['entry_title'] : '');
$key = $key_base;
$count = 0;
while($keys[$key]) {
$key = $key_base . (++$count);
}
$keys[$key] = true;
 
echo '"' . $key . '",'
. ($line[category_export_key] ? $line[category_export_key] : 0)
. ',' . $line[entry_value] . "\n";
}
 
}
}
 
?>