Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.02 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', '0');     # don't show any errors...
  3. error_reporting(E_ALL | E_STRICT);  # ...but do log them
  4.  
  5. session_start();
  6. include('../configs/pdo.inc.php');
  7. include('../libs/Smarty.class.php');
  8. require('../libs/SmartyPaginate.class.php');
  9.  
  10. // create object
  11. $smarty = new Smarty;
  12. try {
  13. // required connect
  14.     SmartyPaginate::connect();
  15. // set items per page
  16.     SmartyPaginate::setLimit(25);
  17.  
  18. // assign your db results to the template
  19.     $smarty->assign('results', get_db_results());
  20. // assign {$paginate} var
  21.     SmartyPaginate::assign($smarty);
  22.  
  23.     function get_db_results() {
  24.         $_query = $oPDO->prepare("SELECT D_content * FROM T_Nieuws LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
  25.  
  26.         $_result = $_query->execute();
  27.  
  28.         while ($_row = $_result->fetchAll(PDO::FETCH_ASSOC)) {
  29.             // collect each record into $_data
  30.             $_data[] = $_row;
  31.         }
  32.  
  33.         // now we get the total number of records from the table
  34.         $_query = $oPDO->prepare("SELECT FOUND_ROWS() as total");
  35.         $_result = $_query->execute();
  36.         $_row = $_result->fetchAll(PDO::FETCH_ASSOC);
  37.  
  38.         SmartyPaginate::setTotal($_row['total']);
  39.  
  40.         return $_data;
  41.     }
  42.  
  43. // Clubs ophalen
  44.     // alleen de zichtbare records uit V_clubs halen
  45.     $query = $oPDO->prepare("SELECT * FROM V_clubs WHERE Zichtbaar = 0 ORDER BY ID");
  46.     $query->execute();
  47.  
  48.     // array anders sorteren om oproepen te vergemakkelijken
  49.     $t = array();
  50.     foreach ($query as $row) {
  51.         $t[$row['ID']] = $row;
  52.     }
  53.     $smarty->assign('clubs', $t);
  54.  
  55.     // Clubteller
  56.     $xclubs = $oPDO->prepare("SELECT ID from V_clubs");
  57.     $xclubs->execute();
  58.     $smarty->assign('xclubs', $xclubs->rowCount());
  59.  
  60.     // clubs verwijderen
  61.     if (isset($_GET['actie'])) {
  62.         if ($_GET['actie'] == 'delete') {
  63.             $verwijderen = $oPDO->prepare("DELETE FROM T_clubs WHERE D_id = :getid");
  64.             $verwijderen->bindValue(':getid', $_GET['clubid']); // door ID
  65.  
  66.             $verwijderen->execute();
  67.  
  68.             // resultaat weergeven
  69.             if ($verwijderen) {
  70.                 $smarty->assign('resultaat', '<p class="success">Club verwijderd!</p>');
  71.             }
  72.         } elseif ($_GET['actie'] == 'accept') { // clubs aanvaarden
  73.             $aanvaarden = $oPDO->prepare("UPDATE T_clubs SET D_zichtbaar = '1' WHERE D_id = :getid");
  74.             $aanvaarden->bindValue(':getid', $_GET['clubid']); // ook door ID
  75.  
  76.             $aanvaarden->execute();
  77.  
  78.             // resultaat weergeven
  79.             if ($aanvaarden) {
  80.                 $smarty->assign('resultaat', '<p class="success">Club toegevoegd!</p>');
  81.             }
  82.         }
  83.     }
  84. } catch (PDOException $e) {
  85.     echo '<pre>';
  86.     echo 'Regelnummer: ' . $e->getLine() . '<br>';
  87.     echo 'Bestand: ' . $e->getFile() . '<br>';
  88.     echo 'Foutmelding: ' . $e->getMessage() . '<br>';
  89.     echo '</pre>';
  90. }
  91. // display it
  92. $smarty->display('extends:a_layout.tpl|a_header.tpl|a_clubs.tpl');
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement