user_manager.ajax.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $language_file = array('admin', 'registration', 'userInfo');
  7. require_once '../global.inc.php';
  8. $action = $_GET['a'];
  9. switch ($action) {
  10. case 'get_user_popup':
  11. $user_info = api_get_user_info($_REQUEST['user_id']);
  12. $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
  13. echo '<div class="well">';
  14. echo '<div class="row">';
  15. echo '<div class="span2">';
  16. echo '<div class="thumbnail">';
  17. echo '<img src="'.$user_info['avatar'].'" /> ';
  18. echo '</div>';
  19. echo '</div>';
  20. echo '<div class="span3">';
  21. if (api_get_setting('show_email_addresses') == 'false') {
  22. $user_info['mail'] = ' ';
  23. } else {
  24. $user_info['mail'] = ' '.$user_info['mail'].' ';
  25. }
  26. echo '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user_info['user_id'].'">';
  27. echo '<h3>'.$user_info['complete_name'].'</h3>'.$user_info['mail'].$user_info['official_code'];
  28. echo '</a>';
  29. echo '</div>';
  30. echo '</div>';
  31. if (api_get_setting('allow_message_tool') == 'true') {
  32. echo '<script>';
  33. echo '
  34. $("#send_message").on("click", function() {
  35. var url = "'.$ajax_url.'?a=send_message&user_id='.$user_info['user_id'].'";
  36. var params = $("#send_message_form").serialize();
  37. $.ajax({
  38. url: url+"&"+params,
  39. success:function(data) {
  40. $("#subject_id").val("");
  41. $("#content_id").val("");
  42. $("#send_message_form").html(data);
  43. $("#send_message").hide();
  44. }
  45. });
  46. });';
  47. echo '</script>';
  48. echo MessageManager::generate_message_form(
  49. 'send_message',
  50. array(),
  51. 'block'
  52. );
  53. echo '<a class="btn btn-primary" id="send_message">'.
  54. get_lang('Send').
  55. '</a>';
  56. }
  57. echo '</div>';
  58. break;
  59. case 'user_id_exists':
  60. if (api_is_anonymous()) {
  61. echo '';
  62. } else {
  63. if (UserManager::is_user_id_valid($_GET['user_id'])) {
  64. echo 1;
  65. } else {
  66. echo 0;
  67. }
  68. }
  69. break;
  70. case 'search_tags':
  71. if (api_is_anonymous()) {
  72. echo '';
  73. } else {
  74. if (isset($_GET['tag']) && isset($_GET['field_id'])) {
  75. echo UserManager::get_tags($_GET['tag'], $_GET['field_id'], 'json', '10');
  76. }
  77. }
  78. break;
  79. case 'generate_api_key':
  80. if (api_is_anonymous()) {
  81. echo '';
  82. } else {
  83. $array_list_key = array();
  84. $user_id = api_get_user_id();
  85. $api_service = 'dokeos';
  86. $num = UserManager::update_api_key($user_id, $api_service);
  87. $array_list_key = UserManager::get_api_keys($user_id, $api_service);
  88. ?>
  89. <div class="row">
  90. <div class="label"><?php echo get_lang('MyApiKey'); ?></div>
  91. <div class="formw">
  92. <input type="text" name="api_key_generate" id="id_api_key_generate" size="40" value="<?php echo $array_list_key[$num]; ?>"/>
  93. </div>
  94. </div>
  95. <?php
  96. }
  97. break;
  98. case 'active_user':
  99. if (api_is_platform_admin() && api_global_admin_can_edit_admin($_GET['user_id'])) {
  100. $user_id = intval($_GET['user_id']);
  101. $status = intval($_GET['status']);
  102. if (!empty($user_id)) {
  103. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  104. $sql="UPDATE $user_table SET active='".$status."' WHERE user_id='".$user_id."'";
  105. $result = Database::query($sql);
  106. //Send and email if account is active
  107. if ($status == 1) {
  108. $user_info = api_get_user_info($user_id);
  109. $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  110. $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
  111. $email_admin = api_get_setting('emailAdministrator');
  112. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  113. $emailbody=get_lang('Dear')." ".stripslashes($recipient_name).",\n\n";
  114. $emailbody.=sprintf(get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'), api_get_setting('siteName'))."\n";
  115. $emailbody.=sprintf(get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'), api_get_path(WEB_PATH)).",\n\n";
  116. $emailbody.=get_lang('HaveFun')."\n\n";
  117. //$emailbody.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula');
  118. $emailbody.=api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
  119. $plugin = new AppPlugin();
  120. $additionalParameters = array(
  121. 'smsType' => constant($plugin->getSMSPluginName().'::ACCOUNT_APPROVED_CONNECT'),
  122. 'userId' => $user_id
  123. );
  124. $result = api_mail(
  125. $recipient_name,
  126. $user_info['mail'],
  127. $emailsubject,
  128. $emailbody,
  129. $sender_name,
  130. $email_admin,
  131. '',
  132. $additionalParameters
  133. );
  134. event_system(LOG_USER_ENABLE, LOG_USER_ID, $user_id);
  135. } else {
  136. event_system(LOG_USER_DISABLE, LOG_USER_ID, $user_id);
  137. }
  138. echo $status;
  139. }
  140. } else {
  141. echo '-1';
  142. }
  143. break;
  144. default:
  145. echo '';
  146. }
  147. exit;