/mods/_standard/announcements/add_news.php

https://github.com/cindyli/ATutor · PHP · 102 lines · 69 code · 18 blank · 15 comment · 23 complexity · a99a750353c239072c7525ecf1a7e5a8 MD5 · raw file

  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. // $Id$
  14. define('AT_INCLUDE_PATH', '../../../include/');
  15. require (AT_INCLUDE_PATH.'vitals.inc.php');
  16. require(AT_INCLUDE_PATH.'lib/tinymce.inc.php');
  17. authenticate(AT_PRIV_ANNOUNCEMENTS);
  18. tool_origin($_SERVER['HTTP_REFERER']);
  19. if (isset($_POST['cancel'])) {
  20. $msg->addFeedback('CANCELLED');
  21. $return_url = $_SESSION['tool_origin']['url'];
  22. tool_origin('off');
  23. header('Location: '.$return_url);
  24. exit;
  25. }
  26. if ((!$_POST['setvisual'] && $_POST['settext']) || !$_GET['setvisual']){
  27. $onload = 'document.form.title.focus();';
  28. }
  29. if (isset($_POST['add_news'])&& isset($_POST['submit'])) {
  30. $_POST['formatting'] = intval($_POST['formatting']);
  31. $_POST['title'] = trim($_POST['title']);
  32. $_POST['body_text'] = trim($_POST['body_text']);
  33. $missing_fields = array();
  34. if (!$_POST['body_text']) {
  35. $missing_fields[] = _AT('body');
  36. }
  37. if ($missing_fields) {
  38. $missing_fields = implode(', ', $missing_fields);
  39. $msg->addError(array('EMPTY_FIELDS', $missing_fields));
  40. }
  41. if (!$msg->containsErrors() && (!isset($_POST['setvisual']) || isset($_POST['submit']))) {
  42. $_POST['formatting'] = intval($_POST['formatting']);
  43. $_POST['title'] = $addslashes($_POST['title']);
  44. //The following checks if title length exceed 100, defined by DB structure
  45. $_POST['title'] = validate_length($_POST['title'], 100);
  46. $sql = "INSERT INTO %snews VALUES (NULL, %d, %d, NOW(), %d, '%s', '%s')";
  47. queryDB($sql, array(TABLE_PREFIX, $_SESSION['course_id'], $_SESSION['member_id'], $_POST['formatting'], $_POST['title'], $_POST['body_text']));
  48. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  49. /* update announcement RSS: */
  50. if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml')) {
  51. @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml');
  52. }
  53. if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml')) {
  54. @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml');
  55. }
  56. $return_url = $_SESSION['tool_origin']['url'];
  57. tool_origin('off');
  58. //header('Location: '.AT_BASE_HREF.'mods/_standard/announcements/index.php');
  59. header('Location: '.$return_url );
  60. exit;
  61. }
  62. }
  63. if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
  64. if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
  65. $_POST['formatting'] = 1;
  66. $_REQUEST['settext'] = 0;
  67. $_REQUEST['setvisual'] = 0;
  68. } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
  69. $_POST['formatting'] = 1;
  70. $_POST['settext'] = 0;
  71. $_POST['setvisual'] = 1;
  72. } else { // else if == 0
  73. $_POST['formatting'] = 0;
  74. $_REQUEST['settext'] = 0;
  75. $_REQUEST['setvisual'] = 0;
  76. }
  77. }
  78. require(AT_INCLUDE_PATH.'header.inc.php');
  79. if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
  80. load_editor();
  81. }
  82. $msg->printErrors();
  83. $savant->display('instructor/announcements/add_news.tmpl.php');
  84. require(AT_INCLUDE_PATH.'footer.inc.php'); ?>