PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/community/www/set_positions.php

https://github.com/svn2github/efront-lms
PHP | 90 lines | 68 code | 3 blank | 19 comment | 23 complexity | 8bdf6bfcc9861537851fa3fa0326c892 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. /**
  3. * Set positions of control panel elements
  4. *
  5. * This page is used to store the positions of the users' control panel elements
  6. *
  7. * @package eFront
  8. * @version 1.0
  9. */
  10. session_cache_limiter('none');
  11. session_start();
  12. $path = "../libraries/";
  13. /** Configuration file.*/
  14. include_once $path."configuration.php";
  15. try {
  16. $currentUser = EfrontUser :: checkUserAccess();
  17. } catch (Exception $e) {
  18. echo "<script>parent.location = 'index.php?logout=true&message=".urlencode($e -> getMessage().' ('.$e -> getCode().')')."&message_type=failure'</script>"; //This way the frameset will revert back to single frame, and the annoying effect of 2 index.php, one in each frame, will not happen
  19. exit;
  20. }
  21. try {
  22. if ($_SESSION['s_lessons_ID']) {
  23. $currentLesson = new EfrontLesson($_SESSION['s_lessons_ID']);
  24. } elseif ($_POST['lessons_ID']) {
  25. $currentLesson = new EfrontLesson($_POST['lessons_ID']);
  26. }
  27. if (isset($currentUser -> coreAccess['settings']) && $currentUser -> coreAccess['settings'] != 'change') {
  28. throw new Exception();
  29. }
  30. } catch (Exception $e) {
  31. eF_redirect("index.php?message=".urlencode(_UNAUTHORIZEDACCESS)."&message_type=failure");
  32. exit;
  33. }
  34. try {
  35. $roles = EfrontUser :: getRoles();
  36. if (isset($_POST['firstlist']) && isset($_POST['secondlist'])) {
  37. parse_str($_POST['firstlist']);
  38. parse_str($_POST['secondlist']);
  39. parse_str($_POST['visibility']);
  40. mb_internal_encoding('utf-8'); //This must be put here due to PHP bug #48697
  41. if ($visibility) {
  42. $positions = serialize(array('first' => array_unique($firstlist), 'second' => array_unique($secondlist), 'visibility' => $visibility));
  43. } else {
  44. $positions = serialize(array('first' => array_unique($firstlist), 'second' => array_unique($secondlist)));
  45. }
  46. //Dashboard positions
  47. if ($_POST['dashboard']) {
  48. eF_updateTableData("users", array('dashboard_positions' => $positions), "login='".($currentUser -> user['login'])."'");
  49. }
  50. //administrator control panel positions
  51. else if ($currentUser -> user['user_type'] == 'administrator' && !isset($_POST['lessons_ID'])) {
  52. EfrontConfiguration::setValue($currentUser -> user['login']."_positions", $positions);
  53. }
  54. //lesson control panel positions
  55. else {
  56. if (isset($_POST['set_default']) && ($currentUser -> user['user_type'] == 'administrator' || $roles[$currentLesson -> getRole($currentUser -> user['login'])] == 'professor')) {
  57. $currentLesson -> setOptions(array("default_positions" => $positions));
  58. $positions = serialize(array('first' => array_unique($firstlist), 'second' => array_unique($secondlist), 'visibility' => $visibility, 'update' => true));
  59. $lessonStudents = $currentLesson -> getUsers('student');
  60. if (sizeof($lessonStudents) > 0) {
  61. $users = implode("','", array_keys($lessonStudents));
  62. eF_updateTableData("users_to_lessons", array('positions' => $positions), "users_LOGIN in ('".$users."') and lessons_ID=".$currentLesson -> lesson['id']);
  63. }
  64. } else {
  65. if (!$visibility) {
  66. $result = eF_getTableData("users_to_lessons", "positions", "lessons_ID=".$currentLesson -> lesson['id']." AND users_LOGIN='".$currentUser -> user['login']."'");
  67. $result = unserialize($result[0]['positions']);
  68. $visibility = $result['visibility'];
  69. if (isset($result['visibility'])) {
  70. $positions = serialize(array('first' => array_unique($firstlist), 'second' => array_unique($secondlist), 'visibility' => $visibility));
  71. }
  72. }
  73. eF_updateTableData("users_to_lessons", array('positions' => $positions), "lessons_ID=".$currentLesson -> lesson['id']." AND users_LOGIN='".$currentUser -> user['login']."'");
  74. }
  75. }
  76. }
  77. } catch (Exception $e) {
  78. handleAjaxExceptions($e);
  79. }
  80. ?>