activity.php 16 KB

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