Exemplo n.º 1
0
/**
 * Permet d'afficher la liste des bières
 * @global type $pdo
 * @global type $tpl
 */
function beers_index()
{
    global $pdo, $tpl;
    if (isset($_POST['search'])) {
        header('location: ' . urldup(array('search' => $_POST['search'])));
        quit();
    }
    $where = '';
    if (isset($_GET['search'])) {
        $where = 'WHERE beer_name LIKE ? ';
    }
    $pager = new SimplePager('beers', $where . 'ORDER BY beer_name ASC', 'p', 20);
    if (isset($_GET['search'])) {
        $pager->bindValue(1, "%{$_GET['search']}%");
    }
    $pager->run($tpl);
    display();
}
Exemplo n.º 2
0
/**
 * Permet d'afficher la liste des utilisateurs
 * @global type $pdo
 * @global type $tpl
 */
function user_index()
{
    global $pdo, $tpl;
    if (isset($_POST['search'])) {
        header('location: ' . urldup(array('search' => $_POST['search'])));
        quit();
    }
    $where = '';
    if (isset($_GET['search'])) {
        $where = 'WHERE user_name LIKE ? ' . 'OR user_lastname LIKE ? ' . 'OR user_firstname LIKE ? ' . 'OR user_email LIKE ? ';
    }
    $pager = new SimplePager('users', $where . 'ORDER BY user_name ASC', 'p', 20);
    if (isset($_GET['search'])) {
        $pager->bindValue(1, "%{$_GET['search']}%");
        $pager->bindValue(2, "%{$_GET['search']}%");
        $pager->bindValue(3, "%{$_GET['search']}%");
        $pager->bindValue(4, "%{$_GET['search']}%");
    }
    $pager->run($tpl);
    $tpl->display('user_index.tpl');
    quit();
}
Exemplo n.º 3
0
 /**
  * Applique le pager à un template
  */
 public function run(&$tpl)
 {
     global $pdo;
     $this->sql->execute();
     $this->sqlCount->execute();
     $total = $this->sqlCount->fetch();
     $total = $total[0];
     if ($this->start < 0 || $this->start > $total) {
         throw new Exception('Out of range');
     }
     $hasPrev = $this->start - $this->nbByPage >= 0;
     $hasNext = $this->start + $this->nbByPage < $total;
     $table = array('total' => $total, 'prev' => urldup(array($this->key => $hasPrev ? $this->start - $this->nbByPage : 0)), 'next' => urldup(array($this->key => $hasNext ? $this->start + $this->nbByPage : $this->start)), 'showNext' => $hasNext, 'showPrev' => $hasPrev, 'rows' => array());
     while ($line = $this->sql->fetch()) {
         $table['rows'][] = $line;
     }
     $tpl->assign($this->prepose . 'table', $table);
 }