2column.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. global $charset;
  48. $web_code_path = api_get_path(WEB_CODE_PATH);
  49. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  50. switch ($course_tool_category)
  51. {
  52. case TOOL_PUBLIC:
  53. $result = Database::query("SELECT * FROM $course_tool_table WHERE visibility=1 ORDER BY id",__FILE__,__LINE__);
  54. $colLink ="##003399";
  55. break;
  56. case TOOL_PUBLIC_BUT_HIDDEN:
  57. $result = Database::query("SELECT * FROM $course_tool_table WHERE visibility=0 AND admin=0 ORDER BY id",__FILE__,__LINE__);
  58. $colLink ="##808080";
  59. break;
  60. case TOOL_COURSE_ADMIN:
  61. $result = Database::query("SELECT * FROM $course_tool_table WHERE admin=1 AND visibility != 2 ORDER BY id",__FILE__,__LINE__);
  62. $colLink ="##003399";
  63. break;
  64. case TOOL_PLATFORM_ADMIN:
  65. $result = Database::query("SELECT * FROM $course_tool_table WHERE visibility = 2 ORDER BY id",__FILE__,__LINE__);
  66. $colLink ="##003399";
  67. }
  68. $i=0;
  69. // grabbing all the tools from $course_tool_table
  70. while ($temp_row = Database::fetch_array($result))
  71. {
  72. if($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif')
  73. {
  74. $temp_row['image']=str_replace('.gif','_na.gif',$temp_row['image']);
  75. }
  76. $all_tools_list[]=$temp_row;
  77. }
  78. // grabbing all the links that have the property on_homepage set to 1
  79. $course_link_table = Database::get_course_table(TABLE_LINK);
  80. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  81. switch ($course_tool_category)
  82. {
  83. case TOOL_PUBLIC:
  84. $sql_links="SELECT tl.*, tip.visibility
  85. FROM $course_link_table tl
  86. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  87. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  88. break;
  89. case TOOL_PUBLIC_BUT_HIDDEN:
  90. $sql_links="SELECT tl.*, tip.visibility
  91. FROM $course_link_table tl
  92. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  93. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  94. break;
  95. default:
  96. $sql_links = null;
  97. break;
  98. }
  99. if( $sql_links != null )
  100. {
  101. $properties = array();
  102. $result_links=Database::query($sql_links,__FILE__,__LINE__);
  103. while ($links_row=Database::fetch_array($result_links))
  104. {
  105. unset($properties);
  106. $properties['name']=$links_row['title'];
  107. $properties['link']=$links_row['url'];
  108. $properties['visibility']=$links_row['visibility'];
  109. $properties['image']=($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)?"external_na.gif":"external.gif";
  110. $properties['adminlink']=api_get_path(WEB_CODE_PATH)."link/link.php?action=editlink&id=".$links_row['id'];
  111. $all_tools_list[]=$properties;
  112. }
  113. }
  114. if (isset($all_tools_list))
  115. {
  116. $lnk = array();
  117. foreach ($all_tools_list as $toolsRow)
  118. {
  119. if (api_get_session_id()!=0 && in_array($toolsRow['name'],array('course_maintenance','course_setting'))) {
  120. continue;
  121. }
  122. if (!($i%2))
  123. {
  124. echo "<tr valign=\"top\">\n";
  125. }
  126. // NOTE : table contains only the image file name, not full path
  127. if(!stristr($toolsRow['link'],'http://') && !stristr($toolsRow['link'],'https://') && !stristr($toolsRow['link'],'ftp://'))
  128. {
  129. $toolsRow['link']=$web_code_path.$toolsRow['link'];
  130. }
  131. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)
  132. {
  133. $class="class=\"invisible\"";
  134. }
  135. $qm_or_amp = ((strpos($toolsRow['link'],'?')===FALSE)?'?':'&amp;');
  136. $toolsRow['link'] = $toolsRow['link'];
  137. echo '<td width="50%" height="30">';
  138. if(strpos($toolsRow['name'],'visio_')!==false)
  139. {
  140. echo '<a '.$class.' href="javascript: void(0);" onclick="window.open(\'' . htmlspecialchars($toolsRow['link']).(($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif") ? '' : $qm_or_amp.api_get_cidreq()) . '\',\'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'] . '">';
  141. }
  142. else if(strpos($toolsRow['name'],'chat')!==false && api_get_course_setting('allow_open_chat_window')==true)
  143. {
  144. /*
  145. echo '<a href="#" onclick="window.open(\'' . htmlspecialchars($toolsRow['link']) .(($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif") ? '' : $qm_or_amp.api_get_cidreq()). '\',\'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.'>';
  146. */
  147. echo '<a href="javascript: void(0);" onclick="window.open(\'' . htmlspecialchars($toolsRow['link']).$qm_or_amp.api_get_cidreq() . '\',\'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.'>';
  148. }
  149. else
  150. {
  151. echo '<a href="'. htmlspecialchars($toolsRow['link']).(($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif") ? '' : $qm_or_amp.api_get_cidreq()).'" target="' , $toolsRow['target'], '" '.$class.'>';
  152. }
  153. /*
  154. echo Display::return_icon($toolsRow['image'], get_lang(ucfirst($toolsRow['name']))),'&nbsp;', ($toolsRow['image']=="external.gif" || $toolsRow['image']=="external_na.gif" || $toolsRow['image']=="scormbuilder.gif" || $toolsRow['image']=="blog.gif") ? htmlspecialchars( $toolsRow['name'],ENT_QUOTES,$charset) : get_lang(ucfirst($toolsRow['name'])),'</a>';
  155. */
  156. if ($toolsRow['image'] == 'file_html.gif' || $toolsRow['image'] == 'file_html_na.gif'
  157. || $toolsRow['image'] == 'scormbuilder.gif' || $toolsRow['image'] == 'scormbuilder_na.gif'
  158. || $toolsRow['image'] == 'blog.gif' || $toolsRow['image'] == 'blog_na.gif'
  159. || $toolsRow['image'] == 'external.gif' || $toolsRow['image'] == 'external_na.gif')
  160. {
  161. $tool_name = htmlspecialchars($toolsRow['name'], ENT_QUOTES, $charset);
  162. }
  163. else
  164. {
  165. $tool_name = get_lang(ucfirst($toolsRow['name']));
  166. }
  167. echo Display::return_icon($toolsRow['image'], $tool_name),'&nbsp;', $tool_name,'</a>';
  168. // This part displays the links to hide or remove a tool.
  169. // These links are only visible by the course manager.
  170. unset($lnk);
  171. if (api_is_allowed_to_edit())
  172. {
  173. if ($toolsRow["visibility"] == '1')
  174. {
  175. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'));
  176. $link['cmd'] = "hide=yes";
  177. $lnk[] = $link;
  178. }
  179. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN)
  180. {
  181. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
  182. $link['cmd'] = "restore=yes";
  183. $lnk[] = $link;
  184. if($toolsRow["added_tool"] == 1)
  185. {
  186. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  187. $link['cmd'] = "remove=yes";
  188. $lnk[] = $link;
  189. }
  190. }
  191. if ($toolsRow['adminlink'])
  192. {
  193. echo '<a href="'.$toolsRow['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  194. //echo "edit link:".$properties['adminlink'];
  195. }
  196. }
  197. if ( api_is_platform_admin() )
  198. {
  199. if ($toolsRow["visibility"]==2)
  200. {
  201. $link['name'] = Display::return_icon('undelete.gif', get_lang('Activate'));
  202. $link['cmd'] = "hide=yes";
  203. $lnk[] = $link;
  204. if($toolsRow["added_tool"] == 1)
  205. {
  206. $link['name'] = get_lang("Delete");
  207. $link['cmd'] = "askDelete=yes";
  208. $lnk[] = $link;
  209. }
  210. }
  211. if ($toolsRow["visibility"] == 0 && $toolsRow["added_tool"] == 0)
  212. {
  213. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  214. $link['cmd'] = "remove=yes";
  215. $lnk[] = $link;
  216. }
  217. }
  218. if (is_array($lnk))
  219. {
  220. foreach($lnk as $this_link)
  221. {
  222. if (!$toolsRow['adminlink'])
  223. {
  224. echo "<a href=\"" .api_get_self(). "?".api_get_cidreq()."&amp;id=" . $toolsRow["id"] . "&amp;" . $this_link['cmd'] . "\">" . $this_link['name'] . "</a>";
  225. }
  226. }
  227. }
  228. // Allow editing of invisible homepage links (modified external_module)
  229. /*
  230. if ($toolsRow["added_tool"] == 1 &&
  231. api_is_allowed_to_edit() && !$toolsRow["visibility"])
  232. */
  233. if ($toolsRow["added_tool"] == 1 && api_is_allowed_to_edit() && !$toolsRow["visibility"]
  234. && $toolsRow['image'] != 'scormbuilder.gif' && $toolsRow['image'] != 'scormbuilder_na.gif')
  235. echo "<a class=\"nobold\" href=\"" . api_get_path(WEB_PATH) .
  236. 'main/external_module/external_module.php' .
  237. "?".api_get_cidreq()."&amp;id=".$toolsRow["id"]."\">". get_lang("Edit"). "</a>";
  238. echo "</td>\n";
  239. if($i%2)
  240. {
  241. echo "</tr>\n";
  242. }
  243. $i++;
  244. }
  245. }
  246. if($i%2)
  247. {
  248. echo "<td width=\"50%\">&nbsp;</td>\n",
  249. "</tr>\n";
  250. }
  251. }
  252. /*
  253. ==============================================================================
  254. MAIN CODE
  255. ==============================================================================
  256. */
  257. /*
  258. -----------------------------------------------------------
  259. Work with data post askable by admin of course (franglais, clean this)
  260. -----------------------------------------------------------
  261. */
  262. if (api_is_allowed_to_edit())
  263. {
  264. /* Work request */
  265. /*
  266. -----------------------------------------------------------
  267. Modify home page
  268. -----------------------------------------------------------
  269. */
  270. /*
  271. * display message to confirm that a tool must be hidden from the list of available tools
  272. * (visibility 0,1->2)
  273. */
  274. if($_GET["remove"])
  275. {
  276. $msgDestroy=get_lang('DelLk').'<br />';
  277. $msgDestroy.='<a href="'.api_get_self().'">'.get_lang('No').'</a>&nbsp;|&nbsp;';
  278. $msgDestroy.='<a href="'.api_get_self().'?destroy=yes&amp;id='.$_GET["id"].'">'.get_lang('Yes').'</a>';
  279. Display :: display_confirmation_message($msgDestroy,false);
  280. }
  281. /*
  282. * Process hiding a tools from available tools.
  283. * visibility=2 are only view by Dokeos Administrator (visibility 0,1->2)
  284. */
  285. elseif ($_GET["destroy"])
  286. {
  287. Database::query("UPDATE $tool_table SET visibility='2' WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  288. }
  289. /*
  290. -----------------------------------------------------------
  291. HIDE
  292. -----------------------------------------------------------
  293. */
  294. elseif ($_GET["hide"]) // visibility 1 -> 0
  295. {
  296. Database::query("UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  297. Display::display_confirmation_message(get_lang('ToolIsNowHidden'));
  298. }
  299. /*
  300. -----------------------------------------------------------
  301. REACTIVATE
  302. -----------------------------------------------------------
  303. */
  304. elseif ($_GET["restore"]) // visibility 0,2 -> 1
  305. {
  306. Database::query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  307. Display::display_confirmation_message(get_lang('ToolIsNowVisible'));
  308. }
  309. }
  310. // work with data post askable by admin of course
  311. if (api_is_platform_admin())
  312. {
  313. // Show message to confirm that a tools must be hide from available tools
  314. // visibility 0,1->2
  315. if($_GET["askDelete"])
  316. {
  317. ?>
  318. <div id="toolhide">
  319. <?php echo get_lang("DelLk"); ?>
  320. <br />&nbsp;&nbsp;&nbsp;
  321. <a href="<?php echo api_get_self(); ?>"><?php echo get_lang("No"); ?></a>&nbsp;|&nbsp;
  322. <a href="<?php echo api_get_self(); ?>?delete=yes&id=<?php echo $_GET["id"]; ?>"><?php echo get_lang("Yes"); ?></a>
  323. </div>
  324. <?php
  325. }
  326. /*
  327. * Process hiding a tools from available tools.
  328. * visibility=2 are only view by Dokeos Administrator visibility 0,1->2
  329. */
  330. elseif (isset($_GET["delete"]) && $_GET["delete"])
  331. {
  332. Database::query("DELETE FROM $tool_table WHERE id='$id' AND added_tool=1",__FILE__,__LINE__);
  333. }
  334. }
  335. /*
  336. ==============================================================================
  337. TOOLS VISIBLE FOR EVERYBODY
  338. ==============================================================================
  339. */
  340. echo "<div class=\"everybodyview\">";
  341. echo "<table width=\"100%\">";
  342. show_tools(TOOL_PUBLIC);
  343. echo "</table>";
  344. echo "</div>";
  345. /*
  346. ==============================================================================
  347. COURSE ADMIN ONLY VIEW
  348. ==============================================================================
  349. */
  350. // start of tools for CourseAdmins (teachers/tutors)
  351. if (api_is_allowed_to_edit())
  352. {
  353. echo "<div class=\"courseadminview\">";
  354. echo "<span class=\"viewcaption\">";
  355. echo get_lang("CourseAdminOnly");
  356. echo "</span>";
  357. echo "<table width=\"100%\">";
  358. show_tools(TOOL_COURSE_ADMIN);
  359. /*
  360. -----------------------------------------------------------
  361. INACTIVE TOOLS - HIDDEN (GREY) LINKS
  362. -----------------------------------------------------------
  363. */
  364. echo "<tr><td colspan=\"4\"><hr style='color:\"#4171B5\"' noshade=\"noshade\" size=\"1\" /></td></tr>\n",
  365. "<tr>\n",
  366. "<td colspan=\"4\">\n",
  367. "<div style=\"margin-bottom: 10px;\"><font color=\"#808080\">\n",get_lang("InLnk"),"</font></div>",
  368. "</td>\n",
  369. "</tr>\n";
  370. show_tools(TOOL_PUBLIC_BUT_HIDDEN);
  371. echo "</table>";
  372. echo "</div> ";
  373. }
  374. /*
  375. -----------------------------------------------------------
  376. Tools for platform admin only
  377. -----------------------------------------------------------
  378. */
  379. if (api_is_platform_admin() && api_is_allowed_to_edit())
  380. {
  381. ?>
  382. <div class="platformadminview">
  383. <span class="viewcaption"><?php echo get_lang("PlatformAdminOnly"); ?></span>
  384. <table width="100%">
  385. <?php
  386. show_tools(TOOL_PLATFORM_ADMIN);
  387. ?>
  388. </table>
  389. </div>
  390. <?php
  391. }
  392. ?>