config = $config;
$this->ui = $ui;
$this->search_base= $this->config->current['BASE'];
$this->month = date("m");
$this->year = date("Y");
/* Use filter settings if we have already searched */
if (!session::is_set("fonfilter")){
$fonfilter = array();
foreach($this->attributes_SO as $name){
$fonfilter[$name]=$this->$name;
}
session::set("fonfilter", $fonfilter);
}else{
$fonfilter = session::get("fonfilter");
foreach($this->attributes_SO as $name){
$this->$name = $fonfilter[$name];
}
}
// Get ALL valid FAX-Accounts and their dns, this allows us to perform correct
// permissions checks later.
$filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))".
"(objectClass=goFonAccount)(telephoneNumber=*))";
$tmp= get_list($filter, "users/viewFonEntries", $this->search_base,
array("telephoneNumber"), GL_SUBSEARCH | GL_NO_ACL_CHECK);
$this->telephoneNumberToDN = array();
foreach($tmp as $attrs){
for($i=0;$i<$attrs['telephoneNumber']['count']; $i++){
$this->telephoneNumberToDN[$attrs['telephoneNumber'][$i]] = $attrs['dn'];
}
}
}
/* Save ui interactions and store results in session,
to remember settings */
function save_object()
{
$fonfilter= session::get("fonfilter");
if(isset($_POST['EntryPerPage'])){
$this->range = $_POST['EntryPerPage'];
}
if (isset($_GET['start'])){
$this->start= (int)$_GET['start'];
}
foreach( array("year", "month", "search_for","selected_server") as $type){
if (isset($_POST[$type])){
$this->$type= get_post($type);
}
}
/* Adapt sorting */
if (isset($_GET['sort'])){
if ($this->sort == (int)$_GET['sort']){
if ($this->sort_direction == "down"){
$this->sort_direction= "up";
} else {
$this->sort_direction= "down";
}
}
$this->sort= (int)$_GET['sort'];
if ($this->sort < 0 || $this->sort > 6){
$this->sort= 0;
}
}
/* remove unwanted tags */
$this->search_for = stripslashes(preg_replace("/[^0-9a-z\*\+ \-\/]/i","",$this->search_for));
foreach($this->attributes_SO as $name){
$fonfilter[$name] = $this->$name;
}
session::set("fonfilter", $fonfilter);
}
/* Search & display results */
function execute()
{
/* Call parent execute */
plugin::execute();
// Use the configured global timezone settings
timezone::get_default_timezone();
/* GVet template engine */
$smarty= get_smarty();
/* Log view */
if(!$this->view_logged){
$this->view_logged = TRUE;
new log("view","fonreport/".get_class($this),$this->dn);
}
/*****************
Variable Init
*****************/
$fields_str = "";
$months= array();
for($i = 1 ; $i <= 12 ; $i ++ ){
$months[$i] = _(date("F",gmmktime(0,0,0,$i)));
}
/* Prepare template */
$current= date("Y");
$years= array();
for ($y= $current - 5; $y<=$current; $y++){
$years[$y]= $y;
}
/*****************
Smarty
*****************/
$smarty->assign("plug", "?plug=".validate($_GET['plug']));
$smarty->assign("search_for", htmlentities($this->search_for));
$smarty->assign("months", $months);
$smarty->assign("month_select", $this->month);
$smarty->assign("years", $years);
$smarty->assign("year_select", $this->year);
$smarty->assign("search_result", "");
/*****************
Check Database , Table , Connection
*****************/
// Collect servers and allow to select the server in the ui.
$servers = array();
foreach($this->config->data['SERVERS']['FON'] as $key => $server){
$servers[$server['SERVER']] = $server['SERVER'];
}
$smarty->assign("servers", $servers);
$smarty->assign("selected_server", $this->selected_server);
/* Connecting, selecting database */
if (!isset($this->config->data['SERVERS']['FON'][0])){
msg_dialog::display(_("Configuration error"), msgPool::noserver(
_("GOfon")), WARNING_DIALOG);
return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
}elseif(!is_callable("mysql_connect")){
msg_dialog::display(_("Configuration error"), msgPool::missingext("php-mysql"), WARNING_DIALOG);
return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
}else{
// Get CFG for the selected server, if empty use first.
if($this->selected_server == ""){
$cfg= $this->config->data['SERVERS']['FON'][0];
}else{
foreach($this->config->data['SERVERS']['FON'] as $server){
if($server['SERVER'] == $this->selected_server){
$cfg = $server;
}
}
}
$link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']);
if ($link === FALSE){
msg_dialog::display(_("Error"), msgPool::dbconnect(
_("GOfon"),@mysql_error(),$cfg['SERVER']),ERROR_DIALOG);
return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
}
if (! @mysql_select_db("gophone")){
msg_dialog::display(_("Error"), msgPool::dbselect(
_("GOfon"),@mysql_error(),$cfg['DB']),ERROR_DIALOG);
return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
}
}
/*****************
Get Query String && Search
*****************/
// Get entries for the selected range only.
$link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']);
@DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
$query = $this->CreateQuerySyntax();
$result = @mysql_query($query);
if ($result === false){
msg_dialog::display(_("Error"), msgPool::dbquery(
_("GOfon"),@mysql_error(),$cfg['SERVER']),ERROR_DIALOG);
return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
}
/*****************
Fetch results
*****************/
$report_list= array();
/* Restricted attributes will not be displayed, this will be displayed instead */
$no_acl = "";
$no_acl = " -";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Get dn to check ACLs for
// Existing ldap-user -> use its dn
// Not existing user -> use ldap base dn
$dn = $this->search_base;
if(isset($this->telephoneNumberToDN[$line['src']])){
$dn = $this->telephoneNumberToDN[$line['src']];
}
// We do not have any ACLs for this entry, so continue.
$acls = $this->ui->get_permissions($dn,"users/viewFonEntries","");
if(!preg_match("/r/",$acls)){
continue;
}
// Check attribute permissions
foreach($line as $attr => $value){
if($attr == "duration") continue;
$acl = $this->ui->get_permissions($dn,"users/viewFonEntries",$attr);
if(!preg_match("/r/",$acl)){
$line[$attr] = $no_acl;
}
}
// Check date permissions
if($this->ui->get_permissions($dn,"users/viewFonEntries","calldate")){
$hour= substr($line["calldate"], 11, 2);
$minute=substr($line["calldate"], 14, 2);
$format= _("Y-M-D");
$date= preg_replace("/Y/", substr($line["calldate"], 0, 4), $format);
$date= preg_replace("/M/", substr($line["calldate"], 5, 2), $date);
$date= preg_replace("/D/", substr($line["calldate"], 8, 2), $date);
$date_str = $date." ".$hour.":".$minute;
}else{
$date_str = $no_acl;
}
$append_str = "