lp_ajax_save_objectives.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php //$id$
  2. /**
  3. * This script contains the server part of the xajax interaction process. The client part is located
  4. * in lp_api.php or other api's.
  5. * This is a first attempt at using xajax and AJAX in general, so the code might be a bit unsettling.
  6. * @package dokeos.learnpath
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. */
  9. /**
  10. * Script
  11. */
  12. //flag to allow for anonymous user - needs to be set before global.inc.php
  13. $use_anonymous = true;
  14. // name of the language file that needs to be included
  15. $language_file[] = 'learnpath';
  16. require_once('back_compat.inc.php');
  17. /**
  18. * Writes an item's new values into the database and returns the operation result
  19. * @param integer Learnpath ID
  20. * @param integer User ID
  21. * @param integer View ID
  22. * @param integer Item ID
  23. * @param array Objectives array
  24. */
  25. function save_objectives($lp_id,$user_id,$view_id,$item_id,$objectives=array())
  26. {
  27. global $_configuration;
  28. $debug=0;
  29. $return = '';
  30. if($debug>0){error_log('In xajax_save_objectives('.$lp_id.','.$user_id.','.$view_id.','.$item_id.',"'.(count($objectives)>0?count($objectives):'').'")',0);}
  31. //$objResponse = new xajaxResponse();
  32. require_once('learnpath.class.php');
  33. require_once('scorm.class.php');
  34. require_once('aicc.class.php');
  35. require_once('learnpathItem.class.php');
  36. require_once('scormItem.class.php');
  37. require_once('aiccItem.class.php');
  38. $mylp = '';
  39. if(isset($_SESSION['lpobject']))
  40. {
  41. if($debug>1){error_log('////$_SESSION[lpobject] is set',0);}
  42. $oLP =& unserialize($_SESSION['lpobject']);
  43. if(!is_object($oLP)){
  44. if($debug>2){error_log(print_r($oLP,true),0);}
  45. if($debug>2){error_log('////Building new lp',0);}
  46. unset($oLP);
  47. $code = api_get_course_id();
  48. $mylp = & new learnpath($code,$lp_id,$user_id);
  49. }else{
  50. if($debug>2){error_log('////Reusing session lp',0);}
  51. $mylp = & $oLP;
  52. }
  53. }
  54. $mylpi =& $mylp->items[$item_id];
  55. //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true),0);
  56. if(is_array($objectives) && count($objectives)>0){
  57. foreach($objectives as $index=>$objective){
  58. //error_log(__FILE__.' '.__LINE__.' '.$objectives[$index][0],0);
  59. $mylpi->add_objective($index,$objectives[$index]);
  60. }
  61. $mylpi->write_objectives_to_db();
  62. }
  63. //return $objResponse;
  64. return $return;
  65. }
  66. $objectives = array();
  67. if(isset($_GET['objectives'])) {
  68. if (is_array($_GET['objectives'])) {
  69. foreach($_GET['objectives'] as $idx=>$ob)
  70. {
  71. $objectives[$idx] = split(',',substr($ob,1,-1));
  72. if(!isset($objectives[$idx][4])){ //make sure there are 7 elements
  73. $objectives[$idx][4]='';
  74. }
  75. }
  76. }
  77. }
  78. echo save_objectives($_GET['lid'],$_GET['uid'],$_GET['vid'],$_GET['iid'],$objectives);