Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1380 → Rev 1381

/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;
}
 
?>