2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-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 /************************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
16 global $db, $associated_forum;
18 $get_related_glossary = true;
19 require(AT_INCLUDE_PATH.'vitals.inc.php');
21 authenticate(AT_PRIV_CONTENT);
23 require(AT_INCLUDE_PATH.'lib/tinymce.inc.php');
24 require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');
26 $cid = intval($_REQUEST['cid']);
34 require(AT_INCLUDE_PATH.'../mods/_core/editor/editor_tab_functions.inc.php');
36 if ($_POST['close'] || $_GET['close']) {
38 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
40 $msg->addFeedback('CLOSED');
42 header('Location: '.AT_BASE_HREF.'mods/_core/content/index.php');
47 if ($_REQUEST['cid'] == 0) {
48 header('Location: '.AT_BASE_HREF.'mods/_core/content/index.php');
51 header('Location: '.$_base_path.url_rewrite('content.php?cid='.intval($_REQUEST['cid'])));
56 $num_tabs = count($tabs);
57 for ($i=0; $i < $num_tabs; $i++) {
58 if (isset($_POST['button_'.$i]) && ($_POST['button_'.$i] != -1)) {
60 $_POST['current_tab'] = $i;
65 if (isset($_GET['tab'])) {
66 $current_tab = intval($_GET['tab']);
68 if (isset($_POST['current_tab'])) {
69 $current_tab = intval($_POST['current_tab']);
72 if (isset($_POST['submit_file'])) {
73 paste_from_file(body_text);
74 } else if (isset($_POST['submit']) && ($_POST['submit'] != 'submit1')) {
75 /* we're saving. redirects if successful. */
76 save_changes(true, $current_tab);
79 if (isset($_POST['submit_file_alt'])) {
80 paste_from_file(body_text_alt);
81 } else if (isset($_POST['submit']) && ($_POST['submit'] != 'submit1')) {
82 /* we're saving. redirects if successful. */
83 save_changes(true, $current_tab);
86 if (isset($_POST['submit'])) {
87 /* we're saving. redirects if successful. */
88 save_changes(true, $current_tab);
91 if (!isset($current_tab) && isset($_POST['button_1']) && ($_POST['button_1'] == -1) && !isset($_POST['submit'])) {
93 } else if (!isset($current_tab)) {
98 $_section[0][0] = _AT('edit_content');
100 $_section[0][0] = _AT('add_content');
103 if($current_tab == 0) {
104 global $_content_tools;
107 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/framework/fss/css/fss-layout.css" />
108 <link rel="stylesheet" type="text/css" href="'.AT_BASE_HREF.'jscripts/infusion/framework/fss/css/fss-text.css" />
110 $_content_tools = is_array($_content_tools) ? $_content_tools : array();
112 $current_tool_pos = 0;
113 $_content_tools[] = array("id"=>"previewtool",
114 "class"=>"fl-col clickable",
115 "src"=>AT_BASE_HREF."images/preview.png",
116 "title"=>_AT('preview').' - '._AT('new_window'),
117 "alt"=>_AT('preview').' - '._AT('new_window'),
118 "text"=>_AT('preview'),
119 "js"=>AT_BASE_HREF."mods/_core/editor/js/edit.js",
120 "position"=>++$current_tool_pos);
122 $_content_tools[] = array("id"=>"accessibilitytool", "class"=>"fl-col", "text"=>_AT('accessibility'), "position"=>++$current_tool_pos);
123 $_content_tools[] = array("id"=>"headtool", "class"=>"fl-col", "text"=>_AT('customized_head'), "position"=>++$current_tool_pos);
124 $_content_tools[] = array("id"=>"pastetool", "class"=>"fl-col", "text"=>_AT('paste'), "position"=>++$current_tool_pos);
125 $_content_tools[] = array("id"=>"filemantool", "class"=>"fl-col", "text"=>_AT('files'), "position"=>++$current_tool_pos);
127 foreach ($_content_tools as $tool) {
128 if (isset($tool["js"])) {
129 $_custom_head .= '<script type="text/javascript" src="'.$tool["js"].'"></script>'."\n";
135 $result = $contentManager->getContentPage($cid);
137 if (!($content_row = @mysql_fetch_assoc($result))) {
138 require(AT_INCLUDE_PATH.'header.inc.php');
139 $msg->printErrors('PAGE_NOT_FOUND');
140 require (AT_INCLUDE_PATH.'footer.inc.php');
144 $path = $contentManager->getContentPath($cid);
145 $content_test = $contentManager->getContentTestsAssoc($cid);
147 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
148 $course_base_href = 'get.php/';
150 $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
153 if ($content_row['content_path']) {
154 $content_base_href .= $content_row['content_path'].'/';
157 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
158 $content_base_href = 'get.php/';
160 $content_base_href = 'content/' . $_SESSION['course_id'] . '/';
164 if (($current_tab == 0) || ($_current_tab == 3)) {
165 if ($_POST['formatting'] == null){
166 // this is a fresh load from just logged in
167 if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 0) { // plain text in text area
168 $_POST['formatting'] = 0;
169 } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) { // html with text area
170 $_POST['formatting'] = 1;
171 } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) { // html with visual editor
172 $_POST['formatting'] = 3;
177 require(AT_INCLUDE_PATH.'header.inc.php');
179 if ($current_tab == 0 || $current_tab == 3)
182 if ($_POST['complexeditor'] == '1') {
185 load_editor($simple, false, "none");
188 // Generate the last content tool elements
189 //loading toolbar for insert discussion topic or web link into the content
190 if ($current_tab == 0){
191 if(authenticate(AT_PRIV_CONTENT,AT_PRIV_RETURN)){
192 $home_links = get_home_navigation(); //vengono lette le caratteristiche di ogni modulo attivato nella home page.
193 $main_links = get_main_navigation($current_page); //vengono lette le caratteristiche di ogni modulo attivo nel main navigation
195 $num = count($main_links); //necessario elminare il primo e l'utlimo elemento poichè sono rispettivamente "Home" e "Manage"
196 unset($main_links[0]); //"Home" label
197 unset($main_links[$num-1]); //"Manage" label
199 $all_tools = $home_links; //$all_tools represent a merge between $home_links and main_links without repetitions.
201 foreach($main_links as $main) {
202 foreach($home_links as $home) {
203 if($home['title'] == $main['title']) {
208 if(!$check && $main['tool_file'] != '' && $main['table'] != '') {
209 $_content_tools[] = array("class"=>"fl-col clickable tool",
212 "title"=>$main['title'],
213 "text"=>$main['title'],
214 "position"=>++$current_tool_pos);
216 if(isset($main['tool_file'])) {
217 echo '<!-- TODO LAW note problem here with one tool_file variable for multiple tools -->'."\n";
218 echo ' <script type="text/javascript" language="javascript">'."\n";
220 echo ' ATutor.mods.editor.tool_file = "'. $main['tool_file'].'";'."\n";
222 echo ' </script>'."\n";
233 // The customized function to sort multi-dimentional array $_content_tools
234 function compare($x, $y) {
235 if (!isset($x["position"])) return 1;
236 if (!isset($y["position"])) return -1;
237 if ( $x["position"] == $y["position"] )
239 else if ( $x["position"] < $y["position"] )
245 // Sort $_content_tools. Always append the element with empty "position" to the end of the result array.
246 usort($_content_tools, 'compare');
248 $cid = intval($_REQUEST['cid']);
249 $pid = intval($_REQUEST['pid']);
251 <form action="<?php echo $_SERVER['PHP_SELF']; ?>?cid=<?php echo $cid; ?>" method="post" name="form" enctype="multipart/form-data">
255 //$content_row = sql_quote($content_row);
256 if (isset($_POST['current_tab'])) {
257 //$changes_made = check_for_changes($content_row);
259 $changes_made = array();
261 $_POST['formatting'] = $content_row['formatting'];
262 $_POST['head'] = $content_row['head'];
263 $_POST['use_customized_head'] = $content_row['use_customized_head'];
264 $_POST['title'] = $content_row['title'];
265 $_POST['body_text'] = $content_row['text'];
266 $_POST['weblink_text'] = $content_row['text'];
267 $_POST['keywords'] = $content_row['keywords'];
268 $_POST['test_message'] = $content_row['test_message'];
269 $_POST['allow_test_export'] = $content_row['allow_test_export'];
271 $_POST['day'] = substr($content_row['release_date'], 8, 2);
272 $_POST['month'] = substr($content_row['release_date'], 5, 2);
273 $_POST['year'] = substr($content_row['release_date'], 0, 4);
274 $_POST['hour'] = substr($content_row['release_date'], 11, 2);
275 $_POST['min']= substr($content_row['release_date'], 14, 2);
277 $_POST['ordering'] = $content_row['ordering'];
278 $_POST['related'] = $contentManager->getRelatedContent($cid);
280 $_POST['pid'] = $pid = $content_row['content_parent_id'];
282 $_POST['related_term'] = $glossary_ids_related;
287 if (!isset($_POST['current_tab'])) {
288 $_POST['day'] = date('d');
289 $_POST['month'] = date('m');
290 $_POST['year'] = date('Y');
291 $_POST['hour'] = date('H');
294 if (isset($_GET['pid'])) {
295 $pid = $_POST['pid'] = intval($_GET['pid']);
296 $_POST['ordering'] = count($contentManager->getContent($pid))+1;
299 $_POST['ordering'] = count($contentManager->getContent(0))+1;
304 echo '<input type="hidden" name="cid" value="'.$cid.'" />';
305 echo '<input type="hidden" name="title" value="'.htmlspecialchars($stripslashes($_POST['title'])).'" />';
306 if ($_REQUEST['sub'] == 1)
308 echo '<input type="hidden" name="sub" value="1" />';
309 echo '<input type="hidden" name="folder_title" value="'.htmlspecialchars($stripslashes($_POST['folder_title'])).'" />';
311 echo '<input type="submit" name="submit" style="display:none;"/>';
312 if (($current_tab != 0) && (($_current_tab != 3))) {
313 echo '<input type="hidden" name="body_text" value="'.htmlspecialchars($stripslashes($_POST['body_text'])).'" />';
314 echo '<input type="hidden" name="weblink_text" value="'.htmlspecialchars($stripslashes($_POST['weblink_text'])).'" />';
315 echo '<input type="hidden" name="head" value="'.htmlspecialchars($stripslashes($_POST['head'])).'" />';
316 echo '<input type="hidden" name="use_customized_head" value="'.(($_POST['use_customized_head']=="") ? 0 : $_POST['use_customized_head']).'" />';
317 echo '<input type="hidden" name="displayhead" id="displayhead" value="'.$_POST['displayhead'].'" />';
318 echo '<input type="hidden" name="complexeditor" id="complexeditor" value="'.$_POST['complexeditor'].'" />';
319 echo '<input type="hidden" name="formatting" value="'.$_POST['formatting'].'" />';
322 echo '<input type="hidden" name="ordering" value="'.$_POST['ordering'].'" />';
323 echo '<input type="hidden" name="pid" value="'.$pid.'" />';
325 echo '<input type="hidden" name="day" value="'.$_POST['day'].'" />';
326 echo '<input type="hidden" name="month" value="'.$_POST['month'].'" />';
327 echo '<input type="hidden" name="year" value="'.$_POST['year'].'" />';
328 echo '<input type="hidden" name="hour" value="'.$_POST['hour'].'" />';
329 echo '<input type="hidden" name="minute" value="'.$_POST['minute'].'" />';
330 echo '<input type="hidden" name="min" value="'.$_POST['min'].'" />';
332 echo '<input type="hidden" name="alternatives" value="'.$_POST['alternatives'].'" />';
334 echo '<input type="hidden" name="current_tab" value="'.$current_tab.'" />';
336 if (is_array($_POST['related']) && ($current_tab != 1)) {
337 foreach($_POST['related'] as $r_id) {
338 echo '<input type="hidden" name="related[]" value="'.$r_id.'" />';
341 echo '<input type="hidden" name="keywords" value="'.htmlspecialchars(stripslashes($_POST['keywords'])).'" />';
343 //content test association
344 echo '<input type="hidden" name="test_message" value="'.$_POST['test_message'].'" />';
346 /* get glossary terms */
347 $matches = find_terms(stripslashes($_POST['body_text']));
348 $num_terms = count($matches[0]);
349 $matches = $matches[0];
350 $word = str_replace(array('[?]', '[/?]'), '', $matches);
352 if (is_array($word)) {
353 /* update $_POST['glossary_defs'] with any new/changed terms */
354 for($i=0; $i<$num_terms; $i++) {
355 // $word[$i] = htmlentities_utf8($word[$i]);
356 if (!isset($_POST['glossary_defs'][$word[$i]])) {
357 $_POST['glossary_defs'][$word[$i]] = $glossary[$word[$i]];
362 if (is_array($_POST['glossary_defs']) && ($current_tab != 2)) {
363 foreach($_POST['glossary_defs'] as $w => $d) {
365 /* this term still exists in the content */
366 if (!in_array($w, $word)) {
367 unset($_POST['glossary_defs'][$w]);
370 echo '<input type="hidden" name="glossary_defs['.AT_print($w, 'glossary.word').']" value="'.AT_print($d, 'glossary.definition').'" />';
372 if (isset($_POST['related_term'])) {
373 foreach($_POST['related_term'] as $w => $d) {
374 echo '<input type="hidden" name="related_term['.AT_print($w, 'glossary.word').']" value="'.AT_print($d, 'glossary.definition').'" />';
380 $sql = "SELECT pr.primary_resource_id, prt.type_id
381 FROM ".TABLE_PREFIX."primary_resources pr, ".
382 TABLE_PREFIX."primary_resources_types prt
383 WHERE pr.content_id = ".$cid."
384 AND pr.language_code = '".$_SESSION['lang']."'
385 AND pr.primary_resource_id = prt.primary_resource_id";
386 $all_types_result = mysql_query($sql, $db);
389 while ($type = mysql_fetch_assoc($all_types_result)) {
390 $row_alternatives['alt_'.$type['primary_resource_id'].'_'.$type['type_id']] = 1;
393 if ($current_tab != 3 && isset($_POST['use_post_for_alt']))
395 echo '<input type="hidden" name="use_post_for_alt" value="1" />';
396 if (is_array($_POST)) {
397 foreach ($_POST as $alt_id => $alt_value) {
398 if (substr($alt_id, 0 ,4) == 'alt_'){
399 echo '<input type="hidden" name="'.$alt_id.'" value="'.$alt_value.'" />';
406 if ($current_tab != 4){
407 // set content associated tests
408 if (is_array($_POST['tid'])) {
409 foreach ($_POST['tid'] as $i=>$tid){
410 echo '<input type="hidden" name="tid['.$i.']" value="'.$tid.'" />';
417 while ($content_test_row = mysql_fetch_assoc($content_test)){
418 echo '<input type="hidden" name="tid['.$i++.']" value="'.$content_test_row['test_id'].'" />';
424 if (is_array($_POST['pre_tid'])) {
425 foreach ($_POST['pre_tid'] as $i=>$pre_tid){
426 echo '<input type="hidden" name="pre_tid['.$i.']" value="'.$pre_tid.'" />';
432 $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$cid AND type='".CONTENT_PRE_TEST."'";
433 $pretests_result = mysql_query($sql, $db);
434 while ($pretest_row = mysql_fetch_assoc($pretests_result)) {
435 echo '<input type="hidden" name="pre_tid['.$i++.']" value="'.$pretest_row['item_id'].'" />';
439 if (!isset($_POST['allow_test_export']) && $current_tab != 4) {
440 //export flag handling.
441 $sql = "SELECT `allow_test_export` FROM ".TABLE_PREFIX."content WHERE content_id=$_REQUEST[cid]";
442 $result2 = mysql_query($sql, $db);
444 $c_row = mysql_fetch_assoc($result2);
446 if (intval($c_row['allow_test_export'])==1){
447 echo '<input type="hidden" name="allow_test_export" value="1" />';
449 echo '<input type="hidden" name="allow_test_export" value="0" />';
452 echo '<input type="hidden" name="allow_test_export" value="'.intval($_POST['allow_test_export']).'" />';
456 $changes_made = check_for_changes($content_row, $row_alternatives);
460 <div class="editor_wrapper">
463 <?php output_tabs($current_tab, $changes_made); ?>
466 <span style="clear:both;"/></span>
467 <div class="input-form">
469 <?php if ($changes_made): ?>
470 <div class="unsaved">
471 <span style="color:red;"><?php echo _AT('save_changes_unsaved'); ?></span>
472 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" title="<?php echo _AT('save_changes'); ?> alt-s" accesskey="s" style="border: 1px solid red;" />
473 <input type="submit" name="close" class="button green" value="<?php echo _AT('close'); ?>" /> <input type="checkbox" id="close" name="save_n_close" value="1" <?php if ($_SESSION['save_n_close']) { echo 'checked="checked"'; } ?> />
474 <label for="close"><?php echo _AT('close_after_saving'); ?></label>
479 <?php //if ($cid) { echo _AT('save_changes_saved'); } ?> <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" title="<?php echo _AT('save_changes'); ?> alt-s" accesskey="s" class="button"/> <input type="submit" name="close" value="<?php echo _AT('close'); ?>" class="button"/> <input type="checkbox" style="border:0px;" id="close" name="save_n_close" value="1" <?php if ($_SESSION['save_n_close']) { echo 'checked="checked"'; } ?>/><label for="close"><?php echo _AT('close_after_saving'); ?></label>
482 <?php include('editor_tabs/'.$tabs[$current_tab][1]); ?>
486 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>