Ignore:
Timestamp:
Jul 30, 2009, 7:36:50 PM (15 years ago)
Author:
grum
Message:

Update AStat 2.1.0 - new features
See main.inc.php file for details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/AStat/astat_aip.class.inc.php

    r3543 r3706  
    1717include_once('astat_aim.class.inc.php');
    1818include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     19include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
    1920
    2021class AStat_AIP extends AStat_AIM
    21 { 
    22   protected $tabsheet; 
     22{
     23  protected $tabsheet;
    2324  protected $list_periods = array('global', 'all', 'year', 'month', 'day');
    2425  protected $list_sortcat = array('page', 'picture', 'nbpicture');
    2526  protected $list_sortimg = array('picture', 'catname');
    2627  protected $list_sortip = array('page', 'picture', 'ip');
     28  protected $ajax;
    2729
    2830  protected $catfilter;    //filter on categories
     
    5658                          l10n('AStat_tools'),
    5759                          $this->page_link.'&fAStat_tabsheet=tools');
     60
     61    $this->ajax = new Ajax();
    5862  }
    5963
     
    7882  {
    7983    global $template;
     84
     85    $this->return_ajax_content();
    8086
    8187    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/astat_admin.tpl");
     
    102108    elseif($_REQUEST['fAStat_tabsheet']=='stats_by_ip')
    103109    {
     110      if(isset($_REQUEST['fAStat_IP_BL']))
     111      {
     112        $this->add_ip_to_filter($_REQUEST['fAStat_IP_BL']);
     113      }
     114
    104115      $this->display_stats_by_ip(
    105116          $_REQUEST['fAStat_year'],
     
    167178  --------------------------------------------------------------------------- */
    168179
     180  /*
     181    return ajax content
     182  */
     183  protected function return_ajax_content()
     184  {
     185    global $ajax, $template;
     186
     187    if(isset($_REQUEST['ajaxfct']))
     188    {
     189      //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']);
     190      $result="<p class='errors'>An error has occured</p>";
     191      switch($_REQUEST['ajaxfct'])
     192      {
     193        case 'astat_listip':
     194          if(!isset($_REQUEST['ipfilter'])) $_REQUEST['ipfilter']="";
     195          if(!isset($_REQUEST['exclude'])) $_REQUEST['exclude']="";
     196          $result=$this->ajax_listip($_REQUEST['ipfilter'], $_REQUEST['exclude']);
     197          break;
     198      }
     199      //$template->
     200      $this->ajax->return_result($result);
     201    }
     202  }
     203
     204
     205
     206
     207
     208
     209
    169210  private function init_request()
    170211  {
     
    292333
    293334    if($day!="")
    294     { 
     335    {
    295336      $sql_groupdef="HOUR(time) as GId,";
    296337      $sql_select="select HOUR(time) as GId, ";
     
    299340      $sql_order=" order by GId asc";
    300341
    301       for($i=0;$i<24;$i++) 
     342      for($i=0;$i<24;$i++)
    302343      {
    303344        $returned[$i] = array(
     
    313354      }
    314355    }
    315     elseif($month!="") 
    316     { 
     356    elseif($month!="")
     357    {
    317358      $sql_groupdef="DAY(date) as GId,";
    318359      $sql_select="select DAY(date) as GId, ";
     
    323364      $delta = 1;
    324365      $NbDays = strftime('%d', mktime(0,0,0,$month+1,0,$year));
    325       for($i=0;$i<$NbDays;$i++) 
     366      for($i=0;$i<$NbDays;$i++)
    326367      {
    327368        $returned[$i] = array(
     
    337378      }
    338379    }
    339     elseif($year!="") 
    340     { 
     380    elseif($year!="")
     381    {
    341382      $sql_groupdef="MONTH(date) as GId,";
    342383      $sql_select="select MONTH(date) as GId, ";
     
    346387
    347388      $delta = 1;
    348       for($i=0;$i<12;$i++) 
     389      for($i=0;$i<12;$i++)
    349390      {
    350391        $returned[$i] = array(
     
    360401      }
    361402    }
    362     elseif($total!="Y") 
     403    elseif($total!="Y")
    363404    {
    364405      $sql_groupdef="YEAR(date) as GId,";
     
    379420    }
    380421
     422    if($this->my_config['AStat_BlackListedIP']!="")
     423    {
     424      ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND ";
     425      $sql_where .= " NOT ".$this->make_IP_where_clause($this->my_config['AStat_BlackListedIP']);
     426    }
     427
    381428    $sql_max=", (select max(n.MaxPages) as MaxPages, max(n.MaxIP) as MaxIP, max(n.MaxImg) as MaxImg
    382429        from (select ".$sql_groupdef." count(id) as MaxPages, count(distinct IP) as MaxIP, count(image_id) as MaxImg
    383             from ".HISTORY_TABLE.$sql_where.$sql_group.") as n) as n "; 
     430            from ".HISTORY_TABLE.$sql_where.$sql_group.") as n) as n ";
    384431    $sql=$sql_select.$sql.$sql_nfomax.$sql_from.$sql_max.$sql_where.$sql_group.$sql_order;
    385432
     
    394441      { $returned[$row["GId"]-$delta] = $row; }
    395442    }
    396    
     443
    397444    return($returned);
    398445  } //stat by period
     
    423470    $sql_where = "";
    424471    $sql_group=" group by IP_USER ";
    425     $sql_order=" order by ".$sortlist[$sortip]." "; 
     472    $sql_order=" order by ".$sortlist[$sortip]." ";
    426473    $sql_limit=" limit ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage;
    427474
    428475
    429     if($day!="") 
    430     { 
     476    if($day!="")
     477    {
    431478      $sql_where=" where YEAR(date) = $year and MONTH(date) = $month and DAY(date) = $day ";
    432479    }
    433     elseif($month!="") 
    434     { 
     480    elseif($month!="")
     481    {
    435482      $sql_where=" where YEAR(date) = $year and MONTH(date) = $month ";
    436483    }
    437     elseif($year!="") 
    438     { 
     484    elseif($year!="")
     485    {
    439486      $sql_where=" where YEAR(date) = $year ";
    440487    }
     
    451498    }
    452499
     500    if($this->my_config['AStat_BlackListedIP']!="")
     501    {
     502      ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND ";
     503      $sql_where .= " NOT ".$this->make_IP_where_clause($this->my_config['AStat_BlackListedIP']);
     504    }
     505
    453506    $sql_max=", (select max(n.MaxPages) as MaxPages, max(n.MaxImg) as MaxImg
    454         from (select if(".HISTORY_TABLE.".user_id = 2, IP, if(".USERS_TABLE.".username is null, '[".l10n("AStat_deleted_user")."]', ".USERS_TABLE.".username)) as IP_USER, count(".HISTORY_TABLE.".id) as MaxPages, count(image_id) as MaxImg 
    455             from ".HISTORY_TABLE." LEFT JOIN ".USERS_TABLE." ON ".HISTORY_TABLE.".user_id = ".USERS_TABLE.".id ".$sql_where.$sql_group.") as n) as n "; 
     507        from (select if(".HISTORY_TABLE.".user_id = 2, IP, if(".USERS_TABLE.".username is null, '[".l10n("AStat_deleted_user")."]', ".USERS_TABLE.".username)) as IP_USER, count(".HISTORY_TABLE.".id) as MaxPages, count(image_id) as MaxImg
     508            from ".HISTORY_TABLE." LEFT JOIN ".USERS_TABLE." ON ".HISTORY_TABLE.".user_id = ".USERS_TABLE.".id ".$sql_where.$sql_group.") as n) as n ";
    456509    $sql=$sql_select.$sql.$sql_nfomax.$sql_from.$sql_max.$sql_where.$sql_group.$sql_order.$sql_limit;
    457510
     
    475528      $returned[1] = -1;
    476529    }
    477    
     530
    478531    return($returned);
    479532  } //stat by ip
     
    483536      %Pages
    484537      %Images
    485       by : 
     538      by :
    486539        Categories
    487540        Categories/years
     
    505558
    506559    if($show_thumb=='true')
    507     { 
     560    {
    508561      $sql_thumb = ', '.IMAGES_TABLE.'.path as ThumbPath, '.IMAGES_TABLE.'.file as ThumbFile, '.IMAGES_TABLE.'.tn_ext as Extension';
    509562      $sql_fromthumb = "LEFT JOIN ".IMAGES_TABLE." ON ic2.representative_picture_id = ".IMAGES_TABLE.".id  ";
     
    514567      $sql_fromthumb = "";
    515568    }
    516    
     569
    517570    $sql_from = " from (".HISTORY_TABLE." LEFT JOIN ".CATEGORIES_TABLE." ON ".CATEGORIES_TABLE.".id = ".HISTORY_TABLE.".category_id),
    518 (select category_id as catid, count(image_id) as nb_images, representative_picture_id 
     571(select category_id as catid, count(image_id) as nb_images, representative_picture_id
    519572 from ".IMAGE_CATEGORY_TABLE.", ".CATEGORIES_TABLE."
    520573 where ".CATEGORIES_TABLE.".id = ".IMAGE_CATEGORY_TABLE.".category_id group by category_id) as ic2 ";
     
    522575    $sql_group=" group by category_id, section ";
    523576    $sql_group2="";
    524     $sql_order=" order by ".$sortlist[$sortcat]; 
     577    $sql_order=" order by ".$sortlist[$sortcat];
    525578    $sql_limit=" limit ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage;
    526579
    527     if($day!="") 
    528     { 
     580    if($day!="")
     581    {
    529582      $sql_where=" where YEAR(date) = $year and MONTH(date) = $month and DAY(date)= $day ";
    530583    }
    531     elseif($month!="") 
    532     { 
     584    elseif($month!="")
     585    {
    533586      $sql_where=" where YEAR(date) = $year and MONTH(date) = $month ";
    534587    }
    535     elseif($year!="") 
    536     { 
     588    elseif($year!="")
     589    {
    537590      $sql_where=" where YEAR(date) = $year ";
    538591    }
     
    552605    $sql_where .= "  ic2.catid = ".HISTORY_TABLE.".category_id ";
    553606
     607    if($this->my_config['AStat_BlackListedIP']!="")
     608    {
     609      $sql_where .= " AND NOT ".$this->make_IP_where_clause($this->my_config['AStat_BlackListedIP']);
     610    }
    554611
    555612    $sql=$sql_select.$sql.$sql_thumb.$sql_from.$sql_fromthumb.$sql_max.$sql_where.$sql_group.$sql_order.$sql_limit;
     
    574631      $returned[1] = -1;
    575632    }
    576    
     633
    577634    return($returned);
    578635  } // stats per categories
     
    582639      Num of view per image
    583640      %view on period
    584       by : 
     641      by :
    585642        Images
    586643        Images/years
     
    605662        ".IMAGES_TABLE.".path as ThumbPath, ".IMAGES_TABLE.".file as ThumbFile,
    606663        MaxImg2.somme as NbVuesMax, ".IMAGES_TABLE.".tn_ext as Extension ";
    607    
     664
    608665    $sql_from = " from ((".HISTORY_TABLE." LEFT JOIN ".IMAGES_TABLE." ON
    609666  ".IMAGES_TABLE.".id = ".HISTORY_TABLE.".image_id) LEFT JOIN ".CATEGORIES_TABLE."
     
    613670    $sql_where = " where ".HISTORY_TABLE.".image_id is not null ";
    614671    $sql_group=" group by image_id, category_id ";
    615     $sql_order=" order by ".$sortlist[$sortimg]; 
     672    $sql_order=" order by ".$sortlist[$sortimg];
    616673    $sql_limit=" limit ".(($pagenumber-1)* $nbipperpage).", ".$nbipperpage;
    617674
    618     if($day!="") 
    619     { 
     675    if($day!="")
     676    {
    620677      $sql_where.=" and YEAR(date) = $year and MONTH(date) = $month and DAY(date)= $day ";
    621678    }
    622     elseif($month!="") 
    623     { 
     679    elseif($month!="")
     680    {
    624681      $sql_where.=" and YEAR(date) = $year and MONTH(date) = $month ";
    625682    }
    626     elseif($year!="") 
    627     { 
     683    elseif($year!="")
     684    {
    628685      $sql_where.=" and YEAR(date) = $year ";
    629686    }
     
    631688
    632689    if($ip!="")
    633     { 
     690    {
    634691      $sql_where.=" and ( ((IP = '$ip') and ( user_id = 2 ))  or (".USERS_TABLE.".username = '$ip') )";
    635       $sql_from_ip=" LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".id = ".HISTORY_TABLE.".user_id ";   
    636     }
    637    
     692      $sql_from_ip=" LEFT JOIN ".USERS_TABLE." ON ".USERS_TABLE.".id = ".HISTORY_TABLE.".user_id ";
     693    }
     694
    638695    if($this->catfilter!="")
    639696    {
     
    643700    }
    644701
     702    if($this->my_config['AStat_BlackListedIP']!="")
     703    {
     704      ($sql_where=="")?$sql_where=" where ":$sql_where.=" AND ";
     705      $sql_where .= " NOT ".$this->make_IP_where_clause($this->my_config['AStat_BlackListedIP']);
     706    }
     707
     708
    645709    $sql_max=", (select count(image_id) as somme from ".HISTORY_TABLE.$sql_from_ip.$sql_where.") as MaxImg, (select count(image_id) as somme from ".HISTORY_TABLE.$sql_from_ip.$sql_where." and ".HISTORY_TABLE.".image_id is not null group by image_id order by somme desc limit 0,1) as MaxImg2 ";
    646710
     
    666730      $returned[1] = -1;
    667731    }
    668    
     732
    669733    return($returned);
    670734  } //stat by images
     
    719783
    720784    /* period label + navigation links */
    721     if($day!="") 
    722     { 
     785    if($day!="")
     786    {
    723787      $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_hours");
    724788      $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day";
    725789    }
    726     elseif($month!="") 
    727     { 
     790    elseif($month!="")
     791    {
    728792      $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_days");
    729793      $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month);
    730794    }
    731     elseif($year!="") 
    732     { 
     795    elseif($year!="")
     796    {
    733797      $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_months");
    734798      $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year;
    735799    }
    736     elseif($total!="Y") 
    737     { 
     800    elseif($total!="Y")
     801    {
    738802      $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_years");
    739803      $template_datas["L_STAT_TITLE"] = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all");
    740804    }
    741     else 
    742     { 
     805    else
     806    {
    743807      $template_datas["PERIOD_LABEL"] = l10n("AStat_period_label_all");
    744808      $template_datas["L_STAT_TITLE"] = l10n("AStat_period_label_global");
    745     } 
     809    }
    746810    $template_datas["MAX_WIDTH"] = $max_width+10;
    747811    $template_datas["ASTAT_NFO_STAT"] = l10n("AStat_Nfo_Period");
     
    763827      }
    764828      else
    765       { 
    766         $width_pages = 0; 
     829      {
     830        $width_pages = 0;
    767831        $width_img = 0;
    768832        $width_ip = 0;
     
    770834      }
    771835
    772    
     836
    773837      if($day!="")
    774838      { // si jours sélectionné, heures affichées
     
    787851        $value_img=$img_links["day"].$stats[$i]["GId"];
    788852      }
    789       elseif($year!="") 
     853      elseif($year!="")
    790854      { // si année sélectionnée, mois affichés
    791855        $value = l10n("AStat_month_of_year_".$stats[$i]["GId"]);
     
    803867        $value_img=$img_links["year"].$stats[$i]["GId"];
    804868      }
    805       else 
    806       { 
    807         $value=l10n("AStat_period_label_all"); 
     869      else
     870      {
     871        $value=l10n("AStat_period_label_all");
    808872        $link=$this->page_link."&amp;fAStat_defper=N&amp;fAStat_all=N";
    809873        $value_ip=$ip_links["all"];
     
    897961
    898962    /* periode label + navigation links */
    899     if($day!="") 
    900     { 
     963    if($day!="")
     964    {
    901965      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day";
    902966      $page_link=$ip_links["day"];
    903967      $img_link=$img_links["day"];
    904968    }
    905     elseif($month!="") 
    906     { 
     969    elseif($month!="")
     970    {
    907971      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month);
    908972      $page_link=$ip_links["month"];
    909973      $img_link=$img_links["month"];
    910974    }
    911     elseif($year!="") 
    912     { 
     975    elseif($year!="")
     976    {
    913977      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year;
    914978      $page_link=$ip_links["year"];
    915979      $img_link=$img_links["year"];
    916980    }
    917     else 
    918     { 
     981    else
     982    {
    919983      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all");
    920984      $page_link=$ip_links["all"];
    921985      $img_link=$img_links["all"];
    922986    }
    923    
     987
    924988
    925989    if($nbpages>1) { $plural="s"; } else { $plural=""; }
     
    927991    for($i=1;$i<=$nbpages;$i++)
    928992    {
    929       if($i==$pagenumber) 
    930       { $pages_links.=" $i "; } 
     993      if($i==$pagenumber)
     994      { $pages_links.=" $i "; }
    931995      else
    932996      {
     
    934998      }
    935999    }
    936    
     1000
    9371001    $template_datas["L_STAT_TITLE"] = $dir_links;
    9381002    $template_datas["MAX_WIDTH"]=$max_width+10;
     
    9551019    {
    9561020        if($stats[$i]["MaxPages"] > 0)
    957       { 
    958         $width_pages = ceil(($stats[$i]["NbPages"] * $max_width) / $stats[$i]["MaxPages"] ); 
     1021      {
     1022        $width_pages = ceil(($stats[$i]["NbPages"] * $max_width) / $stats[$i]["MaxPages"] );
    9591023        $width_img = ceil(($stats[$i]["NbImg"] * $max_width) / $stats[$i]["MaxPages"] );
    9601024      }
    9611025      else
    962       { 
    963         $width_pages = 0; 
     1026      {
     1027        $width_pages = 0;
    9641028        $width_img = 0;
    9651029      }
     
    9701034        $ip_geolocalisation='<a href="http://www.geoiptool.com/fr/?IP='.$stats[$i]["IP_USER"].'" title="Geo IP localisation" target="_blank">['.l10n('AStat_IP_geolocalisation').'] </a>';
    9711035        $ip_adress='<a href="http://www.ripe.net/whois?form_type=simple&amp;full_query_string=&amp;searchtext='.$stats[$i]["IP_USER"].'+&amp;do_search=Search" title="Ripe Whois" target="_blank">'.$stats[$i]["IP_USER"].'</a>';
    972       }
    973       else
     1036        $ip_blacklist=$page_link."&amp;fAStat_IP_BL=".$stats[$i]["IP_USER"];
     1037
     1038        if($pagenumber>1)
     1039        {
     1040          $ip_blacklist.="&amp;fAStat_page_number=$pagenumber";
     1041        }
     1042
     1043        if($sortip!="page")
     1044        {
     1045          $ip_blacklist.="&amp;fAStat_SortIP=$sortip";
     1046        }
     1047
     1048        $ip_blacklist=$this->format_link("[".l10n('AStat_IP_blacklist')."]", $ip_blacklist);
     1049      }
     1050      else
    9741051      {
    9751052        $ip_geolocalisation='';
    9761053        $ip_adress=$stats[$i]["IP_USER"];
    977       }
     1054        $ip_blacklist='';
     1055      }
     1056
    9781057
    9791058
    9801059      $template_datarows[]=array(
     1060        'ASTAT_IP_BLACKLIST' => $ip_blacklist,
    9811061        'ASTAT_IP_GEOLOCALISATION' => $ip_geolocalisation,
    9821062        'ASTAT_IP_ADRESS' => $ip_adress,
     
    10301110
    10311111    /* make navigation links */
    1032     if($day!="") 
    1033     { 
     1112    if($day!="")
     1113    {
    10341114      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day";
    10351115      $page_link=$cat_links["day"];
    10361116    }
    1037     elseif($month!="") 
    1038     { 
     1117    elseif($month!="")
     1118    {
    10391119      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month);
    10401120      $page_link=$cat_links["month"];
    10411121    }
    1042     elseif($year!="") 
    1043     { 
     1122    elseif($year!="")
     1123    {
    10441124      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year;
    10451125      $page_link=$cat_links["year"];
    10461126    }
    1047     else 
    1048     { 
     1127    else
     1128    {
    10491129      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all");
    10501130      $page_link=$cat_links["all"];
    10511131    }
    1052    
     1132
    10531133
    10541134    if($nbpages>1)
     
    10641144    for($i=1;$i<=$nbpages;$i++)
    10651145    {
    1066       if($i==$pagenumber) 
     1146      if($i==$pagenumber)
    10671147      {
    10681148        $pages_links.=" $i ";
     
    10961176      $width_pages = ceil(($stats[$i]["PctPages"] * $max_width)/100);
    10971177      $width_img = ceil(($stats[$i]["PctImg"] * $max_width)/100 );
    1098      
     1178
    10991179      if($showthumb=='true')
    1100       { 
     1180      {
    11011181        $filethumb=$this->change_file_ext($stats[$i]["ThumbFile"], $stats[$i]["Extension"]);
    11021182        $filethumb=str_replace($stats[$i]["ThumbFile"],"thumbnail/".$conf['prefix_thumbnail'].$filethumb,$stats[$i]["ThumbPath"]); }
     
    11091189      { $category = $this->format_link($stats[$i]["IdCat"], PHPWG_ROOT_PATH."index.php?/category/".$stats[$i]["category_id"]); }
    11101190      else
    1111       { 
     1191      {
    11121192        $category = "<i>".l10n('AStat_section_label').' : ';
    11131193        if(l10n('AStat_section_'.$stats[$i]["IdCat"])!='AStat_section_'.$stats[$i]["IdCat"])
     
    11421222
    11431223  /* ------------------------------------------------------------------------------------------
    1144       display stats for images 
     1224      display stats for images
    11451225      ------------------------------------------------------------------------------------------ */
    11461226  function display_stats_by_image($year, $month, $day, $max_width, $nbipperpage, $pagenumber,$showthumb, $sortimg, $ip, $seetimerequest)
     
    11761256
    11771257    /* navigation links */
    1178     if($day!="") 
    1179     { 
     1258    if($day!="")
     1259    {
    11801260      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".$this->format_link(l10n("AStat_month_of_year_".$month), $a_links["month"])." / ".l10n("AStat_day_of_week_".date("w",mktime(0, 0, 0, $month, $day, $year)))." $day";
    11811261      $page_link=$img_links["day"];
    11821262    }
    1183     elseif($month!="") 
    1184     { 
     1263    elseif($month!="")
     1264    {
    11851265      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$this->format_link($year, $a_links["year"])." / ".l10n("AStat_month_of_year_".$month);
    11861266      $page_link=$img_links["month"];
    11871267    }
    1188     elseif($year!="") 
    1189     { 
     1268    elseif($year!="")
     1269    {
    11901270      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".$this->format_link(l10n("AStat_period_label_all"), $a_links["all"])." / ".$year;
    11911271      $page_link=$img_links["year"];
    11921272    }
    1193     else 
    1194     { 
     1273    else
     1274    {
    11951275      $dir_links = $this->format_link(l10n("AStat_period_label_global"), $a_links["global"])." / ".l10n("AStat_period_label_all");
    11961276      $page_link=$img_links["all"];
     
    12011281      $dir_links.= " [IP : $ip]";
    12021282    }
    1203    
     1283
    12041284
    12051285    if($nbpages>1) { $plural="s"; } else { $plural=""; }
     
    12071287    for($i=1;$i<=$nbpages;$i++)
    12081288    {
    1209       if($i==$pagenumber) 
    1210       { $pages_links.=" $i "; } 
     1289      if($i==$pagenumber)
     1290      { $pages_links.=" $i "; }
    12111291      else
    12121292      {
     
    12361316    for($i=0;$i<count($stats);$i++)
    12371317    {
    1238       $width_pages = ceil(($stats[$i]["NbVues"] * $max_width)/$stats[$i]["NbVuesMax"] ); 
     1318      $width_pages = ceil(($stats[$i]["NbVues"] * $max_width)/$stats[$i]["NbVuesMax"] );
    12391319      $width_img = ceil(($stats[$i]["PctImg"] * $max_width)/100 );
    1240      
     1320
    12411321      if($showthumb=='true')
    12421322      {
    12431323        $filethumb=$this->change_file_ext($stats[$i]["ThumbFile"], $stats[$i]["Extension"]);
    1244         $filethumb=str_replace($stats[$i]["ThumbFile"],"thumbnail/".$conf['prefix_thumbnail'].$filethumb,$stats[$i]["ThumbPath"]); 
     1324        $filethumb=str_replace($stats[$i]["ThumbFile"],"thumbnail/".$conf['prefix_thumbnail'].$filethumb,$stats[$i]["ThumbPath"]);
    12451325      }
    12461326      else
     
    12581338        }
    12591339        else
    1260         { 
     1340        {
    12611341          if($stats[$i]["ThumbFile"]!="")
    12621342          {
     
    12701350      }
    12711351      else
    1272       { 
     1352      {
    12731353        $image_links = "<i>".l10n('AStat_section_label').' : ';
    12741354        if(l10n('AStat_section_'.$stats[$i]["CatName"])!='AStat_section_'.$stats[$i]["CatName"])
     
    12811361        }
    12821362
    1283         $image_links.="</i> / "; 
     1363        $image_links.="</i> / ";
    12841364
    12851365        if($stats[$i]["ImgName"]!="")
     
    12881368        }
    12891369        else
    1290         { 
     1370        {
    12911371          if($stats[$i]["ThumbFile"]!="")
    12921372          {
     
    13201400
    13211401
     1402  private function add_ip_to_filter($ip)
     1403  {
     1404    if(strpos($this->my_config['AStat_BlackListedIP'].",", $ip.",")===false)
     1405    {
     1406      ($this->my_config['AStat_BlackListedIP']!='')?$this->my_config['AStat_BlackListedIP'].=",":"";
     1407      $this->my_config['AStat_BlackListedIP'].=$ip;
     1408      $this->save_config();
     1409    }
     1410  }
     1411
    13221412
    13231413  /*
     
    13301420    $save_status=false;
    13311421
    1332     if(isset($_POST['submit'])) 
     1422    if(isset($_POST['submit']))
    13331423    {
    13341424      if(!is_adviser())
    13351425      {
    1336         reset($this->my_config); 
    1337         while (list($key, $val) = each($this->my_config)) 
     1426        reset($this->my_config);
     1427        while (list($key, $val) = each($this->my_config))
    13381428        {
    13391429          if(isset($_POST['f_'.$key]))
     
    13641454
    13651455    //standards inputs zones
    1366     reset($this->my_config); 
    1367     while (list($key, $val) = each($this->my_config)) 
     1456    reset($this->my_config);
     1457    while (list($key, $val) = each($this->my_config))
    13681458    {
    13691459      $template_datas["f_".$key]=$val;
    13701460    }
     1461
     1462    //
     1463    $template_datas['ajaxurl']=$this->page_link;
    13711464
    13721465    // define selected item for lists zones
     
    13951488    }
    13961489    // default ip order
    1397     reset($this->list_sortip); 
    1398     while (list($key, $val) = each($this->list_sortip)) 
     1490    reset($this->list_sortip);
     1491    while (list($key, $val) = each($this->list_sortip))
    13991492    {
    14001493      $template_list_values['sortip'][]=$val;
     
    14341527
    14351528
    1436   /* 
     1529  /*
    14371530    display tools page
    14381531  */
     
    14481541
    14491542    // >> PURGE HISTORY --------------------------------------------------------
    1450     if(isset($_POST['apply_tool_purge_history'])) 
     1543    if(isset($_POST['apply_tool_purge_history']))
    14511544    {
    14521545      if(!is_adviser())
    14531546      {
    1454         $action_result['action']='AStat_tools_purge_history';     
    1455         $action_result['result']='false';     
     1547        $action_result['action']='AStat_tools_purge_history';
     1548        $action_result['result']='false';
    14561549        $action_result['msg']='AStat_tools_result_ko';
    1457        
     1550
    14581551        $ok_to_purge=true;
    14591552        if($_REQUEST['fAStat_purge_history_type']=='bydate')
     
    14661559
    14671560          $purge_date=mktime(0,0,0,$date[1],$date[0],$date[2]);
    1468           $fdate=date("Y-m-d", mktime(0,0,0,$date[1],$date[0],$date[2]));
     1561          $fparam=date("Y-m-d", mktime(0,0,0,$date[1],$date[0],$date[2]));
    14691562
    14701563          if(date("d/m/Y", $purge_date)!=$_REQUEST['fAStat_purge_history_date'])
    1471           {     
    1472             $action_result['nfo']='AStat_tools_invalid_date';     
     1564          {
     1565            $action_result['nfo']='AStat_tools_invalid_date';
    14731566            $ok_to_purge=false;
    14741567          }
    14751568          elseif(date("Ymd", $purge_date)>=date("Ymd"))
    14761569          {
    1477             $action_result['nfo']='AStat_tools_invalid_date2';     
     1570            $action_result['nfo']='AStat_tools_invalid_date2';
    14781571            $ok_to_purge=false;
    14791572          }
    14801573        }
     1574        elseif($_REQUEST['fAStat_purge_history_type']=='byipid0')
     1575        {
     1576          $fparam=$this->my_config['AStat_BlackListedIP'];
     1577        }
    14811578        else
    14821579        {
    1483           $fdate="";
     1580          $fparam="";
    14841581        }
    14851582
    14861583        if($ok_to_purge)
    14871584        {
    1488           $result=$this->do_purge_history( $fdate, $_REQUEST['fAStat_purge_history_type']);
     1585          $result=$this->do_purge_history( $fparam, $_REQUEST['fAStat_purge_history_type']);
    14891586          if($result)
    14901587          {
     
    15421639      }
    15431640    }
    1544     // 
     1641    //
    15451642    elseif(isset($_POST['apply_tool_deleted_picture']))
    15461643    {
     
    15661663
    15671664    // >> DELETED_CATEGORY -----------------------------------------------------
    1568     elseif(isset($_POST['apply_tool_deleted_category'])) 
     1665    elseif(isset($_POST['apply_tool_deleted_category']))
    15691666    {
    15701667      if(!is_adviser())
     
    15871684    }
    15881685    // << DELETED_CATEGORY -----------------------------------------------------
    1589      
     1686
    15901687    // >> DELETED USER ---------------------------------------------------------
    1591     elseif(isset($_POST['apply_tool_deleted_user'])) 
     1688    elseif(isset($_POST['apply_tool_deleted_user']))
    15921689    {
    15931690      if(!is_adviser())
     
    16151712    $table_exists=$this->verify_AStat_picture_table_status();
    16161713    if($table_exists==true)
    1617     { 
     1714    {
    16181715      $template_datas["ASTAT_DELETED_PICTURE_DO_ACTION"] = "checked";
    16191716      $template_datas["ASTAT_DELETED_PICTURE_PREPARE"] = "disabled";
    16201717    }
    16211718    else
    1622     { 
     1719    {
    16231720      $template_datas["ASTAT_DELETED_PICTURE_PREPARE"]="checked";
    16241721      $template_datas["ASTAT_DELETED_PICTURE_DO_ACTION"]="disabled";
     
    16321729    {
    16331730      $list='';
    1634       for($i=0;$i<count($nfo[2]);$i++) 
    1635       { 
     1731      for($i=0;$i<count($nfo[2]);$i++)
     1732      {
    16361733        if($nfo[2][$i][0]>1) { $s='s'; } else { $s=''; }
    1637         $list.="<li>image_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>"; 
     1734        $list.="<li>image_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>";
    16381735      }
    16391736      $template_datas["ASTAT_DELETED_PICTURE_NFO"] = sprintf(l10n('AStat_tools_deleted_picture_nfo1'), $nfo[0], $nfo[1], $list);
     
    16441741    {
    16451742      $template_datas["ASTAT_DELETED_PICTURE_NFO"] = l10n('AStat_tools_deleted_picture_nfo2');
    1646     } 
     1743    }
    16471744    // << DISPLAY DELETED_PICTURE NFO ------------------------------------------
    16481745
     
    16721769    {
    16731770      $list='';
    1674       for($i=0;$i<count($nfo[2]);$i++) 
    1675       { 
     1771      for($i=0;$i<count($nfo[2]);$i++)
     1772      {
    16761773        if($nfo[2][$i][0]>1) { $s='s'; } else { $s=''; }
    1677         $list.="<li>user_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>"; 
     1774        $list.="<li>user_id #".$nfo[2][$i][1]." : ".$nfo[2][$i][0]." ".l10n("AStat_event$s")."</li>";
    16781775      }
    16791776      $template_datas["ASTAT_DELETED_USER_NFO"] = sprintf(l10n('AStat_tools_deleted_user_nfo1'), $nfo[0], $nfo[1], $list);
     
    16831780    {
    16841781      $template_datas["ASTAT_DELETED_USER_NFO"] = l10n('AStat_tools_deleted_user_nfo2');
    1685     } 
     1782    }
    16861783    // << DISPLAY DELETED USER NFO ---------------------------------------------
    16871784
     
    16921789    {
    16931790      $template_datas["ASTAT_GENERAL_NFO"] = sprintf(l10n('AStat_tools_general_nfo_nfo'),
    1694               $nfo[0], 
     1791              $nfo[0],
    16951792              $this->formatoctet($nfo[3]+$nfo[4], "A", " ", 2, true),
    16961793              $this->formatoctet($nfo[3], "A", " ", 2, true),
    16971794              $this->formatoctet($nfo[4], "A", " ", 2, true),
    1698               date(l10n('AStat_date_time_format'), strtotime($nfo[2])), 
     1795              date(l10n('AStat_date_time_format'), strtotime($nfo[2])),
    16991796              date(l10n('AStat_date_time_format'), strtotime($nfo[1])) );
     1797      $template_datas["ASTAT_MINDATE"]=date("m/d/Y",strtotime($nfo[2]));
    17001798    }
    17011799
    17021800    $nfo=$this->purge_history_count_imageid0();
    17031801    $template_datas["ASTAT_PURGE_HISTORY_IMAGE_NFO"] = sprintf(l10n('AStat_tools_purge_history_imageid0'), $nfo);
    1704     if($nfo==0) 
    1705     { 
     1802    if($nfo==0)
     1803    {
    17061804      $template_datas["ASTAT_PURGE_HISTORY_IMAGE_DISABLED"] = " disabled ";
    17071805    }
    17081806    $nfo=$this->purge_history_count_categoryid0();
    17091807    $template_datas["ASTAT_PURGE_HISTORY_CATEGORY_NFO"] = sprintf(l10n('AStat_tools_purge_history_categoryid0'), $nfo);
    1710     if($nfo==0) 
    1711     { 
     1808    if($nfo==0)
     1809    {
    17121810      $template_datas["ASTAT_PURGE_HISTORY_CATEGORY_DISABLED"] = " disabled ";
     1811    }
     1812    $nfo=$this->purge_history_count_ipid0();
     1813    $template_datas["ASTAT_PURGE_HISTORY_IP_NFO"] = sprintf(l10n('AStat_tools_purge_history_ipid0'), $nfo[1], $nfo[0]);
     1814    if($nfo[0]==0)
     1815    {
     1816      $template_datas["ASTAT_PURGE_HISTORY_IP_DISABLED"] = " disabled ";
    17131817    }
    17141818    // << GENERAL NFO ----------------------------------------------------------
     
    17521856    allow to force HISTORY_TABLE.user_id at  2 (guest) for records with user ident
    17531857    doesn't exist anymore in the USERS_TABLE
    1754    
     1858
    17551859    Two usages :
    1756       - analyse : return infos about records wich need to be updated 
     1860      - analyse : return infos about records wich need to be updated
    17571861          * number of users
    17581862          * number of records in HISTORY_TABLE
     
    17631867  {
    17641868    $returned = array(-1,0,'');
    1765    
     1869
    17661870    if($mode=='analyse')
    17671871    {
     
    17811885          $returned[1]+=$row[0];
    17821886        }
    1783        
     1887
    17841888      }
    17851889    }
     
    17971901
    17981902  /*
    1799     tools : deleted_picture 
     1903    tools : deleted_picture
    18001904    analyse history to find deleted pictures
    18011905    Two functions :
     
    18091913  {
    18101914    $returned = array(-1,0,'');
    1811    
     1915
    18121916    if($mode=='analyse')
    18131917    {
     
    18281932          $returned[1]+=$row[0];
    18291933        }
    1830        
     1934
    18311935      }
    18321936    }
     
    18341938    {
    18351939      $sql="UPDATE ".HISTORY_TABLE."
    1836         SET image_id = 0 
    1837         WHERE ".HISTORY_TABLE.".image_id > 0 
     1940        SET image_id = 0
     1941        WHERE ".HISTORY_TABLE.".image_id > 0
    18381942          AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.")";
    18391943      $result=pwg_query($sql);
     
    18611965  {
    18621966    $returned = array(-1,0,'');
    1863    
     1967
    18641968    if($mode=='analyse')
    18651969    {
     
    18801984          $returned[1]+=$row[0];
    18811985        }
    1882        
     1986
    18831987      }
    18841988    }
     
    18861990    {
    18871991      $sql="UPDATE ".HISTORY_TABLE."
    1888         SET category_id = NULL, section = 'deleted_cat' 
    1889         WHERE ".HISTORY_TABLE.".category_id > 0 
     1992        SET category_id = NULL, section = 'deleted_cat'
     1993        WHERE ".HISTORY_TABLE.".category_id > 0
    18901994          AND ".HISTORY_TABLE.".category_id NOT IN (SELECT id FROM ".CATEGORIES_TABLE.")";
    18911995      $result=pwg_query($sql);
     
    19012005
    19022006  /*
    1903     tools : general_nfo 
     2007    tools : general_nfo
    19042008    return infos about historic
    19052009      0 : nulber of records
     
    19122016  {
    19132017    $returned = array(-1,'','',0,0);
    1914  
     2018
    19152019    $sql="SELECT count(id) AS NbRecord, MAX(concat(date,' ', time)) AS LastDate, MIN(concat(date,' ', time)) AS FirstDate ";
    19162020    $sql.=" FROM ".HISTORY_TABLE;
     
    19192023    {
    19202024      $row = mysql_fetch_array($result);
    1921       if(is_array($row)) 
    1922       { 
    1923         $returned = $row; 
     2025      if(is_array($row))
     2026      {
     2027        $returned = $row;
    19242028        $sql="SHOW TABLE STATUS LIKE '".HISTORY_TABLE."';";
    19252029        $result=pwg_query($sql);
     
    19362040
    19372041  /*
    1938     tools : do_purge_history 
     2042    tools : do_purge_history
    19392043    do a purge of history table :
    19402044    - $purgetype='bydate' : purge all record wich date is less than given date
    19412045    - $purgetype='byimageid0' : with and image_id = 0
    19422046  ------------------------------------------------------------------------------------ */
    1943   private function do_purge_history($date, $purgetype)
     2047  private function do_purge_history($param, $purgetype)
    19442048  {
    19452049    if($purgetype=='bydate')
    19462050    {
    1947       $sql="DELETE FROM ".HISTORY_TABLE." WHERE date < '$date'";
     2051      $sql="DELETE FROM ".HISTORY_TABLE." WHERE date < '$param'";
    19482052    }
    19492053    elseif($purgetype=='byimageid0')
     
    19552059      $sql="DELETE FROM ".HISTORY_TABLE." WHERE category_id is null and section='deleted_cat'";
    19562060    }
    1957     else
    1958     {
     2061    elseif($purgetype=='byipid0')
     2062    {
     2063      $sql="DELETE FROM ".HISTORY_TABLE." WHERE ".$this->make_IP_where_clause($param);
     2064    }
     2065    else
     2066    {
    19592067      return(false);
    19602068    }
     
    19652073      $sql="OPTIMIZE TABLE ".HISTORY_TABLE;
    19662074      $result=pwg_query($sql);
    1967       return($result);   
     2075      return($result);
    19682076    }
    19692077    return(false);
     
    19942102  }
    19952103
    1996 
    1997   /*
    1998     tools : deleted_picture
    1999     > verify_AStat_picture_table_status :
    2000     > prepare_AStat_picture_table :
     2104  private function purge_history_count_ipid0()
     2105  {
     2106    if($this->my_config['AStat_BlackListedIP']!="")
     2107    {
     2108      $list=explode(',', $this->my_config['AStat_BlackListedIP']);
     2109    }
     2110    else
     2111    {
     2112      $list=array();
     2113    }
     2114
     2115    $returned=array(0,count($list));
     2116
     2117    if($this->my_config['AStat_BlackListedIP']!='')
     2118    {
     2119      $sql="SELECT COUNT(id)
     2120            FROM ".HISTORY_TABLE."
     2121            WHERE ".$this->make_IP_where_clause($this->my_config['AStat_BlackListedIP']);
     2122      $result=pwg_query($sql);
     2123      if($result)
     2124      {
     2125        $row=mysql_fetch_array($result);
     2126        $returned[0]=$row[0];
     2127      }
     2128    }
     2129    return($returned);
     2130  }
     2131
     2132
     2133  /*
     2134    tools : deleted_picture
     2135    > verify_AStat_picture_table_status :
     2136    > prepare_AStat_picture_table :
    20012137  */
    20022138  private function verify_AStat_picture_table_status()
     
    20202156    global $prefixeTable;
    20212157
    2022     $sql="CREATE TABLE ".$prefixeTable."AStat_picture (PRIMARY KEY (id), KEY ifile(file)) 
    2023       SELECT id, file 
     2158    $sql="CREATE TABLE ".$prefixeTable."AStat_picture (PRIMARY KEY (id), KEY ifile(file))
     2159      SELECT id, file
    20242160      FROM ".IMAGES_TABLE;
    20252161    $result=pwg_query($sql);
     
    20272163    {
    20282164      return(true);
    2029     } 
     2165    }
    20302166    return(false);
    20312167  }
     
    20352171    global $prefixeTable;
    20362172    $returned=array(false,0,0);
    2037    
     2173
    20382174    if($this->verify_AStat_picture_table_status())
    20392175    {
    20402176      $sql="SELECT count(DISTINCT ".$prefixeTable."AStat_picture.id), count(".HISTORY_TABLE.".id)
    2041         FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture 
    2042         WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id 
     2177        FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture
     2178        WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id
    20432179        AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.")
    20442180        ORDER BY ".$prefixeTable."AStat_picture.id";
     
    20642200
    20652201    $sql="CREATE TABLE ".$prefixeTable."AStat_picture2 (PRIMARY KEY (OldId))
    2066       SELECT AStat_tmp.id as OldId , ".IMAGES_TABLE.".id as NewId, ".IMAGES_TABLE.".storage_category_id as NewCatId 
     2202      SELECT AStat_tmp.id as OldId , ".IMAGES_TABLE.".id as NewId, ".IMAGES_TABLE.".storage_category_id as NewCatId
    20672203      FROM (SELECT DISTINCT ".$prefixeTable."AStat_picture.*
    2068         FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture 
    2069         WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id 
     2204        FROM ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture
     2205        WHERE ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture.id
    20702206        AND ".HISTORY_TABLE.".image_id NOT IN (SELECT id FROM ".IMAGES_TABLE.")
    20712207        ORDER BY ".$prefixeTable."AStat_picture.id
     
    20772213      $sql="UPDATE ".HISTORY_TABLE.", ".$prefixeTable."AStat_picture2, ".IMAGES_TABLE."
    20782214        SET ".HISTORY_TABLE.".image_id = ".$prefixeTable."AStat_picture2.NewId,
    2079             ".HISTORY_TABLE.".category_id = ".$prefixeTable."AStat_picture2.NewCatId 
     2215            ".HISTORY_TABLE.".category_id = ".$prefixeTable."AStat_picture2.NewCatId
    20802216        WHERE ".$prefixeTable."AStat_picture2.OldId = ".HISTORY_TABLE.".image_id";
    20812217      $result=pwg_query($sql);
     
    20882224      $sql="DROP TABLE IF EXISTS ".$prefixeTable."AStat_picture";
    20892225      $result=pwg_query($sql);
    2090     } 
     2226    }
    20912227    return($returned);
    20922228  }
     
    21462282
    21472283
    2148   /* 
     2284  /*
    21492285    this function make SELECT "WHERE" clause for filter list
    21502286
     
    21732309
    21742310
    2175   /* 
     2311  /*
    21762312    format text : <a href="$link">$value</a>
    21772313  */
     
    21872323  {  //basic test, maybe a pcre will be more appropriate...
    21882324    $tmp=explode('.', $ip);
    2189     if(count($tmp)!=4) 
     2325    if(count($tmp)!=4)
    21902326    { return (false); }
    21912327
    2192     for($i=0;$i<4;$i++) 
    2193     { 
    2194       if(!is_numeric($tmp[$i])) { return (false); } 
     2328    for($i=0;$i<4;$i++)
     2329    {
     2330      if(!is_numeric($tmp[$i])) { return (false); }
    21952331    }
    21962332    return (true);
     
    22032339  {  //filename can be <filename.truc.jpeg> for example
    22042340    $tmp = explode('.', $file);
    2205     if(count($tmp)>1) { $tmp[count($tmp)-1] = $newext; } 
    2206     return implode('.', $tmp);     
     2341    if(count($tmp)>1) { $tmp[count($tmp)-1] = $newext; }
     2342    return implode('.', $tmp);
    22072343  }
    22082344
    2209   /* 
     2345  /*
    22102346      format number $octets with unit
    22112347      $format = "A" : auto
     
    22292365    { $format="M"; }
    22302366    else
    2231     { $format="G"; } 
     2367    { $format="G"; }
    22322368    }
    22332369    switch($format)
     
    22442380    case "G":
    22452381      $unite="Go"; $div=1024000000;
    2246       break; 
    2247     }
    2248    
     2382      break;
     2383    }
     2384
    22492385    $retour=number_format($octets/$div, $prec, '.', $thsep);
    22502386    if($unitevis)
     
    22532389  }
    22542390
     2391  private function make_IP_where_clause($list)
     2392  {
     2393    $returned="";
     2394
     2395    $tmp=explode(",", $list);
     2396    foreach($tmp as $key=>$val)
     2397    {
     2398      if($returned!="") { $returned.=" OR "; }
     2399      $returned.=" IP LIKE '".$val."' ";
     2400    }
     2401    if($returned!="")
     2402    {
     2403      $returned ="(".$returned.")";
     2404    }
     2405    return($returned);
     2406  }
     2407
     2408  /* ---------------------------------------------------------------------------
     2409   * AJAX functions
     2410   * ------------------------------------------------------------------------- */
     2411  protected function ajax_listip($filter, $exclude)
     2412  {
     2413    $sql="SELECT IP, COUNT(id) as NbEvents FROM ".HISTORY_TABLE;
     2414
     2415    $where=array();
     2416    if($filter!="")
     2417    {
     2418      $where[]=" IP LIKE '".$filter."' ";
     2419    }
     2420    if($exclude!="")
     2421    {
     2422      $where[]=" NOT ".$this->make_IP_where_clause($exclude);
     2423    }
     2424    if(count($where)>0)
     2425    {
     2426      $sql.=" WHERE ".implode(" AND ", $where);
     2427    }
     2428    $sql.=" GROUP BY IP ORDER BY NbEvents desc, IP asc LIMIT 0,100";
     2429
     2430    $list="<select multiple id='iipsellist'>";
     2431    $result=pwg_query($sql);
     2432    if($result)
     2433    {
     2434      while($row=mysql_fetch_array($result))
     2435      {
     2436        $list.="<option value='".$row['IP']."'>".$row['IP'].str_repeat("&nbsp;", 15-strlen($row['IP']))."&nbsp;&nbsp;&nbsp;&nbsp;(".$row['NbEvents'].")</option>";
     2437      }
     2438    }
     2439    $list.="</select>";
     2440
     2441    return($list);
     2442  }
     2443
     2444
    22552445} // AStat_AI class
    22562446
Note: See TracChangeset for help on using the changeset viewer.