131bd873bfa17971bfaeef4872014d4fa1d949ae
[atutor.git] / docs / mods / _standard / announcements / add_news.php
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
18 authenticate(AT_PRIV_ANNOUNCEMENTS);
19 /*
20 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
21         $content_base_href = 'get.php/';
22 } else {
23         $content_base_href = 'content/' . $_SESSION['course_id'] . '/';
24 } */
25
26 if (isset($_POST['cancel'])) {
27         $msg->addFeedback('CANCELLED');
28         header('Location: '.AT_BASE_HREF.'mods/_standard/announcements/index.php');
29         exit;
30
31
32 if ((!$_POST['setvisual'] && $_POST['settext']) || !$_GET['setvisual']){
33         $onload = 'document.form.title.focus();';
34 }
35
36 if (isset($_POST['add_news'])&& isset($_POST['submit'])) {
37         $_POST['formatting'] = intval($_POST['formatting']);
38         $_POST['title'] = trim($_POST['title']);
39         $_POST['body_text'] = trim($_POST['body_text']);
40         
41         $missing_fields = array();
42
43         if (!$_POST['body_text']) {
44                 $missing_fields[] = _AT('body');
45         }
46
47         if ($missing_fields) {
48                 $missing_fields = implode(', ', $missing_fields);
49                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
50         }
51
52         if (!$msg->containsErrors() && (!isset($_POST['setvisual']) || isset($_POST['submit']))) {
53
54                 $_POST['formatting']  = intval($_POST['formatting']);
55                 $_POST['title']  = $addslashes($_POST['title']);
56                 $_POST['body_text']  = $addslashes($_POST['body_text']);
57
58                 //The following checks if title length exceed 100, defined by DB structure
59                 $_POST['title'] = validate_length($_POST['title'], 100);
60
61                 $sql    = "INSERT INTO ".TABLE_PREFIX."news VALUES (NULL, $_SESSION[course_id], $_SESSION[member_id], NOW(), $_POST[formatting], '$_POST[title]', '$_POST[body_text]')";
62                 mysql_query($sql, $db);
63         
64                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
65
66                 /* update announcement RSS: */
67                 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml')) {
68                         @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml');
69                 }
70                 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml')) {
71                         @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml');
72                 }
73
74                 header('Location: '.AT_BASE_HREF.'mods/_standard/announcements/index.php');
75                 exit;
76         }
77 }
78
79 if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
80         if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
81                 $_POST['formatting'] = 1;
82                 $_REQUEST['settext'] = 0;
83                 $_REQUEST['setvisual'] = 0;
84
85         } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
86                 $_POST['formatting'] = 1;
87                 $_POST['settext'] = 0;
88                 $_POST['setvisual'] = 1;
89
90         } else { // else if == 0
91                 $_POST['formatting'] = 0;
92                 $_REQUEST['settext'] = 0;
93                 $_REQUEST['setvisual'] = 0;
94         }
95 }
96
97 require(AT_INCLUDE_PATH.'header.inc.php');
98
99 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
100         load_editor();
101 }
102 $msg->printErrors();
103 $savant->display('instructor/announcements/add_news.tmpl.php');
104 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>