course_home.lib.php 65 KB

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