user_manager.ajax.php 7.8 KB

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