Alternc  latest
Alternc logiel libre pour l'h├ębergement
 All Classes Namespaces Files Functions Variables Pages
Alternc_Api_Object_Account Class Reference

Account Api of AlternC, used by alternc-api package. More...

+ Inheritance diagram for Alternc_Api_Object_Account:

Public Member Functions

 add ($options)
 API Method from legacy class method admin->add_mem() More...
 
 update ($options)
 API Method from legacy class method admin->update_mem() More...
 
 del ($options)
 API Method from legacy class method admin->del_mem() More...
 
 lock ($options)
 API Method from legacy class method admin->lock_mem() More...
 
 unlock ($options)
 API Method from legacy class method admin->unlock_mem() More...
 
 setAdmin ($options)
 API Method from legacy class method admin->normal2su() More...
 
 unsetAdmin ($options)
 API Method from legacy class method admin->su2normal() More...
 
 find ($options)
 API Method from legacy class method admin->get_list() More...
 

Public Attributes

const ERR_INVALID_ARGUMENT = 111201
 
const ERR_ALTERNC_FUNCTION = 111202
 
const ERR_NOT_FOUND = 111203
 

Protected Member Functions

 alterncLegacyErrorManager ()
 return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class More...
 
 offsetAndCount ($options, $max)
 ensure that offset & count are set properly from $options. More...
 

Protected Attributes

 $admin
 
 $cuid
 
 $isAdmin
 
 $db
 

Detailed Description

Account Api of AlternC, used by alternc-api package.

Definition at line 6 of file Account.php.

Member Function Documentation

Alternc_Api_Object_Account::add (   $options)

API Method from legacy class method admin->add_mem()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: login, pass, nom, prenom, mail, non-mandatory: canpass, type, duration, notes, force, create_dom, db_server_id
Returns
Alternc_Api_Response whose content is the newly created UID

Definition at line 14 of file Account.php.

References $key, $uid, $value, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

14  {
15  $mandatory = array("login", "pass", "nom", "prenom", "mail");
16  $defaults = array("canpass" => 1, "type" => "default", "duration" => 0, "notes" => "", "force" => 0, "create_dom" => "");
17  $missing = "";
18  foreach ($mandatory as $key) {
19  if (!isset($options[$key])) {
20  $missing.=$key . " ";
21  }
22  }
23  if ($missing) {
24  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
25  }
26  foreach ($defaults as $key => $value) {
27  if (!isset($options[$key])) {
28  $options[$key] = $value;
29  }
30  }
31  if (!isset($options["db_server_id"])) {
32  $stmt = $this->db->prepare("SELECT MIN(db_servers.id) AS id FROM db_servers;");
33  $stmt->execute();
34  $me = $stmt->fetch(PDO::FETCH_OBJ);
35  $options["db_server_id"] = $me->id;
36  }
37  $uid = $this->admin->add_mem($options["login"], $options["pass"], $options["nom"], $options["prenom"], $options["mail"], $options["canpass"], $options["type"], $options["duration"], $options["notes"], $options["force"], $options["create_dom"], $options["db_server_id"]);
38  if (!$uid) {
39  return $this->alterncLegacyErrorManager();
40  } else {
41  return new Alternc_Api_Response(array("content" => $uid));
42  }
43  }
$uid
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
$value
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Legacyobject::alterncLegacyErrorManager ( )
protectedinherited

return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class

Definition at line 38 of file Legacyobject.php.

References $err.

