2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2010 */
\r
6 /* Inclusive Design Institute */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
13 define('TR_INCLUDE_PATH', '../include/');
\r
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
\r
15 require_once(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
\r
18 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
\r
19 $editable_file_types = array('txt', 'html', 'htm', 'xml', 'css', 'asc', 'csv', 'sql');
\r
21 $current_path = TR_CONTENT_DIR.$_course_id.'/';
\r
23 $popup = $_REQUEST['popup'];
\r
24 $framed = $_REQUEST['framed'];
\r
25 $file = $_REQUEST['file'];
\r
26 $pathext = $_REQUEST['pathext'];
\r
28 if (isset($_POST['cancel'])) {
\r
29 $msg->addFeedback('CANCELLED');
\r
30 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
\r
34 if (isset($_POST['save'])) {
\r
35 $content = str_replace("\r\n", "\n", $stripslashes($_POST['body_text']));
\r
36 $file = $_POST['file'];
\r
38 if (FileUtility::course_realpath($current_path . $pathext . $file) == FALSE) {
\r
39 $msg->addError('FILE_NOT_SAVED');
\r
41 if (($f = @fopen($current_path.$pathext.$file, 'w')) && (@fwrite($f, $content) !== false) && @fclose($f)) {
\r
42 $msg->addFeedback(array('FILE_SAVED', $file));
\r
43 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
\r
46 $msg->addError('FILE_NOT_SAVED');
\r
49 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
\r
54 $path_parts = pathinfo($current_path.$pathext.$file);
\r
55 $ext = strtolower($path_parts['extension']);
\r
57 // open file to edit
\r
58 $real = realpath($current_path . $pathext . $file);
\r
60 if (FileUtility::course_realpath($current_path . $pathext . $file) == FALSE) {
\r
61 // error: File does not exist
\r
62 $msg->addError('FILE_NOT_EXIST');
\r
63 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
\r
65 } else if (is_dir($current_path.$pathext.$file)) {
\r
66 // error: cannot edit folder
\r
67 $msg->addError('BAD_FILE_TYPE');
\r
68 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
\r
70 } else if (!is_readable($current_path.$pathext.$file)) {
\r
71 // error: File cannot open file
\r
72 $msg->addError(array('CANNOT_OPEN_FILE', $file));
\r
73 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
\r
75 } else if (in_array($ext, $editable_file_types)) {
\r
76 $_POST['body_text'] = file_get_contents($current_path.$pathext.$file);
\r
78 //error: bad file type
\r
79 $msg->addError('BAD_FILE_TYPE');
\r
80 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
\r
84 $onload = "on_load();";
\r
85 require(TR_INCLUDE_PATH.'header.inc.php');
\r
86 require(TR_INCLUDE_PATH.'lib/tinymce.inc.php');
\r
88 // load tinymce library
\r
89 load_editor(true, false, "none");
\r
91 if (!isset($_POST['extension'])) {
\r
92 if ($ext == 'html' || $ext == 'htm')
\r
93 $_POST['extension'] = 'html';
\r
95 $_POST['extension'] = 'txt';
\r
99 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
\r
100 <input type="hidden" name="pathext" value="<?php echo $pathext; ?>" />
\r
101 <input type="hidden" name="framed" value="<?php echo $framed; ?>" />
\r
102 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
\r
103 <input type="hidden" name="file" value="<?php echo $file; ?>" />
\r
104 <input type="hidden" name="_course_id" value="<?php echo $_course_id; ?>" />
\r
105 <input type="submit" name="submit" style="display:none;"/>
\r
106 <div class="input-form">
\r
108 <h3><?php echo $file; ?></h3>
\r
111 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('type'); ?><br />
\r
112 <input type="radio" name="extension" value="txt" id="text" <?php if ($_POST['extension'] == 'txt') { echo 'checked="checked"'; } ?> onclick="trans.editor.switch_content_type(this.value);" />
\r
113 <label for="text"><?php echo _AT('plain_text'); ?></label>
\r
115 , <input type="radio" name="extension" value="html" id="html" <?php if ($_POST['extension'] == 'html') { echo 'checked="checked"'; } ?> onclick="trans.editor.switch_content_type(this.value);" />
\r
116 <label for="html"><?php echo _AT('html'); ?></label>
\r
119 <label for="body_text"><?php echo _AT('body'); ?></label><br />
\r
120 <textarea name="body_text" id="body_text" rows="25"><?php echo htmlspecialchars($_POST['body_text']); ?></textarea>
\r
123 <div class="row buttons">
\r
124 <input type="submit" name="save" value="<?php echo _AT('save'); ?>" accesskey="s" />
\r
125 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
130 <script type="text/javascript" language="javascript">
\r
134 if (jQuery('#html').attr("checked")) {
\r
135 tinyMCE.execCommand('mceAddControl', false, 'body_text');
\r
139 trans.editor.switch_content_type = function (extension) {
\r
140 if (extension === 'txt') { //text type
\r
141 tinyMCE.execCommand('mceRemoveControl', false, 'body_text');
\r
144 tinyMCE.execCommand('mceAddControl', false, 'body_text');
\r
150 <?php require(TR_INCLUDE_PATH.'footer.inc.php'); ?>
\r