User.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /**
  3. * Zm_User
  4. *
  5. * @author Yannick Lorenz <ylorenz@1g6.biz>
  6. * @author Fabrizio La Rosa <fabrizio.larosa@unime.it>
  7. * @version 2.2
  8. * @copyright Copyright (c) 2009, Yannick Lorenz
  9. * @copyright Copyright (c) 2012, Fabrizio La Rosa
  10. * @example "../testuser.php"
  11. */
  12. /**
  13. * Zm_User class documentation
  14. */
  15. // utils.php contains a small collection of useful functions
  16. require_once ("utils.php");
  17. /**
  18. * Zm_User is a class which allows a Kerio user to manage its own account via SOAP
  19. *
  20. * You may change password, modify and get the attributes of a Kerio user using this class
  21. *
  22. * For the usage examples of all class methods check the source code of test.php
  23. */
  24. class Zm_User
  25. {
  26. /**
  27. * $auth
  28. * @var Zm_Auth $auth soap authentication
  29. */
  30. private $auth;
  31. /**
  32. * Constructor
  33. * @param Zm_Auth $auth soap authentication
  34. */
  35. function __construct($auth)
  36. {
  37. $this->auth = $auth;
  38. }
  39. /**
  40. * userExists
  41. * @param string $userName user name
  42. * @return bool exists
  43. */
  44. function userExists($userName)
  45. {
  46. $result = null;
  47. $params = array(
  48. new SoapVar('<ns1:account by="name">' . $userName . '</ns1:account>', XSD_ANYXML),
  49. );
  50. $options = array(
  51. 'retry' => false,
  52. );
  53. try
  54. {
  55. $result = $this->auth->execSoapCall(
  56. "GetAccountInfoRequest",
  57. $params,
  58. $options
  59. );
  60. }
  61. catch (SoapFault $exception)
  62. {
  63. $result = $exception;
  64. }
  65. return (!is_a($result, "Exception"));
  66. }
  67. /**
  68. * getUserInfo
  69. * @param string $userName user name
  70. * @return array informations
  71. */
  72. function getUserInfo($userName)
  73. {
  74. $result = null;
  75. $params = array(
  76. new SoapVar('<ns1:account by="name">' . $userName . '</ns1:account>', XSD_ANYXML),
  77. );
  78. try
  79. {
  80. $result = $this->auth->execSoapCall(
  81. "GetInfoRequest",
  82. $params
  83. );
  84. }
  85. catch (SoapFault $exception)
  86. {
  87. $result = $exception;
  88. }
  89. return $result['SOAP:ENVELOPE']['SOAP:BODY']['GETINFORESPONSE'];
  90. }
  91. /**
  92. * getUserAttrs
  93. * @param string $userName user name
  94. * @return string option
  95. */
  96. function getUserAttrs($userName)
  97. {
  98. $result = null;
  99. $params = array(
  100. new SoapVar('<ns1:account by="name">' . $userName . '</ns1:account>', XSD_ANYXML),
  101. new SoapParam("attrs", "sections"),
  102. );
  103. try
  104. {
  105. $result = $this->auth->execSoapCall(
  106. "GetInfoRequest",
  107. $params
  108. );
  109. $attrs = array();
  110. foreach ($result['SOAP:ENVELOPE']['SOAP:BODY']['GETINFORESPONSE']['ATTRS']['ATTR'] as $a) {
  111. $attrs[$a['NAME']] = $a['DATA'];
  112. }
  113. $result = $attrs;
  114. }
  115. catch (SoapFault $exception)
  116. {
  117. $result = $exception;
  118. }
  119. return $result;
  120. }
  121. /**
  122. * getUserPrefs
  123. * @param string $userName user name
  124. * @return array prefs
  125. */
  126. function getUserPrefs($userName)
  127. {
  128. $result = null;
  129. $params = array(
  130. new SoapVar('<ns1:account by="name">' . $userName . '</ns1:account>', XSD_ANYXML),
  131. );
  132. try
  133. {
  134. $result = $this->auth->execSoapCall(
  135. "GetPrefsRequest",
  136. $params
  137. );
  138. $prefs = array();
  139. foreach ($result['SOAP:ENVELOPE']['SOAP:BODY']['GETPREFSRESPONSE']['PREF'] as $p) {
  140. $prefs[$p['NAME']] = $p['DATA'];
  141. }
  142. $result = $prefs;
  143. }
  144. catch (SoapFault $exception)
  145. {
  146. $result = $exception;
  147. }
  148. return $result;
  149. }
  150. /**
  151. * changeUserPassword
  152. * @param string $userName user name
  153. * @param string $oldPassword old password
  154. * @param string $newPassword new password
  155. * @return array informations
  156. */
  157. function changeUserPassword($userName, $oldPassword, $newPassword)
  158. {
  159. $result = null;
  160. $params = array(
  161. new SoapParam($userName, "account"),
  162. new SoapParam($oldPassword, "oldPassword"),
  163. new SoapParam($newPassword, "password"),
  164. );
  165. try
  166. {
  167. $result = $this->auth->execSoapCall(
  168. "ChangePasswordRequest",
  169. $params
  170. );
  171. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['CHANGEPASSWORDRESPONSE'];
  172. }
  173. catch (SoapFault $exception)
  174. {
  175. $result = $exception;
  176. }
  177. return $result;
  178. }
  179. /**
  180. * modifyUserPrefs
  181. * @param string $userName user name
  182. * @param array $prefs an array containing the user prefs to be set
  183. * @return array informations
  184. */
  185. function modifyUserPrefs($userName, $prefs = array())
  186. {
  187. $result = null;
  188. $params = array(
  189. new SoapParam($userName, "account"),
  190. );
  191. foreach ($prefs as $key=>$value)
  192. $params[] = new SoapVar('<ns1:pref name="' . $key . '">' . $value . '</ns1:pref>', XSD_ANYXML);
  193. try
  194. {
  195. $result = $this->auth->execSoapCall(
  196. "ModifyPrefsRequest",
  197. $params
  198. );
  199. }
  200. catch (SoapFault $exception)
  201. {
  202. $result = $exception;
  203. }
  204. return $result;
  205. }
  206. }
  207. ?>