2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
19 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
20 authenticate(AT_PRIV_CONTENT);
24 $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
26 $popup = $_REQUEST['popup'];
27 $framed = $_REQUEST['framed'];
30 if (isset($_POST['cancel'])) {
31 $msg->addFeedback('CANCELLED');
32 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
36 if (isset($_POST['submit_no'])) {
37 $msg->addFeedback('CANCELLED');
38 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
42 if (isset($_POST['submit_yes'])) {
43 $filename = preg_replace("{[^a-zA-Z0-9_]}","_", trim($_POST['filename']));
44 $pathext = $_POST['pathext'];
46 /* only html or txt extensions allowed */
47 if ($_POST['extension'] == 'html') {
53 if (course_realpath($current_path . $pathext . $filename.'.'.$extension) == FALSE) {
54 $msg->addError('FILE_NOT_SAVED');
55 /* take user to home page to avoid unspecified error warning */
56 header('Location: index.php?pathext='.SEP.'framed='.$framed.SEP.'popup='.$popup);
60 if (($f = @fopen($current_path.$pathext.$filename.'.'.$extension,'w')) && @fwrite($f, stripslashes($_POST['body_text'])) !== FALSE && @fclose($f)){
61 $msg->addFeedback('FILE_OVERWRITE');
63 $msg->addError('CANNOT_OVERWRITE_FILE');
65 unset($_POST['newfile']);
66 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
70 if (isset($_POST['savenewfile'])) {
72 if (isset($_POST['filename']) && ($_POST['filename'] != "")) {
73 $filename = preg_replace("{[^a-zA-Z0-9_]}","_", trim($_POST['filename']));
74 $pathext = $_POST['pathext'];
75 $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
77 /* only html or txt extensions allowed */
78 if ($_POST['extension'] == 'html') {
80 $head_html = "<html>\n<head>\n<title>".$_POST['filename']."</title>\n<head>\n<body>";
81 $foot_html ="\n</body>\n</html>";
86 if (!@file_exists($current_path.$pathext.$filename.'.'.$extension)) {
87 $content = str_replace("\r\n", "\n", $head_html.$_POST['body_text'].$foot_html);
89 if (course_realpath($current_path . $pathext . $filename.'.'.$extension) == FALSE) {
90 $msg->addError('FILE_NOT_SAVED');
91 /* take user to home page to avoid unspecified error warning */
92 header('Location: index.php?pathext='.SEP.'framed='.$framed.SEP.'popup='.$popup);
96 if (($f = fopen($current_path.$pathext.$filename.'.'.$extension, 'w')) && (@fwrite($f, stripslashes($content)) !== false) && (@fclose($f))) {
97 $msg->addFeedback(array('FILE_SAVED', $filename.'.'.$extension));
98 header('Location: index.php?pathext='.urlencode($_POST['pathext']).SEP.'popup='.$_POST['popup']);
101 $msg->addError('FILE_NOT_SAVED');
102 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
107 require(AT_INCLUDE_PATH.'header.inc.php');
108 $pathext = $_POST['pathext'];
109 $popup = $_POST['popup'];
111 $_POST['newfile'] = "new";
113 $hidden_vars['pathext'] = $pathext;
114 $hidden_vars['filename'] = $filename;
115 $hidden_vars['extension'] = $extension;
116 $hidden_vars['body_text'] = $_POST['body_text'];
118 $hidden_vars['popup'] = $popup;
119 $hidden_vars['framed'] = $framed;
121 $msg->addConfirm(array('FILE_EXISTS', $filename.'.'.$extension), $hidden_vars);
122 $msg->printConfirm();
124 require(AT_INCLUDE_PATH.'footer.inc.php');
128 $msg->addError(array('EMPTY_FIELDS', _AT('file_name')));
134 require(AT_INCLUDE_PATH.'header.inc.php');
135 require(AT_INCLUDE_PATH.'lib/tinymce.inc.php');
137 if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
138 if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
139 $_POST['formatting'] = 1;
140 $_REQUEST['settext'] = 0;
141 $_REQUEST['setvisual'] = 0;
143 } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
144 $_POST['formatting'] = 1;
145 $_POST['settext'] = 0;
146 $_POST['setvisual'] = 1;
148 } else { // else if == 0
149 $_POST['formatting'] = 0;
150 $_REQUEST['settext'] = 0;
151 $_REQUEST['setvisual'] = 0;
155 // load tinymce library
156 load_editor(false, false, "none");
158 $pathext = $_GET['pathext'];
159 $popup = $_GET['popup'];
162 if (!$_POST['extension']) {
163 $_POST['extension'] = 'txt';
164 $_POST['formatting'] = 0;
165 }else if($_POST['extension'] == "html"){
166 $_POST['formatting'] = 1;
170 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
171 <input type="hidden" name="pathext" value="<?php echo $_REQUEST['pathext'] ?>" />
172 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
174 <div class="input-form">
175 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create_new_file'); ?></legend>
177 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="ctitle"><?php echo _AT('file_name'); ?></label><br />
178 <input type="text" name="filename" id="ctitle" size="40" <?php if (isset($_POST['filename'])) echo 'value="'.$_POST['filename'].'"'?> />
182 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('type'); ?><br />
183 <input type="radio" name="extension" value="txt" id="text" <?php if ($_POST['formatting'] == 0) { echo 'checked="checked"'; } ?> onclick="javascript: document.form.setvisualbutton.disabled=true;" <?php if ($_POST['setvisual'] && !$_POST['settext']) { echo 'disabled="disabled"'; } ?> />
184 <label for="text"><?php echo _AT('plain_text'); ?></label>
186 , <input type="radio" name="extension" value="html" id="html" <?php if ($_POST['formatting'] ==1 || $_POST['setvisual']) { echo 'checked="checked"'; } ?> onclick="javascript: document.form.setvisualbutton.disabled=false;"/>
187 <label for="html"><?php echo _AT('html'); ?></label>
189 <input type="hidden" name="setvisual" value="<?php echo $_POST['setvisual']; ?>" />
190 <input type="hidden" name="settext" value="<?php echo $_POST['settext']; ?>" />
191 <input type="button" name="setvisualbutton" value="<?php echo _AT('switch_visual'); ?>" onClick="switch_body_editor()" />
195 <label for="body_text"><?php echo _AT('body'); ?></label><br />
196 <textarea name="body_text" id="body_text" rows="25"><?php echo ContentManager::cleanOutput($_POST['body_text']); ?></textarea>
199 <div class="row buttons">
200 <input type="submit" name="savenewfile" value="<?php echo _AT('save'); ?>" accesskey="s" />
201 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
207 <script type="text/javascript" language="javascript">
211 if (document.getElementById("text").checked)
212 document.form.setvisualbutton.disabled = true;
214 if (document.form.setvisual.value==1)
216 tinyMCE.execCommand('mceAddControl', false, 'body_text');
217 document.form.extension[0].disabled = "disabled";
218 document.form.setvisualbutton.value = "<?php echo _AT('switch_text'); ?>";
222 document.form.setvisualbutton.value = "<?php echo _AT('switch_visual'); ?>";
226 // switch between text, visual editor for "body text"
227 function switch_body_editor()
229 if (document.form.setvisualbutton.value=="<?php echo _AT('switch_visual'); ?>")
231 tinyMCE.execCommand('mceAddControl', false, 'body_text');
232 document.form.setvisual.value=1;
233 document.form.settext.value=0;
234 document.form.extension[0].disabled = "disabled";
235 document.form.setvisualbutton.value = "<?php echo _AT('switch_text'); ?>";
239 tinyMCE.execCommand('mceRemoveControl', false, 'body_text');
240 document.form.setvisual.value=0;
241 document.form.settext.value=1;
242 document.form.extension[0].disabled = "";
243 document.form.setvisualbutton.value = "<?php echo _AT('switch_visual'); ?>";
249 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>