Account.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. <?php
  2. /**
  3. * Zm_Account
  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 ../test.php
  11. */
  12. /**
  13. * Zm_Account class documentation
  14. */
  15. // utils.php contains a small collection of useful functions
  16. require_once ("utils.php");
  17. /**
  18. * Zm_Account is a class which allows to manage Zimbra accounts via SOAP
  19. *
  20. * You may create, modify, rename, delete and get the attributes of a Zimbra account using this class
  21. *
  22. * For the usage examples of all class methods check the source code of test.php
  23. */
  24. class Zm_Account
  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. * getAllAccounts
  41. * @deprecated it may take a long time to complete and fail on servers with lots of accounts
  42. *
  43. * use fetchAccounts instead
  44. * @param string $idOrNameDomain domain id or domain name
  45. * @param string $type value of the domain (auto, name, id)
  46. * @return array informations for all accounts
  47. */
  48. function getAllAccounts($idOrNameDomain, $type="auto")
  49. {
  50. if($type == "auto")
  51. $realType = getDomainType($idOrNameDomain);
  52. else
  53. $realType = $type;
  54. $result = null;
  55. $params = array(
  56. new SoapVar('<ns1:domain by="' . $realType . '">' . $idOrNameDomain . '</ns1:domain>', XSD_ANYXML),
  57. );
  58. try
  59. {
  60. $result = $this->auth->execSoapCall(
  61. "GetAllAccountsRequest",
  62. $params
  63. );
  64. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETALLACCOUNTSRESPONSE']['ACCOUNT'];
  65. }
  66. catch (SoapFault $exception)
  67. {
  68. $result = $exception;
  69. }
  70. return $result;
  71. }
  72. /**
  73. * fetchAccounts
  74. * @param string $ldapQuery LDAP-style filter string (RFC 2254)
  75. * @param array $attrList names of requested attributes
  76. * @param string $nameDomain domain name to restrict search request
  77. * @return array informations for accounts as specified in $ldapQuery
  78. * @author Marc Lamouche <marc.lamouche@ined.fr>
  79. */
  80. function fetchAccounts($ldapQuery, $attrList, $nameDomain = null)
  81. {
  82. $result = null;
  83. $params = array(
  84. new SoapVar('<ns1:query>'.$ldapQuery.'</ns1:query>', XSD_ANYXML),
  85. new SoapParam("accounts", "types"),
  86. new SoapParam(implode(',', $attrList), "attrs"),
  87. new SoapParam("0", "limit"),
  88. );
  89. if ( is_string($nameDomain) ) $params[] = new SoapParam($nameDomain, "domain");
  90. try
  91. {
  92. $response = $this->auth->execSoapCall(
  93. "SearchDirectoryRequest",
  94. $params
  95. );
  96. $result = array();
  97. $resultCount = intval($response['SOAP:ENVELOPE']['SOAP:BODY']['SEARCHDIRECTORYRESPONSE']['SEARCHTOTAL']);
  98. if ( !$resultCount ) return $result;
  99. if ( $resultCount > 1 )
  100. $accountList = &$response['SOAP:ENVELOPE']['SOAP:BODY']['SEARCHDIRECTORYRESPONSE']['ACCOUNT'];
  101. else
  102. $accountList = array(&$response['SOAP:ENVELOPE']['SOAP:BODY']['SEARCHDIRECTORYRESPONSE']['ACCOUNT']);
  103. foreach($accountList as $account)
  104. {
  105. $data = array();
  106. foreach($attrList as $attrName)
  107. $data[$attrName] = getSoapAttribute($account['A'], $attrName, ATTR_MULTIVALUE);
  108. $result[] = $data;
  109. unset($data);
  110. }
  111. }
  112. catch (SoapFault $exception)
  113. {
  114. $result = $exception;
  115. }
  116. return $result;
  117. }
  118. /**
  119. * getAccount
  120. * @param string $name account name
  121. * @return string account informations
  122. */
  123. function getAccount($name)
  124. {
  125. $result = null;
  126. $params = array(
  127. new SoapVar('<ns1:account by="name">' . $name . '</ns1:account>', XSD_ANYXML),
  128. );
  129. try
  130. {
  131. $result = $this->auth->execSoapCall(
  132. "GetAccountRequest",
  133. $params
  134. );
  135. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT'];
  136. }
  137. catch (SoapFault $exception)
  138. {
  139. $result = $exception;
  140. }
  141. return $result;
  142. }
  143. /**
  144. * getQuota
  145. * @param string $name account name
  146. * @return string account informations
  147. */
  148. function getQuota($name)
  149. {
  150. $result = null;
  151. $params = array(
  152. new SoapVar('<ns1:account by="name">' . $name . '</ns1:account>', XSD_ANYXML),
  153. );
  154. try
  155. {
  156. $result = $this->auth->execSoapCall(
  157. "GetAccountRequest",
  158. $params
  159. );
  160. $result = getSoapAttribute($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT']['A'], "zimbraMailQuota");
  161. }
  162. catch (SoapFault $exception)
  163. {
  164. $result = $exception;
  165. }
  166. return $result;
  167. }
  168. /**
  169. * getAccountId
  170. * @param string $name account name
  171. * @return string account id
  172. */
  173. function getAccountId($name)
  174. {
  175. $result = null;
  176. $params = array(
  177. new SoapVar('<ns1:account by="name">' . $name . '</ns1:account>', XSD_ANYXML),
  178. );
  179. try
  180. {
  181. $result = $this->auth->execSoapCall(
  182. "GetAccountInfoRequest",
  183. $params
  184. );
  185. $result = getSoapAttribute($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTINFORESPONSE']['A'], "zimbraId");
  186. }
  187. catch (SoapFault $exception)
  188. {
  189. $result = $exception;
  190. }
  191. return $result;
  192. }
  193. /**
  194. * accountExists
  195. * @param string $idOrNameAccount account id or account name
  196. * @param string $type value of the account (auto, name, id)
  197. * @return bool exists
  198. */
  199. function accountExists($idOrNameAccount, $type="auto")
  200. {
  201. if($type == "auto")
  202. $realType = getAccountType($idOrNameAccount);
  203. else
  204. $realType = $type;
  205. $result = null;
  206. $params = array(
  207. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  208. );
  209. $options = array(
  210. 'retry' => false,
  211. );
  212. try
  213. {
  214. $result = $this->auth->execSoapCall(
  215. "GetAccountInfoRequest",
  216. $params,
  217. $options
  218. );
  219. }
  220. catch (SoapFault $exception)
  221. {
  222. $result = $exception;
  223. return 'blubb';
  224. }
  225. return 'bla';
  226. }
  227. /**
  228. * getAccountInfo
  229. * @param string $idOrNameAccount account id or account name
  230. * @param string $type value of the account (auto, name, id)
  231. * @return array informations
  232. */
  233. function getAccountInfo($idOrNameAccount, $type="auto")
  234. {
  235. if($type == "auto")
  236. $realType = getAccountType($idOrNameAccount);
  237. else
  238. $realType = $type;
  239. $result = null;
  240. $params = array(
  241. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  242. );
  243. try
  244. {
  245. $result = $this->auth->execSoapCall(
  246. "GetAccountInfoRequest",
  247. $params
  248. );
  249. }
  250. catch (SoapFault $exception)
  251. {
  252. $result = $exception;
  253. }
  254. return $result;
  255. }
  256. /**
  257. * getMailbox
  258. * @param string $idOrNameAccount account id or account name
  259. * @return array informations
  260. */
  261. function getMailbox($idOrNameAccount, $type="auto")
  262. {
  263. if($type == "auto")
  264. $realType = getAccountType($idOrNameAccount);
  265. else
  266. $realType = $type;
  267. if($realTyp = 'name')
  268. $id = $this->getAccountId($idOrNameAccount);
  269. $result = null;
  270. $params = array(
  271. new SoapVar('<ns1:mbox id="' . $id . '" />', XSD_ANYXML),
  272. );
  273. try
  274. {
  275. $result = $this->auth->execSoapCall(
  276. "GetMailboxRequest",
  277. $params
  278. );
  279. $result = $result['SOAP:ENVELOPE']['SOAP:BODY'];
  280. }
  281. catch (SoapFault $exception)
  282. {
  283. $result = $exception;
  284. }
  285. return $result;
  286. }
  287. /**
  288. * getAccountOption
  289. * @param string $idOrNameAccount account id or account name
  290. * @param string $optName name of the option to get
  291. * @param int $multisingle (ATTR_SINGLEVALUE, ATTR_MULTIVALUE)
  292. * @param string $type value of the account (auto, name, id)
  293. * @return string option
  294. */
  295. function getAccountOption($idOrNameAccount, $optName, $multisingle=ATTR_SINGLEVALUE, $type="auto")
  296. {
  297. if($type == "auto")
  298. $realType = getAccountType($idOrNameAccount);
  299. else
  300. $realType = $type;
  301. $result = null;
  302. $params = array(
  303. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  304. );
  305. try
  306. {
  307. $result = $this->auth->execSoapCall(
  308. "GetAccountRequest",
  309. $params
  310. );
  311. $result = getSoapAttribute($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT']['A'], $optName, $multisingle);
  312. }
  313. catch (SoapFault $exception)
  314. {
  315. $result = $exception;
  316. }
  317. return $result;
  318. }
  319. /**
  320. * getAccountOptions
  321. * @param string $idOrNameAccount account id or account name
  322. * @param string $type value of the account (auto, name, id)
  323. * @return array options
  324. */
  325. function getAccountOptions($idOrNameAccount, $type="auto")
  326. {
  327. if($type == "auto")
  328. $realType = getAccountType($idOrNameAccount);
  329. else
  330. $realType = $type;
  331. $result = null;
  332. $params = array(
  333. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  334. );
  335. try
  336. {
  337. $result = $this->auth->execSoapCall(
  338. "GetAccountRequest",
  339. $params
  340. );
  341. $attrs = array();
  342. foreach ($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT']['A'] as $a) {
  343. $attrs[$a['N']] = $a['DATA'];
  344. }
  345. $result = $attrs;
  346. }
  347. catch (SoapFault $exception)
  348. {
  349. $result = $exception;
  350. }
  351. return $result;
  352. }
  353. /**
  354. * createAccount
  355. * @param string $name account name
  356. * @param string $password password
  357. * @param array $attrs an optional array containing the account attributes to be set
  358. * @return string the new account's id
  359. */
  360. function createAccount($name, $password, $attrs = array())
  361. {
  362. $result = null;
  363. $params = array(
  364. new SoapParam($name, "name"),
  365. new SoapParam($password, "password"),
  366. );
  367. foreach ($attrs as $key=>$value)
  368. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  369. try
  370. {
  371. $result = $this->auth->execSoapCall(
  372. "CreateAccountRequest",
  373. $params
  374. );
  375. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID'];
  376. usleep(250000); // introduce a small delay, otherwise some troubles may arise if we modify the new account right after its creation
  377. }
  378. catch (SoapFault $exception)
  379. {
  380. $result = $exception;
  381. }
  382. return $result;
  383. }
  384. /**
  385. * setAccountPassword
  386. * @param string $idOrNameAccount account id or account name
  387. * @param string $password password
  388. * @param string $type value of the account (auto, name, id)
  389. * @return array informations
  390. */
  391. function setAccountPassword($idOrNameAccount, $password, $type="auto")
  392. {
  393. if($type == "auto")
  394. $realType = getAccountType($idOrNameAccount);
  395. else
  396. $realType = $type;
  397. if($realType == "name")
  398. $accountId = $this->getAccountId($idOrNameAccount);
  399. else
  400. $accountId = $idOrNameAccount;
  401. $result = null;
  402. $params = array(
  403. new SoapParam($accountId, "id"),
  404. new SoapParam($password, "newPassword"),
  405. );
  406. try
  407. {
  408. $result = $this->auth->execSoapCall(
  409. "SetPasswordRequest",
  410. $params
  411. );
  412. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['SETPASSWORDRESPONSE'];
  413. }
  414. catch (SoapFault $exception)
  415. {
  416. $result = $exception;
  417. }
  418. return $result;
  419. }
  420. /**
  421. * modifyAccount
  422. * @param string $idOrNameAccount account id or account name
  423. * @param array $attrs an array containing the account attributes to be set
  424. * @param string $type value of the account (auto, name, id)
  425. * @return array informations
  426. */
  427. function modifyAccount($idOrNameAccount, $attrs = array(), $type="auto")
  428. {
  429. if($type == "auto")
  430. $realType = getAccountType($idOrNameAccount);
  431. else
  432. $realType = $type;
  433. if($realType == "name")
  434. $accountId = $this->getAccountId($idOrNameAccount);
  435. else
  436. $accountId = $idOrNameAccount;
  437. $result = null;
  438. $params = array(
  439. new SoapParam($accountId, "id"),
  440. );
  441. foreach ($attrs as $key=>$value)
  442. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  443. try
  444. {
  445. $result = $this->auth->execSoapCall(
  446. "ModifyAccountRequest",
  447. $params
  448. );
  449. }
  450. catch (SoapFault $exception)
  451. {
  452. $result = $exception;
  453. }
  454. return $result;
  455. }
  456. /**
  457. * renameAccount
  458. * @param string $idOrNameAccount account id or account name
  459. * @param string $newName new account name
  460. * @param string $type value of the account (auto, name, id)
  461. * @return array informations
  462. */
  463. function renameAccount($idOrNameAccount, $newName, $type="auto")
  464. {
  465. if($type == "auto")
  466. $realType = getAccountType($idOrNameAccount);
  467. else
  468. $realType = $type;
  469. if($realType == "name")
  470. $accountId = $this->getAccountId($idOrNameAccount);
  471. else
  472. $accountId = $idOrNameAccount;
  473. $result = null;
  474. $params = array(
  475. new SoapParam($accountId, "id"),
  476. new SoapParam($newName, "newName"),
  477. );
  478. try
  479. {
  480. $result = $this->auth->execSoapCall(
  481. "RenameAccountRequest",
  482. $params
  483. );
  484. }
  485. catch (SoapFault $exception)
  486. {
  487. $result = $exception;
  488. }
  489. return $result;
  490. }
  491. /**
  492. * deleteAccount
  493. * @param string $idOrNameAccount account id or account name
  494. * @param string $type value of the account (auto, name, id)
  495. * @return array informations
  496. */
  497. function deleteAccount($idOrNameAccount, $type="auto")
  498. {
  499. if($type == "auto")
  500. $realType = getAccountType($idOrNameAccount);
  501. else
  502. $realType = $type;
  503. if($realType == "name")
  504. $accountId = $this->getAccountId($idOrNameAccount);
  505. else
  506. $accountId = $idOrNameAccount;
  507. $result = null;
  508. $params = array(
  509. new SoapParam($accountId, "id"),
  510. );
  511. try
  512. {
  513. $result = $this->auth->execSoapCall(
  514. "DeleteAccountRequest",
  515. $params
  516. );
  517. }
  518. catch (SoapFault $exception)
  519. {
  520. $result = $exception;
  521. }
  522. return $result;
  523. }
  524. /**
  525. * getAccountAliases
  526. * @param string $idOrNameAccount account id or account name
  527. * @param string $type value of the account (auto, name, id)
  528. * @return array aliases
  529. */
  530. function getAccountAliases($idOrNameAccount, $type="auto")
  531. {
  532. return $this->getAccountOption($idOrNameAccount, "zimbraMailAlias", ATTR_MULTIVALUE, $type);
  533. }
  534. /**
  535. * addAccountAlias
  536. * @param string $idOrNameAccount account id or account name
  537. * @param string $alias account alias
  538. * @param string $type value of the account (auto, name, id)
  539. * @return array informations
  540. */
  541. function addAccountAlias($idOrNameAccount, $alias, $type="auto")
  542. {
  543. if($type == "auto")
  544. $realType = getAccountType($idOrNameAccount);
  545. else
  546. $realType = $type;
  547. if($realType == "name")
  548. $accountId = $this->getAccountId($idOrNameAccount);
  549. else
  550. $accountId = $idOrNameAccount;
  551. $result = null;
  552. $params = array(
  553. new SoapParam($accountId, "id"),
  554. new SoapParam($alias, "alias"),
  555. );
  556. try
  557. {
  558. $result = $this->auth->execSoapCall(
  559. "AddAccountAliasRequest",
  560. $params
  561. );
  562. }
  563. catch (SoapFault $exception)
  564. {
  565. $result = $exception;
  566. }
  567. return $result;
  568. }
  569. /**
  570. * removeAccountAlias
  571. * @param string $idOrNameAccount account id or account name
  572. * @param string $alias account alias
  573. * @param string $type value of the account (auto, name, id)
  574. * @return array informations
  575. */
  576. function removeAccountAlias($idOrNameAccount, $alias, $type="auto")
  577. {
  578. if($type == "auto")
  579. $realType = getAccountType($idOrNameAccount);
  580. else
  581. $realType = $type;
  582. if($realType == "name")
  583. $accountId = $this->getAccountId($idOrNameAccount);
  584. else
  585. $accountId = $idOrNameAccount;
  586. $result = null;
  587. $params = array(
  588. new SoapParam($accountId, "id"),
  589. new SoapParam($alias, "alias"),
  590. );
  591. try
  592. {
  593. $result = $this->auth->execSoapCall(
  594. "RemoveAccountAliasRequest",
  595. $params
  596. );
  597. }
  598. catch (SoapFault $exception)
  599. {
  600. $result = $exception;
  601. }
  602. return $result;
  603. }
  604. /**
  605. * getAccountStatus
  606. * @param string $idOrNameAccount account id or account name
  607. * @param string $type value of the account (auto, name, id)
  608. * @return string status
  609. */
  610. function getAccountStatus($idOrNameAccount, $type="auto")
  611. {
  612. return $this->getAccountOption($idOrNameAccount, "zimbraAccountStatus", ATTR_SINGLEVALUE, $type);
  613. }
  614. /**
  615. * setAccountStatus
  616. * @param string $idOrNameAccount account id or account name
  617. * @param string $status the status (active, maintenance, pending, locked, closed)
  618. * @param string $type value of the account (auto, name, id)
  619. * @return array informations
  620. */
  621. function setAccountStatus($idOrNameAccount, $status, $type = "auto")
  622. {
  623. $hideInGAL = ($status == "active") ? "FALSE" : "TRUE";
  624. $attrs = array(
  625. "zimbraAccountStatus"=>$status,
  626. "zimbraHideInGal"=>$hideInGAL,
  627. );
  628. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  629. return $result;
  630. }
  631. /**
  632. * expireAccountSessions
  633. * @param string $idOrNameAccount account id or account name
  634. * @param string $type value of the account (auto, name, id)
  635. * @return array informations
  636. */
  637. function expireAccountSessions($idOrNameAccount, $type = "auto")
  638. {
  639. $attrName = "zimbraAuthTokenValidityValue";
  640. $oldValue = $this->getAccountOption($idOrNameAccount, $attrName);
  641. $newValue = rand($oldValue+1, 1024);
  642. $attrs = array($attrName=>$newValue);
  643. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  644. return $result;
  645. }
  646. /**
  647. * getAccountCos
  648. * @param string $idOrNameAccount account id or account name
  649. * @param string $returnType get the COS ID or NAME
  650. * @param string $type value of the account (auto, name, id)
  651. * @return string COS id or name
  652. */
  653. function getAccountCos($idOrNameAccount, $returnType = "NAME", $type = "auto")
  654. {
  655. if($type == "auto")
  656. $realType = getAccountType($idOrNameAccount);
  657. else
  658. $realType = $type;
  659. if($realType == "name")
  660. $accountId = $this->getAccountId($idOrNameAccount);
  661. else
  662. $accountId = $idOrNameAccount;
  663. $result = null;
  664. $params = array(
  665. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  666. );
  667. try
  668. {
  669. $result = $this->auth->execSoapCall(
  670. "GetAccountInfoRequest",
  671. $params
  672. );
  673. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTINFORESPONSE']['COS'][$returnType];
  674. }
  675. catch (SoapFault $exception)
  676. {
  677. $result = $exception;
  678. }
  679. return $result;
  680. }
  681. /**
  682. * setAccountCos
  683. * @param string $idOrNameAccount account id or account name
  684. * @param string $cosName the COS name
  685. * @param string $type value of the account (auto, name, id)
  686. * @return array informations
  687. */
  688. function setAccountCos($idOrNameAccount, $cosName, $type = "auto")
  689. {
  690. $cosId = $this->getCosId($cosName);
  691. $attrs = array("zimbraCOSId"=>$cosId);
  692. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  693. return $result;
  694. }
  695. /**
  696. * getCosId
  697. * @param string $name the COS name
  698. * @return string COS id
  699. */
  700. function getCosId($name)
  701. {
  702. $result = null;
  703. $params = array(
  704. new SoapVar('<ns1:cos by="name">' . $name . '</ns1:cos>', XSD_ANYXML),
  705. );
  706. try
  707. {
  708. $result = $this->auth->execSoapCall(
  709. "GetCosRequest",
  710. $params
  711. );
  712. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETCOSRESPONSE']['COS']['ID'];
  713. }
  714. catch (SoapFault $exception)
  715. {
  716. $result = $exception;
  717. }
  718. return $result;
  719. }
  720. /**
  721. * getAllCos
  722. * @return array informations
  723. */
  724. function getAllCos()
  725. {
  726. $result = null;
  727. try
  728. {
  729. $result = $this->auth->execSoapCall(
  730. "GetAllCosRequest"
  731. );
  732. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETALLCOSRESPONSE'];
  733. }
  734. catch (SoapFault $exception)
  735. {
  736. $result = $exception;
  737. }
  738. return $result;
  739. }
  740. }
  741. ?>