course_home.lib.php 69 KB

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