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