Account.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  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. }
  224. return (!is_a($result, "Exception"));
  225. }
  226. /**
  227. * getAccountInfo
  228. * @param string $idOrNameAccount account id or account name
  229. * @param string $type value of the account (auto, name, id)
  230. * @return array informations
  231. */
  232. function getAccountInfo($idOrNameAccount, $type="auto")
  233. {
  234. if($type == "auto")
  235. $realType = getAccountType($idOrNameAccount);
  236. else
  237. $realType = $type;
  238. $result = null;
  239. $params = array(
  240. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  241. );
  242. try
  243. {
  244. $result = $this->auth->execSoapCall(
  245. "GetAccountInfoRequest",
  246. $params
  247. );
  248. }
  249. catch (SoapFault $exception)
  250. {
  251. $result = $exception;
  252. }
  253. return $result;
  254. }
  255. /**
  256. * getMailboxInfo
  257. * @param string $name account name
  258. * @return string account informations
  259. */
  260. function getMailboxInfo($name)
  261. {
  262. $result = null;
  263. $params = array(
  264. new SoapVar('<ns1:account by="name">' . $name . '</ns1:account>', XSD_ANYXML),
  265. );
  266. try
  267. {
  268. $result = $this->auth->execSoapCall(
  269. "GetMailboxInfoRequest",
  270. $params
  271. );
  272. $result = $result['SOAP:ENVELOPE']['SOAP:BODY'];
  273. }
  274. catch (SoapFault $exception)
  275. {
  276. $result = $exception;
  277. }
  278. return $result;
  279. }
  280. /**
  281. * getAccountOption
  282. * @param string $idOrNameAccount account id or account name
  283. * @param string $optName name of the option to get
  284. * @param int $multisingle (ATTR_SINGLEVALUE, ATTR_MULTIVALUE)
  285. * @param string $type value of the account (auto, name, id)
  286. * @return string option
  287. */
  288. function getAccountOption($idOrNameAccount, $optName, $multisingle=ATTR_SINGLEVALUE, $type="auto")
  289. {
  290. if($type == "auto")
  291. $realType = getAccountType($idOrNameAccount);
  292. else
  293. $realType = $type;
  294. $result = null;
  295. $params = array(
  296. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  297. );
  298. try
  299. {
  300. $result = $this->auth->execSoapCall(
  301. "GetAccountRequest",
  302. $params
  303. );
  304. $result = getSoapAttribute($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT']['A'], $optName, $multisingle);
  305. }
  306. catch (SoapFault $exception)
  307. {
  308. $result = $exception;
  309. }
  310. return $result;
  311. }
  312. /**
  313. * getAccountOptions
  314. * @param string $idOrNameAccount account id or account name
  315. * @param string $type value of the account (auto, name, id)
  316. * @return array options
  317. */
  318. function getAccountOptions($idOrNameAccount, $type="auto")
  319. {
  320. if($type == "auto")
  321. $realType = getAccountType($idOrNameAccount);
  322. else
  323. $realType = $type;
  324. $result = null;
  325. $params = array(
  326. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  327. );
  328. try
  329. {
  330. $result = $this->auth->execSoapCall(
  331. "GetAccountRequest",
  332. $params
  333. );
  334. $attrs = array();
  335. foreach ($result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTRESPONSE']['ACCOUNT']['A'] as $a) {
  336. $attrs[$a['N']] = $a['DATA'];
  337. }
  338. $result = $attrs;
  339. }
  340. catch (SoapFault $exception)
  341. {
  342. $result = $exception;
  343. }
  344. return $result;
  345. }
  346. /**
  347. * createAccount
  348. * @param string $name account name
  349. * @param string $password password
  350. * @param array $attrs an optional array containing the account attributes to be set
  351. * @return string the new account's id
  352. */
  353. function createAccount($name, $password, $attrs = array())
  354. {
  355. $result = null;
  356. $params = array(
  357. new SoapParam($name, "name"),
  358. new SoapParam($password, "password"),
  359. );
  360. foreach ($attrs as $key=>$value)
  361. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  362. try
  363. {
  364. $result = $this->auth->execSoapCall(
  365. "CreateAccountRequest",
  366. $params
  367. );
  368. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID'];
  369. usleep(250000); // introduce a small delay, otherwise some troubles may arise if we modify the new account right after its creation
  370. }
  371. catch (SoapFault $exception)
  372. {
  373. $result = $exception;
  374. }
  375. return $result;
  376. }
  377. /**
  378. * setAccountPassword
  379. * @param string $idOrNameAccount account id or account name
  380. * @param string $password password
  381. * @param string $type value of the account (auto, name, id)
  382. * @return array informations
  383. */
  384. function setAccountPassword($idOrNameAccount, $password, $type="auto")
  385. {
  386. if($type == "auto")
  387. $realType = getAccountType($idOrNameAccount);
  388. else
  389. $realType = $type;
  390. if($realType == "name")
  391. $accountId = $this->getAccountId($idOrNameAccount);
  392. else
  393. $accountId = $idOrNameAccount;
  394. $result = null;
  395. $params = array(
  396. new SoapParam($accountId, "id"),
  397. new SoapParam($password, "newPassword"),
  398. );
  399. try
  400. {
  401. $result = $this->auth->execSoapCall(
  402. "SetPasswordRequest",
  403. $params
  404. );
  405. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['SETPASSWORDRESPONSE'];
  406. }
  407. catch (SoapFault $exception)
  408. {
  409. $result = $exception;
  410. }
  411. return $result;
  412. }
  413. /**
  414. * modifyAccount
  415. * @param string $idOrNameAccount account id or account name
  416. * @param array $attrs an array containing the account attributes to be set
  417. * @param string $type value of the account (auto, name, id)
  418. * @return array informations
  419. */
  420. function modifyAccount($idOrNameAccount, $attrs = array(), $type="auto")
  421. {
  422. if($type == "auto")
  423. $realType = getAccountType($idOrNameAccount);
  424. else
  425. $realType = $type;
  426. if($realType == "name")
  427. $accountId = $this->getAccountId($idOrNameAccount);
  428. else
  429. $accountId = $idOrNameAccount;
  430. $result = null;
  431. $params = array(
  432. new SoapParam($accountId, "id"),
  433. );
  434. foreach ($attrs as $key=>$value)
  435. $params[] = new SoapVar('<ns1:a n="' . $key . '">' . $value . '</ns1:a>', XSD_ANYXML);
  436. try
  437. {
  438. $result = $this->auth->execSoapCall(
  439. "ModifyAccountRequest",
  440. $params
  441. );
  442. }
  443. catch (SoapFault $exception)
  444. {
  445. $result = $exception;
  446. }
  447. return $result;
  448. }
  449. /**
  450. * renameAccount
  451. * @param string $idOrNameAccount account id or account name
  452. * @param string $newName new account name
  453. * @param string $type value of the account (auto, name, id)
  454. * @return array informations
  455. */
  456. function renameAccount($idOrNameAccount, $newName, $type="auto")
  457. {
  458. if($type == "auto")
  459. $realType = getAccountType($idOrNameAccount);
  460. else
  461. $realType = $type;
  462. if($realType == "name")
  463. $accountId = $this->getAccountId($idOrNameAccount);
  464. else
  465. $accountId = $idOrNameAccount;
  466. $result = null;
  467. $params = array(
  468. new SoapParam($accountId, "id"),
  469. new SoapParam($newName, "newName"),
  470. );
  471. try
  472. {
  473. $result = $this->auth->execSoapCall(
  474. "RenameAccountRequest",
  475. $params
  476. );
  477. }
  478. catch (SoapFault $exception)
  479. {
  480. $result = $exception;
  481. }
  482. return $result;
  483. }
  484. /**
  485. * deleteAccount
  486. * @param string $idOrNameAccount account id or account name
  487. * @param string $type value of the account (auto, name, id)
  488. * @return array informations
  489. */
  490. function deleteAccount($idOrNameAccount, $type="auto")
  491. {
  492. if($type == "auto")
  493. $realType = getAccountType($idOrNameAccount);
  494. else
  495. $realType = $type;
  496. if($realType == "name")
  497. $accountId = $this->getAccountId($idOrNameAccount);
  498. else
  499. $accountId = $idOrNameAccount;
  500. $result = null;
  501. $params = array(
  502. new SoapParam($accountId, "id"),
  503. );
  504. try
  505. {
  506. $result = $this->auth->execSoapCall(
  507. "DeleteAccountRequest",
  508. $params
  509. );
  510. }
  511. catch (SoapFault $exception)
  512. {
  513. $result = $exception;
  514. }
  515. return $result;
  516. }
  517. /**
  518. * getAccountAliases
  519. * @param string $idOrNameAccount account id or account name
  520. * @param string $type value of the account (auto, name, id)
  521. * @return array aliases
  522. */
  523. function getAccountAliases($idOrNameAccount, $type="auto")
  524. {
  525. return $this->getAccountOption($idOrNameAccount, "zimbraMailAlias", ATTR_MULTIVALUE, $type);
  526. }
  527. /**
  528. * addAccountAlias
  529. * @param string $idOrNameAccount account id or account name
  530. * @param string $alias account alias
  531. * @param string $type value of the account (auto, name, id)
  532. * @return array informations
  533. */
  534. function addAccountAlias($idOrNameAccount, $alias, $type="auto")
  535. {
  536. if($type == "auto")
  537. $realType = getAccountType($idOrNameAccount);
  538. else
  539. $realType = $type;
  540. if($realType == "name")
  541. $accountId = $this->getAccountId($idOrNameAccount);
  542. else
  543. $accountId = $idOrNameAccount;
  544. $result = null;
  545. $params = array(
  546. new SoapParam($accountId, "id"),
  547. new SoapParam($alias, "alias"),
  548. );
  549. try
  550. {
  551. $result = $this->auth->execSoapCall(
  552. "AddAccountAliasRequest",
  553. $params
  554. );
  555. }
  556. catch (SoapFault $exception)
  557. {
  558. $result = $exception;
  559. }
  560. return $result;
  561. }
  562. /**
  563. * removeAccountAlias
  564. * @param string $idOrNameAccount account id or account name
  565. * @param string $alias account alias
  566. * @param string $type value of the account (auto, name, id)
  567. * @return array informations
  568. */
  569. function removeAccountAlias($idOrNameAccount, $alias, $type="auto")
  570. {
  571. if($type == "auto")
  572. $realType = getAccountType($idOrNameAccount);
  573. else
  574. $realType = $type;
  575. if($realType == "name")
  576. $accountId = $this->getAccountId($idOrNameAccount);
  577. else
  578. $accountId = $idOrNameAccount;
  579. $result = null;
  580. $params = array(
  581. new SoapParam($accountId, "id"),
  582. new SoapParam($alias, "alias"),
  583. );
  584. try
  585. {
  586. $result = $this->auth->execSoapCall(
  587. "RemoveAccountAliasRequest",
  588. $params
  589. );
  590. }
  591. catch (SoapFault $exception)
  592. {
  593. $result = $exception;
  594. }
  595. return $result;
  596. }
  597. /**
  598. * getAccountStatus
  599. * @param string $idOrNameAccount account id or account name
  600. * @param string $type value of the account (auto, name, id)
  601. * @return string status
  602. */
  603. function getAccountStatus($idOrNameAccount, $type="auto")
  604. {
  605. return $this->getAccountOption($idOrNameAccount, "zimbraAccountStatus", ATTR_SINGLEVALUE, $type);
  606. }
  607. /**
  608. * setAccountStatus
  609. * @param string $idOrNameAccount account id or account name
  610. * @param string $status the status (active, maintenance, pending, locked, closed)
  611. * @param string $type value of the account (auto, name, id)
  612. * @return array informations
  613. */
  614. function setAccountStatus($idOrNameAccount, $status, $type = "auto")
  615. {
  616. $hideInGAL = ($status == "active") ? "FALSE" : "TRUE";
  617. $attrs = array(
  618. "zimbraAccountStatus"=>$status,
  619. "zimbraHideInGal"=>$hideInGAL,
  620. );
  621. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  622. return $result;
  623. }
  624. /**
  625. * expireAccountSessions
  626. * @param string $idOrNameAccount account id or account name
  627. * @param string $type value of the account (auto, name, id)
  628. * @return array informations
  629. */
  630. function expireAccountSessions($idOrNameAccount, $type = "auto")
  631. {
  632. $attrName = "zimbraAuthTokenValidityValue";
  633. $oldValue = $this->getAccountOption($idOrNameAccount, $attrName);
  634. $newValue = rand($oldValue+1, 1024);
  635. $attrs = array($attrName=>$newValue);
  636. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  637. return $result;
  638. }
  639. /**
  640. * getAccountCos
  641. * @param string $idOrNameAccount account id or account name
  642. * @param string $returnType get the COS ID or NAME
  643. * @param string $type value of the account (auto, name, id)
  644. * @return string COS id or name
  645. */
  646. function getAccountCos($idOrNameAccount, $returnType = "NAME", $type = "auto")
  647. {
  648. if($type == "auto")
  649. $realType = getAccountType($idOrNameAccount);
  650. else
  651. $realType = $type;
  652. if($realType == "name")
  653. $accountId = $this->getAccountId($idOrNameAccount);
  654. else
  655. $accountId = $idOrNameAccount;
  656. $result = null;
  657. $params = array(
  658. new SoapVar('<ns1:account by="' . $realType . '">' . $idOrNameAccount . '</ns1:account>', XSD_ANYXML),
  659. );
  660. try
  661. {
  662. $result = $this->auth->execSoapCall(
  663. "GetAccountInfoRequest",
  664. $params
  665. );
  666. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETACCOUNTINFORESPONSE']['COS'][$returnType];
  667. }
  668. catch (SoapFault $exception)
  669. {
  670. $result = $exception;
  671. }
  672. return $result;
  673. }
  674. /**
  675. * setAccountCos
  676. * @param string $idOrNameAccount account id or account name
  677. * @param string $cosName the COS name
  678. * @param string $type value of the account (auto, name, id)
  679. * @return array informations
  680. */
  681. function setAccountCos($idOrNameAccount, $cosName, $type = "auto")
  682. {
  683. $cosId = $this->getCosId($cosName);
  684. $attrs = array("zimbraCOSId"=>$cosId);
  685. $result = $this->modifyAccount($idOrNameAccount, $attrs, $type);
  686. return $result;
  687. }
  688. /**
  689. * getCosId
  690. * @param string $name the COS name
  691. * @return string COS id
  692. */
  693. function getCosId($name)
  694. {
  695. $result = null;
  696. $params = array(
  697. new SoapVar('<ns1:cos by="name">' . $name . '</ns1:cos>', XSD_ANYXML),
  698. );
  699. try
  700. {
  701. $result = $this->auth->execSoapCall(
  702. "GetCosRequest",
  703. $params
  704. );
  705. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETCOSRESPONSE']['COS']['ID'];
  706. }
  707. catch (SoapFault $exception)
  708. {
  709. $result = $exception;
  710. }
  711. return $result;
  712. }
  713. /**
  714. * getAllCos
  715. * @return array informations
  716. */
  717. function getAllCos()
  718. {
  719. $result = null;
  720. try
  721. {
  722. $result = $this->auth->execSoapCall(
  723. "GetAllCosRequest"
  724. );
  725. $result = $result['SOAP:ENVELOPE']['SOAP:BODY']['GETALLCOSRESPONSE'];
  726. }
  727. catch (SoapFault $exception)
  728. {
  729. $result = $exception;
  730. }
  731. return $result;
  732. }
  733. }
  734. ?>