config = $config; $this->ui = $ui; $this->search_base= get_base_from_people($ui->dn); $this->month = date("m"); $this->year = date("Y"); /* Use filter settings if we have already searched */ if (!is_global("fonfilter")){ $fonfilter = array(); foreach($this->attributes_SO as $name){ $fonfilter[$name]=$this->$name; } register_global("fonfilter", $fonfilter); }else{ $fonfilter = get_global("fonfilter"); foreach($this->attributes_SO as $name){ $this->$name = $fonfilter[$name]; } } } /* Save ui interactions and store results in session, to remember settings */ function save_object() { $fonfilter= get_global("fonfilter"); if(isset($_POST['EntryPerPage'])){ $this->range = $_POST['EntryPerPage']; } if (isset($_GET['start'])){ $this->start= (int)$_GET['start']; } foreach( array("year", "month", "search_for", "search_base") as $type){ if (isset($_POST[$type])){ $this->$type= $_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; } register_global("fonfilter", $fonfilter); } /* Search & display results */ function execute() { /* Call parent execute */ plugin::execute(); /* GVet template engine */ $smarty= get_smarty(); /***************** 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 *****************/ $bases = array(); $cat_bases = $this->ui->get_module_departments("gofon"); foreach($this->config->idepartments as $dn => $name){ if(in_array_ics($dn,$cat_bases)){ $bases[$dn] = $name; } } if(!isset($bases[$this->search_base])){ $this->search_base = key($bases); } $smarty->assign("plug", "?plug=".validate($_GET['plug'])); $smarty->assign("launchimage", get_template_path('images/launch.png')); $smarty->assign("search_image", get_template_path('images/search.png')); $smarty->assign("search_for", $this->search_for); $smarty->assign("bases", $bases); $smarty->assign("base_select", $this->search_base); $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 *****************/ /* Connecting, selecting database */ if (!isset($this->config->data['SERVERS']['FON'][0])){ print_red(_("Can't connect to phone database, no reports can be shown!")); return($smarty->fetch(get_template_path('contents.tpl', TRUE))); }elseif(!is_callable("mysql_connect")){ print_red(_("There is no mysql extension available, please check your php setup.")); return($smarty->fetch(get_template_path('contents.tpl', TRUE))); }else{ $cfg= $this->config->data['SERVERS']['FON'][0]; $link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']); if ($link === FALSE){ print_red(_("Can't connect to phone database, no reports can be shown!")); return($smarty->fetch(get_template_path('contents.tpl', TRUE))); } if (! @mysql_select_db("gophone")){ print_red(_("Can't select phone database for report generation!")); return($smarty->fetch(get_template_path('contents.tpl', TRUE))); } } /***************** Get Query String && Search *****************/ $query = $this->CreateQuerySyntax(); $cfg = $this->config->data['SERVERS']['FON'][0]; $link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']); @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); $result = @mysql_query($query); if ($result === false){ print_red(_("Query for phone database failed!")); 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)) { foreach($line as $attr => $value){ if($attr == "duration") continue; $acl = $this->ui->get_permissions($this->search_base,"gofon/fonreport",$attr); if(!preg_match("/r/",$acl)){ $line[$attr] = $no_acl; } } if($this->ui->get_permissions($this->search_base,"gofon/fonreport","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 = ""; $append_str .= "