PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/include/staff/users.inc.php

https://gitlab.com/billyprice1/osTicket
PHP | 316 lines | 291 code | 19 blank | 6 comment | 37 complexity | 0eaa8863bc7343a370ad8bebe09c1cd1 MD5 | raw file
  1. <?php
  2. if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied');
  3. // Ensure cdata
  4. UserForm::ensureDynamicDataView();
  5. $qs = array();
  6. $users = User::objects()
  7. ->annotate(array('ticket_count'=>SqlAggregate::COUNT('tickets')));
  8. if ($_REQUEST['query']) {
  9. $search = $_REQUEST['query'];
  10. $users->filter(Q::any(array(
  11. 'emails__address__contains' => $search,
  12. 'name__contains' => $search,
  13. 'org__name__contains' => $search,
  14. // TODO: Add search for cdata
  15. )));
  16. $qs += array('query' => $_REQUEST['query']);
  17. }
  18. $sortOptions = array('name' => 'name',
  19. 'email' => 'emails__address',
  20. 'status' => 'account__status',
  21. 'create' => 'created',
  22. 'update' => 'updated');
  23. $orderWays = array('DESC'=>'-','ASC'=>'');
  24. $sort= ($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])]) ? strtolower($_REQUEST['sort']) : 'name';
  25. //Sorting options...
  26. if ($sort && $sortOptions[$sort])
  27. $order_column =$sortOptions[$sort];
  28. $order_column = $order_column ?: 'name';
  29. if ($_REQUEST['order'] && $orderWays[strtoupper($_REQUEST['order'])])
  30. $order = $orderWays[strtoupper($_REQUEST['order'])];
  31. if ($order_column && strpos($order_column,','))
  32. $order_column = str_replace(','," $order,",$order_column);
  33. $x=$sort.'_sort';
  34. $$x=' class="'.($order == '' ? 'asc' : 'desc').'" ';
  35. $total = $users->count();
  36. $page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
  37. $pageNav=new Pagenate($total,$page,PAGE_LIMIT);
  38. $pageNav->paginate($users);
  39. $qstr = '&amp;'. Http::build_query($qs);
  40. $qs += array('sort' => $_REQUEST['sort'], 'order' => $_REQUEST['order']);
  41. $pageNav->setURL('users.php', $qs);
  42. $qstr.='&amp;order='.($order=='-' ? 'ASC' : 'DESC');
  43. //echo $query;
  44. $_SESSION[':Q:users'] = $users;
  45. $users->values('id', 'name', 'default_email__address', 'account__id',
  46. 'account__status', 'created', 'updated');
  47. $users->order_by($order . $order_column);
  48. ?>
  49. <div id="basic_search">
  50. <div style="min-height:25px;">
  51. <form action="users.php" method="get">
  52. <?php csrf_token(); ?>
  53. <input type="hidden" name="a" value="search">
  54. <div class="attached input">
  55. <input type="text" class="basic-search" id="basic-user-search" name="query"
  56. size="30" value="<?php echo Format::htmlchars($_REQUEST['query']); ?>"
  57. autocomplete="off" autocorrect="off" autocapitalize="off">
  58. <!-- <td>&nbsp;&nbsp;<a href="" id="advanced-user-search">[advanced]</a></td> -->
  59. <button type="submit" class="attached button"><i class="icon-search"></i>
  60. </button>
  61. </div>
  62. </form>
  63. </div>
  64. </div>
  65. <form id="users-list" action="users.php" method="POST" name="staff" >
  66. <div style="margin-bottom:20px; padding-top:5px;">
  67. <div class="sticky bar opaque">
  68. <div class="content">
  69. <div class="pull-left flush-left">
  70. <h2><?php echo __('User Directory'); ?></h2>
  71. </div>
  72. <div class="pull-right">
  73. <?php if ($thisstaff->hasPerm(User::PERM_CREATE)) { ?>
  74. <a class="green button action-button popup-dialog"
  75. href="#users/add">
  76. <i class="icon-plus-sign"></i>
  77. <?php echo __('Add User'); ?>
  78. </a>
  79. <a class="action-button popup-dialog"
  80. href="#users/import">
  81. <i class="icon-upload"></i>
  82. <?php echo __('Import'); ?>
  83. </a>
  84. <?php } ?>
  85. <span class="action-button" data-dropdown="#action-dropdown-more"
  86. style="/*DELME*/ vertical-align:top; margin-bottom:0">
  87. <i class="icon-caret-down pull-right"></i>
  88. <span ><i class="icon-cog"></i> <?php echo __('More');?></span>
  89. </span>
  90. <div id="action-dropdown-more" class="action-dropdown anchor-right">
  91. <ul>
  92. <?php if ($thisstaff->hasPerm(User::PERM_EDIT)) { ?>
  93. <li><a href="#add-to-org" class="users-action">
  94. <i class="icon-group icon-fixed-width"></i>
  95. <?php echo __('Add to Organization'); ?></a></li>
  96. <?php
  97. }
  98. if ('disabled' != $cfg->getClientRegistrationMode()) { ?>
  99. <li><a class="users-action" href="#reset">
  100. <i class="icon-envelope icon-fixed-width"></i>
  101. <?php echo __('Send Password Reset Email'); ?></a></li>
  102. <?php if ($thisstaff->hasPerm(User::PERM_MANAGE)) { ?>
  103. <li><a class="users-action" href="#register">
  104. <i class="icon-smile icon-fixed-width"></i>
  105. <?php echo __('Register'); ?></a></li>
  106. <li><a class="users-action" href="#lock">
  107. <i class="icon-lock icon-fixed-width"></i>
  108. <?php echo __('Lock'); ?></a></li>
  109. <li><a class="users-action" href="#unlock">
  110. <i class="icon-unlock icon-fixed-width"></i>
  111. <?php echo __('Unlock'); ?></a></li>
  112. <?php }
  113. if ($thisstaff->hasPerm(User::PERM_DELETE)) { ?>
  114. <li class="danger"><a class="users-action" href="#delete">
  115. <i class="icon-trash icon-fixed-width"></i>
  116. <?php echo __('Delete'); ?></a></li>
  117. <?php }
  118. } # end of registration-enabled? ?>
  119. </ul>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <div class="clear"></div>
  126. <?php
  127. $showing = $search ? __('Search Results').': ' : '';
  128. if($users->exists(true))
  129. $showing .= $pageNav->showing();
  130. else
  131. $showing .= __('No users found!');
  132. ?>
  133. <?php csrf_token(); ?>
  134. <input type="hidden" name="do" value="mass_process" >
  135. <input type="hidden" id="action" name="a" value="" >
  136. <input type="hidden" id="selected-count" name="count" value="" >
  137. <input type="hidden" id="org_id" name="org_id" value="" >
  138. <table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
  139. <thead>
  140. <tr>
  141. <th nowrap width="4%">&nbsp;</th>
  142. <th><a <?php echo $name_sort; ?> href="users.php?<?php
  143. echo $qstr; ?>&sort=name"><?php echo __('Name'); ?></a></th>
  144. <th width="22%"><a <?php echo $status_sort; ?> href="users.php?<?php
  145. echo $qstr; ?>&sort=status"><?php echo __('Status'); ?></a></th>
  146. <th width="20%"><a <?php echo $create_sort; ?> href="users.php?<?php
  147. echo $qstr; ?>&sort=create"><?php echo __('Created'); ?></a></th>
  148. <th width="20%"><a <?php echo $update_sort; ?> href="users.php?<?php
  149. echo $qstr; ?>&sort=update"><?php echo __('Updated'); ?></a></th>
  150. </tr>
  151. </thead>
  152. <tbody>
  153. <?php
  154. $ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null;
  155. foreach ($users as $U) {
  156. // Default to email address mailbox if no name specified
  157. if (!$U['name'])
  158. list($name) = explode('@', $U['default_email__address']);
  159. else
  160. $name = new UsersName($U['name']);
  161. // Account status
  162. if ($U['account__id'])
  163. $status = new UserAccountStatus($U['account__status']);
  164. else
  165. $status = __('Guest');
  166. $sel=false;
  167. if($ids && in_array($U['id'], $ids))
  168. $sel=true;
  169. ?>
  170. <tr id="<?php echo $U['id']; ?>">
  171. <td nowrap align="center">
  172. <input type="checkbox" value="<?php echo $U['id']; ?>" class="ckb mass nowarn"/>
  173. </td>
  174. <td>&nbsp;
  175. <a class="preview"
  176. href="users.php?id=<?php echo $U['id']; ?>"
  177. data-preview="#users/<?php echo $U['id']; ?>/preview"><?php
  178. echo Format::htmlchars($name); ?></a>
  179. &nbsp;
  180. <?php
  181. if ($U['ticket_count'])
  182. echo sprintf('<i class="icon-fixed-width icon-file-text-alt"></i>
  183. <small>(%d)</small>', $U['ticket_count']);
  184. ?>
  185. </td>
  186. <td><?php echo $status; ?></td>
  187. <td><?php echo Format::date($U['created']); ?></td>
  188. <td><?php echo Format::datetime($U['updated']); ?>&nbsp;</td>
  189. </tr>
  190. <?php } //end of foreach. ?>
  191. </tbody>
  192. <tfoot>
  193. <tr>
  194. <td colspan="7">
  195. <?php if ($total) { ?>
  196. <?php echo __('Select');?>:&nbsp;
  197. <a id="selectAll" href="#ckb"><?php echo __('All');?></a>&nbsp;&nbsp;
  198. <a id="selectNone" href="#ckb"><?php echo __('None');?></a>&nbsp;&nbsp;
  199. <a id="selectToggle" href="#ckb"><?php echo __('Toggle');?></a>&nbsp;&nbsp;
  200. <?php }else{
  201. echo '<i>';
  202. echo __('Query returned 0 results.');
  203. echo '</i>';
  204. } ?>
  205. </td>
  206. </tr>
  207. </tfoot>
  208. </table>
  209. <?php
  210. if ($total) {
  211. echo sprintf('<div>&nbsp;'.__('Page').': %s &nbsp; <a class="no-pjax"
  212. href="users.php?a=export&qh=%s">'.__('Export').'</a></div>',
  213. $pageNav->getPageLinks(),
  214. $qhash);
  215. }
  216. ?>
  217. </form>
  218. <script type="text/javascript">
  219. $(function() {
  220. $('input#basic-user-search').typeahead({
  221. source: function (typeahead, query) {
  222. $.ajax({
  223. url: "ajax.php/users/local?q="+query,
  224. dataType: 'json',
  225. success: function (data) {
  226. typeahead.process(data);
  227. }
  228. });
  229. },
  230. onselect: function (obj) {
  231. window.location.href = 'users.php?id='+obj.id;
  232. },
  233. property: "/bin/true"
  234. });
  235. $(document).on('click', 'a.popup-dialog', function(e) {
  236. e.preventDefault();
  237. $.userLookup('ajax.php/' + $(this).attr('href').substr(1), function (user) {
  238. var url = window.location.href;
  239. if (user && user.id)
  240. url = 'users.php?id='+user.id;
  241. $.pjax({url: url, container: '#pjax-container'})
  242. return false;
  243. });
  244. return false;
  245. });
  246. var goBaby = function(action, confirmed) {
  247. var ids = [],
  248. $form = $('form#users-list');
  249. $(':checkbox.mass:checked', $form).each(function() {
  250. ids.push($(this).val());
  251. });
  252. if (ids.length) {
  253. var submit = function(data) {
  254. $form.find('#action').val(action);
  255. $.each(ids, function() { $form.append($('<input type="hidden" name="ids[]">').val(this)); });
  256. if (data)
  257. $.each(data, function() { $form.append($('<input type="hidden">').attr('name', this.name).val(this.value)); });
  258. $form.find('#selected-count').val(ids.length);
  259. $form.submit();
  260. };
  261. var options = {};
  262. if (action === 'delete') {
  263. options['deletetickets']
  264. = __('Also delete all associated tickets and attachments');
  265. }
  266. else if (action === 'add-to-org') {
  267. $.dialog('ajax.php/orgs/lookup/form', 201, function(xhr, json) {
  268. var $form = $('form#users-list');
  269. try {
  270. var json = $.parseJSON(json),
  271. org_id = $form.find('#org_id');
  272. if (json.id) {
  273. org_id.val(json.id);
  274. goBaby('setorg', true);
  275. }
  276. }
  277. catch (e) { }
  278. });
  279. return;
  280. }
  281. if (!confirmed)
  282. $.confirm(__('You sure?'), undefined, options).then(submit);
  283. else
  284. submit();
  285. }
  286. else {
  287. $.sysAlert(__('Oops'),
  288. __('You need to select at least one item'));
  289. }
  290. };
  291. $(document).on('click', 'a.users-action', function(e) {
  292. e.preventDefault();
  293. goBaby($(this).attr('href').substr(1));
  294. return false;
  295. });
  296. });
  297. </script>