course_home.lib.php 66 KB

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