course_home.lib.php 64 KB

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