lp.ajax.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. api_protect_course_script(true);
  8. $action = $_REQUEST['a'];
  9. $course_id = api_get_course_int_id();
  10. $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
  11. switch ($action) {
  12. case 'add_lp_item':
  13. if (api_is_allowed_to_edit(null, true)) {
  14. if ($_SESSION['oLP']) {
  15. //Updating the lp.modified_on
  16. $_SESSION['oLP']->set_modified_on();
  17. echo $_SESSION['oLP']->add_item($_REQUEST['parent_id'], $_REQUEST['previous_id'], $_REQUEST['type'], $_REQUEST['id'], $_REQUEST['title'], null);
  18. }
  19. }
  20. break;
  21. case 'update_lp_item_order':
  22. if (api_is_allowed_to_edit(null, true)) {
  23. $new_order = $_POST['new_order'];
  24. $sections = explode('^', $new_order);
  25. $new_array = array();
  26. $i = 0;
  27. foreach ($sections as $items) {
  28. if (!empty($items)) {
  29. list($id, $parent_id) = explode('|', $items);
  30. $new_array[$i]['id'] = intval($id);
  31. $new_array[$i]['parent_id'] = intval($parent_id);
  32. $i++;
  33. }
  34. }
  35. $counter = 1;
  36. for ($i=0; $i < count($new_array); $i++) {
  37. $params = array();
  38. $id = $new_array[$i]['id'];
  39. if (empty($id)) {
  40. continue;
  41. }
  42. $parent_id = isset($new_array[$i]['parent_id']) ? $new_array[$i]['parent_id'] : 0;
  43. $params['display_order'] = $counter;
  44. $params['previous_item_id'] = isset($new_array[$i-1]) && isset($new_array[$i-1]['id']) ? $new_array[$i-1]['id'] : 0;
  45. $params['next_item_id'] = isset($new_array[$i+1]) && isset($new_array[$i+1]['id']) ? $new_array[$i+1]['id'] : 0;
  46. $params['parent_item_id'] = $parent_id;
  47. Database::update($tbl_lp_item, $params, array('id = ? AND c_id = ? '=> array(intval($id), $course_id)));
  48. $counter ++;
  49. }
  50. Display::display_confirmation_message(get_lang('Saved'));
  51. }
  52. break;
  53. default:
  54. echo '';
  55. }
  56. exit;