user_manager.ajax.php 7.1 KB

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