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

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