Code

Fixed some issues
[gosa.git] / plugins / gofon / fonreports / class_fonreport.inc
index 4a08c04cac148f37c0856b7bfa892e699c602c23..5b810f60b6be0d3d04e86f5e74f96cf9d27bfba9 100644 (file)
@@ -56,12 +56,67 @@ class fonreport extends plugin
        /* Call parent execute */
        plugin::execute();
 
+       /* GVet template engine */
+       $smarty= get_smarty();
+
+       foreach($this->fields as $field){
+               if(chkacl($this->acl,$field)==""){
+                       $smarty->assign($field."ACL","");       
+               }else{
+                       $smarty->assign($field."ACL"," disabled ");     
+               }
+       }
+
+       $months= array();
+       $months[1]= _("January"); $months[2]= _("February"); $months[3]= _("March"); $months[4]= _("April");
+       $months[5]= _("May"); $months[6]= _("June"); $months[7]= _("July"); $months[8]= _("August");
+       $months[9]= _("September"); $months[10]= _("October"); $months[11]= _("November"); $months[12]= _("December");
+
+       /* Prepare template */
+       $current= date("Y");
+       $years= array();
+       for ($y= $current - 5; $y<=$current; $y++){
+               $years[]= $y;
+       }
+
+       $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"                 , $this->config->idepartments);
+       $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" , "");
+       
+       /* Connecting, selecting database */
+       if (!isset($this->config->data['SERVERS']['FON'])){
+               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'];
+               $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)));
+               }
+       }
+
+
        if(isset($_POST['EntryPerPage'])){
                $this->range = $_POST['EntryPerPage'];
        }
 
-         /* Get template engine */
-         $smarty= get_smarty();
          $fonfilter= get_global("fonfilter");
          foreach( array("year", "month", "search_for", "search_base") as $type){
                  if (isset($_POST[$type])){
@@ -124,9 +179,17 @@ class fonreport extends plugin
                  $this->userfilter= preg_replace("/OR $/", "", $this->userfilter);
          }
 
-         /* Perform SQL query */
-##### FIXME ACL, FILTER ######
-#        if ($this->userfilter){
+       $fields_str = "calldate, ";
+
+       foreach($this->fields as $field){
+               if($field == "calldate") continue;      
+               if(chkacl($this->acl,$field)==""){
+                       $fields_str .= $field.", ";
+               }
+       }
+
+       $fields_str = preg_replace("/, $/","",$fields_str);
+
        if ($this->sort_direction == "down"){
                $desc= "DESC";
        } else {
@@ -134,31 +197,12 @@ class fonreport extends plugin
        }
        $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 ".
+       $query = "SELECT ".$fields_str." 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 ("");
-       }
-
-       if(!is_callable("mysql_connect")){
-               print_red("There is no mysql extension available.");
-               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("gophone")){
-               print_red(_("Can't select phone database for report generation!"));
-               return;
-       }
 
        @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,
                        $query, "Database query");
@@ -166,29 +210,32 @@ class fonreport extends plugin
        $result = @mysql_query($query);
        if ($result === false){
                print_red(_("Query for phone database failed!"));
-               return;
+               return($smarty->fetch(get_template_path('contents.tpl', TRUE)));
        }
        $report_list= array();
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
+               $append_str = "";
                $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[]= "<td>$date $hour:$minute</td>".
-                       "<td>".$line["src"]."</td>".
-                       "<td>".$line["dst"]."</td>".
-                       "<td>".$line["channel"]."</td>".
-                       "<td>".$line["lastapp"]."</td>".
-                       "<td>".$line["disposition"]."</td>".
-                       "<td>".$this->gen_duration($line["duration"])."</td>";
+               $append_str .=  "<td>$date $hour:$minute</td>";
+               foreach(array("src","dst","channel","lastapp","disposition") as $atr){
+                       if(isset($line[$atr])){
+                               $append_str .=  "<td>".$line[$atr]."</td>";
+                       }
+               }
+               if(isset($line['duration'])){
+                       $append_str .=  "<td>".$this->gen_duration($line["duration"])."</td>";
+               }
+               $report_list[] = $append_str;
        }
 
        $this->report_list= $report_list;
-       mysql_close($link);
-#        }
+       @mysql_close($link);
+#   }
 
        /* Generate output */
        $mod= 0;
@@ -214,23 +261,6 @@ class fonreport extends plugin
                $output.= "<tr style=\"height:22px; $col\">$val</tr>";
        }
 
-       /* Prepare template */
-       $smarty->assign("search_for", $this->search_for);
-       $smarty->assign("bases", $this->config->idepartments);
-       $smarty->assign("base_select", $this->search_base);
-       $months= array();
-       $months[1]= _("January"); $months[2]= _("February"); $months[3]= _("March"); $months[4]= _("April");
-       $months[5]= _("May"); $months[6]= _("June"); $months[7]= _("July"); $months[8]= _("August");
-       $months[9]= _("September"); $months[10]= _("October"); $months[11]= _("November"); $months[12]= _("December");
-       $smarty->assign("months", $months);
-       $smarty->assign("month_select", $this->month);
-       $current= date("Y");
-       $years= array();
-       for ($y= $current - 5; $y<=$current; $y++){
-               $years[]= $y;
-       }
-       $smarty->assign("years", $years);
-       $smarty->assign("year_select", $this->year);
 
        if ($output != ""){
                $smarty->assign("search_result", $output);
@@ -240,9 +270,6 @@ class fonreport extends plugin
        }
 
        /* Show main page */
-       $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'));
         for($i= 0; $i<7; $i++){
                 $smarty->assign("mode$i", "");
         }