user_manager.ajax.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. header('Content-Type: application/json');
  88. $result = ['items' => []];
  89. if (api_is_anonymous()) {
  90. echo json_encode($result);
  91. break;
  92. }
  93. if (!isset($_GET['q'], $_GET['field_id'])) {
  94. echo json_encode($result);
  95. break;
  96. }
  97. $result['items'] = UserManager::get_tags($_GET['q'], $_GET['field_id'], null, '10');
  98. echo json_encode($result);
  99. break;
  100. case 'generate_api_key':
  101. if (api_is_anonymous()) {
  102. echo '';
  103. } else {
  104. $array_list_key = array();
  105. $user_id = api_get_user_id();
  106. $api_service = 'dokeos';
  107. $num = UserManager::update_api_key($user_id, $api_service);
  108. $array_list_key = UserManager::get_api_keys($user_id, $api_service);
  109. ?>
  110. <div class="form-group">
  111. <label class="col-sm-2 control-label"><?php echo get_lang('MyApiKey'); ?></label>
  112. <div class="col-sm-8">
  113. <input type="text" name="api_key_generate" id="id_api_key_generate" class="form-control" value="<?php echo $array_list_key[$num]; ?>"/>
  114. </div>
  115. </div>
  116. <?php
  117. }
  118. break;
  119. case 'active_user':
  120. if (api_is_platform_admin() && api_global_admin_can_edit_admin($_GET['user_id'])) {
  121. $user_id = intval($_GET['user_id']);
  122. $status = intval($_GET['status']);
  123. if (!empty($user_id)) {
  124. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  125. $sql = "UPDATE $user_table
  126. SET active='".$status."'
  127. WHERE user_id='".$user_id."'";
  128. $result = Database::query($sql);
  129. //Send and email if account is active
  130. if ($status == 1) {
  131. $user_info = api_get_user_info($user_id);
  132. $recipient_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  133. $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
  134. $email_admin = api_get_setting('emailAdministrator');
  135. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  136. $emailbody = get_lang('Dear')." ".stripslashes($recipient_name).",\n\n";
  137. $emailbody .= sprintf(get_lang('YourAccountOnXHasJustBeenApprovedByOneOfOurAdministrators'), api_get_setting('siteName'))."\n";
  138. $emailbody .= sprintf(get_lang('YouCanNowLoginAtXUsingTheLoginAndThePasswordYouHaveProvided'), api_get_path(WEB_PATH)).",\n\n";
  139. $emailbody .= get_lang('HaveFun')."\n\n";
  140. //$emailbody.=get_lang('Problem'). "\n\n". get_lang('SignatureFormula');
  141. $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');
  142. $additionalParameters = array(
  143. 'smsType' => SmsPlugin::ACCOUNT_APPROVED_CONNECT,
  144. 'userId' => $user_id
  145. );
  146. $result = api_mail_html(
  147. $recipient_name,
  148. $user_info['mail'],
  149. $emailsubject,
  150. $emailbody,
  151. $sender_name,
  152. $email_admin,
  153. null,
  154. null,
  155. $additionalParameters
  156. );
  157. Event::addEvent(LOG_USER_ENABLE, LOG_USER_ID, $user_id);
  158. } else {
  159. Event::addEvent(LOG_USER_DISABLE, LOG_USER_ID, $user_id);
  160. }
  161. echo $status;
  162. }
  163. } else {
  164. echo '-1';
  165. }
  166. break;
  167. default:
  168. echo '';
  169. }
  170. exit;