course_home.lib.php 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. define('SHORTCUTS_HORIZONTAL', 0);
  4. define('SHORTCUTS_VERTICAL', 1);
  5. /**
  6. * Class CourseHome
  7. */
  8. class CourseHome
  9. {
  10. /**
  11. * Gets the html content to show in the 3 column view
  12. */
  13. public static function show_tool_3column($cat, $userId = null)
  14. {
  15. $_user = api_get_user_info($userId);
  16. $TBL_ACCUEIL = Database :: get_course_table(TABLE_TOOL_LIST);
  17. $TABLE_TOOLS = Database :: get_main_table(TABLE_MAIN_COURSE_MODULE);
  18. $numcols = 3;
  19. $table = new HTML_Table('width="100%"');
  20. $all_tools = array();
  21. $course_id = api_get_course_int_id();
  22. switch ($cat) {
  23. case 'Basic' :
  24. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND t.position="basic" ';
  25. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  26. $condition_display_tools = ' WHERE a.c_id = '.$course_id.' AND a.link=t.link AND (t.position="basic" OR a.name = "'.TOOL_TRACKING.'") ';
  27. }
  28. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  29. $condition_display_tools ORDER BY t.row, t.column";
  30. break;
  31. case 'External' :
  32. if (api_is_allowed_to_edit()) {
  33. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  34. WHERE a.c_id = $course_id AND ((a.link=t.link AND t.position='external')
  35. OR (a.visibility <= 1 AND (a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image))
  36. ORDER BY a.id";
  37. } else {
  38. $sql = "SELECT a.*, t.image img FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  39. WHERE a.c_id = $course_id AND (a.visibility = 1 AND ((a.link=t.link AND t.position='external')
  40. OR ((a.image = 'external.gif' OR a.image = 'scormbuilder.gif' OR t.image = 'blog.gif') AND a.image=t.image)))
  41. ORDER BY a.id";
  42. }
  43. break;
  44. case 'courseAdmin' :
  45. $sql = "SELECT a.*, t.image img, t.row, t.column FROM $TBL_ACCUEIL a, $TABLE_TOOLS t
  46. WHERE a.c_id = $course_id AND admin=1 AND a.link=t.link ORDER BY t.row, t.column";
  47. break;
  48. case 'platformAdmin' :
  49. $sql = "SELECT *, image img FROM $TBL_ACCUEIL WHERE c_id = $course_id AND visibility = 2 ORDER BY id";
  50. }
  51. $result = Database::query($sql);
  52. // Grabbing all the tools from $course_tool_table
  53. while ($tool = Database::fetch_array($result)) {
  54. $all_tools[] = $tool;
  55. }
  56. $course_id = api_get_course_int_id();
  57. // Grabbing all the links that have the property on_homepage set to 1
  58. if ($cat == 'External') {
  59. $tbl_link = Database :: get_course_table(TABLE_LINK);
  60. $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  61. if (api_is_allowed_to_edit(null, true)) {
  62. $sql_links = "SELECT tl.*, tip.visibility
  63. FROM $tbl_link tl
  64. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  65. WHERE tl.c_id = $course_id AND
  66. tip.c_id = $course_id AND
  67. tl.on_homepage='1' AND
  68. tip.visibility != 2";
  69. } else {
  70. $sql_links = "SELECT tl.*, tip.visibility
  71. FROM $tbl_link tl
  72. LEFT JOIN $tbl_item_property tip ON tip.tool='link' AND tip.ref=tl.id
  73. WHERE tl.c_id = $course_id AND
  74. tip.c_id = $course_id AND
  75. tl.on_homepage='1' AND
  76. tip.visibility = 1";
  77. }
  78. $result_links = Database::query($sql_links);
  79. while ($links_row = Database::fetch_array($result_links)) {
  80. $properties = array();
  81. $properties['name'] = $links_row['title'];
  82. $properties['link'] = $links_row['url'];
  83. $properties['visibility'] = $links_row['visibility'];
  84. $properties['img'] = 'external.gif';
  85. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&amp;id='.$links_row['id'];
  86. $all_tools[] = $properties;
  87. }
  88. }
  89. $cell_number = 0;
  90. // Draw line between basic and external, only if there are entries in External
  91. if ($cat == 'External' && count($all_tools)) {
  92. $table->setCellContents(0, 0, '<hr noshade="noshade" size="1"/>');
  93. $table->updateCellAttributes(0, 0, 'colspan="3"');
  94. $cell_number += $numcols;
  95. }
  96. foreach ($all_tools as & $tool) {
  97. if ($tool['image'] == 'scormbuilder.gif') {
  98. // check if the published learnpath is visible for student
  99. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  100. if (!api_is_allowed_to_edit(null, true) &&
  101. !learnpath::is_lp_visible_for_student(
  102. $published_lp_id,
  103. api_get_user_id(),
  104. api_get_course_id(),
  105. api_get_session_id()
  106. )
  107. ) {
  108. continue;
  109. }
  110. }
  111. if (api_get_session_id() != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
  112. continue;
  113. }
  114. $cell_content = '';
  115. // The name of the tool
  116. $tool_name = self::translate_tool_name($tool);
  117. $link_annex = '';
  118. // The url of the tool
  119. if ($tool['img'] != 'external.gif') {
  120. $tool['link'] = api_get_path(WEB_CODE_PATH).$tool['link'];
  121. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  122. $link_annex = $qm_or_amp.api_get_cidreq();
  123. } else {
  124. // If an external link ends with 'login=', add the actual login...
  125. $pos = strpos($tool['link'], '?login=');
  126. $pos2 = strpos($tool['link'], '&amp;login=');
  127. if ($pos !== false or $pos2 !== false) {
  128. $link_annex = $_user['username'];
  129. }
  130. }
  131. // Setting the actual image url
  132. $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img'];
  133. // VISIBLE
  134. if (($tool['visibility'] || ((api_is_coach() || api_is_course_tutor()) && $tool['name'] == TOOL_TRACKING)) || $cat == 'courseAdmin' || $cat == 'platformAdmin') {
  135. if (strpos($tool['name'], 'visio_') !== false) {
  136. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'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="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  137. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  138. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  139. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  140. } else {
  141. $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'"><img src="'.$tool['img'].'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  142. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  143. }
  144. } else {
  145. // INVISIBLE
  146. if (api_is_allowed_to_edit(null, true)) {
  147. if (strpos($tool['name'], 'visio_') !== false) {
  148. $cell_content .= '<a href="javascript: void(0);" onclick="window.open(\''.$tool['link'].$link_annex.'\',\'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="'.$tool['target'].'"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  149. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  150. $cell_content .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$tool['link'].$link_annex.'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'" class="invisible"><img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  151. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  152. } else {
  153. $cell_content .= '<a href="'.$tool['link'].$link_annex.'" target="'.$tool['target'].'" class="invisible">
  154. <img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">'.$tool_name.'</a>';
  155. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  156. }
  157. } else {
  158. $cell_content .= '<img src="'.str_replace(".gif", "_na.gif", $tool['img']).'" title="'.$tool_name.'" alt="'.$tool_name.'" align="absmiddle" border="0">';
  159. // don't replace img with display::return_icon because $tool['img'] = api_get_path(WEB_IMG_PATH).$tool['img']
  160. $cell_content .= '<span class="invisible">'.$tool_name.'</span>';
  161. }
  162. }
  163. $lnk = array();
  164. if (api_is_allowed_to_edit(null, true) &&
  165. $cat != "courseAdmin" &&
  166. !strpos($tool['link'], 'learnpath_handler.php?learnpath_id') &&
  167. !api_is_coach()
  168. ) {
  169. if ($tool['visibility']) {
  170. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'), array('style' => 'vertical-align: middle;'));
  171. $link['cmd'] = "hide=yes";
  172. $lnk[] = $link;
  173. } else {
  174. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'), array('style' => 'vertical-align: middle;'));
  175. $link['cmd'] = "restore=yes";
  176. $lnk[] = $link;
  177. }
  178. if (is_array($lnk)) {
  179. foreach ($lnk as & $this_lnk) {
  180. if ($tool['adminlink']) {
  181. $cell_content .= '<a href="'.$properties['adminlink'].'">'.
  182. Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  183. } else {
  184. $cell_content .= '<a href="'.api_get_self().'?id='.$tool['id'].'&amp;'.$this_lnk['cmd'].'">'.$this_lnk['name'].'</a>';
  185. }
  186. }
  187. }
  188. }
  189. $table->setCellContents($cell_number / $numcols, ($cell_number) % $numcols, $cell_content);
  190. $table->updateCellAttributes($cell_number / $numcols, ($cell_number) % $numcols, 'width="32%" height="42"');
  191. $cell_number++;
  192. }
  193. return $table->toHtml();
  194. }
  195. /**
  196. * Displays the tools of a certain category.
  197. *
  198. * @return void
  199. * @param string $course_tool_category contains the category of tools to display:
  200. * "Public", "PublicButHide", "courseAdmin", "claroAdmin"
  201. */
  202. public static function show_tool_2column($course_tool_category)
  203. {
  204. $html = '';
  205. $web_code_path = api_get_path(WEB_CODE_PATH);
  206. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  207. $course_id = api_get_course_int_id();
  208. switch ($course_tool_category) {
  209. case TOOL_PUBLIC:
  210. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND visibility = 1 ';
  211. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  212. $condition_display_tools = ' WHERE c_id = '.$course_id.' AND (visibility = 1 OR (visibility = 0 AND name = "'.TOOL_TRACKING.'")) ';
  213. }
  214. $result = Database::query("SELECT * FROM $course_tool_table $condition_display_tools ORDER BY id");
  215. $col_link = "##003399";
  216. break;
  217. case TOOL_PUBLIC_BUT_HIDDEN:
  218. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility=0 AND admin=0 ORDER BY id");
  219. $col_link = "##808080";
  220. break;
  221. case TOOL_COURSE_ADMIN:
  222. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND admin=1 AND visibility != 2 ORDER BY id");
  223. $col_link = "##003399";
  224. break;
  225. case TOOL_PLATFORM_ADMIN:
  226. $result = Database::query("SELECT * FROM $course_tool_table WHERE c_id = $course_id AND visibility = 2 ORDER BY id");
  227. $col_link = "##003399";
  228. }
  229. $i = 0;
  230. // Grabbing all the tools from $course_tool_table
  231. while ($temp_row = Database::fetch_array($result)) {
  232. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif') {
  233. $temp_row['image'] = str_replace('.gif', '_na.gif', $temp_row['image']);
  234. }
  235. $all_tools_list[] = $temp_row;
  236. }
  237. // Grabbing all the links that have the property on_homepage set to 1
  238. $course_link_table = Database::get_course_table(TABLE_LINK);
  239. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  240. switch ($course_tool_category) {
  241. case TOOL_PUBLIC:
  242. $sql_links = "SELECT tl.*, tip.visibility
  243. FROM $course_link_table tl
  244. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  245. WHERE tl.on_homepage='1' AND tip.visibility = 1";
  246. break;
  247. case TOOL_PUBLIC_BUT_HIDDEN:
  248. $sql_links = "SELECT tl.*, tip.visibility
  249. FROM $course_link_table tl
  250. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tl.c_id = tip.c_id AND tl.c_id = $course_id AND tip.ref=tl.id
  251. WHERE tl.on_homepage='1' AND tip.visibility = 0";
  252. break;
  253. default:
  254. $sql_links = null;
  255. break;
  256. }
  257. if ($sql_links != null) {
  258. $properties = array();
  259. $result_links = Database::query($sql_links);
  260. while ($links_row = Database::fetch_array($result_links)) {
  261. unset($properties);
  262. $properties['name'] = $links_row['title'];
  263. $properties['link'] = $links_row['url'];
  264. $properties['visibility'] = $links_row['visibility'];
  265. $properties['image'] = $course_tool_category == TOOL_PUBLIC_BUT_HIDDEN ? 'external_na.gif' : 'external.gif';
  266. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  267. $all_tools_list[] = $properties;
  268. }
  269. }
  270. if (isset($all_tools_list)) {
  271. $lnk = array();
  272. foreach ($all_tools_list as & $tool) {
  273. if ($tool['image'] == 'scormbuilder.gif') {
  274. // display links to lp only for current session
  275. /* if (api_get_session_id() != $tool['session_id']) {
  276. continue;
  277. } */
  278. // check if the published learnpath is visible for student
  279. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  280. if (!api_is_allowed_to_edit(null, true) &&
  281. !learnpath::is_lp_visible_for_student(
  282. $published_lp_id,
  283. api_get_user_id(),
  284. api_get_course_id(),
  285. api_get_session_id()
  286. )
  287. ) {
  288. continue;
  289. }
  290. }
  291. if (api_get_session_id() != 0 &&
  292. in_array($tool['name'], array('course_maintenance', 'course_setting'))
  293. ) {
  294. continue;
  295. }
  296. if (!($i % 2)) {
  297. $html .= "<tr valign=\"top\">";
  298. }
  299. // NOTE : Table contains only the image file name, not full path
  300. if (stripos($tool['link'], 'http://') === false &&
  301. stripos($tool['link'], 'https://') === false &&
  302. stripos($tool['link'], 'ftp://') === false
  303. ) {
  304. $tool['link'] = $web_code_path.$tool['link'];
  305. }
  306. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  307. $class = 'class="invisible"';
  308. }
  309. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&amp;';
  310. $tool['link'] = $tool['link'];
  311. $html .= '<td width="50%" height="30">';
  312. if (strpos($tool['name'], 'visio_') !== false) {
  313. $html .= '<a '.$class.' href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['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="'.$tool['target'].'">';
  314. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  315. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.htmlspecialchars($tool['link']).$qm_or_amp.api_get_cidreq().'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$tool['target'].'"'.$class.'>';
  316. } else {
  317. $html .= '<a href="'.htmlspecialchars($tool['link']).(($tool['image'] == 'external.gif' || $tool['image'] == 'external_na.gif') ? '' : $qm_or_amp.api_get_cidreq()).'" target="'.$tool['target'].'" '.$class.'>';
  318. }
  319. $tool_name = self::translate_tool_name($tool);
  320. $html .= Display::return_icon(
  321. $tool['image'],
  322. $tool_name,
  323. array(),
  324. null,
  325. ICON_SIZE_MEDIUM
  326. ) . '&nbsp;' . $tool_name . '</a>';
  327. // This part displays the links to hide or remove a tool.
  328. // These links are only visible by the course manager.
  329. unset($lnk);
  330. if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
  331. if ($tool['visibility'] == '1' || $tool['name'] == TOOL_TRACKING) {
  332. $link['name'] = Display::return_icon('remove.gif', get_lang('Deactivate'));
  333. $link['cmd'] = 'hide=yes';
  334. $lnk[] = $link;
  335. }
  336. if ($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN) {
  337. $link['name'] = Display::return_icon('add.gif', get_lang('Activate'));
  338. $link['cmd'] = 'restore=yes';
  339. $lnk[] = $link;
  340. if ($tool['added_tool'] == 1) {
  341. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  342. $link['cmd'] = 'remove=yes';
  343. $lnk[] = $link;
  344. }
  345. }
  346. if ($tool['adminlink']) {
  347. $html .= '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  348. }
  349. }
  350. if (api_is_platform_admin() && !api_is_coach()) {
  351. if ($tool['visibility'] == 2) {
  352. $link['name'] = Display::return_icon('undelete.gif', get_lang('Activate'));
  353. $link['cmd'] = 'hide=yes';
  354. $lnk[] = $link;
  355. if ($tool['added_tool'] == 1) {
  356. $link['name'] = get_lang('Delete');
  357. $link['cmd'] = 'askDelete=yes';
  358. $lnk[] = $link;
  359. }
  360. }
  361. if ($tool['visibility'] == 0 && $tool['added_tool'] == 0) {
  362. $link['name'] = Display::return_icon('delete.gif', get_lang('Remove'));
  363. $link['cmd'] = 'remove=yes';
  364. $lnk[] = $link;
  365. }
  366. }
  367. if (is_array($lnk)) {
  368. foreach ($lnk as & $this_link) {
  369. if (!$tool['adminlink']) {
  370. $html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.$this_link['name'].'</a>';
  371. }
  372. }
  373. }
  374. $html .= "</td>";
  375. if ($i % 2) {
  376. $html .= "</tr>";
  377. }
  378. $i++;
  379. }
  380. }
  381. if ($i % 2) {
  382. $html .= "<td width=\"50%\">&nbsp;</td></tr>";
  383. }
  384. return $html;
  385. }
  386. /**
  387. * Gets the tools of a certain category. Returns an array expected
  388. * by show_tools_category()
  389. * @param string $course_tool_category contains the category of tools to
  390. * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  391. * @return array
  392. */
  393. public static function get_tools_category($course_tool_category)
  394. {
  395. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  396. $is_platform_admin = api_is_platform_admin();
  397. $all_tools_list = array();
  398. // Condition for the session
  399. $session_id = api_get_session_id();
  400. $course_id = api_get_course_int_id();
  401. $condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
  402. switch ($course_tool_category) {
  403. case TOOL_STUDENT_VIEW:
  404. $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
  405. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  406. $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) ';
  407. }
  408. $sql = "SELECT *
  409. FROM $course_tool_table t
  410. $conditions AND
  411. c_id = $course_id $condition_session
  412. ORDER BY id";
  413. $result = Database::query($sql);
  414. break;
  415. case TOOL_AUTHORING:
  416. $sql = "SELECT * FROM $course_tool_table t
  417. WHERE category = 'authoring' AND c_id = $course_id $condition_session
  418. ORDER BY id";
  419. $result = Database::query($sql);
  420. break;
  421. case TOOL_INTERACTION:
  422. $sql = "SELECT * FROM $course_tool_table t
  423. WHERE category = 'interaction' AND c_id = $course_id $condition_session
  424. ORDER BY id";
  425. $result = Database::query($sql);
  426. break;
  427. case TOOL_ADMIN_VISIBLE:
  428. $sql = "SELECT * FROM $course_tool_table t
  429. WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
  430. ORDER BY id";
  431. $result = Database::query($sql);
  432. break;
  433. case TOOL_ADMIN_PLATFORM:
  434. $sql = "SELECT * FROM $course_tool_table t
  435. WHERE category = 'admin' AND c_id = $course_id $condition_session
  436. ORDER BY id";
  437. $result = Database::query($sql);
  438. break;
  439. case TOOL_DRH:
  440. $sql = "SELECT * FROM $course_tool_table t
  441. WHERE name IN ('tracking') AND c_id = $course_id $condition_session
  442. ORDER BY id";
  443. $result = Database::query($sql);
  444. break;
  445. case TOOL_COURSE_PLUGIN:
  446. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  447. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  448. $sql = "SELECT * FROM $course_tool_table t
  449. WHERE category = 'plugin' AND c_id = $course_id $condition_session
  450. ORDER BY id";
  451. $result = Database::query($sql);
  452. break;
  453. }
  454. //Get the list of hidden tools - this might imply performance slowdowns
  455. // if the course homepage is loaded many times, so the list of hidden
  456. // tools might benefit from a shared memory storage later on
  457. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  458. $hide_list = array();
  459. $check = false;
  460. foreach ($list as $line) {
  461. // Admin can see all tools even if the course_hide_tools configuration is set
  462. if ($is_platform_admin) {
  463. continue;
  464. }
  465. if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
  466. $hide_list[] = $line['subkey'];
  467. $check = true;
  468. }
  469. }
  470. while ($temp_row = Database::fetch_assoc($result)) {
  471. $add = false;
  472. if ($check) {
  473. if (!in_array($temp_row['name'], $hide_list)) {
  474. $add = true;
  475. }
  476. } else {
  477. $add = true;
  478. }
  479. if ($temp_row['image'] == 'scormbuilder.gif') {
  480. $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
  481. $lp = new learnpath(
  482. api_get_course_id(),
  483. $lp_id,
  484. api_get_user_id()
  485. );
  486. $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
  487. $add = $lp->is_lp_visible_for_student(
  488. $lp_id,
  489. api_get_user_id(),
  490. api_get_course_id(),
  491. api_get_session_id()
  492. );
  493. if ($path) {
  494. $temp_row['custom_image'] = $path;
  495. }
  496. }
  497. if ($add) {
  498. $all_tools_list[] = $temp_row;
  499. }
  500. }
  501. // Grabbing all the links that have the property on_homepage set to 1
  502. $course_link_table = Database::get_course_table(TABLE_LINK);
  503. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  504. $condition_session = api_get_session_condition($session_id, true, true, 'tip.session_id');
  505. switch ($course_tool_category) {
  506. case TOOL_AUTHORING:
  507. $sql_links = "SELECT tl.*, tip.visibility
  508. FROM $course_link_table tl
  509. LEFT JOIN $course_item_property_table tip
  510. ON tip.tool='link' AND tip.ref=tl.id
  511. WHERE
  512. tl.c_id = $course_id AND
  513. tip.c_id = $course_id AND
  514. tl.on_homepage='1' $condition_session";
  515. break;
  516. case TOOL_INTERACTION:
  517. $sql_links = null;
  518. /*
  519. $sql_links = "SELECT tl.*, tip.visibility
  520. FROM $course_link_table tl
  521. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  522. WHERE tl.on_homepage='1' ";
  523. */
  524. break;
  525. case TOOL_STUDENT_VIEW:
  526. $sql_links = "SELECT tl.*, tip.visibility
  527. FROM $course_link_table tl
  528. LEFT JOIN $course_item_property_table tip
  529. ON tip.tool='link' AND tip.ref=tl.id
  530. WHERE
  531. tl.c_id = $course_id AND
  532. tip.c_id = $course_id AND
  533. tl.on_homepage ='1' $condition_session";
  534. break;
  535. case TOOL_ADMIN:
  536. $sql_links = "SELECT tl.*, tip.visibility
  537. FROM $course_link_table tl
  538. LEFT JOIN $course_item_property_table tip
  539. ON tip.tool='link' AND tip.ref=tl.id
  540. WHERE
  541. tl.c_id = $course_id AND
  542. tip.c_id = $course_id AND
  543. tl.on_homepage='1' $condition_session";
  544. break;
  545. default:
  546. $sql_links = null;
  547. break;
  548. }
  549. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  550. if ($sql_links != null) {
  551. $result_links = Database::query($sql_links);
  552. if (Database::num_rows($result_links) > 0) {
  553. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  554. $properties = array();
  555. $properties['name'] = $links_row['title'];
  556. $properties['session_id'] = $links_row['session_id'];
  557. $properties['link'] = $links_row['url'];
  558. $properties['visibility'] = $links_row['visibility'];
  559. $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
  560. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  561. $properties['target'] = $links_row['target'];
  562. $tmp_all_tools_list[] = $properties;
  563. }
  564. }
  565. }
  566. if (isset($tmp_all_tools_list)) {
  567. foreach ($tmp_all_tools_list as $tool) {
  568. if ($tool['image'] == 'blog.gif') {
  569. // Init
  570. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  571. // Get blog id
  572. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  573. // Get blog members
  574. if ($is_platform_admin) {
  575. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  576. WHERE blog_id =".$blog_id;
  577. } else {
  578. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  579. WHERE blog_id =".$blog_id." AND user_id = ".api_get_user_id();
  580. }
  581. $result_blogs = Database::query($sql_blogs);
  582. if (Database::num_rows($result_blogs) > 0) {
  583. $all_tools_list[] = $tool;
  584. }
  585. } else {
  586. $all_tools_list[] = $tool;
  587. }
  588. }
  589. }
  590. return $all_tools_list;
  591. }
  592. /**
  593. * Displays the tools of a certain category.
  594. * @param array $all_tools_list List of tools as returned by get_tools_category()
  595. * @param bool $rows
  596. *
  597. * @return void
  598. */
  599. public static function show_tools_category($all_tools_list, $rows = false)
  600. {
  601. $_user = api_get_user_info();
  602. $theme = api_get_setting('homepage_view');
  603. if ($theme == 'vertical_activity') {
  604. //ordering by get_lang name
  605. $order_tool_list = array();
  606. if (is_array($all_tools_list) && count($all_tools_list) > 0) {
  607. foreach ($all_tools_list as $key => $new_tool) {
  608. $tool_name = self::translate_tool_name($new_tool);
  609. $order_tool_list [$key] = $tool_name;
  610. }
  611. natsort($order_tool_list);
  612. $my_temp_tool_array = array();
  613. foreach ($order_tool_list as $key => $new_tool) {
  614. $my_temp_tool_array[] = $all_tools_list[$key];
  615. }
  616. $all_tools_list = $my_temp_tool_array;
  617. } else {
  618. $all_tools_list = array();
  619. }
  620. }
  621. $web_code_path = api_get_path(WEB_CODE_PATH);
  622. $session_id = api_get_session_id();
  623. $is_platform_admin = api_is_platform_admin();
  624. if ($session_id == 0 ) {
  625. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
  626. } else {
  627. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
  628. }
  629. $i = 0;
  630. $items = array();
  631. $app_plugin = new AppPlugin();
  632. if (isset($all_tools_list)) {
  633. $lnk = '';
  634. foreach ($all_tools_list as & $tool) {
  635. $item = array();
  636. $studentview = false;
  637. $tool['original_link'] = $tool['link'];
  638. if ($tool['image'] == 'scormbuilder.gif') {
  639. // check if the published learnpath is visible for student
  640. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  641. if (api_is_allowed_to_edit(null, true)) {
  642. $studentview = true;
  643. }
  644. if (!api_is_allowed_to_edit(null, true) &&
  645. !learnpath::is_lp_visible_for_student(
  646. $published_lp_id,
  647. api_get_user_id(),
  648. api_get_course_id(),
  649. api_get_session_id()
  650. )
  651. ) {
  652. continue;
  653. }
  654. }
  655. if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
  656. continue;
  657. }
  658. // This part displays the links to hide or remove a tool.
  659. // These links are only visible by the course manager.
  660. unset($lnk);
  661. $item['extra'] = null;
  662. $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
  663. if ($is_allowed_to_edit) {
  664. if (empty($session_id)) {
  665. if (isset($tool['id'])) {
  666. if ($tool['visibility'] == '1' && $toolAdmin != '1') {
  667. $link['name'] = Display::return_icon(
  668. 'visible.png',
  669. get_lang('Deactivate'),
  670. array('id' => 'linktool_'.$tool['id']),
  671. ICON_SIZE_SMALL,
  672. false
  673. );
  674. $link['cmd'] = 'hide=yes';
  675. $lnk[] = $link;
  676. }
  677. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  678. $link['name'] = Display::return_icon(
  679. 'invisible.png',
  680. get_lang('Activate'),
  681. array('id' => 'linktool_'.$tool['id']),
  682. ICON_SIZE_SMALL,
  683. false
  684. );
  685. $link['cmd'] = 'restore=yes';
  686. $lnk[] = $link;
  687. }
  688. }
  689. }
  690. if (!empty($tool['adminlink'])) {
  691. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  692. }
  693. }
  694. // Both checks are necessary as is_platform_admin doesn't take student view into account
  695. if ($is_platform_admin && $is_allowed_to_edit) {
  696. if ($toolAdmin != '1') {
  697. $link['cmd'] = 'hide=yes';
  698. }
  699. }
  700. $item['visibility'] = null;
  701. if (isset($lnk) && is_array($lnk)) {
  702. foreach ($lnk as $this_link) {
  703. if (empty($tool['adminlink'])) {
  704. $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.
  705. $this_link['name'].'</a>';
  706. }
  707. }
  708. } else {
  709. $item['visibility'] .= '';
  710. }
  711. // NOTE : Table contains only the image file name, not full path
  712. if (stripos($tool['link'], 'http://') === false &&
  713. stripos($tool['link'], 'https://') === false &&
  714. stripos($tool['link'], 'ftp://') === false
  715. ) {
  716. $tool['link'] = $web_code_path.$tool['link'];
  717. }
  718. if ($tool['visibility'] == '0' && $toolAdmin != '1' && !isset($tool['original_link'])) {
  719. $class = 'invisible';
  720. $info = pathinfo($tool['image']);
  721. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  722. $tool['image'] = $basename.'_na.'.$info['extension'];
  723. } else {
  724. $class = '';
  725. }
  726. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  727. // If it's a link, we don't add the cidReq
  728. if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
  729. $tool['link'] = $tool['link'].$qm_or_amp;
  730. } else {
  731. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  732. }
  733. $tool_link_params = array();
  734. $toolId = isset($tool["id"]) ? $tool["id"] : null;
  735. //@todo this visio stuff should be removed
  736. if (strpos($tool['name'], 'visio_') !== false) {
  737. $tool_link_params = array(
  738. 'id' => 'tooldesc_'.$toolId,
  739. 'href' => '"javascript: void(0);"',
  740. 'class' => $class,
  741. 'onclick' => 'javascript: window.open(\''.$tool['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\')',
  742. 'target' => $tool['target']
  743. );
  744. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  745. $tool_link_params = array(
  746. 'id' => 'tooldesc_'.$toolId,
  747. 'class' => $class,
  748. 'href' => 'javascript: void(0);',
  749. 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows
  750. 'target' => $tool['target']
  751. );
  752. } else {
  753. if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
  754. $tool_link_params = array(
  755. 'id' => 'tooldesc_'.$toolId,
  756. 'href' => $tool['link'],
  757. 'class' => $class,
  758. 'target' => '_blank'
  759. );
  760. } else {
  761. $tool_link_params = array(
  762. 'id' => 'tooldesc_'.$toolId,
  763. 'href' => $tool['link'],
  764. 'class' => $class,
  765. 'target' => $tool['target']
  766. );
  767. }
  768. }
  769. $tool_name = self::translate_tool_name($tool);
  770. // Including Courses Plugins
  771. // Creating title and the link
  772. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  773. $plugin_info = $app_plugin->getPluginInfo($tool['name']);
  774. if (isset($plugin_info) && isset($plugin_info['title'])) {
  775. $tool_name = $plugin_info['title'];
  776. }
  777. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
  778. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/22/'.$tool['image'])) {
  779. $tool['image'] = 'plugins.png';
  780. }
  781. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
  782. }
  783. $icon = Display::return_icon(
  784. $tool['image'],
  785. $tool_name,
  786. array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolId),
  787. ICON_SIZE_BIG,
  788. false
  789. );
  790. /*if (!empty($tool['custom_icon'])) {
  791. $image = self::getCustomWebIconPath().$tool['custom_icon'];
  792. $icon = Display::img(
  793. $image,
  794. $tool['description'],
  795. array(
  796. 'class' => 'tool-icon',
  797. 'id' => 'toolimage_'.$tool['id']
  798. )
  799. );
  800. }*/
  801. // Validation when belongs to a session
  802. $session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : ''));
  803. if ($studentview) {
  804. $tool_link_params['href'] .= '&isStudentView=true';
  805. }
  806. $item['url_params'] = $tool_link_params;
  807. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  808. $item['tool'] = $tool;
  809. $item['name'] = $tool_name;
  810. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  811. $item['link'] = Display::url(
  812. $tool_name.$session_img,
  813. $tool_link_params['href'],
  814. $tool_link_params
  815. );
  816. $items[] = $item;
  817. $i++;
  818. } // end of foreach
  819. }
  820. $i = 0;
  821. $html = '';
  822. if (!empty($items)) {
  823. foreach ($items as $item) {
  824. switch ($theme) {
  825. case 'activity_big':
  826. $data = '';
  827. $html .= '<div class="col-xs-6 col-md-3 course-tool">';
  828. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  829. $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null;
  830. if (isset($item['tool']['custom_image'])) {
  831. $original_image = Display::img(
  832. $item['tool']['custom_image'],
  833. $item['name'],
  834. array('id' => 'toolimage_'.$toolId)
  835. );
  836. } elseif (isset($item['tool']['custom_icon']) &&
  837. !empty($item['tool']['custom_icon'])
  838. ) {
  839. $customIcon = $item['tool']['custom_icon'];
  840. if ($item['tool']['visibility'] == '0') {
  841. $fileInfo = pathinfo($item['tool']['custom_icon']);
  842. $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
  843. }
  844. $original_image = Display::img(
  845. self::getCustomWebIconPath().$customIcon,
  846. $item['name'],
  847. array('id' => 'toolimage_'.$toolId)
  848. );
  849. } else {
  850. $original_image = Display::return_icon(
  851. $image,
  852. $item['name'],
  853. array('id' => 'toolimage_'.$toolId),
  854. ICON_SIZE_BIG,
  855. false
  856. );
  857. }
  858. $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
  859. $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection
  860. $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content'));
  861. $html .= '</div>';
  862. break;
  863. case 'activity':
  864. $html .= '<div class="offset2 col-md-4 course-tool">';
  865. $html .= $item['extra'];
  866. $html .= $item['visibility'];
  867. $html .= $item['icon'];
  868. $html .= $item['link'];
  869. $html .= '</div>';
  870. break;
  871. case 'vertical_activity':
  872. if ($i == 0) {
  873. $html .= '<ul>';
  874. }
  875. $html .= '<li class="course-tool">';
  876. $html .= $item['extra'];
  877. $html .= $item['visibility'];
  878. $html .= $item['icon'];
  879. $html .= $item['link'];
  880. $html .= '</li>';
  881. if ($i == count($items) - 1) {
  882. $html .= '</ul>';
  883. }
  884. break;
  885. }
  886. $i++;
  887. }
  888. }
  889. return $html;
  890. }
  891. /**
  892. * Shows the general data for a particular meeting
  893. *
  894. * @param id session id
  895. * @return string session data
  896. */
  897. public static function show_session_data($id_session)
  898. {
  899. $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
  900. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  901. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  902. $sessionInfo = api_get_session_info($id_session);
  903. if (empty($sessionInfo)) {
  904. return '';
  905. }
  906. $sql = 'SELECT name FROM '.$session_category_table.'
  907. WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
  908. $rs_category = Database::query($sql);
  909. $session_category = '';
  910. if (Database::num_rows($rs_category) > 0) {
  911. $rows_session_category = Database::store_result($rs_category);
  912. $rows_session_category = $rows_session_category[0];
  913. $session_category = $rows_session_category['name'];
  914. }
  915. $coachInfo = api_get_user_info($sessionInfo['id_coach']);
  916. $output = '';
  917. if (!empty($session_category)) {
  918. $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
  919. }
  920. $dateInfo = SessionManager::parseSessionDates($sessionInfo);
  921. $msgDate = $dateInfo['access'];
  922. $output .= '<tr>
  923. <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
  924. <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
  925. $output .= '<tr>
  926. <td>'.get_lang('SessionIdentifier').': '.
  927. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).'
  928. </td>
  929. <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
  930. </td>
  931. </tr>';
  932. return $output;
  933. }
  934. /**
  935. * Retrieves the name-field within a tool-record and translates it on necessity.
  936. * @param array $tool The input record.
  937. * @return string Returns the name of the corresponding tool.
  938. */
  939. public static function translate_tool_name(& $tool)
  940. {
  941. static $already_translated_icons = array(
  942. 'file_html.gif',
  943. 'file_html_na.gif',
  944. 'file_html.png',
  945. 'file_html_na.png',
  946. 'scormbuilder.gif',
  947. 'scormbuilder_na.gif',
  948. 'blog.gif',
  949. 'blog_na.gif',
  950. 'external.gif',
  951. 'external_na.gif'
  952. );
  953. if (in_array($tool['image'], $already_translated_icons)) {
  954. $toolName = Security::remove_XSS(stripslashes($tool['name']));
  955. } else {
  956. $toolName = get_lang('Tool'.api_underscore_to_camel_case($tool['name']));
  957. }
  958. return $toolName;
  959. }
  960. /**
  961. * Get published learning path id from link inside course home
  962. * @param string Link to published lp
  963. * @return int Learning path id
  964. */
  965. public static function get_published_lp_id_from_link($published_lp_link)
  966. {
  967. $lp_id = 0;
  968. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  969. if (!empty($param_lp_id)) {
  970. $a_param_lp_id = explode('=', $param_lp_id);
  971. if (isset($a_param_lp_id[1])) {
  972. $lp_id = intval($a_param_lp_id[1]);
  973. }
  974. }
  975. return $lp_id;
  976. }
  977. /**
  978. * @param bool $include_admin_tools
  979. * @return array
  980. */
  981. static function get_navigation_items($include_admin_tools = false)
  982. {
  983. $navigation_items = array();
  984. $course_id = api_get_course_int_id();
  985. if (!empty($course_id)) {
  986. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
  987. /* Link to the Course homepage */
  988. $navigation_items['home']['image'] = 'home.gif';
  989. $navigation_items['home']['link'] = api_get_path(REL_COURSE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php';
  990. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  991. $sql_menu_query = "SELECT * FROM $course_tools_table
  992. WHERE c_id = $course_id AND visibility='1' and admin='0'
  993. ORDER BY id ASC";
  994. $sql_result = Database::query($sql_menu_query);
  995. while ($row = Database::fetch_array($sql_result)) {
  996. $navigation_items[$row['id']] = $row;
  997. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  998. $navigation_items[$row['id']]['link'] = api_get_path(REL_CODE_PATH).$row['link'];
  999. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  1000. }
  1001. }
  1002. /* Admin (edit rights) only links
  1003. - Course settings (course admin only)
  1004. - Course rights (roles & rights overview) */
  1005. if ($include_admin_tools) {
  1006. $course_settings_sql = "SELECT name,image FROM $course_tools_table
  1007. WHERE c_id = $course_id AND link='course_info/infocours.php'";
  1008. $sql_result = Database::query($course_settings_sql);
  1009. $course_setting_info = Database::fetch_array($sql_result);
  1010. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  1011. if (api_get_session_id() == 0) {
  1012. // course settings item
  1013. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  1014. $navigation_items['course_settings']['link'] = api_get_path(REL_CODE_PATH).'course_info/infocours.php';
  1015. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  1016. }
  1017. }
  1018. }
  1019. foreach ($navigation_items as $key => $navigation_item) {
  1020. if (strstr($navigation_item['link'], '?')) {
  1021. //link already contains a parameter, add course id parameter with &
  1022. $parameter_separator = '&amp;';
  1023. } else {
  1024. //link doesn't contain a parameter yet, add course id parameter with ?
  1025. $parameter_separator = '?';
  1026. }
  1027. //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  1028. $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.api_get_session_id();
  1029. }
  1030. return $navigation_items;
  1031. }
  1032. /**
  1033. * Show a navigation menu
  1034. */
  1035. public static function show_navigation_menu()
  1036. {
  1037. $navigation_items = self::get_navigation_items(true);
  1038. $course_id = api_get_course_id();
  1039. $html = '<div id="toolnav"> <!-- start of #toolnav -->';
  1040. if (api_get_setting('show_navigation_menu') == 'icons') {
  1041. $html .= self::show_navigation_tool_shortcuts($orientation = SHORTCUTS_VERTICAL);
  1042. } else {
  1043. $html .= '<div id="toolnavbox">';
  1044. $html .= '<div id="toolnavlist"><dl>';
  1045. foreach ($navigation_items as $key => $navigation_item) {
  1046. //students can't see the course settings option
  1047. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  1048. continue;
  1049. }
  1050. $html .= '<dd>';
  1051. $url_item = parse_url($navigation_item['link']);
  1052. $url_current = parse_url($_SERVER['REQUEST_URI']);
  1053. if (strpos($navigation_item['link'], 'chat') !== false &&
  1054. api_get_course_setting('allow_open_chat_window', $course_id)
  1055. ) {
  1056. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
  1057. } else {
  1058. $html .= '<a href="'.$navigation_item['link'].'" target="_top" ';
  1059. }
  1060. if (stristr($url_item['path'], $url_current['path'])) {
  1061. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'], 'learnpath_id='.$_GET['learnpath_id']) === 0) {
  1062. $html .= ' id="here"';
  1063. }
  1064. }
  1065. $html .= ' title="'.$navigation_item['name'].'">';
  1066. if (api_get_setting('show_navigation_menu') != 'text') {
  1067. $html .= '<div align="left"><img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/></div>';
  1068. }
  1069. if (api_get_setting('show_navigation_menu') != 'icons') {
  1070. $html .= $navigation_item['name'];
  1071. }
  1072. $html .= '</a>';
  1073. $html .= '</dd>';
  1074. }
  1075. $html .= '</dl></div></div>';
  1076. }
  1077. $html .= '</div><!-- end "#toolnav" -->';
  1078. return $html;
  1079. }
  1080. /**
  1081. * Show a toolbar with shortcuts to the course tool
  1082. */
  1083. public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  1084. {
  1085. $navigation_items = self::get_navigation_items(false);
  1086. $html = '';
  1087. if (!empty($navigation_items)) {
  1088. if ($orientation == SHORTCUTS_HORIZONTAL)
  1089. $style_id = "toolshortcuts_horizontal";
  1090. else {
  1091. $style_id = "toolshortcuts_vertical";
  1092. }
  1093. $html .= '<div id="'.$style_id.'">';
  1094. foreach ($navigation_items as $key => $navigation_item) {
  1095. if (strpos($navigation_item['link'], 'chat') !== false &&
  1096. api_get_course_setting('allow_open_chat_window')
  1097. ) {
  1098. $html .= '<a href="javascript: void(0);" onclick="javascript: window.open(\''.$navigation_item['link'].'\',\'window_chat'.$_SESSION['_cid'].'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')" target="'.$navigation_item['target'].'"';
  1099. } else {
  1100. $html .= '<a href="'.$navigation_item['link'].'"';
  1101. }
  1102. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  1103. $html .= ' id="here"';
  1104. }
  1105. $html .= ' target="_top" title="'.$navigation_item['name'].'">';
  1106. $html .= '<img src="'.api_get_path(WEB_IMG_PATH).$navigation_item['image'].'" alt="'.$navigation_item['name'].'"/>';
  1107. $html .= '</a> ';
  1108. if ($orientation == SHORTCUTS_VERTICAL) {
  1109. $html .= '<br />';
  1110. }
  1111. }
  1112. $html .= '</div>';
  1113. }
  1114. return $html;
  1115. }
  1116. /**
  1117. * List course homepage tools from authoring and interaction sections
  1118. * @param int $courseId The course ID (guessed from context if not provided)
  1119. * @param int $sessionId The session ID (guessed from context if not provided)
  1120. * @return array List of all tools data from the c_tools table
  1121. */
  1122. public static function toolsIconsAction($courseId = null, $sessionId = null)
  1123. {
  1124. if (empty($courseId)) {
  1125. $courseId = api_get_course_int_id();
  1126. } else {
  1127. $courseId = intval($courseId);
  1128. }
  1129. if (empty($sessionId)) {
  1130. $sessionId = api_get_session_id();
  1131. } else {
  1132. $sessionId = intval($sessionId);
  1133. }
  1134. if (empty($courseId)) {
  1135. // We shouldn't get here, but for some reason api_get_course_int_id()
  1136. // doesn't seem to get the course from the context, sometimes
  1137. return array();
  1138. }
  1139. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1140. $sql = "SELECT * FROM $table
  1141. WHERE category in ('authoring','interaction')
  1142. AND c_id = $courseId
  1143. AND session_id = $sessionId
  1144. ORDER BY id";
  1145. $result = Database::query($sql);
  1146. $data = Database::store_result($result, 'ASSOC');
  1147. return $data;
  1148. }
  1149. /**
  1150. * @param int $editIcon
  1151. * @return array
  1152. */
  1153. public static function getTool($editIcon)
  1154. {
  1155. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1156. $editIcon = intval($editIcon);
  1157. $sql = "SELECT * FROM $course_tool_table
  1158. WHERE iid = $editIcon";
  1159. $result = Database::query($sql);
  1160. $tool = Database::fetch_assoc($result, 'ASSOC');
  1161. return $tool;
  1162. }
  1163. /**
  1164. * @return string
  1165. */
  1166. public static function getCustomSysIconPath()
  1167. {
  1168. // Check if directory exists or create it if it doesn't
  1169. $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1170. if (!is_dir($dir)) {
  1171. mkdir($dir, api_get_permissions_for_new_directories(), true);
  1172. }
  1173. return $dir;
  1174. }
  1175. /**
  1176. * @return string
  1177. */
  1178. public static function getCustomWebIconPath()
  1179. {
  1180. // Check if directory exists or create it if it doesn't
  1181. $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1182. return $dir;
  1183. }
  1184. /**
  1185. * @param string $icon
  1186. * @return string
  1187. */
  1188. public static function getDisableIcon($icon)
  1189. {
  1190. $fileInfo = pathinfo($icon);
  1191. return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1192. }
  1193. /**
  1194. * @param int $id
  1195. * @param int $courseId
  1196. * @param int $sessionId
  1197. * @param $values
  1198. */
  1199. public static function updateTool($id, $values)
  1200. {
  1201. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1202. $params = [
  1203. 'name' => $values['name'],
  1204. 'link' => $values['link'],
  1205. 'target' => $values['target'],
  1206. 'visibility' => $values['visibility'],
  1207. 'description' => $values['description'],
  1208. ];
  1209. if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
  1210. $dir = self::getCustomSysIconPath();
  1211. // Resize image if it is larger than 64px
  1212. $temp = new Image($_FILES['icon']['tmp_name']);
  1213. $picture_infos = $temp->get_image_info();
  1214. if ($picture_infos['width'] > 64) {
  1215. $thumbwidth = 64;
  1216. } else {
  1217. $thumbwidth = $picture_infos['width'];
  1218. }
  1219. if ($picture_infos['height'] > 64) {
  1220. $new_height = 64;
  1221. } else {
  1222. $new_height = $picture_infos['height'];
  1223. }
  1224. $temp->resize($thumbwidth, $new_height, 0);
  1225. //copy the image to the course upload folder
  1226. $path = $dir.$_FILES['icon']['name'];
  1227. $result = $temp->send_image($path);
  1228. $temp = new Image($path);
  1229. $r = $temp->convert2bw();
  1230. $ext = pathinfo($path, PATHINFO_EXTENSION);
  1231. $bwPath = substr($path,0,-(strlen($ext)+1)) . '_na.' . $ext;
  1232. if ($r === false) {
  1233. error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
  1234. } else {
  1235. $temp->send_image($bwPath);
  1236. $iconName = $_FILES['icon']['name'];
  1237. $params['custom_icon'] = $iconName;
  1238. }
  1239. }
  1240. Database::update(
  1241. $table,
  1242. $params,
  1243. [' iid = ?' => [$id]]
  1244. );
  1245. }
  1246. /**
  1247. * @param int $id
  1248. */
  1249. public static function deleteIcon($id)
  1250. {
  1251. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1252. $tool = self::getTool($id);
  1253. if ($tool && !empty($tool['custom_icon'])) {
  1254. $file = self::getCustomSysIconPath().$tool['custom_icon'];
  1255. $fileInfo = pathinfo($file);
  1256. $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1257. $fileGray = self::getCustomSysIconPath().$fileGray;
  1258. if (file_exists($file) && is_file($file)) {
  1259. if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
  1260. unlink($file);
  1261. }
  1262. }
  1263. if (file_exists($fileGray) && is_file($fileGray)) {
  1264. if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
  1265. unlink($fileGray);
  1266. }
  1267. }
  1268. $params = [
  1269. 'custom_icon' => '',
  1270. ];
  1271. Database::update(
  1272. $table,
  1273. $params,
  1274. [' iid = ?' => [$id]]
  1275. );
  1276. }
  1277. }
  1278. }