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,v 1.10 2004/06/19 18:04:47 arnaud Exp $
  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');
  10.     include_once 'finish.inc.php';
  11.     exit();
  12. }
  13.  
  14. $tpl->loadTemplatefile('news_new.tpl.php');
  15.  
  16. // Read form data.
  17. $news     = isset($_POST['news'])     $_POST['news''';
  18. $valid_to = isset($_POST['valid_to']? (int)$_POST['valid_to''';
  19. $group    = isset($_POST['group_id']? (int)$_POST['group_id''';
  20.  
  21.  
  22. // If $news is not empty, we have something to work.
  23. if (!empty($news)) {
  24.  
  25.     if (!ereg('^[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('permUserId')$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.         $db->query('INSERT INTO
  34.                   news (
  35.                       created_at,
  36.                       valid_to,
  37.                       news,
  38.                       owner_user_id,
  39.                       owner_group_id
  40.                   )
  41.                   VALUES (
  42.                       NOW(),
  43.                       ' $db->quoteSmartdate('Y.m.d H:i:s'time()+60*60*24*7*$valid_to) ) ',
  44.                       ' $db->quoteSmartaddslashes$news ) ).',
  45.                       ' $db->quoteSmart$LU->getProperty('permUserId') ) ',
  46.                       ' $group ')');
  47.  
  48.         $tpl->setVariable('script_msg''<p><b>News has been added.</b></p>');
  49.  
  50.         // null form data.
  51.         $news     '';
  52.         $valid_to '';
  53.         $group    '';
  54.     }
  55. }
  56.  
  57. $tpl->setVariable('form_action''news_new.php');
  58.  
  59. if (!empty($news)) {
  60.     $tpl->setVariable('message'$news);
  61. }
  62.  
  63. if (!empty($valid_to)) {
  64.     $tpl->setVariable('valid'$valid_to);
  65. else {
  66.     $tpl->setVariable('valid''2');
  67. }
  68.  
  69. // If the user is member in more than one group, show them.
  70. if (count($LU->getProperty('groupIds')) > 1{
  71.     $res $db->query('SELECT
  72.                          section_id AS group_id,
  73.                          description AS group_comment
  74.                      FROM
  75.                          liveuser_translations
  76.                      WHERE
  77.                          section_type = 3
  78.                          AND section_id IN (' implode(', '$LU->getProperty('groupIds')) ')
  79.                      ORDER BY
  80.                          group_id');
  81.  
  82.     while ($row $res->fetchRow()) {
  83.         $tpl->setCurrentBlock('choose_group');
  84.         $tpl->setVariable(array('value' => $row['group_id'],
  85.                               'label' => $row['group_comment']));
  86.         if ($group == $row['group_id']{
  87.             $tpl->setVariable('selected''selected');
  88.         }
  89.         $tpl->parseCurrentBlock();
  90.     }
  91.  
  92. else {
  93.     $tpl->setCurrentBlock('set_group');
  94.     $tpl->setVariable('group_id'current($LU->getProperty('groupIds')));
  95.     $tpl->parseCurrentBlock();
  96. }
  97.  
  98. include_once 'finish.inc.php';
  99. ?>

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