config= $config; $this->ui= $ui; /* Try to get matching search base for user provided by 'dn' */ $tmp= preg_replace ("/^[^,]+,[^,]+,/", "", $ui->dn); $sb= array_search($tmp, $this->config->departments); if ($sb === FALSE){ $sb= "/"; } $this->search_base= $sb; /* Get global filter config */ if (!is_global("fonfilter")){ $ui= get_userinfo(); $base= get_base_from_people($ui->dn); $fonfilter= array("year" => date("Y"), "month" => date("m"), "search_base" => $base, "search_for" => "*"); register_global("fonfilter", $fonfilter); } } function execute() { /* Get template engine */ $smarty= get_smarty(); $fonfilter= get_global("fonfilter"); foreach( array("year", "month", "search_for", "search_base") as $type){ if (isset($_POST[$type])){ $fonfilter[$type]= $_POST[$type]; } $this->$type= $fonfilter[$type]; } register_global("fonfilter", $fonfilter); /* 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; } } /* Search button has been pressed */ if ($this->search_for != ""){ $this->start= 0; if (is_integer (strpos($this->search_for, "*"))){ $s= $this->search_for; } else { $s= "*".$this->search_for."*"; } $ldap= $this->config->get_ldap_link(); $ldap->cd ($this->search_base); /* Perform ldap search for potential users */ $ldap->search ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))". "(objectClass=gofonAccount)". "(|(uid=$s)(l=$s)(homePhone=$s)". "(telephoneNumber=$s)(facsimileTelephoneNumber=$s)(mobile=$s)". "(pager=$s)(cn=$s)(givenName=$s)(sn=$s)(personalTitle=$s)". "(title=$s)))"); $fon_users= array(); while ($attrs= $ldap->fetch()){ $acl= get_permissions ($ldap->getDN(), $this->ui->subtreeACL); $acl= get_module_permission($acl, "fax", $ldap->getDN()); if (chkacl ($acl, "faxReport") == ""){ $fax_users[]= $attrs["uid"][0]; } } /* Prepare SQL query */ $this->userfilter= ""; foreach ($fon_users as $user){ $this->userfilter.= "uid = '$user' OR "; } $this->userfilter= preg_replace("/OR $/", "", $this->userfilter); } /* Perform SQL query */ ##### FIXME ACL, FILTER ###### # if ($this->userfilter){ if ($this->sort_direction == "down"){ $desc= "DESC"; } else { $desc= ""; } $start= date ("YmdHis", mktime(0,0,0,$this->month,1,$this->year)); $end= date ("YmdHis", mktime(23,59,59,$this->month+1,0,$this->year)); $query = "SELECT calldate, channel, src, clid, lastapp, lastdata, dst, ". "disposition, duration FROM cdr ". "WHERE calldate <= $end AND ". "calldate >= $start ORDER BY ".$this->fields[$this->sort]." $desc;"; /* Connecting, selecting database */ if (!isset($this->config->data['SERVERS']['FON'])){ return (""); } $cfg= $this->config->data['SERVERS']['FON']; $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; } if (! @mysql_select_db("asteriskcdrdb")){ print_red(_("Can't select phone database for report generation!")); return; } @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__, $query, "Database query"); $result = @mysql_query($query); if ($result === false){ print_red(_("Query for phone database failed!")); return; } $report_list= array(); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $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); $report_list[]= "