made a copy
[atutor.git] / editor / add_news.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 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 ((!$_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.'tools/news/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
104 ?>
105         <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
106         <input type="hidden" name="add_news" value="true" />
107         <input type="submit" name="submit" style="display:none;"/>
108         <div class="input-form">
109         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('add_announcement'); ?></legend>
110                 <div class="row">
111                         <label for="title"><?php echo _AT('title'); ?></label><br />
112                         <input type="text" name="title" size="40" id="title" value="<?php echo $_POST['title']; ?>" />
113                 </div>
114
115                 <div class="row">
116                         <?php echo _AT('formatting'); ?><br />
117                         <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"'; } ?> />
118
119                         <label for="text"><?php echo _AT('plain_text'); ?></label>
120                         <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;"/>
121
122                         <label for="html"><?php echo _AT('html'); ?></label>
123                         <?php   //Button for enabling/disabling visual editor
124                                 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
125                                         echo '<input type="hidden" name="setvisual" value="'.$_POST['setvisual'].'" />';
126                                         echo '<input type="submit" name="settext" value="'._AT('switch_text').'" />';
127                                 } else {
128                                         echo '<input type="submit" name="setvisual" value="'._AT('switch_visual').'"  ';
129                                         if ($_POST['formatting']==0) { echo 'disabled="disabled"'; }
130                                         echo '/>';
131                                 }
132                         ?>
133                 </div>
134
135                 <div class="row">
136                         <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="body_text"><?php echo _AT('body'); ?></label><br />
137                         <textarea name="body_text" cols="55" rows="15" id="body_text"><?php echo $_POST['body_text']; ?></textarea>
138                 </div>
139                 
140                 <div class="row buttons">
141                         <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
142                         <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?> " />
143                 </div>
144         </fieldset>
145         </div>
146         </form>
147
148 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>