2 /****************************************************************/
\r
4 /****************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\r
9 /* This program is free software. You can redistribute it and/or*/
\r
10 /* modify it under the terms of the GNU General Public License */
\r
11 /* as published by the Free Software Foundation. */
\r
12 /****************************************************************/
\r
15 define('AT_INCLUDE_PATH', '../../../include/');
\r
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
\r
17 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
\r
20 if (!authenticate(AT_PRIV_FILES,AT_PRIV_RETURN)) {
\r
21 authenticate(AT_PRIV_CONTENT);
\r
24 $current_path = AT_CONTENT_DIR.$_SESSION['course_id'].'/';
\r
26 $popup = $_REQUEST['popup'];
\r
27 $framed = $_REQUEST['framed'];
\r
28 $file = $_REQUEST['file'];
\r
29 $pathext = $_REQUEST['pathext'];
\r
31 if (isset($_POST['cancel'])) {
\r
32 $msg->addFeedback('CANCELLED');
\r
33 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
\r
37 if (isset($_POST['save'])) {
\r
38 $content = str_replace("\r\n", "\n", $stripslashes($_POST['body_text']));
\r
39 $file = $_POST['file'];
\r
41 if (course_realpath($current_path . $pathext . $file) == FALSE) {
\r
42 $msg->addError('FILE_NOT_SAVED');
\r
44 if (($f = @fopen($current_path.$pathext.$file, 'w')) && (@fwrite($f, $content) !== false) && @fclose($f)) {
\r
45 $msg->addFeedback(array('FILE_SAVED', $file));
\r
46 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
\r
49 $msg->addError('FILE_NOT_SAVED');
\r
52 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup']);
\r
57 $path_parts = pathinfo($current_path.$pathext.$file);
\r
58 $ext = strtolower($path_parts['extension']);
\r
60 // open file to edit
\r
61 $real = realpath($current_path . $pathext . $file);
\r
63 if (course_realpath($current_path . $pathext . $file) == FALSE) {
\r
64 // error: File does not exist
\r
65 $msg->addError('FILE_NOT_EXIST');
\r
66 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
\r
68 } else if (is_dir($current_path.$pathext.$file)) {
\r
69 // error: cannot edit folder
\r
70 $msg->addError('BAD_FILE_TYPE');
\r
71 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
\r
73 } else if (!is_readable($current_path.$pathext.$file)) {
\r
74 // error: File cannot open file
\r
75 $msg->addError(array('CANNOT_OPEN_FILE', $file));
\r
76 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
\r
78 } else if (in_array($ext, $editable_file_types)) {
\r
79 $_POST['body_text'] = file_get_contents($current_path.$pathext.$file);
\r
81 //error: bad file type
\r
82 $msg->addError('BAD_FILE_TYPE');
\r
83 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup);
\r
87 require(AT_INCLUDE_PATH.'header.inc.php');
\r
88 require(AT_INCLUDE_PATH.'lib/tinymce.inc.php');
\r
90 if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
\r
91 if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
\r
92 $_POST['formatting'] = 1;
\r
93 $_REQUEST['settext'] = 0;
\r
94 $_REQUEST['setvisual'] = 0;
\r
96 } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
\r
97 $_POST['formatting'] = 1;
\r
98 $_POST['settext'] = 0;
\r
99 $_POST['setvisual'] = 1;
\r
101 } else { // else if == 0
\r
102 $_POST['formatting'] = 0;
\r
103 $_REQUEST['settext'] = 0;
\r
104 $_REQUEST['setvisual'] = 0;
\r
107 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
\r
108 load_editor(false, 'body_text');
\r
114 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
115 <input type="hidden" name="pathext" value="<?php echo $pathext; ?>" />
\r
116 <input type="hidden" name="framed" value="<?php echo $framed; ?>" />
\r
117 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
\r
118 <input type="hidden" name="file" value="<?php echo $file; ?>" />
\r
119 <input type="submit" name="submit" style="display:none;"/>
\r
120 <div class="input-form">
\r
122 <h3><?php echo $file; ?></h3>
\r
126 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
\r
127 echo '<input type="hidden" name="setvisual" value="'.$_POST['setvisual'].'" />';
\r
128 echo '<input type="submit" name="settext" value="'._AT('switch_text').'" />';
\r
130 echo '<input type="submit" name="setvisual" value="'._AT('switch_visual').'" />';
\r
135 <label for="body_text"><?php echo _AT('body'); ?></label><br />
\r
136 <textarea name="body_text" id="body_text" rows="25"><?php echo htmlspecialchars($_POST['body_text']); ?></textarea>
\r
139 <div class="row buttons">
\r
140 <input type="submit" name="save" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
141 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
146 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>