Changeset 1011

Show
Ignore:
Timestamp:
09/14/08 19:02:48 (4 months ago)
Author:
areski
Message:

optimization for CDRs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/agent/Public/call-comp.php

    r1005 r1011  
    1515 
    1616 
    17 if (!isset ($current_page) || ($current_page == "")) 
    18                $current_page=0;  
    19        
     17if (!isset ($current_page) || ($current_page == "")) { 
     18        $current_page=0;  
     19
    2020 
    2121// this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking) 
     
    2929// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE 
    3030$FG_TABLE_HEAD_COLOR = "#D1D9E7"; 
    31  
    32  
    3331$FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge) 
    3432$FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose) 
    35  
    36  
    37  
    38  
    3933// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE 
    4034$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#FFFFFF"; 
     
    4236 
    4337 
    44  
    45 //$link = DbConnect(); 
    4638$DBHandle  = DbConnect(); 
    47  
    48 // The variable Var_col would define the col that we want show in your table 
    49 // First Name of the column in the html page, second name of the field 
    5039$FG_TABLE_COL = array(); 
    51  
    52  
    5340 
    5441/******* 
     
    5744 
    5845$FG_TABLE_COL[]=array (gettext("Calldate"), "starttime", "15%", "center", "SORT", "19", "", "", "", "", "", "display_dateformat"); 
    59 //$FG_TABLE_COL[]=array ("Callend", "stoptime", "15%", "center", "SORT", "19"); 
    60  
    61  
    62 //$FG_TABLE_COL[]=array ("Source", "source", "20%", "center", "SORT", "30"); 
    63  
    6446$FG_TABLE_COL[]=array (gettext("CalledNumber"), "calledstation", "15%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix"); 
    65 $FG_TABLE_COL[]=array (gettext("Destination"), "destination", "15%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix"); 
    66 //$FG_TABLE_COL[]=array ("Country",  "calledcountry", "10%", "center", "SORT", "30", "lie", "country", "countryname", "countrycode='%id'", "%1"); 
    67 //$FG_TABLE_COL[]=array ("Site", "site_id", "7%", "center", "sort", "15", "lie", "site", "name", "id='%id'", "%1"); 
    68  
     47$FG_TABLE_COL[]=array (gettext("Destination"), "id_cc_prefix", "10%", "center", "SORT", "15", "lie", "cc_prefix", "destination", "id='%id'", "%1"); 
    6948$FG_TABLE_COL[]=array (gettext("Duration"), "sessiontime", "7%", "center", "SORT", "30", "", "", "", "", "", "display_minute"); 
    70  
    71 $FG_TABLE_COL[]=array (gettext("CardUsed"), "username", "11%", "center", "SORT", "", "30", "", "", "", "", "linktocustomer"); 
    72 $FG_TABLE_COL[]=array (gettext("terminatecauseid"), "terminatecauseid", "10%", "center", "SORT", "30"); 
     49$FG_TABLE_COL[]=array (gettext("CardUsed"), "card_id", "11%", "center", "SORT", "", "30", "", "", "", "", "linktocustomer"); 
     50$FG_TABLE_COL[]=array (gettext("Terminatecause"), "terminatecauseid", "10%", "center", "SORT", "30"); 
    7351$FG_TABLE_COL[]=array (gettext("IAX/SIP"), "sipiax", "6%", "center", "SORT",  "", "list", $yesno); 
    74 //$FG_TABLE_COL[]=array ("DestID", "destID", "12%", "center", "SORT", "30"); 
    75  
    76 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Con_charg", "connectcharge", "12%", "center", "SORT", "30"); 
    77 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Dis_charg", "disconnectcharge", "12%", "center", "SORT", "30"); 
    78 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Sec/mn", "secpermin", "12%", "center", "SORT", "30"); 
    79  
    80  
    81 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Buycosts", "buycosts", "12%", "center", "SORT", "30"); 
    8252$FG_TABLE_COL[]=array (gettext("InitialRate"), "calledrate", "10%", "center", "SORT", "30", "", "", "", "", "", "display_2dec"); 
    8353$FG_TABLE_COL[]=array (gettext("Cost"), "sessionbill", "10%", "center", "SORT", "30", "", "", "", "", "", "display_2bill"); 
     
    8555 
    8656 
    87 // ??? cardID 
    8857$FG_TABLE_DEFAULT_ORDER = "t1.starttime"; 
    8958$FG_TABLE_DEFAULT_SENS = "DESC"; 
    9059         
    9160// This Variable store the argument for the SQL query 
    92  
    93 $FG_COL_QUERY='t1.starttime, t1.calledstation, t1.destination, t1.sessiontime, t1.username, t1.terminatecauseid, t1.sipiax, t1.calledrate, t1.sessionbill'; 
    94 // t1.stoptime, 
    95  
     61$FG_COL_QUERY='t1.starttime, t1.calledstation, t1.id_cc_prefix, t1.sessiontime, t1.card_id, t1.terminatecauseid, t1.sipiax, t1.calledrate, t1.sessionbill'; 
    9662$FG_COL_QUERY_GRAPH='t1.starttime, t1.sessiontime, t1.sessionbill-t1.buycost as profit, t1.sessionbill, t1.buycost'; 
    97  
    9863 
    9964// The variable LIMITE_DISPLAY define the limit of record to display by page 
     
    11782 
    11883 
    119  
    120  
    12184if ($FG_DEBUG == 3) echo "<br>Table : $FG_TABLE_NAME    -       Col_query : $FG_COL_QUERY"; 
    12285$instance_table = new Table($FG_TABLE_NAME, $FG_COL_QUERY); 
     
    12487 
    12588 
    126 if ( is_null ($order) || is_null($sens) )
     89if ( is_null ($order) || is_null($sens))
    12790        $order = $FG_TABLE_DEFAULT_ORDER; 
    12891        $sens  = $FG_TABLE_DEFAULT_SENS; 
     
    13093 
    13194 
    132 if ($posted==1){ 
    133   $SQLcmd = ''; 
    134   $SQLcmd = do_field($SQLcmd, 'src', 'src'); 
    135   $SQLcmd = do_field($SQLcmd, 'dst', 'calledstation'); 
    136  
    137   if ($_POST['before']) { 
    138     if (strpos($SQLcmd, 'WHERE') > 0) {         $SQLcmd = "$SQLcmd AND "; 
    139     }else{                                                              $SQLcmd = "$SQLcmd WHERE "; } 
    140     $SQLcmd = "$SQLcmd starttime <'".$_POST['before']."'"; 
    141   } 
    142   if ($_POST['after']) {    if (strpos($SQLcmd, 'WHERE') > 0) {      $SQLcmd = "$SQLcmd AND "; 
    143   } else {      $SQLcmd = "$SQLcmd WHERE ";    } 
    144     $SQLcmd = "$SQLcmd starttime >'".$_POST['after']."'"; 
    145   } 
    146    
    147    
    148 
    149  
    150 //echo "SQLcmd:$SQLcmd<br>"; 
     95if ($posted==1) { 
     96        $SQLcmd = ''; 
     97        $SQLcmd = do_field($SQLcmd, 'src', 'src'); 
     98        $SQLcmd = do_field($SQLcmd, 'dst', 'calledstation'); 
     99         
     100        if ($_POST['before']) { 
     101                if (strpos($SQLcmd, 'WHERE') > 0) { 
     102                        $SQLcmd = "$SQLcmd AND "; 
     103                } else {                                                                 
     104                        $SQLcmd = "$SQLcmd WHERE "; 
     105                } 
     106                $SQLcmd = "$SQLcmd starttime <'".$_POST['before']."'"; 
     107        } 
     108        if ($_POST['after']) {     
     109                if (strpos($SQLcmd, 'WHERE') > 0) { 
     110                        $SQLcmd = "$SQLcmd AND "; 
     111                } else {       
     112                        $SQLcmd = "$SQLcmd WHERE "; 
     113                } 
     114                $SQLcmd = "$SQLcmd starttime >'".$_POST['after']."'"; 
     115        } 
     116
    151117 
    152118$date_clause=''; 
    153119// Period (Month-Day) 
    154  
    155  
    156 if (!isset($fromstatsday_sday)){         
     120if (!isset($fromstatsday_sday)) { 
    157121        $fromstatsday_sday = date("d"); 
    158122        $fromstatsmonth_sday = date("Y-m");      
    159123} 
    160124 
    161  
    162 if (!isset($days_compare)){              
    163         $days_compare=2; 
    164 
    165  
    166  
    167  
    168 //if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND calldate <= '$fromstatsmonth_sday-$fromstatsday_sday+23' AND calldate >= SUBDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL $days_compare DAY)"; 
    169  
    170 if (DB_TYPE == "postgres"){      
    171         if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND t1.starttime < date'$fromstatsmonth_sday-$fromstatsday_sday'+ INTERVAL '1 DAY' AND t1.starttime >= date'$fromstatsmonth_sday-$fromstatsday_sday' - INTERVAL '$days_compare DAY'"; 
    172 }else{ 
    173         if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND t1.starttime < ADDDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL 1 DAY) AND t1.starttime >= SUBDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL $days_compare DAY)";   
     125if (!isset($days_compare))      $days_compare=2; 
     126 
     127 
     128 
     129if (DB_TYPE == "postgres") {     
     130        if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday))  
     131                $date_clause.=" AND t1.starttime < date'$fromstatsmonth_sday-$fromstatsday_sday'+ INTERVAL '1 DAY' AND t1.starttime >= date'$fromstatsmonth_sday-$fromstatsday_sday' - INTERVAL '$days_compare DAY'"; 
     132} else { 
     133        if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) 
     134                $date_clause.=" AND t1.starttime < ADDDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL 1 DAY) AND t1.starttime >= SUBDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL $days_compare DAY)";   
    174135} 
    175136 
     
    177138 
    178139 
    179 if (isset($customer)  &&  ($customer>0))
     140if (isset($customer)  &&  ($customer>0))
    180141        if (strlen($SQLcmd)>0) $SQLcmd.=" AND "; 
    181142        else $SQLcmd.=" WHERE "; 
    182         $SQLcmd.=" username='$customer' "; 
    183 }else
     143        $SQLcmd.=" card_id='$customer' "; 
     144} else
    184145        if (isset($entercustomer)  &&  ($entercustomer>0)){ 
    185146                if (strlen($SQLcmd)>0) $SQLcmd.=" AND "; 
    186147                else $SQLcmd.=" WHERE "; 
    187                 $SQLcmd.=" username='$entercustomer' "; 
     148                $SQLcmd.=" card_id='$entercustomer' "; 
    188149        } 
    189150} 
    190 if ($_SESSION["is_admin"] == 1) 
    191 
     151 
     152if ($_SESSION["is_admin"] == 1)
    192153        if (isset($enterprovider) && $enterprovider > 0) { 
    193154                        if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
     
    208169} 
    209170 
    210 //print $SQLcmd;   
     171 
    211172if (strpos($SQLcmd, 'WHERE') > 0) {  
    212173        $FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause;  
    213 }elseif (strpos($date_clause, 'AND') > 0)
     174} elseif (strpos($date_clause, 'AND') > 0)
    214175        $FG_TABLE_CLAUSE = substr($date_clause,5);  
    215176} 
     
    223184 
    224185if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE"; 
    225 //$nb_record = $instance_table -> Table_count ($FG_TABLE_CLAUSE); 
    226186$nb_record = count($list_total); 
    227187if ($FG_DEBUG >= 1) var_dump ($list); 
     
    229189 
    230190 
    231 if ($nb_record<=$FG_LIMITE_DISPLAY){  
     191if ($nb_record<=$FG_LIMITE_DISPLAY) {  
    232192        $nb_record_max=1; 
    233 }else{  
     193} else {  
    234194        $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1); 
    235195} 
     
    239199 
    240200 
    241 /*************************************************************/ 
    242  
    243  
    244 $instance_table_customer = new Table("cc_card", "id,  username, lastname"); 
    245  
    246 $FG_TABLE_CLAUSE = ""; 
    247 /*if ($_SESSION["is_admin"]==0){         
    248         $FG_TABLE_CLAUSE =" IDmanager='".$_SESSION["pr_reseller_ID"]."'";        
    249 }*/ 
    250  
    251 $list_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null); 
    252  
    253 $nb_customer = count($list_customer); 
    254  
    255 ?> 
    256  
    257 <?php 
    258201$smarty->display('main.tpl'); 
     202 
    259203?> 
    260204 
     
    284228                                <tr> 
    285229                                <td class="fontstyle_searchoptions" width="50%" valign="top"> 
    286                                         <?php echo gettext("Enter the cardnumber");?>: <INPUT TYPE="text" NAME="entercustomer" value="<?php echo $entercustomer?>" class="form_input_text"> 
    287                                         <a href="#" onclick="window.open('A2B_entity_card.php?popup_select=2&popup_formname=myForm&popup_fieldname=entercustomer' , 'CardNumberSelection','scrollbars=1,width=550,height=330,top=20,left=100,scrollbars=1');"><img src="<?php echo Images_Path;?>/icon_arrow_orange.gif"></a> 
     230                                        <?php echo gettext("Enter the card ID");?>: <INPUT TYPE="text" NAME="entercustomer" value="<?php echo $entercustomer?>" class="form_input_text"> 
     231                                        <a href="#" onclick="window.open('A2B_entity_card.php?popup_select=1&popup_formname=myForm&popup_fieldname=entercustomer' , 'CardNumberSelection','scrollbars=1,width=550,height=330,top=20,left=100,scrollbars=1');"><img src="<?php echo Images_Path;?>/icon_arrow_orange.gif"></a> 
    288232                                </td> 
    289233                                <td width="50%"> 
     
    580524        <IMG SRC="graph_stat.php?min_call=<?php echo $min_call?>&fromstatsday_sday=<?php echo $fromstatsday_sday?>&days_compare=<?php echo $days_compare?>&fromstatsmonth_sday=<?php echo $fromstatsmonth_sday?>&dsttype=<?php echo $dsttype?>&srctype=<?php echo $srctype?>&clidtype=<?php echo $clidtype?>&channel=<?php echo $channel?>&resulttype=<?php echo $resulttype?>&dst=<?php echo $dst?>&src=<?php echo $src?>&clid=<?php echo $clid?>&userfieldtype=<?php echo $userfieldtype?>&userfield=<?php echo $userfield?>&accountcodetype=<?php echo $accountcodetype?>&accountcode=<?php echo $accountcode?>&customer=<?php echo $customer?>&entercustomer=<?php echo $entercustomer?>&entertariffgroup=<?php echo $entertariffgroup?>&enterprovider=<?php echo $enterprovider?>&entertrunk=<?php echo $entertrunk?>&enterratecard=<?php echo $enterratecard?>" ALT="Stat Graph"> 
    581525 
    582 <?php  }else{ ?> 
     526<?php  } else { ?> 
    583527        <center><h3><?php echo gettext("No calls in your selection");?>.</h3></center> 
    584528<?php  } ?> 
     
    587531 
    588532<br><br> 
     533 
    589534<?php 
    590        $smarty->display('footer.tpl'); 
    591 ?> 
     535 
     536$smarty->display('footer.tpl'); 
  • trunk/agent/Public/call-count-reporting.php

    r1005 r1011  
    1212getpost_ifset(array('inputtopvar','topsearch', 'posted', 'Period', 'frommonth', 'fromstatsmonth', 'tomonth', 'tostatsmonth', 'fromday', 'fromstatsday_sday', 'fromstatsmonth_sday', 'today', 'tostatsday_sday', 'tostatsmonth_sday', 'resulttype', 'stitle', 'atmenu', 'current_page', 'order', 'sens', 'choose_currency', 'terminatecauseid', 'nodisplay','grouped')); 
    1313 
    14 //var $field=array(); 
    15  
    16 switch ($topsearch){ 
    17         case "topuser": 
    18                 $field=array('CARD ID','username'); 
    19         break; 
    20         case "topdestination": 
    21                 $field=array('DESTINATION','destination'); 
    22         break;   
    23         default: 
    24                 $field=array('CARD ID','username'); 
    25 } 
    26  
    2714 
    2815if (!isset ($current_page) || ($current_page == "")){    
     
    3017} 
    3118 
    32 if (!isset ($FG_TABLE_CLAUSE) || strlen($FG_TABLE_CLAUSE)==0){ 
    33                  
    34                 $cc_yearmonth = sprintf("%04d-%02d-%02d",date("Y"),date("n"),date("d"));         
    35                 $FG_TABLE_CLAUSE=" $UNIX_TIMESTAMP(starttime) <= $UNIX_TIMESTAMP('$cc_yearmonth')"; 
     19if (!isset ($FG_TABLE_CLAUSE) || strlen($FG_TABLE_CLAUSE)==0) {  
     20        $cc_yearmonth = sprintf("%04d-%02d-%02d",date("Y"),date("n"),date("d"));         
     21        $FG_TABLE_CLAUSE=" $UNIX_TIMESTAMP(starttime) <= $UNIX_TIMESTAMP('$cc_yearmonth')"; 
    3622} 
    3723 
    3824// this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking) 
    3925$FG_DEBUG = 0; 
    40  
    41 // The variable FG_TABLE_NAME define the table name to use 
    4226$FG_TABLE_NAME="cc_call"; 
    43  
    44 // THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE 
    4527$FG_TABLE_HEAD_COLOR = "#D1D9E7"; 
    46  
    47  
    4828$FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge) 
    4929$FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose) 
     
    5434$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#F2F8FF"; 
    5535 
    56 //$link = DbConnect(); 
    5736$DBHandle  = DbConnect(); 
    5837 
    59 // The variable Var_col would define the col that we want show in your table 
    60 // First Name of the column in the html page, second name of the field 
    6138$FG_TABLE_COL = array(); 
    6239 
    6340 
    64 if ((!isset($field)) && (count($field)<=1)){ 
    65         $field[0]="CARD ID"; 
    66         $field[1]="username";   } 
    67  
    68 $FG_TABLE_COL[]=array (gettext($field[0]), $field[1], "20%", "center","SORT", "", "30", "", "", "", "", "linktocustomer"); 
     41switch ($topsearch) { 
     42         
     43        case "topdestination": 
     44                $FG_TABLE_COL[]=array (gettext("Destination"), "id_cc_prefix", "10%", "center", "SORT", "15", "lie", "cc_prefix", "destination", "id='%id'", "%1"); 
     45                $on_field = "id_cc_prefix"; 
     46                break; 
     47                 
     48        case "topuser": 
     49        default: 
     50                $FG_TABLE_COL[]=array (gettext("CardUsed"), 'card_id', "20%", "center","SORT", "", "30", "", "", "", "", "linktocustomer"); 
     51                $on_field = "card_id"; 
     52         
     53
     54 
    6955$FG_TABLE_COL[]=array (gettext("Duration"), "calltime", "20%", "center", "SORT", "30", "", "", "", "", "", "display_minute"); 
    7056$FG_TABLE_COL[]=array (gettext("Buy"), "buy", "25%", "center","sort","","","","","","","display_2bill"); 
     
    7864 
    7965if ($grouped){ 
    80         $FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecauseid, count(*) as nbcall'; 
    81         $SQL_GROUP="GROUP BY ".$field[1].",day,terminatecauseid "; 
     66        $FG_COL_QUERY=$on_field.', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecauseid, count(*) as nbcall'; 
     67        $SQL_GROUP="GROUP BY ".$on_field.",day,terminatecauseid "; 
    8268}else{ 
    83         $FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecauseid, count(*) as nbcall'; 
    84         $SQL_GROUP="GROUP BY ".$field[1].",terminatecauseid "; 
     69        $FG_COL_QUERY=$on_field.', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecauseid, count(*) as nbcall'; 
     70        $SQL_GROUP="GROUP BY ".$on_field.",terminatecauseid "; 
    8571} 
    8672 
     
    161147if ((isset($inputtopvar)) && ($inputtopvar!="") && (isset($topsearch)) && ($topsearch!="")){ 
    162148        if ($grouped){ 
    163                 $FG_COL_QUERY1=$field[1].', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,substring(starttime,1,10) AS starttime,terminatecauseid, count(*) as nbcall'; 
    164                 $SQL_GROUP1=" GROUP BY $field[1],starttime,terminatecauseid"; 
     149                $FG_COL_QUERY1=$on_field.', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,substring(starttime,1,10) AS starttime,terminatecauseid, count(*) as nbcall'; 
     150                $SQL_GROUP1=" GROUP BY $on_field,starttime,terminatecauseid"; 
    165151        }else{ 
    166                 $FG_COL_QUERY1=$field[1].', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,terminatecauseid, count(*) as nbcall,starttime'; 
    167                 $SQL_GROUP1=" GROUP BY $field[1],terminatecauseid,starttime"; 
     152                $FG_COL_QUERY1=$on_field.', sum(sessiontime) AS sessiontime, sum(sessionbill) as sessionbill, sum(buycost) as buycost,terminatecauseid, count(*) as nbcall,starttime'; 
     153                $SQL_GROUP1=" GROUP BY $on_field,terminatecauseid,starttime"; 
    168154        } 
    169155        $QUERY = "CREATE TEMPORARY TABLE temp_result AS (SELECT $FG_COL_QUERY1 FROM $FG_TABLE_NAME WHERE $FG_TABLE_CLAUSE  $SQL_GROUP1 ORDER BY nbcall DESC LIMIT $inputtopvar)"; 
     
    172158                $FG_TABLE_NAME="temp_result"; 
    173159                if ($grouped){ 
    174                         $FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecauseid, nbcall'; 
    175                         $SQL_GROUP=" GROUP BY ".$field[1].",day,terminatecauseid,nbcall "; 
     160                        $FG_COL_QUERY=$on_field.', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,substring(starttime,1,10) AS day,terminatecauseid, nbcall'; 
     161                        $SQL_GROUP=" GROUP BY ".$on_field.",day,terminatecauseid,nbcall "; 
    176162                        $QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, sum(nbcall) as nbcall,substring(starttime,1,10) AS day FROM $FG_TABLE_NAME GROUP BY day"; 
    177163                }else{ 
    178                         $FG_COL_QUERY=$field[1].', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecauseid, nbcall'; 
    179                         $SQL_GROUP=" GROUP BY ".$field[1].",terminatecauseid,nbcall "; 
     164                        $FG_COL_QUERY=$on_field.', sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy,terminatecauseid, nbcall'; 
     165                        $SQL_GROUP=" GROUP BY ".$on_field.",terminatecauseid,nbcall "; 
    180166                        $QUERY_TOTAL = "SELECT sum(sessiontime) AS calltime, sum(sessionbill) as cost, sum(buycost) as buy, sum(nbcall) as nbcall FROM $FG_TABLE_NAME"; 
    181167                } 
  • trunk/agent/Public/call-daily-load.php

    r1005 r1011  
    44include ("../lib/agent.smarty.php"); 
    55 
    6 if (! has_rights (ACX_CALL_REPORT)){  
     6if (! has_rights (ACX_CALL_REPORT)) {  
    77        Header ("HTTP/1.0 401 Unauthorized"); 
    88        Header ("Location: PP_error.php?c=accessdenied");           
     
    1111 
    1212 
    13  
    1413getpost_ifset(array('current_page', 'fromstatsday_sday', 'fromstatsmonth_sday', 'days_compare', 'min_call', 'posted',  'dsttype', 'srctype', 'clidtype', 'channel', 'resulttype', 'stitle', 'atmenu', 'current_page', 'order', 'sens', 'dst', 'src', 'clid', 'userfieldtype', 'userfield', 'accountcodetype', 'accountcode', 'customer', 'entercustomer','entertariffgroup' ,'enterprovider', 'entertrunk', 'enterratecard')); 
    1514 
    1615 
    17 if (!isset ($current_page) || ($current_page == "")){  
    18                $current_page=0;  
    19        
    20  
    21 // this variable specifie the debug type (0 => nothing, 1 => sql result, 2 => boucle checking, 3 other value checking) 
     16if (!isset ($current_page) || ($current_page == "")) {         
     17        $current_page=0;  
     18
     19 
     20 
    2221$FG_DEBUG = 0; 
    2322 
    24 // The variable FG_TABLE_NAME define the table name to use 
     23 
    2524$FG_TABLE_NAME="cc_call t1 LEFT OUTER JOIN cc_trunk t3 ON t1.id_trunk = t3.id_trunk"; 
    26  
    27 if ($_SESSION["is_admin"]==0){ 
    28         //$FG_TABLE_NAME.=", cc_card t2"; 
    29 } 
    3025 
    3126// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE 
    3227$FG_TABLE_HEAD_COLOR = "#D1D9E7"; 
    33  
    34  
    3528$FG_TABLE_EXTERN_COLOR = "#7F99CC"; //#CC0033 (Rouge) 
    3629$FG_TABLE_INTERN_COLOR = "#EDF3FF"; //#FFEAFF (Rose) 
    37  
    38  
    39  
    40  
    4130// THIS VARIABLE DEFINE THE COLOR OF THE HEAD TABLE 
    4231$FG_TABLE_ALTERNATE_ROW_COLOR[] = "#FFFFFF"; 
     
    4433 
    4534 
    46  
    47 //$link = DbConnect(); 
    4835$DBHandle  = DbConnect(); 
    49  
    50 // The variable Var_col would define the col that we want show in your table 
    51 // First Name of the column in the html page, second name of the field 
    5236$FG_TABLE_COL = array(); 
    5337 
    5438 
    5539 
    56 /******* 
    57 Calldate Clid Src Dst Dcontext Channel Dstchannel Lastapp Lastdata Duration Billsec Disposition Amaflags Accountcode Uniqueid Serverid 
    58 *******/ 
    5940 
    6041$FG_TABLE_COL[]=array (gettext("Calldate"), "starttime", "15%", "center", "SORT", "19", "", "", "", "", "", "display_dateformat"); 
    61 //$FG_TABLE_COL[]=array ("Callend", "stoptime", "15%", "center", "SORT", "19"); 
    62  
    63  
    64 //$FG_TABLE_COL[]=array ("Source", "source", "20%", "center", "SORT", "30"); 
    65  
    6642$FG_TABLE_COL[]=array (gettext("CalledNumber"), "calledstation", "15%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix"); 
    67 $FG_TABLE_COL[]=array (gettext("Destination"), "destination", "15%", "center", "SORT", "30", "", "", "", "", "", "remove_prefix"); 
    68 //$FG_TABLE_COL[]=array ("Country",  "calledcountry", "10%", "center", "SORT", "30", "lie", "country", "countryname", "countrycode='%id'", "%1"); 
    69 //$FG_TABLE_COL[]=array ("Site", "site_id", "7%", "center", "sort", "15", "lie", "site", "name", "id='%id'", "%1"); 
    70  
     43$FG_TABLE_COL[]=array (gettext("Destination"), "id_cc_prefix", "10%", "center", "SORT", "15", "lie", "cc_prefix", "destination", "id='%id'", "%1"); 
    7144$FG_TABLE_COL[]=array (gettext("Duration"), "sessiontime", "7%", "center", "SORT", "30", "", "", "", "", "", "display_minute"); 
    72  
    73 $FG_TABLE_COL[]=array (gettext("CardUsed"), "username", "11%", "center", "SORT", "", "30", "", "", "", "", "linktocustomer"); 
     45$FG_TABLE_COL[]=array (gettext("CardUsed"), "card_id", "11%", "center", "SORT", "", "30", "", "", "", "", "linktocustomer"); 
    7446$FG_TABLE_COL[]=array (gettext("terminatecauseid"), "terminatecauseid", "10%", "center", "SORT", "30"); 
    7547$FG_TABLE_COL[]=array (gettext("IAX/SIP"), "sipiax", "6%", "center", "SORT",  "", "list", $yesno); 
    76 //$FG_TABLE_COL[]=array ("DestID", "destID", "12%", "center", "SORT", "30"); 
    77  
    78 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Con_charg", "connectcharge", "12%", "center", "SORT", "30"); 
    79 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Dis_charg", "disconnectcharge", "12%", "center", "SORT", "30"); 
    80 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Sec/mn", "secpermin", "12%", "center", "SORT", "30"); 
    81  
    82  
    83 //if ($_SESSION["is_admin"]==1) $FG_TABLE_COL[]=array ("Buycosts", "buycosts", "12%", "center", "SORT", "30"); 
    8448$FG_TABLE_COL[]=array (gettext("InitialRate"), "calledrate", "10%", "center", "SORT", "30", "", "", "", "", "", "display_2dec"); 
    8549$FG_TABLE_COL[]=array (gettext("Cost"), "sessionbill", "10%", "center", "SORT", "30", "", "", "", "", "", "display_2bill"); 
    8650 
    8751 
    88  
    89 // ??? cardID 
    9052$FG_TABLE_DEFAULT_ORDER = "t1.starttime"; 
    9153$FG_TABLE_DEFAULT_SENS = "DESC"; 
    92          
    93 // This Variable store the argument for the SQL query 
    94  
    95 $FG_COL_QUERY='t1.starttime, t1.calledstation, t1.destination, t1.sessiontime, t1.username, t1.terminatecauseid, t1.sipiax, t1.calledrate, t1.sessionbill'; 
    96 // t1.stoptime, 
    97  
     54 
     55$FG_COL_QUERY='t1.starttime, t1.calledstation, t1.id_cc_prefix, t1.sessiontime, t1.card_id, t1.terminatecauseid, t1.sipiax, t1.calledrate, t1.sessionbill'; 
    9856$FG_COL_QUERY_GRAPH='t1.starttime, t1.sessiontime'; 
    9957 
    100 // The variable LIMITE_DISPLAY define the limit of record to display by page 
    10158$FG_LIMITE_DISPLAY=25; 
    102  
    103 // Number of column in the html table 
    10459$FG_NB_TABLE_COL=count($FG_TABLE_COL); 
    105  
    106 // The variable $FG_EDITION define if you want process to the edition of the database record 
    10760$FG_EDITION=true; 
    108  
    109 //This variable will store the total number of column 
    11061$FG_TOTAL_TABLE_COL = $FG_NB_TABLE_COL; 
    11162if ($FG_DELETION || $FG_EDITION) $FG_TOTAL_TABLE_COL++; 
    112  
    113 //This variable define the Title of the HTML table 
    11463$FG_HTML_TABLE_TITLE= gettext(" - Call Logs - "); 
    115  
    116 //This variable define the width of the HTML table 
    11764$FG_HTML_TABLE_WIDTH="90%"; 
    11865 
     
    12572 
    12673 
    127 if ( is_null ($order) || is_null($sens) )
     74if (is_null ($order) || is_null($sens))
    12875        $order = $FG_TABLE_DEFAULT_ORDER; 
    12976        $sens  = $FG_TABLE_DEFAULT_SENS; 
     
    13178 
    13279 
    133 if ($posted==1){ 
    134   $SQLcmd = ''; 
    135    
    136   //$SQLcmd = do_field($SQLcmd, 'src', 'source'); 
    137   $SQLcmd = do_field($SQLcmd, 'dst', 'calledstation'); 
    138   if ($_POST['before']) { 
    139     if (strpos($SQLcmd, 'WHERE') > 0) {         $SQLcmd = "$SQLcmd AND "; 
    140     }else{                                                              $SQLcmd = "$SQLcmd WHERE "; } 
    141     $SQLcmd = "$SQLcmd t1.starttime <'".$_POST['before']."'"; 
    142   } 
    143   if ($_POST['after']) {    if (strpos($SQLcmd, 'WHERE') > 0) {      $SQLcmd = "$SQLcmd AND "; 
    144   } else {      $SQLcmd = "$SQLcmd WHERE ";    } 
    145     $SQLcmd = "$SQLcmd t1.starttime >'".$_POST['after']."'"; 
    146   } 
    147    
    148 
    149  
    150  
    151 if (isset($customer)  &&  ($customer>0)){ 
     80if ($posted==1) { 
     81        $SQLcmd = ''; 
     82          
     83        //$SQLcmd = do_field($SQLcmd, 'src', 'source'); 
     84        $SQLcmd = do_field($SQLcmd, 'dst', 'calledstation'); 
     85        if ($_POST['before']) { 
     86                if (strpos($SQLcmd, 'WHERE') > 0) { 
     87                        $SQLcmd = "$SQLcmd AND "; 
     88                }else{ 
     89                        $SQLcmd = "$SQLcmd WHERE "; 
     90                } 
     91                $SQLcmd = "$SQLcmd t1.starttime <'".$_POST['before']."'"; 
     92        } 
     93        if ($_POST['after']) { 
     94                if (strpos($SQLcmd, 'WHERE') > 0) { 
     95                        $SQLcmd = "$SQLcmd AND "; 
     96                } else { 
     97                        $SQLcmd = "$SQLcmd WHERE "; 
     98                } 
     99                $SQLcmd = "$SQLcmd t1.starttime >'".$_POST['after']."'"; 
     100        } 
     101
     102 
     103 
     104if (isset($customer)  &&  ($customer>0)) { 
    152105        if (strlen($SQLcmd)>0) $SQLcmd.=" AND "; 
    153106        else $SQLcmd.=" WHERE "; 
    154         $SQLcmd.=" username='$customer' "; 
    155 }else
    156         if (isset($entercustomer)  &&  ($entercustomer>0))
     107        $SQLcmd.=" card_id='$customer' "; 
     108} else
     109        if (isset($entercustomer)  &&  ($entercustomer>0))
    157110                if (strlen($SQLcmd)>0) $SQLcmd.=" AND "; 
    158111                else $SQLcmd.=" WHERE "; 
    159                 $SQLcmd.=" username='$entercustomer' "; 
     112                $SQLcmd.=" card_id='$entercustomer' "; 
    160113        } 
    161114} 
    162 if ($_SESSION["is_admin"] == 1) 
    163 
    164         if (isset($enterprovider) && $enterprovider > 0) { 
    165                 if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
    166                 $SQLcmd .= " t3.id_provider = '$enterprovider' "; 
    167         } 
    168         if (isset($entertrunk) && $entertrunk > 0) { 
    169                 if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
    170                 $SQLcmd .= " t3.id_trunk = '$entertrunk' "; 
    171         } 
    172                 if (isset($entertariffgroup) && $entertariffgroup > 0) { 
    173                         if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
    174                         $SQLcmd .= "t1.id_tariffgroup = '$entertariffgroup'"; 
    175                 } 
    176                 if (isset($enterratecard) && $enterratecard > 0) { 
    177                         if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
    178                         $SQLcmd .= "t1.id_ratecard = '$enterratecard'"; 
    179                 } 
    180          
     115if ($_SESSION["is_admin"] == 1) { 
     116    if (isset($enterprovider) && $enterprovider > 0) { 
     117        if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
     118        $SQLcmd .= " t3.id_provider = '$enterprovider' "; 
     119    } 
     120    if (isset($entertrunk) && $entertrunk > 0) { 
     121        if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
     122        $SQLcmd .= " t3.id_trunk = '$entertrunk' "; 
     123    } 
     124        if (isset($entertariffgroup) && $entertariffgroup > 0) { 
     125                if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
     126                $SQLcmd .= "t1.id_tariffgroup = '$entertariffgroup'"; 
     127        } 
     128        if (isset($enterratecard) && $enterratecard > 0) { 
     129                if (strlen($SQLcmd) > 0) $SQLcmd .= " AND "; else $SQLcmd .= " WHERE "; 
     130                $SQLcmd .= "t1.id_ratecard = '$enterratecard'"; 
     131        } 
    181132} 
    182133 
    183134 
    184135$date_clause=''; 
    185 // Period (Month-Day) 
    186  
    187  
    188136if (!isset($fromstatsday_sday)){         
    189         $fromstatsday_sday = date("d"); 
    190         $fromstatsmonth_sday = date("Y-m");      
    191 
    192  
    193  
    194  
    195 //if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND calldate <= '$fromstatsmonth_sday-$fromstatsday_sday+23' AND calldate >= SUBDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL $days_compare DAY)"; 
    196  
    197 if (DB_TYPE == "postgres"){      
    198         if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND t1.starttime < date'$fromstatsmonth_sday-$fromstatsday_sday'+ INTERVAL '1 DAY' AND t1.starttime >= date'$fromstatsmonth_sday-$fromstatsday_sday'"; 
    199 }else{ 
    200         if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday)) $date_clause.=" AND t1.starttime < ADDDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL 1 DAY) AND t1.starttime >= '$fromstatsmonth_sday-$fromstatsday_sday'";   
     137        $fromstatsday_sday              = date("d"); 
     138        $fromstatsmonth_sday    = date("Y-m");   
     139
     140 
     141if (DB_TYPE == "postgres") {     
     142        if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday))  
     143                $date_clause.=" AND t1.starttime < date'$fromstatsmonth_sday-$fromstatsday_sday'+ INTERVAL '1 DAY' AND t1.starttime >= date'$fromstatsmonth_sday-$fromstatsday_sday'"; 
     144} else { 
     145        if (isset($fromstatsday_sday) && isset($fromstatsmonth_sday))  
     146                $date_clause.=" AND t1.starttime < ADDDATE('$fromstatsmonth_sday-$fromstatsday_sday',INTERVAL 1 DAY) AND t1.starttime >= '$fromstatsmonth_sday-$fromstatsday_sday'";   
    201147} 
    202148 
    203149if ($FG_DEBUG == 3) echo "<br>$date_clause<br>"; 
    204  
    205150 
    206151   
    207152if (strpos($SQLcmd, 'WHERE') > 0) {  
    208153        $FG_TABLE_CLAUSE = substr($SQLcmd,6).$date_clause;  
    209 }elseif (strpos($date_clause, 'AND') > 0)
     154} elseif (strpos($date_clause, 'AND') > 0)
    210155        $FG_TABLE_CLAUSE = substr($date_clause,5);  
    211156} 
    212157 
    213 if ($_POST['posted']==1)
     158if ($_POST['posted']==1)
    214159        $list = $instance_table -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, $order, $sens, null, null, $FG_LIMITE_DISPLAY, $current_page*$FG_LIMITE_DISPLAY); 
    215          
    216160        $list_total = $instance_table_graph -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, null, null, null, null, null, null); 
    217161} 
     
    219163 
    220164if ($FG_DEBUG == 3) echo "<br>Clause : $FG_TABLE_CLAUSE"; 
    221 //$nb_record = $instance_table -> Table_count ($FG_TABLE_CLAUSE); 
    222165$nb_record = count($list_total); 
    223166if ($FG_DEBUG >= 1) var_dump ($list); 
     
    225168 
    226169 
    227 if ($nb_record<=$FG_LIMITE_DISPLAY){  
     170if ($nb_record<=$FG_LIMITE_DISPLAY) { 
    228171        $nb_record_max=1; 
    229 }else{  
     172} else {  
    230173        $nb_record_max=(intval($nb_record/$FG_LIMITE_DISPLAY)+1); 
    231174} 
     
    237180/*************************************************************/ 
    238181 
    239  
    240 $instance_table_customer = new Table("cc_card", "id,  username, lastname"); 
    241  
    242 $FG_TABLE_CLAUSE = ""; 
    243 /*if ($_SESSION["is_admin"]==0){         
    244         $FG_TABLE_CLAUSE =" IDmanager='".$_SESSION["pr_reseller_ID"]."'";        
    245 }*/ 
    246  
    247 $list_customer = $instance_table_customer -> Get_list ($DBHandle, $FG_TABLE_CLAUSE, "id", "ASC", null, null, null, null); 
    248  
    249 $nb_customer = count($list_customer); 
    250  
    251 ?> 
    252  
    253 <?php 
    254         $smarty->display('main.tpl'); 
     182$smarty->display('main.tpl'); 
     183 
    255184?> 
    256185 
     
    267196 
    268197<!-- ** ** ** ** ** Part for the research ** ** ** ** ** --> 
    269        <center> 
     198<center> 
    270199        <FORM METHOD=POST name="myForm" ACTION="<?php echo $PHP_SELF?>?s=<?php echo $s?>&t=<?php echo $t?>&order=<?php echo $order?>&sens=<?php echo $sens?>&current_page=<?php echo $current_page?>"> 
    271200        <INPUT TYPE="hidden" NAME="posted" value=1> 
     
    280209                                <tr> 
    281210                                <td class="fontstyle_searchoptions" width="50%" valign="top"> 
    282                                         <?php echo gettext("Enter the cardnumber");?>: <INPUT TYPE="text" NAME="entercustomer" value="<?php echo $entercustomer?>" class="form_input_text"> 
    283                                         <a href="#" onclick="window.open('A2B_entity_card.php?popup_select=2&popup_formname=myForm&popup_fieldname=entercustomer' , 'CardNumberSelection','scrollbars=1,width=550,height=330,top=20,left=100,scrollbars=1');"><img src="<?php echo Images_Path;?>/icon_arrow_orange.gif"></a> 
     211                                        <?php echo gettext("Enter the card ID");?>: <INPUT TYPE="text" NAME="entercustomer" value="<?php echo $entercustomer?>" class="form_input_text"> 
     212                                        <a href="#" onclick="window.open('A2B_entity_card.php?popup_select=1&popup_formname=myForm&popup_fieldname=entercustomer' , 'CardNumberSelection','scrollbars=1,width=550,height=330,top=20,left=100,scrollbars=1');"><img src="<?php echo Images_Path;?>/icon_arrow_orange.gif"></a> 
    284213                                </td> 
    285214                                <td width="50%"> 
     
    424353 </td></tr></tbody></table> 
    425354                   
    426 <!-- FIN TITLE GLOBAL MINUTES //--> 
     355<!-- END TITLE GLOBAL MINUTES //--> 
    427356                                 
    428357<table border="0" cellspacing="0" cellpadding="0" width="80%"> 
     
    467396         ?>                      
    468397        </tr> 
    469         <!-- FIN DETAIL -->            
     398        <!-- END DETAIL -->            
    470399         
    471         <!-- FIN BOUCLE --> 
     400        <!-- END LOOP --> 
    472401 
    473402        <!-- TOTAL --> 
     
    478407                <td align="center" nowrap="nowrap"><font class="fontstyle_003"><?php echo $total_tmc_60?