btf_functions.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. // $Id: btf_functions.php 20027 2009-04-23 19:18:54Z cfasanando $
  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 'platformAdmin' :
  70. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE visibility = 2 ORDER BY id";
  71. }
  72. $result = Database::query($sql, __FILE__, __LINE__);
  73. // grabbing all the tools from $course_tool_table
  74. while ($tempRow = Database::fetch_array($result))
  75. {
  76. /*
  77. if ($tempRow['img'] !== "scormbuilder.gif" AND $tempRow['img'] !== "blog.gif")
  78. */
  79. if ($tempRow['img'] != 'file_html.gif' && $tempRow['img'] != 'file_html_na.gif'
  80. && $tempRow['img'] != 'scormbuilder.gif' && $tempRow['img'] != 'scormbuilder_na.gif'
  81. && $tempRow['img'] != 'blog.gif' && $tempRow['img'] != 'blog_na.gif'
  82. && $tempRow['img'] != 'external.gif' && $tempRow['img'] != 'external_na.gif')
  83. {
  84. $tempRow['name_translated'] = get_lang(ucfirst($tempRow['name']));
  85. }
  86. $toolsRow_all[] = $tempRow;
  87. }
  88. // grabbing all the links that have the property on_homepage set to 1
  89. if ($cat == "External")
  90. {
  91. $tbl_link = Database :: get_course_table(TABLE_LINK);
  92. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  93. if (api_is_allowed_to_edit(null,true))
  94. {
  95. $sql_links = "SELECT tl.*, tip.visibility
  96. FROM $tbl_link tl
  97. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  98. WHERE tl.on_homepage='1' AND tip.visibility != 2";
  99. }
  100. else
  101. {
  102. $sql_links = "SELECT tl.*, tip.visibility
  103. FROM $tbl_link tl
  104. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  105. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  106. }
  107. $result_links = Database::query($sql_links);
  108. while ($links_row = Database::fetch_array($result_links))
  109. {
  110. $properties = array ();
  111. $properties['name'] = $links_row['title'];
  112. $properties['link'] = $links_row['url'];
  113. $properties['visibility'] = $links_row['visibility'];
  114. $properties['img'] = 'external.gif';
  115. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  116. $toolsRow_all[] = $properties;
  117. }
  118. }
  119. $cell_number = 0;
  120. // draw line between basic and external, only if there are entries in External
  121. if ($cat == "External" && count($toolsRow_all))
  122. {
  123. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  124. $table->updateCellAttributes(0, 0, 'colspan="3"');
  125. $cell_number += $numcols;
  126. }
  127. foreach ($toolsRow_all as $toolsRow)
  128. {
  129. if (api_get_session_id()!=0 && in_array($toolsRow['name'],array('course_maintenance','course_setting'))) {
  130. continue;
  131. }
  132. $cell_content = '';
  133. // the name of the tool
  134. $tool_name = ($toolsRow['name_translated'] != "" ? $toolsRow['name_translated'] : htmlspecialchars($toolsRow['name'],ENT_QUOTES,$charset)); // RH: added htmlspecialchars
  135. $link_annex = '';
  136. // the url of the tool
  137. if ($toolsRow['img'] != "external.gif")
  138. {
  139. $toolsRow['link'] = api_get_path(WEB_CODE_PATH).$toolsRow['link'];
  140. $qm_or_amp = ((strpos($toolsRow['link'], '?') === FALSE) ? '?' : '&amp;');
  141. $link_annex = $qm_or_amp.api_get_cidreq();
  142. }
  143. else // if an external link ends with 'login=', add the actual login...
  144. {
  145. $pos = strpos($toolsRow['link'], "?login=");
  146. $pos2 = strpos($toolsRow['link'], "&amp;login=");
  147. if ($pos !== false or $pos2 !== false)
  148. {
  149. $link_annex = $_user['username'];
  150. }
  151. }
  152. // setting the actual image url
  153. $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img'];
  154. // VISIBLE
  155. if ($toolsRow['visibility'] or $cat == 'courseAdmin' or $cat == 'platformAdmin')
  156. {
  157. if(strpos($toolsRow['name'],'visio_')!==false)
  158. {
  159. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\'' . $toolsRow['link'].$link_annex . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '"><img src="'.$toolsRow['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  160. }
  161. else if(strpos($toolsRow['name'],'chat')!==false && api_get_course_setting('allow_open_chat_window')==true)
  162. {
  163. /*
  164. $cell_content .= '<a href="#" onclick="window.open(\'' .$toolsRow['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '"><img src="'.$toolsRow['img'].'" alt="'.get_lang(ucfirst($toolsRow['name'])).' " align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  165. */
  166. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\'' .$toolsRow['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '"><img src="'.$toolsRow['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  167. }
  168. else
  169. {
  170. /*
  171. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'"><img src="'.$toolsRow['img'].'" alt="'.get_lang(ucfirst($toolsRow['name'])).' " align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  172. */
  173. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'"><img src="'.$toolsRow['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  174. }
  175. }
  176. // INVISIBLE
  177. else
  178. {
  179. if (api_is_allowed_to_edit(null,true))
  180. {
  181. if(strpos($toolsRow['name'],'visio_')!==false)
  182. {
  183. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\'' . $toolsRow['link'].$link_annex . '\',\'window_visio'.$_SESSION['_cid'].'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'."\n";
  184. }
  185. else if(strpos($toolsRow['name'],'chat')!==false && api_get_course_setting('allow_open_chat_window')==true)
  186. {
  187. /*
  188. $cell_content .= '<a href="#" onclick="window.open(\'' .$toolsRow['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" alt="'.get_lang(ucfirst($toolsRow['name'])).' " align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  189. */
  190. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\'' .$toolsRow['link'].$link_annex. '\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="' . $toolsRow['target'] . '" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'."\n"; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  191. }
  192. else
  193. {
  194. /*
  195. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" alt="'.get_lang(ucfirst($toolsRow['name'])).' " align="absmiddle" border="0">'.$tool_name.'</a>'."\n";// don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  196. */
  197. $cell_content .= '<a href="'.$toolsRow['link'].$link_annex.'" target="'.$toolsRow['target'].'" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>'."\n";// don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  198. }
  199. }
  200. else
  201. {
  202. /*
  203. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" alt="'.get_lang(ucfirst($toolsRow['name'])).' " align="absmiddle" border="0">'; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  204. */
  205. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $toolsRow['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'; // don't replace img with display::return_icon because $toolsRow['img'] = api_get_path(WEB_IMG_PATH).$toolsRow['img']
  206. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  207. }
  208. }
  209. $lnk = array ();
  210. if (api_is_allowed_to_edit(null,true) && $cat != "courseAdmin" && !strpos($toolsRow['link'], 'learnpath_handler.php?learnpath_id') && !api_is_coach())
  211. {
  212. if ($toolsRow["visibility"])
  213. {
  214. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align:middle;'));
  215. $link['cmd'] = "hide=yes";
  216. $lnk[] = $link;
  217. }
  218. else
  219. {
  220. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align:middle;'));
  221. $link['cmd'] = "restore=yes";
  222. $lnk[] = $link;
  223. /*if($toolsRow["img"] == $dokeosRepositoryWeb."img/external.gif")
  224. {
  225. $link['name'] = get_lang('Remove'); $link['cmd'] = "remove=yes";
  226. if ($toolsRow["visibility"]==2 and $cat=="platformAdmin")
  227. {
  228. $link['name'] = get_lang('Delete'); $link['cmd'] = "askDelete=yes";
  229. $lnk[] = $link;
  230. }
  231. }*/
  232. }
  233. //echo "<div class=courseadmin>";
  234. if (is_array($lnk))
  235. {
  236. foreach ($lnk as $thisLnk)
  237. {
  238. if ($toolsRow['adminlink'])
  239. {
  240. $cell_content .= '<a href="'.$properties['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  241. //echo "edit link:".$properties['adminlink'];
  242. }
  243. else
  244. {
  245. $cell_content .= "<a href=\"".api_get_self()."?id=".$toolsRow["id"]."&amp;".$thisLnk['cmd']."\">".$thisLnk['name']."</a>";
  246. }
  247. }
  248. }
  249. // RH: Allow editing of invisible homepage links (modified external_module)
  250. /*
  251. if ($toolsRow["added_tool"] == 1 && api_is_allowed_to_edit() && !$toolsRow["visibility"])
  252. */
  253. if ($toolsRow["added_tool"] == 1 && api_is_allowed_to_edit() && !$toolsRow["visibility"]
  254. && $toolsRow['image'] != 'scormbuilder.gif' && $toolsRow['image'] != 'scormbuilder_na.gif')
  255. {
  256. $cell_content .= "<a class=\"nobold\" href=\"".api_get_path(WEB_CODE_PATH).'external_module/external_module.php'."?id=".$toolsRow["id"]."\">".get_lang("Edit")."</a>";
  257. }
  258. }
  259. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  260. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  261. $cell_number ++;
  262. }
  263. $table->display();
  264. } // end function showtools2($cat)
  265. ?>