lp_ajax_save_objectives.php 2.9 KB

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