api.corporate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Corporate users API
  4. */
  5. /**
  6. * Returns array of all linked users
  7. *
  8. * @return array
  9. */
  10. function cu_GetAllLinkedUsers() {
  11. global $ubillingConfig;
  12. $linkcfid = $ubillingConfig->getAlterParam('USER_LINKING_CFID');
  13. $query = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $linkcfid . "' AND `content` !=''";
  14. $allusers = simple_queryall($query);
  15. $result = array();
  16. if (!empty($allusers)) {
  17. foreach ($allusers as $io => $eachuser) {
  18. $result[$eachuser['login']] = $eachuser['content'];
  19. }
  20. }
  21. return ($result);
  22. }
  23. /**
  24. * Returns parent user login by linking param
  25. *
  26. * @param string $param
  27. * @return string
  28. */
  29. function cu_GetParentUserLogin($param) {
  30. global $ubillingConfig;
  31. $linkfield = $ubillingConfig->getAlterParam('USER_LINKING_FIELD');
  32. $param = mysql_real_escape_string($param);
  33. $query = "SELECT `login` from `users` WHERE `" . $linkfield . "`='" . $param . "'";
  34. $result = simple_query($query);
  35. if (!empty($result)) {
  36. $result = $result['login'];
  37. }
  38. return ($result);
  39. }
  40. /**
  41. * Returns all child users
  42. *
  43. * @param string $param
  44. * @return array
  45. */
  46. function cu_GetAllChildUsers($param) {
  47. global $ubillingConfig;
  48. $linkcfid = $ubillingConfig->getAlterParam('USER_LINKING_CFID');
  49. $param = mysql_real_escape_string($param);
  50. $query = "SELECT `login` from `cfitems` WHERE `typeid`='" . $linkcfid . "' AND `content`='" . $param . "' ";
  51. $result = array();
  52. $alllinks = simple_queryall($query);
  53. if (!empty($alllinks)) {
  54. foreach ($alllinks as $io => $eachlink) {
  55. $result[] = $eachlink['login'];
  56. }
  57. }
  58. return ($result);
  59. }
  60. /**
  61. * Returns array of all parent users
  62. *
  63. * @return array
  64. */
  65. function cu_GetAllParentUsers() {
  66. global $ubillingConfig;
  67. $linkfield = $ubillingConfig->getAlterParam('USER_LINKING_FIELD');
  68. $linkcfid = $ubillingConfig->getAlterParam('USER_LINKING_CFID');
  69. $result = array();
  70. $query_cfs = "SELECT DISTINCT `content` FROM `cfitems` WHERE `typeid`='" . $linkcfid . "' AND `content` <> ''";
  71. $allcfs = simple_queryall($query_cfs);
  72. if (!empty($allcfs)) {
  73. foreach ($allcfs as $io => $eachcf) {
  74. $query_user = "SELECT `login` from `users` WHERE `" . $linkfield . "`='" . $eachcf['content'] . "' ";
  75. $userlogin = simple_query($query_user);
  76. if (!empty($userlogin) AND ! empty($eachcf['content'])) {
  77. $result[$userlogin['login']] = $eachcf['content'];
  78. }
  79. }
  80. }
  81. return ($result);
  82. }
  83. /**
  84. * Checks is some user child of another?
  85. *
  86. * @param string $login
  87. * @return bool
  88. */
  89. function cu_IsChild($login) {
  90. $login = mysql_real_escape_string($login);
  91. $allchilds = cu_GetAllLinkedUsers();
  92. if (isset($allchilds[$login])) {
  93. return (true);
  94. } else {
  95. return (false);
  96. }
  97. }
  98. /**
  99. * Checks is some user parent for another one?
  100. *
  101. * @param string $login
  102. * @return bool
  103. */
  104. function cu_IsParent($login) {
  105. $login = mysql_real_escape_string($login);
  106. $allparents = cu_GetAllParentUsers();
  107. if (isset($allparents[$login])) {
  108. return (true);
  109. } else {
  110. return (false);
  111. }
  112. }
  113. ?>