lp_ajax_save_objectives.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  11. * Code
  12. */
  13. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  14. $use_anonymous = true;
  15. // Name of the language file that needs to be included.
  16. $language_file[] = 'learnpath';
  17. require_once '../inc/global.inc.php';
  18. /**
  19. * Writes an item's new values into the database and returns the operation result
  20. * @param integer Learnpath ID
  21. * @param integer User ID
  22. * @param integer View ID
  23. * @param integer Item ID
  24. * @param array Objectives array
  25. */
  26. function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array()) {
  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. if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
  41. $oLP =unserialize($_SESSION['lpobject']);
  42. if (!is_object($oLP)) {
  43. if ($debug > 2) { error_log(print_r($oLP,true), 0); }
  44. if ($debug > 2) { error_log('Building new lp', 0); }
  45. unset($oLP);
  46. $code = api_get_course_id();
  47. $mylp = new learnpath($code, $lp_id, $user_id);
  48. }else{
  49. if ($debug > 2) { error_log('Reusing session lp', 0); }
  50. $mylp = $oLP;
  51. }
  52. }
  53. $mylpi =& $mylp->items[$item_id];
  54. //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true), 0);
  55. if(is_array($objectives) && count($objectives)>0){
  56. foreach($objectives as $index=>$objective){
  57. //error_log(__FILE__.' '.__LINE__.' '.$objectives[$index][0], 0);
  58. $mylpi->add_objective($index,$objectives[$index]);
  59. }
  60. $mylpi->write_objectives_to_db();
  61. }
  62. //return $objResponse;
  63. return $return;
  64. }
  65. $objectives = array();
  66. if (isset($_REQUEST['objectives'])) {
  67. if (is_array($_REQUEST['objectives'])) {
  68. foreach ($_REQUEST['objectives'] as $idx => $ob) {
  69. $objectives[$idx] = split(',', substr($ob, 1, -1));
  70. if (!isset($objectives[$idx][4])) { // Make sure there are 7 elements.
  71. $objectives[$idx][4] = '';
  72. }
  73. }
  74. }
  75. }
  76. echo save_objectives($_REQUEST['lid'], $_REQUEST['uid'], $_REQUEST['vid'], $_REQUEST['iid'], $objectives);