scorm_api.php 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * API event handler functions for Scorm 1.1 and 1.2 and 1.3 (latter not fully supported)
  6. * This script is divided into three sections.
  7. * The first section (below) is the initialisation part.
  8. * The second section is the SCORM object part
  9. * The third section defines the event handlers for Chamilo's internal messaging
  10. * and frames refresh
  11. * @author Denes Nagy <darkden@freemail.hu> (original author - 2003-2004)
  12. * @author Yannick Warnier <ywarnier@beeznest.org> (extended and maintained - 2005-2014)
  13. * @version v 1.2
  14. * @access public
  15. * @package chamilo.learnpath.scorm
  16. */
  17. // If you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  18. // of Maritime Navigation when trying to execute this row
  19. // var result = api.LMSInitialize("");
  20. // get the error response : you are not authorized to call this function
  21. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  22. $use_anonymous = true;
  23. //require_once '../inc/global.inc.php';
  24. \Chamilo\CoreBundle\Framework\Container::$legacyTemplate = 'layout_empty.html.twig';
  25. $file = Session::read('file');
  26. /** @var learnpath $oLP */
  27. $oLP = learnpath::getCurrentLpFromSession();
  28. /** @var learnpathItem $oItem */
  29. $oItem = isset($oLP->items[$oLP->current]) ? $oLP->items[$oLP->current] : null;
  30. if (!is_object($oItem)) {
  31. error_log('New LP - scorm_api - Could not load oItem item', 0);
  32. exit;
  33. }
  34. $autocomplete_when_80pct = 0;
  35. $user = api_get_user_info();
  36. $userId = api_get_user_id();
  37. header('Content-type: text/javascript');
  38. ?>var scorm_logs=<?php echo ((empty($oLP->scorm_debug) or (!api_is_course_admin() && !api_is_platform_admin()) )?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
  39. var lms_logs = 0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  40. // API Object initialization (eases access later on)
  41. function APIobject() {
  42. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  43. this.Initialize=LMSInitialize; //for Scorm 1.3
  44. this.LMSGetValue=LMSGetValue;
  45. this.GetValue=LMSGetValue;
  46. this.LMSSetValue=LMSSetValue;
  47. this.SetValue=LMSSetValue;
  48. this.LMSCommit=LMSCommit;
  49. this.Commit=LMSCommit;
  50. this.LMSFinish=LMSFinish;
  51. this.Finish=LMSFinish;
  52. this.LMSGetLastError=LMSGetLastError;
  53. this.GetLastError=LMSGetLastError;
  54. this.LMSGetErrorString=LMSGetErrorString;
  55. this.GetErrorString=LMSGetErrorString;
  56. this.LMSGetDiagnostic=LMSGetDiagnostic;
  57. this.GetDiagnostic=LMSGetDiagnostic;
  58. this.Terminate=Terminate; //only in Scorm 1.3
  59. this.save_asset = lms_save_asset;
  60. this.void_save_asset = chamilo_void_save_asset;
  61. }
  62. // it is not sure that the scos use the above declarations. The following
  63. // multiple declarations are to make sure we have an API object for each type of
  64. // SCORM
  65. var API = new APIobject(); //for scorm 1.2
  66. var api = API;
  67. var API_1484_11 = new APIobject(); //for scorm 1.3
  68. var api_1484_11 = API_1484_11;
  69. // SCORM-specific Error codes
  70. var G_NoError = 0;
  71. var G_GeneralException = 101;
  72. var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
  73. var G_InvalidArgumentError = 201;
  74. var G_ElementCannotHaveChildren = 202;
  75. var G_ElementIsNotAnArray = 203;
  76. var G_NotInitialized = 301;
  77. var G_NotImplementedError = 401;
  78. var G_InvalidSetValue = 402;
  79. var G_ElementIsReadOnly = 403;
  80. var G_ElementIsWriteOnly = 404;
  81. var G_IncorrectDataType = 405;
  82. // SCORM-specific Error messages
  83. var G_NoErrorMessage = '';
  84. var G_GeneralExceptionMessage = 'General Exception';
  85. var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
  86. var G_InvalidArgumentErrorMessage = 'Invalid argument error';
  87. var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
  88. var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
  89. var G_NotInitializedMessage = 'Not initialized';
  90. var G_NotImplementedErrorMessage = 'Not implemented error';
  91. var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
  92. var G_ElementIsReadOnlyMessage = 'Element is read only';
  93. var G_ElementIsWriteOnlyMessage = 'Element is write only';
  94. var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
  95. var olms = new Object();
  96. //the last recorded error message was:
  97. olms.G_LastError = G_NoError ;
  98. olms.G_LastErrorMessage = 'No error';
  99. //this is not necessary and is only provided to make bad Articulate contents
  100. // shut up (and not trigger useless JS messages)
  101. olms.G_LastErrorString = 'No error';
  102. //these variables are provided for better control of the current status in the
  103. // SCORM exchange
  104. olms.commit = false;
  105. // informative array helping to select variables to save, later on
  106. olms.scorm_variables = new Array(
  107. 'cmi.core.score.raw',
  108. 'cmi.core.score.max',
  109. 'cmi.core.score.min',
  110. 'cmi.core.lesson_location',
  111. 'cmi.core.lesson_status',
  112. 'cmi.completion_status',
  113. 'cmi.core.session_time',
  114. 'cmi.score.scaled',
  115. 'cmi.success_status',
  116. 'cmi.suspend_data',
  117. 'cmi.core.exit',
  118. 'interactions'
  119. );
  120. // manage variables to save or not
  121. olms.variable_to_send=new Array();
  122. // temporary list of variables (gets set to true when set through LMSSetValue)
  123. olms.updatable_vars_list = new Array();
  124. // marker of whether the LMSFinish() function was called, which is important for SCORM behaviour
  125. olms.finishSignalReceived = 0;
  126. // marker to remember if the SCO has calles a "set" on lesson_status
  127. olms.statusSignalReceived = 0;
  128. // Strictly scorm variables
  129. olms.score=<?php echo $oItem->get_score();?>;
  130. olms.max='<?php echo $oItem->get_max();?>';
  131. olms.min='<?php echo $oItem->get_min();?>';
  132. olms.lesson_status='<?php echo $oItem->get_status();?>';
  133. olms.session_time='<?php echo $oItem->get_scorm_time('js');?>';
  134. olms.suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  135. olms.lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  136. olms.total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  137. olms.mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  138. olms.launch_data = '<?php echo $oItem->get_launch_data(); ?>';
  139. olms.max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  140. olms.interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
  141. olms.item_objectives = new Array();
  142. olms.info_lms_item = new Array();
  143. // Chamilo internal variables (not SCORM)
  144. // olms.saved_lesson_status = 'not attempted';
  145. olms.lms_lp_id = <?php echo $oLP->get_id();?>;
  146. olms.lms_item_id = <?php echo $oItem->get_id();?>;
  147. olms.lms_initialized = 0;
  148. // switch_finished indicates if the switch process is finished (if it has gone
  149. // through LMSInitialize() for the new item. Until then, all LMSSetValue()
  150. // commands received are executed on the *previous/current* item
  151. // This flag is updated in LMSInitialize() and in switch_item()
  152. olms.switch_finished = 0;
  153. //olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  154. //olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  155. //olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  156. //if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  157. olms.lms_view_id = '<?php echo $oLP->get_view();?>';
  158. if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
  159. olms.lms_user_id = '<?php echo $userId;?>';
  160. olms.lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  161. olms.lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  162. olms.lms_lp_type = '<?php echo $oLP->get_type();?>';
  163. olms.lms_item_type = '<?php echo $oItem->get_type();?>';
  164. olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
  165. olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  166. olms.lms_item_launch_data = '<?php echo addslashes($oItem->get_launch_data());?>';
  167. olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  168. olms.lms_course_id = '<?php echo $oLP->get_course_int_id(); ?>';
  169. olms.lms_session_id = '<?php echo api_get_session_id(); ?>';
  170. olms.lms_course_code = '<?php echo $oLP->getCourseCode(); ?>';
  171. olms.lms_course_id = '<?php echo $oLP->get_course_int_id(); ?>';
  172. <?php echo $oLP->get_items_details_as_js('olms.lms_item_types');?>
  173. // Following definition of cmi.core.score.raw in SCORM 1.2, "LMS should
  174. // initialize this to an empty string ("") upon initial launch of a SCO. The
  175. // SCO is responsible for setting this value. If an LMSGetValue() is requested
  176. // before the SCO has set this value, then the LMS should return an empty
  177. // string ("")
  178. // As Chamilo initializes this to 0 for non-sco, we need a little hack here.
  179. if (olms.score == 0 && olms.lms_item_type == 'sco' && olms.lesson_status == 'not attempted') {
  180. olms.score = "";
  181. }
  182. olms.asset_timer = 0;
  183. olms.userfname = '<?php echo str_replace("'", "\\'", $user['firstname']); ?>';
  184. olms.userlname = '<?php echo str_replace("'", "\\'", $user['lastname']); ?>';
  185. olms.execute_stats = false;
  186. /**
  187. * Add the "addListeners" function to the "onload" event of the window and
  188. * start the timer if necessary (asset)
  189. */
  190. addEvent(window, 'load', addListeners, false);
  191. // Initialize stuff when the page is loaded
  192. $(document).ready(function() {
  193. logit_lms('document.ready event starts');
  194. logit_lms('These logs are generated by the main/newscorm/scorm_api.php JS '
  195. + 'library when the admin has clicked on the debug icon in the '
  196. + 'learning paths list: '
  197. + 'lines prefixed with "LMS:" refer to actions taken on the LMS side, '
  198. + 'while lines prefixed with "SCORM:" refer to actions taken to match '
  199. + 'the SCORM standard at the JS level.', 3);
  200. logit_scorm('LMSSetValue calls are shown in red for better visibility.', 0);
  201. logit_scorm('Other SCORM calls are shown in orange.', 1);
  202. logit_lms('To add new messages to these logs, use logit_lms() or logit_scorm().');
  203. olms.info_lms_item[0] = '<?php echo $oItem->get_id();?>';
  204. olms.info_lms_item[1] = '<?php echo $oItem->get_id();?>';
  205. $("#content_id").load(function() {
  206. logit_lms('#content_id load event starts');
  207. olms.info_lms_item[0] = olms.info_lms_item[1];
  208. // Only trigger the LMSInitialize automatically if not SCO
  209. if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
  210. LMSInitialize();
  211. } else {
  212. logit_lms('Content type is SCO and is responsible to launch LMSInitialize() on its own - Skipping',2);
  213. }
  214. });
  215. });
  216. // This code was moved inside LMSInitialize()
  217. if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  218. xajax_start_timer();
  219. }
  220. /**
  221. * The following section represents a set of mandatory functions for SCORM
  222. */
  223. /**
  224. * Function called mandatorily by the SCORM content to start the SCORM comm
  225. * This is the initialize function of all APIobjects
  226. * @return string 'true' or 'false'. Returning a string is mandatory (SCORM).
  227. */
  228. function LMSInitialize() {
  229. /* load info for this new item by calling the js_api_refresh command in
  230. * the message frame. The message frame will update the JS variables by
  231. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  232. * and that kind of stuff, so when the content loads in the content frame
  233. * it will have all the correct variables set
  234. */
  235. logit_scorm('LMSInitialize()');
  236. olms.G_LastError = G_NoError ;
  237. olms.G_LastErrorMessage = 'No error';
  238. olms.lms_initialized = 0;
  239. olms.finishSignalReceived = 0;
  240. olms.statusSignalReceived = 0;
  241. olms.switch_finished = 0;
  242. // if there are more parameters than ""
  243. if (arguments.length > 1) {
  244. olms.G_LastError = G_InvalidArgumentError;
  245. olms.G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  246. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  247. return('false');
  248. } else {
  249. //reinit the list of modified variables
  250. reinit_updatable_vars_list();
  251. // Get LMS values for this item
  252. var params = {
  253. 'lid': olms.lms_lp_id,
  254. 'uid': olms.lms_user_id,
  255. 'vid': olms.lms_view_id,
  256. 'iid': olms.lms_item_id
  257. };
  258. $.ajax({
  259. type: "POST",
  260. url: "lp_ajax_initialize.php",
  261. data: params,
  262. dataType: 'script',
  263. async: false,
  264. success:function(data) {
  265. jQuery("video:not(.skip), audio:not(.skip)").mediaelementplayer();
  266. }
  267. });
  268. olms.lms_initialized = 1;
  269. olms.switch_finished = 1;
  270. // log a more complete object dump when initializing, so we know what data hasn't been cleaned
  271. var log = '\nitem : '+ olms.lms_item_id
  272. + '\nitem_type : '+ olms.lms_item_type
  273. + '\nscore : '+ olms.score
  274. + '\nmax : '+ olms.max
  275. + '\nmin : '+ olms.min
  276. + '\nlesson_status : '+ olms.lesson_status
  277. + '\nsession_time : '+ olms.session_time
  278. + '\nlesson_location : '+ olms.lesson_location
  279. + '\nsuspend_data : '+ olms.suspend_data
  280. + '\ntotal_time : '+ olms.total_time
  281. + '\nmastery_score : '+ olms.mastery_score
  282. + '\nmax_time_allowed: '+ olms.max_time_allowed
  283. + '\ncredit : '+ olms.lms_item_credit
  284. + '\nlms_lp_id : '+ olms.lms_lp_id
  285. + '\nlms_user_id : '+ olms.lms_user_id
  286. + '\nlms_view_id : '+ olms.lms_view_id
  287. + '\nfinishSignalReceived : '+ olms.finishSignalReceived
  288. + '\nstatusSignalReceived : '+ olms.statusSignalReceived
  289. ;
  290. logit_scorm('LMSInitialize() with params: '+log);
  291. if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  292. xajax_start_timer();
  293. }
  294. if (olms.lms_item_type == 'quiz') {
  295. update_toc(olms.lesson_status, olms.lms_item_id);
  296. }
  297. <?php
  298. $glossaryExtraTools = api_get_setting(
  299. 'glossary.show_glossary_in_extra_tools'
  300. );
  301. $fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
  302. $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
  303. if ($showGlossary) {
  304. if (api_get_setting(
  305. 'document.show_glossary_in_documents'
  306. ) == 'ismanual'
  307. ) {
  308. ?>
  309. if (olms.lms_item_type == 'sco') {
  310. attach_glossary_into_scorm('automatic');
  311. } else {
  312. attach_glossary_into_scorm('manual');
  313. }
  314. <?php } elseif (api_get_setting(
  315. 'document.show_glossary_in_documents'
  316. ) == 'isautomatic'
  317. ) { ?>
  318. attach_glossary_into_scorm('automatic');
  319. <?php } ?>
  320. <?php } ?>
  321. <?php if ($fixLinkSetting) { ?>
  322. attach_glossary_into_scorm('fix_links');
  323. <?php } ?>
  324. return('true');
  325. }
  326. }
  327. /**
  328. * Twin sister of LMSInitialize(). Only provided for backwards compatibility.
  329. * this is the initialize function of all APIobjects
  330. */
  331. function Initialize() {
  332. return LMSInitialize();
  333. }
  334. /**
  335. * Gets a value in the current SCORM context and returns it to the calling SCO
  336. * @param string The name of the value we want
  337. * @return string All return values must be string (see SCORM)
  338. */
  339. function LMSGetValue(param) {
  340. olms.G_LastError = G_NoError ;
  341. olms.G_LastErrorMessage = 'No error';
  342. var result='';
  343. // the LMSInitialize is missing
  344. if (olms.lms_initialized == 0) {
  345. if (param == 'cmi.core.score.raw') {
  346. return '';
  347. }
  348. olms.G_LastError = G_NotInitialized;
  349. olms.G_LastErrorMessage = G_NotInitializedMessage;
  350. logit_scorm('LMSGetValue('+param+') on item id '+olms.lms_item_id+':<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  351. return '';
  352. }
  353. //Chamilo does not support these SCO object properties
  354. if (param == 'cmi.student_preference.text' ||
  355. param == 'cmi.student_preference.language' ||
  356. param == 'cmi.student_preference.speed' ||
  357. param == 'cmi.student_preference.audio' ||
  358. param == 'cmi.student_preference._children' ||
  359. param == 'cmi.student_data.time_limit_action' ||
  360. param == 'cmi.comments' ||
  361. param == 'cmi.comments_from_lms' ||
  362. /* The following properties were part of SCORM 1.0 or never implemented at all
  363. but seem to react badly to Captivate content producer when not defined */
  364. param == 'cmi.student_demographics._children' ||
  365. param == 'cmi.student_demographics.city' ||
  366. param == 'cmi.student_demographics.class' ||
  367. param == 'cmi.student_demographics.company' ||
  368. param == 'cmi.student_demographics.country' ||
  369. param == 'cmi.student_demographics.experience' ||
  370. param == 'cmi.student_demographics.familiar_name' ||
  371. param == 'cmi.student_demographics.instructor_name' ||
  372. param == 'cmi.student_demographics.title' ||
  373. param == 'cmi.student_demographics.native_language' ||
  374. param == 'cmi.student_demographics.state' ||
  375. param == 'cmi.student_demographics.street_address' ||
  376. param == 'cmi.student_demographics.telephone' ||
  377. param == 'cmi.student_demographics.years_experience' ) {
  378. // the value is not supported
  379. olms.G_LastError = G_NotImplementedError ;
  380. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  381. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  382. result = '';
  383. return result;
  384. }
  385. if (param=='cmi.student_demographics.first_name') {
  386. result=olms.userfname;
  387. } else if(param=='cmi.student_demographics.last_name') {
  388. result=olms.userlname;
  389. // ---- cmi.core._children
  390. } else if(param=='cmi.core._children' || param=='cmi.core_children'){
  391. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  392. } else if(param == 'cmi.core.entry'){
  393. // ---- cmi.core.entry
  394. if(olms.lms_item_core_exit=='none') {
  395. result='ab-initio';
  396. } else if(olms.lms_item_core_exit=='suspend') {
  397. result='resume';
  398. } else {
  399. result='';
  400. }
  401. } else if(param == 'cmi.core.exit'){
  402. // ---- cmi.core.exit
  403. result='';
  404. olms.G_LastError = G_ElementIsWriteOnly;
  405. } else if(param == 'cmi.core.session_time'){
  406. result='';
  407. olms.G_LastError = G_ElementIsWriteOnly;
  408. } else if(param == 'cmi.core.lesson_status'){
  409. // ---- cmi.core.lesson_status
  410. if(olms.lesson_status != '') {
  411. result=olms.lesson_status;
  412. } else {
  413. //result='not attempted';
  414. }
  415. } else if(param == 'cmi.core.student_id'){
  416. // ---- cmi.core.student_id
  417. result='<?php echo $userId; ?>';
  418. } else if(param == 'cmi.core.student_name'){
  419. // ---- cmi.core.student_name
  420. <?php
  421. $who = addslashes($user['complete_name']);
  422. echo "result='$who';";
  423. ?>
  424. } else if(param == 'cmi.core.lesson_location'){
  425. // ---- cmi.core.lesson_location
  426. result=olms.lesson_location;
  427. } else if(param == 'cmi.core.total_time'){
  428. // ---- cmi.core.total_time
  429. result=olms.total_time;
  430. } else if(param == 'cmi.core.score._children'){
  431. // ---- cmi.core.score._children
  432. result='raw,min,max';
  433. } else if(param == 'cmi.core.score.raw'){
  434. // ---- cmi.core.score.raw
  435. result=olms.score;
  436. } else if(param == 'cmi.core.score.max'){
  437. // ---- cmi.core.score.max
  438. result=olms.max;
  439. } else if(param == 'cmi.core.score.min'){
  440. // ---- cmi.core.score.min
  441. result=olms.min;
  442. } else if(param == 'cmi.core.score'){
  443. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  444. result=olms.score;
  445. } else if(param == 'cmi.core.credit'){
  446. // ---- cmi.core.credit
  447. result = olms.lms_item_credit;
  448. } else if(param == 'cmi.core.lesson_mode'){
  449. // ---- cmi.core.lesson_mode
  450. result = olms.lms_item_lesson_mode;
  451. } else if(param == 'cmi.suspend_data'){
  452. // ---- cmi.suspend_data
  453. result = olms.suspend_data;
  454. } else if(param == 'cmi.launch_data'){
  455. // ---- cmi.launch_data
  456. result = olms.lms_item_launch_data;
  457. } else if(param == 'cmi.objectives._children'){
  458. // ---- cmi.objectives._children
  459. result = 'id,score,status';
  460. } else if(param == 'cmi.objectives._count'){
  461. // ---- cmi.objectives._count
  462. //result='<?php echo $oItem->get_view_count();?>';
  463. result = olms.item_objectives.length;
  464. } else if(param.substring(0,15)== 'cmi.objectives.'){
  465. var myres = '';
  466. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/)) {
  467. var obj_id = myres[1];
  468. var req_type = myres[2];
  469. if(olms.item_objectives[obj_id]==null) {
  470. if(req_type == 'id') {
  471. result = '';
  472. } else if(req_type == '_children'){
  473. result = 'id,score,status';
  474. } else if(req_type == 'score'){
  475. if(myres[3]==null) {
  476. result = '';
  477. olms.G_LastError = G_NotImplementedError;
  478. olms.G_LastErrorString = 'Not implemented yet';
  479. }else if (myres[3] == '._children'){
  480. result = 'raw,min,max'; //non-standard, added for NetG
  481. }else if (myres[3] == '.raw'){
  482. result = '';
  483. }else if (myres[3] == '.max'){
  484. result = '';
  485. }else if (myres[3] == '.min'){
  486. result = '';
  487. }else{
  488. result = '';
  489. olms.G_LastError = G_NotImplementedError;
  490. olms.G_LastErrorString = 'Not implemented yet';
  491. }
  492. }else if(req_type == 'status'){
  493. result = 'not attempted';
  494. }
  495. } else {
  496. //the object is not null
  497. if(req_type == 'id') {
  498. result = olms.item_objectives[obj_id][0];
  499. } else if(req_type == '_children'){
  500. result = 'id,score,status';
  501. } else if(req_type == 'score'){
  502. if(myres[3]==null) {
  503. result = '';
  504. olms.G_LastError = G_NotImplementedError;
  505. olms.G_LastErrorString = 'Not implemented yet';
  506. } else if (myres[3] == '._children'){
  507. result = 'raw,min,max'; //non-standard, added for NetG
  508. } else if (myres[3] == '.raw'){
  509. if(olms.item_objectives[obj_id][2] != null)
  510. {
  511. result = olms.item_objectives[obj_id][2];
  512. }else{
  513. result = '';
  514. }
  515. } else if (myres[3] == '.max'){
  516. if(olms.item_objectives[obj_id][3] != null) {
  517. result = olms.item_objectives[obj_id][3];
  518. }else{
  519. result = '';
  520. }
  521. } else if (myres[3] == '.min') {
  522. if(olms.item_objectives[obj_id][4] != null) {
  523. result = olms.item_objectives[obj_id][4];
  524. } else {
  525. result = '';
  526. }
  527. } else{
  528. result = '';
  529. olms.G_LastError = G_NotImplementedError;
  530. olms.G_LastErrorString = 'Not implemented yet';
  531. }
  532. } else if(req_type == 'status'){
  533. if(olms.item_objectives[obj_id][1] != null) {
  534. result = olms.item_objectives[obj_id][1];
  535. } else {
  536. result = 'not attempted';
  537. }
  538. }
  539. }
  540. }
  541. } else if(param == 'cmi.student_data._children'){
  542. // ---- cmi.student_data._children
  543. result = 'mastery_score,max_time_allowed';
  544. } else if(param == 'cmi.student_data.mastery_score'){
  545. // ---- cmi.student_data.mastery_score
  546. result = olms.mastery_score;
  547. } else if(param == 'cmi.student_data.max_time_allowed'){
  548. // ---- cmi.student_data.max_time_allowed
  549. result = olms.max_time_allowed;
  550. } else if(param == 'cmi.interactions._count'){
  551. // ---- cmi.interactions._count
  552. result = olms.interactions.length;
  553. } else if(param == 'cmi.interactions._children'){
  554. // ---- cmi.interactions._children
  555. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  556. } else{
  557. // ---- anything else
  558. // Invalid argument error
  559. olms.G_LastError = G_InvalidArgumentError ;
  560. olms.G_LastErrorString = G_InvalidArgumentErrorMessage;
  561. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  562. result = '';
  563. return result;
  564. }
  565. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  566. return result;
  567. }
  568. /**
  569. * Twin sister of LMSGetValue(). Only provided for backwards compatibility.
  570. */
  571. function GetValue(param) {
  572. return LMSGetValue(param);
  573. }
  574. /**
  575. * Sets a SCORM variable's value through a call from the SCO.
  576. * @param string The SCORM variable's name
  577. * @param string The SCORM variable's new value
  578. * @param string 'true','false' or an error code
  579. */
  580. function LMSSetValue(param, val) {
  581. logit_scorm("LMSSetValue ('"+param+"','"+val+"')",0);
  582. logit_scorm("Checking olms.lms_item_id " + olms.lms_item_id);
  583. olms.commit = true; //value has changed, need to re-commit
  584. olms.G_LastError = G_NoError ;
  585. olms.G_LastErrorMessage = 'No error';
  586. return_value = 'false';
  587. if ( param == "cmi.core.score.raw" ) {
  588. olms.score= val;
  589. olms.updatable_vars_list['cmi.core.score.raw']=true;
  590. return_value='true';
  591. } else if ( param == "cmi.core.score.max" ) {
  592. olms.max = val;
  593. olms.updatable_vars_list['cmi.core.score.max']=true;
  594. return_value='true';
  595. } else if ( param == "cmi.core.score.min" ) {
  596. olms.min = val;
  597. olms.updatable_vars_list['cmi.core.score.min']=true;
  598. return_value='true';
  599. } else if ( param == "cmi.core.lesson_location" ) {
  600. olms.lesson_location = val;
  601. olms.updatable_vars_list['cmi.core.lesson_location']=true;
  602. return_value='true';
  603. } else if ( param == "cmi.core.lesson_status" ) {
  604. olms.lesson_status = val;
  605. olms.updatable_vars_list['cmi.core.lesson_status'] = true;
  606. olms.statusSignalReceived = 1;
  607. return_value='true';
  608. } else if ( param == "cmi.completion_status" ) {
  609. olms.lesson_status = val;
  610. olms.updatable_vars_list['cmi.completion_status']=true;
  611. return_value='true'; //1.3
  612. } else if ( param == "cmi.core.session_time" ) {
  613. olms.session_time = val;
  614. olms.updatable_vars_list['cmi.core.session_time']=true;
  615. return_value='true';
  616. } else if ( param == "cmi.score.scaled") { //1.3
  617. if (val<=1 && val>=-1) {
  618. olms.score = val ;
  619. olms.updatable_vars_list['cmi.score.scaled']=true;
  620. return_value='true';
  621. } else {
  622. return_value='false';
  623. }
  624. } else if ( param == "cmi.success_status" ) {
  625. success_status = val;
  626. olms.updatable_vars_list['cmi.success_status']=true;
  627. return_value='true'; //1.3
  628. } else if ( param == "cmi.suspend_data" ) {
  629. olms.suspend_data = val;
  630. olms.updatable_vars_list['cmi.suspend_data']=true;
  631. return_value='true';
  632. } else if ( param == "cmi.core.exit" ) {
  633. olms.lms_item_core_exit = val;
  634. olms.updatable_vars_list['cmi.core.exit']=true;
  635. return_value='true';
  636. } else if ( param == "cmi.core.student_id" ) {
  637. olms.G_LastError = G_ElementIsReadOnly;
  638. } else if ( param == "cmi.core.student_name" ) {
  639. olms.G_LastError = G_ElementIsReadOnly;
  640. } else if ( param == "cmi.core.credit" ) {
  641. olms.G_LastError = G_ElementIsReadOnly;
  642. } else if ( param == "cmi.core.entry" ) {
  643. olms.G_LastError = G_ElementIsReadOnly;
  644. } else if ( param == "cmi.core.total_time" ) {
  645. olms.G_LastError = G_ElementIsReadOnly;
  646. } else if ( param == "cmi.core.lesson_mode" ) {
  647. olms.G_LastError = G_ElementIsReadOnly;
  648. } else if ( param == "cmi.comments_from_lms" ) {
  649. olms.G_LastError = G_ElementIsReadOnly;
  650. } else if ( param == "cmi.student_data.time_limit_action" ) {
  651. olms.G_LastError = G_ElementIsReadOnly;
  652. } else if ( param == "cmi.student_data.mastery_score" ) {
  653. olms.G_LastError = G_ElementIsReadOnly;
  654. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  655. olms.G_LastError = G_ElementIsReadOnly;
  656. } else if ( param == "cmi.student_preference._children" ) {
  657. olms.G_LastError = G_ElementIsReadOnly;
  658. } else if ( param == "cmi.launch_data" ) {
  659. olms.G_LastError = G_ElementIsReadOnly;
  660. } else {
  661. var myres = new Array();
  662. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  663. olms.updatable_vars_list['interactions']=true;
  664. elem_id = myres[1];
  665. //interactions setting should start at 0
  666. if(elem_id > olms.interactions.length) {
  667. /*
  668. olms.G_LastError = G_InvalidArgumentError;
  669. olms.G_LastErrorString = 'Invalid argument (interactions)';
  670. return_value = false;
  671. */
  672. olms.interactions[0] = ['0','','','','','','',''];
  673. }
  674. if(olms.interactions[elem_id] == null) {
  675. olms.interactions[elem_id] = ['','','','','','','',''];
  676. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  677. olms.interactions[elem_id][4] = new Array();
  678. }
  679. elem_attrib = myres[2];
  680. switch (elem_attrib) {
  681. case "id":
  682. olms.interactions[elem_id][0] = val;
  683. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  684. return_value='true';
  685. break;
  686. case "time":
  687. olms.interactions[elem_id][2] = val;
  688. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  689. return_value='true';
  690. break;
  691. case "type":
  692. olms.interactions[elem_id][1] = val;
  693. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  694. return_value='true';
  695. break;
  696. case "correct_responses":
  697. // Add at the end of the array
  698. olms.interactions[elem_id][4][olms.interactions[elem_id][4].length] = val;
  699. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  700. return_value='true';
  701. break;
  702. case "weighting":
  703. olms.interactions[elem_id][3] = val;
  704. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  705. return_value='true';
  706. break;
  707. case "student_response":
  708. olms.interactions[elem_id][5] = ''+val;
  709. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  710. return_value='true';
  711. break;
  712. case "result":
  713. olms.interactions[elem_id][6] = val;
  714. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  715. return_value='true';
  716. break;
  717. case "latency":
  718. olms.interactions[elem_id][7] = val;
  719. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  720. return_value='true';
  721. break;
  722. default:
  723. olms.G_LastError = G_NotImplementedError;
  724. olms.G_LastErrorString = 'Not implemented yet';
  725. }
  726. } else if(param.substring(0,15)== 'cmi.objectives.') {
  727. var myres = '';
  728. olms.updatable_vars_list['objectives']=true;
  729. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) {
  730. obj_id = myres[1];
  731. //objectives setting should start at 0
  732. if(obj_id > olms.item_objectives.length) {
  733. olms.G_LastError = G_InvalidArgumentError;
  734. olms.G_LastErrorString = 'Invalid argument (objectives)';
  735. return_value = false;
  736. } else {
  737. req_type = myres[2];
  738. if(obj_id == null || obj_id == '') {
  739. ;//do nothing
  740. } else {
  741. if(olms.item_objectives[obj_id]==null) {
  742. olms.item_objectives[obj_id] = ['','','','',''];
  743. }
  744. if( req_type == "id" ) {
  745. //olms.item_objectives[obj_id][0] = val.substring(51,57);
  746. olms.item_objectives[obj_id][0] = val;
  747. logit_scorm("Objective "+obj_id+"'s id updated",2);
  748. return_value = 'true';
  749. } else if ( req_type == "score" ) {
  750. if (myres[3] == '._children'){
  751. return_value = '';
  752. olms.G_LastError = G_InvalidSetValue;
  753. olms.G_LastErrorString = 'Invalid set value, element is a keyword';
  754. } else if (myres[3] == '.raw'){
  755. olms.item_objectives[obj_id][2] = val;
  756. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  757. return_value = 'true';
  758. } else if (myres[3] == '.max'){
  759. olms.item_objectives[obj_id][3] = val;
  760. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  761. return_value = 'true';
  762. } else if (myres[3] == '.min'){
  763. olms.item_objectives[obj_id][4] = val;
  764. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  765. return_value = 'true';
  766. } else{
  767. return_value = '';
  768. olms.G_LastError = G_NotImplementedError;
  769. olms.G_LastErrorString = 'Not implemented yet';
  770. }
  771. } else if ( req_type == "status" ) {
  772. olms.item_objectives[obj_id][1] = val;
  773. logit_scorm("Objective "+obj_id+"'s status updated",2);
  774. return_value = 'true';
  775. } else {
  776. olms.G_LastError = G_NotImplementedError;
  777. olms.G_LastErrorString = 'Not implemented yet';
  778. }
  779. }
  780. }
  781. }
  782. } else {
  783. olms.G_LastError = G_NotImplementedError;
  784. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  785. }
  786. }
  787. <?php
  788. if ($oLP->force_commit == 1) {
  789. echo " var mycommit = LMSCommit('force');";
  790. }
  791. ?>
  792. return(return_value);
  793. }
  794. /**
  795. * Twin sister of LMSSetValue(). Only provided for backwards compatibility.
  796. */
  797. function SetValue(param, val) {
  798. return LMSSetValue(param, val);
  799. }
  800. /**
  801. * Saves the current data from JS memory to the LMS database
  802. */
  803. function savedata(item_id) {
  804. // Origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
  805. logit_lms('function savedata(' + item_id + ')', 3);
  806. // Status is NOT modified here see the lp_ajax_save_item.php file
  807. if (olms.lesson_status != '') {
  808. olms.updatable_vars_list['cmi.core.lesson_status'] = true;
  809. }
  810. old_item_id = olms.info_lms_item[0];
  811. var item_to_save = olms.lms_item_id;
  812. logit_lms('item_to_save (original value): ' + item_to_save, 3);
  813. // If saving session_time value, we assume that all the new info is about
  814. // the old item, not the current one
  815. // if (olms.session_time != '' && olms.session_time != '0') {
  816. if (olms.switch_finished == 0) {
  817. logit_lms('item_to_save (changed to): ' + old_item_id, 3);
  818. item_to_save = old_item_id;
  819. }
  820. //Original behaviour
  821. // xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
  822. // Modified version
  823. xajax_save_item_scorm(
  824. olms.lms_lp_id,
  825. olms.lms_user_id,
  826. olms.lms_view_id,
  827. item_to_save,
  828. olms.lms_session_id,
  829. olms.lms_course_id,
  830. olms.finishSignalReceived,
  831. olms.userNavigatesAway,
  832. olms.statusSignalReceived
  833. );
  834. olms.info_lms_item[1] = olms.lms_item_id;
  835. if (olms.item_objectives.length > 0) {
  836. xajax_save_objectives(
  837. olms.lms_lp_id,
  838. olms.lms_user_id,
  839. olms.lms_view_id,
  840. old_item_id,
  841. olms.item_objectives
  842. );
  843. }
  844. olms.execute_stats = false;
  845. // Clean array
  846. olms.variable_to_send = new Array();
  847. }
  848. /**
  849. * Send the Commit signal to the LMS (save the data for this element without
  850. * closing the current process)
  851. * From SCORM 1.2 RTE: If the API Adapter is caching values received from the
  852. * SCO via an LMSSetValue(), this call requires that any values not yet
  853. * persisted by the LMS be persisted.
  854. * @param string Must be empty string for conformance with SCORM 1.2
  855. */
  856. function LMSCommit(val) {
  857. logit_scorm('LMSCommit() + val');
  858. olms.G_LastError = G_NoError ;
  859. olms.G_LastErrorMessage = 'No error';
  860. savedata(olms.lms_item_id);
  861. reinit_updatable_vars_list();
  862. //now changes have been commited, no need to update until next SetValue()
  863. //commit = 'false' ;
  864. return('true');
  865. }
  866. /**
  867. * Twin sister of LMSCommit(). Only provided for backwards compatibility.
  868. */
  869. function Commit(val) {
  870. return LMSCommit(val);
  871. }
  872. /**
  873. * Send the closure signal to the LMS. This saves the data and closes the current SCO.
  874. * From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
  875. * longer needs to communicate with the LMS, if it successfully called
  876. * LMSInitialize at any previous point. This call signifies two things:
  877. * 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
  878. * 2.The SCO has finished communicating with the LMS.
  879. * @param string
  880. */
  881. function LMSFinish(val) {
  882. olms.G_LastError = G_NoError ;
  883. olms.G_LastErrorMessage = 'No error';
  884. olms.finishSignalReceived = 1;
  885. // if olms.commit == false, then the SCORM didn't ask for a commit, so we
  886. // should at least report that
  887. if ( !olms.commit ) {
  888. logit_scorm('LMSFinish() (no LMSCommit())',1);
  889. }
  890. logit_scorm('LMSFinish() called on item ' + olms.lms_item_id, 0);
  891. savedata(olms.lms_item_id);
  892. //reinit the commit detector flag
  893. olms.commit = false;
  894. //reinit the list of modified variables
  895. reinit_updatable_vars_list();
  896. return('true');
  897. }
  898. /**
  899. * Twin sister of LMSFinish(). Only provided for backwards compatibility.
  900. */
  901. function Finish(val) {
  902. return LMSFinish(val);
  903. }
  904. /**
  905. * Returns the last error code as a string
  906. * @return string Error code
  907. */
  908. function LMSGetLastError() {
  909. logit_scorm('LMSGetLastError()',1);
  910. return(olms.G_LastError.toString());
  911. }
  912. /**
  913. * Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
  914. */
  915. function GetLastError() {
  916. return LMSGetLastError();
  917. }
  918. /**
  919. * Returns the last error code literal for a given error code
  920. * @param int Error code
  921. * @return string Last error
  922. */
  923. function LMSGetErrorString(errCode){
  924. logit_scorm('LMSGetErrorString()',1);
  925. return(olms.G_LastErrorString);
  926. }
  927. /**
  928. * Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
  929. */
  930. function GetErrorString(errCode){
  931. return LMSGetErrorString(errCode);
  932. }
  933. /**
  934. * Returns a more explanatory, full English, error message
  935. * @param int Error code
  936. * @return string Diagnostic
  937. */
  938. function LMSGetDiagnostic(errCode){
  939. logit_scorm('LMSGetDiagnostic()',1);
  940. return(API.LMSGetLastError());
  941. }
  942. /**
  943. * Twin sister of LMSGetDiagnostic(). Only provided for backwards compatibility.
  944. */
  945. function GetDiagnostic(errCode){
  946. return LMSGetDiagnostic(errCode);
  947. }
  948. /**
  949. * Acts as a "commit"
  950. * This function is not standard SCORM 1.2 and is probably deprecated in all
  951. * meanings of the term.
  952. * @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
  953. */
  954. function Terminate() {
  955. if (olms.lms_initialized == 0) {
  956. olms.G_LastError = G_NotInitialized;
  957. olms.G_LastErrorMessage = G_NotInitializedMessage;
  958. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  959. return('false');
  960. } else {
  961. logit_scorm('Terminate()',0);
  962. olms.G_LastError = G_NoError ;
  963. olms.G_LastErrorMessage = 'No error';
  964. olms.commit = true;
  965. savedata(olms.lms_item_id);
  966. return ('true');
  967. }
  968. }
  969. /**
  970. * LMS-specific code that deals with event handling and inter-frames
  971. * messaging/refreshing.
  972. * Note that from now on, the LMS JS code in this library will act as
  973. * a controller, of the MVC pattern, and receive all requests for frame
  974. * updates, then redispatch to any frame concerned.
  975. */
  976. /**
  977. * Defining the AJAX-object class to be made available from other frames
  978. */
  979. function XAJAXobject() {
  980. this.xajax_switch_item_details = xajax_switch_item_details;
  981. this.switch_item = switch_item;
  982. this.xajax_save_objectives = xajax_save_objectives;
  983. this.xajax_save_item = xajax_save_item;
  984. }
  985. /**
  986. * Cross-browser event handling by Scott Andrew
  987. * @param element Element that needs an event attached
  988. * @param string Event type (load, unload, click, keyDown, ...)
  989. * @param string Function name (the event handler)
  990. * @param string used in addEventListener
  991. */
  992. function addEvent(elm, evType, fn, useCapture){
  993. if (elm.addEventListener){
  994. elm.addEventListener(evType, fn, useCapture);
  995. return true;
  996. } else if (elm.attachEvent) {
  997. var r = elm.attachEvent('on' + evType, fn);
  998. } else{
  999. elm['on'+evType] = fn;
  1000. }
  1001. }
  1002. /**
  1003. * Add listeners to the page objects. This has to be defined for
  1004. * the current context as it acts on objects that should exist
  1005. * on the page
  1006. * possibly deprecated
  1007. * @todo Try to use $(document).unload(lms_save_asset()) instead of the addEvent() method
  1008. */
  1009. function addListeners(){
  1010. //exit if the browser doesn't support ID or tag retrieval
  1011. logit_lms('Entering addListeners()', 3);
  1012. if (!document.getElementsByTagName){
  1013. logit_lms("getElementsByTagName not available", 2);
  1014. return;
  1015. }
  1016. if (!document.getElementById){
  1017. logit_lms("getElementById not available", 2);
  1018. return;
  1019. }
  1020. //assign event handlers to objects
  1021. if (olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.lms_item_type == 'document') {
  1022. logit_lms('Chamilo LP or asset');
  1023. //if this path is a Chamilo learnpath, then start manual save
  1024. //when something is loaded in there
  1025. addEvent(window, 'unload', lms_save_asset,false);
  1026. logit_lms('Added event listener lms_save_asset() on window unload', 3);
  1027. }
  1028. logit_lms('Quitting addListeners()');
  1029. }
  1030. /**
  1031. * Save a Chamilo learnpath item's time and mark as completed upon
  1032. * leaving it
  1033. */
  1034. function lms_save_asset() {
  1035. // only for Chamilo lps
  1036. if (olms.execute_stats) {
  1037. olms.execute_stats = false;
  1038. } else {
  1039. olms.execute_stats = true;
  1040. }
  1041. //For scorms do not show stats
  1042. if (olms.lms_lp_type == 2 && olms.lms_lp_item_type != 'document') {
  1043. olms.execute_stats = false;
  1044. }
  1045. if (olms.lms_item_type == 'quiz') {
  1046. olms.execute_stats = true;
  1047. }
  1048. if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  1049. logit_lms('lms_save_asset');
  1050. logit_lms('execute_stats :'+ olms.execute_stats);
  1051. xajax_save_item(
  1052. olms.lms_lp_id,
  1053. olms.lms_user_id,
  1054. olms.lms_view_id,
  1055. olms.lms_item_id,
  1056. olms.score,
  1057. olms.max,
  1058. olms.min,
  1059. olms.lesson_status,
  1060. olms.session_time,
  1061. olms.suspend_data,
  1062. olms.lesson_location,
  1063. olms.interactions,
  1064. olms.lms_item_core_exit,
  1065. olms.lms_item_type,
  1066. olms.session_id,
  1067. olms.course_id
  1068. );
  1069. if (olms.item_objectives.length>0) {
  1070. xajax_save_objectives(
  1071. olms.lms_lp_id,
  1072. olms.lms_user_id,
  1073. olms.lms_view_id,
  1074. olms.lms_item_id,
  1075. olms.item_objectives
  1076. );
  1077. }
  1078. }
  1079. }
  1080. /**
  1081. * Save a Chamilo learnpath item's time and mark as completed upon leaving it.
  1082. * Same function as lms_save_asset() but saves it with empty params
  1083. * to use values set from another side in the database. Only used by Chamilo quizzes.
  1084. * Also save the score locally because it hasn't been done through SetValue().
  1085. * Saving the status will be dealt with by the XAJAX function.
  1086. */
  1087. function chamilo_void_save_asset(score, max, min, status) {
  1088. logit_lms('chamilo_void_save_asset('+score+','+max+','+min+','+status+')', 3);
  1089. olms.score = score;
  1090. if ((max == null) || (max == '')){
  1091. max = 100;
  1092. }
  1093. if ((min == null) || (min == '')){
  1094. min = 0;
  1095. }
  1096. // Assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  1097. xajax_save_item(
  1098. olms.lms_lp_id,
  1099. olms.lms_user_id,
  1100. olms.lms_view_id,
  1101. olms.lms_item_id,
  1102. score,
  1103. max,
  1104. min,
  1105. status
  1106. );
  1107. }
  1108. /**
  1109. * Logs information about SCORM messages into the log frame
  1110. * @param string Message to log
  1111. * @param integer Priority (0 for top priority, 3 for lowest)
  1112. */
  1113. function logit_scorm(message, priority) {
  1114. if (scorm_logs) {
  1115. log_in_log("SCORM: " + message, priority);
  1116. }
  1117. return false;
  1118. }
  1119. function log_in_log(message, priority) {
  1120. // Colorize a little
  1121. var color = "color: black";
  1122. switch (priority) {
  1123. case 0:
  1124. color = "color:red;font-weight:bold";
  1125. break;
  1126. case 1:
  1127. color = "color:orange";
  1128. break;
  1129. case 2:
  1130. color = "color:green";
  1131. break;
  1132. case 3:
  1133. color = "color:blue";
  1134. break;
  1135. }
  1136. if (this.console) {
  1137. // Log in console with syntax colouring
  1138. console.log("%c"+message, color);
  1139. } else {
  1140. window.console.log(message);
  1141. }
  1142. }
  1143. /**
  1144. * Logs information about LMS activity into the log frame
  1145. * @param string Message to log
  1146. * @param integer Priority (0 for top priority, 3 for lowest)
  1147. */
  1148. function logit_lms(message, priority){
  1149. if (scorm_logs) {
  1150. log_in_log("LMS: " + message + ' (# lms_item_id = '+olms.lms_item_id+')', priority);
  1151. }
  1152. return false;
  1153. }
  1154. /**
  1155. * Update the Table Of Contents frame, by changing CSS styles, mostly
  1156. * @param string Action to be taken
  1157. * @param integer Item id to update
  1158. */
  1159. function update_toc(update_action, update_id, change_ids) {
  1160. if (!change_ids || change_ids != 'no') {
  1161. change_ids = 'yes';
  1162. }
  1163. var myelem = $("#toc_"+update_id);
  1164. logit_lms('update_toc("'+update_action+'", '+update_id+')',2);
  1165. if (update_id != 0) {
  1166. // Switch function is broken
  1167. if (update_action == "unhighlight" || update_action == "highlight") {
  1168. if (update_action == "unhighlight") {
  1169. myelem.removeClass('scorm_highlight');
  1170. } else {
  1171. if (change_ids=='yes') {
  1172. olms.lms_next_item = update_id;
  1173. olms.lms_previous_item = update_id;
  1174. }
  1175. myelem.addClass('scorm_highlight');
  1176. }
  1177. } else {
  1178. myelem.removeClass("scorm_not_attempted scorm_incomplete scorm_completed scorm_failed scorm_passed");
  1179. if (update_action == "not attempted") {
  1180. myelem.addClass('scorm_not_attempted');
  1181. } else if (update_action == "incomplete") {
  1182. myelem.addClass('scorm_not_attempted');
  1183. } else if (update_action == "completed") {
  1184. myelem.addClass('scorm_completed');
  1185. } else if (update_action == "failed") {
  1186. myelem.addClass('scorm_failed');
  1187. } else if (update_action == "passed") {
  1188. myelem.addClass('scorm_completed');
  1189. } else if (update_action == "browsed") {
  1190. myelem.addClass('scorm_completed');
  1191. } else {
  1192. logit_lms('Update action unknown',1);
  1193. }
  1194. }
  1195. }
  1196. return true;
  1197. }
  1198. /**
  1199. * Update the stats frame using a reload of the frame to avoid unsynched data
  1200. */
  1201. function update_stats() {
  1202. logit_lms('update_stats()');
  1203. if (olms.execute_stats) {
  1204. try {
  1205. cont_f = document.getElementById('content_id');
  1206. cont_f.src = "lp_controller.php?action=stats";
  1207. cont_f.reload();
  1208. } catch (e) {
  1209. return false;
  1210. }
  1211. }
  1212. olms.execute_stats = false;
  1213. }
  1214. /**
  1215. * Update the stats frame using a reload of the frame to avoid unsynched data
  1216. */
  1217. function update_stats_page() {
  1218. logit_lms('update_stats_page',3);
  1219. var myframe = document.getElementById('content_id');
  1220. var mysrc = myframe.location.href;
  1221. if(mysrc == 'lp_controller.php?action=stats'){
  1222. if(myframe && myframe.src){
  1223. var mysrc = myframe.src;
  1224. myframe.src = mysrc;
  1225. }
  1226. // = mysrc; //refresh page
  1227. }
  1228. return true;
  1229. }
  1230. /**
  1231. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1232. * @param integer Number of completed items
  1233. * @param integer Number of items in total
  1234. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1235. */
  1236. function update_progress_bar(nbr_complete, nbr_total, mode) {
  1237. logit_lms('update_progress_bar('+nbr_complete+', '+nbr_total+', '+mode+')',3);
  1238. logit_lms(
  1239. 'update_progress_bar with params: lms_lp_id= ' + olms.lms_lp_id +
  1240. ', lms_view_id= '+ olms.lms_view_id + ' lms_user_id= '+ olms.lms_user_id,
  1241. 3
  1242. );
  1243. if (mode == '') {
  1244. mode='%';
  1245. }
  1246. if (nbr_total == 0) {
  1247. nbr_total=1;
  1248. }
  1249. var percentage = (nbr_complete/nbr_total)*100;
  1250. percentage = Math.round(percentage);
  1251. var progress_bar = $("#progress_bar_value");
  1252. progress_bar.css('width', percentage + "%");
  1253. var mytext = '';
  1254. switch(mode){
  1255. case 'abs':
  1256. mytext = nbr_complete + '/' + nbr_total;
  1257. break;
  1258. case '%':
  1259. default:
  1260. mytext = percentage + '%';
  1261. break;
  1262. }
  1263. progress_bar.html(mytext);
  1264. return true;
  1265. }
  1266. /**
  1267. * Update the gamification values (number of stars and score)
  1268. */
  1269. function updateGamificationValues() {
  1270. var fetchValues = $.ajax('<?php echo api_get_path(
  1271. WEB_AJAX_PATH
  1272. ) ?>lp.ajax.php?<?php echo api_get_cidreq() ?>', {
  1273. dataType: 'json',
  1274. data: {
  1275. a: 'update_gamification'
  1276. }
  1277. });
  1278. $.when(fetchValues).done(function (values) {
  1279. if (values.stars > 0) {
  1280. $('#scorm-gamification .fa-star:nth-child(' + values.stars + ')').addClass('level');
  1281. }
  1282. $('#scorm-gamification .col-xs-4').text(values.score);
  1283. });
  1284. }
  1285. /**
  1286. * Analyses the variables that have been modified through this SCO's life and
  1287. * put them into an array for later shipping to lp_ajax_save_item.php
  1288. * @return array Array of SCO variables
  1289. */
  1290. function process_scorm_values() {
  1291. logit_scorm('process_scorm_values()');
  1292. for (i=0; i < olms.scorm_variables.length; i++) {
  1293. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1294. olms.variable_to_send.push(olms.scorm_variables[i]);
  1295. }
  1296. }
  1297. return olms.variable_to_send;
  1298. }
  1299. /**
  1300. * Reinitializes the SCO's modified variables to an empty list.
  1301. * @return void
  1302. * @uses The global updatable_vars_list array to register this
  1303. */
  1304. function reinit_updatable_vars_list() {
  1305. logit_scorm('Cleaning updatable_vars_list: reinit_updatable_vars_list');
  1306. for (i=0;i < olms.scorm_variables.length;i++) {
  1307. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1308. olms.updatable_vars_list[olms.scorm_variables[i]]=false;
  1309. }
  1310. }
  1311. olms.lesson_status='';
  1312. }
  1313. /**
  1314. * Function that handles the saving of an item and switching from an item to another.
  1315. * Once called, this function should be able to do the whole process of
  1316. * (1) saving the current item,
  1317. * (2) refresh all the values inside the SCORM API object,
  1318. * (3) open the new item into the content_id frame,
  1319. * (4) refresh the table of contents
  1320. * (5) refresh the progress bar (completion)
  1321. * (6) refresh the message frame
  1322. * @param integer Chamilo ID for the current item
  1323. * @param string This parameter can be a string specifying the next
  1324. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1325. */
  1326. function switch_item(current_item, next_item){
  1327. // backup these params
  1328. var orig_current_item = current_item;
  1329. var orig_next_item = next_item;
  1330. var orig_lesson_status = olms.lesson_status;
  1331. var orig_item_type = olms.lms_item_types['i'+current_item];
  1332. var next_item_type = olms.lms_item_types['i'+next_item];
  1333. if (olms.statusSignalReceived == 0 && olms.lesson_status != 'not attempted') {
  1334. // In this situation, the status can be considered set as it was clearly
  1335. // set in a previous stage
  1336. olms.statusSignalReceived = 1;
  1337. }
  1338. logit_lms('switch_item() called with params '+olms.lms_item_id+' and '+next_item+'',2);
  1339. /*
  1340. There are four "cases" for switching items:
  1341. (1) asset switching to asset
  1342. We need to save, then switch
  1343. (2) asset switching to sco
  1344. We need to save, switching not necessary (LMSInitialize does the job)
  1345. (3) sco switching to asset
  1346. We need to switch the document in the content frame, but we cannot
  1347. switch the item details, otherwise the LMSFinish() call (that *must*
  1348. be triggered by the SCO when it unloads) will use bad values. However,
  1349. we need to load the new asset's context once the SCO has unloaded
  1350. (4) sco switching to sco
  1351. We don't neet to switch nor commit, LMSFinish() on unload and
  1352. LMSInitialize on load will do the job
  1353. In any case, we need to change the current document frame.
  1354. These cases, although clear here, are however very difficult to implement
  1355. */
  1356. if (orig_item_type != 'sco') {
  1357. if (next_item_type != 'sco' ) {
  1358. logit_lms('Case 1 - current != sco and next != sco');
  1359. } else {
  1360. logit_lms('Case 2 - current != sco but next == sco');
  1361. }
  1362. xajax_save_item(
  1363. olms.lms_lp_id,
  1364. olms.lms_user_id,
  1365. olms.lms_view_id,
  1366. olms.lms_item_id,
  1367. olms.score,
  1368. olms.max,
  1369. olms.min,
  1370. olms.lesson_status,
  1371. olms.asset_timer,
  1372. olms.suspend_data,
  1373. olms.lesson_location,
  1374. olms.interactions,
  1375. olms.lms_item_core_exit,
  1376. orig_item_type,
  1377. olms.session_id,
  1378. olms.course_id,
  1379. olms.finishSignalReceived,
  1380. 1,
  1381. olms.statusSignalReceived
  1382. );
  1383. xajax_switch_item_details(
  1384. olms.lms_lp_id,
  1385. olms.lms_user_id,
  1386. olms.lms_view_id,
  1387. olms.lms_item_id,
  1388. next_item
  1389. );
  1390. } else {
  1391. if (next_item_type != 'sco') {
  1392. logit_lms('Case 3 - current == sco but next != sco');
  1393. } else {
  1394. logit_lms('Case 4 - current == sco and next == sco');
  1395. }
  1396. xajax_save_item_scorm(
  1397. olms.lms_lp_id,
  1398. olms.lms_user_id,
  1399. olms.lms_view_id,
  1400. olms.lms_item_id,
  1401. olms.lms_session_id,
  1402. olms.lms_course_id,
  1403. olms.finishSignalReceived,
  1404. 1,
  1405. olms.statusSignalReceived
  1406. );
  1407. reinit_updatable_vars_list();
  1408. xajax_switch_item_toc(
  1409. olms.lms_lp_id,
  1410. olms.lms_user_id,
  1411. olms.lms_view_id,
  1412. olms.lms_item_id,
  1413. next_item
  1414. );
  1415. if (olms.item_objectives.length>0) {
  1416. xajax_save_objectives(
  1417. olms.lms_lp_id,
  1418. olms.lms_user_id,
  1419. olms.lms_view_id,
  1420. olms.lms_item_id,
  1421. olms.item_objectives
  1422. );
  1423. }
  1424. }
  1425. /**
  1426. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1427. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1428. * then some checks have to be done on score), we have to force a
  1429. * special commit here to avoid getting to the next element with a
  1430. * missing prerequisite. The 'onunload' event is treated with
  1431. * savedata_onunload(), and doesn't need to be triggered at any
  1432. * particular time, but here we are in the case of switching to another
  1433. * item, so this is particularly important to complete the element in
  1434. * time.
  1435. * However, this cannot be initiated from the JavaScript, mainly
  1436. * because another onunload event can be triggered by the SCO itself,
  1437. * which can set, for example, the status to incomplete while the
  1438. * status has already been set to "completed" by the hand-made
  1439. * savedata() (and then the status cannot be "incompleted"
  1440. * anymore)
  1441. */
  1442. /*
  1443. if (olms.lms_item_type=='sco' &&
  1444. olms.lesson_status != 'completed' &&
  1445. olms.lesson_status != 'passed' &&
  1446. olms.lesson_status != 'browsed' &&
  1447. olms.lesson_status != 'incomplete' &&
  1448. olms.lesson_status != 'failed'
  1449. ) {
  1450. // savedata() with olms.finishSignalReceived == 1 treats the special
  1451. // condition and saves the new status to the database, so
  1452. // switch_item_details() enjoys the new status
  1453. savedata(olms.lms_item_id);
  1454. }
  1455. xajax_save_item(
  1456. olms.lms_lp_id,
  1457. olms.lms_user_id,
  1458. olms.lms_view_id,
  1459. olms.lms_item_id,
  1460. olms.score, olms.max,
  1461. olms.min,
  1462. olms.lesson_status,
  1463. olms.session_time,
  1464. olms.suspend_data,
  1465. olms.lesson_location,
  1466. olms.interactions,
  1467. olms.lms_item_core_exit,
  1468. orig_item_type,
  1469. olms.session_id,
  1470. olms.course_id,
  1471. olms.finishSignalReceived,
  1472. 1,
  1473. olms.statusSignalReceived
  1474. );
  1475. */
  1476. olms.execute_stats = false;
  1477. // Considering info_lms_item[0] is initially the oldest and info_lms_item[1]
  1478. // is the newest item, and considering we are done switching the items now,
  1479. // we need to update these markers so that the new item is loaded when
  1480. // changing the document in the content frame
  1481. if (olms.info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1482. olms.info_lms_item[0]=next_item;
  1483. olms.info_lms_item[1]=next_item;
  1484. } else {
  1485. if (next_item!='next' && next_item!='previous') {
  1486. olms.info_lms_item[0]=olms.info_lms_item[1];
  1487. olms.info_lms_item[1]=next_item;
  1488. }
  1489. }
  1490. if (olms.info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1491. olms.info_lms_item[0]=next_item;
  1492. olms.info_lms_item[1]=next_item;
  1493. } else {
  1494. if (next_item!='next' && next_item!='previous') {
  1495. olms.info_lms_item[0]=olms.info_lms_item[0];
  1496. olms.info_lms_item[1]=next_item;
  1497. }
  1498. }
  1499. //(3) open the new item in the content_id frame
  1500. switch (next_item){
  1501. case 'next':
  1502. next_item = olms.lms_next_item;
  1503. olms.info_lms_item[0] = olms.info_lms_item[1];
  1504. olms.info_lms_item[1] = olms.lms_next_item;
  1505. break;
  1506. case 'previous':
  1507. next_item = olms.lms_previous_item;
  1508. olms.info_lms_item[0] = olms.info_lms_item[1];
  1509. olms.info_lms_item[1] = olms.lms_previous_item;
  1510. break;
  1511. default:
  1512. break;
  1513. }
  1514. var mysrc = '<?php echo api_get_path(WEB_CODE_PATH); ?>newscorm/lp_controller.php?action=content&lp_id=' + olms.lms_lp_id +
  1515. '&item_id=' + next_item + '&cidReq=' + olms.lms_course_code + '&id_session=' + olms.lms_session_id;
  1516. var cont_f = $("#content_id");
  1517. <?php if ($oLP->mode == 'fullscreen') { ?>
  1518. cont_f = window.open('' + mysrc, 'content_id', 'toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1519. cont_f.onload=function(){
  1520. olms.info_lms_item[0]=olms.info_lms_item[1];
  1521. }
  1522. cont_f.onunload=function(){
  1523. olms.info_lms_item[0]=olms.info_lms_item[1];
  1524. }
  1525. <?php } else { ?>
  1526. log_in_log('loading '+mysrc+' in frame');
  1527. cont_f.attr("src",mysrc);
  1528. <?php } ?>
  1529. if (olms.lms_lp_type==1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  1530. xajax_start_timer();
  1531. }
  1532. //(4) refresh the audio player if needed
  1533. $.ajax({
  1534. type: "POST",
  1535. url: "lp_nav.php",
  1536. data: "",
  1537. beforeSend: function() {
  1538. $.each($('audio'), function () {
  1539. var player = new MediaElementPlayer($(this));
  1540. player.pause();
  1541. });
  1542. },
  1543. success: function(tmp_data) {
  1544. if ($("#lp_media_file").length != 0) {
  1545. $("#lp_media_file").html(tmp_data);
  1546. }
  1547. }
  1548. });
  1549. olms.switch_finished = 0; //only changed back once LMSInitialize() happens
  1550. loadForumThead(olms.lms_lp_id, next_item);
  1551. return true;
  1552. }
  1553. /**
  1554. * Get a forum info when the learning path item has a associated forum
  1555. */
  1556. var loadForumThead = function(lpId, lpItemId) {
  1557. var loadForum = $.getJSON('<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php', {
  1558. a: 'get_forum_thread',
  1559. lp: lpId,
  1560. lp_item: lpItemId,
  1561. cidReq : '<?php echo api_get_course_id(); ?>',
  1562. id_session: '<?php echo api_get_session_id(); ?>'
  1563. }
  1564. );
  1565. $.when(loadForum).done(function(forumThreadData) {
  1566. var tabForumLink = $('.lp-view-tabs a[href="#lp-view-forum"]'),
  1567. tabForum = tabForumLink.parent();
  1568. $("#navTabs").show();
  1569. if (forumThreadData.error) {
  1570. tabForumLink.removeAttr('data-toggle');
  1571. tabForum.addClass('disabled');
  1572. $("#navTabs").hide();
  1573. $('#lp-view-forum').html('');
  1574. return;
  1575. }
  1576. tabForumLink.attr('data-toggle', 'tab');
  1577. tabForum.removeClass('disabled');
  1578. var forumIframe = $('<iframe>').attr({
  1579. width:'100%',
  1580. frameborder:'0',
  1581. scrolling:'yes',
  1582. tabindex:'0',
  1583. id:'chamilo-disqus',
  1584. src: '<?php echo api_get_path(WEB_CODE_PATH) ?>forum/viewthread.php?<?php echo api_get_cidreq() ?>&' + $.param({
  1585. gradebook: 0,
  1586. origin: 'learnpath',
  1587. forum: forumThreadData.forumId,
  1588. thread: forumThreadData.threadId,
  1589. posts_order: 'desc'
  1590. })
  1591. });
  1592. $('#lp-view-forum').html(forumIframe);
  1593. });
  1594. };
  1595. /**
  1596. * Save a specific item (with its interactions, if any) into the LMS through
  1597. * an AJAX call to lp_ajax_save_item.php.
  1598. * Because of the need to pass an array, we have to build the parameters
  1599. * manually into GET[].
  1600. * This function has a twin sister for SCO elements (xajax_save_item_scorm)
  1601. * which takes into account the interactions.
  1602. * @param int ID of the learning path (for the LMS)
  1603. * @param int ID of the user
  1604. * @param int ID of the view of this learning path
  1605. * @param int ID of the item currently looked at
  1606. * @param float Score
  1607. * @param float Max score
  1608. * @param float Min score
  1609. * @param string Lesson status
  1610. * @param string Current session time (in 'xxxx:xx:xx.xx' format)
  1611. * @param string Suspend data (maximum 255 chars)
  1612. * @param string Lesson location (which page we've reached in the SCO)
  1613. * @param array Interactions
  1614. * @param string Core exit value (up to 4096 chars)
  1615. * @return void
  1616. * @uses lp_ajax_save_item.php through an AJAX call
  1617. */
  1618. function xajax_save_item(
  1619. lms_lp_id,
  1620. lms_user_id,
  1621. lms_view_id,
  1622. lms_item_id,
  1623. score,
  1624. max,
  1625. min,
  1626. lesson_status,
  1627. session_time,
  1628. suspend_data,
  1629. lesson_location,
  1630. interactions,
  1631. lms_item_core_exit,
  1632. item_type,
  1633. session_id,
  1634. course_id,
  1635. finishSignalReceived,
  1636. userNavigatesAway,
  1637. statusSignalReceived
  1638. ) {
  1639. var params = '';
  1640. if (typeof(finishSignalReceived) == 'undefined') {
  1641. finishSignalReceived = 0;
  1642. }
  1643. if (typeof(userNavigatesAway) == 'undefined') {
  1644. userNavigatesAway = 0;
  1645. }
  1646. if (typeof(statusSignalReceived) == 'undefined') {
  1647. statusSignalReceived = 0;
  1648. }
  1649. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1650. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1651. params += '&status='+lesson_status+'&t='+session_time;
  1652. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1653. params += '&core_exit='+lms_item_core_exit;
  1654. params += '&session_id='+session_id;
  1655. params += '&course_id='+course_id;
  1656. params += '&finishSignalReceived='+finishSignalReceived;
  1657. params += '&userNavigatesAway='+userNavigatesAway;
  1658. params += '&statusSignalReceived='+statusSignalReceived;
  1659. // console.info(session_time);
  1660. if (olms.lms_lp_type == 1 || item_type == 'document' || item_type == 'asset') {
  1661. logit_lms('xajax_save_item with params:' + params,3);
  1662. $.ajax({
  1663. type:"POST",
  1664. data: params,
  1665. url: "lp_ajax_save_item.php",
  1666. dataType: "script",
  1667. async: false
  1668. });
  1669. }
  1670. }
  1671. /**
  1672. * Save a SCORM item's variables, getting its SCORM values from
  1673. * updatable_vars_list. Takes interactions into account and considers whether
  1674. * variables have been modified or not.
  1675. * @param int ID of the learning path
  1676. * @param int ID of the user
  1677. * @param int ID of the view
  1678. * @param int ID of the item
  1679. * @param bool 1 if this call comes from a "LMSFinish()" call, 0 or nothing otherwise
  1680. * @return void
  1681. * @uses olms.updatable_vars_list
  1682. * @uses lp_ajax_save_item.php through an AJAX call
  1683. */
  1684. function xajax_save_item_scorm(
  1685. lms_lp_id,
  1686. lms_user_id,
  1687. lms_view_id,
  1688. lms_item_id,
  1689. session_id,
  1690. course_id,
  1691. finishSignalReceived,
  1692. userNavigatesAway,
  1693. statusSignalReceived
  1694. )
  1695. {
  1696. if (typeof(finishSignalReceived) == 'undefined') {
  1697. finishSignalReceived = 0;
  1698. }
  1699. if (typeof(userNavigatesAway) == 'undefined') {
  1700. userNavigatesAway = 0;
  1701. }
  1702. if (typeof(statusSignalReceived) == 'undefined') {
  1703. statusSignalReceived = 0;
  1704. }
  1705. var is_interactions='false';
  1706. var params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1707. // The missing arguments will be ignored by lp_ajax_save_item.php
  1708. //params += '&s=&max=&min=&status=&t=&suspend=&loc=&interact=&core_exit=';
  1709. params += '&session_id='+session_id;
  1710. params += '&course_id='+course_id;
  1711. params += '&finishSignalReceived='+finishSignalReceived;
  1712. params += '&userNavigatesAway='+userNavigatesAway;
  1713. params += '&statusSignalReceived='+statusSignalReceived;
  1714. var my_scorm_values = new Array();
  1715. my_scorm_values = process_scorm_values();
  1716. for (k=0; k < my_scorm_values.length; k++) {
  1717. if (my_scorm_values[k]=='cmi.core.session_time') {
  1718. params += '&t='+olms.session_time;
  1719. } else if (my_scorm_values[k]=='cmi.core.lesson_status' && olms.lesson_status!='') {
  1720. params += '&status='+olms.lesson_status;
  1721. } else if (my_scorm_values[k]=='cmi.core.score.raw') {
  1722. params += '&s='+olms.score;
  1723. } else if (my_scorm_values[k]=='cmi.core.score.max') {
  1724. params += '&max='+olms.max;
  1725. } else if (my_scorm_values[k]=='cmi.core.score.min') {
  1726. params += '&min='+olms.min;
  1727. } else if (my_scorm_values[k]=='cmi.core.lesson_location') {
  1728. params += '&loc='+olms.lesson_location;
  1729. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1730. } else if (my_scorm_values[k]=='cmi.score.scaled') {
  1731. } else if (my_scorm_values[k]=='cmi.suspend_data') {
  1732. params += '&suspend='+olms.suspend_data;
  1733. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1734. } else if (my_scorm_values[k]=='cmi.core.exit') {
  1735. params += '&core_exit='+olms.lms_item_core_exit;
  1736. }
  1737. if (my_scorm_values[k]=='interactions') {
  1738. is_interactions='true';
  1739. } else {
  1740. is_interactions='false';
  1741. }
  1742. }
  1743. if (is_interactions == 'true') {
  1744. interact_string = '';
  1745. temp = '';
  1746. for (i in olms.interactions) {
  1747. interact_string += '&interact['+i+']=';
  1748. interact_temp = '[';
  1749. for (j in olms.interactions[i]) {
  1750. temp = olms.interactions[i][j];
  1751. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1752. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1753. while(temp.indexOf(',') >= 0){
  1754. temp = temp.replace(',','@.|@');
  1755. };
  1756. interact_temp +=temp+',';
  1757. }
  1758. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1759. // interact_string += encodeURIComponent(interact_temp);
  1760. interact_string += interact_temp;
  1761. }
  1762. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1763. params += interact_string;
  1764. is_interactions='false';
  1765. }
  1766. logit_lms('xajax_save_item_scorm with params:' + params, 3);
  1767. $.ajax({
  1768. type:"POST",
  1769. data: params,
  1770. url: "lp_ajax_save_item.php",
  1771. dataType: "script",
  1772. async: false
  1773. });
  1774. params = '';
  1775. my_scorm_values = null;
  1776. }
  1777. /**
  1778. * Starts the timer with the server clock time.
  1779. * @return void
  1780. * @todo check the timer stuff really works and rename function to startTimer()
  1781. * @uses lp_ajax_start_timer.php
  1782. */
  1783. function xajax_start_timer() {
  1784. logit_lms('xajax_start_timer() called',3);
  1785. $.ajax({
  1786. type: "GET",
  1787. url: "lp_ajax_start_timer.php",
  1788. dataType: "script",
  1789. async: false,
  1790. success: function(time) {
  1791. olms.asset_timer = time;
  1792. olms.asset_timer_total = 0;
  1793. logit_lms('xajax_start_timer result: ' + time,3);
  1794. var date = new Date(time * 1000);
  1795. logit_lms('xajax_start_timer result: ' + date.toString(),3);
  1796. }
  1797. });
  1798. }
  1799. /**
  1800. * Save a specific item's objectives into the LMS through an Synch JAX call
  1801. * @param int ID of the learning path
  1802. * @param int ID of the user
  1803. * @param int ID of the view
  1804. * @param int ID of the item
  1805. * @param array SCO's recorded objectives
  1806. * @uses lp_ajax_save_objectives.php
  1807. */
  1808. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1809. var params = '';
  1810. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1811. params += '&iid='+lms_item_id;
  1812. obj_string = '';
  1813. logit_lms('xajax_save_objectives with params:' + params, 3);
  1814. for (i in item_objectives){
  1815. obj_string += '&objectives['+i+']=';
  1816. obj_temp = '[';
  1817. for (j in item_objectives[i]) {
  1818. obj_temp += item_objectives[i][j]+',';
  1819. }
  1820. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1821. obj_string += encodeURIComponent(obj_temp);
  1822. }
  1823. params += obj_string;
  1824. $.ajax({
  1825. type: "POST",
  1826. data: params,
  1827. url: "lp_ajax_save_objectives.php",
  1828. dataType: "script",
  1829. async: false
  1830. });
  1831. }
  1832. /**
  1833. * Switch between two items through an AJAX call.
  1834. * @param int ID of the learning path
  1835. * @param int ID of the user
  1836. * @param int ID of the view
  1837. * @param int ID of the item
  1838. * @param int ID of the next item
  1839. * @uses lp_ajax_switch_item.php
  1840. */
  1841. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1842. var params = {
  1843. 'lid': lms_lp_id,
  1844. 'uid': lms_user_id,
  1845. 'vid': lms_view_id,
  1846. 'iid': lms_item_id,
  1847. 'next': next_item
  1848. };
  1849. logit_lms('xajax_switch_item_details with params:' + params, 3);
  1850. $.ajax({
  1851. type: "POST",
  1852. data: params,
  1853. url: "lp_ajax_switch_item.php",
  1854. dataType: "script",
  1855. async: false
  1856. });
  1857. }
  1858. /**
  1859. * Switch between two items through an AJAX call, but only update the TOC and
  1860. * progress bar.
  1861. * @param int ID of the learning path
  1862. * @param int ID of the user
  1863. * @param int ID of the view
  1864. * @param int ID of the item
  1865. * @param int ID of the next item
  1866. * @uses lp_ajax_switch_toc.php
  1867. */
  1868. function xajax_switch_item_toc(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, next_item) {
  1869. var params = {
  1870. 'lid': lms_lp_id,
  1871. 'uid': lms_user_id,
  1872. 'vid': lms_view_id,
  1873. 'iid': lms_item_id,
  1874. 'next': next_item
  1875. };
  1876. logit_lms('xajax_switch_item_toc');
  1877. $.ajax({
  1878. type: "POST",
  1879. data: params,
  1880. url: "lp_ajax_switch_item_toc.php",
  1881. dataType: "script",
  1882. async: false
  1883. });
  1884. }
  1885. /**
  1886. * Allow attach the glossary terms into html document of scorm. This has
  1887. * nothing to do with SCORM itself, and should not interfere w/ SCORM either.
  1888. * @param string automatic or manual values are allowed
  1889. */
  1890. function attach_glossary_into_scorm(type) {
  1891. var f = $('#content_id')[0];
  1892. //Prevents "f is undefined" javascript error
  1893. if (f == null) {
  1894. logit_lms('attach_glossary_into_scorm failed', 0);
  1895. return false;
  1896. }
  1897. try {
  1898. var doc = f.contentWindow ? f.contentWindow.document : f.contentDocument ? f.contentDocument : f.document;
  1899. } catch (ex) { }
  1900. var $frame_content = $('body',doc);
  1901. var my_text=$frame_content.html();
  1902. my_protocol = location.protocol;
  1903. my_pathname=location.pathname;
  1904. work_path = my_pathname.substr(0,my_pathname.indexOf('<?php echo api_get_path(REL_COURSE_PATH) ?>'));
  1905. var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php'; ?>';
  1906. if (type == 'automatic') {
  1907. $.ajax({
  1908. contentType: "application/x-www-form-urlencoded",
  1909. beforeSend: function(object) {
  1910. },
  1911. type: "POST",
  1912. url: ajaxRequestUrl,
  1913. data: "glossary_data=true",
  1914. success: function(datas) {
  1915. if (datas.length==0) {
  1916. return false;
  1917. }
  1918. // glossary terms
  1919. data_terms=datas.split("[|.|_|.|-|.|]");
  1920. var complex_array = new Array();
  1921. var cp_complex_array = new Array();
  1922. for(i=0;i < data_terms.length;i++) {
  1923. specific_terms= data_terms[i].split("__|__|");
  1924. var real_term = specific_terms[1]; // glossary term
  1925. var real_code = specific_terms[0]; // glossary id
  1926. complex_array[real_code] = real_term;
  1927. cp_complex_array[real_code] = real_term;
  1928. }
  1929. complex_array.reverse();
  1930. for (var my_index in complex_array) {
  1931. n = complex_array[my_index];
  1932. if (n == null) {
  1933. n = '';
  1934. } else {
  1935. for (var cp_my_index in cp_complex_array) {
  1936. cp_data = cp_complex_array[cp_my_index];
  1937. if (cp_data == null) {
  1938. cp_data = '';
  1939. } else {
  1940. if (cp_data == n) {
  1941. my_index = cp_my_index;
  1942. }
  1943. }
  1944. }
  1945. //alert(n + ' ' + my_index);
  1946. $("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
  1947. }
  1948. }
  1949. var complex_array = new Array();
  1950. $("iframe").contents().find("body").on("click", ".glossary-ajax", function() {
  1951. div_show_id="div_show_id";
  1952. div_content_id="div_content_id";
  1953. $("iframe").contents().find("body").
  1954. append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1955. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1956. show_description = $("iframe").contents().find("div#"+div_content_id);
  1957. var $target = $(this);
  1958. if ($("#learning_path_left_zone").is(':visible') ) {
  1959. var extra_left = $("#learning_path_left_zone").width() + 20;
  1960. } else {
  1961. var extra_left = 0;
  1962. }
  1963. show_dialog.dialog({
  1964. autoOpen: false,
  1965. width: 600,
  1966. height: 200,
  1967. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  1968. close: function(){
  1969. show_dialog.remove();
  1970. show_description.remove();
  1971. }
  1972. });
  1973. notebook_id=$(this).attr("name");
  1974. data_notebook=notebook_id.split("link");
  1975. my_glossary_id=data_notebook[1];
  1976. $.ajax({
  1977. contentType: "application/x-www-form-urlencoded",
  1978. type: "POST",
  1979. url: ajaxRequestUrl,
  1980. data: "glossary_id="+my_glossary_id,
  1981. success: function(data) {
  1982. show_description.html(data);
  1983. show_dialog.dialog("open");
  1984. }
  1985. });
  1986. });
  1987. }
  1988. });
  1989. } else {
  1990. if (type == 'manual') {
  1991. $("iframe").contents().find("body").on("click", ".glossary", function() {
  1992. is_glossary_name = $(this).html();
  1993. div_show_id="div_show_id";
  1994. div_content_id="div_content_id";
  1995. $("iframe").contents().find("body").
  1996. append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1997. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1998. show_description = $("iframe").contents().find("div#"+div_content_id);
  1999. var $target = $(this);
  2000. if ($("#learning_path_left_zone").is(':visible') ) {
  2001. var extra_left = $("#learning_path_left_zone").width() + 20;
  2002. } else {
  2003. var extra_left = 0;
  2004. }
  2005. //$("#"+div_show_id).dialog("destroy");
  2006. show_dialog.dialog({
  2007. autoOpen: false,
  2008. width: 600,
  2009. height: 200,
  2010. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  2011. close: function(){
  2012. show_dialog.remove();
  2013. show_description.remove();
  2014. }
  2015. });
  2016. $.ajax({
  2017. contentType: "application/x-www-form-urlencoded",
  2018. type: "POST",
  2019. url: ajaxRequestUrl,
  2020. data: "glossary_name="+is_glossary_name,
  2021. success: function(data) {
  2022. show_description.html(data);
  2023. show_dialog.dialog("open");
  2024. }
  2025. });
  2026. });
  2027. }
  2028. if (type == 'fix_links') {
  2029. $(document).ready(function() {
  2030. var objects = $("iframe").contents().find('object');
  2031. var pathname = location.pathname;
  2032. var coursePath = pathname.substr(0, pathname.indexOf('/main/'));
  2033. var url = "http://"+location.host + coursePath+"/courses/proxy.php?";
  2034. objects.each(function (value, obj) {
  2035. var dialogId = this.id +'_dialog';
  2036. var openerId = this.id +'_opener';
  2037. var link = '<a id="'+openerId+'" href="#" class="generated btn">'+
  2038. '<div style="text-align: center"><img src="<?php echo Display::returnIconPath('play-circle-8x.png'); ?>"/><br />If video does not work, try clicking here.</div></a>';
  2039. var embed = $("iframe").contents().find("#"+this.id).find('embed').first();
  2040. var hasHttp = embed.attr('src').indexOf("http");
  2041. if (hasHttp < 0) {
  2042. return true;
  2043. }
  2044. var height = embed.attr('height');
  2045. var width = embed.attr('width');
  2046. var src = embed.attr('src').replace('https', 'http');
  2047. var completeUrl = url + 'width='+embed.attr('width')+
  2048. '&height='+height+
  2049. '&id='+this.id+
  2050. '&flashvars='+encodeURIComponent(embed.attr('flashvars'))+
  2051. '&src='+src+
  2052. '&width='+width;
  2053. var iframe = '<iframe ' +
  2054. 'style="border: 0px;" width="100%" height="100%" ' +
  2055. 'src="'+completeUrl+
  2056. '">' +
  2057. '</iframe>';
  2058. $("iframe").contents().find("#"+this.id).append(link + '<br />');
  2059. $("iframe").contents().find('#' + openerId).click(function() {
  2060. var w = window.open(completeUrl, "Video", "width="+width+", "+"height="+height+"");
  2061. w = window.document.title = 'Video';
  2062. });
  2063. });
  2064. var iframes = $("iframe").contents().find('iframe');
  2065. iframes.each(function (value, obj) {
  2066. var randLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
  2067. var uniqid = randLetter + Date.now();
  2068. var openerId = uniqid +'_opener';
  2069. var link = '<a id="'+openerId+'" class="generated" href="#">Open website <img src="<?php echo Display::returnIconPath('link-external.png'); ?>"/></a>';
  2070. var embed = $(this);
  2071. var height = embed.attr('height');
  2072. var width = embed.attr('width');
  2073. var src = embed.attr('src');
  2074. var completeUrl = url + 'width='+embed.attr('width')+
  2075. '&height='+height+
  2076. '&type=iframe'+
  2077. '&id='+uniqid+
  2078. '&src='+src+
  2079. '&width='+width;
  2080. var result = $("iframe").contents().find('#'+openerId);
  2081. var n = src.indexOf("youtube.com");
  2082. if (n > 0) {
  2083. return true;
  2084. }
  2085. if (result.length == 0) {
  2086. if (embed.prev().attr('class') != 'generated') {
  2087. $(this).parent().prepend(link + '<br />');
  2088. $("iframe").contents().find('#' + openerId).click(function() {
  2089. width = 1280;
  2090. height = 640;
  2091. var win = window.open(completeUrl, "Video", "width=" + width + ", " + "height=" + height + "");
  2092. win.document.title = 'Video';
  2093. });
  2094. }
  2095. }
  2096. });
  2097. var anchors = $("iframe").contents().find('a').not('.generated');
  2098. anchors.each(function (value, obj) {
  2099. if ($(this).next().attr('class') != 'generated') {
  2100. var content = $(this).html();
  2101. content = content.replace('<br />', '');
  2102. content = content.replace('<br>', '');
  2103. content = $.trim(content);
  2104. if (content == '') {
  2105. return true;
  2106. }
  2107. if ($(this).attr('href')) {
  2108. var hasLocalhost = $(this).attr('href').indexOf(location.host);
  2109. if (hasLocalhost > 0) {
  2110. return true;
  2111. }
  2112. var hasJs = $(this).attr('href').indexOf('javascript');
  2113. if (hasJs >= 0) {
  2114. return true;
  2115. }
  2116. }
  2117. if ($(this).attr('class')) {
  2118. var hasAccordion = $(this).attr('class').indexOf('accordion-toggle');
  2119. if (hasAccordion >= 0) {
  2120. return true;
  2121. }
  2122. }
  2123. var src = $(this).attr('href');
  2124. src = url+'&type=link&src='+src;
  2125. src = src.replace('https', 'http');
  2126. $(this).attr('href', src);
  2127. var myAnchor = $('<a><img src="<?php echo Display::returnIconPath('link-external.png'); ?>"/></a>').attr("href", src).attr('target', '_blank').attr('class', 'generated');
  2128. $(this).after(myAnchor);
  2129. $(this).after('-');
  2130. }
  2131. });
  2132. });
  2133. }
  2134. }
  2135. }