Alternc  latest
Alternc logiel libre pour l'hébergement
Subdomain.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Subdomain Api of AlternC, used by alternc-api package
5  */
7 
8  protected $dom; // m_dom instance
9 
10  function __construct($service) {
11  global $dom;
12  parent::__construct($service);
13  $this->dom = $dom;
14  }
15 
16  /** API Method from legacy class method dom->get_sub_domain_all($dom)
17  * @param $options a hash with parameters transmitted to legacy call
18  * musr be the subdomain id ID
19  * @return Alternc_Api_Response whose content is the list of subdomains on this server
20  */
21  function get($options) {
22  global $cuid;
23  if ($this->isAdmin) {
24  if (isset($options["uid"])) {
25  $cuid = intval($options["uid"]);
26  }
27  }
28  $mandatory = array("id");
29  $missing = "";
30  foreach ($mandatory as $key) {
31  if (!isset($options[$key])) {
32  $missing.=$key . " ";
33  }
34  }
35  if ($missing) {
36  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
37  }
38  $this->dom->lock();
39  $did = $this->dom->get_sub_domain_all($options["id"]);
40  $this->dom->unlock();
41  if (!$did) {
42  return $this->alterncLegacyErrorManager();
43  } else {
44  return new Alternc_Api_Response(array("content" => $did));
45  }
46  }
47 
48  /** API Method from legacy class method dom->set_sub_domain($dom)
49  * @param $options a hash with parameters transmitted to legacy call
50  * must be $dom, $sub, $type, $dest and could be $sub_domain_id
51  * @return Alternc_Api_Response whose content is true or false
52  * if the change has been made
53  */
54  function set($options) {
55  global $cuid;
56  if ($this->isAdmin) {
57  if (isset($options["uid"])) {
58  $cuid = intval($options["uid"]);
59  }
60  }
61  $mandatory = array("dom", "sub", "type", "dest");
62  $defaults = array("sub_domain_id" => null);
63  $missing = "";
64  foreach ($mandatory as $key) {
65  if (!isset($options[$key])) {
66  $missing.=$key . " ";
67  }
68  }
69  foreach ($defaults as $key => $value) {
70  if (!isset($options[$key])) {
71  $options[$key] = $value;
72  }
73  }
74  if ($missing) {
75  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
76  }
77  $this->dom->lock();
78  $did = $this->dom->set_sub_domain($options["dom"], $options["sub"], $options["type"], $options["dest"], $options["sub_domain_id"]);
79  $this->dom->unlock();
80  if (!$did) {
81  return $this->alterncLegacyErrorManager();
82  } else {
83  return new Alternc_Api_Response(array("content" => $did));
84  }
85  }
86 
87 }
88 
89 // class Alternc_Api_Object_Subdomain
Any Legacy AlternC Api should use this class as a parent to be able to handle properly the access rig...
Definition: Legacyobject.php:9
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class
Subdomain Api of AlternC, used by alternc-api package.
Definition: Subdomain.php:6
Standard Response object for the AlternC API.
Definition: Response.php:7
$value
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14