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

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