LiveUser
[ class tree: LiveUser ] [ index: LiveUser ] [ all elements ]

Source for file admin.php

Documentation is available at admin.php

  1. <?php
  2. /**
  3.  * Administration page
  4.  */
  5. require_once 'conf.php';
  6. require_once 'liveuser_rights.php';
  7. require_once 'HTML/Template/IT.php';
  8.  
  9. if (!$usr->isLoggedIn(|| !$usr->checkRight(EDITNEWS)) {
  10.     echo 'Sorry but you cannot access this page';
  11.     exit;
  12. }
  13.  
  14. if (array_key_exists('news'$_POST)) {
  15.     if (!$usr->checkRight(MODIFYNEWS)) {
  16.         echo 'You are trying to modify a news but do not have the right to do so !';
  17.         exit;
  18.     }
  19.     if (array_key_exists('id'$_POST)) {
  20.         $id = (int)$_POST['id'];
  21.         $title htmlspecialchars(strip_tags($_POST['title']));
  22.         $newscontent htmlspecialchars(strip_tags($_POST['newscontent']));
  23.         if ($id == 0{
  24.             insertNews($db$title$newscontent$usr->getProperty('perm_user_id'));
  25.         else {
  26.             updateNewsContent($db$id$title$newscontent$usr->getProperty('perm_user_id'));
  27.         }
  28.     }
  29. }
  30.  
  31. $category 'general';
  32.  
  33. if (array_key_exists('mode'$_GET&& $_GET['mode'== 'edit'{
  34.     if (!array_key_exists('id'$_GET&& !is_numeric($_GET['id'])) {
  35.         die('Missing news id');
  36.     }
  37.  
  38.     $id = (int)$_GET['id'];
  39.     $news getNewsContent($db$id);
  40. elseif (array_key_exists('mode'$_GET&& $_GET['mode'== 'insert'{
  41.     $news getNewsContent($db);
  42. else {
  43.     $news getNewsList($db$category);
  44. }
  45.  
  46. $tpl =new HTML_Template_IT('./');
  47. $tpl->loadTemplatefile('admin.tpl');
  48.  
  49. // assign the content to the vars
  50. $tpl->setVariable('USER'$usr->getProperty('handle'));
  51. $tpl->setVariable('NEWS'$news);
  52.  
  53. $tpl->show();
  54.  
  55. /**
  56.  * Returns news list
  57.  * for a given category
  58.  *
  59.  * @param  object  &$db      a reference to a db connection object
  60.  * @param  string  $category news category
  61.  */
  62. function getNewsList(&$db$category)
  63. {
  64.     $query "
  65.         SELECT
  66.             news_id      AS assockey,
  67.             news_id      AS id,
  68.             DATE_FORMAT(news_date, '%D %b %Y at %H:%I:%S') AS date,
  69.             news_title   AS title
  70.         FROM
  71.             news
  72.         WHERE
  73.             news_category = "$db->quote($category'text');
  74.  
  75.     $news $db->queryAll($querynullMDB2_FETCHMODE_ASSOCtrue);
  76.  
  77.     if (PEAR::isError($news)) {
  78.         die($news->getMessage(' ' $news->getUserinfo());
  79.     else {
  80.         $tpl =new HTML_Template_IT('./');
  81.  
  82.         $tpl->loadTemplatefile('news_list.tpl'falsefalse);
  83.  
  84.         $tpl->setVariable('CATEGORY'ucfirst($category));
  85.  
  86.         foreach ($news as $id => $name{
  87.             foreach ($name as $cell{
  88.                 // Assign data to the inner block
  89.                 $tpl->setCurrentBlock('cell');
  90.                 $tpl->setVariable("ID",   $id);
  91.                 $tpl->setVariable("DATA"nl2br($cell));
  92.                 $tpl->parseCurrentBlock('cell');
  93.             }
  94.             // Assign data and the inner block to the
  95.             // outer block
  96.             $tpl->setCurrentBlock('row');
  97.             $tpl->parseCurrentBlock('row');
  98.         }
  99.         return $tpl->get();
  100.     }
  101.  
  102. }
  103.  
  104. /**
  105.  * Get a news content.
  106.  *
  107.  * @param  object  &$db     a reference to a db connection object
  108.  * @param int     $id      news id
  109.  * @param  string  $content the new content
  110.  * @return string content as a string
  111.  */
  112. function getNewsContent(&$db$news = null)
  113. {
  114.     if (!is_null($news)) {
  115.         $query = "
  116.             SELECT
  117.                 news_id      AS id,
  118.                 news_title   AS title,
  119.                 DATE_FORMAT(news_date, '%D %b %Y at %H:%I:%S') AS date,
  120.                 news_content AS content
  121.             FROM
  122.                 news
  123.             WHERE
  124.                 news_id = $news";
  125.  
  126.         $news $db->queryRow$query );
  127.     }
  128.  
  129.     if  (PEAR::isError($news)) {
  130.         die($news->getMessage(' ' $news->getUserinfo());
  131.     else {
  132.         $tpl =new HTML_Template_IT('./');
  133.  
  134.         $tpl->loadTemplatefile('news_edit.tpl'falsefalse);
  135.  
  136.         $tpl->setVariable('ID',      $news['id']);
  137.         $tpl->setVariable('TITLE',   $news['title']);
  138.         $tpl->setVariable('DATE',    $news['date']);
  139.         $tpl->setVariable('CONTENT'$news['content']);
  140.  
  141.         return $tpl->get();
  142.     }
  143.  
  144. }
  145.  
  146. /**
  147.  * Update a news content
  148.  *
  149.  * @param  object  &$db     a reference to a db connection object
  150.  * @param int     $id      news id
  151.  * @param  string  $content the new content
  152.  * @return void 
  153.  */
  154. function updateNewsContent(&$db&$id$title$content$user)
  155. {
  156.     $content strip_tags($content);
  157.     $query '
  158.         UPDATE
  159.             news
  160.         SET
  161.             news_content = ' $db->quote($content'text'',
  162.             news_title = ' $db->quote($title'text''
  163.         WHERE
  164.             news_id = "' $id '"';
  165.  
  166.     $db->query($query);
  167. }
  168.  
  169. /**
  170.  * Insert news in database
  171.  *
  172.  * @param  object  &$db     a reference to a db connection object
  173.  * @param  string  $title   news title
  174.  * @param  string  $content the new content
  175.  * @return void 
  176.  */
  177. function insertNews(&$db$title$content$user)
  178. {
  179.     $content strip_tags($content);
  180.     $query '
  181.         INSERT INTO
  182.             news
  183.         (news_id, news_date,
  184.         news_title, news_content)
  185.         VALUES
  186.         ("' $db->nextId('news''", "' date('Y-m-d H:i:s''",
  187.         ' $db->quote($title'text'', ' $db->quote($content'text'')';
  188.  
  189.     $db->query($query);
  190. }
  191. ?>

Documentation generated on Mon, 11 Mar 2019 14:31:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.