course_home.lib.php 71 KB

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