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

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

+ Inheritance diagram for Alternc_Api_Object_Mysql:

Public Member Functions

 __construct ($service)
 
 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

 $mysql
 
 $admin
 
 $cuid
 
 $isAdmin
 
 $db
 

Detailed Description

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

Definition at line 6 of file Mysql.php.

Constructor & Destructor Documentation

Alternc_Api_Object_Mysql::__construct (   $service)

Definition at line 10 of file Mysql.php.

References $mysql.

10  {
11  global $mysql;
12  parent::__construct($service);
13  $this->mysql = $mysql;
14  }

Member Function Documentation

Alternc_Api_Object_Mysql::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 22 of file Mysql.php.

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

22  {
23  $mandatory = array("login", "pass", "nom", "prenom", "mail");
24  $defaults = array("canpass" => 1, "type" => "default", "duration" => 0, "notes" => "", "force" => 0, "create_dom" => "");
25  $missing = "";
26  foreach ($mandatory as $key) {
27  if (!isset($options[$key])) {
28  $missing.=$key . " ";
29  }
30  }
31  if ($missing) {
32  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: " . $missing));
33  }
34  foreach ($defaults as $key => $value) {
35  if (!isset($options[$key])) {
36  $options[$key] = $value;
37  }
38  }
39  if (!isset($options["db_server_id"])) {
40  $stmt = $this->db->prepare("SELECT MIN(db_servers.id) AS id FROM db_servers;");
41  $stmt->execute();
42  $me = $stmt->fetch(PDO::FETCH_OBJ);
43  $options["db_server_id"] = $me->id;
44  }
45  $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"]);
46  if (!$uid) {
47  return $this->alterncLegacyErrorManager();
48  } else {
49  return new Alternc_Api_Response(array("content" => $uid));
50  }
51  }
$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(), Alternc_Api_Object_Account\add(), Alternc_Api_Object_Ftp\add(), 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(), Alternc_Api_Object_Account\del(), 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(), Alternc_Api_Object_Account\find(), 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(), Alternc_Api_Object_Account\lock(), lock(), Alternc_Api_Object_Ssl\newCsr(), Alternc_Api_Object_Mail\passwd(), Alternc_Api_Object_Subdomain\set(), Alternc_Api_Object_Account\setAdmin(), setAdmin(), Alternc_Api_Object_Ssl\share(), Alternc_Api_Object_Mail\undelete(), Alternc_Api_Object_Account\unlock(), unlock(), Alternc_Api_Object_Account\unsetAdmin(), unsetAdmin(), Alternc_Api_Object_Policy\update(), Alternc_Api_Object_Ftp\update(), Alternc_Api_Object_Account\update(), 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_Mysql::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 90 of file Mysql.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

90  {
91  if (!isset($options["uid"])) {
92  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
93  }
94  $result = $this->admin->del_mem(intval($options["uid"]));
95  if (!$result) {
96  return $this->alterncLegacyErrorManager();
97  } else {
98  return new Alternc_Api_Response(array("content" => true));
99  }
100  }
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_Mysql::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 177 of file Mysql.php.

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

177  {
178  $result = false;
179  if (!$result && isset($options["uid"])) {
180  $result = $this->admin->get(intval($options["uid"]));
181  if ($result)
182  $result = array($result);
183  }
184  if (!$result && isset($options["login"])) {
185  $result = $this->admin->get_list(1/* ALL */, "", $options["login"], "login");
186  }
187  if (!$result && isset($options["domain"])) {
188  $result = $this->admin->get_list(1/* ALL */, "", $options["domain"], "domaine");
189  }
190  if (!$result && isset($options["creator"])) {
191  $result = $this->admin->get_list(1/* ALL */, intval($options["creator"]));
192  }
193  if (!$result) { // everybody
194  $result = $this->admin->get_list(1/* ALL */, "");
195  }
196 
197  if (!$result) {
198  return $this->alterncLegacyErrorManager();
199  } else {
200  list($offset, $count) = $this->offsetAndCount($options, count($result));
201  if ($offset != -1 || $count != -1) {
202  $result = array_slice($result, $offset, $count);
203  }
204  return new Alternc_Api_Response(array("content" => $result));
205  }
206  }
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_Mysql::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 107 of file Mysql.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

107  {
108  if (!isset($options["uid"])) {
109  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
110  }
111  $result = $this->admin->lock_mem(intval($options["uid"]));
112  if (!$result) {
113  return $this->alterncLegacyErrorManager();
114  } else {
115  return new Alternc_Api_Response(array("content" => true));
116  }
117  }
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(), Alternc_Api_Object_Account\find(), and 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_Mysql::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 141 of file Mysql.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

141  {
142  if (!isset($options["uid"])) {
143  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
144  }
145  $result = $this->admin->normal2su(intval($options["uid"]));
146  if (!$result) {
147  return $this->alterncLegacyErrorManager();
148  } else {
149  return new Alternc_Api_Response(array("content" => true));
150  }
151  }
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_Mysql::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 124 of file Mysql.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

124  {
125  if (!isset($options["uid"])) {
126  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
127  }
128  $result = $this->admin->unlock_mem(intval($options["uid"]));
129  if (!$result) {
130  return $this->alterncLegacyErrorManager();
131  } else {
132  return new Alternc_Api_Response(array("content" => true));
133  }
134  }
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_Mysql::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 158 of file Mysql.php.

References Alternc_Api_Legacyobject\alterncLegacyErrorManager().

158  {
159  if (!isset($options["uid"])) {
160  return new Alternc_Api_Response(array("code" => self::ERR_ALTERNC_FUNCTION, "message" => "Missing or invalid argument: UID"));
161  }
162  $result = $this->admin->su2normal(intval($options["uid"]));
163  if (!$result) {
164  return $this->alterncLegacyErrorManager();
165  } else {
166  return new Alternc_Api_Response(array("content" => true));
167  }
168  }
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_Mysql::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 59 of file Mysql.php.

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

59  {
60  $defaults = array("nom", "prenom", "mail", "canpass", "enabled", "type", "duration", "notes");
61  if (!isset($options["uid"])) {
62  return new Alternc_Api_Response(array("code" => self::ERR_INVALID_ARGUMENT, "message" => "Missing or invalid argument: UID"));
63  }
64  $uid = intval($options["uid"]);
65  $old = $this->admin->get($uid);
66  if (!$old) {
67  return new Alternc_Api_Response(array("code" => self::ERR_NOT_FOUND, "message" => "User not found"));
68  }
69 
70  foreach ($defaults as $key) {
71  if (!isset($options[$key])) {
72  $options[$key] = $old[$key];
73  }
74  }
75  if (!isset($options["pass"]))
76  $options["pass"] = "";
77  $uid = $this->admin->update_mem($uid, $options["mail"], $options["nom"], $options["prenom"], $options["pass"], $options["enabled"], $options["canpass"], $options["type"], $options["duration"], $options["notes"]);
78  if (!$uid) {
79  return $this->alterncLegacyErrorManager();
80  } else {
81  return new Alternc_Api_Response(array("content" => $uid));
82  }
83  }
$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().

Alternc_Api_Object_Mysql::$mysql
protected

Definition at line 8 of file Mysql.php.

Referenced by __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: