admin.ajax.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. api_protect_admin_script();
  7. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  8. switch ($action) {
  9. case 'user_exists':
  10. $user_info = api_get_user_info($_REQUEST['id']);
  11. if (empty($user_info)) {
  12. echo 0;
  13. } else {
  14. echo 1;
  15. }
  16. break;
  17. case 'find_coaches':
  18. $coaches = SessionManager::get_coaches_by_keyword($_REQUEST['tag']);
  19. $json_coaches = array();
  20. if (!empty($coaches)) {
  21. foreach ($coaches as $coach) {
  22. $json_coaches[] = array(
  23. 'key' => $coach['user_id'],
  24. 'value' => api_get_person_name($coach['firstname'], $coach['lastname'])
  25. );
  26. }
  27. }
  28. echo json_encode($json_coaches);
  29. break;
  30. case 'update_changeable_setting':
  31. $url_id = api_get_current_access_url_id();
  32. if (api_is_global_platform_admin() && $url_id == 1) {
  33. if (isset($_GET['id']) && !empty($_GET['id'])) {
  34. $params = array('variable = ? ' => array($_GET['id']));
  35. $data = api_get_settings_params($params);
  36. if (!empty($data)) {
  37. foreach ($data as $item) {
  38. $params = array('id' =>$item['id'], 'access_url_changeable' => $_GET['changeable']);
  39. api_set_setting_simple($params);
  40. }
  41. }
  42. echo '1';
  43. }
  44. }
  45. break;
  46. case 'version':
  47. echo version_check();
  48. exit;
  49. break;
  50. }
  51. /**
  52. * Displays either the text for the registration or the message that the installation is (not) up to date
  53. *
  54. * @return string html code
  55. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  56. * @version august 2006
  57. * @todo have a 6monthly re-registration
  58. */
  59. function version_check()
  60. {
  61. $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  62. $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable="registered" ';
  63. $result = Database::query($sql);
  64. $row = Database::fetch_array($result, 'ASSOC');
  65. // The site has not been registered yet.
  66. $return = '';
  67. if ($row['selected_value'] == 'false') {
  68. $return .= get_lang('VersionCheckExplanation');
  69. $return .= '<form class="well" action="'.api_get_path(WEB_CODE_PATH).'admin/index.php" id="VersionCheck" name="VersionCheck" method="post">';
  70. $return .= '<label class="checkbox"><input type="checkbox" name="donotlistcampus" value="1" id="checkbox" />'.get_lang('HideCampusFromPublicPlatformsList');
  71. $return .= '</label><button type="submit" class="btn btn-primary" name="Register" value="'.get_lang('EnableVersionCheck').'" id="register" >'.get_lang('EnableVersionCheck').'</button>';
  72. $return .= '</form>';
  73. check_system_version();
  74. } else {
  75. // site not registered. Call anyway
  76. $return .= check_system_version();
  77. }
  78. return $return;
  79. }
  80. /**
  81. * Check if the current installation is up to date
  82. * The code is borrowed from phpBB and slighlty modified
  83. * @author The phpBB Group <support@phpbb.com> (the code)
  84. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University (the modifications)
  85. * @author Yannick Warnier <ywarnier@beeznest.org> for the move to HTTP request
  86. * @copyright (C) 2001 The phpBB Group
  87. * @return string language string with some layout (color)
  88. */
  89. function check_system_version()
  90. {
  91. global $_configuration;
  92. $system_version = trim($_configuration['system_version']); // the chamilo version of your installation
  93. if (ini_get('allow_url_fopen') == 1) {
  94. // The number of courses
  95. $number_of_courses = Statistics::count_courses();
  96. // The number of users
  97. $number_of_users = Statistics::count_users();
  98. $number_of_active_users = Statistics::count_users(null, null, null, true);
  99. // The number of sessions
  100. $number_of_sessions = Statistics::count_sessions();
  101. $data = array(
  102. 'url' => api_get_path(WEB_PATH),
  103. 'campus' => api_get_setting('platform.site_name'),
  104. 'contact' => api_get_setting('platform.administrator_email'),
  105. 'version' => $system_version,
  106. 'numberofcourses' => $number_of_courses,
  107. 'numberofusers' => $number_of_users,
  108. 'numberofactiveusers' => $number_of_active_users,
  109. 'numberofsessions' => $number_of_sessions,
  110. //The donotlistcampus setting recovery should be improved to make
  111. // it true by default - this does not affect numbers counting
  112. 'donotlistcampus' => api_get_setting('donotlistcampus'),
  113. 'organisation' => api_get_setting('platform.institution'),
  114. 'language' => api_get_setting('platformLanguage'),
  115. 'adminname' => api_get_setting('platform.administrator_name').' '.api_get_setting('platform.administrator_surname'),
  116. );
  117. $res = api_http_request('version.chamilo.org', 80, '/version.php', $data);
  118. if ($res != 0) {
  119. $version_info = $res;
  120. if ($system_version != $version_info) {
  121. $output = '<br /><span style="color:red">' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' <b>Chamilo '.$version_info.'</b>. '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version. '</b>. '.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>';
  122. } else {
  123. $output = '<br /><span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version_info.'</span>';
  124. }
  125. } else {
  126. $output = '<span style="color:red">' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . '</span>';
  127. }
  128. } else {
  129. $output = '<span style="color:red">' . get_lang('AllowurlfopenIsSetToOff') . '</span>';
  130. }
  131. return $output;
  132. }
  133. exit;