admin.ajax.php 5.8 KB

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