Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1278 → Rev 1281

/asterisk-stats/trunk/includes/db/postgresql.php
0,0 → 1,102
<?php
####################################################
# AstWeb - Asterisk PBX Dynamic config environment #
# #
# Written by: Jamie Carl #
# jazz@funkynerd.com #
# #
# Copyright (C) 2006 Achieve Corp #
# #
# Licence: This software is licenced under the #
# GNU/GPL. Please see licence.txt for #
# more information. #
####################################################
 
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
class db_obj {
private $connection;
private $result;
private $row;
function __construct($host, $user, $password, $database) {
$this->connection = pg_connect('host='.$host.' user='.$user.' password='.$password.' dbname='.$database) or
die("SQL service unavailable please try again later");
}
 
function __destruct() {
if($this->connection) {
pg_close($this->connection);
}
}
 
function query($sql) {
if($this->connection) {
$this->result = pg_query($this->connection, $sql) or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function query_params($sql, $params) {
if($this->connection) {
$this->result = pg_query_params($this->connection, $sql, $params)
or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function fetch_row() {
if($this->result) {
$this->row = pg_fetch_assoc($this->result);
return $this->row;
}
return false;
}
 
function fetch_row_idx() {
if($this->result) {
$this->row = pg_fetch_row($this->result);
return $this->row;
}
return false;
}
 
function fetch_all() {
if($this->result) {
return pg_fetch_all($this->result);
}
return false;
}
 
function num_rows() {
if($this->result) {
return pg_num_rows($this->result);
}
 
return 0;
}
 
function num_fields() {
if($this->result) {
return pg_num_fields($this->result);
}
}
 
function get_field_name($col) {
if($this->result) {
return pg_field_name($this->result, $col);
}
}
 
function get_field($col) {
if($this->row) {
return $this->row[$col];
}
return NULL;
}
}
?>
/asterisk-stats/trunk/includes/db.php
0,0 → 1,27
<?php
####################################################
# AstWeb - Asterisk PBX Dynamic config environment #
# #
# Written by: Jamie Carl #
# jazz@funkynerd.com #
# #
# Copyright (C) 2006 Achieve Corp #
# #
# Licence: This software is licenced under the #
# GNU/GPL. Please see licence.txt for #
# more information. #
####################################################
 
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
switch($db_type) {
case 'PGSQL':
include($includes.'/db/postgresql.php');
break;
}
 
$db = new db_obj($db_host, $db_user, $db_password, $db_database);
 
?>
/asterisk-stats/trunk/includes/display.php
0,0 → 1,236
<?php
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
class template_handler {
private $data = array();
private $files = array();
private $vars = array();
private $root;
 
function __construct($root_dir) {
$this->root = $root_dir;
}
function add_template($file) {
array_push($this->files, array('FILE' => $file));
}
 
function add_text($text) {
array_push($this->files, array('TEXT' => $text));
}
 
function __toString() {
foreach($this->files as $f) {
if(array_key_exists('FILE', $f)) {
$this->data = array_merge($this->data, file($this->root.'/'.$f['FILE'].'.tpl'));
}
if(array_key_exists('TEXT', $f)) {
array_push($this->data, $f['TEXT']."\n");
}
}
foreach($this->data as $l) {
$form = $form.$this->replace_variables($l);
}
 
return $form;
}
 
function replace_variables($data) {
$varrefs = array();
preg_match_all('/\$\{(\w+)\}/', $data, $varrefs);
$varcount = sizeof($varrefs[1]);
for ($i = 0; $i < $varcount; $i++) {
if(array_key_exists($varrefs[1][$i], $this->vars)) {
$data = str_replace($varrefs[0][$i], $this->vars[$varrefs[1][$i]], $data);
}
}
 
return $data;
}
 
function add_variables($args) {
if(is_array($args)) {
$this->vars = array_merge($this->vars, $args);
}
}
}
 
function display_link($url, $label) {
if(!$label) {
$label = $url;
}
 
return '<A HREF="'.$url.'">'.$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;
protected $rows = array();
protected $row_styles = array();
protected $hdr = array();
 
#Define an array to store the stylesheet classes for each row
protected $table_class = '';
protected $header_class = '';
 
function __construct($header = array()) {
$this->hdr = $header;
}
 
public function destroy() {
$this->hdr = array();
$this->sc = array();
$this->rows = array();
}
 
public function set_table_class($class) {
$this->table_class = $class;
}
 
public function newrow() {
$this->rows[] = array();
}
 
public function addcell($data) {
$key = count($this->rows) - 1;
if($key < 0) {
$this->newrow();
$key = 0;
}
 
if(!is_array($data)) {
$data = array('text' => $data);
}
 
$this->rows[$key][] = $data;
}
 
public function __toString() {
return $this->build();
}
 
public function build() {
$tag = "table";
if($this->table_class) $tag .= " class=\"$this->table_class\"";
 
$output = "<$tag>\n";
 
#Display the header
if($this->hdr) {
$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 .= "\t\t</tr>\n\t</thead>\n";
}
 
$output .= "\t<tbody>\n";
 
foreach($this->rows as $row) {
$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 .= "\t\t</tr>\n";
}
 
$output .= "\t</tbody>\n</table>\n";
 
return $output;
}
}
 
function Form($method, $action, $text) {
$form = '<form method="'.$method.'" action="'.$action.'">'."\n";
$form .= $text;
$form .= "</form>\n";
return $form;
}
 
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/includes/functions.php
0,0 → 1,49
<?php
 
if(!defined('IN_ASTWEB')) {
die('Hacking Attempt');
}
 
 
$PHP_SELF = $_SERVER['PHP_SELF'];
 
function GetGet($var) {
$val = "";
 
if(array_key_exists($var, $_GET)) {
$val = $_GET[$var];
} elseif(array_key_exists($var, $_POST)) {
$val = $_POST[$var];
} else {
$val = "";
}
 
$val = str_replace("'", "\\'", $val);
$val = str_replace('\\', '\\\\', $val);
 
return $val;
}
 
 
function Duration($seconds) {
$minutes = $seconds / 60;
$seconds = $seconds % 60;
$hours = $minutes / 60;
$minutes = $minutes % 60;
 
return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
}
 
function FormatTime($time) {
//Format the time to human readable format
$diff = $time;
$hrsdiff = floor($diff/60/60);
$diff -= $hrsdiff*60*60;
$minsdiff = floor($diff/60);
$diff -= $minsdiff*60;
$secsdiff = $diff;
 
return (' ('.$hrsdiff.'h '.$minsdiff.'m '.$secsdiff.'s)');
}
 
?>