Referenced by Alternc_Api_Object_Mail\account(), add(), Alternc_Api_Object_Ftp\add(), Alternc_Api_Object_Mysql\add(), Alternc_Api_Object_Domain\add(), Alternc_Api_Object_Ssl\aliasAdd(), Alternc_Api_Object_Ssl\aliasDel(), Alternc_Api_Object_Policy\check(), Alternc_Api_Object_Mail\create(), Alternc_Api_Object_Ftp\del(), del(), Alternc_Api_Object_Mysql\del(), Alternc_Api_Object_Domain\del(), Alternc_Api_Object_Mail\delete(), Alternc_Api_Object_Mail\disable(), Alternc_Api_Object_Mail\enable(), Alternc_Api_Object_Ssl\finalize(), Alternc_Api_Object_Policy\find(), Alternc_Api_Object_Ftp\find(), find(), Alternc_Api_Object_Mysql\find(), Alternc_Api_Object_Subdomain\get(), Alternc_Api_Object_Domain\get(), Alternc_Api_Object_Mail\get(), Alternc_Api_Object_Mail\getAll(), Alternc_Api_Object_Ssl\getCertificate(), Alternc_Api_Object_Ssl\importCert(), Alternc_Api_Object_Mail\isAvailable(), Alternc_Api_Object_Ftp\isFtp(), Alternc_Api_Object_Mail\listDomains(), lock(), Alternc_Api_Object_Mysql\lock(), Alternc_Api_Object_Ssl\newCsr(), Alternc_Api_Object_Mail\passwd(), Alternc_Api_Object_Subdomain\set(), setAdmin(), Alternc_Api_Object_Mysql\setAdmin(), Alternc_Api_Object_Ssl\share(), Alternc_Api_Object_Mail\undelete(), unlock(), Alternc_Api_Object_Mysql\unlock(), unsetAdmin(), Alternc_Api_Object_Mysql\unsetAdmin(), Alternc_Api_Object_Policy\update(), Alternc_Api_Object_Ftp\update(), update(), Alternc_Api_Object_Mysql\update(), Alternc_Api_Object_Domain\update(), and Alternc_Api_Object_Mail\update().

38  {
39  global $err;
40  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "[" . $err->clsid . "] " . $err->error));
41  }
$err
Definition: bootstrap.php:72
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::del (   $options)

API Method from legacy class method admin->del_mem()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: uid
Returns
Alternc_Api_Response TRUE if the account has been deleted.

Definition at line 82 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

