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($db0);
  38. else {
  39.     $news getNewsList($db$category);
  40. }
  41.  
  42. $tpl =new HTML_Template_IT('./');
  43. $tpl->loadTemplatefile('admin.tpl'truetrue);
  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 = '$category'
  70.         AND
  71.             news_id<>0";
  72.  
  73.     $news $db->getAssoc($query);
  74.  
  75.     if (DB::isError($news)) {
  76.         die($news->getMessage(' ' $news->getUserinfo());
  77.     else {
  78.         $tpl =new HTML_Template_IT('./');
  79.  
  80.         $tpl->loadTemplatefile('news_list.tpl'truetrue);
  81.  
  82.         $tpl->setVariable('CATEGORY'ucfirst($category));
  83.  
  84.         foreach ($news as $id => $name{
  85.             foreach ($name as $cell{
  86.                 // Assign data to the inner block
  87.                 $tpl->setCurrentBlock('cell');
  88.                 $tpl->setVariable("ID",   $id);
  89.                 $tpl->setVariable("DATA"nl2br($cell));
  90.                 $tpl->parseCurrentBlock('cell');
  91.             }
  92.             // Assign data and the inner block to the
  93.             // outer block
  94.             $tpl->setCurrentBlock('row');
  95.             $tpl->parseCurrentBlock('row');
  96.         }
  97.         return $tpl->get();
  98.     }
  99.  
  100. }
  101.  
  102. /**
  103.  * Get a news content.
  104.  *
  105.  * @param  object  &$db     a reference to a db connection object
  106.  * @param  int     $id      news id
  107.  * @param  string  $content the new content
  108.  * @return mixed   content as a string or error
  109.  */
  110. function getNewsContent(&$db$id)
  111. {
  112.     $query = "
  113.         SELECT
  114.             news_id      AS id,
  115.             news_title   AS title,
  116.             DATE_FORMAT(news_date, '%D %b %Y at %H:%I:%S') AS date,
  117.             news_content AS content
  118.         FROM
  119.             news
  120.         WHERE
  121.             news_id = $id";
  122.  
  123.     $news $db->getRow$query );
  124.  
  125.     if  (DB::isError($news)) {
  126.         die($news->getMessage(' ' $news->getUserinfo());
  127.     else {
  128.         $tpl =new HTML_Template_IT('./');
  129.  
  130.         $tpl->loadTemplatefile('news_edit.tpl'truetrue);
  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->quoteSmart($content',
  158.             news_title = ' $db->quoteSmart($title'
  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->quoteSmart($title', ' $db->quoteSmart($content')';
  184.  
  185.     $db->query($query);
  186. }
  187. ?>

Documentation generated on Mon, 11 Mar 2019 13:56:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.