course_home.lib.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. * @param int $courseId Optional
  405. * @param int $sessionId Optional
  406. * @return array
  407. */
  408. public static function get_tools_category($course_tool_category, $courseId = 0, $sessionId = 0)
  409. {
  410. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  411. $is_platform_admin = api_is_platform_admin();
  412. $all_tools_list = array();
  413. // Condition for the session
  414. $session_id = $sessionId ?: api_get_session_id();
  415. $course_id = $courseId ?: api_get_course_int_id();
  416. $condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
  417. switch ($course_tool_category) {
  418. case TOOL_STUDENT_VIEW:
  419. $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
  420. if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
  421. $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "'.TOOL_TRACKING.'") ) ';
  422. }
  423. $sql = "SELECT *
  424. FROM $course_tool_table t
  425. $conditions AND
  426. c_id = $course_id $condition_session
  427. ORDER BY id";
  428. $result = Database::query($sql);
  429. break;
  430. case TOOL_AUTHORING:
  431. $sql = "SELECT * FROM $course_tool_table t
  432. WHERE category = 'authoring' AND c_id = $course_id $condition_session
  433. ORDER BY id";
  434. $result = Database::query($sql);
  435. break;
  436. case TOOL_INTERACTION:
  437. $sql = "SELECT * FROM $course_tool_table t
  438. WHERE category = 'interaction' AND c_id = $course_id $condition_session
  439. ORDER BY id";
  440. $result = Database::query($sql);
  441. break;
  442. case TOOL_ADMIN_VISIBLE:
  443. $sql = "SELECT * FROM $course_tool_table t
  444. WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session
  445. ORDER BY id";
  446. $result = Database::query($sql);
  447. break;
  448. case TOOL_ADMIN_PLATFORM:
  449. $sql = "SELECT * FROM $course_tool_table t
  450. WHERE category = 'admin' AND c_id = $course_id $condition_session
  451. ORDER BY id";
  452. $result = Database::query($sql);
  453. break;
  454. case TOOL_DRH:
  455. $sql = "SELECT * FROM $course_tool_table t
  456. WHERE name IN ('tracking') AND c_id = $course_id $condition_session
  457. ORDER BY id";
  458. $result = Database::query($sql);
  459. break;
  460. case TOOL_COURSE_PLUGIN:
  461. //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
  462. // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
  463. $sql = "SELECT * FROM $course_tool_table t
  464. WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session
  465. ORDER BY id";
  466. $result = Database::query($sql);
  467. break;
  468. }
  469. //Get the list of hidden tools - this might imply performance slowdowns
  470. // if the course homepage is loaded many times, so the list of hidden
  471. // tools might benefit from a shared memory storage later on
  472. $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
  473. $hide_list = array();
  474. $check = false;
  475. foreach ($list as $line) {
  476. // Admin can see all tools even if the course_hide_tools configuration is set
  477. if ($is_platform_admin) {
  478. continue;
  479. }
  480. if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
  481. $hide_list[] = $line['subkey'];
  482. $check = true;
  483. }
  484. }
  485. while ($temp_row = Database::fetch_assoc($result)) {
  486. $add = false;
  487. if ($check) {
  488. if (!in_array($temp_row['name'], $hide_list)) {
  489. $add = true;
  490. }
  491. } else {
  492. $add = true;
  493. }
  494. if ($temp_row['image'] == 'scormbuilder.gif') {
  495. $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
  496. $lp = new learnpath(
  497. api_get_course_id(),
  498. $lp_id,
  499. api_get_user_id()
  500. );
  501. $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
  502. $add = $lp->is_lp_visible_for_student(
  503. $lp_id,
  504. api_get_user_id(),
  505. api_get_course_id(),
  506. api_get_session_id()
  507. );
  508. if ($path) {
  509. $temp_row['custom_image'] = $path;
  510. }
  511. }
  512. if ($add) {
  513. $all_tools_list[] = $temp_row;
  514. }
  515. }
  516. // Grabbing all the links that have the property on_homepage set to 1
  517. $course_link_table = Database::get_course_table(TABLE_LINK);
  518. $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  519. $condition_session = api_get_session_condition($session_id, true, true, 'tip.session_id');
  520. switch ($course_tool_category) {
  521. case TOOL_AUTHORING:
  522. $sql_links = "SELECT tl.*, tip.visibility
  523. FROM $course_link_table tl
  524. LEFT JOIN $course_item_property_table tip
  525. ON tip.tool='link' AND tip.ref=tl.id
  526. WHERE
  527. tl.c_id = $course_id AND
  528. tip.c_id = $course_id AND
  529. tl.on_homepage='1' $condition_session";
  530. break;
  531. case TOOL_INTERACTION:
  532. $sql_links = null;
  533. /*
  534. $sql_links = "SELECT tl.*, tip.visibility
  535. FROM $course_link_table tl
  536. LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
  537. WHERE tl.on_homepage='1' ";
  538. */
  539. break;
  540. case TOOL_STUDENT_VIEW:
  541. $sql_links = "SELECT tl.*, tip.visibility
  542. FROM $course_link_table tl
  543. LEFT JOIN $course_item_property_table tip
  544. ON tip.tool='link' AND tip.ref=tl.id
  545. WHERE
  546. tl.c_id = $course_id AND
  547. tip.c_id = $course_id AND
  548. tl.on_homepage ='1' $condition_session";
  549. break;
  550. case TOOL_ADMIN:
  551. $sql_links = "SELECT tl.*, tip.visibility
  552. FROM $course_link_table tl
  553. LEFT JOIN $course_item_property_table tip
  554. ON tip.tool='link' AND tip.ref=tl.id
  555. WHERE
  556. tl.c_id = $course_id AND
  557. tip.c_id = $course_id AND
  558. tl.on_homepage='1' $condition_session";
  559. break;
  560. default:
  561. $sql_links = null;
  562. break;
  563. }
  564. // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
  565. if ($sql_links != null) {
  566. $result_links = Database::query($sql_links);
  567. if (Database::num_rows($result_links) > 0) {
  568. while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
  569. $properties = array();
  570. $properties['name'] = $links_row['title'];
  571. $properties['session_id'] = $links_row['session_id'];
  572. $properties['link'] = $links_row['url'];
  573. $properties['visibility'] = $links_row['visibility'];
  574. $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
  575. $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id'];
  576. $properties['target'] = $links_row['target'];
  577. $tmp_all_tools_list[] = $properties;
  578. }
  579. }
  580. }
  581. if (isset($tmp_all_tools_list)) {
  582. foreach ($tmp_all_tools_list as $tool) {
  583. if ($tool['image'] == 'blog.gif') {
  584. // Init
  585. $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
  586. // Get blog id
  587. $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
  588. // Get blog members
  589. if ($is_platform_admin) {
  590. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  591. WHERE blog_id =".$blog_id;
  592. } else {
  593. $sql_blogs = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user
  594. WHERE blog_id =".$blog_id." AND user_id = ".api_get_user_id();
  595. }
  596. $result_blogs = Database::query($sql_blogs);
  597. if (Database::num_rows($result_blogs) > 0) {
  598. $all_tools_list[] = $tool;
  599. }
  600. } else {
  601. $all_tools_list[] = $tool;
  602. }
  603. }
  604. }
  605. return $all_tools_list;
  606. }
  607. /**
  608. * Displays the tools of a certain category.
  609. * @param array $all_tools_list List of tools as returned by get_tools_category()
  610. * @param bool $rows
  611. *
  612. * @return string
  613. */
  614. public static function show_tools_category($all_tools_list, $rows = false)
  615. {
  616. $_user = api_get_user_info();
  617. $theme = api_get_setting('homepage_view');
  618. if ($theme === 'vertical_activity') {
  619. //ordering by get_lang name
  620. $order_tool_list = array();
  621. if (is_array($all_tools_list) && count($all_tools_list) > 0) {
  622. foreach ($all_tools_list as $key => $new_tool) {
  623. $tool_name = self::translate_tool_name($new_tool);
  624. $order_tool_list [$key] = $tool_name;
  625. }
  626. natsort($order_tool_list);
  627. $my_temp_tool_array = array();
  628. foreach ($order_tool_list as $key => $new_tool) {
  629. $my_temp_tool_array[] = $all_tools_list[$key];
  630. }
  631. $all_tools_list = $my_temp_tool_array;
  632. } else {
  633. $all_tools_list = array();
  634. }
  635. }
  636. $web_code_path = api_get_path(WEB_CODE_PATH);
  637. $session_id = api_get_session_id();
  638. $is_platform_admin = api_is_platform_admin();
  639. if ($session_id == 0 ) {
  640. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
  641. } else {
  642. $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
  643. }
  644. $i = 0;
  645. $items = array();
  646. $app_plugin = new AppPlugin();
  647. if (isset($all_tools_list)) {
  648. $lnk = '';
  649. foreach ($all_tools_list as & $tool) {
  650. $item = array();
  651. $studentview = false;
  652. $tool['original_link'] = $tool['link'];
  653. if ($tool['image'] == 'scormbuilder.gif') {
  654. // check if the published learnpath is visible for student
  655. $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
  656. if (api_is_allowed_to_edit(null, true)) {
  657. $studentview = true;
  658. }
  659. if (!api_is_allowed_to_edit(null, true) &&
  660. !learnpath::is_lp_visible_for_student(
  661. $published_lp_id,
  662. api_get_user_id(),
  663. api_get_course_id(),
  664. api_get_session_id()
  665. )
  666. ) {
  667. continue;
  668. }
  669. }
  670. if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
  671. continue;
  672. }
  673. // This part displays the links to hide or remove a tool.
  674. // These links are only visible by the course manager.
  675. unset($lnk);
  676. $item['extra'] = null;
  677. $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
  678. if ($is_allowed_to_edit) {
  679. if (empty($session_id)) {
  680. if (isset($tool['id'])) {
  681. if ($tool['visibility'] == '1' && $toolAdmin != '1') {
  682. $link['name'] = Display::return_icon(
  683. 'visible.png',
  684. get_lang('Deactivate'),
  685. array('id' => 'linktool_'.$tool['id']),
  686. ICON_SIZE_SMALL,
  687. false
  688. );
  689. $link['cmd'] = 'hide=yes';
  690. $lnk[] = $link;
  691. }
  692. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  693. $link['name'] = Display::return_icon(
  694. 'invisible.png',
  695. get_lang('Activate'),
  696. array('id' => 'linktool_'.$tool['id']),
  697. ICON_SIZE_SMALL,
  698. false
  699. );
  700. $link['cmd'] = 'restore=yes';
  701. $lnk[] = $link;
  702. }
  703. }
  704. }
  705. if (!empty($tool['adminlink'])) {
  706. $item['extra'] = '<a href="'.$tool['adminlink'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
  707. }
  708. }
  709. // Both checks are necessary as is_platform_admin doesn't take student view into account
  710. if ($is_platform_admin && $is_allowed_to_edit) {
  711. if ($toolAdmin != '1') {
  712. $link['cmd'] = 'hide=yes';
  713. }
  714. }
  715. $item['visibility'] = null;
  716. if (isset($lnk) && is_array($lnk)) {
  717. foreach ($lnk as $this_link) {
  718. if (empty($tool['adminlink'])) {
  719. $item['visibility'] .= '<a class="make_visible_and_invisible" href="'.api_get_self().'?'.api_get_cidreq().'&amp;id='.$tool['id'].'&amp;'.$this_link['cmd'].'">'.
  720. $this_link['name'].'</a>';
  721. }
  722. }
  723. } else {
  724. $item['visibility'] .= '';
  725. }
  726. // NOTE : Table contains only the image file name, not full path
  727. if (stripos($tool['link'], 'http://') === false &&
  728. stripos($tool['link'], 'https://') === false &&
  729. stripos($tool['link'], 'ftp://') === false
  730. ) {
  731. $tool['link'] = $web_code_path.$tool['link'];
  732. }
  733. if ($tool['visibility'] == '0' && $toolAdmin != '1') {
  734. $class = 'text-muted';
  735. $info = pathinfo($tool['image']);
  736. $basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
  737. $tool['image'] = $basename.'_na.'.$info['extension'];
  738. } else {
  739. $class = '';
  740. }
  741. $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
  742. // If it's a link, we don't add the cidReq
  743. if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
  744. $tool['link'] = $tool['link'].$qm_or_amp;
  745. } else {
  746. $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
  747. }
  748. $tool_link_params = array();
  749. $toolId = isset($tool["id"]) ? $tool["id"] : null;
  750. //@todo this visio stuff should be removed
  751. if (strpos($tool['name'], 'visio_') !== false) {
  752. $tool_link_params = array(
  753. 'id' => 'tooldesc_'.$toolId,
  754. 'href' => '"javascript: void(0);"',
  755. 'class' => $class,
  756. '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\')',
  757. 'target' => $tool['target']
  758. );
  759. } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
  760. $tool_link_params = array(
  761. 'id' => 'tooldesc_'.$toolId,
  762. 'class' => $class,
  763. 'href' => 'javascript: void(0);',
  764. '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
  765. 'target' => $tool['target']
  766. );
  767. } else {
  768. $tool_link_params = array(
  769. 'id' => 'tooldesc_'.$toolId,
  770. 'href' => $tool['link'],
  771. 'class' => $class,
  772. 'target' => $tool['target']
  773. );
  774. }
  775. $tool_name = self::translate_tool_name($tool);
  776. // Including Courses Plugins
  777. // Creating title and the link
  778. if (isset($tool['category']) && $tool['category'] == 'plugin') {
  779. $plugin_info = $app_plugin->getPluginInfo($tool['name']);
  780. if (isset($plugin_info) && isset($plugin_info['title'])) {
  781. $tool_name = $plugin_info['title'];
  782. }
  783. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
  784. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
  785. $tool['image'] = 'plugins.png';
  786. }
  787. $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
  788. }
  789. $icon = Display::return_icon(
  790. $tool['image'],
  791. $tool_name,
  792. array('class' => 'tool-icon', 'id' => 'toolimage_'.$toolId),
  793. ICON_SIZE_BIG,
  794. false
  795. );
  796. /*if (!empty($tool['custom_icon'])) {
  797. $image = self::getCustomWebIconPath().$tool['custom_icon'];
  798. $icon = Display::img(
  799. $image,
  800. $tool['description'],
  801. array(
  802. 'class' => 'tool-icon',
  803. 'id' => 'toolimage_'.$tool['id']
  804. )
  805. );
  806. }*/
  807. // Validation when belongs to a session
  808. $session_img = api_get_session_image($tool['session_id'], (!empty($_user['status']) ? $_user['status'] : ''));
  809. if ($studentview) {
  810. $tool_link_params['href'] .= '&isStudentView=true';
  811. }
  812. $item['url_params'] = $tool_link_params;
  813. $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
  814. $item['tool'] = $tool;
  815. $item['name'] = $tool_name;
  816. $tool_link_params['id'] = 'is'.$tool_link_params['id'];
  817. $item['link'] = Display::url(
  818. $tool_name.$session_img,
  819. $tool_link_params['href'],
  820. $tool_link_params
  821. );
  822. $items[] = $item;
  823. $i++;
  824. } // end of foreach
  825. }
  826. $i = 0;
  827. $html = '';
  828. if (!empty($items)) {
  829. foreach ($items as $item) {
  830. switch ($theme) {
  831. case 'activity_big':
  832. $data = '';
  833. $html .= '<div class="col-xs-6 col-md-3 course-tool">';
  834. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  835. $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null;
  836. if (isset($item['tool']['custom_image'])) {
  837. $original_image = Display::img(
  838. $item['tool']['custom_image'],
  839. $item['name'],
  840. array('id' => 'toolimage_'.$toolId)
  841. );
  842. } elseif (isset($item['tool']['custom_icon']) &&
  843. !empty($item['tool']['custom_icon'])
  844. ) {
  845. $customIcon = $item['tool']['custom_icon'];
  846. if ($item['tool']['visibility'] == '0') {
  847. $fileInfo = pathinfo($item['tool']['custom_icon']);
  848. $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
  849. }
  850. $original_image = Display::img(
  851. self::getCustomWebIconPath().$customIcon,
  852. $item['name'],
  853. array('id' => 'toolimage_'.$toolId)
  854. );
  855. } else {
  856. $original_image = Display::return_icon(
  857. $image,
  858. $item['name'],
  859. array('id' => 'toolimage_'.$toolId),
  860. ICON_SIZE_BIG,
  861. false
  862. );
  863. }
  864. $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
  865. $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection
  866. $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content'));
  867. $html .= '</div>';
  868. break;
  869. case 'activity':
  870. $html .= '<div class="offset2 col-md-4 course-tool">';
  871. $html .= $item['extra'];
  872. $html .= $item['visibility'];
  873. $html .= $item['icon'];
  874. $html .= $item['link'];
  875. $html .= '</div>';
  876. break;
  877. case 'vertical_activity':
  878. if ($i == 0) {
  879. $html .= '<ul>';
  880. }
  881. $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
  882. $original_image = Display::return_icon(
  883. $image,
  884. $item['name'],
  885. array('id' => 'toolimage_'.$item['tool']['id']),
  886. ICON_SIZE_SMALL,
  887. false
  888. );
  889. $html .= '<li class="course-tool">';
  890. $html .= $item['extra'];
  891. $html .= $item['visibility'];
  892. $url = Display::url($original_image, $item['url_params']['href'], $item['url_params']);
  893. $html .= $url;
  894. $html .= $item['link'];
  895. $html .= '</li>';
  896. if ($i == count($items) - 1) {
  897. $html .= '</ul>';
  898. }
  899. break;
  900. }
  901. $i++;
  902. }
  903. }
  904. return $html;
  905. }
  906. /**
  907. * Shows the general data for a particular meeting
  908. *
  909. * @param id session id
  910. * @return string session data
  911. */
  912. public static function show_session_data($id_session)
  913. {
  914. $session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  915. $sessionInfo = api_get_session_info($id_session);
  916. if (empty($sessionInfo)) {
  917. return '';
  918. }
  919. $sql = 'SELECT name FROM '.$session_category_table.'
  920. WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
  921. $rs_category = Database::query($sql);
  922. $session_category = '';
  923. if (Database::num_rows($rs_category) > 0) {
  924. $rows_session_category = Database::store_result($rs_category);
  925. $rows_session_category = $rows_session_category[0];
  926. $session_category = $rows_session_category['name'];
  927. }
  928. $coachInfo = api_get_user_info($sessionInfo['id_coach']);
  929. $output = '';
  930. if (!empty($session_category)) {
  931. $output .= '<tr><td>'.get_lang('SessionCategory').': '.'<b>'.$session_category.'</b></td></tr>';
  932. }
  933. $dateInfo = SessionManager::parseSessionDates($sessionInfo);
  934. $msgDate = $dateInfo['access'];
  935. $output .= '<tr>
  936. <td style="width:50%">'.get_lang('SessionName').': '.'<b>'.$sessionInfo['name'].'</b></td>
  937. <td>'.get_lang('GeneralCoach').': '.'<b>'.$coachInfo['complete_name'].'</b></td></tr>';
  938. $output .= '<tr>
  939. <td>'.get_lang('SessionIdentifier').': '.
  940. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')).'
  941. </td>
  942. <td>'.get_lang('Date').': '.'<b>'.$msgDate.'</b>
  943. </td>
  944. </tr>';
  945. return $output;
  946. }
  947. /**
  948. * Retrieves the name-field within a tool-record and translates it on necessity.
  949. * @param array $tool The input record.
  950. * @return string Returns the name of the corresponding tool.
  951. */
  952. public static function translate_tool_name(& $tool)
  953. {
  954. static $already_translated_icons = array(
  955. 'file_html.gif',
  956. 'file_html_na.gif',
  957. 'file_html.png',
  958. 'file_html_na.png',
  959. 'scormbuilder.gif',
  960. 'scormbuilder_na.gif',
  961. 'blog.gif',
  962. 'blog_na.gif',
  963. 'external.gif',
  964. 'external_na.gif'
  965. );
  966. $toolName = Security::remove_XSS(stripslashes($tool['name']));
  967. if (in_array($tool['image'], $already_translated_icons)) {
  968. return $toolName;
  969. }
  970. $toolName = api_underscore_to_camel_case($toolName);
  971. if (isset($GLOBALS['Tool' . $toolName])) {
  972. return get_lang('Tool' . $toolName);
  973. }
  974. return $toolName;
  975. }
  976. /**
  977. * Get published learning path id from link inside course home
  978. * @param string Link to published lp
  979. * @return int Learning path id
  980. */
  981. public static function get_published_lp_id_from_link($published_lp_link)
  982. {
  983. $lp_id = 0;
  984. $param_lp_id = strstr($published_lp_link, 'lp_id=');
  985. if (!empty($param_lp_id)) {
  986. $a_param_lp_id = explode('=', $param_lp_id);
  987. if (isset($a_param_lp_id[1])) {
  988. $lp_id = intval($a_param_lp_id[1]);
  989. }
  990. }
  991. return $lp_id;
  992. }
  993. /**
  994. * @param bool $include_admin_tools
  995. * @return array
  996. */
  997. public static function get_navigation_items($include_admin_tools = false)
  998. {
  999. $navigation_items = array();
  1000. $course_id = api_get_course_int_id();
  1001. $courseInfo = api_get_course_info();
  1002. $sessionId = api_get_session_id();
  1003. if (!empty($course_id)) {
  1004. $course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
  1005. /* Link to the Course homepage */
  1006. $navigation_items['home']['image'] = 'home.gif';
  1007. $navigation_items['home']['link'] = $courseInfo['course_public_url'];
  1008. $navigation_items['home']['name'] = get_lang('CourseHomepageLink');
  1009. $sql = "SELECT * FROM $course_tools_table
  1010. WHERE c_id = $course_id AND visibility='1' and admin='0'
  1011. ORDER BY id ASC";
  1012. $sql_result = Database::query($sql);
  1013. while ($row = Database::fetch_array($sql_result)) {
  1014. $navigation_items[$row['id']] = $row;
  1015. if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
  1016. $navigation_items[$row['id']]['link'] = api_get_path(WEB_CODE_PATH).$row['link'];
  1017. $navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
  1018. }
  1019. }
  1020. /* Admin (edit rights) only links
  1021. - Course settings (course admin only)
  1022. - Course rights (roles & rights overview) */
  1023. if ($include_admin_tools) {
  1024. $sql = "SELECT name, image FROM $course_tools_table
  1025. WHERE c_id = $course_id AND link='course_info/infocours.php'";
  1026. $sql_result = Database::query($sql);
  1027. $course_setting_info = Database::fetch_array($sql_result);
  1028. $course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
  1029. if ($sessionId == 0) {
  1030. // course settings item
  1031. $navigation_items['course_settings']['image'] = $course_setting_info['image'];
  1032. $navigation_items['course_settings']['link'] = api_get_path(WEB_CODE_PATH).'course_info/infocours.php';
  1033. $navigation_items['course_settings']['name'] = $course_setting_visual_name;
  1034. }
  1035. }
  1036. }
  1037. foreach ($navigation_items as $key => $navigation_item) {
  1038. if (strstr($navigation_item['link'], '?')) {
  1039. //link already contains a parameter, add course id parameter with &
  1040. $parameter_separator = '&amp;';
  1041. } else {
  1042. //link doesn't contain a parameter yet, add course id parameter with ?
  1043. $parameter_separator = '?';
  1044. }
  1045. //$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
  1046. $navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.$sessionId;
  1047. }
  1048. return $navigation_items;
  1049. }
  1050. /**
  1051. * Show a navigation menu
  1052. */
  1053. public static function show_navigation_menu()
  1054. {
  1055. $navigation_items = self::get_navigation_items(true);
  1056. $course_id = api_get_course_id();
  1057. $class= null;
  1058. $idLearn = null;
  1059. $item = null;
  1060. $marginLeft = 160;
  1061. $html = '<div id="toolnav">';
  1062. $html .= '<ul id="toolnavbox">';
  1063. $count = 0;
  1064. foreach ($navigation_items as $key => $navigation_item) {
  1065. //students can't see the course settings option
  1066. $count++;
  1067. if (!api_is_allowed_to_edit() && $key == 'course_settings') {
  1068. continue;
  1069. }
  1070. $html .= '<li>';
  1071. $url_item = parse_url($navigation_item['link']);
  1072. $url_current = parse_url($_SERVER['REQUEST_URI']);
  1073. if (api_get_setting('show_navigation_menu') == 'text') {
  1074. $class = 'text';
  1075. $marginLeft = 170;
  1076. $item = $navigation_item['name'];
  1077. } else if (api_get_setting('show_navigation_menu') == 'icons') {
  1078. $class = 'icons';
  1079. $marginLeft = 25;
  1080. $item = Display::return_icon(substr($navigation_item['image'],0,-3)."png", $navigation_item['name'], array('class'=>'tool-img'), ICON_SIZE_SMALL);
  1081. } else {
  1082. $class = 'icons-text';
  1083. $item = $navigation_item['name'] . Display::return_icon(substr($navigation_item['image'],0,-3)."png", $navigation_item['name'], array('class'=>'tool-img'), ICON_SIZE_SMALL);
  1084. }
  1085. if (stristr($url_item['path'], $url_current['path'])) {
  1086. if (!isset($_GET['learnpath_id']) || strpos($url_item['query'], 'learnpath_id='.intval($_GET['learnpath_id'])) === 0) {
  1087. $idLearn = ' id="here"';
  1088. }
  1089. }
  1090. if (strpos($navigation_item['link'], 'chat') !== false &&
  1091. api_get_course_setting('allow_open_chat_window', $course_id)
  1092. ) {
  1093. $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'].'"';
  1094. $html .= ' title="'.$navigation_item['name'].'">';
  1095. $html .= $item;
  1096. $html .= '</a>';
  1097. } else {
  1098. $html .= '<a ' . $idLearn . ' class="btn btn-default text-left ' . $class . '" href="'.$navigation_item['link'].'" target="_top" title="'.$navigation_item['name'].'">';
  1099. $html .= $item;
  1100. $html .= '</a>';
  1101. }
  1102. $html .= '</li>';
  1103. }
  1104. $html .= '</ul>';
  1105. $html .= '<script>$(function() {
  1106. $("#toolnavbox a").stop().animate({"margin-left":"-' . $marginLeft . 'px"},1000);
  1107. $("#toolnavbox > li").hover(
  1108. function () {
  1109. $("a",$(this)).stop().animate({"margin-left":"-2px"},200);
  1110. $("span",$(this)).css("display","block");
  1111. },
  1112. function () {
  1113. $("a",$(this)).stop().animate({"margin-left":"-' . $marginLeft . 'px"},200);
  1114. $("span",$(this)).css("display","initial");
  1115. }
  1116. );
  1117. });</script>';
  1118. $html .= '</div>';
  1119. return $html;
  1120. }
  1121. /**
  1122. * Show a toolbar with shortcuts to the course tool
  1123. * @param int $orientation
  1124. *
  1125. * @return string
  1126. */
  1127. public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
  1128. {
  1129. $navigation_items = self::get_navigation_items(false);
  1130. $html = '';
  1131. if (!empty($navigation_items)) {
  1132. if ($orientation == SHORTCUTS_HORIZONTAL) {
  1133. $style_id = "toolshortcuts_horizontal";
  1134. } else {
  1135. $style_id = "toolshortcuts_vertical";
  1136. }
  1137. $html .= '<div id="'.$style_id.'">';
  1138. foreach ($navigation_items as $key => $navigation_item) {
  1139. if (strpos($navigation_item['link'], 'chat') !== false &&
  1140. api_get_course_setting('allow_open_chat_window')
  1141. ) {
  1142. $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'].'"';
  1143. } else {
  1144. $html .= '<a class="items-icon" href="'.$navigation_item['link'].'"';
  1145. }
  1146. if (strpos(api_get_self(), $navigation_item['link']) !== false) {
  1147. $html .= ' id="here"';
  1148. }
  1149. $html .= ' target="_top" title="'.$navigation_item['name'].'">';
  1150. if (isset($navigation_item['category']) && $navigation_item['category'] == 'plugin') {
  1151. /*$plugin_info = $app_plugin->getPluginInfo($navigation_item['name']);
  1152. if (isset($plugin_info) && isset($plugin_info['title'])) {
  1153. $tool_name = $plugin_info['title'];
  1154. }*/
  1155. if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$navigation_item['image']) &&
  1156. !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/'.ICON_SIZE_MEDIUM.'/'.$navigation_item['image'])
  1157. ) {
  1158. $navigation_item['image'] = 'plugins.png';
  1159. }
  1160. //$tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$navigation_item['link'].'?'.api_get_cidreq();
  1161. }
  1162. $html .= Display::return_icon(
  1163. substr($navigation_item['image'], 0, -3).'png',
  1164. $navigation_item['name'],
  1165. [],
  1166. ICON_SIZE_MEDIUM
  1167. );
  1168. $html .= '</a> ';
  1169. if ($orientation == SHORTCUTS_VERTICAL) {
  1170. $html .= '<br />';
  1171. }
  1172. }
  1173. $html .= '</div>';
  1174. }
  1175. return $html;
  1176. }
  1177. /**
  1178. * List course homepage tools from authoring and interaction sections
  1179. * @param int $courseId The course ID (guessed from context if not provided)
  1180. * @param int $sessionId The session ID (guessed from context if not provided)
  1181. * @return array List of all tools data from the c_tools table
  1182. */
  1183. public static function toolsIconsAction($courseId = null, $sessionId = null)
  1184. {
  1185. if (empty($courseId)) {
  1186. $courseId = api_get_course_int_id();
  1187. } else {
  1188. $courseId = intval($courseId);
  1189. }
  1190. if (empty($sessionId)) {
  1191. $sessionId = api_get_session_id();
  1192. } else {
  1193. $sessionId = intval($sessionId);
  1194. }
  1195. if (empty($courseId)) {
  1196. // We shouldn't get here, but for some reason api_get_course_int_id()
  1197. // doesn't seem to get the course from the context, sometimes
  1198. return array();
  1199. }
  1200. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1201. $sql = "SELECT * FROM $table
  1202. WHERE category in ('authoring','interaction')
  1203. AND c_id = $courseId
  1204. AND session_id = $sessionId
  1205. ORDER BY id";
  1206. $result = Database::query($sql);
  1207. $data = Database::store_result($result, 'ASSOC');
  1208. return $data;
  1209. }
  1210. /**
  1211. * @param int $editIcon
  1212. * @return array
  1213. */
  1214. public static function getTool($editIcon)
  1215. {
  1216. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  1217. $editIcon = intval($editIcon);
  1218. $sql = "SELECT * FROM $course_tool_table
  1219. WHERE iid = $editIcon";
  1220. $result = Database::query($sql);
  1221. $tool = Database::fetch_assoc($result, 'ASSOC');
  1222. return $tool;
  1223. }
  1224. /**
  1225. * @return string
  1226. */
  1227. public static function getCustomSysIconPath()
  1228. {
  1229. // Check if directory exists or create it if it doesn't
  1230. $dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1231. if (!is_dir($dir)) {
  1232. mkdir($dir, api_get_permissions_for_new_directories(), true);
  1233. }
  1234. return $dir;
  1235. }
  1236. /**
  1237. * @return string
  1238. */
  1239. public static function getCustomWebIconPath()
  1240. {
  1241. // Check if directory exists or create it if it doesn't
  1242. $dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
  1243. return $dir;
  1244. }
  1245. /**
  1246. * @param string $icon
  1247. * @return string
  1248. */
  1249. public static function getDisableIcon($icon)
  1250. {
  1251. $fileInfo = pathinfo($icon);
  1252. return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1253. }
  1254. /**
  1255. * @param int $id
  1256. * @param array $values
  1257. */
  1258. public static function updateTool($id, $values)
  1259. {
  1260. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1261. $params = [
  1262. 'name' => $values['name'],
  1263. 'link' => $values['link'],
  1264. 'target' => $values['target'],
  1265. 'visibility' => $values['visibility'],
  1266. 'description' => $values['description'],
  1267. ];
  1268. if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
  1269. $dir = self::getCustomSysIconPath();
  1270. // Resize image if it is larger than 64px
  1271. $temp = new Image($_FILES['icon']['tmp_name']);
  1272. $picture_infos = $temp->get_image_info();
  1273. if ($picture_infos['width'] > 64) {
  1274. $thumbwidth = 64;
  1275. } else {
  1276. $thumbwidth = $picture_infos['width'];
  1277. }
  1278. if ($picture_infos['height'] > 64) {
  1279. $new_height = 64;
  1280. } else {
  1281. $new_height = $picture_infos['height'];
  1282. }
  1283. $temp->resize($thumbwidth, $new_height, 0);
  1284. //copy the image to the course upload folder
  1285. $path = $dir.$_FILES['icon']['name'];
  1286. $result = $temp->send_image($path);
  1287. $temp = new Image($path);
  1288. $r = $temp->convert2bw();
  1289. $ext = pathinfo($path, PATHINFO_EXTENSION);
  1290. $bwPath = substr($path,0,-(strlen($ext)+1)) . '_na.' . $ext;
  1291. if ($r === false) {
  1292. error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
  1293. } else {
  1294. $temp->send_image($bwPath);
  1295. $iconName = $_FILES['icon']['name'];
  1296. $params['custom_icon'] = $iconName;
  1297. }
  1298. }
  1299. Database::update(
  1300. $table,
  1301. $params,
  1302. [' iid = ?' => [$id]]
  1303. );
  1304. }
  1305. /**
  1306. * @param int $id
  1307. */
  1308. public static function deleteIcon($id)
  1309. {
  1310. $table = Database::get_course_table(TABLE_TOOL_LIST);
  1311. $tool = self::getTool($id);
  1312. if ($tool && !empty($tool['custom_icon'])) {
  1313. $file = self::getCustomSysIconPath().$tool['custom_icon'];
  1314. $fileInfo = pathinfo($file);
  1315. $fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
  1316. $fileGray = self::getCustomSysIconPath().$fileGray;
  1317. if (file_exists($file) && is_file($file)) {
  1318. if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
  1319. unlink($file);
  1320. }
  1321. }
  1322. if (file_exists($fileGray) && is_file($fileGray)) {
  1323. if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
  1324. unlink($fileGray);
  1325. }
  1326. }
  1327. $params = [
  1328. 'custom_icon' => ''
  1329. ];
  1330. Database::update(
  1331. $table,
  1332. $params,
  1333. [' iid = ?' => [$id]]
  1334. );
  1335. }
  1336. }
  1337. }