activity.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <?php // $Id: activity.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. * "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform"
  44. */
  45. function show_tools_category($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_STUDENT_VIEW:
  52. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE category = 'authoring' OR category = 'interaction' AND visibility = '1' ORDER BY id",__FILE__,__LINE__);
  53. $colLink ="##003399";
  54. break;
  55. case TOOL_AUTHORING:
  56. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE category = 'authoring' ORDER BY id",__FILE__,__LINE__);
  57. $colLink ="##003399";
  58. break;
  59. case TOOL_INTERACTION:
  60. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE category = 'interaction' ORDER BY id",__FILE__,__LINE__);
  61. $colLink ="##003399";
  62. break;
  63. case TOOL_ADMIN_VISIBLE:
  64. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE category = 'admin' AND visibility ='1' ORDER BY id",__FILE__,__LINE__);
  65. $colLink ="##003399";
  66. break;
  67. case TOOL_ADMIN_PLATEFORM:
  68. $result = api_sql_query("SELECT * FROM $course_tool_table WHERE category = 'admin' ORDER BY id",__FILE__,__LINE__);
  69. $colLink ="##003399";
  70. break;
  71. }
  72. while ($temp_row = mysql_fetch_array($result))
  73. {
  74. $all_tools_list[]=$temp_row;
  75. }
  76. $i=0;
  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_AUTHORING:
  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'";
  87. break;
  88. case TOOL_INTERACTION:
  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' ";
  93. break;
  94. case TOOL_STUDENT_VIEW:
  95. $sql_links="SELECT tl.*, tip.visibility
  96. FROM $course_link_table tl
  97. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  98. WHERE tl.on_homepage='1'";
  99. break;
  100. case TOOL_ADMIN:
  101. $sql_links="SELECT tl.*, tip.visibility
  102. FROM $course_link_table tl
  103. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  104. WHERE tl.on_homepage='1'";
  105. break;
  106. default:
  107. $sql_links = null;
  108. break;
  109. }
  110. //edit by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  111. if($sql_links != null)
  112. {
  113. $result_links = api_sql_query($sql_links,__FILE__,__LINE__);
  114. while($links_row = mysql_fetch_array($result_links))
  115. {
  116. unset($properties);
  117. $properties['name'] = $links_row['title'];
  118. $properties['link'] = $links_row['url'];
  119. $properties['visibility'] = $links_row['visibility'];
  120. $properties['image'] = ($links_row['visibility']== '0') ? "external_na.gif" : "external.gif";
  121. $properties['adminlink'] = api_get_path(WEB_CODE_PATH) . "link/link.php?action=editlink&id=".$links_row['id'];
  122. $tmp_all_tools_list[] = $properties;
  123. }
  124. }
  125. if(isset($tmp_all_tools_list))
  126. {
  127. foreach($tmp_all_tools_list as $toolsRow)
  128. {
  129. if($toolsRow['image'] == 'blog.gif')
  130. {
  131. // Init
  132. $tbl_blogs_rel_user = Database::get_course_table(BLOGS_REL_USER_TABLE);
  133. // Get blog id
  134. $blog_id = substr($toolsRow['link'], strrpos($toolsRow['link'], '=') + 1, strlen($toolsRow['link']));
  135. // Get blog members
  136. if(api_is_platform_admin())
  137. {
  138. $sql_blogs = "
  139. SELECT *
  140. FROM " . $tbl_blogs_rel_user . " `blogs_rel_user`
  141. WHERE `blog_id` = " . $blog_id;
  142. }
  143. else
  144. {
  145. $sql_blogs = "
  146. SELECT *
  147. FROM " . $tbl_blogs_rel_user . " `blogs_rel_user`
  148. WHERE
  149. `blog_id` = " . $blog_id . " AND
  150. `user_id` = " . api_get_user_id();
  151. }
  152. $result_blogs = api_sql_query($sql_blogs, __FILE__, __LINE__);
  153. if(mysql_num_rows($result_blogs) > 0)
  154. $all_tools_list[] = $toolsRow;
  155. }
  156. else
  157. $all_tools_list[] = $toolsRow;
  158. }
  159. }
  160. if(isset($all_tools_list))
  161. {
  162. foreach($all_tools_list as $toolsRow)
  163. {
  164. if(!($i%2))
  165. {echo "<tr valign=\"top\">\n";}
  166. // This part displays the links to hide or remove a tool.
  167. // These links are only visible by the course manager.
  168. unset($lnk);
  169. echo '<td width="50%">' . "\n";
  170. if(api_is_allowed_to_edit())
  171. {
  172. if($toolsRow['visibility'] == '1' && $toolsRow['admin'] !='1' && !strpos($toolsRow['link'],'learnpath_handler.php?learnpath_id'))
  173. {
  174. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/visible.gif" align="absmiddle" alt="'.get_lang("Deactivate").'"/>';
  175. $link['cmd'] = "hide=yes";
  176. $lnk[] = $link;
  177. }
  178. if($toolsRow['visibility'] == '0' && $toolsRow['admin'] !='1')
  179. {
  180. $link['name'] = '<img src="'.api_get_path(WEB_CODE_PATH).'img/invisible.gif" align="absmiddle" alt="'.get_lang("Activate").'"/>';
  181. $link['cmd'] = "restore=yes";
  182. $lnk[] = $link;
  183. }
  184. if($toolsRow['adminlink'])
  185. {
  186. echo '<a href="'.$toolsRow['adminlink'].'"><img src="'.api_get_path(WEB_CODE_PATH).'img/edit.gif" align="absmiddle" alt="'.get_lang("Edit").'"/></a>';
  187. }
  188. }
  189. if( api_is_platform_admin() )
  190. {
  191. if($toolsRow['admin'] !='1')
  192. {
  193. $link['cmd'] = "hide=yes";
  194. }
  195. }
  196. if(is_array($lnk))
  197. {
  198. foreach($lnk as $this_link)
  199. {
  200. if(!$toolsRow['adminlink'])
  201. {
  202. echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?".api_get_cidreq()."&amp;id=" . $toolsRow["id"] . "&amp;" . $this_link['cmd'] . "\">" . $this_link['name'] . "</a>";
  203. }
  204. }
  205. }
  206. else{ echo '&nbsp;&nbsp;&nbsp;&nbsp;';}
  207. // Allow editing of invisible homepage links (modified external_module)
  208. if($toolsRow["added_tool"] == 1 &&
  209. api_is_allowed_to_edit() && !$toolsRow["visibility"])
  210. echo "<a class=\"nobold\" href=\"" . api_get_path(WEB_PATH) .
  211. 'main/external_module/external_module.php' .
  212. "?".api_get_cidreq()."&amp;id=".$toolsRow["id"]."\">". get_lang("Edit"). "</a>";
  213. // NOTE : table contains only the image file name, not full path
  214. if(!stristr($toolsRow['link'], 'http://') && !stristr($toolsRow['link'], 'https://') && !stristr($toolsRow['link'],'ftp://'))
  215. $toolsRow['link'] = $web_code_path . $toolsRow['link'];
  216. if($toolsRow['visibility'] == '0' && $toolsRow['admin'] != '1')
  217. {
  218. $class="class=\"invisible\"";
  219. $info = pathinfo($toolsRow['image']);
  220. $basename = basename ($toolsRow['image'],'.'.$info['extension']); // $file is set to "index"
  221. $toolsRow['image'] = $basename.'_na.'.$info['extension'];
  222. }
  223. else
  224. $class='';
  225. $qm_or_amp = ((strpos($toolsRow['link'], '?') === FALSE) ? '?' : '&amp;');
  226. echo "\t" . ' &nbsp <a ' . $class . ' href="' . htmlspecialchars($toolsRow['link']) . '" target="' . $toolsRow['target'] . '">&nbsp;&nbsp;';
  227. echo '<img src="' . $web_code_path . 'img/' . $toolsRow['image'] . '" align="absmiddle" border="0" alt="' . $toolsRow['image'] . '" /> &nbsp;&nbsp;';
  228. echo ($toolsRow['image'] == 'external.gif' || $toolsRow['image'] == 'external_na.gif' || $toolsRow['image'] == 'scormbuilder.gif' || $toolsRow['image'] == 'blog.gif') ? ' '.htmlspecialchars(stripslashes($toolsRow['name'])) : ' '.get_lang($toolsRow['name']);
  229. echo "\t" . '</a>';
  230. echo '</td>';
  231. if($i%2)
  232. {
  233. echo "</tr>";
  234. }
  235. $i++;
  236. }
  237. }
  238. if($i%2)
  239. {
  240. echo "<td width=\"50%\">&nbsp;</td>\n",
  241. "</tr>\n";
  242. }
  243. }
  244. //End of functions show tools
  245. /*
  246. ==============================================================================
  247. MAIN CODE
  248. ==============================================================================
  249. */
  250. /*
  251. -----------------------------------------------------------
  252. Work with data post askable by admin of course (franglais, clean this)
  253. -----------------------------------------------------------
  254. */
  255. if(api_is_allowed_to_edit())
  256. {
  257. /* Work request */
  258. /*
  259. -----------------------------------------------------------
  260. Modify home page
  261. -----------------------------------------------------------
  262. */
  263. /*
  264. * display message to confirm that a tool must be hidden from the list of available tools
  265. * (visibility 0,1->2)
  266. */
  267. /*if($_GET["remove"])
  268. {
  269. $msgDestroy=get_lang('DelLk').'<br />';
  270. $msgDestroy.='<a href="'.$_SERVER['PHP_SELF'].'">'.get_lang('No').'</a>&nbsp;|&nbsp;';
  271. $msgDestroy.='<a href="'.$_SERVER['PHP_SELF'].'?destroy=yes&amp;id='.$_GET["id"].'">'.get_lang('Yes').'</a>';
  272. Display :: display_normal_message($msgDestroy);
  273. }*/
  274. /*
  275. * Process hiding a tools from available tools.
  276. * visibility=2 are only view by Dokeos Administrator (visibility 0,1->2)
  277. */
  278. /*elseif($_GET["destroy"])
  279. {
  280. api_sql_query("UPDATE $tool_table SET visibility='2' WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  281. }*/
  282. /*
  283. -----------------------------------------------------------
  284. HIDE
  285. -----------------------------------------------------------
  286. */
  287. if($_GET["hide"]) // visibility 1 -> 0
  288. {
  289. api_sql_query("UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  290. Display::display_confirmation_message(get_lang('ToolIsNowHidden'));
  291. }
  292. /*
  293. -----------------------------------------------------------
  294. REACTIVATE
  295. -----------------------------------------------------------
  296. */
  297. elseif($_GET["restore"]) // visibility 0,2 -> 1
  298. {
  299. api_sql_query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
  300. Display::display_confirmation_message(get_lang('ToolIsNowVisible'));
  301. }
  302. }
  303. // work with data post askable by admin of course
  304. if(api_is_platform_admin())
  305. {
  306. // Show message to confirm that a tools must be hide from available tools
  307. // visibility 0,1->2
  308. if($_GET["askDelete"])
  309. {
  310. ?>
  311. <div id="toolhide">
  312. <?php echo get_lang("DelLk")?>
  313. <br />&nbsp;&nbsp;&nbsp;
  314. <a href="<?php echo $_SERVER['PHP_SELF']?>"><?php echo get_lang("No")?></a>&nbsp;|&nbsp;
  315. <a href="<?php echo $_SERVER['PHP_SELF']?>?delete=yes&id=<?php echo $_GET["id"]?>"><?php echo get_lang("Yes")?></a>
  316. </div>
  317. <?php
  318. }
  319. /*
  320. * Process hiding a tools from available tools.
  321. */
  322. elseif(isset($_GET["delete"]) && $_GET["delete"])
  323. {
  324. api_sql_query("DELETE FROM $tool_table WHERE id='$id' AND added_tool=1",__FILE__,__LINE__);
  325. }
  326. }
  327. /*
  328. ==============================================================================
  329. COURSE ADMIN ONLY VIEW
  330. ==============================================================================
  331. */
  332. // start of tools for CourseAdmins (teachers/tutors)
  333. if(api_is_allowed_to_edit() && !api_is_platform_admin())
  334. {
  335. ?>
  336. <div class="courseadminview">
  337. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Authoring") ?></font></span>
  338. <table width="100%">
  339. <?php show_tools_category(TOOL_AUTHORING);?>
  340. </table>
  341. </div>
  342. <div class="courseadminview">
  343. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Interaction") ?></font></span>
  344. <table width="100%">
  345. <?php show_tools_category(TOOL_INTERACTION) ?>
  346. </table>
  347. </div>
  348. <div class="courseadminview">
  349. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Administration") ?></font></span>
  350. <table width="100%">
  351. <?php show_tools_category(TOOL_ADMIN_PLATEFORM) ?>
  352. </table>
  353. </div>
  354. <?php
  355. }
  356. /*
  357. -----------------------------------------------------------
  358. Tools for platform admin only
  359. -----------------------------------------------------------
  360. */
  361. elseif(api_is_platform_admin() || api_is_allowed_to_edit())
  362. {
  363. ?>
  364. <div class="courseadminview">
  365. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Authoring") ?></font></span>
  366. <table width="100%">
  367. <?php show_tools_category(TOOL_AUTHORING);?>
  368. </table>
  369. </div>
  370. <div class="courseadminview">
  371. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Interaction") ?></font></span>
  372. <table width="100%">
  373. <?php show_tools_category(TOOL_INTERACTION) ?>
  374. </table>
  375. </div>
  376. <div class="courseadminview">
  377. <span class="viewcaption"><font size="3" style="color:#FF9900;"><?php echo get_lang("Administration") ?></font></span>
  378. <table width="100%">
  379. <?php show_tools_category(TOOL_ADMIN_PLATEFORM) ?>
  380. </table>
  381. </div>
  382. <?php
  383. }
  384. /*
  385. ==============================================================================
  386. TOOLS AUTHORING
  387. ==============================================================================
  388. */
  389. else{
  390. ?>
  391. <div class="Authoringview">
  392. <table width="100%">
  393. <?php show_tools_category(TOOL_STUDENT_VIEW) ?>
  394. </table>
  395. </div>
  396. <?php
  397. }
  398. ?>