scorm_api.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. <?php // $Id: scorm_api.php 21162 2009-06-01 16:18:46Z yannoo $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * API event handler functions for Scorm 1.1 and 1.2 and 1.3
  5. *
  6. * @author Denes Nagy <darkden@freemail.hu>
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @version v 1.0
  9. * @access public
  10. * @package dokeos.learnpath.scorm
  11. */
  12. /**
  13. * This script is divided into three sections.
  14. * The first section (below) is the initialisation part.
  15. * The second section is the SCORM object part
  16. * The third section defines the event handlers for Dokeos' internal messaging
  17. * and frames refresh
  18. */
  19. /*
  20. INIT SECTION
  21. */
  22. // if you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  23. // of Maritime Navigation when trying to execute this row
  24. // var result = api.LMSInitialize("");
  25. // get the error response : you are not authorized to call this function
  26. //flag to allow for anonymous user - needs to be set before global.inc.php
  27. $use_anonymous = true;
  28. require_once('back_compat.inc.php');
  29. require_once('learnpath.class.php');
  30. require_once('learnpathItem.class.php');
  31. require_once('scorm.class.php');
  32. // Is this needed? This is probabaly done in the header file
  33. //$_user = $_SESSION['_user'];
  34. $file = (empty($_SESSION['file'])?'':$_SESSION['file']);
  35. $oLP = unserialize($_SESSION['lpobject']);
  36. $oItem = $oLP->items[$oLP->current];
  37. if (!is_object($oItem)) {
  38. error_log('New LP - scorm_api - Could not load oItem item',0);
  39. exit;
  40. }
  41. $autocomplete_when_80pct = 0;
  42. /*
  43. * JavaScript Functions
  44. */
  45. ?>var scorm_logs=<?php echo ((empty($oLP->scorm_debug) or !api_is_course_admin())?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
  46. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  47. //logit_lms('scormfunctions.php included',0);
  48. // API Object initialization (eases access later on)
  49. function APIobject() {
  50. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  51. this.Initialize=LMSInitialize; //for Scorm 1.3
  52. this.LMSGetValue=LMSGetValue;
  53. this.GetValue=LMSGetValue;
  54. this.LMSSetValue=LMSSetValue;
  55. this.SetValue=LMSSetValue;
  56. this.LMSCommit=LMSCommit;
  57. this.Commit=LMSCommit;
  58. this.LMSFinish=LMSFinish;
  59. this.Finish=LMSFinish;
  60. this.LMSGetLastError=LMSGetLastError;
  61. this.GetLastError=LMSGetLastError;
  62. this.LMSGetErrorString=LMSGetErrorString;
  63. this.GetErrorString=LMSGetErrorString;
  64. this.LMSGetDiagnostic=LMSGetDiagnostic;
  65. this.GetDiagnostic=LMSGetDiagnostic;
  66. this.Terminate=Terminate; //only in Scorm 1.3
  67. this.save_asset = lms_save_asset;
  68. this.void_save_asset = dokeos_void_save_asset;
  69. }
  70. // it is not sure that the scos use the above declarations. The following
  71. // multiple declarations are to make sure we have an API object for each type of
  72. // SCORM
  73. var API = new APIobject(); //for scorm 1.2
  74. var api = API;
  75. var API_1484_11 = new APIobject(); //for scorm 1.3
  76. var api_1484_11 = API_1484_11;
  77. // SCORM-specific Error codes
  78. var G_NoError = 0;
  79. var G_GeneralException = 101;
  80. var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
  81. var G_InvalidArgumentError = 201;
  82. var G_ElementCannotHaveChildren = 202;
  83. var G_ElementIsNotAnArray = 203;
  84. var G_NotInitialized = 301;
  85. var G_NotImplementedError = 401;
  86. var G_InvalidSetValue = 402;
  87. var G_ElementIsReadOnly = 403;
  88. var G_ElementIsWriteOnly = 404;
  89. var G_IncorrectDataType = 405;
  90. // SCORM-specific Error messages
  91. var G_NoErrorMessage = '';
  92. var G_GeneralExceptionMessage = 'General Exception';
  93. var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
  94. var G_InvalidArgumentErrorMessage = 'Invalid argument error';
  95. var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
  96. var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
  97. var G_NotInitializedMessage = 'Not initialized';
  98. var G_NotImplementedErrorMessage = 'Not implemented error';
  99. var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
  100. var G_ElementIsReadOnlyMessage = 'Element is read only';
  101. var G_ElementIsWriteOnlyMessage = 'Element is write only';
  102. var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
  103. var olms = new Object();
  104. //the last recorded error message was:
  105. olms.G_LastError = G_NoError ;
  106. olms.G_LastErrorMessage = 'No error';
  107. //this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages)
  108. olms.G_LastErrorString = 'No error';
  109. //these variables are provided for better control of the current status in the
  110. // SCORM exchange
  111. olms.commit = false;
  112. // informative array helping to select variables to save, later on
  113. olms.scorm_variables = new Array(
  114. 'cmi.core.score.raw',
  115. 'cmi.core.score.max',
  116. 'cmi.core.score.min',
  117. 'cmi.core.lesson_location',
  118. 'cmi.core.lesson_status',
  119. 'cmi.completion_status',
  120. 'cmi.core.session_time',
  121. 'cmi.score.scaled',
  122. 'cmi.success_status',
  123. 'cmi.suspend_data',
  124. 'cmi.core.exit',
  125. 'interactions'
  126. );
  127. // manage variables to save or not
  128. olms.variable_to_send=new Array();
  129. // temporary list of variables (gets set to true when set through LMSSetValue)
  130. olms.updatable_vars_list=new Array();
  131. // Strictly scorm variables
  132. olms.score=<?php echo $oItem->get_score();?>;
  133. olms.max='<?php echo $oItem->get_max();?>';
  134. olms.min='<?php echo $oItem->get_min();?>';
  135. olms.lesson_status='<?php echo $oItem->get_status();?>';
  136. olms.session_time='<?php echo $oItem->get_scorm_time('js');?>';
  137. olms.suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  138. olms.lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  139. olms.total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  140. olms.mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  141. olms.launch_data = '<?php echo $oItem->get_launch_data();?>';
  142. olms.max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  143. olms.interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
  144. olms.item_objectives = new Array();
  145. olms.info_lms_item=new Array();
  146. // Dokeos internal variables (not SCORM)
  147. // olms.saved_lesson_status = 'not attempted';
  148. olms.lms_lp_id = <?php echo $oLP->get_id();?>;
  149. olms.lms_item_id = <?php echo $oItem->get_id();?>;
  150. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  151. olms.lms_initialized = 0;
  152. //olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  153. //olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  154. //olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  155. //if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  156. olms.lms_view_id = '<?php echo $oLP->get_view();?>';
  157. if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
  158. olms.lms_user_id = '<?php echo $_user['user_id'];?>';
  159. olms.lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  160. olms.lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  161. olms.lms_lp_type = '<?php echo $oLP->get_type();?>';
  162. olms.lms_item_type = '<?php echo $oItem->get_type();?>';
  163. olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
  164. olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  165. olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  166. olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  167. olms.asset_timer = 0;
  168. //Backup for old values
  169. //var olms.old_score = 0;
  170. //var old_max = 0;
  171. //var old_min = 0;
  172. //var old_lesson_status = '';
  173. //var old_session_time = '';
  174. //var old_suspend_data = '';
  175. //var olms.lms_old_item_id = 0;
  176. olms.execute_stats=false;
  177. // Initialize stuff when the page is loaded
  178. $(document).ready( function() {
  179. //
  180. olms.info_lms_item[0]='<?php echo $oItem->get_id();?>';
  181. olms.info_lms_item[1]='<?php echo $oItem->get_id();?>';
  182. $("iframe#content_id").load( function(){
  183. olms.info_lms_item[0]=olms.info_lms_item[1];
  184. <?php
  185. if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
  186. ?>
  187. if (olms.lms_lp_type == 2) { //Only scorm
  188. attach_glossary_into_scorm();
  189. }
  190. <?php
  191. }
  192. ?>
  193. });
  194. });
  195. /**
  196. * The following section represents a set of mandatory functions for SCORM
  197. */
  198. /**
  199. * Function called mandatorily by the SCORM content to start the SCORM comm
  200. * @return string 'true' or 'false'. Returning a string is mandatory (SCORM).
  201. */
  202. function LMSInitialize() { //this is the initialize function of all APIobjects
  203. /* load info for this new item by calling the js_api_refresh command in
  204. * the message frame. The message frame will update the JS variables by
  205. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  206. * and that kind of stuff, so when the content loads in the content frame
  207. * it will have all the correct variables set
  208. */
  209. olms.G_LastError = G_NoError ;
  210. olms.G_LastErrorMessage = 'No error';
  211. olms.lms_initialized=0;
  212. // if there are more parameters than ""
  213. if (arguments.length>1) {
  214. olms.G_LastError = G_InvalidArgumentError;
  215. olms.G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  216. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  217. return('false');
  218. } else {
  219. //reinit the list of modified variables
  220. reinit_updatable_vars_list();
  221. // Get LMS values for this item
  222. params = {
  223. 'lid': olms.lms_lp_id,
  224. 'uid': olms.lms_user_id,
  225. 'vid': olms.lms_view_id,
  226. 'iid': olms.lms_item_id
  227. };
  228. $.ajax({
  229. type: "POST",
  230. url: "lp_ajax_initialize.php",
  231. data: params,
  232. dataType: 'script',
  233. async: false
  234. });
  235. // log a more complete object dump when initializing, so we know what data hasn't been cleaned
  236. var log = '<br />item : '+ olms.lms_item_id
  237. + '<br />score : '+ olms.score
  238. + '<br />max : '+ olms.max
  239. + '<br />min : '+ olms.min
  240. + '<br />lesson_status : '+ olms.lesson_status
  241. + '<br />session_time : '+ olms.session_time
  242. + '<br />lesson_location : '+ olms.lesson_location
  243. + '<br />suspend_data : '+ olms.suspend_data
  244. + '<br />total_time : '+ olms.total_time
  245. + '<br />mastery_score : '+ olms.mastery_score
  246. + '<br />max_time_allowed: '+ olms.max_time_allowed+'<br />';
  247. logit_scorm('LMSInitialize()'+log,0);
  248. olms.lms_initialized=1;
  249. return('true');
  250. }
  251. }
  252. /**
  253. * Twin sister of LMSInitialize(). Only provided for backwards compatibility.
  254. */
  255. function Initialize()
  256. { //this is the initialize function of all APIobjects
  257. return LMSInitialize();
  258. }
  259. /**
  260. * Gets a value in the current SCORM context and returns it to the calling SCO
  261. * @param string The name of the value we want
  262. * @return string All return values must be string (see SCORM)
  263. */
  264. function LMSGetValue(param)
  265. {
  266. //logit_scorm("LMSGetValue('"+param+"')",1);
  267. olms.G_LastError = G_NoError ;
  268. olms.G_LastErrorMessage = 'No error';
  269. var result='';
  270. // the LMSInitialize is missing
  271. if (olms.lms_initialized == 0) {
  272. olms.G_LastError = G_NotInitialized;
  273. olms.G_LastErrorMessage = G_NotInitializedMessage;
  274. logit_scorm('LMSGetValue('+param+'):<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  275. return '';
  276. }
  277. //Dokeos does not support this SCO object properties
  278. if (param == 'cmi.student_preference.text' ||
  279. param == 'cmi.student_preference.language' ||
  280. param == 'cmi.student_preference.speed' ||
  281. param == 'cmi.student_preference.audio' ||
  282. param == 'cmi.student_preference._children' ||
  283. param == 'cmi.student_data.time_limit_action' ||
  284. param == 'cmi.comments' ||
  285. param == 'cmi.comments_from_lms' ) {
  286. // the value is not supported
  287. olms.G_LastError = G_NotImplementedError ;
  288. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  289. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  290. result = '';
  291. return result;
  292. }
  293. // ---- cmi.core._children
  294. if(param=='cmi.core._children' || param=='cmi.core_children'){
  295. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  296. }else if(param == 'cmi.core.entry'){
  297. // ---- cmi.core.entry
  298. if(olms.lms_item_core_exit=='none') {
  299. result='ab-initio';
  300. } else if(olms.lms_item_core_exit=='suspend') {
  301. result='resume';
  302. } else {
  303. result='';
  304. }
  305. }else if(param == 'cmi.core.exit'){
  306. // ---- cmi.core.exit
  307. result='';
  308. olms.G_LastError = G_ElementIsWriteOnly;
  309. }else if(param == 'cmi.core.session_time'){
  310. result='';
  311. olms.G_LastError = G_ElementIsWriteOnly;
  312. }else if(param == 'cmi.core.lesson_status'){
  313. // ---- cmi.core.lesson_status
  314. if(olms.lesson_status != '') {
  315. result=olms.lesson_status;
  316. } else {
  317. //result='not attempted';
  318. }
  319. }else if(param == 'cmi.core.student_id'){
  320. // ---- cmi.core.student_id
  321. result='<?php echo $_user['user_id']; ?>';
  322. }else if(param == 'cmi.core.student_name'){
  323. // ---- cmi.core.student_name
  324. <?php
  325. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  326. echo "result='$who';";
  327. ?>
  328. }else if(param == 'cmi.core.lesson_location'){
  329. // ---- cmi.core.lesson_location
  330. result=olms.lesson_location;
  331. }else if(param == 'cmi.core.total_time'){
  332. // ---- cmi.core.total_time
  333. result=olms.total_time;
  334. }else if(param == 'cmi.core.score._children'){
  335. // ---- cmi.core.score._children
  336. result='raw,min,max';
  337. }else if(param == 'cmi.core.score.raw'){
  338. // ---- cmi.core.score.raw
  339. result=olms.score;
  340. }else if(param == 'cmi.core.score.max'){
  341. // ---- cmi.core.score.max
  342. result=olms.max;
  343. }else if(param == 'cmi.core.score.min'){
  344. // ---- cmi.core.score.min
  345. result=olms.min;
  346. }else if(param == 'cmi.core.score'){
  347. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  348. result=olms.score;
  349. }else if(param == 'cmi.core.credit'){
  350. // ---- cmi.core.credit
  351. result = olms.lms_item_credit;
  352. }else if(param == 'cmi.core.lesson_mode'){
  353. // ---- cmi.core.lesson_mode
  354. result = olms.lms_item_lesson_mode;
  355. }else if(param == 'cmi.suspend_data'){
  356. // ---- cmi.suspend_data
  357. result = olms.suspend_data;
  358. }else if(param == 'cmi.launch_data'){
  359. // ---- cmi.launch_data
  360. result = olms.lms_item_launch_data;
  361. }else if(param == 'cmi.objectives._children'){
  362. // ---- cmi.objectives._children
  363. result = 'id,score,status';
  364. }else if(param == 'cmi.objectives._count'){
  365. // ---- cmi.objectives._count
  366. //result='<?php echo $oItem->get_view_count();?>';
  367. result = olms.item_objectives.length;
  368. }else if(param.substring(0,15)== 'cmi.objectives.'){
  369. var myres = '';
  370. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  371. {
  372. var obj_id = myres[1];
  373. var req_type = myres[2];
  374. if(olms.item_objectives[obj_id]==null)
  375. {
  376. if(req_type == 'id')
  377. {
  378. result = '';
  379. }else if(req_type == '_children'){
  380. result = 'id,score,status';
  381. }else if(req_type == 'score'){
  382. if(myres[3]==null)
  383. {
  384. result = '';
  385. olms.G_LastError = G_NotImplementedError;
  386. olms.G_LastErrorString = 'Not implemented yet';
  387. }else if (myres[3] == '._children'){
  388. result = 'raw,min,max'; //non-standard, added for NetG
  389. }else if (myres[3] == '.raw'){
  390. result = '';
  391. }else if (myres[3] == '.max'){
  392. result = '';
  393. }else if (myres[3] == '.min'){
  394. result = '';
  395. }else{
  396. result = '';
  397. olms.G_LastError = G_NotImplementedError;
  398. olms.G_LastErrorString = 'Not implemented yet';
  399. }
  400. }else if(req_type == 'status'){
  401. result = 'not attempted';
  402. }
  403. }
  404. else
  405. {
  406. //the object is not null
  407. if(req_type == 'id')
  408. {
  409. result = olms.item_objectives[obj_id][0];
  410. }else if(req_type == '_children'){
  411. result = 'id,score,status';
  412. }else if(req_type == 'score'){
  413. if(myres[3]==null)
  414. {
  415. result = '';
  416. olms.G_LastError = G_NotImplementedError;
  417. olms.G_LastErrorString = 'Not implemented yet';
  418. }else if (myres[3] == '._children'){
  419. result = 'raw,min,max'; //non-standard, added for NetG
  420. }else if (myres[3] == '.raw'){
  421. if(olms.item_objectives[obj_id][2] != null)
  422. {
  423. result = olms.item_objectives[obj_id][2];
  424. }else{
  425. result = '';
  426. }
  427. }else if (myres[3] == '.max'){
  428. if(olms.item_objectives[obj_id][3] != null)
  429. {
  430. result = olms.item_objectives[obj_id][3];
  431. }else{
  432. result = '';
  433. }
  434. }else if (myres[3] == '.min'){
  435. if(olms.item_objectives[obj_id][4] != null)
  436. {
  437. result = olms.item_objectives[obj_id][4];
  438. }else{
  439. result = '';
  440. }
  441. }else{
  442. result = '';
  443. olms.G_LastError = G_NotImplementedError;
  444. olms.G_LastErrorString = 'Not implemented yet';
  445. }
  446. }else if(req_type == 'status'){
  447. if(olms.item_objectives[obj_id][1] != null)
  448. {
  449. result = olms.item_objectives[obj_id][1];
  450. }else{
  451. result = 'not attempted';
  452. }
  453. }
  454. }
  455. }
  456. }else if(param == 'cmi.student_data._children'){
  457. // ---- cmi.student_data._children
  458. result = 'mastery_score,max_time_allowed';
  459. }else if(param == 'cmi.student_data.mastery_score'){
  460. // ---- cmi.student_data.mastery_score
  461. result = olms.mastery_score;
  462. }else if(param == 'cmi.student_data.max_time_allowed'){
  463. // ---- cmi.student_data.max_time_allowed
  464. result = olms.max_time_allowed;
  465. }else if(param == 'cmi.interactions._count'){
  466. // ---- cmi.interactions._count
  467. result = olms.interactions.length;
  468. }else if(param == 'cmi.interactions._children'){
  469. // ---- cmi.interactions._children
  470. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  471. }else{
  472. // ---- anything else
  473. // Invalid argument error
  474. olms.G_LastError = G_InvalidArgumentError ;
  475. olms.G_LastErrorString = G_InvalidArgumentErrorMessage;
  476. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  477. result = '';
  478. return result;
  479. }
  480. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  481. return result;
  482. }
  483. /**
  484. * Twin sister of LMSGetValue(). Only provided for backwards compatibility.
  485. */
  486. function GetValue(param) {
  487. return LMSGetValue(param);
  488. }
  489. /**
  490. * Sets a SCORM variable's value through a call from the SCO.
  491. * @param string The SCORM variable's name
  492. * @param string The SCORM variable's new value
  493. * @param string 'true','false' or an error code
  494. */
  495. function LMSSetValue(param, val) {
  496. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  497. olms.commit = true; //value has changed, need to re-commit
  498. olms.G_LastError = G_NoError ;
  499. olms.G_LastErrorMessage = 'No error';
  500. return_value = 'false';
  501. if( param == "cmi.core.score.raw" ) {
  502. olms.score= val;
  503. olms.updatable_vars_list['cmi.core.score.raw']=true;
  504. return_value='true';
  505. } else if ( param == "cmi.core.score.max" ) {
  506. olms.max = val;
  507. olms.updatable_vars_list['cmi.core.score.max']=true;
  508. return_value='true';
  509. } else if ( param == "cmi.core.score.min" ) {
  510. olms.min = val;
  511. olms.updatable_vars_list['cmi.core.score.min']=true;
  512. return_value='true';
  513. } else if ( param == "cmi.core.lesson_location" ) {
  514. olms.lesson_location = val;
  515. olms.updatable_vars_list['cmi.core.lesson_location']=true;
  516. return_value='true';
  517. } else if ( param == "cmi.core.lesson_status" ) {
  518. olms.lesson_status = val;
  519. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  520. return_value='true';
  521. } else if ( param == "cmi.completion_status" ) {
  522. olms.lesson_status = val;
  523. olms.updatable_vars_list['cmi.completion_status']=true;
  524. return_value='true'; //1.3
  525. } else if ( param == "cmi.core.session_time" ) {
  526. olms.session_time = val;
  527. olms.updatable_vars_list['cmi.core.session_time']=true;
  528. return_value='true';
  529. } else if ( param == "cmi.score.scaled") { //1.3
  530. if(val<=1 && val>=-1) {
  531. olms.score = val ;
  532. olms.updatable_vars_list['cmi.score.scaled']=true;
  533. return_value='true';
  534. } else {
  535. return_value='false';
  536. }
  537. } else if ( param == "cmi.success_status" ) {
  538. success_status = val;
  539. olms.updatable_vars_list['cmi.success_status']=true;
  540. return_value='true'; //1.3
  541. } else if ( param == "cmi.suspend_data" ) {
  542. olms.suspend_data = val;
  543. olms.updatable_vars_list['cmi.suspend_data']=true;
  544. return_value='true';
  545. } else if ( param == "cmi.core.exit" ) {
  546. olms.lms_item_core_exit = val;
  547. olms.updatable_vars_list['cmi.core.exit']=true;
  548. return_value='true';
  549. } else if ( param == "cmi.core.student_id" ) {
  550. olms.G_LastError = G_ElementIsReadOnly;
  551. } else if ( param == "cmi.core.student_name" ) {
  552. olms.G_LastError = G_ElementIsReadOnly;
  553. } else if ( param == "cmi.core.credit" ) {
  554. olms.G_LastError = G_ElementIsReadOnly;
  555. } else if ( param == "cmi.core.entry" ) {
  556. olms.G_LastError = G_ElementIsReadOnly;
  557. } else if ( param == "cmi.core.total_time" ) {
  558. olms.G_LastError = G_ElementIsReadOnly;
  559. } else if ( param == "cmi.core.lesson_mode" ) {
  560. olms.G_LastError = G_ElementIsReadOnly;
  561. } else if ( param == "cmi.comments_from_lms" ) {
  562. olms.G_LastError = G_ElementIsReadOnly;
  563. } else if ( param == "cmi.student_data.time_limit_action" ) {
  564. olms.G_LastError = G_ElementIsReadOnly;
  565. } else if ( param == "cmi.student_data.mastery_score" ) {
  566. olms.G_LastError = G_ElementIsReadOnly;
  567. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  568. olms.G_LastError = G_ElementIsReadOnly;
  569. } else if ( param == "cmi.student_preference._children" ) {
  570. olms.G_LastError = G_ElementIsReadOnly;
  571. } else if ( param == "cmi.launch_data" ) {
  572. olms.G_LastError = G_ElementIsReadOnly;
  573. } else {
  574. var myres = new Array();
  575. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  576. olms.updatable_vars_list['interactions']=true;
  577. elem_id = myres[1];
  578. if(elem_id > olms.interactions.length) //interactions setting should start at 0
  579. {
  580. /*
  581. olms.G_LastError = G_InvalidArgumentError;
  582. olms.G_LastErrorString = 'Invalid argument (interactions)';
  583. return_value = false;
  584. */
  585. olms.interactions[0] = ['0','','','','','','',''];
  586. }
  587. if(olms.interactions[elem_id] == null){
  588. olms.interactions[elem_id] = ['','','','','','','',''];
  589. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  590. olms.interactions[elem_id][4] = new Array();
  591. }
  592. elem_attrib = myres[2];
  593. switch(elem_attrib) {
  594. case "id":
  595. olms.interactions[elem_id][0] = val;
  596. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  597. return_value='true';
  598. break;
  599. case "time":
  600. olms.interactions[elem_id][2] = val;
  601. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  602. return_value='true';
  603. break;
  604. case "type":
  605. olms.interactions[elem_id][1] = val;
  606. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  607. return_value='true';
  608. break;
  609. case "correct_responses":
  610. //do nothing yet
  611. olms.interactions[elem_id][4].push(val);
  612. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  613. return_value='true';
  614. break;
  615. case "weighting":
  616. olms.interactions[elem_id][3] = val;
  617. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  618. return_value='true';
  619. break;
  620. case "student_response":
  621. olms.interactions[elem_id][5] = ''+val;
  622. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  623. return_value='true';
  624. break;
  625. case "result":
  626. olms.interactions[elem_id][6] = val;
  627. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  628. return_value='true';
  629. break;
  630. case "latency":
  631. olms.interactions[elem_id][7] = val;
  632. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  633. return_value='true';
  634. break;
  635. default:
  636. olms.G_LastError = G_NotImplementedError;
  637. olms.G_LastErrorString = 'Not implemented yet';
  638. }
  639. }else if(param.substring(0,15)== 'cmi.objectives.'){
  640. var myres = '';
  641. olms.updatable_vars_list['objectives']=true;
  642. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  643. {
  644. obj_id = myres[1];
  645. if(obj_id > olms.item_objectives.length) //objectives setting should start at 0
  646. {
  647. olms.G_LastError = G_InvalidArgumentError;
  648. olms.G_LastErrorString = 'Invalid argument (objectives)';
  649. return_value = false;
  650. }
  651. else
  652. {
  653. req_type = myres[2];
  654. if(obj_id == null || obj_id == '')
  655. {
  656. ;//do nothing
  657. }
  658. else
  659. {
  660. if(olms.item_objectives[obj_id]==null)
  661. {
  662. olms.item_objectives[obj_id] = ['','','','',''];
  663. }
  664. if( req_type == "id" ) {
  665. //olms.item_objectives[obj_id][0] = val.substring(51,57);
  666. olms.item_objectives[obj_id][0] = val;
  667. logit_scorm("Objective "+obj_id+"'s id updated",2);
  668. return_value = 'true';
  669. } else if ( req_type == "score" ) {
  670. if (myres[3] == '._children'){
  671. return_value = '';
  672. olms.G_LastError = G_InvalidSetValue;
  673. olms.G_LastErrorString = 'Invalid set value, element is a keyword';
  674. }else if (myres[3] == '.raw'){
  675. olms.item_objectives[obj_id][2] = val;
  676. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  677. return_value = 'true';
  678. }else if (myres[3] == '.max'){
  679. olms.item_objectives[obj_id][3] = val;
  680. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  681. return_value = 'true';
  682. }else if (myres[3] == '.min'){
  683. olms.item_objectives[obj_id][4] = val;
  684. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  685. return_value = 'true';
  686. }else{
  687. return_value = '';
  688. olms.G_LastError = G_NotImplementedError;
  689. olms.G_LastErrorString = 'Not implemented yet';
  690. }
  691. } else if ( req_type == "status" ) {
  692. olms.item_objectives[obj_id][1] = val;
  693. logit_scorm("Objective "+obj_id+"'s status updated",2);
  694. return_value = 'true';
  695. } else {
  696. olms.G_LastError = G_NotImplementedError;
  697. olms.G_LastErrorString = 'Not implemented yet';
  698. }
  699. }
  700. }
  701. }
  702. }else{
  703. olms.G_LastError = G_NotImplementedError;
  704. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  705. }
  706. }
  707. <?php
  708. if ($oLP->force_commit == 1){
  709. echo " var mycommit = LMSCommit('force');";
  710. }
  711. ?>
  712. return(return_value);
  713. }
  714. /**
  715. * Twin sister of LMSSetValue(). Only provided for backwards compatibility.
  716. */
  717. function SetValue(param, val) {
  718. return LMSSetValue(param, val);
  719. }
  720. /**
  721. * Saves the current data from JS memory to the LMS database
  722. * @param string The origin of the call to save the data ('commit','finish', 'unload' or 'terminate')
  723. * @note origin actually seems deprecated now
  724. */
  725. function savedata(origin) {
  726. //origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
  727. if ((olms.lesson_status != 'completed') && (olms.lesson_status != 'passed') && (olms.mastery_score >=0) && (olms.score >= olms.mastery_score)) {
  728. olms.lesson_status = 'passed';
  729. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  730. } else if( (olms.mastery_score < 0) && (olms.lms_lp_type != '2') && ( olms.lesson_status == 'incomplete') && (olms.score >= (0.8*olms.max) ) ) {
  731. //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  732. <?php if ($autocomplete_when_80pct){ ?>
  733. olms.lesson_status = 'completed';
  734. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  735. <?php }?>
  736. ;
  737. } else {
  738. /* DEPRECATED
  739. * See notes in switch_item for why this has been disabled
  740. if ((origin== 'finish' || origin == 'unload') && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'failed' && olms.lesson_status != 'incomplete') {
  741. // The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable:
  742. // Upon receiving the LMSFinish() call or the user navigates away,
  743. // the LMS should set the cmi.core.lesson_status for the SCO to 'completed'
  744. logit_lms('the LMS did saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1);
  745. if (olms.mastery_score && olms.mastery_score!= '' && olms.score && olms.score != '') {
  746. if (olms.score >= olms.mastery_score) {
  747. olms.lesson_status = 'passed';
  748. } else {
  749. olms.lesson_status = 'failed';
  750. }
  751. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  752. } else if (olms.mastery_score && olms.mastery_score!= '') {
  753. olms.lesson_status = 'completed';
  754. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  755. }
  756. }
  757. */
  758. }
  759. logit_lms('saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1);
  760. old_item_id=olms.info_lms_item[0];
  761. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
  762. //olms.info_lms_item[0] is old_item_id and olms.info_lms_item[1] is current_item_id
  763. olms.info_lms_item[1]=olms.lms_item_id;
  764. if(olms.item_objectives.length>0) {
  765. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,old_item_id,olms.item_objectives);
  766. }
  767. olms.execute_stats=false;
  768. //clean array
  769. olms.variable_to_send=new Array();
  770. }
  771. /**
  772. * Send the Commit signal to the LMS (save the data for this element without
  773. * closing the current process)
  774. * From SCORM 1.2 RTE: If the API Adapter is caching values received from the
  775. * SCO via an LMSSetValue(), this call requires that any values not yet
  776. * persisted by the LMS be persisted.
  777. * @param string Must be empty string for conformance with SCORM 1.2
  778. */
  779. function LMSCommit(val) {
  780. logit_scorm('LMSCommit()',0);
  781. olms.G_LastError = G_NoError ;
  782. olms.G_LastErrorMessage = 'No error';
  783. savedata('commit');
  784. reinit_updatable_vars_list();
  785. //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
  786. return('true');
  787. }
  788. /**
  789. * Twin sister of LMSCommit(). Only provided for backwards compatibility.
  790. */
  791. function Commit(val) {
  792. return LMSCommit(val);
  793. }
  794. /**
  795. * Send the closure signal to the LMS. This saves the data and closes the current SCO.
  796. * From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
  797. * longer needs to communicate with the LMS, if it successfully called
  798. * LMSInitialize at any previous point. This call signifies two things:
  799. * 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
  800. * 2.The SCO has finished communicating with the LMS.
  801. * @param string
  802. */
  803. function LMSFinish(val) {
  804. olms.G_LastError = G_NoError ;
  805. olms.G_LastErrorMessage = 'No error';
  806. // if olms.commit == false, then the SCORM didn't ask for a commit, so we
  807. // should at least report that
  808. if (( olms.commit == false )) {
  809. logit_scorm('LMSFinish() (no LMSCommit())',1);
  810. }
  811. //if ( olms.commit == true ) {
  812. logit_scorm('LMSFinish() called',1);
  813. savedata('finish');
  814. olms.commit = false;
  815. //}
  816. //reinit the list of modified variables
  817. reinit_updatable_vars_list()
  818. return('true');
  819. }
  820. /**
  821. * Twin sister of LMSFinish(). Only provided for backwards compatibility.
  822. */
  823. function Finish(val) {
  824. return LMSFinish(val);
  825. }
  826. /**
  827. * Returns the last error code as a string
  828. * @return string Error code
  829. */
  830. function LMSGetLastError() {
  831. logit_scorm('LMSGetLastError()',1);
  832. return(olms.G_LastError.toString());
  833. }
  834. /**
  835. * Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
  836. */
  837. function GetLastError() {
  838. return LMSGetLastError();
  839. }
  840. /**
  841. * Returns the last error code literal for a given error code
  842. * @param int Error code
  843. * @return string Last error
  844. */
  845. function LMSGetErrorString(errCode){
  846. logit_scorm('LMSGetErrorString()',1);
  847. return(olms.G_LastErrorString);
  848. }
  849. /**
  850. * Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
  851. */
  852. function GetErrorString(errCode){
  853. return LMSGetErrorString(errCode);
  854. }
  855. /**
  856. * Returns a more explanatory, full English, error message
  857. * @param int Error code
  858. * @return string Diagnostic
  859. */
  860. function LMSGetDiagnostic(errCode){
  861. logit_scorm('LMSGetDiagnostic()',1);
  862. return(API.LMSGetLastError());
  863. }
  864. /**
  865. * Twin sister of LMSGetDiagnostic(). Only provided for backwards compatibility.
  866. */
  867. function GetDiagnostic(errCode){
  868. return LMSGetDiagnostic(errCode);
  869. }
  870. /**
  871. * Acts as a "commit"
  872. * This function is not standard SCORM 1.2 and is probably deprecated in all
  873. * meanings of the term.
  874. * @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
  875. */
  876. function Terminate()
  877. {
  878. if (olms.lms_initialized == 0) {
  879. olms.G_LastError = G_NotInitialized;
  880. olms.G_LastErrorMessage = G_NotInitializedMessage;
  881. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  882. return('false');
  883. } else {
  884. logit_scorm('Terminate()',0);
  885. olms.G_LastError = G_NoError ;
  886. olms.G_LastErrorMessage = 'No error';
  887. olms.commit = true;
  888. savedata('terminate');
  889. return ('true');
  890. }
  891. }
  892. /**
  893. * LMS-specific code that deals with event handling and inter-frames
  894. * messaging/refreshing.
  895. * Note that from now on, the LMS JS code in this library will act as
  896. * a controller, of the MVC pattern, and receive all requests for frame
  897. * updates, then redispatch to any frame concerned.
  898. */
  899. /**
  900. * Defining the AJAX-object class to be made available from other frames
  901. */
  902. function XAJAXobject() {
  903. this.xajax_switch_item_details=xajax_switch_item_details;
  904. this.switch_item=switch_item;
  905. this.xajax_save_objectives=xajax_save_objectives;
  906. this.xajax_save_item = xajax_save_item;
  907. }
  908. /**
  909. * It is not sure that the SCOs use the above declarations
  910. */
  911. oXAJAX = new XAJAXobject();
  912. oxajax = new XAJAXobject();
  913. /**
  914. * Cross-browser event handling by Scott Andrew
  915. * @param element Element that needs an event attached
  916. * @param string Event type (load, unload, click, keyDown, ...)
  917. * @param string Function name (the event handler)
  918. * @param string used in addEventListener
  919. */
  920. function addEvent(elm, evType, fn, useCapture){
  921. if(elm.addEventListener){
  922. elm.addEventListener(evType, fn, useCapture);
  923. return true;
  924. }else if (elm.attachEvent){
  925. var r = elm.attachEvent('on' + evType, fn);
  926. }else{
  927. elm['on'+evType] = fn;
  928. }
  929. }
  930. /**
  931. * Add listeners to the page objects. This has to be defined for
  932. * the current context as it acts on objects that should exist
  933. * on the page
  934. * possibly deprecated
  935. * @todo Try to use $(document).unload(lms_save_asset()) instead of the addEvent() method
  936. */
  937. function addListeners(){
  938. //exit if the browser doesn't support ID or tag retrieval
  939. logit_lms('Entering addListeners()',2);
  940. if(!document.getElementsByTagName){
  941. logit_lms("getElementsByTagName not available",2);
  942. return;
  943. }
  944. if(!document.getElementById){
  945. logit_lms("getElementById not available",2);
  946. return;
  947. }
  948. //assign event handlers to objects
  949. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  950. logit_lms('Dokeos LP or asset',2);
  951. //if this path is a Dokeos learnpath, then start manual save
  952. //when something is loaded in there
  953. addEvent(window,'unload',lms_save_asset,false);
  954. logit_lms('Added event listener on content_id for unload',2);
  955. }
  956. logit_lms('Quitting addListeners()',2);
  957. }
  958. /**
  959. * Load an item into the content frame:
  960. * - making sure the previous item status have been saved
  961. * - first updating the current item ID (to save the right item)
  962. * - updating the frame src
  963. * possibly deprecated
  964. */
  965. function load_item(item_id,url){
  966. if(document.getElementById('content_id')) {
  967. logit_lms('Loading item '+item_id,2);
  968. var cont_f = document.getElementById('content_id');
  969. if(cont_f.src){
  970. olms.lms_old_item_id = olms.lms_item_id;
  971. var lms_new_item_id = item_id;
  972. //load new content page into content frame
  973. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  974. lms_save_asset();
  975. }
  976. cont_f.src = url;
  977. update_toc('unhighlight',olms.lms_old_item_id);
  978. update_toc('highlight',olms.lms_old_item_id);
  979. return true;
  980. }
  981. logit_lms('cont_f.src has no properties',0);
  982. }
  983. logit_lms('content_id has no properties',0);
  984. return false;
  985. }
  986. /**
  987. * Save a Dokeos learnpath item's time and mark as completed upon
  988. * leaving it
  989. */
  990. function lms_save_asset(){
  991. // only for dokeos lps
  992. if (olms.execute_stats==true) {
  993. olms.execute_stats=false;
  994. } else {
  995. olms.execute_stats=true;
  996. }
  997. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  998. logit_lms('lms_save_asset',2);
  999. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1000. if(olms.item_objectives.length>0)
  1001. {
  1002. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
  1003. }
  1004. }
  1005. }
  1006. /**
  1007. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  1008. * Same function as lms_save_asset() but saves it with empty params
  1009. * to use values set from another side in the database. Only used by Dokeos quizzes.
  1010. * Also save the score locally because it hasn't been done through SetValue().
  1011. * Saving the status will be dealt with by the XAJAX function.
  1012. */
  1013. function dokeos_void_save_asset(myscore,mymax)
  1014. {
  1015. logit_lms('lms_save_asset',2);
  1016. olms.score = myscore;
  1017. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  1018. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, myscore, mymax);
  1019. }
  1020. /**
  1021. * Logs information about SCORM messages into the log frame
  1022. * @param string Message to log
  1023. * @param integer Priority (0 for top priority, 3 for lowest)
  1024. */
  1025. function logit_scorm(message,priority){
  1026. if(scorm_logs>=priority){
  1027. if($("#lp_log_name") && $("#log_content")){
  1028. $("#log_content").append("SCORM: " + message + "<br/>");
  1029. }
  1030. }
  1031. }
  1032. /**
  1033. * Logs information about LMS activity into the log frame
  1034. * @param string Message to log
  1035. * @param integer Priority (0 for top priority, 3 for lowest)
  1036. */
  1037. function logit_lms(message,priority){
  1038. if(lms_logs>=priority){
  1039. if ($("#lp_log_name") && $("#log_content")) {
  1040. $("#log_content").append("LMS: " + message + "<br />");
  1041. }
  1042. }
  1043. }
  1044. /**
  1045. * Update the Table Of Contents frame, by changing CSS styles, mostly
  1046. * @param string Action to be taken
  1047. * @param integer Item id to update
  1048. */
  1049. function update_toc(update_action,update_id,change_ids)
  1050. {
  1051. if (!change_ids || change_ids != 'no') {
  1052. change_ids = 'yes';
  1053. }
  1054. var myelem = $("#toc_"+update_id);
  1055. var myelemimg = $("#toc_img_"+update_id);
  1056. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  1057. if(update_id != 0)
  1058. {
  1059. switch(update_action)
  1060. {
  1061. case 'unhighlight':
  1062. if (update_id%2==0)
  1063. {
  1064. myelem.attr('class',"scorm_item_2");
  1065. }
  1066. else
  1067. {
  1068. myelem.attr('class',"scorm_item_1");
  1069. }
  1070. break;
  1071. case 'highlight':
  1072. if (change_ids=='yes') {
  1073. olms.lms_next_item = update_id;
  1074. olms.lms_previous_item = update_id;
  1075. }
  1076. myelem.attr('class',"scorm_item_highlight");
  1077. break;
  1078. case 'not attempted':
  1079. if( myelemimg.attr('src') != '../img/notattempted.gif') {
  1080. myelemimg.attr('src','../img/notattempted.gif');
  1081. myelemimg.attr('alt','n');
  1082. }
  1083. break;
  1084. case 'incomplete':
  1085. if( myelemimg.attr('src') != '../img/incomplete.gif') {
  1086. myelemimg.attr('src','../img/incomplete.gif');
  1087. myelemimg.attr('alt','i');
  1088. }
  1089. break;
  1090. case 'completed':
  1091. if( myelemimg.attr('src') != '../img/completed.gif') {
  1092. myelemimg.attr('src','../img/completed.gif');
  1093. myelemimg.attr('alt','c');
  1094. }
  1095. break;
  1096. case 'failed':
  1097. if( myelemimg.attr('src') != '../img/failed.gif') {
  1098. myelemimg.attr('src','../img/failed.gif');
  1099. myelemimg.attr('alt','f');
  1100. }
  1101. break;
  1102. case 'passed':
  1103. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'passed') {
  1104. myelemimg.attr('src','../img/completed.gif');
  1105. myelemimg.attr('alt','p');
  1106. }
  1107. break;
  1108. case 'browsed':
  1109. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'browsed') {
  1110. myelemimg.attr('src','../img/completed.gif');
  1111. myelemimg.attr('alt','b');
  1112. }
  1113. break;
  1114. default:
  1115. logit_lms('Update action unknown',2);
  1116. break;
  1117. }
  1118. }
  1119. return true;
  1120. }
  1121. /**
  1122. * Update the stats frame using a reload of the frame to avoid unsynched data
  1123. */
  1124. function update_stats() {
  1125. if (olms.execute_stats==true) {
  1126. try {
  1127. cont_f = document.getElementById('content_id');
  1128. cont_f.src="lp_controller.php?action=stats";
  1129. cont_f.reload();
  1130. } catch (e) {
  1131. return false;
  1132. }
  1133. }
  1134. olms.execute_stats=false;
  1135. }
  1136. /**
  1137. * Update the stats frame using a reload of the frame to avoid unsynched data
  1138. */
  1139. function update_stats_page()
  1140. {
  1141. var myframe = document.getElementById('content_id');
  1142. var mysrc = myframe.location.href;
  1143. if(mysrc == 'lp_controller.php?action=stats'){
  1144. if(myframe && myframe.src){
  1145. var mysrc = myframe.src;
  1146. myframe.src = mysrc;
  1147. }
  1148. // = mysrc; //refresh page
  1149. }
  1150. return true;
  1151. }
  1152. /**
  1153. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1154. * @param integer Number of completed items
  1155. * @param integer Number of items in total
  1156. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1157. */
  1158. function update_progress_bar(nbr_complete, nbr_total, mode)
  1159. {
  1160. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  1161. logit_lms('could update with data: '+olms.lms_lp_id+','+olms.lms_view_id+','+olms.lms_user_id,2);
  1162. if(mode == ''){mode='%';}
  1163. if(nbr_total == 0){nbr_total=1;}
  1164. var percentage = (nbr_complete/nbr_total)*100;
  1165. percentage = Math.round(percentage);
  1166. var pr_text = $("#progress_text");
  1167. var pr_full = $("#progress_img_full");
  1168. var pr_empty = $("#progress_img_empty");
  1169. pr_full.attr('width',percentage*1.2);
  1170. pr_empty.attr('width',(100-percentage)*1.2);
  1171. var mytext = '';
  1172. switch(mode){
  1173. case 'abs':
  1174. mytext = nbr_complete + '/' + nbr_total;
  1175. break;
  1176. case '%':
  1177. default:
  1178. mytext = percentage + '%';
  1179. break;
  1180. }
  1181. pr_text.html(mytext);
  1182. return true;
  1183. }
  1184. /**
  1185. * Analyses the variables that have been modified through this SCO's life and
  1186. * put them into an array for later shipping to lp_ajax_save_item.php
  1187. * @return array Array of SCO variables
  1188. */
  1189. function process_scorm_values () {
  1190. for (i=0;i<olms.scorm_variables.length;i++) {
  1191. if (olms.updatable_vars_list[olms.scorm_variables[i]]==true) {
  1192. olms.variable_to_send.push(olms.scorm_variables[i]);
  1193. }
  1194. }
  1195. return olms.variable_to_send;
  1196. }
  1197. /**
  1198. * Reinitializes the SCO's modified variables to an empty list.
  1199. * @return void
  1200. * @uses The global updatable_vars_list array to register this
  1201. */
  1202. function reinit_updatable_vars_list () {
  1203. for (i=0;i<olms.scorm_variables.length;i++) {
  1204. if (olms.updatable_vars_list[olms.scorm_variables[i]]==true) {
  1205. olms.updatable_vars_list[olms.scorm_variables[i]]=false;
  1206. }
  1207. }
  1208. olms.lesson_status='';
  1209. }
  1210. /**
  1211. * Function that handles the saving of an item and switching from an item to another.
  1212. * Once called, this function should be able to do the whole process of
  1213. * (1) saving the current item,
  1214. * (2) refresh all the values inside the SCORM API object,
  1215. * (3) open the new item into the content_id frame,
  1216. * (4) refresh the table of contents
  1217. * (5) refresh the progress bar (completion)
  1218. * (6) refresh the message frame
  1219. * @param integer Dokeos ID for the current item
  1220. * @param string This parameter can be a string specifying the next
  1221. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1222. */
  1223. function switch_item(current_item, next_item){
  1224. //backup these params
  1225. var orig_current_item = current_item;
  1226. var orig_next_item = next_item;
  1227. var orig_lesson_status = olms.lesson_status;
  1228. //(1) save the current item
  1229. logit_lms('Called switch_item with params '+olms.lms_item_id+' and '+next_item+'',0);
  1230. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.session_time == '0' || olms.session_time == '0:00:00'){
  1231. if (olms.lms_lp_type==1) {
  1232. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1233. } else {
  1234. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
  1235. }
  1236. if(olms.item_objectives.length>0) {
  1237. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
  1238. }
  1239. }else{
  1240. /**
  1241. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1242. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1243. * then some checks have to be done on score), we have to force a
  1244. * special commit here to avoid getting to the next element with a
  1245. * missing prerequisite. The 'onunload' event is treated with
  1246. * savedata_onunload(), and doesn't need to be triggered at any
  1247. * particular time, but here we are in the case of switching to another
  1248. * item, so this is particularly important to complete the element in
  1249. * time.
  1250. * However, this cannot be initiated from the JavaScript, mainly
  1251. * because another onunload event can be triggered by the SCO itself,
  1252. * which can set, for example, the status to incomplete while the
  1253. * status has already been set to "completed" by the hand-made
  1254. * savedata(unload) (and then the status cannot be "incompleted"
  1255. * anymore)
  1256. */
  1257. /*if (olms.lms_item_type=='sco' && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'incomplete' && olms.lesson_status != 'failed') {
  1258. // savedata('finish') treats the special condition and saves the
  1259. // new status to the database, so switch_item_details() enjoys the
  1260. // new status
  1261. savedata('finish');
  1262. }
  1263. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1264. */
  1265. }
  1266. olms.execute_stats=false;
  1267. //(2) Refresh all the values inside this SCORM API object - use AJAX
  1268. xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1269. if (olms.info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1270. olms.info_lms_item[0]=next_item;
  1271. olms.info_lms_item[1]=next_item;
  1272. } else {
  1273. if (next_item!='next' && next_item!='previous') {
  1274. olms.info_lms_item[0]=olms.info_lms_item[1];
  1275. olms.info_lms_item[1]=next_item;
  1276. }
  1277. }
  1278. if (olms.info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1279. olms.info_lms_item[0]=next_item;
  1280. olms.info_lms_item[1]=next_item;
  1281. } else {
  1282. if (next_item!='next' && next_item!='previous') {
  1283. olms.info_lms_item[0]=olms.info_lms_item[0];
  1284. olms.info_lms_item[1]=next_item;
  1285. }
  1286. }
  1287. //(3) open the new item in the content_id frame
  1288. switch(next_item){
  1289. case 'next':
  1290. next_item = olms.lms_next_item;
  1291. olms.info_lms_item[0]=olms.info_lms_item[1];
  1292. olms.info_lms_item[1]=olms.lms_next_item;
  1293. break;
  1294. case 'previous':
  1295. next_item = olms.lms_previous_item;
  1296. olms.info_lms_item[0]=olms.info_lms_item[1];
  1297. olms.info_lms_item[1]=olms.lms_previous_item;
  1298. break;
  1299. default:
  1300. break;
  1301. }
  1302. var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item;
  1303. var cont_f = $("#content_id");
  1304. <?php if($oLP->mode == 'fullscreen'){ ?>
  1305. cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1306. cont_f.onload=function(){
  1307. olms.info_lms_item[0]=olms.info_lms_item[1];
  1308. }
  1309. cont_f.onunload=function(){
  1310. olms.info_lms_item[0]=olms.info_lms_item[1];
  1311. }
  1312. <?php } else { ?>
  1313. cont_f.attr("src",mysrc);
  1314. <?php } ?>
  1315. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  1316. xajax_start_timer();
  1317. }
  1318. //(4) refresh the audio player if needed
  1319. $.ajax({
  1320. type: "POST",
  1321. url: "lp_nav.php",
  1322. data: "",
  1323. success: function(tmp_data) {
  1324. $("#media").html(tmp_data);
  1325. }
  1326. });
  1327. return true;
  1328. }
  1329. /**
  1330. * Save a specific item (with its interactions, if any) into the LMS through
  1331. * an AJAX call to lp_ajax_save_item.php.
  1332. * Because of the need to pass an array, we have to build the parameters
  1333. * manually into GET[].
  1334. * This function has a twin sister for SCO elements (xajax_save_item_scorm)
  1335. * which takes into account the interactions.
  1336. * @param int ID of the learning path (for the LMS)
  1337. * @param int ID of the user
  1338. * @param int ID of the view of this learning path
  1339. * @param int ID of the item currently looked at
  1340. * @param float Score
  1341. * @param float Max score
  1342. * @param float Min score
  1343. * @param string Lesson status
  1344. * @param string Current session time (in 'xxxx:xx:xx.xx' format)
  1345. * @param string Suspend data (maximum 255 chars)
  1346. * @param string Lesson location (which page we've reached in the SCO)
  1347. * @param array Interactions
  1348. * @param string Core exit value (up to 4096 chars)
  1349. * @return void
  1350. * @uses lp_ajax_save_item.php through an AJAX call
  1351. */
  1352. function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit) {
  1353. params='';
  1354. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1355. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1356. params += '&status='+lesson_status+'&t='+session_time;
  1357. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1358. params += '&core_exit='+lms_item_core_exit;
  1359. if ( olms.lms_lp_type==1) {
  1360. $.ajax({
  1361. type:"GET",
  1362. data: params,
  1363. url: "lp_ajax_save_item.php",
  1364. dataType: "script",
  1365. async: false
  1366. }
  1367. );
  1368. }
  1369. }
  1370. /**
  1371. * Save a SCORM item's variables, getting its SCORM values from
  1372. * updatable_vars_list. Takes interactions into account and considers whether
  1373. * variables have been modified or not.
  1374. * @param int ID of the learning path
  1375. * @param int ID of the user
  1376. * @param int ID of the view
  1377. * @param int ID of the item
  1378. * @return void
  1379. * @uses olms.updatable_vars_list
  1380. * @uses lp_ajax_save_item.php through an AJAX call
  1381. */
  1382. function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id) {
  1383. var is_interactions='false';
  1384. var params='';
  1385. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1386. var my_scorm_values=new Array();
  1387. my_scorm_values=process_scorm_values();
  1388. for (k=0;k<my_scorm_values.length;k++) {
  1389. if (my_scorm_values[k]=='cmi.core.session_time') {
  1390. params += '&t='+olms.session_time;
  1391. } else if (my_scorm_values[k]=='cmi.core.lesson_status' && olms.lesson_status!='') {
  1392. params += '&status='+olms.lesson_status;
  1393. } else if (my_scorm_values[k]=='cmi.core.score.raw') {
  1394. params += '&s='+olms.score;
  1395. } else if (my_scorm_values[k]=='cmi.core.score.max') {
  1396. params += '&max='+olms.max;
  1397. } else if (my_scorm_values[k]=='cmi.core.score.min') {
  1398. params += '&min='+olms.min;
  1399. } else if (my_scorm_values[k]=='cmi.core.lesson_location') {
  1400. params += '&loc='+olms.lesson_location;
  1401. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1402. } else if (my_scorm_values[k]=='cmi.score.scaled') {
  1403. } else if (my_scorm_values[k]=='cmi.suspend_data') {
  1404. params += '&suspend='+olms.suspend_data;
  1405. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1406. } else if (my_scorm_values[k]=='cmi.core.exit') {
  1407. params += '&core_exit='+olms.lms_item_core_exit;
  1408. }
  1409. if (my_scorm_values[k]=='interactions') {
  1410. is_interactions='true';
  1411. } else {
  1412. is_interactions='false';
  1413. }
  1414. }
  1415. if (is_interactions=='true') {
  1416. interact_string = '';
  1417. temp = '';
  1418. for (i in olms.interactions) {
  1419. interact_string += '&interact['+i+']=';
  1420. interact_temp = '[';
  1421. for (j in olms.interactions[i]) {
  1422. temp = olms.interactions[i][j];
  1423. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1424. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1425. while(temp.indexOf(',') >= 0){
  1426. temp = temp.replace(',','@.|@');
  1427. };
  1428. interact_temp +=temp+',';
  1429. }
  1430. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1431. // interact_string += encodeURIComponent(interact_temp);
  1432. interact_string += interact_temp;
  1433. }
  1434. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1435. params += interact_string;
  1436. is_interactions='false';
  1437. }
  1438. $.ajax({
  1439. type:"GET",
  1440. data: params,
  1441. url: "lp_ajax_save_item.php",
  1442. dataType: "script",
  1443. async: false
  1444. });
  1445. params='';
  1446. my_scorm_values = null;
  1447. }
  1448. /**
  1449. * Starts the timer with the server clock time.
  1450. * @return void
  1451. * @todo check the timer stuff really works
  1452. * @uses lp_ajax_start_timer.php
  1453. */
  1454. function xajax_start_timer() {
  1455. $.ajax({
  1456. type: "GET",
  1457. url: "lp_ajax_start_timer.php",
  1458. dataType: "script",
  1459. async: false
  1460. });
  1461. }
  1462. /**
  1463. * Save a specific item's objectives into the LMS through an Synch JAX call
  1464. * @param int ID of the learning path
  1465. * @param int ID of the user
  1466. * @param int ID of the view
  1467. * @param int ID of the item
  1468. * @param array SCO's recorded objectives
  1469. * @uses lp_ajax_save_objectives.php
  1470. */
  1471. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1472. params='';
  1473. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1474. params += '&iid='+lms_item_id;
  1475. obj_string = '';
  1476. for (i in item_objectives){
  1477. obj_string += '&objectives['+i+']=';
  1478. obj_temp = '[';
  1479. for (j in item_objectives[i]) {
  1480. obj_temp += item_objectives[i][j]+',';
  1481. }
  1482. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1483. obj_string += encodeURIComponent(obj_temp);
  1484. }
  1485. params += obj_string;
  1486. $.ajax({
  1487. type: "GET",
  1488. data: params,
  1489. url: "lp_ajax_save_objectives.php",
  1490. dataType: "script",
  1491. async: false
  1492. });
  1493. }
  1494. /**
  1495. * Switch between two items through an AJAX call.
  1496. * @param int ID of the learning path
  1497. * @param int ID of the user
  1498. * @param int ID of the view
  1499. * @param int ID of the item
  1500. * @param int ID of the next item
  1501. * @uses lp_ajax_switch_item.php
  1502. */
  1503. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1504. params = {
  1505. 'lid': lms_lp_id,
  1506. 'uid': lms_user_id,
  1507. 'vid': lms_view_id,
  1508. 'iid': lms_item_id,
  1509. 'next': next_item
  1510. };
  1511. $.ajax({
  1512. type: "POST",
  1513. data: params,
  1514. url: "lp_ajax_switch_item.php",
  1515. dataType: "script",
  1516. async: false
  1517. });
  1518. }
  1519. /**
  1520. * Add the "addListeners" function to the "onload" event of the window and
  1521. * start the timer if necessary (asset)
  1522. */
  1523. addEvent(window,'load',addListeners,false);
  1524. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  1525. xajax_start_timer();
  1526. }
  1527. /**
  1528. * Allow attach the glossary terms into html document of scorm. This has
  1529. * nothing to do with SCORM itself, and should not interfere w/ SCORM either.
  1530. * Added by Isaac flores
  1531. */
  1532. function attach_glossary_into_scorm() {
  1533. var f = $('#content_id')[0];
  1534. var doc = f.contentWindow ? f.contentWindow.document :
  1535. f.contentDocument ? f.contentDocument : f.document;
  1536. var $frame_content = $('body',doc);
  1537. var my_text=$frame_content.html();
  1538. my_protocol = location.protocol;
  1539. my_pathname=location.pathname;
  1540. work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
  1541. $.ajax({
  1542. contentType: "application/x-www-form-urlencoded",
  1543. beforeSend: function(object) {
  1544. },
  1545. type: "POST",
  1546. url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
  1547. data: "glossary_data=true",
  1548. success: function(datos) {
  1549. if (datos.length==0) {
  1550. return false;
  1551. }
  1552. data_terms=datos.split("[|.|_|.|-|.|]");
  1553. for (i=0;i<data_terms.length;i++) {
  1554. specific_terms=data_terms[i].split("__|__|");
  1555. var real_term = specific_terms[1];
  1556. var my_specific_terms = new RegExp('(^|)'+specific_terms[1]+'[^ ]?',"gi");
  1557. new_html=my_text.replace(my_specific_terms,function(m){return replace_complete_char(m)});
  1558. $frame_content.html(new_html);
  1559. my_text=$frame_content.html();
  1560. }
  1561. //mouse over event
  1562. $("iframe").contents().find('body').find('.glossary-ajax').mouseover(function() {
  1563. random_id=Math.round(Math.random()*100);
  1564. div_show_id="div_show_id"+random_id;
  1565. div_content_id="div_content_id"+random_id;
  1566. $(this).append("<div id="+div_show_id+" ><div id="+div_content_id+">&nbsp;</div></div>");
  1567. $("iframe").contents().find('body').find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;");
  1568. $("iframe").contents().find('body').find("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;");
  1569. notebook_id=$(this).attr("name");
  1570. data_notebook=notebook_id.split("link");
  1571. my_glossary_id=data_notebook[1];
  1572. $.ajax({
  1573. contentType: "application/x-www-form-urlencoded",
  1574. beforeSend: function(object) {
  1575. $("iframe").contents().find('body').find("div#"+div_content_id).html("<img src="+my_protocol+"//"+location.host+work_path+"/main/inc/lib/javascript/indicator.gif />");
  1576. },
  1577. type: "POST",
  1578. url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
  1579. data: "glossary_id="+my_glossary_id,
  1580. success: function(datos) {
  1581. $("iframe").contents().find('body').find("div#"+div_content_id).html(datos);
  1582. }
  1583. });
  1584. });
  1585. // mouse out event
  1586. $("iframe").contents().find('body').find('.glossary-ajax').mouseout(function(){
  1587. var current_element,
  1588. current_element=$(this);
  1589. div_show_id=current_element.find("div").attr("id");
  1590. $("iframe").contents().find('body').find("div#"+div_show_id).remove();
  1591. });
  1592. //Callback Helper
  1593. function replace_complete_char(m) {
  1594. var complete_term_pattern = new RegExp(real_term,"i");
  1595. var tag = m.replace(complete_term_pattern," <span class=\"glossary-ajax\" style='color:blue' name=\"link"+specific_terms[0]+"\">$&</span>");
  1596. return tag;
  1597. }
  1598. }
  1599. });
  1600. }