resourcelinker.inc.php 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool - original version
  5. * @author Denes Nagy - further improvements for learning path builder
  6. * @author Roan Embrechts - refactoring to improve code organisation
  7. * @package chamilo.resourcelinker
  8. * @todo use the constants for the tools
  9. * @todo use Database API instead of creating table names locally.
  10. */
  11. /**
  12. * Code
  13. */
  14. /* INIT SECTION */
  15. //$language_file = 'resourcelinker';
  16. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  17. use \ChamiloSession as Session;
  18. $use_anonymous = true;
  19. require_once '../inc/global.inc.php';
  20. require_once api_get_path(SYS_CODE_PATH).'lang/english/resourcelinker.inc.php';
  21. if (!empty($_course['language'])) {
  22. $resource_linker_file = api_get_path(SYS_CODE_PATH).'lang/'.$_course['language'].'/resourcelinker.inc.php';
  23. if (file_exists($resource_linker_file)) {
  24. require_once $resource_linker_file;
  25. }
  26. }
  27. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  28. /* FUNCTIONS */
  29. function unset_session_resources()
  30. {
  31. $_SESSION['addedresource'] = '';
  32. $_SESSION['addedresourceid'] = '';
  33. Session::erase(addedresource);
  34. Session::erase(addedresourceid);
  35. }
  36. /**
  37. * Insert description here.
  38. */
  39. function show_folder_up()
  40. {
  41. global $folder;
  42. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  43. $level = FileManager::get_levels($folder);
  44. if ($level == 1) {
  45. echo "<a href='".api_get_self(
  46. )."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang(
  47. 'LevelUp'
  48. )."</a>";
  49. }
  50. if ($level && $level != 0 && $level != 1) {
  51. $folder_up = $folder;
  52. $folder_temp = explode('/', $folder);
  53. $last = count($folder_temp) - 1;
  54. unset($folder_temp[$last]);
  55. $folder_up = implode('/', $folder_temp);
  56. echo "<a href='".api_get_self(
  57. )."?content=Document&amp;source_forum=".$_GET['source_forum']."&amp;folder=$folder_up&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no'><img src='../img/folder_up.gif' border='0' />".get_lang(
  58. 'LevelUp'
  59. )."</a>";
  60. }
  61. }
  62. /**
  63. * Shows the documents of the document tool
  64. * @param $folder
  65. */
  66. function show_documents($folder)
  67. {
  68. $_course = api_get_course_info();
  69. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  70. // Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)
  71. // other tools do not have this feature.
  72. if (api_is_allowed_to_edit()) {
  73. $visibility = "ip.visibility<>'2'";
  74. } else {
  75. $visibility = "ip.visibility='1'";
  76. }
  77. $course_id = api_get_course_int_id();
  78. $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
  79. $document_table = Database::get_course_table(TABLE_DOCUMENT);
  80. $sql = "SELECT * from $document_table docs , $item_property_table ip
  81. WHERE docs.c_id = $course_id AND
  82. ip.c_id = $course_id AND
  83. docs.id=ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND $visibility AND ip.to_group_id = 0 AND ip.to_user_id IS NULL ORDER BY docs.path ASC";
  84. $result = Database::query($sql);
  85. while ($row = Database::fetch_array($result)) {
  86. if (!$folder) {
  87. if (FileManager::get_levels($row['path']) - 1 == 1) {
  88. // showing the right icon.
  89. if (file_or_folder($row['path'])) {
  90. echo '<img src="../img/file.gif" align="middle" />';
  91. } else {
  92. $image = FileManager::choose_image($row['path']);
  93. echo "<img src=\"../img/$image\" align=\"middle\" />";
  94. }
  95. // Folders should be clickable.
  96. if (file_or_folder($row['path'])) {
  97. echo "<a href='".api_get_self()."?content=Document";
  98. echo "&folder=".substr(
  99. $row['path'],
  100. 1
  101. )."&source_id=$source_id&source_forum=".$_GET['source_forum']."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".substr(
  102. $row['path'],
  103. 1
  104. ).'</a><br />';
  105. } else {
  106. echo substr($row['path'], 1).' ';
  107. echo showorhide_addresourcelink('Document', $row['id']);
  108. echo '<br />';
  109. }
  110. }
  111. } else {
  112. // We calculate the level we are in by using the $folder in the url.
  113. // We put +1 because it does not start with an / and in the database it does
  114. $level = FileManager::get_levels($folder) + 1;
  115. // We calculate each level of the database entry.
  116. $file_level = FileManager::get_levels($row['path']) - 1;
  117. // If the level of the database entry is equal to the level we ar in, we put it into an array
  118. // as this is a potential good entry.
  119. if ($file_level == $level) {
  120. $good_paths[] = $row['path'];
  121. $good_ids[] = $row['id'];
  122. }
  123. //$haystack=$row['path'];
  124. //$conform_folder=strstr($haystack, $folder);
  125. //if (str_replace($folder.'/', '', $conform_folder) !== $folder) {
  126. // $good_folders[] = $row['path'];
  127. //echo str_replace($folder.'/', '', $conform_folder);
  128. // echo '<br />';
  129. // }// if (str_replace($folder.'/','',$conform_folder)!==$folder)
  130. } // else (if (!$folder))
  131. } //while ($row=Database::fetch_array($result))
  132. // This is code for the case that we are in a subfolder.
  133. if ($good_paths) {
  134. // We have all the potential good database entries, the good ones are those that start with $folder
  135. foreach ($good_paths as $path) {
  136. if (strstr($path, $folder)) {
  137. $good_key = key($good_paths);
  138. // Showing the right icon.
  139. if (file_or_folder($path)) {
  140. echo '<img src="../img/file.gif" align="middle" />';
  141. } else {
  142. $image = FileManager::choose_image($path);
  143. echo "<img src=\"../img/$image\" align=\"middle\" />";
  144. }
  145. // Folders should be clickable
  146. if (file_or_folder($path)) {
  147. $path = substr($path, 1); // Remove the first / in folder_up.
  148. $uri = str_replace($folder, $path, $_SERVER['REQUEST_URI']);
  149. $newuri = str_replace('add=', 'addnot=', $uri);
  150. // Using the correct name of the folder.
  151. $folder_name = str_replace($folder.'/', '', $path);
  152. echo "<a href='$newuri'>".$folder_name.'</a><br />';
  153. } else {
  154. echo str_replace("/$folder/", '', $path).' ';
  155. echo showorhide_addresourcelink('Document', $good_ids[$good_key]);
  156. echo '<br />';
  157. }
  158. }
  159. next($good_paths);
  160. }
  161. }
  162. }
  163. /**
  164. * Checks wether something is a file or a folder
  165. * 0 means file, 1 means folder
  166. * @param $filefolder
  167. * @todo use true and false instead of 1 and 0.
  168. */
  169. function file_or_folder($filefolder)
  170. {
  171. $_course = api_get_course_info();
  172. global $baseServDir;
  173. $courseDir = $_course['path'].'/document';
  174. $baseWorkDir = api_get_path(SYS_COURSE_PATH).$courseDir;
  175. return (is_dir($baseWorkDir.$filefolder) ? 1 : 0);
  176. }
  177. /**
  178. * Inserts a resource into the database
  179. *
  180. * @param $source_type
  181. * @param $source_id
  182. */
  183. function store_resources($source_type, $source_id)
  184. {
  185. $_course = api_get_course_info();
  186. $resource_table = Database::get_course_table(TABLE_LINKED_RESOURCES);
  187. $course_id = api_get_course_int_id();
  188. $addedresource = $_SESSION['addedresource'];
  189. $addedresourceid = $_SESSION['addedresourceid'];
  190. if ($_SESSION['addedresource']) {
  191. foreach ($addedresource as $resource_type) {
  192. $sql = "INSERT INTO $resource_table (c_id, source_type, source_id, resource_type, resource_id) VALUES
  193. ($course_id, '$source_type', '$source_id', '$resource_type', '".$addedresourceid[key($addedresource)]."')";
  194. Database::query($sql);
  195. $i = key($addedresource);
  196. next($addedresource);
  197. }
  198. $_SESSION['addedresource'] = '';
  199. $_SESSION['addedresourceid'] = '';
  200. }
  201. }
  202. /**
  203. * DEPRECATED - use rl_get_resource_link() instead - DEPRECATED
  204. * Displays the link that opens a new browser window that views the added resource.
  205. *
  206. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  207. * @param $type the type of the tool
  208. * @param $id the id of the resource
  209. * @param $style this is used to style the link (for instance when a resource is hidden => the added resources should also be styled like they are hidden)
  210. * @todo use the constants for the type definitions.
  211. */
  212. function display_addedresource_link($type, $id, $style = '')
  213. {
  214. $_course = api_get_course_info();
  215. $course_id = api_get_course_int_id();
  216. // Styling the link of the added resource.
  217. if ($style != '') {
  218. $styling = ' class="'.$style.'"';
  219. }
  220. switch ($type) {
  221. case 'Agenda':
  222. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  223. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  224. $myrow = Database::fetch_array($result);
  225. echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  226. break;
  227. case 'Ad_Valvas':
  228. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  229. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  230. $myrow = Database::fetch_array($result);
  231. echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
  232. break;
  233. case 'Link':
  234. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  235. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  236. $myrow = Database::fetch_array($result);
  237. echo '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode(
  238. $myrow['url']
  239. )."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
  240. break;
  241. case 'Exercise':
  242. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  243. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  244. $myrow = Database::fetch_array($result);
  245. echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
  246. break;
  247. case 'Forum':
  248. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  249. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  250. $myrow = Database::fetch_array($result);
  251. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />\n";
  252. break;
  253. case 'Thread': //=topics
  254. //@deprecated bb_posts, bb_posts_text, bb_forums
  255. /*
  256. $tbl_posts = $_course['dbNameGlu'].'bb_posts';
  257. $tbl_posts_text = $_course['dbNameGlu'].'bb_posts_text';
  258. $TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
  259. $result = Database::query("SELECT * FROM $tbl_posts posts, $TBL_FORUMS forum WHERE forum.forum_id=posts.forum_id and post_id=$id");
  260. $myrow = Database::fetch_array($result);
  261. // grabbing the title of the post
  262. $sql_title = "SELECT * FROM $tbl_posts_text WHERE c_id = $course_id AND post_id=".$myrow["post_id"];
  263. $result_title = Database::query($sql_title);
  264. $myrow_title = Database::fetch_array($result_title);
  265. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow_title['post_title']."</a><br />\n";
  266. */
  267. break;
  268. case 'Post':
  269. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  270. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND post_id = $id";
  271. $result = Database::query($sql);
  272. $post = Database::fetch_object($result);
  273. echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />\n";
  274. break;
  275. case 'Document':
  276. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  277. $result = Database::query("SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id");
  278. $myrow = Database::fetch_array($result);
  279. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  280. $last = count($pathname) - 1; // Making a correct name for the link.
  281. $filename = $pathname[$last]; // Making a correct name for the link.
  282. $image = FileManager::choose_image($filename);
  283. $ext = explode('.', $filename);
  284. $ext = strtolower($ext[sizeof($ext) - 1]);
  285. $myrow['path'] = rawurlencode($myrow['path']);
  286. $array_ext = array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png');
  287. if (api_browser_support('svg')) {
  288. $array_ext[] = 'svg';
  289. }
  290. if (api_browser_support('ogg')) {
  291. $array_ext[] = 'ogg';
  292. }
  293. $in_frames = in_array($ext, $array_ext);
  294. echo '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.'>'.$filename."</a><br />\n";
  295. break;
  296. case 'Externallink':
  297. echo '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.'>'.$id."</a><br />\n";
  298. break;
  299. }
  300. }
  301. /**
  302. * This function is to display the added resources (lessons) in the learning path player and builder
  303. * this function is a modification of display_addedresource_link($type, $id) function
  304. * the two ids are a bit confusing, I admit, but I did not want to change Patrick's work, I was
  305. * building upon it. - Denes
  306. *
  307. * Parameters:
  308. * @param completed - if ="completed" then green presentation with checkbox
  309. * @param id_in_path - if onclick then this lesson will be considered completed, that is the unique index in the items table
  310. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  311. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  312. * @param builder - if ="builder" then onclick shows in new window
  313. * @param icon - if ="icon" then the small icon will appear
  314. * if ="wrap" then wrapped settings are used (and no icon is displayed)
  315. * if ="nolink" then only the name is returned with no href and no icon (note:only in this case, the result is not displayed, but returned)
  316. * @todo this function is too long, rewrite
  317. */
  318. function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_path, $builder, $icon, $level = 0)
  319. {
  320. global $learnpath_id, $tbl_learnpath_item, $items;
  321. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  322. $_course = api_get_course_info();
  323. $course_id = api_get_course_int_id();
  324. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  325. $hyperlink_target_parameter = ''; //or e.g. 'target="_blank"'
  326. $length = ((($builder == 'builder') && ($icon == 'nolink')) ? 65 : 32);
  327. if ($builder != 'builder') {
  328. $origin = 'learnpath';
  329. } //origin = learnpath in student view
  330. $linktype = $type;
  331. if (($type == 'Link _self') or ($type == 'Link _blank')) {
  332. $type = 'Link';
  333. }
  334. // YW switched litteral tool names to use of constants declared in api.lib.php
  335. switch ($type) {
  336. case TOOL_CALENDAR_EVENT:
  337. case 'Agenda':
  338. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  339. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  340. $myrow = Database::fetch_array($result);
  341. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  342. $result = Database::query($sql);
  343. $row = Database::fetch_array($result);
  344. if ($row['title'] != '') {
  345. $myrow['title'] = $row['title'];
  346. }
  347. $desc = $row['description'];
  348. $agenda_id = $row['item_id'];
  349. echo str_repeat("&nbsp;&gt;", $level);
  350. if (($builder != 'builder') && ($icon != 'wrap')) {
  351. echo "<td>";
  352. }
  353. if ($icon != 'nolink') {
  354. if ($completed == 'completed') {
  355. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  356. } else {
  357. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  358. //echo "&nbsp;";
  359. }
  360. }
  361. if (($builder != 'builder') && ($icon != 'wrap')) {
  362. echo "</td><td>";
  363. }
  364. if ($myrow['title'] == '') {
  365. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  366. 'StepDeleted2'
  367. )."</span>";
  368. return (true);
  369. }
  370. if ($icon == 'nolink') {
  371. return (shorten($myrow['title'], $length));
  372. }
  373. if ($icon == 'icon') {
  374. echo "<img src='../img/agenda.gif' align=\"absmiddle\" alt='agenda'>";
  375. }
  376. if ($builder != 'builder') {
  377. echo "<a href=\"".api_get_self(
  378. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path\" class='$completed'>".shorten(
  379. $myrow['title'],
  380. ($length - 3 * $level)
  381. )."</a>";
  382. $items[] = api_get_self(
  383. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  384. if ($desc != '') {
  385. if ($icon != 'wrap') {
  386. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  387. $desc,
  388. ($length - 3 * $level)
  389. )."</div></td></tr>";
  390. } else {
  391. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  392. $desc,
  393. ($length - 3 * $level)
  394. )."</div>";
  395. }
  396. }
  397. } else {
  398. echo "<a href=\"../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id\" class='$completed' target='_blank'>".shorten(
  399. $myrow['title'],
  400. ($length - 3 * $level)
  401. )."</a>";
  402. }
  403. break;
  404. case TOOL_ANNOUNCEMENT:
  405. case 'Ad_Valvas':
  406. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  407. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  408. $myrow = Database::fetch_array($result);
  409. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  410. $result = Database::query($sql);
  411. $row = Database::fetch_array($result);
  412. if ($row['title'] != '') {
  413. $myrow['content'] = $row['title'];
  414. }
  415. $desc = $row['description'];
  416. $ann_id = $row['item_id'];
  417. echo str_repeat("&nbsp;&gt;", $level);
  418. // The title and the text are in the content field and we only want to display the title.
  419. list($title, $text) = split('<br>', $myrow['content']);
  420. if ($title == '') {
  421. $title = $myrow['content'];
  422. }
  423. $title = $myrow['title'];
  424. $text = $myrow['content'];
  425. if (($builder != 'builder') && ($icon != 'wrap')) {
  426. echo "<td>";
  427. }
  428. if ($icon != 'nolink') {
  429. if ($completed == 'completed') {
  430. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  431. } else {
  432. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  433. //echo "&nbsp;";
  434. }
  435. }
  436. if (($builder != 'builder') && ($icon != 'wrap')) {
  437. echo "</td><td>";
  438. }
  439. if ($title == '') {
  440. $type = 'Announcement';
  441. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  442. 'StepDeleted2'
  443. )."</span>";
  444. return (true);
  445. }
  446. if ($icon == 'nolink') {
  447. return (shorten($title, $length));
  448. }
  449. if ($icon == 'icon') {
  450. echo "<img src='../img/valves.gif' align=\"absmiddle\" alt='ad valvas'>";
  451. }
  452. if ($builder != 'builder') {
  453. echo "<a href=\"".api_get_self(
  454. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path\" class='$completed'>".shorten(
  455. $title,
  456. ($length - 3 * $level)
  457. )."</a>";
  458. $items[] = api_get_self(
  459. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$ann_id#$id_in_path";
  460. if ($desc != '') {
  461. if ($icon != 'wrap') {
  462. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  463. $desc,
  464. ($length - 3 * $level)
  465. )."</div></td></tr>";
  466. } else {
  467. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  468. $desc,
  469. ($length - 3 * $level)
  470. )."</div>";
  471. }
  472. }
  473. } else {
  474. echo "<a href=\"../announcements/announcements.php?origin=$origin&ann_id=$ann_id\" class='$completed' target='_blank'>".shorten(
  475. $title,
  476. ($length - 3 * $level)
  477. )."</a>";
  478. }
  479. break;
  480. case TOOL_LINK:
  481. case 'Link':
  482. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  483. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  484. $myrow = Database::fetch_array($result);
  485. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  486. $result = Database::query($sql);
  487. $row = Database::fetch_array($result);
  488. if ($row['title'] != '') {
  489. $myrow['title'] = $row['title'];
  490. }
  491. $desc = $row['description'];
  492. echo str_repeat("&nbsp;&gt;", $level);
  493. if (($builder != 'builder') && ($icon != 'wrap')) {
  494. echo "<td>";
  495. }
  496. if ($icon != 'nolink') {
  497. if ($completed == 'completed') {
  498. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  499. } else {
  500. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  501. //echo "&nbsp;";
  502. }
  503. }
  504. if (($builder != 'builder') && ($icon != 'wrap')) {
  505. echo "</td><td>";
  506. }
  507. if ($myrow['title'] == '') {
  508. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  509. 'StepDeleted2'
  510. )."</span>";
  511. return (true);
  512. }
  513. if ($icon == 'nolink') {
  514. return (shorten($myrow['title'], $length));
  515. }
  516. if ($icon == 'icon') {
  517. if ($linktype == 'Link _self') {
  518. echo "<img src='../img/links.gif' align=\"absmiddle\" alt='links'>";
  519. } else {
  520. echo "<img src='../img/link_blank.gif' align=\"absmiddle\" alt='blank links'>";
  521. }
  522. }
  523. $thelink = $myrow['url'];
  524. if ($builder != 'builder') {
  525. echo "<a href=\"".api_get_self(
  526. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path\" class='$completed'>".shorten(
  527. $myrow['title'],
  528. ($length - 3 * $level)
  529. )."</a>";
  530. $items[] = api_get_self(
  531. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
  532. if ($desc != '') {
  533. if ($icon != 'wrap') {
  534. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  535. $desc,
  536. ($length - 3 * $level)
  537. )."</div></td></tr>";
  538. } else {
  539. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  540. $desc,
  541. ($length - 3 * $level)
  542. )."</div>";
  543. }
  544. }
  545. } else {
  546. echo "<a href=\"$thelink\" class='$completed' target='_blank'>".shorten(
  547. $myrow['title'],
  548. ($length - 3 * $level)
  549. )."</a>";
  550. }
  551. break;
  552. case TOOL_QUIZ :
  553. case 'Exercise':
  554. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  555. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  556. $myrow = Database::fetch_array($result);
  557. if ($builder == 'builder') {
  558. $origin = 'builder';
  559. }
  560. // This is needed for the exercise_submit.php can delete the session info about tests.
  561. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  562. $result = Database::query($sql);
  563. $row = Database::fetch_array($result);
  564. if ($row['title'] != '') {
  565. $myrow['title'] = $row['title'];
  566. }
  567. $desc = $row['description'];
  568. echo str_repeat("&nbsp;&gt;", $level);
  569. if (($builder != 'builder') && ($icon != 'wrap')) {
  570. echo "<td>";
  571. }
  572. if ($icon != 'nolink') {
  573. if ($completed == 'completed') {
  574. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  575. } else {
  576. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  577. //echo "&nbsp;";
  578. }
  579. }
  580. if (($builder != 'builder') && ($icon != 'wrap')) {
  581. echo "</td><td>";
  582. }
  583. if ($myrow['title'] == '') {
  584. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  585. 'StepDeleted2'
  586. )."</span>";
  587. return (true);
  588. }
  589. if ($icon == 'nolink') {
  590. return (shorten($myrow['title'], $length));
  591. }
  592. if ($icon == 'icon') {
  593. echo "<img src='../img/quiz.gif' align=\"absmiddle\" alt='quizz'>";
  594. }
  595. if ($builder != 'builder') {
  596. echo "<a href=\"".api_get_self(
  597. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path\" class='$completed'>".shorten(
  598. $myrow['title'],
  599. ($length - 3 * $level)
  600. )."</a>";
  601. $items[] = api_get_self(
  602. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  603. if ($desc != '') {
  604. if ($icon != 'wrap') {
  605. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  606. $desc,
  607. ($length - 3 * $level)
  608. )."</div></td></tr>";
  609. } else {
  610. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  611. $desc,
  612. ($length - 3 * $level)
  613. )."</div>";
  614. }
  615. }
  616. } else {
  617. echo "<a href=\"../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow['id']."\" class='$completed' target='_blank'>".shorten(
  618. $myrow['title'],
  619. ($length - 3 * $level)
  620. )."</a>";
  621. }
  622. break;
  623. case 'hotpotatoes':
  624. case 'HotPotatoes':
  625. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  626. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  627. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  628. $myrow = Database::fetch_array($result);
  629. $path = $myrow['path'];
  630. $name = GetQuizName($path, $documentPath);
  631. if ($builder == 'builder') {
  632. $origin = 'builder';
  633. }
  634. // This is needed for the exercise_submit.php can delete the session info about tests.
  635. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  636. $result = Database::query($sql);
  637. $row = Database::fetch_array($result);
  638. if ($row['title'] != '') {
  639. $name = $row['title'];
  640. }
  641. $desc = $row['description'];
  642. echo str_repeat("&nbsp;&gt;", $level);
  643. if (($builder != 'builder') && ($icon != 'wrap')) {
  644. echo "<td>";
  645. }
  646. if ($icon != 'nolink') {
  647. if ($completed == 'completed') {
  648. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  649. } else {
  650. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  651. //echo "&nbsp;";
  652. }
  653. }
  654. if (($builder != 'builder') && ($icon != 'wrap')) {
  655. echo "</td><td>";
  656. }
  657. if ($name == '') {
  658. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  659. 'StepDeleted2'
  660. )."</span>";
  661. return (true);
  662. }
  663. if ($icon == 'nolink') {
  664. return (shorten($name, $length));
  665. }
  666. if ($icon == 'icon') {
  667. echo "<img src='../img/jqz.jpg' align=\"absmiddle\" alt='hot potatoes'>";
  668. }
  669. $cid = $_course['official_code'];
  670. if ($builder != 'builder') {
  671. echo "<a href=\"".api_get_self(
  672. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path\" class='$completed'>".shorten(
  673. $name,
  674. ($length - 3 * $level)
  675. )."</a>";
  676. $items[] = api_get_self(
  677. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
  678. if ($desc != '') {
  679. if ($icon != 'wrap') {
  680. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  681. $desc,
  682. ($length - 3 * $level)
  683. )."</div></td></tr>";
  684. } else {
  685. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  686. $desc,
  687. ($length - 3 * $level)
  688. )."</div>";
  689. }
  690. }
  691. } else {
  692. echo "&nbsp;<a href=\"../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id']."\" class='$completed' target='_blank'>".shorten(
  693. $name,
  694. ($length - 3 * $level)
  695. )."</a>";
  696. }
  697. break;
  698. case TOOL_FORUM:
  699. case 'Forum':
  700. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  701. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  702. $myrow = Database::fetch_array($result);
  703. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  704. $result = Database::query($sql);
  705. $row = Database::fetch_array($result);
  706. if ($row['title'] != '') {
  707. $myrow["forum_name"] = $row['title'];
  708. }
  709. $desc = $row['description'];
  710. echo str_repeat("&nbsp;&gt;", $level);
  711. if (($builder != 'builder') && ($icon != 'wrap')) {
  712. echo "<td>";
  713. }
  714. if ($icon != 'nolink') {
  715. if ($completed == 'completed') {
  716. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  717. } else {
  718. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  719. //echo "&nbsp;";
  720. }
  721. }
  722. if (($builder != 'builder') && ($icon != 'wrap')) {
  723. echo "</td><td>";
  724. }
  725. if ($myrow["forum_name"] == '') {
  726. $type = "Forum";
  727. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  728. 'StepDeleted2'
  729. )."</span>";
  730. return (true);
  731. }
  732. if ($icon == 'nolink') {
  733. return (shorten($myrow['forum_name'], $length));
  734. }
  735. if ($icon == 'icon') {
  736. echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>";
  737. }
  738. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  739. if ($builder != 'builder') {
  740. echo "<a href=\"".api_get_self(
  741. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path\" class='$completed'>".shorten(
  742. $myrow["forum_name"],
  743. ($length - 3 * $level)
  744. )."</a>";
  745. $items[] = api_get_self(
  746. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
  747. if ($desc != '') {
  748. if ($icon != 'wrap') {
  749. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  750. $desc,
  751. ($length - 3 * $level)
  752. )."</div></td></tr>";
  753. } else {
  754. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  755. $desc,
  756. ($length - 3 * $level)
  757. )."</div>";
  758. }
  759. }
  760. } else {
  761. echo "<a href=\"../phpbb/viewforum.php?$forumparameters\" class='$completed' target='_blank'>".shorten(
  762. $myrow["forum_name"],
  763. ($length - 3 * $level)
  764. )."</a>";
  765. }
  766. break;
  767. case TOOL_THREAD:
  768. case 'Thread': //forum post
  769. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  770. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  771. $result = Database::query($sql);
  772. $myrow = Database::fetch_array($result);
  773. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  774. $result = Database::query($sql);
  775. $row = Database::fetch_array($result);
  776. if ($row['title'] != '') {
  777. $myrow['topic_title'] = $row['title'];
  778. }
  779. $desc = $row['description'];
  780. echo str_repeat("&nbsp;&gt;", $level);
  781. if (($builder != 'builder') && ($icon != 'wrap')) {
  782. echo "<td>";
  783. }
  784. if ($icon != 'nolink') {
  785. if ($completed == 'completed') {
  786. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  787. } else {
  788. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  789. //echo "&nbsp;";
  790. }
  791. }
  792. if (($builder != 'builder') && ($icon != 'wrap')) {
  793. echo "</td><td>";
  794. }
  795. if ($myrow["topic_title"] == '') {
  796. $type = "Forum Post";
  797. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  798. 'StepDeleted2'
  799. )."</span>";
  800. return (true);
  801. }
  802. if ($icon == 'nolink') {
  803. return (shorten($myrow['topic_title'], $length));
  804. }
  805. if ($icon == 'icon') {
  806. echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>";
  807. }
  808. if ($builder != 'builder') {
  809. echo "<a href=\"".api_get_self(
  810. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path\" class='$completed'>".shorten(
  811. $myrow["topic_title"],
  812. ($length - 3 * $level)
  813. )."</a>";
  814. $items[] = api_get_self(
  815. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
  816. if ($desc != '') {
  817. if ($icon != 'wrap') {
  818. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  819. $desc,
  820. ($length - 3 * $level)
  821. )."</div></td></tr>";
  822. } else {
  823. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  824. $desc,
  825. ($length - 3 * $level)
  826. )."</div>";
  827. }
  828. }
  829. } else {
  830. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten(
  831. $myrow["topic_title"],
  832. ($length - 3 * $level)
  833. )."</a>";
  834. }
  835. break;
  836. case TOOL_POST:
  837. case 'Post':
  838. //deprecated
  839. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  840. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  841. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  842. $myrow = Database::fetch_array($result);
  843. // Grabbing the title of the post.
  844. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  845. $result = Database::query($sql);
  846. $row = Database::fetch_array($result);
  847. if ($row['title'] != '') {
  848. $myrow['post_title'] = $row['title'];
  849. }
  850. $desc = $row['description'];
  851. echo str_repeat("&nbsp;&gt;", $level);
  852. $posternom = $myrow['nom'];
  853. $posterprenom = $myrow['prenom'];
  854. $posttime = $myrow['post_time'];
  855. $posttext = $myrow['post_text'];
  856. $posttitle = $myrow['post_title'];
  857. $posttext = str_replace('"', "'", $posttext);
  858. if (($builder != 'builder') && ($icon != 'wrap')) {
  859. echo "<td>";
  860. }
  861. if ($icon != 'nolink') {
  862. if ($completed == 'completed') {
  863. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  864. } else {
  865. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  866. //echo "&nbsp;";
  867. }
  868. }
  869. if (($builder != 'builder') && ($icon != 'wrap')) {
  870. echo "</td><td>";
  871. }
  872. if ($myrow["post_title"] == '') {
  873. $type = 'Forum';
  874. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  875. 'StepDeleted2'
  876. )."</span>";
  877. return (true);
  878. }
  879. if ($icon == 'nolink') {
  880. return (shorten($myrow["post_title"], $length));
  881. }
  882. if ($icon == 'icon') {
  883. echo "<img src='../img/forum.gif' align=\"absmiddle\" alt='forum'>";
  884. }
  885. if ($builder != 'builder') {
  886. echo "<a href=\"".api_get_self()."?action=closelesson&source_forum=".intval(
  887. $_GET['source_forum']
  888. )."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path\" class='$completed'>".shorten(
  889. $myrow["post_title"],
  890. ($length - 3 * $level)
  891. )."</a>";
  892. $items[] = api_get_self()."?action=closelesson&source_forum=".intval(
  893. $_GET['source_forum']
  894. )."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
  895. if ($desc != '') {
  896. if ($icon != 'wrap') {
  897. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  898. $desc,
  899. ($length - 3 * $level)
  900. )."</div></td></tr>";
  901. } else {
  902. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  903. $desc,
  904. ($length - 3 * $level)
  905. )."</div>";
  906. }
  907. }
  908. } else {
  909. echo "<a href=\"../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."\" class='$completed' target='_blank'>".shorten(
  910. $myrow["post_title"],
  911. ($length - 3 * $level)
  912. )."</a>";
  913. }
  914. break;
  915. case TOOL_DOCUMENT:
  916. case 'Document':
  917. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  918. $my_sql = "SELECT * FROM $dbTable WHERE c_id = $course_id AND id=$id";
  919. //error_log('New LP - Querying document table: '.$my_sql,0);
  920. $result = Database::query($my_sql);
  921. $myrow = Database::fetch_array($result);
  922. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  923. $last = count($pathname) - 1; // Making a correct name for the link.
  924. $filename = $pathname[$last]; // Making a correct name for the link.
  925. if (($builder != 'builder') && ($icon != 'wrap')) {
  926. echo "<td>";
  927. }
  928. echo str_repeat("&nbsp;&gt;", $level);
  929. if ($icon != 'nolink') {
  930. if ($completed == 'completed') {
  931. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  932. } else {
  933. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  934. //echo "&nbsp;";
  935. }
  936. }
  937. if (($builder != 'builder') && ($icon != 'wrap')) {
  938. echo "</td><td>";
  939. }
  940. $image = FileManager::choose_image($filename);
  941. $sql = "select * from $tbl_lp_item where id=$id_in_path";
  942. //error_log('New LP - Querying lp_item table: '.$sql, 0);
  943. $result = Database::query($sql);
  944. $row = Database::fetch_array($result);
  945. if ($row['title'] != '') {
  946. $filename = $row['title'];
  947. }
  948. $desc = $row['description'];
  949. if (($myrow['path'] == '') && ($filename == '')) {
  950. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  951. 'StepDeleted2'
  952. )."</span>";
  953. return (true);
  954. }
  955. if ($icon == 'nolink') {
  956. return (shorten($filename, $length));
  957. }
  958. if ($icon == 'icon') {
  959. echo "<img src='../img/$image' align=\"absmiddle\" alt='$image'>";
  960. }
  961. if ($builder != 'builder') {
  962. echo "<a href=\"".api_get_self(
  963. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path\" class='$completed'>".shorten(
  964. $filename,
  965. ($length - 3 * $level)
  966. )."</a>";
  967. if ($desc != '') {
  968. if ($icon != 'wrap') {
  969. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  970. $desc,
  971. ($length - 3 * $level)
  972. )."</div></td></tr>";
  973. } else {
  974. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  975. $desc,
  976. ($length - 3 * $level)
  977. )."</div>";
  978. }
  979. }
  980. $items[] = api_get_self(
  981. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";
  982. } else {
  983. $enableDocumentParsing = yes;
  984. if (!$enableDocumentParsing) {
  985. // This is the solution for the non-parsing version in the builder.
  986. $file = urlencode($myrow['path']);
  987. echo "<a href='../document/showinframes.php?file=$file' class='$completed' $hyperlink_target_parameter>".shorten(
  988. $filename,
  989. ($length - 3 * $level)
  990. )."</a>";
  991. } else {
  992. echo "<a href=\"../document/download.php?doc_url=".$myrow['path']."\" class='$completed' $hyperlink_target_parameter>".shorten(
  993. $filename,
  994. ($length - 3 * $level)
  995. )."</a>";
  996. }
  997. }
  998. break;
  999. case 'assignments':
  1000. case 'Assignments':
  1001. $name = get_lang('Assignments');
  1002. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1003. $result = Database::query($sql);
  1004. $row = Database::fetch_array($result);
  1005. if ($row['title'] != '') {
  1006. $name = $row['title'];
  1007. }
  1008. $desc = $row['description'];
  1009. echo str_repeat("&nbsp;&gt;", $level);
  1010. if (($builder != 'builder') && ($icon != 'wrap')) {
  1011. echo "<td>";
  1012. }
  1013. if ($icon != 'nolink') {
  1014. if ($completed == 'completed') {
  1015. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1016. } else {
  1017. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1018. //echo "&nbsp;";
  1019. }
  1020. }
  1021. if (($builder != 'builder') && ($icon != 'wrap')) {
  1022. echo "</td><td>";
  1023. }
  1024. if ($name == '') {
  1025. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1026. 'StepDeleted2'
  1027. )."</span>";
  1028. return (true);
  1029. }
  1030. if ($icon == 'nolink') {
  1031. return (shorten($name, $length));
  1032. }
  1033. if ($icon == 'icon') {
  1034. echo "<img src='../img/works.gif' align=\"absmiddle\">";
  1035. }
  1036. if ($builder != 'builder') {
  1037. echo "<a href=\"".api_get_self(
  1038. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1039. $name,
  1040. ($length - 3 * $level)
  1041. )."</a>";
  1042. $items[] = api_get_self(
  1043. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
  1044. if ($desc != '') {
  1045. if ($icon != 'wrap') {
  1046. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1047. $desc,
  1048. ($length - 3 * $level)
  1049. )."</div></td></tr>";
  1050. } else {
  1051. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1052. $desc,
  1053. ($length - 3 * $level)
  1054. )."</div>";
  1055. }
  1056. }
  1057. } else {
  1058. echo "<a href=\"../work/work.php\" class='$completed' target='_blank'>".shorten(
  1059. $name,
  1060. ($length - 3 * $level)
  1061. )."</a>";
  1062. }
  1063. break;
  1064. case TOOL_DROPBOX:
  1065. case 'Dropbox':
  1066. $name = get_lang('Dropbox');
  1067. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1068. $result = Database::query($sql);
  1069. $row = Database::fetch_array($result);
  1070. if ($row['title'] != '') {
  1071. $name = $row['title'];
  1072. }
  1073. $desc = $row['description'];
  1074. echo str_repeat("&nbsp;&gt;", $level);
  1075. if (($builder != 'builder') && ($icon != 'wrap')) {
  1076. echo "<td>";
  1077. }
  1078. if ($icon != 'nolink') {
  1079. if ($completed == 'completed') {
  1080. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1081. } else {
  1082. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1083. //echo "&nbsp;";
  1084. }
  1085. }
  1086. if (($builder != 'builder') && ($icon != 'wrap')) {
  1087. echo "</td><td>";
  1088. }
  1089. if ($name == '') {
  1090. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1091. 'StepDeleted2'
  1092. )."</span>";
  1093. return (true);
  1094. }
  1095. if ($icon == 'nolink') {
  1096. return (shorten($name, $length));
  1097. }
  1098. if ($icon == 'icon') {
  1099. echo "<img src='../img/dropbox.gif' align=\"absmiddle\">";
  1100. }
  1101. if ($builder != 'builder') {
  1102. echo "<a href=\"".api_get_self(
  1103. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1104. $name,
  1105. ($length - 3 * $level)
  1106. )."</a>";
  1107. $items[] = api_get_self(
  1108. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
  1109. if ($desc != '') {
  1110. if ($icon != 'wrap') {
  1111. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1112. $desc,
  1113. ($length - 3 * $level)
  1114. )."</div></td></tr>";
  1115. } else {
  1116. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1117. $desc,
  1118. ($length - 3 * $level)
  1119. )."</div>";
  1120. }
  1121. }
  1122. } else {
  1123. echo "<a href=\"../dropbox/index.php\" class='$completed' target='_blank'>".shorten(
  1124. $name,
  1125. ($length - 3 * $level)
  1126. )."</a>";
  1127. }
  1128. break;
  1129. case 'introduction_text':
  1130. case 'Introduction_text':
  1131. $name = get_lang('IntroductionText');
  1132. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1133. $result = Database::query($sql);
  1134. $row = Database::fetch_array($result);
  1135. if ($row['title'] != '') {
  1136. $name = $row['title'];
  1137. }
  1138. $desc = $row['description'];
  1139. echo str_repeat("&nbsp;&gt;", $level);
  1140. if (($builder != 'builder') && ($icon != 'wrap')) {
  1141. echo "<td>";
  1142. }
  1143. if ($icon != 'nolink') {
  1144. if ($completed == 'completed') {
  1145. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1146. } else {
  1147. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1148. //echo "&nbsp;";
  1149. }
  1150. }
  1151. if (($builder != 'builder') && ($icon != 'wrap')) {
  1152. echo "</td><td>";
  1153. }
  1154. if ($name == '') {
  1155. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1156. 'StepDeleted2'
  1157. )."</span>";
  1158. return (true);
  1159. }
  1160. if ($icon == 'nolink') {
  1161. return (shorten($name, $length));
  1162. }
  1163. if ($icon == 'icon') {
  1164. echo "<img src='../img/introduction.gif' align=\"absmiddle\" alt='introduction'>";
  1165. }
  1166. if ($builder != 'builder') {
  1167. echo "<a href=\"".api_get_self(
  1168. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1169. $name,
  1170. ($length - 3 * $level)
  1171. )."</a>";
  1172. $items[] = api_get_self(
  1173. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
  1174. if ($desc != '') {
  1175. if ($icon != 'wrap') {
  1176. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1177. $desc,
  1178. ($length - 3 * $level)
  1179. )."</div></td></tr>";
  1180. } else {
  1181. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1182. $desc,
  1183. ($length - 3 * $level)
  1184. )."</div>";
  1185. }
  1186. }
  1187. } else {
  1188. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1189. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length - 3 * $level))."</a>";
  1190. }
  1191. break;
  1192. case TOOL_COURSE_DESCRIPTION:
  1193. case 'Course_description':
  1194. $name = get_lang('CourseDescription');
  1195. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1196. $result = Database::query($sql);
  1197. $row = Database::fetch_array($result);
  1198. if ($row['title'] != '') {
  1199. $name = $row['title'];
  1200. }
  1201. $desc = $row['description'];
  1202. echo str_repeat("&nbsp;&gt;", $level);
  1203. if (($builder != 'builder') && ($icon != 'wrap')) {
  1204. echo "<td>";
  1205. }
  1206. if ($icon != 'nolink') {
  1207. if ($completed == 'completed') {
  1208. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1209. } else {
  1210. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1211. //echo "&nbsp;";
  1212. }
  1213. }
  1214. if (($builder != 'builder') && ($icon != 'wrap')) {
  1215. echo "</td><td>";
  1216. }
  1217. if ($name == '') {
  1218. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1219. 'StepDeleted2'
  1220. )."</span>";
  1221. return (true);
  1222. }
  1223. if ($icon == 'nolink') {
  1224. return (shorten($name, $length));
  1225. }
  1226. if ($icon == 'icon') {
  1227. echo "<img src='../img/info.gif' align=\"absmiddle\" alt='info'>";
  1228. }
  1229. if ($builder != 'builder') {
  1230. echo "<a href=\"".api_get_self(
  1231. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1232. $name,
  1233. ($length - 3 * $level)
  1234. )."</a>";
  1235. $items[] = api_get_self(
  1236. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
  1237. if ($desc != '') {
  1238. if ($icon != 'wrap') {
  1239. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1240. $desc,
  1241. ($length - 3 * $level)
  1242. )."</div></td></tr>";
  1243. } else {
  1244. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1245. $desc,
  1246. ($length - 3 * $level)
  1247. )."</div>";
  1248. }
  1249. }
  1250. } else {
  1251. $s = api_get_path(WEB_CODE_PATH)."course_description";
  1252. echo "<a href=\"$s\" class='$completed' target='_blank'>".shorten($name, ($length - 3 * $level))."</a>";
  1253. }
  1254. break;
  1255. case TOOL_GROUP:
  1256. case 'Groups':
  1257. $name = get_lang('Groups');
  1258. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1259. $result = Database::query($sql);
  1260. $row = Database::fetch_array($result);
  1261. if ($row['title'] != '') {
  1262. $name = $row['title'];
  1263. }
  1264. $desc = $row['description'];
  1265. echo str_repeat("&nbsp;&gt;", $level);
  1266. if (($builder != 'builder') && ($icon != 'wrap')) {
  1267. echo "<td>";
  1268. }
  1269. if ($icon != 'nolink') {
  1270. if ($completed == 'completed') {
  1271. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1272. } else {
  1273. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1274. //echo "&nbsp;";
  1275. }
  1276. }
  1277. if (($builder != 'builder') && ($icon != 'wrap')) {
  1278. echo "</td><td>";
  1279. }
  1280. if ($name == '') {
  1281. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1282. 'StepDeleted2'
  1283. )."</span>";
  1284. return (true);
  1285. }
  1286. if ($icon == 'nolink') {
  1287. return (shorten($name, $length));
  1288. }
  1289. if ($icon == 'icon') {
  1290. echo "<img src='../img/group.gif' align=\"absmiddle\" alt='group'>";
  1291. }
  1292. if ($builder != 'builder') {
  1293. echo "<a href=\"".api_get_self(
  1294. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1295. $name,
  1296. ($length - 3 * $level)
  1297. )."</a>";
  1298. $items[] = api_get_self(
  1299. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
  1300. if ($desc != '') {
  1301. if ($icon != 'wrap') {
  1302. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1303. $desc,
  1304. ($length - 3 * $level)
  1305. )."</div></td></tr>";
  1306. } else {
  1307. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1308. $desc,
  1309. ($length - 3 * $level)
  1310. )."</div>";
  1311. }
  1312. }
  1313. } else {
  1314. echo "<a href=\"../group/group.php?origin=$origin\" class='$completed' target='_blank'>".shorten(
  1315. $name,
  1316. ($length - 3 * $level)
  1317. )."</a>";
  1318. }
  1319. break;
  1320. case TOOL_USER:
  1321. case 'Users':
  1322. $name = get_lang('Users');
  1323. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1324. $result = Database::query($sql);
  1325. $row = Database::fetch_array($result);
  1326. if ($row['title'] != '') {
  1327. $name = $row['title'];
  1328. }
  1329. $desc = $row['description'];
  1330. echo str_repeat("&nbsp;&gt;", $level);
  1331. if (($builder != 'builder') && ($icon != 'wrap')) {
  1332. echo "<td>";
  1333. }
  1334. if ($icon != 'nolink') {
  1335. if ($completed == 'completed') {
  1336. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on'>";
  1337. } else {
  1338. echo "<img src='../img/checkbox_on2.gif' border='0' width='13' height='11' alt='on' style='visibility: hidden'>";
  1339. //echo "&nbsp;";
  1340. }
  1341. }
  1342. if (($builder != 'builder') && ($icon != 'wrap')) {
  1343. echo "</td><td>";
  1344. }
  1345. if ($name == '') {
  1346. echo "<span class='messagesmall'>".get_lang('StepDeleted1')." $type ".get_lang(
  1347. 'StepDeleted2'
  1348. )."</span>";
  1349. return (true);
  1350. }
  1351. if ($icon == 'nolink') {
  1352. return (shorten($name, $length));
  1353. }
  1354. if ($icon == 'icon') {
  1355. echo "<img src='../img/members.gif' align=\"absmiddle\" alt='members'>";
  1356. }
  1357. if ($builder != 'builder') {
  1358. echo "<a href=\"".api_get_self(
  1359. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path\" class='$completed'>".shorten(
  1360. $name,
  1361. ($length - 3 * $level)
  1362. )."</a>";
  1363. $items[] = api_get_self(
  1364. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
  1365. if ($desc != '') {
  1366. if ($icon != 'wrap') {
  1367. echo "</tr><tr><td></td><td></td><td><div class='description'>&nbsp;&nbsp;".shorten(
  1368. $desc,
  1369. ($length - 3 * $level)
  1370. )."</div></td></tr>";
  1371. } else {
  1372. echo "<div class='description'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".shorten(
  1373. $desc,
  1374. ($length - 3 * $level)
  1375. )."</div>";
  1376. }
  1377. }
  1378. } else {
  1379. echo "<a href=\"../user/user.php?origin=$origin\" class='$completed' target='_blank'>".shorten(
  1380. $name,
  1381. ($length - 3 * $level)
  1382. )."</a>";
  1383. }
  1384. break;
  1385. }
  1386. //end huge switch-statement
  1387. }
  1388. /**
  1389. * This function is to create and return a link to the added resources (lessons).
  1390. * It returns the same thing as display_addedresource_link_in_learnpath() but doesn't display
  1391. * anything.
  1392. *
  1393. * Parameters:
  1394. * @param type - that is the correspondent type in the mirror tool (like this is a Link item)
  1395. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1396. * @param id_in_path - the unique index in the items table
  1397. */
  1398. function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
  1399. {
  1400. global $learnpath_id, $tbl_learnpath_item, $items;
  1401. global $curDirPath, $_configuration, $enableDocumentParsing, $_user, $_cid;
  1402. $_course = api_get_course_info();
  1403. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1404. $course_id = api_get_course_int_id();
  1405. $hyperlink_target_parameter = ''; // or e.g. target='_blank'
  1406. $builder = 'player';
  1407. $origin = 'learnpath';
  1408. $linktype = $type;
  1409. if (($type == 'Link _self') || ($type == 'Link _blank')) {
  1410. $type = 'Link';
  1411. }
  1412. $link = '';
  1413. switch ($type) {
  1414. case 'Agenda':
  1415. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1416. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1417. $myrow = Database::fetch_array($result);
  1418. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1419. $result = Database::query($sql);
  1420. $row = Database::fetch_array($result);
  1421. if ($row['title'] != '') {
  1422. $myrow['title'] = $row['title'];
  1423. }
  1424. $desc = $row['description'];
  1425. $agenda_id = $row['item_id'];
  1426. if ($builder != 'builder') {
  1427. $link .= api_get_self(
  1428. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Agenda&origin=$origin&agenda_id=$agenda_id#$id_in_path";
  1429. } else {
  1430. $link .= "../calendar/agenda.php?origin=$origin&agenda_id=$agenda_id";
  1431. }
  1432. break;
  1433. case 'Ad_Valvas':
  1434. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1435. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1436. $myrow = Database::fetch_array($result);
  1437. if ($builder != 'builder') {
  1438. $link .= api_get_self(
  1439. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Ad_Valvas&origin=$origin&ann_id=$id#$id_in_path";
  1440. } else {
  1441. $link .= "../announcements/announcements.php?origin=$origin&ann_id=$id";
  1442. }
  1443. break;
  1444. case 'Link':
  1445. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1446. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1447. $myrow = Database::fetch_array($result);
  1448. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1449. $result = Database::query($sql);
  1450. $row = Database::fetch_array($result);
  1451. $thelink = $myrow['url'];
  1452. if ($builder != 'builder') {
  1453. $link .= api_get_self(
  1454. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=$linktype&origin=$origin&thelink=$thelink#$id_in_path";
  1455. } else {
  1456. $link .= $thelink;
  1457. }
  1458. break;
  1459. case 'Exercise':
  1460. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1461. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  1462. $myrow = Database::fetch_array($result);
  1463. if ($builder == 'builder') {
  1464. $origin = 'builder';
  1465. }
  1466. // This is needed for the exercise_submit.php can delete the session info about tests.
  1467. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id = $id_in_path";
  1468. $result = Database::query($sql);
  1469. $row = Database::fetch_array($result);
  1470. if ($row['title'] != '') {
  1471. $myrow['title'] = $row['title'];
  1472. }
  1473. if ($builder != 'builder') {
  1474. $link .= api_get_self(
  1475. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Exercise&origin=$origin&exerciseId=".$myrow["id"]."#$id_in_path";
  1476. } else {
  1477. $link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
  1478. }
  1479. break;
  1480. case 'HotPotatoes':
  1481. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  1482. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  1483. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  1484. $myrow = Database::fetch_array($result);
  1485. $path = $myrow['path'];
  1486. $name = GetQuizName($path, $documentPath);
  1487. if ($builder == 'builder') {
  1488. $origin = 'builder';
  1489. }
  1490. $cid = $_course['official_code'];
  1491. if ($builder != 'builder') {
  1492. $link .= api_get_self(
  1493. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
  1494. } else {
  1495. $link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
  1496. }
  1497. break;
  1498. case 'Forum':
  1499. //deprecated
  1500. $TBL_FORUMS = Database::get_course_table(
  1501. TABLE_FORUM
  1502. ); // TODO: This is the old table name, it should be corrected.
  1503. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1504. $myrow = Database::fetch_array($result);
  1505. if ($builder == 'builder') {
  1506. $origin = 'builder';
  1507. }
  1508. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1509. $result = Database::query($sql);
  1510. $row = Database::fetch_array($result);
  1511. if ($row['title'] != '') {
  1512. $myrow['forum_name'] = $row['title'];
  1513. }
  1514. if ($myrow['forum_name'] == '') {
  1515. $type = 'Forum';
  1516. }
  1517. $forumparameters = "forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1518. if ($builder != 'builder') {
  1519. $link .= api_get_self(
  1520. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Forum&origin=$origin&forumparameters=$forumparameters#$id_in_path";
  1521. } else {
  1522. $link .= "../phpbb/viewforum.php?$forumparameters";
  1523. }
  1524. break;
  1525. case 'Thread': //forum post
  1526. //deprecated
  1527. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  1528. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1529. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1530. $sql = "SELECT * FROM $tbl_topics where c_id = $course_id AND topic_id=$id";
  1531. $result = Database::query($sql);
  1532. $myrow = Database::fetch_array($result);
  1533. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1534. $result = Database::query($sql);
  1535. $row = Database::fetch_array($result);
  1536. if ($builder != 'builder') {
  1537. $link .= api_get_self(
  1538. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Thread&origin=$origin&topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"]."#$id_in_path";
  1539. } else {
  1540. $link .= "../forum/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1541. }
  1542. break;
  1543. case 'Post':
  1544. //deprecated
  1545. $tbl_posts = Database::get_course_table(TABLE_FORUM_POST);
  1546. $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$id");
  1547. $myrow = Database::fetch_array($result);
  1548. // Grabbing the title of the post.
  1549. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1550. $result = Database::query($sql);
  1551. $row = Database::fetch_array($result);
  1552. if ($row['title'] != '') {
  1553. $myrow['post_title'] = $row['title'];
  1554. }
  1555. $desc = $row['description'];
  1556. //$link .= str_repeat("&nbsp;&gt;", $level);
  1557. $posternom = $myrow['nom'];
  1558. $posterprenom = $myrow['prenom'];
  1559. $posttime = $myrow['post_time'];
  1560. $posttext = $myrow['post_text'];
  1561. $posttitle = $myrow['post_title'];
  1562. $posttext = str_replace('"', "'", $posttext);
  1563. if ($builder != 'builder') {
  1564. $link .= api_get_self(
  1565. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Post&origin=$origin&posternom=$posternom&posterprenom=$posterprenom&posttime=$posttime&posttext=$posttext&posttitle=$posttitle#$id_in_path";
  1566. } else {
  1567. $link .= "../phpbb/viewtopic.php?topic=".$myrow["topic_id"]."&forum=".$myrow["forum_id"]."&md5=".$myrow["md5"];
  1568. }
  1569. break;
  1570. case 'Document':
  1571. $dbTable = Database::get_course_table(TABLE_DOCUMENT);
  1572. $result = Database::query("SELECT * FROM $dbTable WHERE id=$id");
  1573. $myrow = Database::fetch_array($result);
  1574. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1575. $last = count($pathname) - 1; // Making a correct name for the link.
  1576. $filename = $pathname[$last]; // Making a correct name for the link.
  1577. $sql = "select * from $tbl_lp_item where c_id = $course_id AND id=$id_in_path";
  1578. $result = Database::query($sql);
  1579. $row = Database::fetch_array($result);
  1580. if ($builder != 'builder') {
  1581. $link .= api_get_self(
  1582. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Document&origin=$origin&docurl=".$myrow["path"]."#$id_in_path";
  1583. } else {
  1584. $enableDocumentParsing = yes;
  1585. if (!$enableDocumentParsing) {
  1586. // This is the solution for the non-parsing version in the builder.
  1587. $file = urlencode($myrow['path']);
  1588. $link .= "../document/showinframes.php?file=$file";
  1589. } else {
  1590. $link .= "../document/download.php?doc_url=".$myrow['path'];
  1591. }
  1592. }
  1593. break;
  1594. case 'Assignments':
  1595. if ($builder != 'builder') {
  1596. $link .= api_get_self(
  1597. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Assignments&origin=$origin#$id_in_path";
  1598. } else {
  1599. $link .= "../work/work.php";
  1600. }
  1601. break;
  1602. case 'Dropbox':
  1603. if ($builder != 'builder') {
  1604. $link .= api_get_self(
  1605. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Dropbox&origin=$origin#$id_in_path";
  1606. } else {
  1607. $link .= "../dropbox/index.php";
  1608. }
  1609. break;
  1610. case 'Introduction_text':
  1611. if ($builder != 'builder') {
  1612. $link .= api_get_self(
  1613. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Introduction_text&origin=$origin#$id_in_path";
  1614. } else {
  1615. $s = api_get_path(WEB_COURSE_PATH)."$_cid/index.php?intro_cmdEdit=1";
  1616. $link .= $s;
  1617. }
  1618. break;
  1619. case 'Course_description':
  1620. if ($builder != 'builder') {
  1621. $link .= api_get_self(
  1622. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Course_description&origin=$origin#$id_in_path";
  1623. } else {
  1624. $s = api_get_path(WEB_CODE_PATH).'course_description';
  1625. $link .= $s;
  1626. }
  1627. break;
  1628. case 'Groups':
  1629. if ($builder != 'builder') {
  1630. $link .= api_get_self(
  1631. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Groups&origin=$origin#$id_in_path";
  1632. } else {
  1633. $link .= "../group/group.php?origin=$origin";
  1634. }
  1635. break;
  1636. case 'Users':
  1637. if ($builder != 'builder') {
  1638. $link .= api_get_self(
  1639. )."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=Users&origin=$origin#$id_in_path";
  1640. } else {
  1641. $link .= "../user/user.php?origin=$origin";
  1642. }
  1643. break;
  1644. }
  1645. //end huge switch-statement
  1646. return $link;
  1647. }
  1648. /**
  1649. * This function is to remove an resource item from the array
  1650. */
  1651. function remove_resource($resource_key)
  1652. {
  1653. $addedresource = $_SESSION['addedresource'];
  1654. $addedresourceid = $_SESSION['addedresourceid'];
  1655. unset($addedresource[$resource_key]);
  1656. unset($addedresourceid[$resource_key]);
  1657. $_SESSION['addedresource'] = $addedresource;
  1658. $_SESSION['addedresourceid'] = $addedresourceid;
  1659. }
  1660. /**
  1661. * This function is to show the button "click to add resource" on the tool page
  1662. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1663. */
  1664. function show_addresource_button($additionalparameters = '')
  1665. {
  1666. global $charset;
  1667. echo '<label for="addresources"><img src="../img/attachment.gif" /></label><input class="link_alike" type="submit" name="addresources" id="addresources" value="'.api_htmlentities(
  1668. get_lang('Attachment'),
  1669. ENT_QUOTES,
  1670. $charset
  1671. ).'" '.$additionalparameters.' />';
  1672. }
  1673. /**
  1674. * This function is to delete ONE specific resource that were added to a specific item
  1675. * Deprecated
  1676. */
  1677. /*
  1678. function delete_one_added_resource($source_type, $source_id, $resource_type, $resource_id) {
  1679. //echo "delete_one_added_resource";
  1680. $_course = api_get_course_info();
  1681. $TABLERESOURCE = $_course['dbNameGlu'].'resource';
  1682. $sql = "DELETE FROM $TABLERESOURCE WHERE source_type='$source_type' and source_id='$source_id' and resource_type='$resource_type' and resource_id='$resource_id'";
  1683. Database::query($sql);
  1684. }*/
  1685. /**
  1686. * This function is to delete the resources that were added to a specific item
  1687. */
  1688. function delete_added_resource($type, $id)
  1689. {
  1690. $_course = api_get_course_info();
  1691. $course_id = api_get_course_int_id();
  1692. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1693. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1694. Database::query($sql);
  1695. }
  1696. /**
  1697. * This function is te delete all resources of a specific type (only used in announcements -- delete all)
  1698. * Author : Frederik Vermeire <frederik.vermeire@pandora.be>
  1699. */
  1700. function delete_all_resources_type($type)
  1701. {
  1702. $_course = api_get_course_info();
  1703. $course_id = api_get_course_int_id();
  1704. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1705. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type'";
  1706. Database::query($sql);
  1707. }
  1708. /**
  1709. * This function checks wether there are added resources or not
  1710. */
  1711. function check_added_resources($type, $id)
  1712. {
  1713. $course_id = api_get_course_int_id();
  1714. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1715. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1716. $result = Database::query($sql);
  1717. $number_added = Database::num_rows($result);
  1718. if ($number_added != 0) {
  1719. return true;
  1720. } else {
  1721. return false;
  1722. }
  1723. }
  1724. /**
  1725. * this function is to load the resources that were added to a specific item
  1726. * into the session variables
  1727. */
  1728. function edit_added_resources($type, $id)
  1729. {
  1730. $_course = api_get_course_info();
  1731. $course_id = api_get_course_int_id();
  1732. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1733. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id=$id";
  1734. $result = Database::query($sql);
  1735. while ($row = Database::fetch_array($result)) {
  1736. $addedresource[] = $row["resource_type"];
  1737. $addedresourceid[] = $row["resource_id"];
  1738. }
  1739. $_SESSION['addedresource'] = $addedresource;
  1740. $_SESSION['addedresourceid'] = $addedresourceid;
  1741. }
  1742. /**
  1743. * this function is store the modified resources
  1744. * first we delete all the added resources in the database,
  1745. * then we add all the resources from the session object.
  1746. */
  1747. function update_added_resources($type, $id)
  1748. {
  1749. $_course = api_get_course_info();
  1750. $course_id = api_get_course_int_id();
  1751. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1752. // delete all the added resources for this item in the database;
  1753. $sql = "DELETE FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' AND source_id='$id'";
  1754. //echo $sql;
  1755. Database::query($sql);
  1756. // Store the resources from the session into the database.
  1757. store_resources($type, $id);
  1758. //delete_added_resource_($type, $id);
  1759. unset_session_resources();
  1760. }
  1761. /**
  1762. * this function is to display the resources that were added to a specific item
  1763. */
  1764. function display_added_resources($type, $id, $style = '')
  1765. {
  1766. $course_id = api_get_course_int_id();
  1767. // The array containing the icons
  1768. $arr_icons = array(
  1769. 'Agenda' => '../img/agenda.gif',
  1770. 'Ad Valvas' => '../img/valves.gif',
  1771. 'Link' => '../img/links.gif',
  1772. 'Exercise' => '../img/quiz.gif'
  1773. );
  1774. global $origin;
  1775. $TABLERESOURCE = Database::get_course_table(TABLE_LINKED_RESOURCES);
  1776. $sql = "SELECT * FROM $TABLERESOURCE WHERE c_id = $course_id AND source_type='$type' and source_id='$id'";
  1777. $result = Database::query($sql);
  1778. while ($row = Database::fetch_array($result)) {
  1779. if ($origin != 'learnpath') {
  1780. display_addedresource_link($row['resource_type'], $row['resource_id'], $style);
  1781. } else {
  1782. display_addedresource_link_in_learnpath(
  1783. $row['resource_type'],
  1784. $row['resource_id'],
  1785. 'agendaitems',
  1786. '',
  1787. 'builder',
  1788. 'icon'
  1789. );
  1790. echo "<br>";
  1791. }
  1792. }
  1793. }
  1794. /**
  1795. * This function is to show the added resources when adding an item
  1796. * $showdeleteimg determine if the delete image should appear or not.
  1797. * deleting an added resource is only possible through the resource linker file itself
  1798. */
  1799. function display_resources($showdeleteimg)
  1800. {
  1801. global $action;
  1802. global $resourceaction;
  1803. global $id;
  1804. global $locationkey;
  1805. global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
  1806. if ($resourceaction == 'removeresource') {
  1807. remove_resource($locationkey);
  1808. }
  1809. $addedresource = $_SESSION['addedresource'];
  1810. $addedresourceid = $_SESSION['addedresourceid'];
  1811. if (is_array($addedresource)) {
  1812. echo '<table>';
  1813. foreach ($addedresource as $resource) {
  1814. echo '<tr><td>';
  1815. display_addedresource_link($resource, $addedresourceid[key($addedresource)]);
  1816. echo '</td><td width="30">';
  1817. // if $_SERVER['REQUEST_URI'] contains and ?id=xx we have an edit and the url for deleting a session added resource
  1818. // should also contain this id.
  1819. $test = parse_url($_SERVER['REQUEST_URI']);
  1820. $output = array();
  1821. parse_str($test[query], $output);
  1822. if ($showdeleteimg == 1) {
  1823. echo "<a href=".api_get_self(
  1824. )."?showresources=true&amp;source_forum=".$_GET['source_forum']."&amp;resourceaction=removeresource&amp;locationkey=".key(
  1825. $addedresource
  1826. )."&amp;source_id=$source_id&amp;action=$action&amp;learnpath_id=$learnpath_id&amp;chapter_id=$chapter_id&amp;originalresource=no><img src='../img/delete.gif' border='0' alt='resource ".get_lang(
  1827. 'Delete'
  1828. )."' /></a><br />";
  1829. }
  1830. echo '</td></tr>';
  1831. next($addedresource);
  1832. }
  1833. echo '</table>';
  1834. } else { // it is a string
  1835. echo '';
  1836. }
  1837. } // end of the display_resources function
  1838. /**
  1839. * This function checks wether the link add resource should be displayed next the item in the linker page
  1840. * So we have to check if the specific id of that tool is already in the array of the added resources
  1841. * if it is already in, the link should not be showed since it would make it possible to add
  1842. * the same resource a second time (=duplication of added resources)
  1843. */
  1844. function showorhide_addresourcelink($type, $id)
  1845. {
  1846. global $from_learnpath, $source_id, $action, $learnpath_id, $chapter_id, $originalresource, $folder, $content, $target;
  1847. $addedresource = $_SESSION['addedresource'];
  1848. $addedresourceid = $_SESSION['addedresourceid'];
  1849. if (is_array($_SESSION['addedresource'])) {
  1850. foreach ($addedresource as $toolcompare) {
  1851. if ($toolcompare == $type && $addedresourceid[key($addedresource)] == $id) {
  1852. $show = 0;
  1853. }
  1854. next($addedresource);
  1855. }
  1856. if ($from_learnpath) {
  1857. $lang_add_it_or_resource = get_lang('AddIt');
  1858. } else {
  1859. $lang_add_it_or_resource = get_lang('AddResource');
  1860. }
  1861. if ($show !== 0) {
  1862. if ($type == 'Document') {
  1863. echo "<a href=".api_get_self(
  1864. )."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no>".$lang_add_it_or_resource."</a>";
  1865. } else {
  1866. echo "<a href='".api_get_self(
  1867. )."?content=".$type."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
  1868. }
  1869. }
  1870. } else { // if it is not an array, it is a string
  1871. if ($_SESSION['addedresource'] !== $type || $_SESSION['addedresourceid'] !== $id) {
  1872. if ($from_learnpath) {
  1873. $lang_add_it_or_resource = get_lang('AddIt');
  1874. } else {
  1875. $lang_add_it_or_resource = get_lang('AddResource');
  1876. }
  1877. echo "<a href='".api_get_self(
  1878. )."?content=".$type."&folder=".$folder."&source_forum=".$_GET['source_forum']."&add=".$id."&source_id=$source_id&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no&target=$target'>".$lang_add_it_or_resource."</a>";
  1879. }
  1880. }
  1881. }
  1882. /**
  1883. * Gets the link to the given added resource.
  1884. *
  1885. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1886. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  1887. * @param string Course code
  1888. * @param string The tool type (using constants declared in api.lib.php)
  1889. * @param integer The resource ID
  1890. * @param string Resource style (e.g. when a resource is hidden => the added resources should also be styled like they are hidden)
  1891. * @param boolean Open in a new window (true) or in the current frame/window (false)?
  1892. * @todo use the constants for the type definitions.
  1893. */
  1894. function rl_get_html_resource_link($course_code, $type, $id, $style = '', $new_window = true)
  1895. {
  1896. $course_id = api_get_course_int_id();
  1897. // Styling the link of the added resource
  1898. if ($style != '') {
  1899. $styling = ' class="'.$style.'"';
  1900. }
  1901. if ($new_window) {
  1902. $target = ' target = "_blank" ';
  1903. } else {
  1904. $target = ' target = "_self" ';
  1905. }
  1906. $output = '';
  1907. switch ($type) {
  1908. case TOOL_CALENDAR_EVENT:
  1909. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1910. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  1911. $myrow = Database::fetch_array($result);
  1912. $output = '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1913. break;
  1914. case TOOL_ANNOUNCEMENT:
  1915. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1916. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  1917. $myrow = Database::fetch_array($result);
  1918. $output = '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1919. break;
  1920. case TOOL_LINK:
  1921. //doesn't take $target into account
  1922. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  1923. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  1924. $myrow = Database::fetch_array($result);
  1925. $output = '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode(
  1926. $myrow['url']
  1927. )."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
  1928. break;
  1929. case TOOL_QUIZ:
  1930. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1931. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  1932. $myrow = Database::fetch_array($result);
  1933. $output = '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercise_submit.php?exerciseId='.$myrow['id'].'"'.$styling.' '.$target.'>'.$myrow['title']."</a><br />\n";
  1934. break;
  1935. case TOOL_FORUM:
  1936. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  1937. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  1938. $myrow = Database::fetch_array($result);
  1939. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&md5='.$myrow['md5'].'"'.$styling.' '.$target.'>'.$myrow['forum_name']."</a><br />\n";
  1940. break;
  1941. case TOOL_THREAD: //=topics
  1942. //$tbl_forum = Database::get_course_table(TABLE_FORUM);
  1943. //$tbl_thread = Database::get_course_table(TABLE_FORUM_THREAD);
  1944. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1945. // grabbing the title of the post
  1946. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  1947. $result_title = Database::query($sql_title);
  1948. $myrow_title = Database::fetch_array($result_title);
  1949. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow_title['thread_id'].'&forum='.$myrow_title['forum_id'].'" '.$styling.' '.$target.'>'.$myrow_title['post_title']."</a><br />\n";
  1950. break;
  1951. case TOOL_POST:
  1952. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  1953. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  1954. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  1955. $result = Database::query($sql);
  1956. $post = Database::fetch_array($result);
  1957. $output = '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post['thread_id'].'&forum='.$post['forum_id'].'"'.$styling.' '.$target.'>'.$post['post_title']."</a><br />\n";
  1958. break;
  1959. case TOOL_DOCUMENT:
  1960. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  1961. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  1962. $myrow = Database::fetch_array($result);
  1963. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  1964. $last = count($pathname) - 1; // Making a correct name for the link.
  1965. $filename = $pathname[$last]; // Making a correct name for the link.
  1966. $image = FileManager::choose_image($filename);
  1967. $ext = explode('.', $filename);
  1968. $ext = strtolower($ext[sizeof($ext) - 1]);
  1969. $myrow['path'] = rawurlencode($myrow['path']);
  1970. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  1971. $output = '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.' '.$target.'>'.$filename."</a><br />\n";
  1972. break;
  1973. /*
  1974. case 'Externallink':
  1975. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  1976. break;
  1977. */
  1978. }
  1979. return $output;
  1980. }
  1981. /**
  1982. * Returns an HTML-formatted link to a resource, to incorporate directly into
  1983. * the new learning path tool.
  1984. *
  1985. * The function is a big switch on tool type.
  1986. * In each case, we query the corresponding table for information and build the link
  1987. * with that information.
  1988. * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
  1989. * @param string Course code
  1990. * @param integer The learning path ID (in lp table)
  1991. * @param integer The database ID for that item in the lp_item table
  1992. * @param id - that is the correspondent id in the mirror tool (like Agenda item 2)
  1993. * @param id_in_path - the unique index in the items table
  1994. */
  1995. function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path)
  1996. {
  1997. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1998. $course_info = api_get_course_info_by_id($course_id);
  1999. $course_id = $course_info['real_id'];
  2000. $course_code = $course_info['code'];
  2001. $session_id = api_get_session_id();
  2002. $learnpath_id = intval($learnpath_id);
  2003. $id_in_path = intval($id_in_path);
  2004. $sql_item = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  2005. $res_item = Database::query($sql_item);
  2006. if (Database::num_rows($res_item) < 1) {
  2007. return -1;
  2008. } //exit
  2009. $row_item = Database::fetch_array($res_item);
  2010. $type = strtolower($row_item['item_type']);
  2011. $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
  2012. $origin = 'learnpath';
  2013. $main_dir_path = api_get_path(WEB_CODE_PATH);
  2014. $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
  2015. $link = '';
  2016. switch ($type) {
  2017. case 'dokeos_chapter':
  2018. $link .= $main_dir_path.'newscorm/blank.php';
  2019. case TOOL_CALENDAR_EVENT:
  2020. $link .= $main_dir_path.'calendar/agenda.php?origin='.$origin.'&agenda_id='.$id;
  2021. break;
  2022. case TOOL_ANNOUNCEMENT:
  2023. $link .= $main_dir_path.'announcements/announcements.php?origin='.$origin.'&ann_id='.$id;
  2024. break;
  2025. case TOOL_LINK:
  2026. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  2027. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  2028. $myrow = Database::fetch_array($result);
  2029. $thelink = $myrow["url"];
  2030. $link .= $thelink;
  2031. break;
  2032. case TOOL_QUIZ:
  2033. if (!empty($id)) {
  2034. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  2035. $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id";
  2036. $result = Database::query($sql);
  2037. $myrow = Database::fetch_array($result);
  2038. if ($row_item['title'] != '') {
  2039. $myrow['title'] = $row_item['title'];
  2040. }
  2041. $link .= $main_dir_path.'exercice/overview.php?cidReq='.$course_code.'&session_id='.$session_id.'&lp_init=1&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&exerciseId='.$id;
  2042. }
  2043. break;
  2044. case 'hotpotatoes': //lowercase because of strtolower above
  2045. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  2046. $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
  2047. $myrow = Database::fetch_array($result);
  2048. $path = $myrow['path'];
  2049. $link .= $main_dir_path.'exercice/showinframes.php?file='.$path.''.
  2050. '&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().''.
  2051. '&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path;
  2052. break;
  2053. case TOOL_FORUM:
  2054. $link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';
  2055. break;
  2056. case TOOL_THREAD: //forum post
  2057. $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
  2058. if (!empty($id)) {
  2059. $sql = "SELECT * FROM $tbl_topics WHERE c_id = $course_id AND thread_id=$id";
  2060. $result = Database::query($sql);
  2061. $myrow = Database::fetch_array($result);
  2062. $link .= $main_dir_path.'forum/viewthread.php?origin=learnpath&thread='.$id.''.
  2063. '&forum='.$myrow['forum_id'].'&lp=true';
  2064. }
  2065. break;
  2066. case TOOL_POST:
  2067. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2068. $result = Database::query("SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=$id");
  2069. $myrow = Database::fetch_array($result);
  2070. $title = $myrow['post_title'];
  2071. //$desc = $row_item['description'];
  2072. $posternom = $myrow['poster_name'];
  2073. $posttime = $myrow['post_date'];
  2074. $posttext = $myrow['post_text'];
  2075. $posttitle = $title;
  2076. $posttext = str_replace('"', "'", $posttext);
  2077. $link .= $main_dir_path.'forum/viewthread.php?post='.$id.''.
  2078. '&thread='.$myrow['thread_id'].'&forum='.$myrow['forum_id'].''.
  2079. '&lp=true';
  2080. break;
  2081. case TOOL_DOCUMENT:
  2082. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  2083. $sql = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id";
  2084. $result = Database::query($sql);
  2085. $myrow = Database::fetch_array($result);
  2086. $docurl = str_replace('%2F', '/', urlencode($myrow['path']));
  2087. $link .= $main_course_path.'document'.$docurl.'?'.api_get_cidreq();
  2088. $openmethod = 2;
  2089. $officedoc = false;
  2090. Session::write('openmethod', $openmethod);
  2091. Session::write('officedoc', $officedoc);
  2092. break;
  2093. case 'assignments':
  2094. $link .= $main_dir_path.'work/work.php?origin='.$origin;
  2095. break;
  2096. case TOOL_DROPBOX:
  2097. $link .= $main_dir_path.'dropbox/index.php?origin=learnpath';
  2098. break;
  2099. case 'introduction_text': //DEPRECATED
  2100. $link .= '';
  2101. break;
  2102. case TOOL_COURSE_DESCRIPTION:
  2103. $link .= $main_dir_path.'course_description?origin=learnpath';
  2104. break;
  2105. case TOOL_GROUP:
  2106. $link .= $main_dir_path.'group/group.php?origin='.$origin;
  2107. break;
  2108. case TOOL_USER:
  2109. $link .= $main_dir_path.'user/user.php?origin='.$origin;
  2110. break;
  2111. case 'student_publication' :
  2112. $link .= $main_dir_path.'work/work.php?origin=learnpath';
  2113. break;
  2114. } //end switch
  2115. return $link;
  2116. }
  2117. /**
  2118. * Gets the name of a resource (generally used in learnpath when no name is provided)
  2119. *
  2120. * @author Yannick Warnier <ywarnier@beeznest.org>, Dokeos - rebranding
  2121. * @param string Course code
  2122. * @param string The tool type (using constants declared in api.lib.php)
  2123. * @param integer The resource ID
  2124. */
  2125. function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
  2126. {
  2127. $_course = api_get_course_info($course_code);
  2128. $course_id = $_course['real_id'];
  2129. $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  2130. $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
  2131. $res_item = Database::query($sql_item);
  2132. if (Database::num_rows($res_item) < 1) {
  2133. return ''; //exit
  2134. }
  2135. $row_item = Database::fetch_array($res_item);
  2136. $type = strtolower($row_item['item_type']);
  2137. $id = $row_item['ref'];
  2138. $output = '';
  2139. switch ($type) {
  2140. case TOOL_CALENDAR_EVENT:
  2141. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  2142. $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
  2143. $myrow = Database::fetch_array($result);
  2144. $output = $myrow['title'];
  2145. break;
  2146. case TOOL_ANNOUNCEMENT:
  2147. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  2148. $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
  2149. $myrow = Database::fetch_array($result);
  2150. $output = $myrow['title'];
  2151. break;
  2152. case TOOL_LINK:
  2153. // Doesn't take $target into account.
  2154. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  2155. $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
  2156. $myrow = Database::fetch_array($result);
  2157. $output = $myrow['title'];
  2158. break;
  2159. case TOOL_QUIZ:
  2160. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  2161. $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $id");
  2162. $myrow = Database::fetch_array($result);
  2163. $output = $myrow['title'];
  2164. break;
  2165. case TOOL_FORUM:
  2166. $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
  2167. $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
  2168. $myrow = Database::fetch_array($result);
  2169. $output = $myrow['forum_name'];
  2170. break;
  2171. case TOOL_THREAD: //=topics
  2172. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2173. // Grabbing the title of the post.
  2174. $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
  2175. $result_title = Database::query($sql_title);
  2176. $myrow_title = Database::fetch_array($result_title);
  2177. $output = $myrow_title['post_title'];
  2178. break;
  2179. case TOOL_POST:
  2180. $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
  2181. //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
  2182. $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
  2183. $result = Database::query($sql);
  2184. $post = Database::fetch_array($result);
  2185. $output = $post['post_title'];
  2186. break;
  2187. case 'dokeos_chapter':
  2188. $title = $row_item['title'];
  2189. if (!empty($title)) {
  2190. $output = $title;
  2191. } else {
  2192. $output = '-';
  2193. }
  2194. break;
  2195. case TOOL_DOCUMENT:
  2196. $title = $row_item['title'];
  2197. if (!empty($title)) {
  2198. $output = $title;
  2199. } else {
  2200. $output = '-';
  2201. }
  2202. break;
  2203. case 'hotpotatoes':
  2204. $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
  2205. $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
  2206. $myrow = Database::fetch_array($result);
  2207. $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
  2208. $last = count($pathname) - 1; // Making a correct name for the link.
  2209. $filename = $pathname[$last]; // Making a correct name for the link.
  2210. $image = FileManager::choose_image($filename);
  2211. $ext = explode('.', $filename);
  2212. $ext = strtolower($ext[sizeof($ext) - 1]);
  2213. $myrow['path'] = rawurlencode($myrow['path']);
  2214. $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
  2215. $output = $filename;
  2216. break;
  2217. /*
  2218. case 'externallink':
  2219. $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
  2220. break;
  2221. */
  2222. }
  2223. return stripslashes($output);
  2224. }