lp_ajax_save_objectives.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. {
  25. $debug = 0;
  26. $return = '';
  27. if ($debug > 0) {
  28. error_log('In xajax_save_objectives('.$lp_id.','.$user_id.','.$view_id.','.$item_id.',"'.(count($objectives) > 0 ? count($objectives) : '').'")', 0);
  29. }
  30. require_once 'learnpath.class.php';
  31. require_once 'scorm.class.php';
  32. require_once 'aicc.class.php';
  33. require_once 'learnpathItem.class.php';
  34. require_once 'scormItem.class.php';
  35. require_once 'aiccItem.class.php';
  36. $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
  37. $mylpi =& $mylp->items[$item_id];
  38. if (is_array($objectives) && count($objectives)>0){
  39. foreach ($objectives as $index=>$objective){
  40. $mylpi->add_objective($index,$objectives[$index]);
  41. }
  42. $mylpi->write_objectives_to_db();
  43. }
  44. return $return;
  45. }
  46. $objectives = array();
  47. if (isset($_REQUEST['objectives'])) {
  48. if (is_array($_REQUEST['objectives'])) {
  49. foreach ($_REQUEST['objectives'] as $idx => $ob) {
  50. $objectives[$idx] = explode(',', substr($ob, 1, -1));
  51. if (!isset($objectives[$idx][4])) {
  52. // Make sure there are 7 elements.
  53. $objectives[$idx][4] = '';
  54. }
  55. }
  56. }
  57. }
  58. echo save_objectives(
  59. $_REQUEST['lid'],
  60. $_REQUEST['uid'],
  61. $_REQUEST['vid'],
  62. $_REQUEST['iid'],
  63. $objectives
  64. );