course_home.lib.php 64 KB

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