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

Source for file news_new.php

Documentation is available at news_new.php

  1. <?php
  2.     // CREATING ENVIRONMENT
  3.     require_once 'main.inc.php';
  4.  
  5.     // If the user hasn't the right to write news -> access denied.
  6.     if (!$LU->checkRight(RIGHT_NEWS_NEW)) {
  7.         $tpl->loadTemplatefile('news_notallowed.tpl.php');
  8.         include_once 'finish.inc.php';
  9.         exit();
  10.     }
  11.  
  12.     $tpl->loadTemplatefile('news_new.tpl.php');
  13.  
  14.     // Read form data.
  15.     $news     = isset($_POST['news'])     $_POST['news''';
  16.     $valid_to = isset($_POST['valid_to']? (int)$_POST['valid_to''';
  17.     $group    = isset($_POST['group_id']? (int)$_POST['group_id''';
  18.  
  19.  
  20.     // If $news is not empty, we have something to work.
  21.     if (!empty($news)) {
  22.  
  23.         if (!ereg('^[1-9][0-9]?$'$valid_to)) {
  24.             $tpl->setVariable('script_msg''<p style="color: red;">Only numbers between 1 and 99 are allowed here.</p>');
  25.         elseif (!$LU->checkRightLevel(RIGHT_NEWS_NEW$LU->getProperty('permUserId')$group)) {
  26.             $tpl->setVariable('script_msg''<p style="color: red;">You don\'t have the right to post news for this group.</p>');
  27.         else {
  28.         // Form seems to be correct. Write data into the db.
  29.         $news str_replace("\r\n",'<br />',$news);
  30.  
  31.             $db->query('INSERT INTO
  32.                       news (
  33.                           created_at,
  34.                           valid_to,
  35.                           news,
  36.                           owner_user_id,
  37.                           owner_group_id
  38.                       )
  39.                       VALUES (
  40.                           NOW(),
  41.                           ' $db->quoteSmartdate('Y.m.d H:i:s'time()+60*60*24*7*$valid_to) ) ',
  42.                           ' $db->quoteSmartaddslashes$news ) ).',
  43.                           ' $db->quoteSmart$LU->getProperty('permUserId') ) ',
  44.                           ' $group ')');
  45.  
  46.             $tpl->setVariable('script_msg''<p><b>News has been added.</b></p>');
  47.  
  48.             // null form data.
  49.             $news     '';
  50.             $valid_to '';
  51.             $group    '';
  52.         }
  53.     }
  54.  
  55.     $tpl->setVariable('form_action''news_new.php');
  56.  
  57.     if (!empty($news)) {
  58.         $tpl->setVariable('message'$news);
  59.     }
  60.  
  61.     if (!empty($valid_to)) {
  62.         $tpl->setVariable('valid'$valid_to);
  63.     else {
  64.         $tpl->setVariable('valid''2');
  65.     }
  66.  
  67.     // If the user is member in more than one group, show them.
  68.     if (count($LU->getProperty('groupIds')) > 1{
  69.         $res $db->query('SELECT
  70.                              section_id AS group_id,
  71.                              description AS group_comment
  72.                          FROM
  73.                              liveuser_translations
  74.                          WHERE
  75.                              section_type = 3
  76.                              AND section_id IN (' implode(', '$LU->getProperty('groupIds')) ')
  77.                          ORDER BY
  78.                              group_id');
  79.  
  80.         while ($row $res->fetchRow()) {
  81.             $tpl->setCurrentBlock('choose_group');
  82.             $tpl->setVariable(array('value' => $row['group_id'],
  83.                                   'label' => $row['group_comment']));
  84.             if ($group == $row['group_id']{
  85.                 $tpl->setVariable('selected''selected');
  86.             }
  87.             $tpl->parseCurrentBlock();
  88.         }
  89.  
  90.     else {
  91.         $tpl->setCurrentBlock('set_group');
  92.         $tpl->setVariable('group_id'current($LU->getProperty('groupIds')));
  93.         $tpl->parseCurrentBlock();
  94.     }
  95.  
  96.     include_once 'finish.inc.php';
  97. ?>

Documentation generated on Mon, 11 Mar 2019 10:16:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.