btf_functions.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. // $Id: btf_functions.php 13294 2007-09-27 02:14:48Z yannoo $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University
  8. Copyright (c) 2001 Universite Catholique de Louvain
  9. Copyright (c) various contributors
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  19. Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. * HOME PAGE FUNCTIONS (BASIC TOOLS FIXED)
  25. *
  26. * This page, included in every course's index.php is the home
  27. * page.To make administration simple, the professor edits his
  28. * course from it's home page. Only the login detects that the
  29. * visitor is allowed to activate, deactivate home page links,
  30. * access to Professor's tools (statistics, edit forums...).
  31. *
  32. * @package dokeos.course_home
  33. ==============================================================================
  34. */
  35. function showtools2($cat)
  36. {
  37. global $_user, $charset;
  38. $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST);
  39. $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE);
  40. $numcols = 3;
  41. $table = new HTML_Table('width="100%"');
  42. $toolsRow_all = array ();
  43. switch ($cat)
  44. {
  45. case 'Basic' :
  46. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  47. WHERE a.link=t.link AND t.position='basic' ORDER BY t.row, t.column";
  48. break;
  49. case 'External' :
  50. if (api_is_allowed_to_edit())
  51. {
  52. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  53. WHERE (a.link=t.link AND t.position='external')
  54. OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)
  55. ORDER BY a.id";
  56. }
  57. else
  58. {
  59. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  60. WHERE a.visibility = 1 AND ((a.link=t.link AND t.position='external')
  61. OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
  62. ORDER BY a.id";
  63. }
  64. break;
  65. case 'courseAdmin' :
  66. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  67. WHERE admin=1 AND a.link=t.link ORDER BY t.row, t.column";
  68. break;
  69. case 'claroAdmin' :
  70. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE visibility = 2 ORDER BY id";
  71. }
  72. $result = api_sql_query($sql, __FILE__, __LINE__);
  73. // grabbing all the tools from $course_tool_table
  74. while ($tempRow = mysql_fetch_array($result))
  75. {
  76. if ($tempRow['img'] !== "scormbuilder.gif" AND $tempRow['img'] !== "blog.gif")
  77. {
  78. $tempRow['name_translated'] = get_lang(ucfirst($tempRow['name']));
  79. }
  80. $toolsRow_all[] = $tempRow;
  81. }
  82. // grabbing all the links that have the property on_homepage set to 1
  83. if ($cat == "External")
  84. {
  85. $tbl_link = Database :: get_course_table(TABLE_LINK);
  86. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  87. if (api_is_allowed_to_edit())
  88. {
  89. $sql_links = "SELECT tl.*, tip.visibility
  90. FROM $tbl_link tl
  91. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  92. WHERE tl.on_homepage='1' AND tip.visibility != 2";
  93. }
  94. else
  95. {
  96. $sql_links = "SELECT tl.*, tip.visibility
  97. FROM $tbl_link tl
  98. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  99. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  100. }
  101. $result_links = api_sql_query($sql_links);
  102. while ($links_row = mysql_fetch_array($result_links))
  103. {
  104. $properties = array ();
  105. $properties['name'] = $links_row['title'];
  106. $properties['link'] = $links_row['url'];
  107. $properties['visibility'] = $links_row['visibility'];
  108. $properties['img'] = 'external.gif';
  109. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  110. $toolsRow_all[] = $properties;
  111. }
  112. }
  113. $cell_number = 0;
  114. // draw line between basic and external, only if there are entries in External
  115. if ($cat == "External" && count($toolsRow_all))
  116. {
  117. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  118. $table->updateCellAttributes(0, 0, 'colspan="3"');
  119. $cell_number += $numcols;
  120. }
  121. foreach ($toolsRow_all as $toolsRow)
  122. {
  123. $cell_content = '';
  124. // the name of the tool
  125. $tool_name = ($toolsRow['name_translated'] != "" ? $toolsRow['name_translated'] : htmlspecialchars($toolsRow['name'],ENT_QUOTES,$charset)); // RH: added htmlspecialchars
  126. $link_annex = '';
  127. // the url of the tool
  128. if ($toolsRow['img'] != "external.gif")
  129. {
  130. $toolsRow['link'] = api_get_path(WEB_CODE_PATH).$toolsRow['link'];
  131. $qm_or_amp = ((strpos($toolsRow['link'], '?') === FALSE) ? '?' : '&amp;');
  132. $link_annex = $qm_or_amp.api_get_cidreq();
  133. }
  134. else // if an external link ends with 'login=', add the actual login...
  135. {
  136. $pos = strpos($toolsRow['link'], "?login=");
  137. $pos2 = strpos($toolsRow['link'], "&amp;login=");
  138. if ($pos !== false or $pos2 !== false)
  139. {
  140. $link_annex = $_user['username'];
  141. }
  142. }
  143. // setting the actual image url
  144. $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img'];
  145. // VISIBLE
  146. if ($toolsRow['visibility'] or $cat == 'courseAdmin' or $cat == 'claroAdmin')
  147. {
  148. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'"><img src="'.$toolsRow['img'].'" alt="" border="0" style="vertical-align:middle;"/></a>'."\n";
  149. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'">'.$tool_name."</a>\n";
  150. }
  151. // INVISIBLE
  152. else
  153. {
  154. if (api_is_allowed_to_edit())
  155. {
  156. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" alt="" border="0" style="vertical-align:middle;"/></a>'."\n";
  157. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'" class="invisible">'.$tool_name.'</a>'."\n";
  158. }
  159. else
  160. {
  161. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" alt="" border="0" style="vertical-align:middle;">'."\n";
  162. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  163. }
  164. }
  165. $lnk = array ();
  166. if (api_is_allowed_to_edit() and $cat != "courseAdmin" && !strpos($toolsRow['link'], 'learnpath_handler.php?learnpath_id'))
  167. {
  168. if ($toolsRow["visibility"])
  169. {
  170. $link['name'] = '<img src="'.api_get_path(WEB_IMG_PATH).'remove.gif" style="vertical-align:middle;" alt="'.get_lang('Deactivate').'"/>';
  171. $link['cmd'] = "hide=yes";
  172. $lnk[] = $link;
  173. }
  174. else
  175. {
  176. $link['name'] = '<img src="'.api_get_path(WEB_IMG_PATH).'add.gif" style="vertical-align:middle;" alt="'.get_lang('Activate').'"/>';
  177. $link['cmd'] = "restore=yes";
  178. $lnk[] = $link;
  179. /*if($toolsRow["img"] == $dokeosRepositoryWeb."img/external.gif")
  180. {
  181. $link['name'] = get_lang('Remove'); $link['cmd'] = "remove=yes";
  182. if ($toolsRow["visibility"]==2 and $cat=="claroAdmin")
  183. {
  184. $link['name'] = get_lang('Delete'); $link['cmd'] = "askDelete=yes";
  185. $lnk[] = $link;
  186. }
  187. }*/
  188. }
  189. //echo "<div class=courseadmin>";
  190. if (is_array($lnk))
  191. {
  192. foreach ($lnk as $thisLnk)
  193. {
  194. if ($toolsRow['adminlink'])
  195. {
  196. $cell_content .= '<a href="'.$properties['adminlink'].'">'.'<img src="'.api_get_path(WEB_IMG_PATH).'edit.gif" alt="'.get_lang('Edit').'"/>'.'</a>';
  197. //echo "edit link:".$properties['adminlink'];
  198. }
  199. else
  200. {
  201. $cell_content .= "<a href=\"".api_get_self()."?id=".$toolsRow["id"]."&amp;".$thisLnk['cmd']."\">".$thisLnk['name']."</a>";
  202. }
  203. }
  204. }
  205. // RH: Allow editing of invisible homepage links (modified external_module)
  206. if ($toolsRow["added_tool"] == 1 && api_is_allowed_to_edit() && !$toolsRow["visibility"])
  207. {
  208. $cell_content .= "<a class=\"nobold\" href=\"".api_get_path(WEB_CODE_PATH).'external_module/external_module.php'."?id=".$toolsRow["id"]."\">".get_lang("Edit")."</a>";
  209. }
  210. }
  211. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  212. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  213. $cell_number ++;
  214. }
  215. $table->display();
  216. } // end function showtools2($cat)
  217. ?>