<?php
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Unbenannt 3
 *
 * @category     Addons
 * @package      Addons_wrapper
 * @subpackage
 * @copyright       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker@org>
 * @author       Manuela v.d.Decken <manuela@isteam.de>
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker@org>
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
 * @version      3.0.1
 * @lastmodified $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 * @since        File available since 2015-12-17
 * @deprecated   This interface is deprecated since 2015-12-17
 * @description  xyz
 * @created      2016-12-3
 */

class Pagination {

    protected $oReg    = null;
    protected $oDb     = null;
    protected $oTrans  = null;
    protected $oApp    = null;

    protected $error   = null;
    protected $Debug   = false;
    protected $aConfig = array();
/*
    protected $oTpl      = null;
    protected $Twig      = null;
    protected $loader    = null;
    protected $aTwigData = array();
*/
    public function __construct($aOptions) { $this->init($aOptions);}

    public function __destruct()
    {
        ini_restore('memory_limit');
    }

    public function __isset($name)
    {
        return isset($this->aConfig[$name]);
    }

     public function __set($name, $value)
     {
//         throw new Exception('Tried to set a readonly or nonexisting property ['.$name.']!!');
         return $this->aConfig[$name] = $value;
     }

    public function __get($name)
    {
        $retval = null;
        if (!$this->__isset($name)) {
            throw new Exception('Tried to get nonexisting property ['.$name.']');
        }
            $retval = $this->aConfig[$name];
        return $retval;
    }

/*********************************************************************************************/

/*********************************************************************************************/

    public function set($name, $value = '')
    {
        $this->aConfig[$name] = $value;
    }

    public function get($name)
    {
        if (!$this->aConfig[$name]){throw new Exception('Tried to get nonexisting property ['.$name.']');;}
        return $this->aConfig[$name];
    }

    public function removeExtension ($sFilename){
        $sRetval = '';
        return preg_replace('#^.*?([^/]*?)\.[^\.]*$#i', '\1', $sFilename);
    }

    public function isError() {
        return sizeof($this->error);
    }

    protected function setError($Message) {
        $this->error[] = $message;
    }

    protected function getError() {
        return $this->error;
    }

    public function convertToArray ($sList)
    {
        $retVal = $sList;
        if (!is_array($sList)){
            $retVal = preg_split('/[\s,=+\;\:\.\|]+/', $sList, -1, PREG_SPLIT_NO_EMPTY);
        }
        return $retVal;
    }

    protected function init($aOptions)
    {
        $this->oReg   = ($GLOBALS['oReg']?:null);
        $this->oDb    = ($GLOBALS['database']?:null);
        $this->oTrans = ($GLOBALS['MESSAGE']?:null);
        foreach ($aOptions AS $name=>$value){
            switch ($name):
                case 'ItemPerPage':
                case 'CurrentPage':
                case 'TotalValues':
                    $this->aConfig[$name] = $value;
                    break;
                case 'Style':
                    $this->aConfig[$name] = $value.'.css';
                    break;
                default:
                    $this->setError('Tried to set a not allowed property ['.$name.']!!');
            endswitch;
        }

        $this->aConfig['bStart'] = TotalValues > $max;
        $this->aConfig['bCrump'] = TotalValues > $max;

    }


} // end of class

/* Old oding


if (isset($_GET['pPage'])) {
    $max = $_GET['pPage'];
} elseif (isset($_POST['pPage'])) {
    $max = $_POST['pPage'];
} else {
    $max = 20;
}


<form action="<?php echo $module_edit_link ?>" method="get" name="filterform" >
    <input type="hidden" name="tool" value="wb_addons" />
    <table class="row_a" style="width: 100%;">
        <thead>

        </thead>
        <tbody>
            <tr style="line-height: 1.5; vertical-align: middle;">
                <td style="width: 15%; white-space: nowrap;">
                    <label>Addons per Page</label>
                </td>
                <td style="width: 20%;">
                    <select class="pPage" name="pPage">
                      <option value="'.$value.'" '.$sSelected.'>'.$name.'</option>

        </tbody>
    </table>
</form>


table of data items if existst




//Pagination
$page = 1;
if (isset($_GET['page'])) $page = $_GET['page'];
$total = get_itemcount($addon_type,-1,0,$filter,$new_upl);
$npage = 0;

$aPerPage = array('10'=>10,'20'=>20,'30'=>30,'50'=>50,'100'=>100,'All Add-ons'=>$total);
//$PagStart = PHP_EOL.''.PHP_EOL;
$sDataPerPage  = "\t\t\t\t".'<tr style="height: 4.225em;">'.PHP_EOL;
$sDataPerPage  = "".'<select class="pPage" name="pPage">'.PHP_EOL;
foreach($aPerPage as $name=>$value){
    $sSelected = (($max==$value)?' selected="selected"':'');
    $sDataPerPage .= "\t\t\t\t\t\t\t\t".'<option value="'.$value.'" '.$sSelected.'>'.$name.'</option>'.PHP_EOL;
}
$sDataPerPage .= "\t\t\t\t\t\t\t".'</select>'.PHP_EOL;
$links = '';
if ($total > $max) {
// start Pagination
    $links  = "\t\t\t\t\t".'<td  colspan="4">'.PHP_EOL;
    $links .= '<div class="w3-center">';
    $links .= '<ul class="w3-pagination pagination">'.PHP_EOL;
    if ($page > 1) {
        $ypage = $page - 1;
        $links .= "\t\t\t\t\t\t"."<li><a class=\"w3-hover-green\" href=\"$module_edit_link$urlfilter&page=$ypage&pPage=$max\">Previous page &laquo; </a></li>";
    } else {
        $links .= "\t\t\t\t\t\t".'<li><a class="w3-disabled">Previous page &laquo; </a></li>';
    }
    for ($x=0;$x < $total; $x=$x+$max) {
        $npage++;
        $sCurrent = ($npage==($page)?'current':'');
        $links .= "\t\t\t\t\t\t"."<li><a class=\"w3-hover-green ".($sCurrent)."\" href=\"$module_edit_link$urlfilter&page=$npage&pPage=$max\">$npage</a></li>";
    }
    if ($page < $npage) {
        $xpage = $page + 1;
        $links .= "\t\t\t\t\t\t"."<li><a class=\"w3-hover-green\" href=\"$module_edit_link$urlfilter&page=$xpage&pPage=$max\"> &raquo; Next Page</a></li>";
    } else {
        $links .= '<li> <a class="w3-disabled ">&raquo; Next Page</a></li>';
    }
    $links .= '</ul>'.PHP_EOL;
    $links .= '</div>';
    $links .= "\t\t\t\t\t".'</td>'.PHP_EOL;
// End Pagination

*/

// end of file
