fix bugs from merging atutor changes.
[acontent.git] / docs / home / editor / editor_tab_functions.inc.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
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 /************************************************************************/
12
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
14
15 function in_array_cin($strItem, $arItems)
16 {
17    foreach ($arItems as $key => $strValue)
18    {
19        if (strtoupper($strItem) == strtoupper($strValue))
20        {
21                    return $key;
22        }
23    }
24    return false;
25
26
27
28 function get_tabs() {
29         //these are the _AT(x) variable names and their include file
30         /* tabs[tab_id] = array(tab_name, file_name,                accesskey) */
31         $tabs[0] = array('content',                     'edit.inc.php',          'n');
32         $tabs[1] = array('metadata',                    'properties.inc.php',    'p');
33         $tabs[2] = array('alternative_content', 'alternatives.inc.php',  'l');  
34         $tabs[3] = array('tests',               'tests.inc.php',         't');  
35         
36         return $tabs;
37 }
38
39
40 function output_tabs($current_tab, $changes) {
41         global $_base_path;
42         $tabs = get_tabs();
43         $num_tabs = count($tabs);
44 ?>
45         <table class="etabbed-table" border="0" cellpadding="0" cellspacing="0" width="95%">
46         <tr>            
47                 <?php 
48                 for ($i=0; $i < $num_tabs; $i++): 
49                         if ($current_tab == $i):?>
50                                 <td class="editor_tab_selected">
51                                         <?php if ($changes[$i]): ?>
52                                                 <img src="<?php echo $_base_path; ?>images/changes_bullet.gif" alt="<?php echo _AT('usaved_changes_made'); ?>" height="12" width="15" />
53                                         <?php endif; ?>
54                                         <?php echo _AT($tabs[$i][0]); ?>
55                                 </td>
56                                 <td class="tab-spacer">&nbsp;</td>
57                         <?php else: ?>
58                                 <td class="editor_tab">
59                                         <?php if ($changes[$i]): ?>
60                                                 <img src="<?php echo $_base_path; ?>images/changes_bullet.gif" alt="<?php echo _AT('usaved_changes_made'); ?>" height="12" width="15" />
61                                         <?php endif; ?>
62
63                                         <?php echo '<input type="submit" name="button_'.$i.'" value="'._AT($tabs[$i][0]).'" title="'._AT($tabs[$i][0]).' - alt '.$tabs[$i][2].'" class="editor_buttontab" accesskey="'.$tabs[$i][2].'" onmouseover="this.style.cursor=\'pointer\';" '.$clickEvent.' />'; ?>
64                                 </td>
65                                 <td class="tab-spacer">&nbsp;</td>
66                         <?php endif; ?>
67                 <?php endfor; ?>
68                 <td >&nbsp;</td>
69         </tr>
70         </table>
71 <?php }
72 /**
73  * Strips all tags and encodes special characters in the URL
74  * Returns false if the URL is invalid
75  * 
76  * @param string $url
77  * @return mixed - returns a stripped and encoded URL or false if URL is invalid
78  */
79 function isValidURL($url) {
80     if (substr($url,0,4) === 'http') {
81         return filter_var(filter_var($url, FILTER_SANITIZE_STRING), FILTER_VALIDATE_URL);
82     }
83     return false;
84 }
85
86 /*
87  * Parse the primary resources out of the content and save into db.
88  * Clean up the removed primary resources from db.
89  * @param: $cid: content id
90  * @param: $content
91  * @return: none
92  */
93 function populate_a4a($cid, $content, $formatting){
94         global $db, $my_files;
95         
96     include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
97         include_once(TR_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php');        /* for XML_HTMLSax */
98         include_once(TR_INCLUDE_PATH.'classes/ContentOutputParser.class.php');  /* for parser */
99         
100         $body = ContentUtility::formatContent($content, $formatting);
101     
102         $handler = new ContentOutputParser();
103         $parser = new XML_HTMLSax();
104         $parser->set_object($handler);
105         $parser->set_element_handler('openHandler','closeHandler');
106         
107         $my_files               = array();
108         $parser->parse($body);
109         $my_files = array_unique($my_files);
110         
111         foreach ($my_files as $file) {
112                 /* filter out full urls */
113                 $url_parts = @parse_url($file);
114                 
115                 // file should be relative to content
116                 if ((substr($file, 0, 1) == '/')) {
117                         continue;
118                 }
119                 
120                 // The URL of the movie from youtube.com has been converted above in embed_media().
121                 // For example:  http://www.youtube.com/watch?v=a0ryB0m0MiM is converted to
122                 // http://www.youtube.com/v/a0ryB0m0MiM to make it playable. This creates the problem
123                 // that the parsed-out url (http://www.youtube.com/v/a0ryB0m0MiM) does not match with
124                 // the URL saved in content table (http://www.youtube.com/watch?v=a0ryB0m0MiM).
125                 // The code below is to convert the URL back to original.
126                 $file = ContentUtility::convertYoutubePlayURLToWatchURL($file);
127                 
128                 $resources[] = convertAmp($file);  // converts & to &amp;
129         }
130     
131     if (count($resources) == 0) return;
132
133     $a4a = new A4a($cid);
134     $db_primary_resources = $a4a->getPrimaryResources();
135     
136     // clean up the removed resources
137     foreach ($db_primary_resources  as $primary_rid=>$db_resource){
138         //if this file from our table is not found in the $resource, then it's not used.
139         if(in_array($db_resource['resource'], $resources)===false){
140             $a4a->deletePrimaryResource($primary_rid);
141         }
142     }
143
144         // insert the new resources
145     foreach($resources as $primary_resource)
146         {
147                 if (!is_array($a4a->getPrimaryResourceByName($primary_resource))){
148                         $a4a->setPrimaryResource($cid, $primary_resource, $_SESSION['lang']);
149                 }
150         }
151 }
152
153 // save all changes to the DB
154 function save_changes($redir, $current_tab) {
155         global $contentManager, $addslashes, $msg, $_course_id, $_content_id;
156         
157         $_POST['pid']   = intval($_POST['pid']);
158         $_POST['_cid']  = intval($_POST['_cid']);
159         
160         $_POST['alternatives'] = intval($_POST['alternatives']);
161         
162         $_POST['title'] = trim($_POST['title']);
163         $_POST['head']  = trim($_POST['head']);
164         $_POST['use_customized_head']   = isset($_POST['use_customized_head'])?$_POST['use_customized_head']:0;
165         $_POST['body_text']     = trim($_POST['body_text']);
166         $_POST['weblink_text'] = trim($_POST['weblink_text']);
167         $_POST['formatting'] = intval($_POST['formatting']);
168         $_POST['keywords']      = trim($_POST['keywords']);
169         $_POST['test_message'] = trim($_POST['test_message']);
170
171         //if weblink is selected, use it
172         if ($_POST['formatting']==CONTENT_TYPE_WEBLINK) {
173             $url = $_POST['weblink_text'];
174             $validated_url = isValidURL($url);
175         if (!validated_url || $validated_url !== $url) {
176                $msg->addError(array('INVALID_INPUT', _AT('weblink')));
177             } else {
178                     $_POST['body_text'] = $url;
179                     $content_type_pref = CONTENT_TYPE_WEBLINK;
180             }
181         } else {
182                 $content_type_pref = CONTENT_TYPE_CONTENT;
183         }
184
185         /*if (!($release_date = generate_release_date())) {
186                 $msg->addError('BAD_DATE');
187         }*/
188
189 //      if ($_POST['title'] == '') {
190 //              $msg->addError(array('EMPTY_FIELDS', _AT('title')));
191 //      }
192                 
193 //      if (!$msg->containsErrors()) {
194         $orig_body_text = $_POST['body_text'];  // used to populate a4a tables
195 //              $_POST['title']                 = $addslashes($_POST['title']);
196 //              $_POST['body_text']             = $addslashes($_POST['body_text']);
197 //              $_POST['head']                  = $addslashes($_POST['head']);
198 //              $_POST['keywords']              = $addslashes($_POST['keywords']);
199 //              $_POST['test_message']  = $addslashes($_POST['test_message']);          
200
201                 // add or edit content
202                 if ($_POST['_cid']) {
203                         /* editing an existing page */
204                         $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $_POST['body_text'], 
205                                                             $_POST['keywords'], $_POST['formatting'], 
206                                                             $_POST['head'], $_POST['use_customized_head'], 
207                                                             $_POST['test_message']);
208                         $cid = $_POST['_cid'];
209                 } else {
210                         /* insert new */
211                         $cid = $contentManager->addContent($_course_id,
212                                                                                                   $_POST['pid'],
213                                                                                                   $_POST['ordering'],
214                                                                                                   $_POST['title'],
215                                                                                                   $_POST['body_text'],
216                                                                                                   $_POST['keywords'],
217                                                                                                   $_POST['related'],
218                                                                                                   $_POST['formatting'],
219                                                                                                   $_POST['head'],
220                                                                                                   $_POST['use_customized_head'],
221                                                                                                   $_POST['test_message'],
222                                                                                                   $content_type_pref);
223                         $_POST['_cid']    = $cid;
224                         $_REQUEST['_cid'] = $cid;
225                 }
226         // re-populate a4a tables based on the new content
227                 populate_a4a($cid, $orig_body_text, $_POST['formatting']);
228                 if ($cid == 0) return;
229 //      }
230
231         /* insert glossary terms */
232         /*
233         if (is_array($_POST['glossary_defs']) && ($num_terms = count($_POST['glossary_defs']))) {
234                 global $glossary, $glossary_ids, $msg;
235
236                 foreach($_POST['glossary_defs'] as $w => $d) {
237                         $old_w = $w;
238                         $key = in_array_cin($w, $glossary_ids);
239                         $w = urldecode($w);
240                         $d = $addslashes($d);
241
242                         if (($key !== false) && (($glossary[$old_w] != $d) || isset($_POST['related_term'][$old_w])) ) {
243                                 $w = addslashes($w);
244                                 $related_id = intval($_POST['related_term'][$old_w]);
245                                 $sql = "UPDATE ".TABLE_PREFIX."glossary SET definition='$d', related_word_id=$related_id WHERE word_id=$key AND course_id=$_SESSION[course_id]";
246                                 $result = mysql_query($sql, $db);
247                                 $glossary[$old_w] = $d;
248                         } else if ($key === false && ($d != '')) {
249                                 $w = addslashes($w);
250                                 $related_id = intval($_POST['related_term'][$old_w]);
251                                 $sql = "INSERT INTO ".TABLE_PREFIX."glossary VALUES (NULL, $_SESSION[course_id], '$w', '$d', $related_id)";
252
253                                 $result = mysql_query($sql, $db);
254                                 $glossary[$old_w] = $d;
255                         }
256                 }
257         }*/
258         if (isset($_GET['tab'])) {
259                 $current_tab = intval($_GET['tab']);
260         }
261         if (isset($_POST['current_tab'])) {
262                 $current_tab = intval($_POST['current_tab']);
263         }
264
265         // adapted content: save primary content type
266         if (isset($_POST['use_post_for_alt']))
267         {
268                 include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
269                 $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
270                 
271                 // 1. delete old primary content type
272                 $sql = "DELETE FROM ".TABLE_PREFIX."primary_resources_types
273                          WHERE primary_resource_id in 
274                                (SELECT DISTINCT primary_resource_id 
275                                   FROM ".TABLE_PREFIX."primary_resources
276                                  WHERE content_id=".$cid."
277                                    AND language_code='".$_SESSION['lang']."')";
278                 $primaryResourcesTypesDAO->execute($sql);
279                 
280                 // 2. insert the new primary content type
281                 $sql = "SELECT pr.primary_resource_id, rt.type_id
282                           FROM ".TABLE_PREFIX."primary_resources pr, ".
283                                  TABLE_PREFIX."resource_types rt
284                          WHERE pr.content_id = ".$cid."
285                            AND pr.language_code = '".$_SESSION['lang']."'";
286                 $all_types_rows = $primaryResourcesTypesDAO->execute($sql);
287                 
288                 if (is_array($all_types_rows)) {
289                         foreach ($all_types_rows as $type) {
290                                 if (isset($_POST['alt_'.$type['primary_resource_id'].'_'.$type['type_id']]))
291                                 {
292                                         $primaryResourcesTypesDAO->Create($type['primary_resource_id'], $type['type_id']);
293 //                                      $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources_types (primary_resource_id, type_id)
294 //                                              VALUES (".$type['primary_resource_id'].", ".$type['type_id'].")";
295 //                                      $result = mysql_query($sql, $db);
296                                 }
297                         }
298                 }
299         }
300         
301         include_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
302         $contentTestsAssocDAO = new ContentTestsAssocDAO();
303         $test_rows = $contentTestsAssocDAO->getByContent($_POST['_cid']);
304 //      $sql = 'SELECT * FROM '.TABLE_PREFIX."content_tests_assoc WHERE content_id=$_POST[cid]";
305 //      $result = mysql_query($sql, $db);
306         $db_test_array = array();
307         if (is_array($test_rows)) {
308                 foreach ($test_rows as $row) {
309                         $db_test_array[] = $row['test_id'];
310                 }
311         }
312
313         if (is_array($_POST['tid']) && sizeof($_POST['tid']) > 0){
314                 $toBeDeleted = array_diff($db_test_array, $_POST['tid']);
315                 $toBeAdded = array_diff($_POST['tid'], $db_test_array);
316                 //Delete entries
317                 if (!empty($toBeDeleted)){
318                         $tids = implode(",", $toBeDeleted);
319                         $sql = 'DELETE FROM '. TABLE_PREFIX . "content_tests_assoc WHERE content_id=$_POST[cid] AND test_id IN ($tids)";
320                         $contentTestsAssocDAO->execute($sql);
321                 }
322         
323                 //Add entries
324                 if (!empty($toBeAdded)){
325                         foreach ($toBeAdded as $i => $tid){
326                                 $tid = intval($tid);
327 //                              $sql = 'INSERT INTO '. TABLE_PREFIX . "content_tests_assoc SET content_id=$_POST[cid], test_id=$tid";
328 //                              $result = mysql_query($sql, $db);
329                                 if ($contentTestsAssocDAO->Create($_POST['_cid'], $tid) === false){
330                                         $msg->addError('DB_NOT_UPDATED');
331                                 }
332                         }
333                 }
334         } else {
335                 //All tests has been removed.
336                 $contentTestsAssocDAO->DeleteByContentID($_POST['_cid']);
337 //              $sql = 'DELETE FROM '. TABLE_PREFIX . "content_tests_assoc WHERE content_id=$_POST[cid]";
338 //              $result = mysql_query($sql, $db);
339         }
340         //End Add test
341
342         //TODO*******************BOLOGNA****************REMOVE ME**************/
343 /*
344         if(isset($_SESSION['associated_forum']) && !$msg->containsErrors()){
345                 if($_SESSION['associated_forum']=='none'){
346                         $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
347                         mysql_query($sql,$db);
348                 } else {
349                         $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
350                         mysql_query($sql,$db);
351                         $associated_forum = $_SESSION['associated_forum'];
352                         for($i=0; $i<count($associated_forum); $i++){
353                                 $sql="INSERT INTO ".TABLE_PREFIX."content_forums_assoc SET content_id='$_POST[cid]',forum_id='$associated_forum[$i]'";
354                                 mysql_query($sql,$db);
355                         }
356                 }
357                 unset($_SESSION['associated_forum']);
358         }
359 */
360         if (!$msg->containsErrors() && $redir) {
361                 $_SESSION['save_n_close'] = $_POST['save_n_close'];
362                 
363                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
364                 header('Location: '.basename($_SERVER['PHP_SELF']).'?_cid='.$cid.SEP.'close='.$addslashes($_POST['save_n_close']).SEP.'tab='.$addslashes($_POST['current_tab']).SEP.'displayhead='.$addslashes($_POST['displayhead']).SEP.'alternatives='.$addslashes($_POST['alternatives']));
365                 exit;
366         } else {
367                 return;
368         }
369 }
370 /*
371 function generate_release_date($now = false) {
372         if ($now) {
373                 $day  = date('d');
374                 $month= date('m');
375                 $year = date('Y');
376                 $hour = date('H');
377                 $min  = 0;
378         } else {
379                 $day    = intval($_POST['day']);
380                 $month  = intval($_POST['month']);
381                 $year   = intval($_POST['year']);
382                 $hour   = intval($_POST['hour']);
383                 $min    = intval($_POST['min']);
384         }
385
386         if (!checkdate($month, $day, $year)) {
387                 return false;
388         }
389
390         if (strlen($month) == 1){
391                 $month = "0$month";
392         }
393         if (strlen($day) == 1){
394                 $day = "0$day";
395         }
396         if (strlen($hour) == 1){
397                 $hour = "0$hour";
398         }
399         if (strlen($min) == 1){
400                 $min = "0$min";
401         }
402         $release_date = "$year-$month-$day $hour:$min:00";
403         
404         return $release_date;
405 }
406 */
407 function check_for_changes($row, $row_alternatives) {
408         global $contentManager, $cid, $glossary, $glossary_ids_related, $addslashes;
409
410         $changes = array();
411
412         if ($row && strcmp(trim($addslashes($_POST['title'])), addslashes($row['title']))) {
413                 $changes[0] = true;
414         } else if (!$row && $_POST['title']) {
415                 $changes[0] = true;
416         }
417
418         if ($row && strcmp($addslashes(trim($_POST['head'])), trim(addslashes($row['head'])))) {
419                 $changes[0] = true;
420         } else if (!$row && $_POST['head']) {
421                 $changes[0] = true;
422         }
423
424         if ($row && strcmp($addslashes(trim($_POST['body_text'])), trim(addslashes($row['text'])))) {
425                 $changes[0] = true;
426         } else if (!$row && $_POST['body_text']) {
427                 $changes[0] = true;
428         }
429         
430     if ($row && strcmp($addslashes(trim($_POST['weblink_text'])), trim(addslashes($row['text'])))) {
431         $changes[0] = true;
432     } else if (!$row && $_POST['weblink_text']) {
433         $changes[0] = true;
434     }
435
436         /* use customized head: */
437         if ($row && isset($_POST['use_customized_head']) && ($_POST['use_customized_head'] != $row['use_customized_head'])) {
438                 $changes[0] = true;
439         }
440
441         /* formatting: */
442         if ($row && strcmp(trim($_POST['formatting']), $row['formatting'])) {
443                 $changes[0] = true;
444         } else if (!$row && $_POST['formatting']) {
445                 $changes[0] = true;
446         }
447
448         /* release date: */
449 //      if ($row && strcmp(substr(generate_release_date(), 0, -2), substr($row['release_date'], 0, -2))) {
450 //              /* the substr was added because sometimes the release_date in the db has the seconds field set, which we dont use */
451 //              /* so it would show a difference, even though it should actually be the same, so we ignore the seconds with the -2 */
452 //              /* the seconds gets added if the course was created during the installation process. */
453 //              $changes[1] = true;
454 //      } else if (!$row && strcmp(generate_release_date(), generate_release_date(true))) {
455 //              $changes[1] = true;
456 //      }
457
458         /* related content: */
459 //      $row_related = $contentManager->getRelatedContent($cid);
460 //
461 //      if (is_array($_POST['related']) && is_array($row_related)) {
462 //              $sum = array_sum(array_diff($_POST['related'], $row_related));
463 //              $sum += array_sum(array_diff($row_related, $_POST['related']));
464 //              if ($sum > 0) {
465 //                      $changes[1] = true;
466 //              }
467 //      } else if (!is_array($_POST['related']) && !empty($row_related)) {
468 //              $changes[1] = true;
469 //      }
470
471         /* keywords */
472         if ($row && strcmp(trim($_POST['keywords']), $row['keywords'])) {
473                 $changes[1] = true;
474         }  else if (!$row && $_POST['keywords']) {
475                 $changes[1] = true;
476         }
477
478
479         /* glossary */
480 //      if (is_array($_POST['glossary_defs'])) {
481 //              global $glossary_ids;
482 //              foreach ($_POST['glossary_defs'] as $w => $d) {
483 //
484 //                      $key = in_array_cin($w, $glossary_ids);
485 //                      if ($key === false) {
486 //                              /* new term */
487 //                              $changes[2] = true;
488 //                              break;
489 //                      } else if ($cid && ($d &&($d != $glossary[$glossary_ids[$key]]))) {
490 //                              /* changed term */
491 //                              $changes[2] = true;
492 //                              break;
493 //                      }
494 //              }
495 //
496 //              if (is_array($_POST['related_term'])) {
497 //                      foreach($_POST['related_term'] as $term => $r_id) {
498 //                              if ($glossary_ids_related[$term] != $r_id) {
499 //                                      $changes[2] = true;
500 //                                      break;
501 //                              }
502 //                      }
503 //              }
504 //      }
505
506         /* adapted content */
507         if (isset($_POST['use_post_for_alt']))
508         {
509                 foreach ($_POST as $alt_id => $alt_value) {
510                         if (substr($alt_id, 0 ,4) == 'alt_' && $alt_value != $row_alternatives[$alt_id]){
511                                 $changes[2] = true;
512                                 break;
513                         }
514                 }
515         }
516         
517         /* test & survey */     
518         if ($row && isset($_POST['test_message']) && $_POST['test_message'] != $row['test_message']){
519                 $changes[3] = true;
520         }
521         
522         $content_tests = $contentManager->getContentTestsAssoc($cid);
523         
524         if (isset($_POST['visited_tests'])) {
525                 if (!is_array($content_tests) && is_array($_POST['tid'])) {
526                         $changes[3] = true;
527                 }
528                 if (is_array($content_tests)) {
529                         for ($i = 0; $i < count($content_tests); $i++) {
530                                 if ($content_tests[$i]['test_id'] <> $_POST['tid'][$i]) {
531                                         $changes[3] = true;
532                                         break;
533                                 }
534                         }
535                 }
536         }
537
538         return $changes;
539 }
540
541 function paste_from_file() {
542         global $msg;
543         
544         include_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
545         if ($_FILES['uploadedfile_paste']['name'] == '')        {
546                 $msg->addError('FILE_NOT_SELECTED');
547                 return;
548         }
549         if ($_FILES['uploadedfile_paste']['name']
550                 && (($_FILES['uploadedfile_paste']['type'] == 'text/plain')
551                         || ($_FILES['uploadedfile_paste']['type'] == 'text/html')) )
552                 {
553
554                 $path_parts = pathinfo($_FILES['uploadedfile_paste']['name']);
555                 $ext = strtolower($path_parts['extension']);
556
557                 if (in_array($ext, array('html', 'htm'))) {
558                         $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
559
560                         /* get the <title></title> of this page                         */
561
562                         $start_pos      = strpos(strtolower($_POST['body_text']), '<title>');
563                         $end_pos        = strpos(strtolower($_POST['body_text']), '</title>');
564
565                         if (($start_pos !== false) && ($end_pos !== false)) {
566                                 $start_pos += strlen('<title>');
567                                 $_POST['title'] = trim(substr($_POST['body_text'], $start_pos, $end_pos-$start_pos));
568                         }
569                         unset($start_pos);
570                         unset($end_pos);
571
572                         $_POST['head'] = ContentUtility::getHtmlHeadByTag($_POST['body_text'], array("link", "style", "script")); 
573                         if (strlen(trim($_POST['head'])) > 0)   
574                                 $_POST['use_customized_head'] = 1;
575                         else
576                                 $_POST['use_customized_head'] = 0;
577                         
578                         $_POST['body_text'] = ContentUtility::getHtmlBody($_POST['body_text']); 
579
580                         $msg->addFeedback('FILE_PASTED');
581                 } else if ($ext == 'txt') {
582                         $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
583                         //LAW
584 //                      debug($_POST);
585                         $msg->addFeedback('FILE_PASTED');
586
587                 }
588         } else {
589                 $msg->addError('BAD_FILE_TYPE');
590         }
591
592         return;
593 }
594
595 //for accessibility checker
596 function write_temp_file() {
597         global $_POST, $msg;
598
599         if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
600                 $content_base = 'get.php/';
601         } else {
602                 $content_base = 'content/' . $_SESSION['course_id'] . '/';
603         }
604
605         if ($_POST['content_path']) {
606                 $content_base .= $_POST['content_path'] . '/';
607         }
608
609         $file_name = $_POST['_cid'].'.html';
610
611         if ($handle = fopen(TR_CONTENT_DIR . $file_name, 'wb+')) {
612 //              $temp_content = '<h2>'.TR_print(stripslashes($_POST['title']), 'content.title').'</h2>';
613 //
614 //              if ($_POST['body_text'] != '') {
615 //                      $temp_content .= format_content(stripslashes($_POST['body_text']), $_POST['formatting'], $_POST['glossary_defs']);
616 //              }
617 //              $temp_title = $_POST['title'];
618 //
619 //              $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
620 //                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
621 //              <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
622 //              <head>
623 //                      <base href="{BASE_HREF}" />
624 //                      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
625 //                      <title>{TITLE}</title>
626 //                      <meta name="Generator" content="ATutor accessibility checker file - can be deleted">
627 //              </head>
628 //              <body>
629 //              {CONTENT}
630 //              </body>
631 //              </html>';
632 //
633 //              $page_html = str_replace(       array('{BASE_HREF}', '{TITLE}', '{CONTENT}'),
634 //                                                                      array($content_base, $temp_title, $temp_content),
635 //                                                                      $html_template);
636                 
637                 if (!@fwrite($handle, stripslashes($_POST['body_text']))) {
638                         $msg->addError('FILE_NOT_SAVED');       
639            }
640         } else {
641                 $msg->addError('FILE_NOT_SAVED');
642         }
643         $msg->printErrors();
644 }
645 ?>