2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 define('TR_INCLUDE_PATH', '../include/');
14 require(TR_INCLUDE_PATH.'vitals.inc.php');
15 require(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
18 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
20 $current_path = TR_CONTENT_DIR.$_course_id.'/';
22 $popup = $_REQUEST['popup'];
23 $framed = $_REQUEST['framed'];
26 if (isset($_POST['cancel'])) {
27 $msg->addFeedback('CANCELLED');
28 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
32 if (isset($_POST['submit_no'])) {
33 $msg->addFeedback('CANCELLED');
34 header('Location: index.php?pathext='.$_POST['pathext'].SEP.'framed='.$_POST['framed'].SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
38 if (isset($_POST['submit_yes'])) {
39 $filename = preg_replace("{[^a-zA-Z0-9_]}","_", trim($_POST['filename']));
40 $pathext = $_POST['pathext'];
42 /* only html or txt extensions allowed */
43 if ($_POST['extension'] == 'html') {
49 if (FileUtility::course_realpath($current_path . $pathext . $filename.'.'.$extension) == FALSE) {
50 $msg->addError('FILE_NOT_SAVED');
51 /* take user to home page to avoid unspecified error warning */
52 header('Location: index.php?pathext='.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
56 if (($f = @fopen($current_path.$pathext.$filename.'.'.$extension,'w')) && @fwrite($f, stripslashes($_POST['body_text'])) !== FALSE && @fclose($f)){
57 $msg->addFeedback('FILE_OVERWRITE');
59 $msg->addError('CANNOT_OVERWRITE_FILE');
61 unset($_POST['newfile']);
62 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
66 if (isset($_POST['savenewfile'])) {
68 if (isset($_POST['filename']) && ($_POST['filename'] != "")) {
69 $filename = preg_replace("{[^a-zA-Z0-9_]}","_", trim($_POST['filename']));
70 $pathext = $_POST['pathext'];
71 $current_path = TR_CONTENT_DIR.$_course_id.'/';
73 /* only html or txt extensions allowed */
74 if ($_POST['extension'] == 'html') {
76 $head_html = "<html>\n<head>\n<title>".$_POST['filename']."</title>\n<head>\n<body>";
77 $foot_html ="\n</body>\n</html>";
82 if (!@file_exists($current_path.$pathext.$filename.'.'.$extension)) {
83 $content = str_replace("\r\n", "\n", $head_html.$_POST['body_text'].$foot_html);
85 if (FileUtility::course_realpath($current_path . $pathext . $filename.'.'.$extension) == FALSE) {
86 $msg->addError('FILE_NOT_SAVED');
87 /* take user to home page to avoid unspecified error warning */
88 header('Location: index.php?pathext='.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
92 if (($f = fopen($current_path.$pathext.$filename.'.'.$extension, 'w')) && (@fwrite($f, stripslashes($content)) !== false) && (@fclose($f))) {
93 $msg->addFeedback(array('FILE_SAVED', $filename.'.'.$extension));
94 header('Location: index.php?pathext='.urlencode($_POST['pathext']).SEP.'popup='.$_POST['popup'].SEP.'_course_id='.$_course_id);
97 $msg->addError('FILE_NOT_SAVED');
98 header('Location: index.php?pathext='.$pathext.SEP.'framed='.$framed.SEP.'popup='.$popup.SEP.'_course_id='.$_course_id);
103 require(TR_INCLUDE_PATH.'header.inc.php');
104 $pathext = $_POST['pathext'];
105 $popup = $_POST['popup'];
107 $_POST['newfile'] = "new";
109 $hidden_vars['pathext'] = $pathext;
110 $hidden_vars['filename'] = $filename;
111 $hidden_vars['extension'] = $extension;
112 $hidden_vars['_course_id'] = $_course_id;
113 $hidden_vars['body_text'] = $_POST['body_text'];
115 $hidden_vars['popup'] = $popup;
116 $hidden_vars['framed'] = $framed;
118 $msg->addConfirm(array('FILE_EXISTS', $filename.'.'.$extension), $hidden_vars);
119 $msg->printConfirm();
121 require(TR_INCLUDE_PATH.'footer.inc.php');
125 $msg->addError(array('EMPTY_FIELDS', _AT('file_name')));
131 require(TR_INCLUDE_PATH.'header.inc.php');
132 require(TR_INCLUDE_PATH.'lib/tinymce.inc.php');
134 // set default body editor to tinymce editor
135 if (!isset($_POST['extension'])) $_POST['extension'] = 'html';
137 // load tinymce library
138 load_editor(true, false, "none");
140 $pathext = $_GET['pathext'];
141 $popup = $_GET['popup'];
146 <form action="<?php echo $_SERVER['PHP_SELF'].'?_course_id='.$_course_id; ?>" method="post" name="form">
147 <input type="hidden" name="pathext" value="<?php echo $_REQUEST['pathext'] ?>" />
148 <input type="hidden" name="popup" value="<?php echo $popup; ?>" />
150 <div class="input-form">
151 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create_new_file'); ?></legend>
153 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="ctitle"><?php echo _AT('file_name'); ?></label><br />
154 <input type="text" name="filename" id="ctitle" size="40" <?php if (isset($_POST['filename'])) echo 'value="'.AT_print($_POST['filename'], 'input.text').'"'?> />
158 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><?php echo _AT('type'); ?><br />
159 <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);" />
160 <label for="text"><?php echo _AT('plain_text'); ?></label>
162 , <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);" />
163 <label for="html"><?php echo _AT('html'); ?></label>
167 <label for="body_text"><?php echo _AT('body'); ?></label><br />
168 <textarea name="body_text" id="body_text" rows="25"><?php echo ContentManager::cleanOutput($_POST['body_text']); ?></textarea>
171 <div class="row buttons">
172 <input type="submit" name="savenewfile" value="<?php echo _AT('save'); ?>" accesskey="s" />
173 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
179 <script type="text/javascript" language="javascript">
183 document.form.filename.focus();
184 if (jQuery('#html').attr("checked")) {
185 tinyMCE.execCommand('mceAddControl', false, 'body_text');
189 trans.editor.switch_content_type = function (extension) {
190 if (extension === 'txt') { //text type
191 tinyMCE.execCommand('mceRemoveControl', false, 'body_text');
194 tinyMCE.execCommand('mceAddControl', false, 'body_text');
201 <?php require(TR_INCLUDE_PATH.'footer.inc.php'); ?>