Moved scripts in "docs" one level up into root folder. In addition, removed "docs...
[atutor.git] / 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
112 ?>
113
114
115 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
116 <input type="hidden" name="edit_news" value="true">
117 <input type="hidden" name="aid" value="<?php echo $row['news_id']; ?>">
118 <input type="submit" name="submit" style="display:none;"/>
119 <div class="input-form">
120         <div class="row">
121                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
122                 <input type="text" name="title" id="title" value="<?php echo htmlentities_utf8(stripslashes($row['title'])); ?>" size="40">
123         </div>
124
125         <div class="row">
126                 <?php echo _AT('formatting'); ?><br />
127                 <input type="radio" name="formatting" value="0" id="text" <?php if ($_POST['formatting'] === 0) { echo 'checked="checked"'; } ?> onclick="javascript: document.form.setvisual.disabled=true;" <?php if ($_POST['setvisual'] && !$_POST['settext']) { echo 'disabled="disabled"'; } ?> /><label for="text"><?php echo _AT('plain_text'); ?></label>,
128
129                 <input type="radio" name="formatting" value="1" id="html" <?php if ($_POST['formatting'] == 1 || $_POST['setvisual']) { echo 'checked="checked"'; } ?> onclick="javascript: document.form.setvisual.disabled=false;"  /> <label for="html"><?php echo _AT('html'); ?></label>
130                 <?php
131                         if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
132                                 echo '<input type="hidden" name="setvisual" value="'.$_POST['setvisual'].'" />';
133                                 echo '<input type="submit" name="settext"   value="'._AT('switch_text').'" />';
134                         } else {
135                                 echo '<input type="submit" name="setvisual" value="'._AT('switch_visual').'" ';
136                                 if ($_POST['formatting']==0) { echo 'disabled="disabled"'; }
137                                 echo '/>';
138                         } 
139                 ?>
140         </div>
141
142         <div class="row">
143                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="body_text"><?php echo _AT('body'); ?></label><br />
144                 <textarea name="body_text" cols="55" rows="15" id="body_text" wrap="wrap"><?php echo htmlentities_utf8($row['body']); ?></textarea>
145         </div>
146
147         <div class="row buttons">
148                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
149                 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
150         </div>
151
152
153 </div>
154 </form>
155
156 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>