tagging as ATutor 1.5.4-release
[atutor.git] / editor / add_news.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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.'tools/news/index.php');
29         exit;
30
31
32 if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
33         if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
34                 $_POST['formatting'] = 1;
35                 $_REQUEST['settext'] = 0;
36                 $_REQUEST['setvisual'] = 0;
37
38         } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
39                 $_POST['formatting'] = 1;
40                 $_POST['settext'] = 0;
41                 $_POST['setvisual'] = 1;
42
43         } else { // else if == 0
44                 $_POST['formatting'] = 0;
45                 $_REQUEST['settext'] = 0;
46                 $_REQUEST['setvisual'] = 0;
47         }
48 }
49
50 if ((!$_POST['setvisual'] && $_POST['settext']) || !$_GET['setvisual']){
51         $onload = 'document.form.title.focus();';
52 }
53
54 if (isset($_POST['add_news'])&& isset($_POST['submit'])) {
55         $_POST['formatting'] = intval($_POST['formatting']);
56         $_POST['title'] = trim($_POST['title']);
57         $_POST['body_text'] = trim($_POST['body_text']);
58         
59         $missing_fields = array();
60
61         if (!$_POST['body_text']) {
62                 $missing_fields[] = _AT('body');
63         }
64
65         if ($missing_fields) {
66                 $missing_fields = implode(', ', $missing_fields);
67                 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
68         }
69
70         if (!$msg->containsErrors() && (!isset($_POST['setvisual']) || isset($_POST['submit']))) {
71
72                 $_POST['formatting']  = $addslashes($_POST['formatting']);
73                 $_POST['title']  = $addslashes($_POST['title']);
74                 $_POST['body_text']  = $addslashes($_POST['body_text']);
75
76                 $sql    = "INSERT INTO ".TABLE_PREFIX."news VALUES (NULL, $_SESSION[course_id], $_SESSION[member_id], NOW(), $_POST[formatting], '$_POST[title]', '$_POST[body_text]')";
77                 mysql_query($sql, $db);
78         
79                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
80
81                 /* update announcement RSS: */
82                 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml')) {
83                         @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS1.0.xml');
84                 }
85                 if (file_exists(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml')) {
86                         @unlink(AT_CONTENT_DIR . 'feeds/' . $_SESSION['course_id'] . '/RSS2.0.xml');
87                 }
88
89                 header('Location: '.AT_BASE_HREF.'tools/news/index.php');
90                 exit;
91         }
92 }
93
94 require(AT_INCLUDE_PATH.'header.inc.php');
95
96 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
97         load_editor();
98 }
99 $msg->printErrors();
100
101 ?>
102         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
103         <input type="hidden" name="add_news" value="true" />
104
105         <div class="input-form">
106                 <div class="row">
107                         <label for="title"><?php echo _AT('title'); ?></label><br />
108                         <input type="text" name="title" size="40" id="title" value="<?php echo $_POST['title']; ?>" />
109                 </div>
110
111                 <div class="row">
112                         <?php echo _AT('formatting'); ?><br />
113                         <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"'; } ?> />
114
115                         <label for="text"><?php echo _AT('plain_text'); ?></label>
116                         <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;"/>
117
118                         <label for="html"><?php echo _AT('html'); ?></label>
119                         <?php   //Button for enabling/disabling visual editor
120                                 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
121                                         echo '<input type="hidden" name="setvisual" value="'.$_POST['setvisual'].'" />';
122                                         echo '<input type="submit" name="settext" value="'._AT('switch_text').'" />';
123                                 } else {
124                                         echo '<input type="submit" name="setvisual" value="'._AT('switch_visual').'"  ';
125                                         if ($_POST['formatting']==0) { echo 'disabled="disabled"'; }
126                                         echo '/>';
127                                 }
128                         ?>
129                 </div>
130
131                 <div class="row">
132                         <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="body_text"><?php echo _AT('body'); ?></label><br />
133                         <textarea name="body_text" cols="55" rows="15" id="body_text"><?php echo $_POST['body_text']; ?></textarea>
134                 </div>
135                 
136                 <div class="row buttons">
137                         <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
138                         <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
139                 </div>
140         </div>
141         </form>
142
143 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>