ae2679ec061f7f94cac356cf9b7703232950098a
[acontent.git] / docs / themes / default / home / index_course.tmpl.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 // determine the from url is search.php or index.php
14 global $_base_path;
15 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
16 require_once(TR_INCLUDE_PATH.'classes/DAO/UserCoursesDAO.class.php');
17
18 // This template is called by home/index.php and home/search.php
19 // Find out the caller URL and direct the page back to the caller 
20 // after adding/removing the course from "My Courses"
21 list($caller_url, $url_param) = Utility::getRefererURLAndParams();
22
23 if (isset($this->search_text)) $keywords = explode(' ', $this->search_text);
24 ?>
25 <!-- 
26 <div class="input-form">
27 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('search'); ?></legend>
28         <form target="_top" action="<?php echo TR_BASE_HREF; ?>home/search.php" method="get" name="frm_search">
29         <input type="text" name="search_text" id="search_text" value="<?php if (isset($_REQUEST['search_text'])) echo $_REQUEST['search_text']; ?>" size="50"   />
30
31 <?php if (is_array($this->categories)) { // print category dropdown list box?>
32     <select name="catid">
33       <option value="" <?php if (!isset($_GET['catid']) || $_GET['catid'] == '') echo 'selected="selected"'; ?>><?php echo _AT('all_categories'); ?></option>
34       <option value="">---------------------------------</option>
35 <?php foreach ($this->categories as $category) {?>
36       <option value="<?php echo $category['category_id']; ?>" <?php if ($_GET['catid'] == $category['category_id']) echo 'selected'; ?>><?php echo $category['category_name']; ?></option>
37 <?php }?>
38       <option value="0" <?php if ($_GET['catid'] == 0 && $_GET['catid'] <> '') echo 'selected'; ?>><?php echo _AT('cats_uncategorized'); ?></option>
39     </select>
40 <?php }?>
41         
42         <input type="submit" name="search" size="100" value="<?php echo _AT("search"); ?>" />
43         </form>
44 </fieldset>
45 </div> 
46 -->
47
48 <div class="input-form">
49 <fieldset class="group_form"><legend class="group_form"><?php echo $this->title; ?></legend>
50 <?php if (is_array($this->courses)) { ?>
51   <div class="results">
52     <ol class="remove-margin-left">
53 <?php 
54         if (isset($_SESSION['user_id'])) $userCoursesDAO = new UserCoursesDAO();
55         
56         $num_results = count($this->courses);
57         
58         // if the requested page number exceeds the max number of pages, set the current page to the last page
59         $num_pages = ceil($num_results / RESULTS_PER_PAGE);
60         if ($this->curr_page_num > $num_pages) $this->curr_page_num = $num_pages;
61         
62         
63         $start_num = ($this->curr_page_num - 1) * RESULTS_PER_PAGE;
64         $end_num = min($this->curr_page_num * RESULTS_PER_PAGE, $num_results);
65 ?>
66       <li class="course" style="font-weight:bold">
67         <div><?php echo ((strstr($caller_script, 'search.php') ? _AT('results'):_AT('lessons'))).' '.($start_num+1) .'-'.$end_num.' '._AT('of').' '.$num_results.' '. ($this->search_text<>'' ? _AT('for').' "<em>'.$this->search_text.'</em>"':'');?>
68         <?php  
69         if($_SESSION['user_id']){ ?>
70           <span style="float: right"><img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/my_own_course.gif" alt="<?php echo _AT('my_authoring_course'); ?>" title="<?php echo _AT('my_authoring_course'); ?>" />&nbsp;&nbsp;&nbsp;<?php echo _AT('authoring_img_info'); ?></span>
71           <?php } ?>
72         </div>
73                                 
74       </li>
75 <?php   for ($i = $start_num; $i < $end_num; $i++) {
76                 // only display the first 200 character of course description
77                 $row = $this->courses[$i];
78                 
79                 // find whether the current user is the author of this course
80                 if (isset($_SESSION['user_id'])) $user_role = $userCoursesDAO->get($_SESSION['user_id'], $row['course_id']);
81                 
82                 $len_description = 330;
83                 if (strlen($row['description']) > $len_description)
84                         $description = Utility::highlightKeywords(substr($row['description'], 0, $len_description), $keywords).' ...';
85                 else
86                         $description = Utility::highlightKeywords($row['description'], $keywords);
87 ?>
88       <li class="course">
89         <h3>
90 <?php if ($user_role['role'] == TR_USERROLE_AUTHOR) {?>
91           <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/my_own_course.gif" alt="<?php echo _AT('my_authoring_course'); ?>" title="<?php echo _AT('my_authoring_course'); ?>" />
92 <?php } else  {?>
93           <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/others_course.png" alt="<?php echo _AT('others_course'); ?>" title="<?php echo _AT('others_course'); ?>" />
94 <?php } ?>
95           <a href="<?php echo TR_BASE_HREF; ?>home/course/index.php?_course_id=<?php echo $row['course_id']; ?>"><?php echo Utility::highlightKeywords($row['title'], $keywords); ?></a>
96 <?php if ($user_role['role'] == TR_USERROLE_VIEWER) {?>
97           <a href="<?php echo TR_BASE_HREF; ?>home/<?php echo $caller_url; ?>action=remove&cid=<?php echo $row['course_id']; ?>">
98             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/bookmark_remove.png" alt='<?php echo htmlspecialchars(_AT('remove_from_list')); ?>' title='<?php echo htmlspecialchars(_AT('remove_from_list')); ?>' border="0" />
99           </a>
100 <?php } if ($user_role['role'] == NULL && $_SESSION['user_id']>0) {?>
101           <a href="<?php echo TR_BASE_HREF; ?>home/<?php echo $caller_url; ?>action=add&cid=<?php echo $row['course_id'];?>">
102             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/bookmark_add.png" alt="<?php echo htmlspecialchars(_AT('add_into_list')); ?>" title="<?php echo htmlspecialchars(_AT('add_into_list')); ?>" border="0" />
103           </a>
104 <?php }?>
105           <a href="<?php echo TR_BASE_HREF; ?>home/ims/ims_export.php?course_id=<?php echo $row['course_id']; ?>">
106             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/export.png" alt="<?php echo _AT('download_content_package'); ?>" title="<?php echo _AT('download_content_package'); ?>" border="0" />
107           </a>
108           <a href="<?php echo TR_BASE_HREF; ?>home/imscc/ims_export.php?course_id=<?php echo $row['course_id']; ?>">
109             <img src="<?php echo TR_BASE_HREF; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/export_cc.png" alt="<?php echo _AT('download_common_cartridge'); ?>" title="<?php echo _AT('download_common_cartridge'); ?>" border="0" />
110           </a>
111         </h3>
112         <div><?php echo $description; ?></div>
113       </li>                             
114 <?php } // end of foreach; ?>
115     </ol>
116 <?php   print_paginator($this->curr_page_num, $num_results, $url_param, RESULTS_PER_PAGE);?>
117   </div>
118 <?php } // end of if
119 else {
120 //      echo _AT("no_results_for_keywords", $this->search_text);
121         echo _AT("none_found");
122 } // end of else?>
123 </fieldset>
124 </div>