remove old readme
[atutor.git] / docs / mods / _standard / announcements / edit_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
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 } else if ($_POST['edit_news']) {
31         $_POST['title'] = trim($_POST['title']);
32         $_POST['body_text']  = trim($_POST['body_text']);
33         $_POST['aid']   = intval($_POST['aid']);
34         $_POST['formatting']    = intval($_POST['formatting']);
35
36         if (($_POST['title'] == '') && ($_POST['body_text'] == '')) {
37                 $msg->addErros('ANN_BOTH_EMPTY');
38         }
39
40         if (!$msg->containsErrors() && isset($_POST['submit'])) {
41                 $_POST['title']  = $addslashes($_POST['title']);
42                 $_POST['body_text']  = $addslashes($_POST['body_text']);
43                 //Check if the title has exceeded the DB length, 100
44                 $_POST['title'] = validate_length($_POST['title'], 100);
45
46                 $sql = "UPDATE ".TABLE_PREFIX."news SET title='$_POST[title]', body='$_POST[body_text]', formatting=$_POST[formatting], date=date WHERE news_id=$_POST[aid] AND course_id=$_SESSION[course_id]";
47                 $result = mysql_query($sql,$db);
48
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
57                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
58                 header('Location: '.AT_BASE_HREF.'mods/_standard/announcements/index.php');
59                 exit;
60         }
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
69         } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
70                 $_POST['formatting'] = 1;
71                 $_POST['settext'] = 0;
72                 $_POST['setvisual'] = 1;
73
74         } else { // else if == 0
75                 $_POST['formatting'] = 0;
76                 $_REQUEST['settext'] = 0;
77                 $_REQUEST['setvisual'] = 0;
78         }
79 }
80
81 if ((!$_POST['setvisual'] && $_POST['settext']) || !$_GET['setvisual']){
82         $onload = 'document.form.title.focus();';
83 }
84
85 require(AT_INCLUDE_PATH.'header.inc.php');
86
87 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
88         load_editor();
89 }
90
91 if (isset($_GET['aid'])) {
92         $aid = intval($_GET['aid']);
93 } else {
94         $aid = intval($_POST['aid']);
95 }
96
97 if ($aid == 0) {
98         $msg->printErrors('ITEM_NOT_FOUND');
99         require (AT_INCLUDE_PATH.'footer.inc.php');
100         exit;
101 }
102
103 $sql = "SELECT * FROM ".TABLE_PREFIX."news WHERE news_id=$aid AND course_id=$_SESSION[course_id]";
104 $result = mysql_query($sql,$db);
105 if (!($row = mysql_fetch_array($result))) {
106         $msg->printErrors('ITEM_NOT_FOUND');
107         require (AT_INCLUDE_PATH.'footer.inc.php');
108         exit;
109 }
110 $_POST['formatting'] = intval($row['formatting']);
111 $savant->assign('row', $row);
112 $savant->display('instructor/announcements/edit_news.tmpl.php');
113 require (AT_INCLUDE_PATH.'footer.inc.php'); ?>