scorm_api.php 87 KB

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