activity.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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. require_once '../../main/inc/global.inc.php';
  34. /*
  35. ==============================================================================
  36. FUNCTIONS
  37. ==============================================================================
  38. */
  39. /**
  40. * Gets the tools of a certain category. Returns an array expected
  41. * by show_tools_category()
  42. * @param string $course_tool_category contains the category of tools to
  43. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform"
  44. * @return array
  45. */
  46. function get_tools_category($course_tool_category) {
  47. global $_user;
  48. $web_code_path = api_get_path(WEB_CODE_PATH);
  49. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  50. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  51. $is_platform_admin = api_is_platform_admin();
  52. $all_tools_list = array();
  53. //condition for the session
  54. $session_id = api_get_session_id();
  55. $condition_session = api_get_session_condition($session_id,true,true);
  56. switch ($course_tool_category) {
  57. case TOOL_STUDENT_VIEW:
  58. //$visibility_codition = !api_is_coach()?" visibility = '1' AND ":" ";
  59. $sql = "SELECT * FROM $course_tool_table WHERE visibility = '1' AND (category = 'authoring' OR category = 'interaction') $condition_session ORDER BY id";
  60. $result = Database::query($sql,__FILE__,__LINE__);
  61. $colLink ="##003399";
  62. break;
  63. case TOOL_AUTHORING:
  64. $sql = "SELECT * FROM $course_tool_table WHERE category = 'authoring' $condition_session ORDER BY id";
  65. $result = Database::query($sql,__FILE__,__LINE__);
  66. $colLink ="##003399";
  67. break;
  68. case TOOL_INTERACTION:
  69. $sql = "SELECT * FROM $course_tool_table WHERE category = 'interaction' $condition_session ORDER BY id";
  70. $result = Database::query($sql,__FILE__,__LINE__);
  71. $colLink ="##003399";
  72. break;
  73. case TOOL_ADMIN_VISIBLE:
  74. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' AND visibility ='1' $condition_session ORDER BY id";
  75. $result = Database::query($sql,__FILE__,__LINE__);
  76. $colLink ="##003399";
  77. break;
  78. case TOOL_ADMIN_PLATEFORM:
  79. $sql = "SELECT * FROM $course_tool_table WHERE category = 'admin' $condition_session ORDER BY id";
  80. $result = Database::query($sql,__FILE__,__LINE__);
  81. $colLink ="##003399";
  82. break;
  83. }
  84. while ($temp_row = Database::fetch_array($result)) {
  85. $all_tools_list[]=$temp_row;
  86. }
  87. /*if(api_is_course_coach())
  88. {
  89. $result = Database::query("SELECT * FROM $course_tool_table WHERE name='tracking'",__FILE__,__LINE__);
  90. $all_tools_list[]=Database :: fetch_array($result);
  91. }*/
  92. $i=0;
  93. // grabbing all the links that have the property on_homepage set to 1
  94. $course_link_table = Database::get_course_table(TABLE_LINK);
  95. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  96. switch ($course_tool_category) {
  97. case TOOL_AUTHORING:
  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' $condition_session";
  102. break;
  103. case TOOL_INTERACTION:
  104. $sql_links = null;
  105. /*
  106. $sql_links="SELECT tl.*, tip.visibility
  107. FROM $course_link_table tl
  108. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  109. WHERE tl.on_homepage='1' ";
  110. */
  111. break;
  112. case TOOL_STUDENT_VIEW:
  113. $sql_links="SELECT tl.*, tip.visibility
  114. FROM $course_link_table tl
  115. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  116. WHERE tl.on_homepage='1' $condition_session";
  117. break;
  118. case TOOL_ADMIN:
  119. $sql_links="SELECT tl.*, tip.visibility
  120. FROM $course_link_table tl
  121. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  122. WHERE tl.on_homepage='1' $condition_session";
  123. break;
  124. default:
  125. $sql_links = null;
  126. break;
  127. }
  128. //edit by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  129. if ($sql_links != null) {
  130. $result_links = Database::query($sql_links,__FILE__,__LINE__);
  131. $properties = array();
  132. if (Database::num_rows($result_links) > 0) {
  133. while ($links_row = Database::fetch_array($result_links)) {
  134. unset($properties);
  135. $properties['name'] = $links_row['title'];
  136. $properties['session_id'] = $links_row['session_id'];
  137. $properties['link'] = $links_row['url'];
  138. $properties['visibility'] = $links_row['visibility'];
  139. $properties['image'] = ($links_row['visibility']== '0') ? "file_html.gif" : "file_html.gif";
  140. $properties['adminlink'] = api_get_path(WEB_CODE_PATH) . "link/link.php?action=editlink&id=".$links_row['id'];
  141. $properties['target'] = $links_row['target'];
  142. $tmp_all_tools_list[] = $properties;
  143. }
  144. }
  145. }
  146. if (isset($tmp_all_tools_list)) {
  147. foreach ($tmp_all_tools_list as $toolsRow) {
  148. if ($toolsRow['image'] == 'blog.gif') {
  149. // Init
  150. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  151. // Get blog id
  152. $blog_id = substr($toolsRow['link'], strrpos($toolsRow['link'], '=') + 1, strlen($toolsRow['link']));
  153. // Get blog members
  154. if($is_platform_admin) {
  155. $sql_blogs = "
  156. SELECT *
  157. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  158. WHERE blog_id = " . $blog_id;
  159. } else {
  160. $sql_blogs = "
  161. SELECT *
  162. FROM " . $tbl_blogs_rel_user . " blogs_rel_user
  163. WHERE
  164. blog_id = " . $blog_id . " AND
  165. user_id = " . api_get_user_id();
  166. }
  167. $result_blogs = Database::query($sql_blogs, __FILE__, __LINE__);
  168. if (Database::num_rows($result_blogs) > 0) {
  169. $all_tools_list[] = $toolsRow;
  170. }
  171. } else {
  172. $all_tools_list[] = $toolsRow;
  173. }
  174. }
  175. }
  176. return $all_tools_list;
  177. }
  178. /**
  179. * Displays the tools of a certain category.
  180. * @param array List of tools as returned by get_tools_category()
  181. * @return void
  182. */
  183. function show_tools_category($all_tools_list)
  184. {
  185. global $_user;
  186. $web_code_path = api_get_path(WEB_CODE_PATH);
  187. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  188. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  189. $is_platform_admin = api_is_platform_admin();
  190. if (isset($all_tools_list)) {
  191. $lnk = '';
  192. foreach ($all_tools_list as $toolsRow) {
  193. if (api_get_session_id()!=0 && in_array($toolsRow['name'],array('course_maintenance','course_setting'))) {
  194. continue;
  195. }
  196. if (!($i%2)) {
  197. echo "<tr valign=\"top\">\n";
  198. }
  199. // This part displays the links to hide or remove a tool.
  200. // These links are only visible by the course manager.
  201. unset($lnk);
  202. echo '<td width="50%">' . "\n";
  203. if ($is_allowed_to_edit && !api_is_coach()) {
  204. if ($toolsRow['visibility'] == '1' && $toolsRow['admin'] !='1') {
  205. $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'),array('id'=>'linktool_'.$toolsRow["id"]));
  206. $link['cmd'] = "hide=yes";
  207. $lnk[] = $link;
  208. }
  209. if ($toolsRow['visibility'] == '0' && $toolsRow['admin'] !='1') {
  210. $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'),array('id'=>'linktool_'.$toolsRow["id"]));
  211. $link['cmd'] = "restore=yes";
  212. $lnk[] = $link;
  213. }
  214. if (!empty($toolsRow['adminlink'])) {
  215. echo '<a href="'.$toolsRow['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  216. }
  217. }
  218. // Both checks are necessary as is_platform_admin doesn't take student view into account
  219. if ($is_platform_admin && $is_allowed_to_edit) {
  220. if ($toolsRow['admin'] !='1') {
  221. $link['cmd'] = "hide=yes";
  222. }
  223. }
  224. if (isset($lnk) && is_array($lnk)) {
  225. foreach ($lnk as $this_link) {
  226. if (empty($toolsRow['adminlink'])) {
  227. echo "<a class=\"make_visible_and_invisible\" href=\"" .api_get_self(). "?".api_get_cidreq()."&amp;id=" . $toolsRow["id"] . "&amp;" . $this_link['cmd'] . "\">" . $this_link['name'] . "</a>";
  228. //echo "<a class=\"make_visible_and_invisible\" href=\"javascript:void(0)\" >" . $this_link['name'] . "</a>";
  229. }
  230. }
  231. } else { echo '&nbsp;&nbsp;&nbsp;&nbsp;';}
  232. // NOTE : table contains only the image file name, not full path
  233. if (!stristr($toolsRow['link'], 'http://')
  234. && !stristr($toolsRow['link'], 'https://')
  235. && !stristr($toolsRow['link'],'ftp://')) {
  236. $toolsRow['link'] = $web_code_path . $toolsRow['link'];
  237. }
  238. if ($toolsRow['visibility'] == '0' && $toolsRow['admin'] != '1') {
  239. $class="class=\"invisible\"";
  240. $info = pathinfo($toolsRow['image']);
  241. $basename = basename ($toolsRow['image'],'.'.$info['extension']); // $file is set to "index"
  242. $toolsRow['image'] = $basename.'_na.'.$info['extension'];
  243. } else {
  244. $class='';
  245. }
  246. $qm_or_amp = ((strpos($toolsRow['link'], '?') === FALSE) ? '?' : '&amp;');
  247. //If it's a link, we don't add the cidReq
  248. if ($toolsRow['image'] == 'file_html.gif' || $toolsRow['image'] == 'file_html_na.gif') {
  249. $toolsRow['link'] = $toolsRow['link'].$qm_or_amp;
  250. } else {
  251. $toolsRow['link'] = $toolsRow['link'].$qm_or_amp.api_get_cidreq();
  252. }
  253. if (strpos($toolsRow['name'],'visio_')!==false) {
  254. /*
  255. $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'] . '">';
  256. */
  257. $toollink = "\t" . '<a id="tooldesc_'.$toolsRow["id"].'" ' . $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'] . '">';
  258. $my_tool_link = "\t" . '<a id="istooldesc_'.$toolsRow["id"].'" ' . $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'] . '">';
  259. } elseif (strpos($toolsRow['name'],'chat')!==false && api_get_course_setting('allow_open_chat_window')==true) {
  260. /*
  261. $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'] . '">';
  262. */
  263. $toollink = "\t" . '<a id="tooldesc_'.$toolsRow["id"].'" ' . $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'] . '">';
  264. $my_tool_link="\t" . '<a id="istooldesc_'.$toolsRow["id"].'" ' . $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'] . '">';
  265. } else {
  266. if (count(explode('type=classroom',$toolsRow['link']))==2 || count(explode('type=conference',$toolsRow['link']))==2) {
  267. //$toollink = "\t" . '<a ' . $class . ' href="' . $toolsRow['link'] . '" target="_blank">';
  268. $toollink = "\t" . '<a id="tooldesc_'.$toolsRow["id"].'" ' . $class . ' href="' . $toolsRow['link'] . '" target="_blank">';
  269. $my_tool_link = "\t" . '<a id="istooldesc_'.$toolsRow["id"].'" ' . $class . ' href="' . $toolsRow['link'] . '" target="_blank">';
  270. } else {
  271. //$toollink = "\t" . '<a ' . $class . ' href="' . htmlspecialchars($toolsRow['link']) . '" target="' . $toolsRow['target'] . '">';
  272. $toollink = "\t" . '<a id="tooldesc_'.$toolsRow["id"].'" ' . $class . ' href="' . htmlspecialchars($toolsRow['link']) . '" target="' . $toolsRow['target'] . '">';
  273. $my_tool_link = "\t" . '<a id="istooldesc_'.$toolsRow["id"].'" ' . $class . ' href="' . htmlspecialchars($toolsRow['link']) . '" target="' . $toolsRow['target'] . '">';
  274. }
  275. }
  276. echo $toollink;
  277. //var_dump($toollink);
  278. /*
  279. Display::display_icon($toolsRow['image'], get_lang(ucfirst($toolsRow['name'])));
  280. */
  281. if ($toolsRow['image'] == 'file_html.gif' || $toolsRow['image'] == 'file_html_na.gif'
  282. || $toolsRow['image'] == 'scormbuilder.gif' || $toolsRow['image'] == 'scormbuilder_na.gif'
  283. || $toolsRow['image'] == 'blog.gif' || $toolsRow['image'] == 'blog_na.gif'
  284. || $toolsRow['image'] == 'external.gif' || $toolsRow['image'] == 'external_na.gif')
  285. {
  286. $tool_name = stripslashes($toolsRow['name']);
  287. } else {
  288. $tool_name = get_lang(ucfirst($toolsRow['name']));
  289. }
  290. Display::display_icon($toolsRow['image'], $tool_name, array('class'=>'tool-icon','id'=>'toolimage_'.$toolsRow["id"]));
  291. //validacion when belongs to a session
  292. $session_img = api_get_session_image($toolsRow['session_id'], $_user['status']);
  293. echo '</a> ';
  294. echo $my_tool_link;
  295. /*
  296. 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']));
  297. */
  298. echo "{$tool_name}$session_img";
  299. echo "\t" . '</a>';
  300. echo '</td>';
  301. if ($i%2) {
  302. echo "</tr>";
  303. }
  304. $i++;
  305. }
  306. }
  307. if ($i%2) {
  308. echo "<td width=\"50%\">&nbsp;</td>\n",
  309. "</tr>\n";
  310. }
  311. }
  312. //End of functions show tools
  313. /*
  314. ==============================================================================
  315. MAIN CODE
  316. ==============================================================================
  317. */
  318. /*
  319. -----------------------------------------------------------
  320. Work with data post askable by admin of course (franglais, clean this)
  321. -----------------------------------------------------------
  322. */
  323. //$session_id = api_get_session_id();
  324. if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
  325. if(api_is_allowed_to_edit(null,true)) {
  326. $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  327. $tool_id = Security::remove_XSS($_GET["id"]);
  328. $tool_info = api_get_tool_information($tool_id);
  329. $tool_visibility = $tool_info['visibility'];
  330. $tool_image = $tool_info['image'];
  331. $new_image = str_replace('.gif','_na.gif',$tool_image);
  332. $requested_image = ($tool_visibility == 0 ) ? $tool_image : $new_image;
  333. $requested_clase = ($tool_visibility == 0 ) ? 'visible' : 'invisible';
  334. $requested_message = ($tool_visibility == 0 ) ? 'is_active' : 'is_inactive';
  335. $requested_view = ($tool_visibility == 0 ) ? 'visible.gif' : 'invisible.gif';
  336. $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
  337. $requested_view = ($tool_visibility == 0 ) ? 'visible.gif' : 'invisible.gif';
  338. $requested_visible = ($tool_visibility == 0 ) ? 1 : 0;
  339. //HIDE AND REACTIVATE TOOL
  340. if ($_GET["id"]==strval(intval($_GET["id"]))) {
  341. /* -- session condition for visibility
  342. if (!empty($session_id)) {
  343. $sql = "select session_id FROM $tool_table WHERE id='".$_GET["id"]."' AND session_id = '$session_id'";
  344. $rs = Database::query($sql,__FILE__,__LINE__);
  345. if (Database::num_rows($rs) > 0) {
  346. $sql="UPDATE $tool_table SET visibility=$requested_visible WHERE id='".$_GET["id"]."' AND session_id = '$session_id'";
  347. } else {
  348. $sql_select = "select * FROM $tool_table WHERE id='".$_GET["id"]."'";
  349. $res_select = Database::query($sql_select,__FILE__,__LINE__);
  350. $row_select = Database::fetch_array($res_select);
  351. $sql = "INSERT INTO $tool_table(name,link,image,visibility,admin,address,added_tool,target,category,session_id)
  352. VALUES('{$row_select['name']}','{$row_select['link']}','{$row_select['image']}','0','{$row_select['admin']}','{$row_select['address']}','{$row_select['added_tool']}','{$row_select['target']}','{$row_select['category']}','$session_id')";
  353. }
  354. } else $sql="UPDATE $tool_table SET visibility=$requested_visible WHERE id='".$_GET["id"]."'";
  355. */
  356. $sql="UPDATE $tool_table SET visibility=$requested_visible WHERE id='".$_GET["id"]."'";
  357. Database::query($sql,__FILE__,__LINE__);
  358. }
  359. /*
  360. -----------------------------------------------------------
  361. HIDE
  362. -----------------------------------------------------------
  363. */
  364. /* if(isset($_GET['visibility']) && $_GET['visibility']==0) // visibility 1 -> 0
  365. {
  366. if ($_GET["id"]==strval(intval($_GET["id"]))) {
  367. $sql="UPDATE $tool_table SET visibility=0 WHERE id='".intval($_GET["id"])."'";
  368. Database::query($sql,__FILE__,__LINE__);
  369. }
  370. }
  371. /*
  372. -----------------------------------------------------------
  373. REACTIVATE
  374. -----------------------------------------------------------
  375. */
  376. /* elseif(isset($_GET['visibility'])&& $_GET['visibility']==1) // visibility 0,2 -> 1
  377. {
  378. if ($_GET["id"]==strval(intval($_GET["id"]))) {
  379. Database::query("UPDATE $tool_table SET visibility=1 WHERE id='".intval($_GET["id"])."'",__FILE__,__LINE__);
  380. }
  381. }
  382. */
  383. $response_data = array(
  384. 'image' => $requested_image,
  385. 'tclass' => $requested_clase,
  386. 'message' => $requested_message,
  387. 'view' => $requested_view
  388. );
  389. print(json_encode($response_data));
  390. exit;
  391. }
  392. } else {
  393. if(api_is_allowed_to_edit(null,true)) {
  394. /*
  395. -----------------------------------------------------------
  396. HIDE
  397. -----------------------------------------------------------
  398. */
  399. if(!empty($_GET['hide'])) // visibility 1 -> 0
  400. {
  401. /* -- session condition for visibility
  402. if (!empty($session_id)) {
  403. $sql = "select session_id FROM $tool_table WHERE id='".intval($_GET["id"])."' AND session_id = '".intval($session_id)."'";
  404. $rs = Database::query($sql,__FILE__,__LINE__);
  405. if (Database::num_rows($rs) > 0) {
  406. $sql="UPDATE $tool_table SET visibility=0 WHERE id='".intval($_GET["id"])."' AND session_id = '".intval($session_id)."'";
  407. } else {
  408. $sql_select = "select * FROM $tool_table WHERE id='".$_GET["id"]."'";
  409. $res_select = Database::query($sql_select,__FILE__,__LINE__);
  410. $row_select = Database::fetch_array($res_select);
  411. $sql = "INSERT INTO $tool_table(name,link,image,visibility,admin,address,added_tool,target,category,session_id)
  412. VALUES('{$row_select['name']}','{$row_select['link']}','{$row_select['image']}','0','{$row_select['admin']}','{$row_select['address']}','{$row_select['added_tool']}','{$row_select['target']}','{$row_select['category']}','$session_id')";
  413. }
  414. } else {
  415. $sql="UPDATE $tool_table SET visibility=0 WHERE id='".intval($_GET["id"])."'";
  416. }*/
  417. $sql="UPDATE $tool_table SET visibility=0 WHERE id='".intval($_GET["id"])."'";
  418. Database::query($sql,__FILE__,__LINE__);
  419. Display::display_confirmation_message(get_lang('ToolIsNowHidden'));
  420. }
  421. /*
  422. -----------------------------------------------------------
  423. REACTIVATE
  424. -----------------------------------------------------------
  425. */
  426. elseif(!empty($_GET['restore'])) // visibility 0,2 -> 1
  427. {
  428. $sql = "UPDATE $tool_table SET visibility=1 WHERE id='".intval($_GET["id"])."'";
  429. Database::query($sql,__FILE__,__LINE__);
  430. Display::display_confirmation_message(get_lang('ToolIsNowVisible'));
  431. }
  432. }
  433. }
  434. // work with data post askable by admin of course
  435. if (api_is_platform_admin()) {
  436. // Show message to confirm that a tools must be hidden from available tools
  437. // visibility 0,1->2
  438. if (!empty($_GET['askDelete'])) {
  439. ?>
  440. <div id="toolhide">
  441. <?php echo get_lang("DelLk")?>
  442. <br />&nbsp;&nbsp;&nbsp;
  443. <a href="<?php echo api_get_self()?>"><?php echo get_lang("No")?></a>&nbsp;|&nbsp;
  444. <a href="<?php echo api_get_self()?>?delete=yes&id=<?php echo Security::remove_XSS($_GET['id'])?>"><?php echo get_lang("Yes")?></a>
  445. </div>
  446. <?php
  447. }
  448. /*
  449. * Process hiding a tools from available tools.
  450. */
  451. elseif (isset($_GET["delete"]) && $_GET["delete"]) {
  452. //where $id is set?
  453. $id = intval($id);
  454. Database::query("DELETE FROM $tool_table WHERE id='$id' AND added_tool=1",__FILE__,__LINE__);
  455. }
  456. }
  457. /*
  458. ==============================================================================
  459. SESSION DATA
  460. ==============================================================================
  461. */
  462. /**
  463. * Shows the general data for a particular meeting
  464. *
  465. * @param id session id
  466. * @return string session data
  467. *
  468. */
  469. function show_session_data($id_session) {
  470. $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
  471. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  472. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  473. if ($id_session!=strval(intval($id_session))) {
  474. return '';
  475. } else {
  476. $id_session = intval($id_session);
  477. }
  478. $sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
  479. FROM '.$session_table.'
  480. LEFT JOIN '.$user_table.'
  481. ON id_coach = user_id
  482. WHERE '.$session_table.'.id='.$id_session;
  483. $rs = Database::query($sql, __FILE__, __LINE__);
  484. $session = Database::store_result($rs);
  485. $session = $session[0];
  486. $sql_category = 'SELECT name FROM '.$session_category_table.' WHERE id = "'.intval($session['session_category_id']).'"';
  487. $rs_category = Database::query($sql_category, __FILE__, __LINE__);
  488. $session_category = '';
  489. if (Database::num_rows($rs_category) > 0) {
  490. $rows_session_category = Database::store_result($rs_category);
  491. $rows_session_category = $rows_session_category[0];
  492. $session_category = $rows_session_category['name'];
  493. }
  494. if ($session['date_start'] == '00-00-0000') {
  495. $msg_date = get_lang('NoTimeLimits');
  496. } else {
  497. $msg_date = get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
  498. }
  499. $output = '';
  500. if (!empty($session_category)) {
  501. $output .= '<tr><td>'. get_lang('SessionCategory') . ': ' . '<b>' . $session_category .'</b></td></tr>';
  502. }
  503. $output .= '<tr><td style="width:50%">'. get_lang('SessionName') . ': ' . '<b>' . $session['name'] .'</b></td><td>'. get_lang('GeneralCoach') . ': ' . '<b>' . $session['lastname'].' '.$session['firstname'].' ('.$session['username'].')' .'</b></td></tr>';
  504. $output .= '<tr><td>'. get_lang('SessionIdentifier') . ': '. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) .'</td><td>'. get_lang('Date') . ': ' . '<b>' . $msg_date .'</b></td></tr>';
  505. return $output;
  506. }
  507. /*
  508. ==============================================================================
  509. COURSE ADMIN ONLY VIEW
  510. ==============================================================================
  511. */
  512. // start of tools for CourseAdmins (teachers/tutors)
  513. if(api_is_allowed_to_edit(null,true) && !api_is_coach()) {
  514. $current_protocol = $_SERVER['SERVER_PROTOCOL'];
  515. $current_host = $_SERVER['HTTP_HOST'];
  516. $server_protocol = substr($current_protocol,0,strrpos($current_protocol,'/'));
  517. $server_protocol = $server_protocol.'://';
  518. if ($current_host == 'localhost') {
  519. //Get information of path
  520. $info = explode('courses',api_get_self());
  521. $path_work = substr($info[0], 0, strlen($info[0]));
  522. } else {
  523. $path_work = "";
  524. }
  525. ?>
  526. <div class="courseadminview" style="border:0px; margin-top: 0px;padding:5px 0px;">
  527. <div class="normal-message" id="id_normal_message" style="display:none">
  528. <?php
  529. echo '<img src="'.$server_protocol.$current_host.'/'.$path_work.'main/inc/lib/javascript/indicator.gif"/>'."&nbsp;&nbsp;";
  530. echo get_lang('PleaseStandBy');
  531. ?>
  532. </div>
  533. <div class="confirmation-message" id="id_confirmation_message" style="display:none"></div>
  534. </div>
  535. <?php
  536. if (api_get_setting('show_session_data') === 'true' && $id_session > 0) {
  537. ?>
  538. <div class="courseadminview">
  539. <span class="viewcaption"><?php echo get_lang("SessionData") ?></span>
  540. <table width="100%">
  541. <?php echo show_session_data($id_session);?>
  542. </table>
  543. </div>
  544. <?php
  545. }
  546. ?>
  547. <div class="courseadminview">
  548. <span class="viewcaption"><?php echo get_lang("Authoring") ?></span>
  549. <table width="100%">
  550. <?php $my_list = get_tools_category(TOOL_AUTHORING); show_tools_category($my_list);?>
  551. </table>
  552. </div>
  553. <div class="courseadminview">
  554. <span class="viewcaption"><?php echo get_lang("Interaction") ?></span>
  555. <table width="100%">
  556. <?php $my_list = get_tools_category(TOOL_INTERACTION); show_tools_category($my_list);?>
  557. </table>
  558. </div>
  559. <div class="courseadminview">
  560. <span class="viewcaption"><?php echo get_lang("Administration") ?></span>
  561. <table width="100%">
  562. <?php $my_list = get_tools_category(TOOL_ADMIN_PLATEFORM); show_tools_category($my_list);?>
  563. </table>
  564. </div>
  565. <?php
  566. } elseif (api_is_coach()) {
  567. if (api_get_setting('show_session_data') === 'true' && $id_session > 0) {
  568. ?>
  569. <div class="courseadminview">
  570. <span class="viewcaption"><?php echo get_lang("SessionData") ?></span>
  571. <table width="100%">
  572. <?php echo show_session_data($id_session);?>
  573. </table>
  574. </div>
  575. <?php
  576. }
  577. ?>
  578. <div class="Authoringview">
  579. <table width="100%">
  580. <?php $my_list = get_tools_category(TOOL_STUDENT_VIEW); show_tools_category($my_list);?>
  581. </table>
  582. </div>
  583. <?php
  584. /*
  585. ==============================================================================
  586. TOOLS AUTHORING
  587. ==============================================================================
  588. */
  589. } else {
  590. $my_list = get_tools_category(TOOL_STUDENT_VIEW);
  591. if (count($my_list)>0) {
  592. ?>
  593. <div class="Authoringview">
  594. <table width="100%">
  595. <?php show_tools_category($my_list);?>
  596. </table>
  597. </div>
  598. <?php
  599. }
  600. }