[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/extinc/ -> class.lum.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # Version: MPL 1.1/GPL 2.0/LGPL 2.1
   4  #
   5  # The contents of this file are subject to the Mozilla Public License Version
   6  # 1.1 (the "License"); you may not use this file except in compliance with
   7  # the License. You may obtain a copy of the License at
   8  # http://www.mozilla.org/MPL/
   9  #
  10  # Software distributed under the License is distributed on an "AS IS" basis,
  11  # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12  # for the specific language governing rights and limitations under the
  13  # License.
  14  #
  15  # The Original Code is DotClear Weblog.
  16  #
  17  # The Initial Developer of the Original Code is
  18  # Olivier Meunier.
  19  # Portions created by the Initial Developer are Copyright (C) 2003
  20  # the Initial Developer. All Rights Reserved.
  21  #
  22  # Contributor(s):
  23  # Kevyn Lebouille
  24  #
  25  # Alternatively, the contents of this file may be used under the terms of
  26  # either the GNU General Public License Version 2 or later (the "GPL"), or
  27  # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28  # in which case the provisions of the GPL or the LGPL are applicable instead
  29  # of those above. If you wish to allow use of your version of this file only
  30  # under the terms of either the GPL or the LGPL, and not to allow others to
  31  # use your version of this file under the terms of the MPL, indicate your
  32  # decision by deleting the provisions above and replace them with the notice
  33  # and other provisions required by the GPL or the LGPL. If you do not delete
  34  # the provisions above, a recipient may use your version of this file under
  35  # the terms of any one of the MPL, the GPL or the LGPL.
  36  #
  37  # ***** END LICENSE BLOCK *****
  38  
  39  /*
  40  Classe LUM
  41  */
  42  
  43  class lum
  44  {
  45  
  46      //Déclaration des variables
  47      var $env;
  48      var $nb_per_page;
  49      var $nb_pages_per_group;
  50      var $nb_colonnes;
  51      var $arryValues;
  52      var $func_name;
  53      var $varPage;
  54      
  55      //Constructeur
  56  	function lum($env, $func_name, $arryValues, $virtual=0, $nb_per_page='', $nb_pages_per_group='', $nb_colonnes='')
  57      {
  58          $this->init();
  59          
  60          $this->func_name = $func_name;
  61          $this->arryValues = $arryValues;
  62          $this->virtual = $virtual;
  63          
  64          if($nb_per_page != '') {
  65              $this->nb_per_page = $nb_per_page; 
  66          }
  67          
  68          if($nb_pages_per_group != '') {
  69              $this->nb_pages_per_group = $nb_pages_per_group; 
  70          }
  71          
  72          if($nb_colonnes != "") {
  73              $this->nb_colonnes = $nb_colonnes;
  74          }
  75          
  76          //Nombre d'éléments du tableau
  77          if (!$this->virtual)
  78          {
  79              $this->nb_elements = count($arryValues);
  80          }
  81          else
  82          {
  83              $this->nb_elements = $this->virtual;
  84          }
  85          
  86          //Nombre de pages possibles
  87          $this->nb_pages = ceil($this->nb_elements/$this->nb_per_page);
  88          
  89          //On vérifie que env ne sort pas du nombre de pages
  90          if ($env <= $this->nb_pages && $env != "")
  91          {
  92              $this->env = $env;
  93          }
  94          else
  95          {
  96              $this->env = 1;
  97          }
  98          
  99          //Nombre de groupes
 100          $this->nb_groups = ceil($this->nb_pages/$this->nb_pages_per_group);
 101          
 102          //Index de début de page
 103          $this->index_start = ($this->env-1)*$this->nb_per_page;
 104          
 105          //Index de fin de page
 106          $this->index_end = $this->index_start+$this->nb_per_page-1;
 107          if($this->index_end >= $this->nb_elements)
 108          {
 109              $this->index_end = $this->nb_elements-1;
 110          }
 111          
 112          //Index du groupe en cours
 113          $this->env_group = ceil($this->env/$this->nb_pages_per_group);
 114          
 115          //Index de la première page du groupe
 116          $this->index_group_start = ($this->env_group-1)*$this->nb_pages_per_group+1;
 117          
 118          //Index de la dernière page du groupe
 119          $this->index_group_end = $this->index_group_start+$this->nb_pages_per_group-1;
 120          if($this->index_group_end > $this->nb_pages)
 121          {
 122              $this->index_group_end = $this->nb_pages;
 123          }
 124      }
 125      
 126      # Initialisation
 127  	function init()
 128      {
 129          //Déclaration des variables
 130          $this->nb_per_page = 15;
 131          $this->nb_pages_per_group = 10;
 132          $this->nb_colonnes = 1;
 133          $this->arryValues = array();
 134          $this->func_name = NULL;
 135          $this->varPage = 'env';
 136          
 137          //Formatage HTML
 138          $this->htmlLegende = '';
 139          
 140          $this->htmlHeader = '<table cellpadding="0" cellspacing="0" width="100%" border="1">';
 141          $this->htmlLineStart = '<tr>';
 142          $this->htmlColStart = '<td>';
 143          $this->htmlColEnd = '</td>';
 144          $this->htmlLineEnd = '</tr>';
 145          $this->htmlFooter = '</table>';
 146          
 147          $this->htmlLinksStart = '<p>';
 148          $this->htmlLinksEnd = '</p>';
 149          
 150          $this->htmlCurPgStart = '<span class="lumActive"><b>';
 151          $this->htmlCurPgEnd = '</b></span>';
 152          
 153          $this->htmlPrev = '&lt;page préc.';
 154          $this->htmlNext = 'page suiv.&gt;';
 155          $this->htmlPrevGrp = '...';
 156          $this->htmlNextGrp = '...';
 157          
 158          $this->htmlEmpty = '<p><b>Aucun résultat</b></p>';
 159          
 160          $this->htmlLinksLib = 'page(s) : ';
 161      }
 162      
 163      
 164  	function drawPage()
 165      {
 166          $htmlres = NULL;
 167          
 168          if($this->virtual)
 169              $index = 0;
 170          
 171          if(count($this->arryValues))
 172          {
 173              $htmlres .= $this->htmlLegende;
 174              $htmlres .= $this->htmlHeader;
 175              
 176              $line_num = 0;
 177              
 178              for($i=$this->index_start; $i<=$this->index_end; $i++)
 179              {
 180                  $func_name = $this->func_name;
 181                  
 182                  if(!$this->virtual)
 183                      $index = $i;
 184                  
 185                  $base_index = $i-$this->index_start;
 186                  
 187                  //*
 188                  if(($base_index+$this->nb_colonnes)%$this->nb_colonnes == 0)
 189                  {
 190                      $htmlres .= $this->htmlLineStart;
 191                      $line_num++;
 192                  }
 193                  //*/
 194                  
 195                  $htmlres .= $this->htmlColStart;
 196                  $htmlres .= $func_name($this->arryValues[$index],$i);
 197                  $htmlres .= $this->htmlColEnd;
 198                  
 199                  //*
 200                  if($i==$this->index_end)
 201                  {
 202                      $rest_cols = ($line_num*$this->nb_colonnes)-1-$base_index;
 203                      for($j=0;$j<$rest_cols;$j++)
 204                          $htmlres .= $this->htmlColStart.'&nbsp;'.$this->htmlColEnd;
 205                  }
 206                  
 207                  if(($base_index+1)%$this->nb_colonnes == 0 || $i==$this->index_end)
 208                      $htmlres .= $this->htmlLineEnd;
 209                  //*/
 210                  
 211                  $index++;
 212              }
 213              
 214              $htmlres .= $this->htmlFooter;
 215          }
 216          else
 217          {
 218              $htmlres .= $this->htmlEmpty;
 219          }
 220          
 221          return $htmlres;
 222      }
 223      
 224      
 225  	function setURL($pageNum)
 226      {
 227          $strLink = $_SERVER['REQUEST_URI'];
 228          
 229          //Suppression de l'information de session
 230          if(ereg(session_name().'='.session_id().'([&]){1}',$strLink))                
 231                  $strLink = ereg_replace(session_name()."=".session_id().'([&]){1}','',$strLink);                
 232          else                
 233                  $strLink = ereg_replace('([?&]){1}'.session_name().'='.session_id(),'',$strLink);
 234          
 235          
 236          if(ereg('([?&]){1}'.$this->varPage.'=([0-9])+',$strLink))
 237          {
 238              $strLink = ereg_replace('([?&]){1}'.$this->varPage.'=([0-9])+', '\\1'.$this->varPage.'='.$pageNum, $strLink);
 239          }
 240          else
 241          {
 242              if(ereg('\?',$strLink))
 243              {
 244                  $strLink = $strLink.'&'.$this->varPage.'='.$pageNum;
 245              }
 246              else
 247              {    
 248                  $strLink = $strLink.'?'.$this->varPage.'='.$pageNum;
 249              }            
 250          }    
 251          return str_replace('&','&amp;',$strLink);
 252      }
 253      
 254      
 255  	function drawLinks()
 256      {
 257          //Création des liens
 258          $htmlLinks = '';
 259          $htmlPrev = '';
 260          $htmlNext = '';
 261          $htmlPrevGrp = '';
 262          $htmlNextGrp = '';
 263          
 264          for($i=$this->index_group_start; $i<=$this->index_group_end; $i++)
 265          {
 266              if($i == $this->env)
 267              {
 268                  $htmlLinks .= $this->htmlCurPgStart.$i.$this->htmlCurPgEnd;
 269              }
 270              else
 271              {
 272                  $htmlLinks .= '<a href="'.$this->setURL($i).'">'.$i.'</a>';
 273              }
 274              
 275              if($i != $this->index_group_end)
 276              {
 277                  $htmlLinks .= '-';
 278              }
 279          }
 280          
 281          //Page précédente
 282          if($this->env != 1)
 283          {
 284              $htmlPrev = '<a href="'.$this->setURL($this->env-1).'">';
 285              $htmlPrev .= $this->htmlPrev;
 286              $htmlPrev .= '</a>&nbsp;';
 287          }
 288          
 289          //Page suivante
 290          if($this->env != $this->nb_pages)
 291          {
 292              $htmlNext = '&nbsp;<a href="'.$this->setURL($this->env+1).'">';
 293              $htmlNext .= $this->htmlNext;
 294              $htmlNext .= '</a>';
 295          }
 296          
 297          //Groupe précédent
 298          if($this->env_group != 1)
 299          {
 300              $htmlPrevGrp = '&nbsp;<a href="'.$this->setURL($this->index_group_start - $this->nb_pages_per_group).'">';
 301              $htmlPrevGrp .= $this->htmlPrevGrp;
 302              $htmlPrevGrp .= '</a>&nbsp;';
 303          }
 304          
 305          if($this->env_group != $this->nb_groups)
 306          {
 307              $htmlNextGrp = '&nbsp;<a href="'.$this->setURL($this->index_group_end+1).'">';
 308              $htmlNextGrp .= $this->htmlNextGrp;
 309              $htmlNextGrp .= '</a>&nbsp;';
 310          }
 311          
 312          $htmlres =    $this->htmlLinksStart.
 313                      $this->htmlLinksLib.
 314                      $htmlPrev.
 315                      $htmlPrevGrp.
 316                      $htmlLinks.
 317                      $htmlNextGrp.
 318                      $htmlNext.
 319                      $this->htmlLinksEnd;
 320          
 321          if(count($this->arryValues)) {
 322              return $htmlres; }            
 323      }
 324      
 325      //Méthode de débugage
 326  	function debug()
 327      {
 328          return '<pre>'.
 329          'Nombre d\'éléments par page ........ '.$this->nb_per_page."\n".
 330          'Nombre de pages par groupe ......... '.$this->nb_pages_per_group."\n".
 331          'Nombre de colonnes ................. '.$this->nb_colonnes."\n".
 332          'Nombre d\'éléments ................. '.$this->nb_elements."\n".
 333          'Nombre de pages .................... '.$this->nb_pages."\n".
 334          'Nombre de groupes .................. '.$this->nb_groups."\n\n".
 335          'Index de départ .................... '.$this->index_start."\n".
 336          'Index de fin ....................... '.$this->index_end."\n".
 337          'Groupe en cours .................... '.$this->env_group."\n".
 338          'Index de la première page du groupe  '.$this->index_group_start."\n".
 339          'Index de la dernière page du groupe  '.$this->index_group_end."\n".
 340          '</pre>';
 341      }
 342  }//Fin de la classe
 343  
 344  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics