[ Index ]

PHP Cross Reference of Nucleus CMS 3.64

title

Body

[close]

/nucleus3.64/nucleus/libs/ -> ENCAPSULATE.php (source)

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2009 The Nucleus Group
   5   *
   6   * This program is free software; you can redistribute it and/or
   7   * modify it under the terms of the GNU General Public License
   8   * as published by the Free Software Foundation; either version 2
   9   * of the License, or (at your option) any later version.
  10   * (see nucleus/documentation/index.html#license for more info)
  11   */
  12  
  13  /**
  14   * Part of the code for the Nucleus admin area
  15   *
  16   * @license http://nucleuscms.org/license.txt GNU General Public License
  17   * @copyright Copyright (C) 2002-2009 The Nucleus Group
  18   * @version $Id: ENCAPSULATE.php 1388 2009-07-18 06:31:28Z shizuki $
  19   */
  20  
  21  class ENCAPSULATE {
  22      /**
  23        * Uses $call to call a function using parameters $params
  24        * This function should return the amount of entries shown.
  25        * When entries are show, batch operation handlers are shown too.
  26        * When no entries were shown, $errormsg is used to display an error
  27        *
  28        * Passes on the amount of results found (for further encapsulation)
  29        */
  30  	function doEncapsulate($call, $params, $errorMessage = _ENCAPSULATE_ENCAPSULATE_NOENTRY) {
  31          // start output buffering
  32          ob_start();
  33  
  34          $nbOfRows = call_user_func_array($call, $params);
  35  
  36          // get list contents and stop buffering
  37          $list = ob_get_contents();
  38          ob_end_clean();
  39  
  40          if ($nbOfRows > 0) {
  41              $this->showHead();
  42              echo $list;
  43              $this->showFoot();
  44          } else {
  45              echo $errorMessage;
  46          }
  47  
  48          return $nbOfRows;
  49      }
  50  }
  51  
  52  /**
  53    * A class used to encapsulate a list of some sort inside next/prev buttons
  54    */
  55  class NAVLIST extends ENCAPSULATE {
  56  
  57  	function NAVLIST($action, $start, $amount, $minamount, $maxamount, $blogid, $search, $itemid) {
  58          $this->action = $action;
  59          $this->start = $start;
  60          $this->amount = $amount;
  61          $this->minamount = $minamount;
  62          $this->maxamount = $maxamount;
  63          $this->blogid = $blogid;
  64          $this->search = $search;
  65          $this->itemid = $itemid;
  66      }
  67  
  68  	function showBatchList($batchtype, $query, $type, $template, $errorMessage = _LISTS_NOMORE) {
  69          $batch =& new BATCH($batchtype);
  70  
  71          $this->doEncapsulate(
  72                  array(&$batch, 'showlist'),
  73                  array(&$query, $type, $template),
  74                  $errorMessage
  75          );
  76  
  77      }
  78  
  79  
  80  	function showHead() {
  81          $this->showNavigation();
  82      }
  83  	function showFoot() {
  84          $this->showNavigation();
  85      }
  86  
  87      /**
  88        * Displays a next/prev bar for long tables
  89        */
  90  	function showNavigation() {
  91          $action = $this->action;
  92          $start = $this->start;
  93          $amount = $this->amount;
  94          $minamount = $this->minamount;
  95          $maxamount = $this->maxamount;
  96          $blogid = $this->blogid;
  97          $search = htmlspecialchars($this->search);
  98          $itemid = $this->itemid;
  99  
 100          $prev = $start - $amount;
 101          if ($prev < $minamount) $prev=$minamount;
 102  
 103          // maxamount not used yet
 104      //    if ($start + $amount <= $maxamount)
 105              $next = $start + $amount;
 106      //    else
 107      //        $next = $start;
 108  
 109      ?>
 110      <table class="navigation">
 111      <tr><td>
 112          <form method="post" action="index.php"><div>
 113          <input type="submit" value="&lt;&lt; <?php echo  _LISTS_PREV?>" />
 114          <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
 115          <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
 116          <input type="hidden" name="action" value="<?php echo  $action; ?>" />
 117          <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
 118          <input type="hidden" name="search" value="<?php echo  $search; ?>" />
 119          <input type="hidden" name="start" value="<?php echo  $prev; ?>" />
 120          </div></form>
 121      </td><td>
 122          <form method="post" action="index.php"><div>
 123          <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
 124          <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
 125          <input type="hidden" name="action" value="<?php echo  $action; ?>" />
 126          <input name="amount" size="3" value="<?php echo  $amount; ?>" /> <?php echo _LISTS_PERPAGE?>
 127          <input type="hidden" name="start" value="<?php echo  $start; ?>" />
 128          <input type="hidden" name="search" value="<?php echo  $search; ?>" />
 129          <input type="submit" value="&gt; <?php echo _LISTS_CHANGE?>" />
 130          </div></form>
 131      </td><td>
 132          <form method="post" action="index.php"><div>
 133          <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
 134          <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
 135          <input type="hidden" name="action" value="<?php echo  $action; ?>" />
 136          <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
 137          <input type="hidden" name="start" value="0" />
 138          <input type="text" name="search" value="<?php echo  $search; ?>" size="7" />
 139          <input type="submit" value="&gt; <?php echo  _LISTS_SEARCH?>" />
 140          </div></form>
 141      </td><td>
 142          <form method="post" action="index.php"><div>
 143          <input type="submit" value="<?php echo _LISTS_NEXT?> &gt; &gt;" />
 144          <input type="hidden" name="search" value="<?php echo  $search; ?>" />
 145          <input type="hidden" name="blogid" value="<?php echo  $blogid; ?>" />
 146          <input type="hidden" name="itemid" value="<?php echo  $itemid; ?>" />
 147          <input type="hidden" name="action" value="<?php echo  $action; ?>" />
 148          <input type="hidden" name="amount" value="<?php echo  $amount; ?>" />
 149          <input type="hidden" name="start" value="<?php echo  $next; ?>" />
 150          </div></form>
 151      </td></tr>
 152      </table>
 153      <?php    }
 154  
 155  
 156  }
 157  
 158  
 159  /**
 160   * A class used to encapsulate a list of some sort in a batch selection
 161   */
 162  class BATCH extends ENCAPSULATE {
 163  	function BATCH($type) {
 164          $this->type = $type;
 165      }
 166  
 167  	function showHead() {
 168          ?>
 169              <form method="post" action="index.php">
 170          <?php
 171  // TODO: get a list op operations above the list too
 172  // (be careful not to use the same names for the select...)
 173  //        $this->showOperationList();
 174      }
 175  
 176  	function showFoot() {
 177          $this->showOperationList();
 178          ?>
 179              </form>
 180          <?php    }
 181  
 182  	function showOperationList() {
 183          global $manager;
 184          ?>
 185          <div class="batchoperations">
 186              <?php echo _BATCH_WITH_SEL ?>
 187              <select name="batchaction">
 188              <?php                $options = array();
 189                  switch($this->type) {
 190                      case 'item':
 191                          $options = array(
 192                              'delete'    => _BATCH_ITEM_DELETE,
 193                              'move'        => _BATCH_ITEM_MOVE
 194                          );
 195                          break;
 196                      case 'member':
 197                          $options = array(
 198                              'delete'    => _BATCH_MEMBER_DELETE,
 199                              'setadmin'    => _BATCH_MEMBER_SET_ADM,
 200                              'unsetadmin' => _BATCH_MEMBER_UNSET_ADM
 201                          );
 202                          break;
 203                      case 'team':
 204                          $options = array(
 205                              'delete'     => _BATCH_TEAM_DELETE,
 206                              'setadmin'    => _BATCH_TEAM_SET_ADM,
 207                              'unsetadmin' => _BATCH_TEAM_UNSET_ADM,
 208                          );
 209                          break;
 210                      case 'category':
 211                          $options = array(
 212                              'delete'    => _BATCH_CAT_DELETE,
 213                              'move'        => _BATCH_CAT_MOVE,
 214                          );
 215                          break;
 216                      case 'comment':
 217                          $options = array(
 218                              'delete'    => _BATCH_COMMENT_DELETE,
 219                          );
 220                      break;
 221                  }
 222                  foreach ($options as $option => $label) {
 223                      echo '<option value="',$option,'">',$label,'</option>';
 224                  }
 225              ?>
 226              </select>
 227              <input type="hidden" name="action" value="batch<?php echo $this->type?>" />
 228              <?php
 229                  $manager->addTicketHidden();
 230  
 231                  // add hidden fields for 'team' and 'comment' batchlists
 232                  if ($this->type == 'team')
 233                  {
 234                      echo '<input type="hidden" name="blogid" value="',intRequestVar('blogid'),'" />';
 235                  }
 236                  if ($this->type == 'comment')
 237                  {
 238                      echo '<input type="hidden" name="itemid" value="',intRequestVar('itemid'),'" />';
 239                  }
 240  
 241                  echo '<input type="submit" value="',_BATCH_EXEC,'" />';
 242              ?>(
 243               <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(1); "><?php echo _BATCH_SELECTALL?></a> -
 244               <a href="" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return batchSelectAll(0); "><?php echo _BATCH_DESELECTALL?></a>
 245              )
 246          </div>
 247          <?php    }
 248  
 249      // shortcut :)
 250  	function showList($query, $type, $template, $errorMessage = _LISTS_NOMORE) {
 251          return $this->doEncapsulate(    'showlist',
 252                                      array($query, $type, $template),
 253                                      $errorMessage
 254                                  );
 255      }
 256  
 257  }
 258  ?>


Generated: Mon May 2 16:14:08 2011 Cross-referenced by PHPXref 0.7.1