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

Source for file news_new.php

Documentation is available at news_new.php

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

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