PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/user/ajax/list.php

https://bitbucket.org/speedealing/speedealing
PHP | 132 lines | 83 code | 24 blank | 25 comment | 21 complexity | 54ba03a58ab3791529f2e4b973d85b84 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2013 Regis Houssin <regis.houssin@capnetworks.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. /**
  19. * \file htdocs/user/ajax/list.php
  20. * \brief File to return Ajax response for user list
  21. */
  22. if (!defined('NOTOKENRENEWAL'))
  23. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  24. if (!defined('NOREQUIREMENU'))
  25. define('NOREQUIREMENU', '1');
  26. if (!defined('NOREQUIREHTML'))
  27. define('NOREQUIREHTML', '1');
  28. if (!defined('NOREQUIRESOC'))
  29. define('NOREQUIRESOC', '1');
  30. if (!defined('NOREQUIREAJAX'))
  31. define('NOREQUIREAJAX', '1');
  32. if (!defined('NOREQUIRETRAN'))
  33. define('NOREQUIRETRAN', '1');
  34. include '../../main.inc.php';
  35. $json = GETPOST('json', 'alpha');
  36. $sEcho = GETPOST('sEcho');
  37. top_httphead('json');
  38. if ($json == "list") {
  39. $object = new User($db);
  40. $output = array(
  41. "sEcho" => intval($sEcho),
  42. "iTotalRecords" => 0,
  43. "iTotalDisplayRecords" => 0,
  44. "aaData" => array()
  45. );
  46. $user_in = array();
  47. $var_exclude_db = array("_users", "_replicator", "mips", "system");
  48. $listEntity = new stdClass();
  49. try {
  50. $result = $object->getView('listAll');
  51. $result_all = $object->getAllUsers(true);
  52. $admins = $object->getUserAdmins();
  53. $list_db = array_diff($couch->listDatabases(), $var_exclude_db);
  54. //$admins = $object->getDatabaseAdminUsers();
  55. //$enabled = $object->getDatabaseReaderUsers();
  56. foreach ($list_db as $db) {
  57. $object->useDatabase($db);
  58. $listEntity->$db = $object->getDatabaseReaderUsers();
  59. }
  60. } catch (Exception $exc) {
  61. print $exc->getMessage();
  62. }
  63. //print_r($result_all);
  64. if (!empty($result->rows)) {
  65. foreach ($result->rows as $aRow) {
  66. // To hide specific users for all normals users except superadmin
  67. if (!empty($aRow->value->hide) && empty($user->superadmin))
  68. continue;
  69. $name = substr($aRow->value->_id, 5);
  70. if (isset($admins->$name))
  71. $aRow->value->admin = true;
  72. else
  73. $aRow->value->admin = false;
  74. $aRow->value->entityList = array();
  75. foreach ($list_db as $db) {
  76. if (is_array($listEntity->$db) && in_array($name, $listEntity->$db, true))
  77. $aRow->value->entityList[] = $db;
  78. }
  79. $output["aaData"][] = $aRow->value;
  80. $user_in[] = $name;
  81. }
  82. }
  83. if ($result_all) {
  84. foreach ($result_all as $aRow) {
  85. // To hide specific users for all normals users except superadmin
  86. if (!empty($aRow->value->hide) && empty($user->superadmin))
  87. continue;
  88. $name = substr($aRow->doc->_id, 17);
  89. if (in_array($name, $user_in))
  90. continue;
  91. if (isset($admins->$name))
  92. $aRow->doc->admin = true;
  93. else
  94. $aRow->doc->admin = false;
  95. $aRow->doc->entityList = array();
  96. foreach ($list_db as $db) {
  97. if (is_array($listEntity->$db) && in_array($name, $listEntity->$db, true))
  98. $aRow->doc->entityList[] = $db;
  99. }
  100. $output["aaData"][] = $aRow->doc;
  101. }
  102. }
  103. $iTotal = count($output["aaData"]);
  104. $output["iTotalRecords"] = $iTotal;
  105. $output["iTotalDisplayRecords"] = $iTotal;
  106. echo json_encode($output);
  107. }
  108. ?>