82  {
83  if (!isset($options["uid"])) {
84  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
85  }
86  $result = $this->admin->del_mem(intval($options["uid"]));
87  if (!$result) {
88  return $this->alterncLegacyErrorManager();
89  } else {
90  return new Alternc_Api_Response(array("content" => true));
91  }
92  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::find (   $options)

API Method from legacy class method admin->get_list()

Parameters
$optionsa hash with parameters transmitted to legacy call non-mandatory parameters: ONE OF: uid(strict), login(like %%), domain(like %%), creator(strict, by uid), Any of: offset(int=0), count(int=+inf)
Returns
Alternc_Api_Response An array with all matching users informations as hashes

Definition at line 169 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager(), and Alternc_Api_Legacyobject\offsetAndCount().

169  {
170  $result = false;
171  if (!$result && isset($options["uid"])) {
172  $result = $this->admin->get(intval($options["uid"]));
173  if ($result)
174  $result = array($result);
175  }
176  if (!$result && isset($options["login"])) {
177  $result = $this->admin->get_list(1/* ALL */, "", $options["login"], "login");
178  }
179  if (!$result && isset($options["domain"])) {
180  $result = $this->admin->get_list(1/* ALL */, "", $options["domain"], "domaine");
181  }
182  if (!$result && isset($options["creator"])) {
183  $result = $this->admin->get_list(1/* ALL */, intval($options["creator"]));
184  }
185  if (!$result) { // everybody
186  $result = $this->admin->get_list(1/* ALL */, "");
187  }
188 
189  if (!$result) {
190  return $this->alterncLegacyErrorManager();
191  } else {
192  list($offset, $count) = $this->offsetAndCount($options, count($result));
193  if ($offset != -1 || $count != -1) {
194  $result = array_slice($result, $offset, $count);
195  }
196  return new Alternc_Api_Response(array("content" => $result));
197  }
198  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
offsetAndCount($options, $max)
ensure that offset & count are set properly from $options.
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::lock (   $options)

API Method from legacy class method admin->lock_mem()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: uid
Returns
Alternc_Api_Response TRUE if the account has been locked

Definition at line 99 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

99  {
100  if (!isset($options["uid"])) {
101  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
102  }
103  $result = $this->admin->lock_mem(intval($options["uid"]));
104  if (!$result) {
105  return $this->alterncLegacyErrorManager();
106  } else {
107  return new Alternc_Api_Response(array("content" => true));
108  }
109  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Legacyobject::offsetAndCount (   $options,
  $max 
)
protectedinherited

ensure that offset & count are set properly from $options.

Definition at line 45 of file Legacyobject.php.

Referenced by Alternc_Api_Object_Domain\find(), Alternc_Api_Object_Ftp\find(), find(), and Alternc_Api_Object_Mysql\find().

45  {
46  $offset = -1;
47  $count = -1;
48  if (isset($options["count"]))
49  $count = intval($options["count"]);
50  if (isset($options["offset"]))
51  $offset = intval($options["offset"]);
52  if ($offset != -1 || $count != -1) {
53  if ($offset < 0 || $offset > $max)
54  $offset = 0;
55  if ($count < 0 || $count > 1000)
56  $count = 1000;
57  }
58  return array($offset, $count);
59  }
Alternc_Api_Object_Account::setAdmin (   $options)

API Method from legacy class method admin->normal2su()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: uid
Returns
Alternc_Api_Response TRUE if the account has been set to be an administator

Definition at line 133 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

133  {
134  if (!isset($options["uid"])) {
135  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
136  }
137  $result = $this->admin->normal2su(intval($options["uid"]));
138  if (!$result) {
139  return $this->alterncLegacyErrorManager();
140  } else {
141  return new Alternc_Api_Response(array("content" => true));
142  }
143  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::unlock (   $options)

API Method from legacy class method admin->unlock_mem()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: uid
Returns
Alternc_Api_Response TRUE if the account has been unlocked

Definition at line 116 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

116  {
117  if (!isset($options["uid"])) {
118  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
119  }
120  $result = $this->admin->unlock_mem(intval($options["uid"]));
121  if (!$result) {
122  return $this->alterncLegacyErrorManager();
123  } else {
124  return new Alternc_Api_Response(array("content" => true));
125  }
126  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::unsetAdmin (   $options)

API Method from legacy class method admin->su2normal()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: uid
Returns
Alternc_Api_Response TRUE if the account has been set to NOT be an administrator

Definition at line 150 of file Account.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

150  {
151  if (!isset($options["uid"])) {
152  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
153  }
154  $result = $this->admin->su2normal(intval($options["uid"]));
155  if (!$result) {
156  return $this->alterncLegacyErrorManager();
157  } else {
158  return new Alternc_Api_Response(array("content" => true));
159  }
160  }
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Object_Account::update (   $options)

API Method from legacy class method admin->update_mem()

Parameters
$optionsa hash with parameters transmitted to legacy call mandatory parameters: nom, prenom, mail, non-mandatory: pass, canpass, type, duration, notes, force, create_dom, db_server_id
Returns
Alternc_Api_Response whose content is the updated UID

Definition at line 51 of file Account.php.

References $key, $uid, and Alternc_Api_Legacyobject\alterncLegacyErrorManager().

51  {
52  $defaults = array("nom", "prenom", "mail", "canpass", "enabled", "type", "duration", "notes");
53  if (!isset($options["uid"])) {
54  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: UID"));
55  }
56  $uid = intval($options["uid"]);
57  $old = $this->admin->get($uid);
58  if (!$old) {
59  return new Alternc_Api_Response(array("code" => self::ERR_NOT_FOUND, "message" => "User not found"));
60  }
61 
62  foreach ($defaults as $key) {
63  if (!isset($options[$key])) {
64  $options[$key] = $old[$key];
65  }
66  }
67  if (!isset($options["pass"]))
68  $options["pass"] = "";
69  $uid = $this->admin->update_mem($uid, $options["mail"], $options["nom"], $options["prenom"], $options["pass"], $options["enabled"], $options["canpass"], $options["type"], $options["duration"], $options["notes"]);
70  if (!$uid) {
71  return $this->alterncLegacyErrorManager();
72  } else {
73  return new Alternc_Api_Response(array("content" => $uid));
74  }
75  }
$uid
alterncLegacyErrorManager()
return a proper Alternc_Api_Response from an error class and error string from AlternC legacy class ...
if(empty($_POST['key'])||empty($_POST['val'])) $key
Definition: tempovars.php:14
Standard Response object for the AlternC API.
Definition: Response.php:7

Member Data Documentation

Alternc_Api_Legacyobject::$admin
protectedinherited

Definition at line 11 of file Legacyobject.php.

Referenced by Alternc_Api_Legacyobject\__construct().

Alternc_Api_Legacyobject::$db
protectedinherited

Definition at line 14 of file Legacyobject.php.

Alternc_Api_Legacyobject::$isAdmin
protectedinherited

Definition at line 13 of file Legacyobject.php.

Referenced by Alternc_Api_Legacyobject\__construct().

const Alternc_Api_Legacyobject::ERR_ALTERNC_FUNCTION = 111202
inherited

Definition at line 17 of file Legacyobject.php.

const Alternc_Api_Legacyobject::ERR_INVALID_ARGUMENT = 111201
inherited

Definition at line 16 of file Legacyobject.php.

const Alternc_Api_Legacyobject::ERR_NOT_FOUND = 111203
inherited

Definition at line 18 of file Legacyobject.php.


The documentation for this class was generated from the following file: