course_home.lib.php 61 KB

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