fix the bug that once the a content is deleted from the lesson via "delete content...
[acontent.git] / docs / home / classes / ContentManager.class.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 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
16 require_once(TR_INCLUDE_PATH. 'classes/DAO/ContentDAO.class.php');
17 require_once(TR_INCLUDE_PATH. 'classes/Utility.class.php');
18
19 class ContentManager
20 {
21         /* db handler   */
22         var $db;
23
24         /*      array           */
25         var $_menu;
26
27         /*      array           */
28         var $_menu_info;
29
30         /*      array           */
31         var $_menu_in_order;
32
33         /* int                  */
34         var $course_id;
35
36         // private
37         var $num_sections;
38         var $max_depth;
39         var $content_length;
40         var $dao;
41         var $contentDAO;
42
43         /* constructor  */
44         function ContentManager($course_id) {
45                 if (!($course_id > 0)) {
46                         return;
47                 }
48                 $this->course_id = $course_id;
49                 $this->dao = new DAO();
50                 $this->contentDAO = new ContentDAO();
51                 
52                 /* x could be the ordering or even the content_id       */
53                 /* don't really need the ordering anyway.                       */
54                 /* $_menu[content_parent_id][x] = array('content_id', 'ordering', 'title') */
55                 $_menu = array();
56
57                 /* number of content sections */
58                 $num_sections = 0;
59
60                 $max_depth = array();
61                 $_menu_info = array();
62
63 //              $sql = "SELECT content_id, content_parent_id, ordering, title, UNIX_TIMESTAMP(release_date) AS u_release_date, content_type 
64 //                        FROM ".TABLE_PREFIX."content 
65 //                       WHERE course_id=$this->course_id 
66 //                       ORDER BY content_parent_id, ordering";
67 //              $result = mysql_query($sql, $this->db);
68
69                 $rows = $this->contentDAO->getContentByCourseID($this->course_id);
70                 
71                 if (is_array($rows)) {
72                         foreach ($rows as $row) {
73                                 $num_sections++;
74                                 $_menu[$row['content_parent_id']][] = array('content_id'=> $row['content_id'],
75                                                                                                                         'ordering'      => $row['ordering'], 
76                                                                                                                         'title'         => htmlspecialchars($row['title']),
77                                                                                                                         'content_type' => $row['content_type']);
78         
79                                 $_menu_info[$row['content_id']] = array('content_parent_id' => $row['content_parent_id'],
80                                                                                                                 'title'                         => htmlspecialchars($row['title']),
81                                                                                                                 'ordering'                      => $row['ordering'],
82                                                                                                                 'content_type' => $row['content_type']);
83         
84                                 /* 
85                                  * add test content asscioations
86                                  * find associations per content page, and add it as a sublink.
87                                  * @author harris
88                                  */
89                                 $test_rows = $this->getContentTestsAssoc($row['content_id']);
90                                 if (is_array($test_rows)) {
91                                         foreach ($test_rows as $test_row){
92                                                 $_menu[$row['content_id']][] = array(   'test_id'       => $test_row['test_id'],
93                                                                                                                                 'title'         => htmlspecialchars($test_row['title']),
94                                                                                                                                 'content_type' => CONTENT_TYPE_CONTENT);
95                                         } // end of foreach
96                                 } // end of if
97                                 /* End of add test content asscioations */
98         
99                                 if ($row['content_parent_id'] == 0) {
100                                         $max_depth[$row['content_id']] = 1;
101                                 } else {
102                                         $max_depth[$row['content_id']] = $max_depth[$row['content_parent_id']]+1;
103                                 }
104                         } // end of foreach
105                 } // end of if
106
107                 $this->_menu = $_menu;
108
109                 $this->_menu_info =  $_menu_info;
110
111                 $this->num_sections = $num_sections;
112
113                 if (count($max_depth) > 1) {
114                         $this->max_depth = max($max_depth);
115                 } else {
116                         $this->max_depth = 0;
117                 }
118
119                 // generate array of all the content ids in the same order that they appear in "content navigation"
120                 if ($this->getNextContentID(0) > 0) {
121                         $this->_menu_in_order[] = $next_content_id = $this->getNextContentID(0);
122                 }
123                 while ($next_content_id > 0)
124                 {
125                         $next_content_id = $this->getNextContentID($next_content_id);
126                         
127                         if (in_array($next_content_id, $this->_menu_in_order)) break;
128                         else if ($next_content_id > 0) $this->_menu_in_order[] = $next_content_id;
129                 }
130                 
131                 $this->content_length = count($_menu[0]);
132         }
133
134         // This function is called by initContent to construct $this->_menu_in_order, an array to 
135         // holds all the content ids in the same order that they appear in "content navigation"
136         function getNextContentID($content_id, $order=0) {
137                 // return first root content when $content_id is not given
138                 if (!$content_id) {
139                         return $this->_menu[0][0]['content_id'];
140                 }
141                 
142                 $myParent = $this->_menu_info[$content_id]['content_parent_id'];
143                 $myOrder  = $this->_menu_info[$content_id]['ordering'];
144                 
145                 // calculate $myOrder, add in the number of tests in front of this content page
146                 if (is_array($this->_menu[$myParent])) {
147                         $num_of_tests = 0;
148                         foreach ($this->_menu[$myParent] as $menuContent) {
149                                 if ($menuContent['content_id'] == $content_id) break;
150                                 if (isset($menuContent['test_id'])) $num_of_tests++;
151                         }
152                 }
153                 $myOrder += $num_of_tests;
154                 // end of calculating $myOrder
155                 
156                 /* if this content has children, then take the first one. */
157                 if ( isset($this->_menu[$content_id]) && is_array($this->_menu[$content_id]) && ($order==0) ) {
158                         /* has children */
159                         // if the child is a test, keep searching for the content id
160                         foreach ($this->_menu[$content_id] as $menuID => $menuContent)
161                         {
162                                 if (!empty($menuContent['test_id'])) continue;
163                                 else 
164                                 {
165                                         $nextMenu = $this->_menu[$content_id][$menuID]['content_id'];
166                                         break;
167                                 }
168                         }
169                         
170                         // all children are tests
171                         if (!isset($nextMenu))
172                         {
173                                 if (isset($this->_menu[$myParent][$myOrder]['content_id'])) {
174                                         // has sibling
175                                         return $this->_menu[$myParent][$myOrder]['content_id'];
176                                 }
177                                 else { // no sibling
178                                         $nextMenu = $this->getNextContentID($myParent, 1);
179                                 }
180                         }
181                         return $nextMenu;
182                 } else {
183                         /* no children */
184                         if (isset($this->_menu[$myParent][$myOrder]) && $this->_menu[$myParent][$myOrder] != '') {
185                                 /* Has sibling */
186                                 return $this->_menu[$myParent][$myOrder]['content_id'];
187                         } else {
188                                 /* No more siblings */
189                                 if ($myParent != 0) {
190                                         return $this->getNextContentID($myParent, 1);
191                                 }
192                         }
193                 }
194         }
195         
196         function getContent($parent_id=-1, $length=-1) {
197                 if ($parent_id == -1) {
198                         $my_menu_copy = $this->_menu;
199                         if ($length != -1) {
200                                 $my_menu_copy[0] = array_slice($my_menu_copy[0], 0, $length);
201                         }
202                         return $my_menu_copy;
203                 }
204                 return $this->_menu[$parent_id];
205         }
206
207
208         function &getContentPath($content_id) {
209                 $path = array();
210
211                 $path[] = array('content_id' => $content_id, 'title' => $this->_menu_info[$content_id]['title']);
212
213                 $this->getContentPathRecursive($content_id, $path);
214
215                 $path = array_reverse($path);
216                 return $path;
217         }
218
219
220         function getContentPathRecursive($content_id, &$path) {
221                 $parent_id = $this->_menu_info[$content_id]['content_parent_id'];
222
223                 if ($parent_id > 0) {
224                         $path[] = array('content_id' => $parent_id, 'title' => $this->_menu_info[$parent_id]['title']);
225                         $this->getContentPathRecursive($parent_id, $path);
226                 }
227         }
228
229         function addContent($course_id, $content_parent_id, $ordering, $title, $text, $keywords, 
230                             $related, $formatting, $head = '', $use_customized_head = 0, 
231                             $test_message = '', $content_type = CONTENT_TYPE_CONTENT) {
232                 global $_current_user, $_course_id;
233                 
234             if (!isset($_current_user) || !$_current_user->isAuthor($this->course_id)) {
235                         return false;
236                 }
237
238                 // shift the new neighbouring content down
239                 $sql = "UPDATE ".TABLE_PREFIX."content SET ordering=ordering+1 
240                          WHERE ordering>=$ordering 
241                            AND content_parent_id=$content_parent_id 
242                            AND course_id=$_course_id";
243                 $this->contentDAO->execute($sql);
244
245                 /* main topics all have minor_num = 0 */
246                 $cid = $this->contentDAO->Create($_course_id, $content_parent_id, $ordering, 0, $formatting,
247                                           $keywords, '', $title, $text, $head, $use_customized_head,
248                                           $test_message, $content_type);
249                 return $cid;
250         }
251         
252         function editContent($content_id, $title, $text, $keywords, $formatting, 
253                              $head, $use_customized_head, $test_message) {
254             global $_current_user;
255             
256                 if (!isset($_current_user) || !$_current_user->isAuthor($this->course_id)) {
257                         return FALSE;
258                 }
259
260                 $this->contentDAO->Update($content_id, $title, $text, $keywords, $formatting, $head, $use_customized_head,
261                                           $test_message);
262         }
263
264         function moveContent($content_id, $new_content_parent_id, $new_content_ordering) {
265                 global $msg, $_current_user, $_course_id;
266                 
267             if (!isset($_current_user) || !$_current_user->isAuthor($this->course_id)) {
268                         return FALSE;
269                 }
270
271                 /* first get the content to make sure it exists */
272 //              $sql    = "SELECT ordering, content_parent_id FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
273 //              $result = mysql_query($sql, $this->db);
274                 if (!($row = $this->getContentPage($content_id)) ) {
275                         return FALSE;
276                 }
277                 $old_ordering           = $row['ordering'];
278                 $old_content_parent_id  = $row['content_parent_id'];
279                 
280                 $sql    = "SELECT max(ordering) max_ordering FROM ".TABLE_PREFIX."content WHERE content_parent_id=$old_content_parent_id AND course_id=$_course_id";
281 //              $result = mysql_query($sql, $this->db);
282 //              $row = mysql_fetch_assoc($result);
283                 $row = $this->contentDAO->execute($sql);
284                 $max_ordering = $row[0]['max_ordering'];
285                 
286                 if ($content_id == $new_content_parent_id) {
287                         $msg->addError("NO_SELF_AS_PARENT");
288                         return;
289                 }
290                 
291                 if ($old_content_parent_id == $new_content_parent_id && $old_ordering == $new_content_ordering) {
292                         $msg->addError("SAME_LOCATION");
293                         return;
294                 }
295                 
296                 $content_path = $this->getContentPath($new_content_parent_id);
297                 foreach ($content_path as $parent){
298                         if ($parent['content_id'] == $content_id) {
299                                 $msg->addError("NO_CHILD_AS_PARENT");
300                                 return;
301                         }
302                 }
303                 
304                 // if the new_content_ordering is greater than the maximum ordering of the parent content, 
305                 // set the $new_content_ordering to the maximum ordering. This happens when move the content 
306                 // to the last element under the same parent content.
307                 if ($old_content_parent_id == $new_content_parent_id && $new_content_ordering > $max_ordering) 
308                         $new_content_ordering = $max_ordering;
309                 if (($old_content_parent_id != $new_content_parent_id) || ($old_ordering != $new_content_ordering)) {
310                         // remove the gap left by the moved content
311                         $sql = "UPDATE ".TABLE_PREFIX."content 
312                                    SET ordering=ordering-1 
313                                  WHERE ordering>$old_ordering 
314                                    AND content_parent_id=$old_content_parent_id 
315                                    AND content_id<>$content_id 
316                                    AND course_id=$_course_id";
317 //                      $result = mysql_query($sql, $this->db);
318                         $this->contentDAO->execute($sql);
319
320                         // shift the new neighbouring content down
321                         $sql = "UPDATE ".TABLE_PREFIX."content 
322                                    SET ordering=ordering+1 
323                                  WHERE ordering>=$new_content_ordering 
324                                    AND content_parent_id=$new_content_parent_id 
325                                    AND content_id<>$content_id 
326                                    AND course_id=$_course_id";
327 //                      $result = mysql_query($sql, $this->db);
328                         $this->contentDAO->execute($sql);
329
330                         $sql    = "UPDATE ".TABLE_PREFIX."content 
331                                       SET content_parent_id=$new_content_parent_id, ordering=$new_content_ordering 
332                                     WHERE content_id=$content_id AND course_id=$_course_id";
333 //                      $result = mysql_query($sql, $this->db);
334                         $this->contentDAO->execute($sql);
335                 }
336         }
337         
338         function deleteContent($content_id) {
339                 global $_current_user, $_course_id;
340                 
341                 if (!isset($_current_user) || !$_current_user->isAuthor($this->course_id)) {
342                         return false;
343                 }
344
345                 /* check if exists */
346 //              $sql    = "SELECT ordering, content_parent_id FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
347 //              $result = mysql_query($sql, $this->db);
348 //              if (!($row = @mysql_fetch_assoc($result)) ) {
349                 if (!($row = $this->getContentPage($content_id)) ) {
350                         return false;
351                 }
352                 $ordering                       = $row['ordering'];
353                 $content_parent_id      = $row['content_parent_id'];
354
355                 /* check if this content has sub content        */
356                 $children = $this->_menu[$content_id];
357
358                 if (is_array($children) && (count($children)>0) ) {
359                         /* delete its children recursively first*/
360                         foreach ($children as $x => $info) {
361                                 if ($info['content_id'] > 0) {
362                                         $this->deleteContentRecursive($info['content_id']);
363                                 }
364                         }
365                 }
366
367                 $this->contentDAO->Delete($content_id);
368
369                 /* re-order the rest of the content */
370                 $sql = "UPDATE ".TABLE_PREFIX."content SET ordering=ordering-1 WHERE ordering>=$ordering AND content_parent_id=$content_parent_id AND course_id=$_course_id";
371                 $this->contentDAO->execute($sql);
372                 
373                 // unset last-visited content id
374                 require_once(TR_INCLUDE_PATH.'classes/DAO/UserCoursesDAO.class.php');
375                 $userCoursesDAO = new UserCoursesDAO();
376                 $userCoursesDAO->UpdateLastCid($_SESSION['user_id'], $_course_id, 0);
377                 
378                 unset($_SESSION['s_cid']);
379                 unset($_SESSION['from_cid']);
380                 
381                 /* delete this content page                                     */
382 //              $sql    = "DELETE FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
383 //              $result = mysql_query($sql, $this->db);
384
385                 /* delete this content from member tracking page        */
386 //              $sql    = "DELETE FROM ".TABLE_PREFIX."member_track WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
387 //              $result = mysql_query($sql, $this->db);
388
389 //              $sql    = "DELETE FROM ".TABLE_PREFIX."related_content WHERE content_id=$content_id OR related_content_id=$content_id";
390 //              $result = mysql_query($sql, $this->db);
391
392                 /* delete the content tests association */
393 //              $sql    = "DELETE FROM ".TABLE_PREFIX."content_tests_assoc WHERE content_id=$content_id";
394 //              $result = mysql_query($sql, $this->db);
395
396                 /* delete the content forum association */
397 //              $sql    = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id=$content_id";
398 //              $result = mysql_query($sql, $this->db);
399
400                 /* Delete all AccessForAll contents */
401 //              require_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
402 //              $a4a = new A4a($content_id);
403 //              $a4a->deleteA4a();
404
405                 /* remove the "resume" to this page, b/c it was deleted */
406 //              $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET last_cid=0 WHERE course_id=$_SESSION[course_id] AND last_cid=$content_id";
407 //              $result = mysql_query($sql, $this->db);
408
409                 return true;
410         }
411
412
413         /* private. call from deleteContent only. */
414         function deleteContentRecursive($content_id) {
415                 /* check if this content has sub content        */
416                 $children = $this->_menu[$content_id];
417
418                 if (is_array($children) && (count($children)>0) ) {
419                         /* delete its children recursively first*/
420                         foreach ($children as $x => $info) {
421                                 if ($info['content_id'] > 0) {
422                                         $this->deleteContent($info['content_id']);
423                                 }
424                         }
425                 }
426
427                 // delete this content page
428                 $this->contentDAO->Delete($content_id);
429 //              $sql    = "DELETE FROM ".TABLE_PREFIX."content WHERE content_id=$content_id AND course_id=$_SESSION[course_id]";
430 //              $result = mysql_query($sql, $this->db);
431
432                 /* delete this content from member tracking page        */
433 //              $sql    = "DELETE FROM ".TABLE_PREFIX."member_track WHERE content_id=$content_id";
434 //              $result = mysql_query($sql, $this->db);
435
436                 /* delete the content tests association */
437 //              $sql    = "DELETE FROM ".TABLE_PREFIX."content_tests_assoc WHERE content_id=$content_id";
438 //              $result = mysql_query($sql, $this->db);
439         }
440
441         function getContentPage($content_id) {
442                 include_once(TR_INCLUDE_PATH.'classes/DAO/ContentDAO.class.php');
443                 $contentDAO = new ContentDAO();
444                 return $contentDAO->get($content_id);
445         }
446         
447         /** 
448          * Return a list of tests associated with the selected content
449          * @param       int             the content id that all tests are associated with it.
450          * @return      array   list of tests
451          * @date        Sep 10, 2008
452          * @author      Harris
453          */
454         function & getContentTestsAssoc($content_id){
455                 $sql    = "SELECT ct.test_id, t.title 
456                              FROM (SELECT * FROM ".TABLE_PREFIX."content_tests_assoc 
457                                     WHERE content_id=$content_id) AS ct 
458                              LEFT JOIN ".TABLE_PREFIX."tests t ON ct.test_id=t.test_id
459                             ORDER BY t.title";
460                 return $this->dao->execute($sql);
461         }
462
463         function & cleanOutput($value) {
464                 return stripslashes(htmlspecialchars($value));
465         }
466
467
468         /* @See include/html/editor_tabs/properties.inc.php */
469         /* Access: Public */
470         function getNumSections() {
471                 return $this->num_sections;
472         }
473
474         /* Access: Public */
475         function getMaxDepth() {
476                 return $this->max_depth;
477         }
478
479         /* Access: Public */
480         function getContentLength() {
481                 return $this->content_length;
482         }
483
484         /* @See include/html/dropdowns/local_menu.inc.php */
485         function getLocationPositions($parent_id, $content_id) {
486                 $siblings = $this->getContent($parent_id);
487                 for ($i=0;$i<count($siblings); $i++){
488                         if ($siblings[$i]['content_id'] == $content_id) {
489                                 return $i;
490                         }
491                 }
492                 return 0;       
493         }
494
495         /* Access: Private */
496         function getNumbering($content_id) {
497                 $path = $this->getContentPath($content_id);
498                 $parent = 0;
499                 $numbering = '';
500                 foreach ($path as $page) {
501                         $num = $this->getLocationPositions($parent, $page['content_id']) +1;
502                         $parent = $page['content_id'];
503                         $numbering .= $num.'.';
504                 }
505                 $numbering = substr($numbering, 0, -1);
506
507                 return $numbering;
508         }
509
510         function getPreviousContent($content_id) {
511                 if (is_array($this->_menu_in_order))
512                 {
513                         foreach ($this->_menu_in_order as $content_location => $this_content_id)
514                         {
515                                 if ($this_content_id == $content_id) break;
516                         }
517                         
518                         for ($i=$content_location-1; $i >= 0; $i--)
519                         {
520                                 $content_type = $this->_menu_info[$this->_menu_in_order[$i]]['content_type'];
521                                 
522                                 if ($content_type == CONTENT_TYPE_CONTENT || $content_type == CONTENT_TYPE_WEBLINK)
523                                         return array('content_id'       => $this->_menu_in_order[$i],
524                                                  'ordering'             => $this->_menu_info[$this->_menu_in_order[$i]]['ordering'],
525                                                      'title'            => $this->_menu_info[$this->_menu_in_order[$i]]['title']);
526                         }
527                 }
528                 return NULL;
529         }
530         
531         /**
532          * return the array of the next content node of the given $content_id
533          * when $content_id = 0 or is not set, return the first content node
534          * @param $content_id
535          * @return an array of the next content node
536          */
537         function getNextContent($content_id) {
538                 if (is_array($this->_menu_in_order))
539                 {
540                         // find out the location of the $content_id
541                         if (!$content_id) $content_location = 0; // the first content location when $content_id = 0 or is not set
542                         else
543                         {
544                                 foreach ($this->_menu_in_order as $content_location => $this_content_id)
545                                 {
546                                         if ($this_content_id == $content_id) 
547                                         {
548                                                 $content_location++;
549                                                 break;
550                                         }
551                                 }
552                         }
553                         
554                         // the next content node must be at or after the $content_location
555                         // and with the content type CONTENT or WEBLINK
556                         for ($i=$content_location; $i < count($this->_menu_in_order); $i++)
557                         {
558                                 $content_type = $this->_menu_info[$this->_menu_in_order[$i]]['content_type'];
559                                 
560                                 if ($content_type == CONTENT_TYPE_CONTENT || $content_type == CONTENT_TYPE_WEBLINK)
561                                         return(array('content_id'       => $this->_menu_in_order[$i],
562                                                  'ordering'             => $this->_menu_info[$this->_menu_in_order[$i]]['ordering'],
563                                                      'title'            => $this->_menu_info[$this->_menu_in_order[$i]]['title']));
564                         }
565                 }
566                 return NULL;
567         }
568         
569         /* @See include/header.inc.php */
570         function generateSequenceCrumbs($cid) {
571                 global $_base_path;
572
573                 $sequence_links = array();
574                 
575                 $first = $this->getNextContent(0); // get first
576                 
577                 if ($_SESSION['prefs']['PREF_NUMBERING'] && $first) {
578                         $first['title'] = $this->getNumbering($first['content_id']).' '.$first['title'];
579                 }
580                 if ($first) {
581                         $first['url'] = $_base_path.'home/course/content.php?_cid='.$first['content_id'];
582                         $sequence_links['first'] = $first;
583                 }
584
585                 if (!$cid && $_SESSION['s_cid']) {
586                         $resume['title'] = $this->_menu_info[$_SESSION['s_cid']]['title'];
587
588                         if ($_SESSION['prefs']['PREF_NUMBERING']) {
589                                 $resume['title'] = $this->getNumbering($_SESSION['s_cid']).' ' . $resume['title'];
590                         }
591
592                         $resume['url'] = $_base_path.'home/course/content.php?_cid='.$_SESSION['s_cid'];
593                         
594                         $sequence_links['resume'] = $resume;
595                 } else {
596                         if ($cid) {
597                                 $previous = $this->getPreviousContent($cid);
598                         }
599                         $next = $this->getNextContent($cid ? $cid : 0);
600
601                         if ($_SESSION['prefs']['PREF_NUMBERING']) {
602                                 $previous['title'] = $this->getNumbering($previous['content_id']).' '.$previous['title'];
603                                 $next['title'] = $this->getNumbering($next['content_id']).' '.$next['title'];
604                         }
605
606                         $next['url'] = $_base_path.'home/course/content.php?_cid='.$next['content_id'];
607                         if (isset($previous['content_id'])) {
608                                 $previous['url'] = $_base_path.'home/course/content.php?_cid='.$previous['content_id'];
609                         }
610                         
611                         if (isset($previous['content_id'])) {
612                                 $sequence_links['previous'] = $previous;
613                         } else if ($cid) {
614 //                              $previous['url']   = $_base_path . url_rewrite('index.php');
615 //                              $previous['url']   = $_base_path . 'home/course/index.php';
616 //                              $previous['title'] = _AT('home');
617 //                              $sequence_links['previous'] = $previous;
618                         }
619                         if (!empty($next['content_id'])) {
620                                 $sequence_links['next'] = $next;
621                         }
622                 }
623
624                 return $sequence_links;
625         }
626
627         /** Generate javascript to hide all root content folders, except the one with current content page
628          * access: private
629          * @return print out javascript function initContentMenu()
630          */
631         function initMenu(){
632                 global $_base_path, $_course_id;
633                 
634                 echo '
635 function initContentMenu() {
636   tree_collapse_icon = "'.$_base_path.'images/tree/tree_collapse.gif";
637   tree_expand_icon = "'.$_base_path.'images/tree/tree_expand.gif";
638                 
639 ';
640                 
641                 $sql = "SELECT content_id
642                           FROM ".TABLE_PREFIX."content 
643                          WHERE course_id=$this->course_id
644                            AND content_type = ".CONTENT_TYPE_FOLDER;
645                 $rows = $this->dao->execute($sql);
646
647                 // collapse all root content folders
648                 if (is_array($rows)) {
649                         foreach ($rows as $row) {
650                                 echo '
651   if (trans.utility.getcookie("t.c'.$_course_id.'_'.$row['content_id'].'") == "1")
652   {
653     jQuery("#folder"+'.$row['content_id'].').show();
654     jQuery("#tree_icon"+'.$row['content_id'].').attr("src", tree_collapse_icon);
655     jQuery("#tree_icon"+'.$row['content_id'].').attr("alt", "'._AT("collapse").'");
656     jQuery("#tree_icon"+'.$row['content_id'].').attr("title", "'._AT("collapse").'");
657   }
658   else
659   {
660     jQuery("#folder"+'.$row['content_id'].').hide();
661     jQuery("#tree_icon"+'.$row['content_id'].').attr("src", tree_expand_icon);
662     jQuery("#tree_icon"+'.$row['content_id'].').attr("alt", "'._AT("expand").'");
663     jQuery("#tree_icon"+'.$row['content_id'].').attr("title", "'._AT("expand").'");
664   }
665 ';
666                         }
667                 }
668                 
669                 // expand the content folder that has current content
670                 if (isset($_SESSION['s_cid']) && $_SESSION['s_cid'] > 0) {
671                         $current_content_path = $this->getContentPath($_SESSION['s_cid']);
672                         
673                         for ($i=0; $i < count($current_content_path)-1; $i++)
674                                 echo '
675   jQuery("#folder"+'.$current_content_path[$i]['content_id'].').show();
676   jQuery("#tree_icon"+'.$current_content_path[$i]['content_id'].').attr("src", tree_collapse_icon);
677   jQuery("#tree_icon"+'.$current_content_path[$i]['content_id'].').attr("alt", "'._AT("collapse").'");
678   trans.utility.setcookie("t.c'.$_course_id.'_'.$current_content_path[$i]['content_id'].'", "1", 1);
679 ';
680                 }
681                 echo '}'; // end of javascript function initContentMenu()
682         }
683         
684         /* @See include/html/dropdowns/menu_menu.inc.php */
685         function printMainMenu( ) {
686                 global $_current_user, $_course_id;
687                 
688                 if (!($this->course_id > 0)) {
689                         return;
690                 }
691                 
692                 global $_base_path;
693                 
694                 $parent_id    = 0;
695                 $depth        = 0;
696                 $path         = '';
697                 $children     = array();
698                 $truncate     = true;
699                 $ignore_state = true;
700
701                 $this->start = true;
702                 
703                 // if change the location of this line, change function switchEditMode(), else condition accordingly
704                 echo '<div id="editable_table">';
705                 
706                 if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme())
707                 {
708                         echo "\n".'
709   <div class="menuedit">
710     <a href="'.$_base_path.'home/editor/edit_content_folder.php?_course_id='.$_course_id.'">
711       <img id="img_create_top_folder" src="'.$_base_path.'images/mfolder.gif" alt="'._AT("add_top_folder").'" title="'._AT("add_top_folder").'" style="border:0;height:1.2em" />
712     </a>'."\n".'
713     <a href="'.$_base_path.'home/editor/edit_content.php?_course_id='.$_course_id.'">
714       <img id="img_create_top_content" src="'.$_base_path.'images/mpage.gif" alt="'._AT("add_top_page").'" title="'._AT("add_top_page").'" style="border:0;height:1.2em" />
715     </a>'."\n".'
716     <a href="javascript:void(0)" onclick="javascript:switchEditMode();">
717       <img id="img_switch_edit_mode" src="'.$_base_path.'images/medit.gif" alt="'._AT("enter_edit_mode").'" title="'._AT("enter_edit_mode").'" style="border:0;height:1.2em" />
718     </a>
719   </div>'."\n";
720                 }
721                 $this->printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_state);
722                 
723                 // javascript for inline editor
724                 echo '
725 <script type="text/javascript">
726 ';
727                 // only expand the content folder that has the current content page
728                 $this->initMenu();
729                 
730                 echo '
731 function switchEditMode() {
732   title_edit = "'._AT("enter_edit_mode").'";
733   img_edit = "'.$_base_path.'images/medit.gif";
734         
735   title_view = "'._AT("exit_edit_mode").'";
736   img_view = "'.$_base_path.'images/mlock.gif";
737         
738   if (jQuery("#img_switch_edit_mode").attr("src") == img_edit)
739   {
740     jQuery("#img_switch_edit_mode").attr("src", img_view);
741     jQuery("#img_switch_edit_mode").attr("alt", title_view);
742     jQuery("#img_switch_edit_mode").attr("title", title_view);
743     inlineEditsSetup();
744   }
745   else
746   { // refresh the content navigation to exit the edit mode
747     jQuery.post("'. TR_BASE_HREF. 'home/course/refresh_content_nav.php?_course_id='.$_course_id.'", {}, 
748                 function(data) {jQuery("#editable_table").replaceWith(data); initContentMenu();});
749   }
750 }
751
752 function inlineEditsSetup() {
753   jQuery("#editable_table").find(".inlineEdits").each(function() {
754     jQuery(this).text(jQuery(this).attr("title"));
755   });
756         
757   var tableEdit = fluid.inlineEdits("#editable_table", {
758     selectors : {
759       text : ".inlineEdits",
760       editables : "span:has(span.inlineEdits)"
761     },
762     defaultViewText: "",
763       applyEditPadding: false,
764       useTooltip: true,
765       listeners: {
766         afterFinishEdit : function (newValue, oldValue, editNode, viewNode) {
767           if (newValue != oldValue) 
768           {
769             rtn = jQuery.post("'. TR_BASE_HREF. 'home/course/content_nav_inline_editor_submit.php", { "field":viewNode.id, "value":newValue }, 
770                   function(data) {}, "json");
771           }
772         }
773       }
774    });
775
776   jQuery(".fl-inlineEdit-edit").css("width", "80px")
777 };
778
779 initContentMenu();
780 </script>
781 ';
782                 echo '</div>';
783         }
784
785         /* @See tools/sitemap/index.php */
786         function printSiteMapMenu() {
787                 $parent_id    = 0;
788                 $depth        = 1;
789                 $path         = '';
790                 $children     = array();
791                 $truncate     = false;
792                 $ignore_state = true;
793
794                 $this->start = true;
795                 $this->printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_state, 'sitemap');
796         }
797
798         /* @See index.php */
799         function printTOCMenu($cid, $top_num) {
800                 $parent_id    = $cid;
801                 $depth        = 1;
802                 $path         = $top_num.'.';
803                 $children     = array();
804                 $truncate     = false;
805                 $ignore_state = false;
806
807                 $this->start = true;
808                 $this->printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_state);
809         }
810
811         /* @See index.php include/html/dropdowns/local_menu.inc.php */
812         function printSubMenu($cid, $top_num) {
813                 $parent_id    = $cid;
814                 $depth        = 1;
815                 $path         = $top_num.'.';
816                 $children     = array();
817                 $truncate     = true;
818                 $ignore_state = false;
819         
820                 $this->start = true;
821                 $this->printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_state);
822         }
823
824         /* @See include/html/menu_menu.inc.php  */
825         /* Access: PRIVATE */
826         function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_state, $from = '') {
827                 global $cid, $_my_uri, $_base_path, $rtl, $substr, $strlen, $_current_user;
828                 static $temp_path;
829
830                 if (!isset($temp_path)) {
831                         if ($cid) {
832                                 $temp_path      = $this->getContentPath($cid);
833                         } else {
834                                 $temp_path      = $this->getContentPath($_SESSION['s_cid']);
835                         }
836                 }
837
838                 $highlighted = array();
839                 if (is_array($temp_path)) {
840                         foreach ($temp_path as $temp_path_item) {
841                                 $_SESSION['menu'][$temp_path_item['content_id']] = 1;
842                                 $highlighted[$temp_path_item['content_id']] = true;
843                         }
844                 }
845
846                 if ($this->start) {
847                         reset($temp_path);
848                         $this->start = false;
849                 }
850
851                 if ( isset($this->_menu[$parent_id]) && is_array($this->_menu[$parent_id]) ) {
852                         $top_level = $this->_menu[$parent_id];
853                         $counter = 1;
854                         $num_items = count($top_level);
855                         
856 //                      if ($parent_id <> 0) echo '<li>';
857                         
858 //                      echo '<ul id="folder'.$parent_id.$from.'">'."\n";
859                         echo '<div id="folder'.$parent_id.$from.'">'."\n";
860                         
861                         foreach ($top_level as $garbage => $content) {
862                                 $link = '';
863                                 //tests do not have content id
864                                 $content['content_id'] = isset($content['content_id']) ? $content['content_id'] : '';
865
866                                 if (!$ignore_state) {
867                                         $link .= '<a name="menu'.$content['content_id'].'"></a>';
868                                 }
869
870                                 $on = false;
871
872                                 if ( (($_SESSION['s_cid'] != $content['content_id']) || ($_SESSION['s_cid'] != $cid)) && ($content['content_type'] == CONTENT_TYPE_CONTENT || $content['content_type'] == CONTENT_TYPE_WEBLINK)) 
873                                 { // non-current content nodes with content type "CONTENT_TYPE_CONTENT"
874                                         if (isset($highlighted[$content['content_id']])) {
875                                                 $link .= '<strong>';
876                                                 $on = true;
877                                         }
878
879                                         //content test extension  @harris
880                                         //if this is a test link.
881                                         if (isset($content['test_id'])){
882                                                 $title_n_alt =  $content['title'];
883                                                 $in_link = $_base_path.'tests/preview.php?tid='.$content['test_id'].'&_cid='.$parent_id;
884                                                 $img_link = ' <img src="'.$_base_path.'images/check.gif" title="'.$title_n_alt.'" alt="'.$title_n_alt.'" />';
885                                         } else {
886                                                 $in_link = $_base_path.'home/course/content.php?_cid='.$content['content_id'];
887                                                 $img_link = '';
888                                         }
889                                         
890                                         $full_title = $content['title'];
891 //                                      $link .= $img_link . ' <a href="'.$_base_path.url_rewrite($in_link).'" title="';
892                                         $link .= $img_link . ' <a href="'.$in_link.'" title="';
893                                         $base_title_length = 29;
894                                         if ($_SESSION['prefs']['PREF_NUMBERING']) {
895 //                                              $link .= $path.$counter.' ';
896                                                 $base_title_length = 24;
897                                         }
898
899                                         $link .= $content['title'].'">';
900
901                                         if ($truncate && ($strlen($content['title']) > ($base_title_length-$depth*4)) ) {
902                                                 $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, ($base_title_length-$depth*4)-4))).'...';
903                                         }
904 //                                      $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, $base_title_length-4))).'...';
905                                         
906                                         if (isset($content['test_id']))
907                                                 $link .= $content['title'];
908                                         else
909                                                 $link .= '<span class="inlineEdits" id="menu-'.$content['content_id'].'" title="'.$full_title.'">'.
910                                                          ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.'&nbsp;' : '').
911                                                          $content['title'].'</span>';
912                                         
913                                         $link .= '</a>';
914                                         if ($on) {
915                                                 $link .= '</strong>';
916                                         }
917                                         
918                                         // instructors have privilege to delete content
919                                         if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !isset($content['test_id']) && !Utility::isMobileTheme()) {
920                                                 $link .= '<a href="'.$_base_path.'home/editor/delete_content.php?_cid='.$content['content_id'].'"><img src="'.TR_BASE_HREF.'images/x.gif" alt="'._AT("delete_content").'" title="'._AT("delete_content").'" style="border:0" height="10" /></a>';
921                                         }
922                                 } 
923                                 else 
924                                 { // current content page & nodes with content type "CONTENT_TYPE_FOLDER"
925                                         $base_title_length = 26;
926                                         if ($_SESSION['prefs']['PREF_NUMBERING']) {
927                                                 $base_title_length = 21;
928                                         }
929                                         
930                                         if (isset($highlighted[$content['content_id']])) {
931                                                 $link .= '<strong>';
932                                                 $on = true;
933                                         }
934
935                                         if ($content['content_type'] == CONTENT_TYPE_CONTENT || $content['content_type'] == CONTENT_TYPE_WEBLINK)
936                                         { // current content page
937                                                 $full_title = $content['title'];
938                                                 $link .= '<a href="'.$_my_uri.'"><img src="'.$_base_path.'images/clr.gif" alt="'._AT('you_are_here').': '.
939                                                          ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter : '').
940                                                          $content['title'].'" height="1" width="1" border="0" /></a><strong style="color:red" title="'.$content['title'].'">'."\n";
941                                                 
942                                                 if ($truncate && ($strlen($content['title']) > ($base_title_length-$depth*4)) ) {
943                                                         $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, ($base_title_length-$depth*4)-4))).'...';
944                                                 }
945 //                                              $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, $base_title_length-4))).'...';
946                                                 $link .= '<a name="menu'.$content['content_id'].'"></a><span class="inlineEdits" id="menu-'.$content['content_id'].'" title="'.$full_title.'">'.
947                                                          ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.'&nbsp;' : '').
948                                                          $content['title'].'</span></strong>';
949                                                 
950                                                 // instructors have privilege to delete content
951                                                 if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme()) {
952                                                         $link .= '<a href="'.$_base_path.'home/editor/delete_content.php?_cid='.$content['content_id'].'"><img src="'.TR_BASE_HREF.'images/x.gif" alt="'._AT("delete_content").'" title="'._AT("delete_content").'" style="border:0" height="10" /></a>';
953                                                 }
954                                         }
955                                         else
956                                         { // nodes with content type "CONTENT_TYPE_FOLDER"
957 //                                              $link .= '<a href="javascript:void(0)" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\'); "><img src="'.$_base_path.'images/clr.gif" alt="'._AT('content_folder').': '.$content['title'].'" height="1" width="1" border="0" /></a>'."\n";
958                                                 
959                                                 $full_title = $content['title'];
960                                                 if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme()) {
961 //                                                      $link .= '<a href="'.$_base_path.url_rewrite("editor/edit_content_folder.php?_cid=".$content['content_id']).'" title="'.$full_title. _AT('click_edit').'">'."\n";
962                                                         $link .= '<a href="'.$_base_path.'home/editor/edit_content_folder.php?_cid='.$content['content_id'].'" title="'.$full_title. _AT('click_edit').'">'."\n";
963                                                 }
964                                                 else {
965                                                         $link .= '<span style="cursor:pointer" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\', \''._AT("expand").'\', \''._AT('collapse').'\', '.$this->course_id.'); ">'."\n";
966                                                 }
967                                                 
968                                                 if ($truncate && ($strlen($content['title']) > ($base_title_length-$depth*4)) ) {
969                                                         $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, ($base_title_length-$depth*4)-4))).'...';
970                                                 }
971 //                                              $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, $base_title_length-4))).'...';
972                                                 if (isset($content['test_id']))
973                                                         $link .= $content['title'];
974                                                 else
975                                                         $link .= '<span class="inlineEdits" id="menu-'.$content['content_id'].'" title="'.$full_title.'">'.
976                                                                  ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.'&nbsp;' : '').
977                                                                  $content['title'].'</span>';
978                                                 
979                                                 if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme()) {
980                                                         $link .= '</a>'."\n";
981                                                 }
982                                                 else {
983                                                         $link .= '</span>'."\n";
984                                                 }
985                                                 
986                                                 // instructors have privilege to delete content
987                                                 if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme()) {
988                                                         $link .= '<a href="'.$_base_path.'home/editor/delete_content.php?_cid='.$content['content_id'].'"><img src="'.TR_BASE_HREF.'images/x.gif" alt="'._AT("delete_content").'" title="'._AT("delete_content").'" style="border:0" height="10" /></a>';
989                                                 }
990 //                                              echo '<div id="folder_content_'.$content['content_id'].'">';
991                                         }
992                                         
993                                         if ($on) {
994                                                 $link .= '</strong>';
995                                         }
996                                 }
997
998                                 if ($ignore_state) {
999                                         $on = true;
1000                                 }
1001
1002 //                              echo '<li>'."\n";
1003                                 echo '<span>'."\n";
1004                                 
1005                                 if ( isset($this->_menu[$content['content_id']]) && is_array($this->_menu[$content['content_id']]) ) {
1006                                         /* has children */
1007                                         for ($i=0; $i<$depth; $i++) {
1008                                                 if ($children[$i] == 1) {
1009                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1010                                                 } else {
1011                                                         echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1012                                                 }
1013                                         }
1014
1015                                         if (($counter == $num_items) && ($depth > 0)) {
1016                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1017                                                 $children[$depth] = 0;
1018                                         } else if ($counter == $num_items) {
1019                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1020                                                 $children[$depth] = 0;
1021                                         } else {
1022                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_split.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1023                                                 $children[$depth] = 1;
1024                                         }
1025
1026                                         if ($_SESSION['s_cid'] == $content['content_id']) {
1027                                                 if (is_array($this->_menu[$content['content_id']])) {
1028                                                         $_SESSION['menu'][$content['content_id']] = 1;
1029                                                 }
1030                                         }
1031
1032                                         if (isset($_SESSION['menu'][$content['content_id']]) && $_SESSION['menu'][$content['content_id']] == 1) {
1033                                                 if ($on) {
1034 //                                                      echo '<img src="'.$_base_path.'images/tree/tree_collapse.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('collapse').'" border="0" width="16" height="16" title="'._AT('collapse').'" class="img-size-tree" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\'); " />'."\n";
1035                                                         echo '<a href="javascript:void(0)" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\', \''._AT("expand").'\', \''._AT('collapse').'\', '.$this->course_id.'); "><img src="'.$_base_path.'images/tree/tree_collapse.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('collapse').'" border="0" width="16" height="16" title="'._AT('collapse').'" class="img-size-tree" /></a>'."\n";
1036                                                         
1037                                                 } else {
1038                                                         echo '<a href="'.$_my_uri.'collapse='.$content['content_id'].'">'."\n";
1039                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_collapse.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('collapse').'" border="0" width="16" height="16" title="'._AT('collapse').' '.$content['title'].'" class="img-size-tree" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\', \''._AT("expand").'\', \''._AT('collapse').'\', '.$this->course_id.'); " />'."\n";
1040                                                         echo '</a>'."\n";
1041                                                 }
1042                                         } else {
1043                                                 if ($on) {
1044 //                                                      echo '<img src="'.$_base_path.'images/tree/tree_collapse.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('collapse').'" border="0" width="16" height="16" title="'._AT('collapse').'" class="img-size-tree" />'."\n";
1045                                                         echo '<a href="javascript:void(0)" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\', \''._AT("expand").'\', \''._AT('collapse').'\', '.$this->course_id.'); "><img src="'.$_base_path.'images/tree/tree_collapse.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('collapse').'" border="0" width="16" height="16" title="'._AT('collapse').'" class="img-size-tree" /></a>'."\n";
1046                                                         
1047                                                 } else {
1048                                                         echo '<a href="'.$_my_uri.'expand='.$content['content_id'].'">'."\n";
1049                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_expand.gif" id="tree_icon'.$content['content_id'].$from.'" alt="'._AT('expand').'" border="0" width="16" height="16"    title="'._AT('expand').' '.$content['title'].'" class="img-size-tree" onclick="javascript: trans.utility.toggleFolder(\''.$content['content_id'].$from.'\', \''._AT("expand").'\', \''._AT('collapse').'\', '.$this->course_id.'); " />';
1050                                                         echo '</a>'."\n";
1051                                                 }
1052                                         }
1053
1054                                 } else {
1055                                         /* doesn't have children */
1056                                         if ($counter == $num_items) {
1057                                                 for ($i=0; $i<$depth; $i++) {
1058                                                         if ($children[$i] == 1) {
1059                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1060                                                         } else {
1061                                                                 echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1062                                                         }
1063                                                 }
1064                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" class="img-size-tree" />'."\n";
1065                                         } else {
1066                                                 for ($i=0; $i<$depth; $i++) {
1067                                                         if ($children[$i] == 1) {
1068                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1069                                                         } else {
1070                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_space.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1071                                                         }
1072                                                 }
1073                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_split.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1074                                         }
1075                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_horizontal.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />'."\n";
1076                                 }
1077
1078 //                              if ($_SESSION['prefs']['PREF_NUMBERING']) {
1079 //                                      echo $path.$counter;
1080 //                              }
1081                                 
1082                                 echo $link;
1083                                 
1084                                 echo "\n<br /></span>\n\n";
1085                                 
1086                                 if ( $ignore_state || (isset($_SESSION['menu'][$content['content_id']]) && $_SESSION['menu'][$content['content_id']] == 1)) {
1087
1088                                         $depth ++;
1089
1090                                         $this->printMenu($content['content_id'],
1091                                                                                 $depth, 
1092                                                                                 $path.$counter.'.', 
1093                                                                                 $children,
1094                                                                                 $truncate, 
1095                                                                                 $ignore_state,
1096                                                                                 $from);
1097
1098                                                                                 
1099                                         $depth--;
1100
1101                                 }
1102                                 $counter++;
1103                         } // end of foreach
1104 //                      echo "</ul>";
1105 //                      if ($parent_id <> 0) print "</li>\n\n";
1106                         print "</div>\n\n";
1107                 }
1108         }
1109
1110         /* @See include/html/editor_tabs/properties.inc.php
1111            @See editor/arrange_content.php
1112             $print_type: "movable" or "related_content"
1113          */
1114         function printActionMenu($menu, $parent_id, $depth, $path, $children, $print_type = 'movable') {
1115                 
1116                 global $cid, $_my_uri, $_base_path, $rtl;
1117
1118                 static $end;
1119
1120                 $top_level = $menu[$parent_id];
1121
1122                 if ( is_array($top_level) ) {
1123                         $counter = 1;
1124                         $num_items = count($top_level);
1125                         foreach ($top_level as $current_num => $content) {
1126                                 if (isset($content['test_id'])){
1127                                         continue;
1128                                 }
1129
1130                                 $link = $buttons = '';
1131
1132                                 echo '<tr>'."\n";
1133                                 
1134                                 if ($print_type == 'movable')
1135                                 {
1136                                         if ($content['content_id'] == $_POST['moved_cid']) {
1137                                                 $radio_selected = ' checked="checked" ';
1138                                         }
1139                                         else {
1140                                                 $radio_selected = '';
1141                                         }
1142                                 
1143                                         $buttons = '<td>'."\n".
1144                                                    '   <small>'."\n".
1145                                                    '      <input type="image" name="move['.$parent_id.'_'.$content['ordering'].']" src="'.$_base_path.'images/before.gif" alt="'._AT('before_topic', $content['title']).'" title="'._AT('before_topic', $content['title']).'" style="height:1.5em; width:1.9em;" />'."\n";
1146
1147                                         if ($current_num + 1 == count($top_level))
1148                                                 $buttons .= '      <input type="image" name="move['.$parent_id.'_'.($content['ordering']+1).']" src="'.$_base_path.'images/after.gif" alt="'._AT('after_topic', $content['title']).'" title="'._AT('after_topic', $content['title']).'" style="height:1.5em; width:1.9em;" />'."\n";
1149                                         
1150                                         $buttons .= '   </small>'."\n".
1151                                                    '</td>'."\n".
1152                                                    '<td>';
1153                                         
1154                                         if ($content['content_type'] == CONTENT_TYPE_FOLDER)
1155                                                 $buttons .= '<input type="image" name="move['.$content['content_id'].'_1]" src="'.$_base_path.'images/child_of.gif" style="height:1.25em; width:1.7em;" alt="'._AT('child_of', $content['title']).'" title="'._AT('child_of', $content['title']).'" />';
1156                                         else
1157                                                 $buttons .= '&nbsp;';
1158                                                 
1159                                         $buttons .= '</td>'."\n".
1160                                                    '<td><input name="moved_cid" value="'.$content['content_id'].'" type="radio" id="r'.$content['content_id'].'" '.$radio_selected .'/></td>'."\n";
1161                                 }
1162                                 
1163                                 $buttons .= '<td>'."\n";
1164                                 if ($print_type == "related_content")
1165                                 {
1166                                         if ($content['content_type'] == CONTENT_TYPE_CONTENT || $content['content_type'] == CONTENT_TYPE_WEBLINK)
1167                                         {
1168                                                 $link .= '<input type="checkbox" name="related[]" value="'.$content['content_id'].'" id="r'.$content['content_id'].'" ';
1169                                                 if (isset($_POST['related']) && in_array($content['content_id'], $_POST['related'])) {
1170                                                         $link .= ' checked="checked"';
1171                                                 }
1172                                                 $link .= ' />'."\n";
1173                                         }
1174                                 }       
1175                                 
1176                                 if ($content['content_type'] == CONTENT_TYPE_FOLDER)
1177                                 {
1178                                         $link .= '<img src="'.$_base_path.'images/folder.gif" />';
1179                                 }
1180                                 $link .= '&nbsp;<label for="r'.$content['content_id'].'">'.$content['title'].'</label>'."\n";
1181
1182                                 if ( is_array($menu[$content['content_id']]) && !empty($menu[$content['content_id']]) ) {
1183                                         /* has children */
1184
1185                                         for ($i=0; $i<$depth; $i++) {
1186                                                 if ($children[$i] == 1) {
1187                                                         echo $buttons;
1188                                                         unset($buttons);
1189                                                         if ($end && ($i==0)) {
1190                                                                 echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />';
1191                                                         } else {
1192                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" />';
1193                                                         }
1194                                                 } else {
1195                                                         echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />';
1196                                                 }
1197                                         }
1198
1199                                         if (($counter == $num_items) && ($depth > 0)) {
1200                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" width="16" height="16" />';
1201                                                 $children[$depth] = 0;
1202                                         } else {
1203                                                 echo $buttons;
1204                                                 if (($num_items == $counter) && ($parent_id == 0)) {
1205                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" width="16" height="16" />';
1206                                                         $end = true;
1207                                                 } else {
1208                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_split.gif" alt="" border="0" width="16" height="16" />';
1209                                                 }
1210                                                 $children[$depth] = 1;
1211                                         }
1212
1213                                         if ($_SESSION['s_cid'] == $content['content_id']) {
1214                                                 if (is_array($menu[$content['content_id']])) {
1215                                                         $_SESSION['menu'][$content['content_id']] = 1;
1216                                                 }
1217                                         }
1218
1219                                         if ($_SESSION['menu'][$content['content_id']] == 1) {
1220                                                 echo '<img src="'.$_base_path.'images/tree/tree_disabled.gif" alt="'._AT('toggle_disabled').'" border="0" width="16" height="16" title="'._AT('toggle_disabled').'" />';
1221
1222                                         } else {
1223                                                 echo '<img src="'.$_base_path.'images/tree/tree_disabled.gif" alt="'._AT('toggle_disabled').'" border="0" width="16" height="16" title="'._AT('toggle_disabled').'" />';
1224                                         }
1225
1226                                 } else {
1227                                         /* doesn't have children */
1228                                         if ($counter == $num_items) {
1229                                                 if ($depth) {
1230                                                         echo $buttons;
1231                                                         for ($i=0; $i<$depth; $i++) {
1232                                                                 if ($children[$i] == 1) {
1233                                                                         if ($end && ($i == 0)) {
1234                                                                                 echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />';
1235                                                                         } else {
1236                                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" />';
1237                                                                         }
1238                                                                 } else {
1239                                                                         echo '<img src="'.$_base_path.'images/clr.gif" alt="" border="0" width="16" height="16" class="img-size-tree" />';
1240                                                                 }
1241                                                         }
1242                                                 } else {
1243                                                         echo $buttons;
1244                                                 }
1245                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_end.gif" alt="" border="0" />';
1246                                         } else {
1247                                                 if ($depth) {
1248                                                         echo $buttons;
1249                                                         $print = false;
1250                                                         for ($i=0; $i<$depth; $i++) {
1251                                                                 if ($children[$i] == 1) {
1252                                                                         if ($end && !$print) {
1253                                                                                 $print = true;
1254                                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_space.gif" alt="" border="0" width="16" height="16" />';
1255                                                                         } else {
1256                                                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_vertline.gif" alt="" border="0" width="16" height="16" />';
1257                                                                         }
1258                                                                 } else {
1259                                                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_space.gif" alt="" border="0" width="16" height="16" />';
1260                                                                 }
1261                                                         }
1262                                                         $print = false;
1263                                                 } else {
1264                                                         echo $buttons;
1265                                                 }
1266                 
1267                                                 echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_split.gif" alt="" border="0" width="16" height="16" />';
1268                                         }
1269                                         echo '<img src="'.$_base_path.'images/'.$rtl.'tree/tree_horizontal.gif" alt="" border="0" width="16" height="16" />';
1270                                 }
1271
1272                                 echo '<small> '.($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter : '');
1273                                 
1274                                 echo $link;
1275                                 
1276                                 echo '</small></td>'."\n".'</tr>'."\n";
1277
1278                                 $this->printActionMenu($menu,
1279                                                                         $content['content_id'],
1280                                                                         ++$depth, 
1281                                                                         $path.$counter.'.', 
1282                                                                         $children,
1283                                                                         $print_type);
1284                                 $depth--;
1285
1286                                 $counter++;
1287                         }
1288                 }
1289         }
1290 }
1291
1292 ?>