2column.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <?php // $Id: 2column.php,v 1.5 2006/08/10 14:34:54 pcool Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University
  7. Copyright (c) 2001 Universite Catholique de Louvain
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * HOME PAGE FOR EACH COURSE
  23. *
  24. * This page, included in every course's index.php is the home
  25. * page. To make administration simple, the teacher edits his
  26. * course from the home page. Only the login detects that the
  27. * visitor is allowed to activate, deactivate home page links,
  28. * access to the teachers tools (statistics, edit forums...).
  29. *
  30. * @package dokeos.course_home
  31. ==============================================================================
  32. */
  33. /*
  34. ==============================================================================
  35. FUNCTIONS
  36. ==============================================================================
  37. */
  38. /**
  39. * Displays the tools of a certain category.
  40. *
  41. * @return void
  42. * @param string $course_tool_category contains the category of tools to display:
  43. * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
  44. */
  45. function show_tools($course_tool_category)
  46. {
  47. $web_code_path = api_get_path(WEB_CODE_PATH);
  48. $course_tool_table = Database::get_course_table(TOOL_LIST_TABLE);
  49. switch ($course_tool_category)
  50. {
  51. case TOOL_PUBLIC:
  52. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE visibility=1 ORDER BY id",__FILE__,__LINE__);
  53. $colLink ="##003399";
  54. break;
  55. case TOOL_PUBLIC_BUT_HIDDEN:
  56. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE visibility=0 AND admin=0 ORDER BY id",__FILE__,__LINE__);
  57. $colLink ="##808080";
  58. break;
  59. case TOOL_COURSE_ADMIN:
  60. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE admin=1 AND visibility != 2 ORDER BY id",__FILE__,__LINE__);
  61. $colLink ="##003399";
  62. break;
  63. case TOOL_PLATFORM_ADMIN:
  64. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE visibility = 2 ORDER BY id",__FILE__,__LINE__);
  65. $colLink ="##003399";
  66. }
  67. $i=0;
  68. // grabbing all the tools from $course_tool_table
  69. while ($temp_row = mysql_fetch_array($result))
  70. {
  71. if($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif')
  72. {
  73. $temp_row['image']=str_replace('.gif','_na.gif',$temp_row['image']);
  74. }
  75. $all_tools_list[]=$temp_row;
  76. }
  77. // grabbing all the links that have the property on_homepage set to 1
  78. $course_link_table = Database::get_course_table(LINK_TABLE);
  79. $course_item_property_table = Database::get_course_table(ITEM_PROPERTY_TABLE);
  80. switch ($course_tool_category)
  81. {
  82. case TOOL_PUBLIC:
  83. $sql_links="SELECT tl.*, tip.visibility
  84. FROM $course_link_table tl
  85. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  86. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  87. break;
  88. case TOOL_PUBLIC_BUT_HIDDEN:
  89. $sql_links="SELECT tl.*, tip.visibility
  90. FROM $course_link_table tl
  91. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  92. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  93. break;
  94. default:
  95. $sql_links = null;
  96. break;
  97. }
  98. if( $sql_links != null )
  99. {
  100. $result_links=api_sql_query($sql_links,__FILE__,__LINE__);
  101. while ($links_row=mysql_fetch_array($result_links))
  102. {
  103. unset($properties);
  104. $properties['name']=$links_row['title'];
  105. $properties['link']=$links_row['url'];
  106. $properties['visibility']=$links_row['visibility'];
  107. $properties['image']=($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)?"external_na.gif":"external.gif";
  108. $properties['adminlink']=api_get_path(WEB_CODE_PATH)."link/link.php?action=editlink&id=".$links_row['id'];
  109. $all_tools_list[]=$properties;
  110. }
  111. }
  112. if (isset($all_tools_list))
  113. {
  114. foreach ($all_tools_list as $toolsRow)
  115. {
  116. if (!($i%2))
  117. {
  118. echo "<tr valign=\"top\">\n";
  119. }
  120. // NOTE : table contains only the image file name, not full path
  121. if(!stristr($toolsRow['link'],'http://') && !stristr($toolsRow['link'],'https://') && !stristr($toolsRow['link'],'ftp://'))
  122. {
  123. $toolsRow['link']=$web_code_path.$toolsRow['link'];
  124. }
  125. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)
  126. {
  127. $class="class=\"invisible\"";
  128. }
  129. $qm_or_amp = ((strpos($toolsRow['link'],'?')===FALSE)?'?':'&amp;');
  130. echo '<td width="50%" height="30">', "\n",
  131. '<a href="', htmlspecialchars($toolsRow['link'])
  132. .(($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif") ? '' : $qm_or_amp.api_get_cidreq()),
  133. '" target="' , $toolsRow['target'], '" '.$class.'>',
  134. '<img src="', $web_code_path, 'img/',
  135. $toolsRow['image'], '" align="absmiddle" border="0" alt="', $toolsRow['image'],'" />',
  136. '&nbsp;', ($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif" || $toolsRow['image']=="scormbuilder.gif") ? htmlspecialchars( $toolsRow['name']) : get_lang($toolsRow['name']),
  137. "</a>\n ";
  138. // This part displays the links to hide or remove a tool.
  139. // These links are only visible by the course manager.
  140. unset($lnk);
  141. if (api_is_allowed_to_edit())
  142. {
  143. if ($toolsRow["visibility"] == '1' && !strpos($toolsRow['link'],'learnpath_handler.php?learnpath_id'))
  144. {
  145. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/visible.gif" align="absmiddle" alt="'.get_lang("Deactivate").'"/>';
  146. $link['cmd'] = "hide=yes";
  147. $lnk[] = $link;
  148. }
  149. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)
  150. {
  151. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/invisible.gif" align="absmiddle" alt="'.get_lang("Activate").'"/>';
  152. $link['cmd'] = "restore=yes";
  153. $lnk[] = $link;
  154. if($toolsRow["added_tool"] == 1)
  155. {
  156. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/delete.gif" align="absmiddle" alt="'.get_lang("Remove").'"/>';
  157. $link['cmd'] = "remove=yes";
  158. $lnk[] = $link;
  159. }
  160. }
  161. if ($toolsRow['adminlink'])
  162. {
  163. echo '<a href="'.$toolsRow['adminlink'].'"><img src="'.api_get_path(WEB_CODE_PATH).'img/edit.gif" align="absmiddle" alt="'.get_lang("Edit").'"/></a>';
  164. //echo "edit link:".$properties['adminlink'];
  165. }
  166. }
  167. if ( api_is_platform_admin() )
  168. {
  169. if ($toolsRow["visibility"]==2)
  170. {
  171. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/undelete.gif" align="absmiddle" alt="'.get_lang("Activate").'"/>';
  172. $link['cmd'] = "hide=yes";
  173. $lnk[] = $link;
  174. if($toolsRow["added_tool"] == 1)
  175. {
  176. $link['name'] = get_lang("Delete");
  177. $link['cmd'] = "askDelete=yes";
  178. $lnk[] = $link;
  179. }
  180. }
  181. if ($toolsRow["visibility"] == 0 && $toolsRow["added_tool"] == 0)
  182. {
  183. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/delete.gif" align="absmiddle" alt="'.get_lang("Remove").'"/>';
  184. $link['cmd'] = "remove=yes";
  185. $lnk[] = $link;
  186. }
  187. }
  188. if (is_array($lnk))
  189. {
  190. foreach($lnk as $this_link)
  191. {
  192. if (!$toolsRow['adminlink'])
  193. {
  194. echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?".api_get_cidreq()."&amp;id=" . $toolsRow["id"] . "&amp;" . $this_link['cmd'] . "\">" . $this_link['name'] . "</a>";
  195. }
  196. }
  197. }
  198. // Allow editing of invisible homepage links (modified external_module)
  199. if ($toolsRow["added_tool"] == 1 &&
  200. api_is_allowed_to_edit() && !$toolsRow["visibility"])
  201. echo "<a class=\"nobold\" href=\"" . api_get_path(WEB_PATH) .
  202. 'main/external_module/external_module.php' .
  203. "?".api_get_cidreq()."&amp;id=".$toolsRow["id"]."\">". get_lang("Edit"). "</a>";
  204. echo "</td>\n";
  205. if($i%2)
  206. {
  207. echo "</tr>\n";
  208. }
  209. $i++;
  210. }
  211. }
  212. if($i%2)
  213. {
  214. echo "<td width=\"50%\">&nbsp;</td>\n",
  215. "</tr>\n";
  216. }
  217. }
  218. /*
  219. ==============================================================================
  220. MAIN CODE
  221. ==============================================================================
  222. */
  223. /*
  224. -----------------------------------------------------------
  225. Work with data post askable by admin of course (franglais, clean this)
  226. -----------------------------------------------------------
  227. */
  228. if (api_is_allowed_to_edit())
  229. {
  230. /* Work request */
  231. /*
  232. -----------------------------------------------------------
  233. Modify home page
  234. -----------------------------------------------------------
  235. */
  236. /*
  237. * display message to confirm that a tool must be hidden from the list of available tools
  238. * (visibility 0,1->2)
  239. */
  240. if($_GET["remove"])
  241. {
  242. $msgDestroy=get_lang('DelLk').'<br />';
  243. $msgDestroy.='<a href="'.$_SERVER['PHP_SELF'].'">'.get_lang('No').'</a>&nbsp;|&nbsp;';
  244. $msgDestroy.='<a href="'.$_SERVER['PHP_SELF'].'?destroy=yes&amp;id='.$_GET["id"].'">'.get_lang('Yes').'</a>';
  245. Display :: display_confirmation_message($msgDestroy);
  246. }
  247. /*
  248. * Process hiding a tools from available tools.
  249. * visibility=2 are only view by Dokeos Administrator (visibility 0,1->2)
  250. */
  251. elseif ($_GET["destroy"])
  252. {
  253. api_sql_query("UPDATE $tool_table SET visibility='2' WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  254. }
  255. /*
  256. -----------------------------------------------------------
  257. HIDE
  258. -----------------------------------------------------------
  259. */
  260. elseif ($_GET["hide"]) // visibility 1 -> 0
  261. {
  262. api_sql_query("UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  263. Display::display_confirmation_message(get_lang('ToolIsNowHidden'));
  264. }
  265. /*
  266. -----------------------------------------------------------
  267. REACTIVATE
  268. -----------------------------------------------------------
  269. */
  270. elseif ($_GET["restore"]) // visibility 0,2 -> 1
  271. {
  272. api_sql_query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  273. Display::display_confirmation_message(get_lang('ToolIsNowVisible'));
  274. }
  275. }
  276. // work with data post askable by admin of course
  277. if (api_is_platform_admin())
  278. {
  279. // Show message to confirm that a tools must be hide from available tools
  280. // visibility 0,1->2
  281. if($_GET["askDelete"])
  282. {
  283. ?>
  284. <div id="toolhide">
  285. <?php echo get_lang("DelLk"); ?>
  286. <br />&nbsp;&nbsp;&nbsp;
  287. <a href="<?php echo $_SERVER['PHP_SELF']; ?>"><?php echo get_lang("No"); ?></a>&nbsp;|&nbsp;
  288. <a href="<?php echo $_SERVER['PHP_SELF']; ?>?delete=yes&id=<?php echo $_GET["id"]; ?>"><?php echo get_lang("Yes"); ?></a>
  289. </div>
  290. <?php
  291. }
  292. /*
  293. * Process hiding a tools from available tools.
  294. * visibility=2 are only view by Dokeos Administrator visibility 0,1->2
  295. */
  296. elseif (isset($_GET["delete"]) && $_GET["delete"])
  297. {
  298. api_sql_query("DELETE FROM $tool_table WHERE id='$id' AND added_tool=1",__FILE__,__LINE__);
  299. }
  300. }
  301. /*
  302. ==============================================================================
  303. TOOLS VISIBLE FOR EVERYBODY
  304. ==============================================================================
  305. */
  306. echo "<div class=\"everybodyview\">";
  307. echo "<table width=\"100%\">";
  308. show_tools(TOOL_PUBLIC);
  309. echo "</table>";
  310. echo "</div>";
  311. /*
  312. ==============================================================================
  313. COURSE ADMIN ONLY VIEW
  314. ==============================================================================
  315. */
  316. // start of tools for CourseAdmins (teachers/tutors)
  317. if (api_is_allowed_to_edit())
  318. {
  319. echo "<div class=\"courseadminview\">";
  320. echo "<span class=\"viewcaption\">";
  321. echo get_lang("CourseAdminOnly");
  322. echo "</span>";
  323. echo "<table width=\"100%\">";
  324. show_tools(TOOL_COURSE_ADMIN);
  325. /*
  326. -----------------------------------------------------------
  327. INACTIVE TOOLS - HIDDEN (GREY) LINKS
  328. -----------------------------------------------------------
  329. */
  330. echo "<tr><td colspan=\"4\"><hr style='color:\"#4171B5\"' noshade=\"noshade\" size=\"1\" /></td></tr>\n",
  331. "<tr>\n",
  332. "<td colspan=\"4\">\n",
  333. "<div style=\"margin-bottom: 10px;\"><font color=\"#808080\">\n",get_lang("InLnk"),"</font></div>",
  334. "</td>\n",
  335. "</tr>\n";
  336. show_tools(TOOL_PUBLIC_BUT_HIDDEN);
  337. echo "</table>";
  338. echo "</div> ";
  339. }
  340. /*
  341. -----------------------------------------------------------
  342. Tools for platform admin only
  343. -----------------------------------------------------------
  344. */
  345. if (api_is_platform_admin() && api_is_allowed_to_edit())
  346. {
  347. ?>
  348. <div class="platformadminview">
  349. <span class="viewcaption"><?php echo get_lang("PlatformAdminOnly"); ?></span>
  350. <table width="100%">
  351. <?php
  352. show_tools(TOOL_PLATFORM_ADMIN);
  353. ?>
  354. </table>
  355. </div>
  356. <?php
  357. }
  358. ?>