AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / home / imscc / include / ims_template.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 // This function gets files from html tag @import
16 function get_import_files($text)
17 {
18         $text = strtolower($text);
19         $tag = '@import';
20         $files = array();
21         
22         while (strpos(strtolower($text), strtolower($tag)) > 0)
23         {
24                 $start_pos      = strpos($text, $tag);
25                 if ($start_pos !== false) 
26                 {
27                         $text = substr($text, $start_pos);
28                         $start_pos = strlen($tag);
29                         $len = strpos($text, ';') - strlen($tag);
30                         
31                         $file = substr(trim($text), $start_pos, $len);
32                         
33                         // remove these characters from file name: url, (, ), ", '
34                         $file = trim(preg_replace('/(\'|\"|url|\(|\))/', '', $file));
35                         
36                         // strip processed tag
37                         $text = substr($text, $start_pos);
38                         array_push($files, $file);
39                 }
40         
41         }
42         
43         return $files;
44 }
45         
46 function print_organizations($parent_id,
47                                                          &$_menu, 
48                                                          $depth, 
49                                                          $path='',
50                                                          $children,
51                                                          &$string) {
52         
53         global $html_content_template, $default_html_style, $zipfile, $resources, $ims_template_xml, $parser, $my_files;
54         global $used_glossary_terms, $course_id, $course_language_charset, $course_language_code;
55         static $paths, $zipped_files;
56 //      global $glossary;
57         global $test_list, $test_zipped_files, $test_files, $test_xml_items, $use_a4a;
58         global $contentManager;
59         /* added by bologna*///TODO***********BOLOGNA**************REMOVE ME*****************/
60         global $db,$forum_list;//forum_list contiene tutti i forum distinti associati ai contenuti. poich� la funzione in questione � ricorsiva deve essere globale in modo che in fase di creazione dell'archivio zip i file descrittori dei forum non vengano ripetuti
61
62         require_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
63         require_once(TR_INCLUDE_PATH.'classes/DAO/ContentForumsAssocDAO.class.php');
64         
65         $space  = '    ';
66         $prefix = '                    ';
67
68         if ($depth == 0) {
69                 $string .= '<ul>';
70         }
71         $top_level = $_menu[$parent_id];
72         if (!is_array($paths)) {
73                 $paths = array();
74         }
75         if (!is_array($zipped_files)) {
76                 $zipped_files = array();
77         }
78         if ( is_array($top_level) ) {
79                 
80                 $counter = 1;
81                 $num_items = count($top_level);
82                 
83                 foreach ($top_level as $garbage => $content) {
84                         $link = '';
85                         //XSL characters handling
86                         $content['title'] = str_replace('&', '&amp;', $content['title']);
87                                 
88                         if ($content['content_path'] && (substr($content['content_path'],-1)!='/')) {
89                                 $content['content_path'] .= '/';
90                         }
91
92                         /* 
93                          * generate weblinks 
94                          * Reason to put it here is cause we don't want the content to be overwrittened.
95                          */
96                         if ($content['content_type']==CONTENT_TYPE_WEBLINK){
97                                 $wl = new Weblinks($content['title'], $content['text']);
98                                 $wlexport = new WeblinksExport($wl);
99                                 $wl_xml = $wlexport->export();
100                                 $wl_filename = 'weblinks_'.$content['content_id'].'.xml';
101                                 $zipfile->add_file($wl_xml , 'Weblinks/'.$wl_filename, $content['u_ts']);
102                                 $resources .= str_replace(      array('{PATH}', '{CONTENT_ID}'), 
103                                                                                         array($wl_filename, $content['content_id']), 
104                                                                                         $ims_template_xml['resource_weblink']);
105                                 //Done.
106 //                              continue;
107                         }
108
109                         if ($content['content_type']==CONTENT_TYPE_FOLDER){
110                                 $link .= $prefix.'<item identifier="MANIFEST01_FOLDER'.$content['content_id'].'">'."\n";
111                                 $link .= $prefix.$space.'<title>'.$content['title'].'</title>'."\n";
112                         } else {
113                                 $link .= '<item identifier="MANIFEST01_ITEM'.$content['content_id'].'" identifierref="MANIFEST01_RESOURCE'.$content['content_id'].'">'."\n";
114                                 $link .= $prefix.$space.'<title>'.$content['title'].'</title>'."\n$prefix$space";
115                         }
116                         $html_link = '<a href="resources/'.$content['content_path'].$content['content_id'].'.html" target="body">'.$content['title'].'</a>';
117                         
118                         /* save the content as HTML files */
119                         $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']);
120                         /* Commented by Cindy Qi Li on Jan 12, 2010
121                          * AContent does not support glossary
122                         // get all the glossary terms used
123                         $terms = find_terms($content['text']);
124                         if (is_array($terms)) {
125                                 foreach ($terms[2] as $term) {
126                                         $used_glossary_terms[] = $term;
127                                 }
128                         }
129 */
130                         $f_count = count($forum_list); //count all distinct forum_id associated to a content page
131                                                 //la funzione è ricorsiva quindi lo devo ricavare attraverso la variabile globale forum_list
132
133                         $contentForumsAssocDAO = new ContentForumsAssocDAO();
134                         $forums = $contentForumsAssocDAO->getByContent($content[content_id]);
135 //                    $sql = "SELECT cf.forum_id, f.title, f.description FROM (SELECT * FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id=$content[content_id]) AS cf LEFT JOIN ".TABLE_PREFIX."forums f ON cf.forum_id=f.forum_id";
136 //                    $result_cf = mysql_query($sql,$db);
137    
138                         $find=false;
139                         $forums_dependency='';  //template for associate Discussion Topic to the current content into the manifest
140                         if (is_array($forums)) {
141                                 foreach($forums as $current_forum) {
142                                         for($j=0;$j<$f_count;$j++) {
143                                                 if($forum_list[$j]['id'] == $current_forum['forum_id']) $find= true;
144                                         }
145                                         if(!$find) {
146                                                 $forum_list[$f_count]['id']=$current_forum['forum_id'];
147                                                 $forum_list[$f_count]['title']=$current_forum['title'];
148                                                 $forum_list[$f_count]['description']=$current_forum['description'];
149                                                 $find=false;
150                                                 $f_count++;
151                                         }
152                                 }
153                                 $forums_dependency .= $prefix.$space.'<dependency identifierref="Forum'.$current_forum['forum_id'].'_R" />';
154             }
155
156                          /** Test dependency **/
157                         require_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
158                         $contentTestsAssocDAO = new ContentTestsAssocDAO();
159                         
160 //                      $sql = 'SELECT * FROM '.TABLE_PREFIX.'content_tests_assoc WHERE content_id='.$content['content_id'];
161 //                      $result = mysql_query($sql, $db);
162 //                      while ($row = mysql_fetch_assoc($result)){
163                         $rows = $contentTestsAssocDAO->getByContent($content['content_id']);
164                         if (is_array($rows)) {
165                                 //add test dependency on top of forum dependency
166                                 foreach ($rows as $row)
167                                         $forums_dependency .= $prefix.$space.'<dependency identifierref="MANIFEST01_RESOURCE_QTI'.$row['test_id'].'" />';
168                         }
169
170
171                         /* calculate how deep this page is: */
172                         $path = '../';
173                         if ($content['content_path']) {
174                                 $depth = substr_count($content['content_path'], '/');
175
176                                 $path .= str_repeat('../', $depth);
177                         }
178
179                         $content['text'] = ContentUtility::formatContent($content['text'], $content['formatting']);
180                         // add HTML header and footers to the files
181                         // use default style if <style> is not in imported html head
182                         $head = '';
183                         if ($content['use_customized_head'])
184                         {
185                                 if (strpos(strtolower($content['head']), '<style') > 0)
186                                 {
187                                         $head = $content['head'];
188                                 }
189                                 else
190                                 {
191                                         if (strlen($content['head']) > 0)  
192                                                 $head = $content['head'] . $default_html_style;
193                                         else 
194                                                 $head = $default_html_style;
195                                 }
196                         }
197
198                         $content['text'] = str_replace( array('{TITLE}',        '{CONTENT}', '{KEYWORDS}', '{COURSE_PRIMARY_LANGUAGE_CHARSET}', '{COURSE_PRIMARY_LANGUAGE_CODE}', '{HEAD}'),
199                                                                         array($content['title'],        $content['text'], $content['keywords'], $course_language_charset, $course_language_code, $head),
200                                                                         $html_content_template);
201                                                                 
202                         /* duplicate the paths in the content_path field in the zip file */
203                         if ($content['content_path']) {
204                                 if (!in_array($content['content_path'], $paths)) {
205                                         $zipfile->create_dir('resources/'.$content['content_path'], time());
206                                         $paths[] = $content['content_path'];
207                                 }
208                         }
209                         //add the file iff it's a content file
210                         if($content['content_type']==CONTENT_TYPE_CONTENT){
211                                 $zipfile->add_file($content['text'], 'resources/'.$content['content_path'].$content['content_id'].'.html', $content['u_ts']);
212                         }
213                         $content['title'] = htmlspecialchars($content['title']);
214
215                         /* add the resource dependancies */                     
216                         if ($my_files == null) $my_files = array();
217                         $content_files = "\n";
218                         $parser->parse($content['text']);
219
220                         /* generate the IMS QTI resource and files */
221                         //check if test export is allowed.
222                         $content_test_rs = $contentManager->getContentTestsAssoc($content['content_id']);       
223                         $test_ids = array();            //reset test ids
224                         //$my_files = array();          //reset myfiles.
225                         if (is_array($content_test_rs)) {
226                                 foreach ($content_test_rs as $content_test_row){
227                                         //export
228                                         $test_ids[] = $content_test_row['test_id'];
229                                         //the 'added_files' is for adding into the manifest file in this zip
230                                         $added_files = test_qti_export($content_test_row['test_id'], '', $zipfile);
231                                         foreach($added_files as $xml_file=>$chunk){
232                                                 foreach ($chunk as $xml_filename){
233                                                         $added_files_xml .= str_replace('{FILE}', 'resources/'.$xml_filename, $ims_template_xml['xml']);
234                                                 }
235                                         }
236                                         //Save all the xml files in this array, and then print_organizations will add it to the manifest file.
237                                         $resources .= str_replace(      array('{TEST_ID}', '{PATH}', '{FILES}'),
238                                                                                                 array($content_test_row['test_id'], 'tests_'.$content_test_row['test_id'].'.xml', $added_files_xml),
239                                                                                                 $ims_template_xml['resource_test']); 
240 /*      Taken out since we are gonna use dependency instead
241                                         $test_xml_items .= str_replace( array('{TEST_ID}'),
242                                                                                                 array($content_test_row['test_id']),
243                                                                                                 $ims_template_xml['test']); 
244 */
245                                         foreach($test_files as $filename=>$realfilepath){
246                                                 $zipfile->add_file(@file_get_contents($realfilepath), 'resources/'.$filename, filemtime($realfilepath));
247                                         }
248                                 }
249                         }
250
251                         /* generate the a4a files */
252                         $a4a_xml_array = array();
253             //http://atutor.ca/atutor/mantis/view.php?id=4593
254             if ($content['formatting']===0){
255                 $use_a4a = false;
256             }
257                         if ($use_a4a == true){
258                                 $a4aExport = new A4aExport($content['content_id']);
259 //                              $a4aExport->setRelativePath('resources/'.$content['content_path']);
260                                 $secondary_files = $a4aExport->getAllSecondaryFiles();
261                                 $a4a_xml_array = $a4aExport->exportA4a();
262                                 $my_files = array_merge($my_files, $a4aExport->getAllSecondaryFiles());
263                         }
264
265                         /* handle @import */
266                         $import_files = get_import_files($content['text']);
267
268                         if (count($import_files) > 0) $my_files = array_merge($my_files, $import_files);
269
270                         foreach ($my_files as $file) {
271                                 /* filter out full urls */
272                                 $url_parts = @parse_url($file);
273 //                              if (isset($url_parts['scheme'])) {
274 //                                      continue;
275 //                              }
276
277                                 /* file should be relative to content. let's double check */
278                                 if ((substr($file, 0, 1) == '/')) {
279                                         continue;
280                                 }
281
282
283                                 if (substr($file, 0, 7) != 'http://' && substr($file, 0, 8) != 'https://') {
284                                         $file_path = realpath(TR_CONTENT_DIR . $course_id . '/' . $content['content_path'] . $file);
285         
286                                         /* check if the path contains TR_CONTENT_DIR in it, if not, skip it, it's trying to scan through 
287                                          * the file system */
288                                         if (strpos($file_path, TR_CONTENT_DIR)!==0){
289                                                 continue; //skip
290                                         }
291                      
292                                         /* check if this file exists in the content dir, if not don't include it */
293                                         if (file_exists($file_path) &&  is_file($file_path) && !in_array($file_path, $zipped_files)) {
294                                                 $zipped_files[] = $file_path;
295                                                 $dir = substr(dirname($file_path), strlen(TR_CONTENT_DIR . $course_id));
296         
297                                                 if (!in_array($dir, $paths) && $dir) {
298                                                         $dir = str_replace('\\', '/', substr($dir, 1));
299                                                         $zipfile->create_dir('resources/' . $dir, time());
300                                                         
301                                                         $paths[] = $dir;
302                                                 }
303         
304                                                 $file_info = stat( $file_path );
305         
306                                                 //remove relative path in the content_path.     
307                                                 $filepath_array = explode('/', 'resources/' . $content['content_path'] . $file);
308                                                 $new_filepath_array = array();
309                                                 if (in_array('..', $filepath_array)){
310                                                         while (!empty($filepath_array)){
311                                                                 $temp = array_shift($filepath_array);
312                                                                 if ($temp == '..'){
313                                                                         array_pop($new_filepath_array);
314                                                                 } else {
315                                                                         array_push($new_filepath_array, $temp);
316                                                                 }
317                                                         }
318                                                         $zip_path = implode('/', $new_filepath_array);
319                                                 } else {
320                                                         $zip_path = 'resources/' . $content['content_path'] . $file;
321                                                 }
322         
323                                                 $zipfile->add_file(@file_get_contents($file_path), $zip_path, $file_info['mtime']);
324                                         }
325                                 }
326                                 //a4a secondary files have mapping, save the ones that we want in order to add the tag in
327                                 $a4a_secondary_files = array();
328                                 foreach ($a4a_xml_array as $a4a_filename=>$a4a_filearray){
329                                         if (preg_match('/(.*)\sto\s(.*)/', $a4a_filename, $matches)){
330                                                 //save the actual file name
331                                                 $a4a_secondary_files[$matches[1]][] = $a4a_filename;    //values are holders
332                                         }
333                                 }
334
335                 /**
336                  * A hack to fix youtube links.  one uses youtube.com?watch=xxx, the other uses youtube.com/v/xxx,
337                  * in which both points to the same file, but needed different links to play.
338                  * in A4a, these youtube links are always stored as "?watch=xxx", however, output.inc.php converted
339                  * these to /v/xxx for rendering purposes.  Convert it back if youtube exists in url.
340                  * http://atutor.ca/atutor/mantis/view.php?id=4548
341                  * @harris 9/30/2010
342                  */
343                 if (strpos($file, 'youtube.com')!==false){
344                     //apply the conversion before linking the alternatives. Otherwise it will not be added.
345                     $file = ContentUtility::convertYoutubePlayURLToWatchURL($file);
346                 }
347                                 // If this file has a4a alternatives, link it.
348                                 if (isset($a4a_xml_array[$file]) || isset($a4a_secondary_files[$file])){
349                                         //if this is an array, meaning that it has more than 1 alternatives, print all
350                                         if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
351                                                 $name_in_file_meta = $file;
352                                         } else {
353                                                 $name_in_file_meta = 'resources/'.$content['content_path'] . $file;
354                                         }
355                                         if (is_array($a4a_secondary_files[$file])){
356                                                 $all_secondary_files_md = '';   //reinitialize string to null
357                                                 foreach ($a4a_secondary_files[$file] as $v){
358                                                         foreach($a4a_xml_array[$v] as $v2){
359                                                                 $all_secondary_files_md .= $v2; //all the meta data             
360                                                         }                                                               
361                                                 }
362                                                 $content_files .= str_replace(  array('{FILE}', '{FILE_META_DATA}'), 
363                                                 array($name_in_file_meta, $all_secondary_files_md), 
364                                                 $ims_template_xml['file_meta']);
365                                         } else {
366                                                 $content_files .= str_replace(  array('{FILE}', '{FILE_META_DATA}'), 
367                                                 array($name_in_file_meta, $a4a_xml_array[$file]), 
368                                                 $ims_template_xml['file_meta']);
369                                         }
370                                 } else {
371                                         //if this file is in the test array, add an extra link to the direct file, 
372                                         if (!empty($test_zipped_files) && in_array($file_path, $test_zipped_files)){
373                                                 $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);
374                                         } else {
375                                                 if (preg_match('/^http[s]?\:/', $file) == 1){
376                                                         $content_files .= str_replace('{FILE}', $file, $ims_template_xml['xml']);
377                                                 } elseif (file_exists($file_path) && is_file($file_path)) {
378                                                         //relative link that goes beyond get.php shouldn't be added
379                                                         //relative link that does not exist shouldn't be added.
380                                                         $filepath_array = explode('/', $content['content_path'] . $file);
381                                                     $new_filepath_array = array();
382                                                     if (in_array('..', $filepath_array)){
383                                                             while (!empty($filepath_array)){
384                                                                     $temp = array_shift($filepath_array);
385                                                                     if ($temp == '..'){
386                                                                             array_pop($new_filepath_array);
387                                                                     } else {
388                                                                             array_push($new_filepath_array, $temp);
389                                                                     }
390                                                             }
391                                                             $file = implode('/', $new_filepath_array);
392                                                     } else {
393                                                         $file = $content['content_path'] . $file;
394                             }
395                                                         $content_files .= str_replace('{FILE}', $file, $ims_template_xml['file']);                                                      
396                                                 }
397                                         }
398                                 }
399                                 /* check if this file is one of the test xml file, if so, we need to add the dependency
400                                  * Note:  The file has already been added to the archieve before this is called.
401                                  */
402                                 if (preg_match('/tests\_[0-9]+\.xml$/', $file) && !in_array($file, $test_zipped_files)){
403                                         $content_files .= str_replace('{FILE}', 'QTI/'.$file, $ims_template_xml['xml']);
404                                         $test_zipped_files[] = $file;
405                                 }
406                         }
407                         
408                         /******************************
409                          * http://www.atutor.ca/atutor/mantis/view.php?id=4383 
410                      */
411                         $my_files = array();
412                         
413                         /******************************/
414                         //add it to the resources section if it hasn't been added.  
415                         //Weblinks have been added.
416                         //Folders aren't resourecs, they shouldn't be added
417                         if($content['content_type']==CONTENT_TYPE_CONTENT){
418                                 $resources .= str_replace(      array('{CONTENT_ID}', '{PATH}', '{FILES}','{DEPENDENCY}'),
419                                                                                         array($content['content_id'], $content['content_path'], $content_files, $forums_dependency),
420                                                                                         $ims_template_xml['resource']); 
421                         }
422                         
423
424                         for ($i=0; $i<$depth; $i++) {
425                                 $link .= $space;
426                         }
427
428                         if ( is_array($_menu[$content['content_id']]) ) {
429                                 /* has children */
430
431                                 $html_link = '<li>'.$html_link.'<ul>';
432                                 for ($i=0; $i<$depth; $i++) {
433                                         if ($children[$i] == 1) {
434                                                 echo $space;
435                                                 //$html_link = $space.$html_link;
436                                         } else {
437                                                 echo $space;
438                                                 //$html_link = $space.$html_link;
439                                         }
440                                 }
441
442                         } else {
443                                 /* doesn't have children */
444
445                                 $html_link = '<li>'.$html_link.'</li>';
446                                 if ($counter == $num_items) {
447                                         for ($i=0; $i<$depth; $i++) {
448                                                 if ($children[$i] == 1) {
449                                                         echo $space;
450                                                         //$html_link = $space.$html_link;
451                                                 } else {
452                                                         echo $space;
453                                                         //$html_link = $space.$html_link;
454                                                 }
455                                         }
456                                 } else {
457                                         for ($i=0; $i<$depth; $i++) {
458                                                 echo $space;
459                                                 //$html_link = $space.$html_link;
460                                         }
461                                 }
462                                 $title = $space.$title;
463                         }
464
465                         echo $prefix.$link;
466 //                      echo $title;
467                         echo "\n";
468
469                         $string .= $html_link."\n";
470
471                         $depth ++;
472                         print_organizations($content['content_id'],
473                                                                 $_menu, 
474                                                                 $depth, 
475                                                                 $path.$counter.'.', 
476                                                                 $children,
477                                                                 $string);
478                         $depth--;
479
480                         $counter++;
481                         for ($i=0; $i<$depth; $i++) {
482                                 echo $space;
483                         }
484
485 //                      if (!empty($_menu[$content['content_id']])){
486                         echo $prefix.'</item>';
487 //                      }
488                         echo "\n";
489                 }  
490
491                 $string .= '</ul>';
492                 if ($depth > 0) {
493                         $string .= '</li>';
494                 }
495
496         }
497 }
498
499
500 //TODO***************BOLOGNA******************REMOVE ME***************/
501 /* Export Forum */
502 function print_resources_forum() {
503
504     global $forum_list, $zipfile, $resources;           //$forum_list contiene tutti i forum DISTINTI associati ai contenuti. caricato in print_organizations()
505
506     $ims_template_xml['resource_forum'] =
507
508         '<resource identifier="Forum{FORUMID}_R" type="imsdt_xmlv1p0">
509             <metadata/>
510             <file href="Forum{FORUMID}/FileDescriptorForum{FORUMID}.xml"/>
511         </resource>
512         '."\n";
513
514     if (is_array($forum_list)) {
515             foreach ($forum_list as $f){
516             // per ogni forum associato ad uno o pi� contenuti del corso viene aggiunto un elemento resource in imsmanifest.xml
517                 $resources .= str_replace("{FORUMID}", $f['id'], $ims_template_xml['resource_forum']);
518         
519                 //viene generato il file descrittore
520                 //file Descrittore con la descrzione del forum
521            /*     $fileDesDT_D = '<?xml version="1.0" encoding="UTF-8"?>
522         
523                             <topic
524                             xmlns="http://www.imsglobal.org/xsd/imsdt_v1p0"
525                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsdt_v1p0 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_6/imsdt_v1p0_localised.xsd">
526         
527                                 <title>{TitleDiscussionTopic}</title>
528         
529                                 <text texttype="text/plain">{DescriptionDiscussionTopic}</text>
530         
531                             </topic>';
532         
533                 //file Descrittore senza la descrizione del forum
534                 $fileDesDT = '<?xml version="1.0" encoding="UTF-8"?>
535         
536                             <topic
537                             xmlns="http://www.imsglobal.org/xsd/imsdt_v1p0"
538                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsdt_v1p0 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_6/imsdt_v1p0_localised.xsd">
539         
540                                 <title>{TitleDiscussionTopic}</title>
541         
542                                 <text/>
543         
544                             </topic>'; */
545                 $fileDesDT_D = '<?xml version="1.0" encoding="UTF-8"?>
546
547 <dt:topic xmlns:dt="http://www.imsglobal.org/xsd/imsdt_v1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsdt_v1p0 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_6/imsdt_v1p0_localised.xsd">
548 <title>{TitleDiscussionTopic}</title>
549 <text texttype="text/plain">{DescriptionDiscussionTopic}</text>
550 </dt:topic>';
551
552         //file Descrittore senza la descrizione del forum
553         $fileDesDT = '<?xml version="1.0" encoding="UTF-8"?>
554 <dt:topic xmlns:dt="http://www.imsglobal.org/xsd/imsdt_v1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsdt_v1p0 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_6/imsdt_v1p0_localised.xsd">
555 <title>{TitleDiscussionTopic}</title>
556 <text/>
557 </dt:topic>';
558                         $f['title'] = htmlspecialchars($f['title']);
559                         $f['description'] = htmlspecialchars($f['description']);
560                 if (empty($f['description']))
561                     $text_file_des_xml = str_replace (array('{TitleDiscussionTopic}', '{DescriptionDiscussionTopic}'), array($f['title'], $f['description']), $fileDesDT);
562                 else
563                     $text_file_des_xml = str_replace (array('{TitleDiscussionTopic}', '{DescriptionDiscussionTopic}'), array($f['title'], $f['description']), $fileDesDT_D);
564         
565                 $zipfile->add_file($text_file_des_xml,  'Forum'.$f['id'].'/'.'FileDescriptorForum'.$f['id'].'.xml');
566             }
567     }
568     //$zipfile->add_file(file_get_contents('../../images/home-forums_sm.png'),  'resources/home-forums_sm.png');
569 }
570
571
572 $ims_template_xml['header'] = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
573 <!--This is an AContent IMS Common Cartridge 1.0 document-->
574 <!--Created from the AContent Content Package Generator - http://www.atutor.ca-->
575 <manifest identifier="MANIFEST-'.md5($cid).'" 
576 xmlns="http://www.imsglobal.org/xsd/imscc/imscp_v1p1" 
577 xmlns:imsmd="http://ltsc.ieee.org/xsd/imscc/LOM" 
578 xmlns:lomimscc="http://ltsc.ieee.org/xsd/imscc/LOM" 
579 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
580 xsi:schemaLocation="http://www.imsglobal.org/xsd/imscc/imscp_v1p1 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/imscp_v1p2_localised.xsd http://ltsc.ieee.org/xsd/imscc/LOM http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_1/lomLoose_localised.xsd" version="IMS Common Cartridge 1.0.0"> <metadata>
581                 <schema>IMS Common Cartridge</schema>
582             <schemaversion>1.0.0</schemaversion>
583                 <lomimscc:lom>
584       <lomimscc:general>
585         <lomimscc:identifier>          
586                         <lomimscc:catalog>ATutor</lomimscc:catalog>
587                         <lomimscc:entry></lomimscc:entry>
588         </lomimscc:identifier>
589         <lomimscc:title>
590                         <lomimscc:string language="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_TITLE}</lomimscc:string>
591         </lomimscc:title>
592         <lomimscc:language>en</lomimscc:language>
593         <lomimscc:description> 
594                         <lomimscc:string language="{COURSE_PRIMARY_LANGUAGE_CODE}">{COURSE_DESCRIPTION}</lomimscc:string>
595         </lomimscc:description>
596         <lomimscc:keyword>
597                         <lomimscc:string language="{COURSE_PRIMARY_LANGUAGE_CODE}">{KEYWORDS}</lomimscc:string>
598         </lomimscc:keyword>
599       </lomimscc:general>
600     </lomimscc:lom>
601         </metadata>'
602 ;
603
604 $ims_template_xml['resource'] = '               <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="webcontent" href="resources/{PATH}{CONTENT_ID}.html">
605                         <metadata/>
606                         <file href="resources/{PATH}{CONTENT_ID}.html"/>{FILES}
607                         {DEPENDENCY}
608                 </resource>
609 '."\n";
610 $ims_template_xml['resource_glossary'] = '              <resource identifier="MANIFEST01_RESOURCE_GLOSSARY" type="associatedcontent/imscc_xmlv1p0/learning-application-resource" href="resources/GlossaryItem/glossary.xml">
611                         <metadata/>
612                         <file href="resources/GlossaryItem/glossary.xml"/>
613                 </resource>
614 '."\n";
615 $ims_template_xml['resource_test'] = '          <resource identifier="MANIFEST01_RESOURCE_QTI{TEST_ID}" type="imsqti_xmlv1p2/imscc_xmlv1p0/assessment">
616                         <metadata/>
617                         <file href="QTI/{PATH}"/>{FILES}
618                 </resource>
619 '."\n";
620 $ims_template_xml['resource_weblink'] = '               <resource identifier="MANIFEST01_RESOURCE{CONTENT_ID}" type="imswl_xmlv1p0">
621                         <metadata/>
622                         <file href="Weblinks/{PATH}"/>
623                 </resource>
624 '."\n";
625 $ims_template_xml['file'] = '                   <file href="resources/{FILE}"/>'."\n";
626 $ims_template_xml['xml'] = '                    <file href="{FILE}"/>'."\n";
627 $ims_template_xml['glossary'] = '                       <item identifier="GlossaryItem" identifierref="MANIFEST01_RESOURCE_GLOSSARY">
628                                 <title>Glossary</title>
629                         </item>';
630 $ims_template_xml['test'] = '                   <item identifier="QTI{TEST_ID}" identifierref="MANIFEST01_RESOURCE_QTI{TEST_ID}">
631                                 <title>Test {TEST_ID}</title>
632                         </item>';
633 $ims_template_xml['file_meta'] = '                      <file href="{FILE}">
634                                 <metadata>
635                                 {FILE_META_DATA}
636                                 </metadata>
637                         </file>'."\n";
638
639 $ims_template_xml['final'] = '
640         <organizations>
641                 <organization identifier="MANIFEST01_ORG1" structure="rooted-hierarchy">
642                         <item identifier="resources">           
643                 {ORGANIZATIONS}
644                     </item>
645                 </organization>
646         </organizations>
647         <resources>
648 {RESOURCES}
649         </resources>
650 </manifest>';
651
652 $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
653     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
654 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
655 <head>
656         <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
657         <title>{TITLE}</title>
658         <meta name="Generator" content="ATutor">
659         <meta name="Keywords" content="{KEYWORDS}">
660 </head>
661 <body>{CONTENT}</body>
662 </html>';
663
664 $html_content_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
665     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
666 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
667 <head>
668         <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
669         {HEAD}
670         <title>{TITLE}</title>
671         <meta name="Generator" content="ATutor">
672         <meta name="Keywords" content="{KEYWORDS}">
673 </head>
674 <body>{CONTENT}</body>
675 </html>';
676
677 $default_html_style = ' <style type="text/css">
678         body { font-family: Verdana, Arial, Helvetica, sans-serif;}
679         a.at-term {     font-style: italic; }
680         </style>';
681         
682 //output this as header.html
683 $html_mainheader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
684     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
685 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
686 <head>
687         <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
688         <link rel="stylesheet" type="text/css" href="ims.css"/>
689         <title>{COURSE_TITLE}</title>
690 </head>
691 <body class="headerbody"><h3>{COURSE_TITLE}</h3></body></html>';
692
693
694 $html_toc = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
695     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
696 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
697 <head>
698         <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
699         <link rel="stylesheet" type="text/css" href="ims.css" />
700         <title></title>
701 </head>
702 <body>{TOC}</body></html>';
703
704 // index.html
705 $html_frame = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
706    "http://www.w3.org/TR/html4/frameset.dtd">
707 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{COURSE_PRIMARY_LANGUAGE_CODE}" lang="{COURSE_PRIMARY_LANGUAGE_CODE}">
708         <meta http-equiv="Content-Type" content="text/html; charset={COURSE_PRIMARY_LANGUAGE_CHARSET}" />
709         <title>{COURSE_TITLE}</title>
710 </head>
711 <frameset rows="50,*,50">
712 <frame src="header.html" name="header" title="header" scrolling="no">
713         <frameset cols="25%, *" frameborder="1" framespacing="3">
714                 <frame frameborder="2" marginwidth="0" marginheight="0" src="toc.html" name="frame" title="TOC">
715                 <frame frameborder="2" src="resources/{PATH}{FIRST_ID}.html" name="body" title="{COURSE_TITLE}">
716         </frameset>
717 <frame src="footer.html" name="footer" title="footer" scrolling="no">
718         <noframes>
719                 <h1>{COURSE_TITLE}</h1>
720       <p><a href="toc.html">Table of Contents</a> | <a href="footer.html">About</a><br />
721           </p>
722   </noframes>
723 </frameset>
724 </html>';
725
726
727
728 $glossary_xml = '<?xml version="1.0" encoding="{COURSE_PRIMARY_LANGUAGE_CHARSET}"?>
729 <!--This is an ATutor Glossary terms document-->
730 <!--Created from the ATutor Content Package Generator - http://www.atutor.ca-->
731 <glossary:glossary xmlns:glossary="http://www.atutor.ca/xsd/glossary" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
732       {GLOSSARY_TERMS}
733 </glossary:glossary>
734 ';
735
736 $glossary_term_xml = '  <item>
737                 <term>{TERM}</term>
738                 <definition>{DEFINITION}</definition>
739         </item>';
740
741 $glossary_body_html = '<h2>Glossary</h2>
742         <ul>
743 {BODY}
744 </ul>';
745
746 $glossary_term_html = ' <li><a name="{ENCODED_TERM}"></a><strong>{TERM}</strong><br />
747                 {DEFINITION}<br /><br /></li>';
748
749 ?>