lp_ajax_save_objectives.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $app['template.show_footer'] = false;
  19. $app['template.show_header'] = false;
  20. $app['default_layout'] = 'default/layout/blank.tpl';
  21. /**
  22. * Writes an item's new values into the database and returns the operation result
  23. * @param integer Learnpath ID
  24. * @param integer User ID
  25. * @param integer View ID
  26. * @param integer Item ID
  27. * @param array Objectives array
  28. */
  29. function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array()) {
  30. global $_configuration;
  31. $debug = 0;
  32. $return = '';
  33. if ($debug > 0) { error_log('In xajax_save_objectives('.$lp_id.','.$user_id.','.$view_id.','.$item_id.',"'.(count($objectives) > 0 ? count($objectives) : '').'")', 0); }
  34. //$objResponse = new xajaxResponse();
  35. require_once 'learnpath.class.php';
  36. require_once 'scorm.class.php';
  37. require_once 'aicc.class.php';
  38. require_once 'learnpathItem.class.php';
  39. require_once 'scormItem.class.php';
  40. require_once 'aiccItem.class.php';
  41. $mylp = '';
  42. if (isset($_SESSION['lpobject'])) {
  43. if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
  44. $oLP =unserialize($_SESSION['lpobject']);
  45. if (!is_object($oLP)) {
  46. if ($debug > 2) { error_log(print_r($oLP,true), 0); }
  47. if ($debug > 2) { error_log('Building new lp', 0); }
  48. unset($oLP);
  49. $code = api_get_course_id();
  50. $mylp = new learnpath($code, $lp_id, $user_id);
  51. }else{
  52. if ($debug > 2) { error_log('Reusing session lp', 0); }
  53. $mylp = $oLP;
  54. }
  55. }
  56. $mylpi =& $mylp->items[$item_id];
  57. //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true), 0);
  58. if(is_array($objectives) && count($objectives)>0){
  59. foreach($objectives as $index=>$objective){
  60. //error_log(__FILE__.' '.__LINE__.' '.$objectives[$index][0], 0);
  61. $mylpi->add_objective($index,$objectives[$index]);
  62. }
  63. $mylpi->write_objectives_to_db();
  64. }
  65. //return $objResponse;
  66. return $return;
  67. }
  68. $objectives = array();
  69. if (isset($_REQUEST['objectives'])) {
  70. if (is_array($_REQUEST['objectives'])) {
  71. foreach ($_REQUEST['objectives'] as $idx => $ob) {
  72. $objectives[$idx] = split(',', substr($ob, 1, -1));
  73. if (!isset($objectives[$idx][4])) { // Make sure there are 7 elements.
  74. $objectives[$idx][4] = '';
  75. }
  76. }
  77. }
  78. }
  79. echo save_objectives($_REQUEST['lid'], $_REQUEST['uid'], $_REQUEST['vid'], $_REQUEST['iid'], $objectives);