summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Conf.php178
-rw-r--r--lib/SQL.php101
-rw-r--r--lib/User.php169
-rw-r--r--lib/api/kolab_domains_actions.php4
-rw-r--r--lib/api/kolab_form_value_actions.php220
-rw-r--r--lib/api/kolab_group_actions.php175
-rw-r--r--lib/api/kolab_group_types_actions.php53
-rw-r--r--lib/api/kolab_user_actions.php160
-rw-r--r--lib/api/kolab_user_types_actions.php53
9 files changed, 564 insertions, 549 deletions
diff --git a/lib/Conf.php b/lib/Conf.php
index af3769b..2fbe9d1 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -1,116 +1,118 @@
<?php
- class Conf {
- static private $instance;
-
- /**
- * This implements the 'singleton' design pattern
- *
- * @return Conf The one and only instance
- */
- static function get_instance()
- {
- if (!self::$instance) {
- self::$instance = new Conf();
- }
-
- return self::$instance;
+class Conf {
+ static private $instance;
+
+ /**
+ * This implements the 'singleton' design pattern
+ *
+ * @return Conf The one and only instance
+ */
+ static function get_instance()
+ {
+ if (!self::$instance) {
+ self::$instance = new Conf();
}
- public function __construct()
- {
- // Do some magic configuration loading here.
- if (file_exists('/etc/kolab/kolab.conf'))
- {
- $_ini_raw = file('/etc/kolab/kolab.conf');
+ return self::$instance;
+ }
- $this->_conf = Array();
+ public function __construct()
+ {
+ // Do some magic configuration loading here.
+ if (!file_exists('/etc/kolab/kolab.conf')) {
+ return;
+ }
- foreach ($_ini_raw as $_line) {
- if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
- $_cur_section = $matches[1];
- $this->_conf[$_cur_section] = Array();
- unset($_cur_key);
- }
+ $_ini_raw = file('/etc/kolab/kolab.conf');
- if (preg_match('/^;/', $_line, $matches)) {
- }
+ $this->_conf = array();
- if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
- if (isset($_cur_section) && !empty($_cur_section)) {
- $_cur_key = $matches[1];
- $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
+ foreach ($_ini_raw as $_line) {
+ if (preg_match('/^\[([a-z0-9-_\.]+)\]/', $_line, $matches)) {
+ $_cur_section = $matches[1];
+ $this->_conf[$_cur_section] = array();
+ unset($_cur_key);
+ }
- }
- }
+ if (preg_match('/^;/', $_line, $matches)) {
+ }
- if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
- if (isset($_cur_key) && !empty($_cur_key)) {
- $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
- }
- }
+ if (preg_match('/^([a-z0-9\.-_]+)\s*=\s*(.*)/', $_line, $matches)) {
+ if (isset($_cur_section) && !empty($_cur_section)) {
+ $_cur_key = $matches[1];
+ $this->_conf[$_cur_section][$matches[1]] = isset($matches[2]) ? $matches[2] : '';
}
}
- }
- public function get($key1, $key2 = NULL) {
- return $this->expand($this->get_raw($key1, $key2));
+ if (preg_match('/^\s+(.*)$/', $_line, $matches)) {
+ if (isset($_cur_key) && !empty($_cur_key)) {
+ $this->_conf[$_cur_section][$_cur_key] .= $matches[1];
+ }
+ }
}
+ }
- public function get_raw($key1, $key2 = NULL) {
- if (isset($this->_conf[$key1])) {
- if ($key2) {
- if (isset($this->_conf[$key1][$key2])) {
- return $this->_conf[$key1][$key2];
- } elseif (isset($this->_conf['kolab'][$key2])) {
- return $this->_conf['kolab'][$key2];
- }
- } else {
- return $this->_conf[$key1];
+ public function get($key1, $key2 = NULL)
+ {
+ return $this->expand($this->get_raw($key1, $key2));
+ }
+
+ public function get_raw($key1, $key2 = NULL)
+ {
+ if (isset($this->_conf[$key1])) {
+ if ($key2) {
+ if (isset($this->_conf[$key1][$key2])) {
+ return $this->_conf[$key1][$key2];
+ }
+ else if (isset($this->_conf['kolab'][$key2])) {
+ return $this->_conf['kolab'][$key2];
}
}
-
- // Simple (global) settings may be obtained by calling the key and omitting
- // the section. This goes for sections 'kolab', and whatever is the equivalent
- // of 'kolab', 'auth_mechanism'.
-# echo "<pre>";
-# print_r($this->_conf);
-# echo "</pre>";
-
- if (isset($this->_conf['kolab'][$key1])) {
- return $this->_conf['kolab'][$key1];
- } elseif (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) {
- return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1];
+ else {
+ return $this->_conf[$key1];
}
-
}
- public function expand($str, $custom = FALSE) {
- if (preg_match_all('/%\((?P<variable>\w+)\)s/', $str, $matches)) {
- if (isset($matches['variable']) && !empty($matches['variable'])) {
- if (is_array($matches['variable'])) {
- foreach ($matches['variable'] as $key => $value) {
- if (is_array($custom) && array_key_exists($value, $custom)) {
- $str = str_replace("%(" . $value . ")s", $custom[$value], $str);
- }
+ // Simple (global) settings may be obtained by calling the key and omitting
+ // the section. This goes for sections 'kolab', and whatever is the equivalent
+ // of 'kolab', 'auth_mechanism'.
+// echo "<pre>";
+// print_r($this->_conf);
+// echo "</pre>";
- $str = str_replace("%(" . $value . ")s", $this->get($value), $str);
- }
+ if (isset($this->_conf['kolab'][$key1])) {
+ return $this->_conf['kolab'][$key1];
+ }
+ else if (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) {
+ return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1];
+ }
+ }
- return $str;
+ public function expand($str, $custom = FALSE)
+ {
+ if (preg_match_all('/%\((?P<variable>\w+)\)s/', $str, $matches)) {
+ if (isset($matches['variable']) && !empty($matches['variable'])) {
+ if (is_array($matches['variable'])) {
+ foreach ($matches['variable'] as $key => $value) {
+ if (is_array($custom) && array_key_exists($value, $custom)) {
+ $str = str_replace("%(" . $value . ")s", $custom[$value], $str);
+ }
- } else {
- return str_replace("%(" . $matches['variable'] . ")s", $this->get($matches['variable']), $str);
+ $str = str_replace("%(" . $value . ")s", $this->get($value), $str);
}
- }
-
- return $str;
- } else {
- return $str;
+ return $str;
+ }
+ else {
+ return str_replace("%(" . $matches['variable'] . ")s", $this->get($matches['variable']), $str);
+ }
}
- }
+ return $str;
+ }
+ else {
+ return $str;
+ }
}
-
-?>
+}
diff --git a/lib/SQL.php b/lib/SQL.php
index 6bcf7ed..af1968b 100644
--- a/lib/SQL.php
+++ b/lib/SQL.php
@@ -1,61 +1,62 @@
<?php
- class SQL {
- static private $instance = Array();
-
- private $sql_uri = "mysql://username:password@hostname/database";
-
- /* Placeholder for the existing MySQL connection */
- private $conn = FALSE;
-
- private $sql_stats = Array(
- 'queries' => 0,
- 'query_time' => 0,
- 'connections' => 0
- );
-
- /**
- * This implements the 'singleton' design pattern
- *
- * @return SQL The one and only instance associated with $_conn
- */
- static function get_instance($_conn = 'kolab_wap')
- {
- if (!isset(self::$instance[$_conn])) {
- self::$instance[$_conn] = new SQL($_conn);
- }
-
- return self::$instance[$_conn];
+class SQL {
+ static private $instance = array();
+
+ private $sql_uri = "mysql://username:password@hostname/database";
+
+ /* Placeholder for the existing MySQL connection */
+ private $conn = FALSE;
+
+ private $sql_stats = array(
+ 'queries' => 0,
+ 'query_time' => 0,
+ 'connections' => 0
+ );
+
+ /**
+ * This implements the 'singleton' design pattern
+ *
+ * @return SQL The one and only instance associated with $_conn
+ */
+ static function get_instance($_conn = 'kolab_wap')
+ {
+ if (!isset(self::$instance[$_conn])) {
+ self::$instance[$_conn] = new SQL($_conn);
}
- public function __construct($_conn = 'kolab_wap') {
- $this->name = $_conn;
- $conf = Conf::get_instance();
- $this->sql_uri = $conf->get($_conn, 'sql_uri');
- }
+ return self::$instance[$_conn];
+ }
- public function query($query) {
- if (!$this->conn) {
- $this->_connect();
- }
+ public function __construct($_conn = 'kolab_wap')
+ {
+ $this->name = $_conn;
+ $conf = Conf::get_instance();
+ $this->sql_uri = $conf->get($_conn, 'sql_uri');
+ }
- $result = mysql_query($query);
- return $result;
+ public function query($query)
+ {
+ if (!$this->conn) {
+ $this->_connect();
}
- private function _connect() {
- if (!$this->conn) {
- $_uri = parse_url($this->sql_uri);
- $this->_username = $_uri['user'];
- $this->_password = $_uri['pass'];
- $this->_hostname = $_uri['host'];
- $this->_database = str_replace('/','',$_uri['path']);
-
- $this->conn = mysql_connect($this->_hostname, $this->_username, $this->_password);
- mysql_select_db($this->_database, $this->conn);
- }
- }
+ $result = mysql_query($query);
+ return $result;
+ }
+ private function _connect()
+ {
+ if (!$this->conn) {
+ $_uri = parse_url($this->sql_uri);
+ $this->_username = $_uri['user'];
+ $this->_password = $_uri['pass'];
+ $this->_hostname = $_uri['host'];
+ $this->_database = str_replace('/','',$_uri['path']);
+
+ $this->conn = mysql_connect($this->_hostname, $this->_username, $this->_password);
+ mysql_select_db($this->_database, $this->conn);
+ }
}
-?>
+}
diff --git a/lib/User.php b/lib/User.php
index db456bf..2e0ea21 100644
--- a/lib/User.php
+++ b/lib/User.php
@@ -3,114 +3,119 @@
// @require_once($_SERVER["DOCUMENT_ROOT"] . "../bin/lib/User/LDAP.php");
// @require_once($_SERVER["DOCUMENT_ROOT"] . "../bin/lib/User/SQL.php");
- require_once('Auth.php');
+require_once 'Auth.php';
- class User
- {
+class User
+{
+ private $_authenticated = FALSE;
+ private $auth;
- private $_authenticated = FALSE;
+ private $username = NULL;
+ private $password = NULL;
- private $auth;
+ private $_groups = FALSE;
- private $username = NULL;
- private $password = NULL;
+ private $domain;
+ private $working_domain;
- private $_groups = FALSE;
+ public function get_username()
+ {
+ // Who's asking?
+ return $this->username;
+ }
- private $domain;
- private $working_domain;
+ public function _get_information()
+ {
+ // Return an array of information about this user. For one, the auth method.
+ $user['information'] = array(
+ 'email_address' => $this->_auth_method->_get_email_address(),
+ 'username' => $this->username,
+ 'password' => $this->password,
+ );
+ }
- public function get_username()
- {
- // Who's asking?
- return $this->username;
- }
+ public function authenticate($username, $password, $method = FALSE)
+ {
+ $this->auth = Auth::get_instance();
- public function _get_information()
- {
- // Return an array of information about this user. For one, the auth method.
- $user['information'] = Array(
- 'email_address' => $this->_auth_method->_get_email_address(),
- 'username' => $this->username,
- 'password' => $this->password,
- );
- }
+ $result = $this->auth->authenticate($username, $password);
- public function authenticate($username, $password, $method = FALSE)
- {
- $this->auth = Auth::get_instance();
+ if ($result) {
+ $this->_authenticated = TRUE;
+ $this->username = $username;
+ $this->password = $password;
+ $this->domain = $this->auth->domain;
+// $this->_groups = $this->groups();
+ }
- $result = $this->auth->authenticate($username, $password);
+ return $this->_authenticated;
+ }
- if ($result) {
- $this->_authenticated = TRUE;
- $this->username = $username;
- $this->password = $password;
- $this->domain = $this->auth->domain;
-# $this->_groups = $this->groups();
- }
+ public function authenticated()
+ {
+ return $this->_authenticated;
+ }
- return $this->_authenticated;
+ public function get_domain()
+ {
+ if ($this->working_domain) {
+ return $this->working_domain;
}
-
- public function authenticated() {
- return $this->_authenticated;
+ else if ($this->domain) {
+ return $this->domain;
}
-
- public function get_domain() {
- if ($this->working_domain) {
- return $this->working_domain;
- } elseif ($this->domain) {
- return $this->domain;
- } else {
- throw new Exception("No domain selected to work on", 1024);
- }
+ else {
+ throw new Exception("No domain selected to work on", 1024);
}
+ }
- public function groups() {
- #error_log("Called " . __FUNCTION__ . " on line " . __LINE__ . " of " . __FILE__);
- #debug_print_backtrace();
+ public function groups()
+ {
+ //error_log("Called " . __FUNCTION__ . " on line " . __LINE__ . " of " . __FILE__);
+ //debug_print_backtrace();
- if ($this->_groups || (is_array($this->_groups) && count($this->_groups) >= 1))
- return $this->_groups;
+ if ($this->_groups || (is_array($this->_groups) && count($this->_groups) >= 1)) {
+ return $this->_groups;
+ }
- $this->_groups = Array();
- $this->auth = Auth::get_instance();
+ $this->_groups = array();
+ $this->auth = Auth::get_instance();
- $entry = $this->auth->user_find_by_attribute(Array('mail' => $this->username));
+ $entry = $this->auth->user_find_by_attribute(array('mail' => $this->username));
- if ($entry) {
- foreach ($entry as $dn => $attributes) {
- if (array_key_exists('memberof', $attributes)) {
- $this->_groups = (array)($attributes['memberof']);
- } else {
- $this->_groups = $this->auth->find_user_groups($dn);
- }
+ if ($entry) {
+ foreach ($entry as $dn => $attributes) {
+ if (array_key_exists('memberof', $attributes)) {
+ $this->_groups = (array)($attributes['memberof']);
+ }
+ else {
+ $this->_groups = $this->auth->find_user_groups($dn);
}
- } else {
- $this->_groups = Array();
}
-
- return $this->_groups;
}
-
- public function reset_domain() {
- // Validate domain
- // Validate access to domain
- // Set $this->working_domain
- $this->working_domain = $this->domain;
- return TRUE;
+ else {
+ $this->_groups = array();
}
- public function set_domain($domain) {
- // Validate domain
- // Validate access to domain
- // Set $this->working_domain
- $this->working_domain = $domain;
- return TRUE;
- }
+ return $this->_groups;
+ }
+ public function reset_domain()
+ {
+ // Validate domain
+ // Validate access to domain
+ // Set $this->working_domain
+ $this->working_domain = $this->domain;
+ return TRUE;
}
-?>
+ public function set_domain($domain)
+ {
+ // Validate domain
+ // Validate access to domain
+ // Set $this->working_domain
+ $this->working_domain = $domain;
+ return TRUE;
+ }
+}
diff --git a/lib/api/kolab_domains_actions.php b/lib/api/kolab_domains_actions.php
index c9694fc..666f0c5 100644
--- a/lib/api/kolab_domains_actions.php
+++ b/lib/api/kolab_domains_actions.php
@@ -15,10 +15,10 @@ class kolab_domains_actions extends kolab_api_service
public function domains_list($get, $post) {
$auth = Auth::get_instance();
-
+
$domains = $auth->list_domains();
$count = count($domains);
-
+
return array(
'list' => $domains,
'count' => $count,
diff --git a/lib/api/kolab_form_value_actions.php b/lib/api/kolab_form_value_actions.php
index 9ded4de..2036b1c 100644
--- a/lib/api/kolab_form_value_actions.php
+++ b/lib/api/kolab_form_value_actions.php
@@ -1,160 +1,160 @@
<?php
- /**
- *
- */
- class kolab_form_value_actions extends kolab_api_service
+/**
+ *
+ */
+class kolab_form_value_actions extends kolab_api_service
+{
+
+ public function capabilities($domain)
{
- public function capabilities($domain)
- {
- return array(
- 'generate_cn' => 'w',
- 'generate_displayname' => 'w',
- 'generate_mail' => 'w',
- 'generate_password' => 'r',
- 'generate_uid' => 'w',
- 'generate_userpassword' => 'r',
-// 'info' => 'r',
- );
- }
+ return array(
+ 'generate_cn' => 'w',
+ 'generate_displayname' => 'w',
+ 'generate_mail' => 'w',
+ 'generate_password' => 'r',
+ 'generate_uid' => 'w',
+ 'generate_userpassword' => 'r',
+// 'info' => 'r',
+ );
+ }
- public function generate_cn($getdata, $postdata) {
- if (!isset($postdata['user_type_id'])) {
- throw new Exception("No user type ID specified", 34);
- }
+ public function generate_cn($getdata, $postdata)
+ {
+ if (!isset($postdata['user_type_id'])) {
+ throw new Exception("No user type ID specified", 34);
+ }
- $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
+ $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
- $uta = json_decode(unserialize($user_type['attributes']), true);
+ $uta = json_decode(unserialize($user_type['attributes']), true);
- if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['cn'])) {
- // Use Data Please
- foreach ($uta['auto_form_fields']['cn']['data'] as $key) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
+ if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['cn'])) {
+ // Use Data Please
+ foreach ($uta['auto_form_fields']['cn']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
}
-
- return Array("cn" => $postdata['givenname'] . " " . $postdata['sn']);
}
+ return array("cn" => $postdata['givenname'] . " " . $postdata['sn']);
}
+ }
- public function generate_displayname($getdata, $postdata) {
- if (!isset($postdata['user_type_id'])) {
- throw new Exception("No user type ID specified", 34);
- }
+ public function generate_displayname($getdata, $postdata)
+ {
+ if (!isset($postdata['user_type_id'])) {
+ throw new Exception("No user type ID specified", 34);
+ }
- $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
+ $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
- $uta = json_decode(unserialize($user_type['attributes']), true);
+ $uta = json_decode(unserialize($user_type['attributes']), true);
- if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['displayname'])) {
- // Use Data Please
- foreach ($uta['auto_form_fields']['displayname']['data'] as $key) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
+ if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['displayname'])) {
+ // Use Data Please
+ foreach ($uta['auto_form_fields']['displayname']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
}
-
- return Array("displayname" => $postdata['sn'] . ", " . $postdata['givenname']);
}
+ return array("displayname" => $postdata['sn'] . ", " . $postdata['givenname']);
}
- public function generate_mail($getdata, $postdata) {
- if (!isset($postdata['user_type_id'])) {
- throw new Exception("No user type ID specified", 34);
- }
-
- $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
+ }
- $uta = json_decode(unserialize($user_type['attributes']), true);
+ public function generate_mail($getdata, $postdata)
+ {
+ if (!isset($postdata['user_type_id'])) {
+ throw new Exception("No user type ID specified", 34);
+ }
- if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['mail'])) {
- // Use Data Please
- foreach ($uta['auto_form_fields']['mail']['data'] as $key) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
- }
+ $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
- $givenname = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['givenname']);
- $sn = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
+ $uta = json_decode(unserialize($user_type['attributes']), true);
- $givenname = strtolower($givenname);
+ if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['mail'])) {
+ // Use Data Please
+ foreach ($uta['auto_form_fields']['mail']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ }
- $sn = str_replace(' ', '', $sn);
- $sn = strtolower($sn);
+ $givenname = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['givenname']);
+ $sn = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
- $mail = $givenname . "." . $sn . "@" . $_SESSION['user']->get_domain();
+ $givenname = strtolower($givenname);
+ $sn = str_replace(' ', '', $sn);
+ $sn = strtolower($sn);
- $orig_mail = $mail;
+ $mail = $givenname . "." . $sn . "@" . $_SESSION['user']->get_domain();
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $orig_mail = $mail;
- $x = 2;
- while ($auth->user_find_by_attribute(Array('mail' => $mail))) {
- list($mail_local, $mail_domain) = explode('@', $orig_mail);
- $mail = $mail_local . $x . '@' . $mail_domain;
- $x++;
- }
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
- return Array('mail' => $mail);
+ $x = 2;
+ while ($auth->user_find_by_attribute(array('mail' => $mail))) {
+ list($mail_local, $mail_domain) = explode('@', $orig_mail);
+ $mail = $mail_local . $x . '@' . $mail_domain;
+ $x++;
}
+ return array('mail' => $mail);
}
+ }
- public function generate_password($getdata, $postdata) {
- exec("head -c 200 /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c15", $userpassword_plain);
- $userpassword_plain = $userpassword_plain[0];
- return Array('password' => $userpassword_plain);
- }
+ public function generate_password($getdata, $postdata)
+ {
+ exec("head -c 200 /dev/urandom | tr -dc _A-Z-a-z-0-9 | head -c15", $userpassword_plain);
+ $userpassword_plain = $userpassword_plain[0];
+ return array('password' => $userpassword_plain);
+ }
- public function generate_uid($getdata, $postdata) {
- if (!isset($postdata['user_type_id'])) {
- throw new Exception("No user type ID specified", 34);
- }
+ public function generate_uid($getdata, $postdata)
+ {
+ if (!isset($postdata['user_type_id'])) {
+ throw new Exception("No user type ID specified", 34);
+ }
- $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
+ $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
- $uta = json_decode(unserialize($user_type['attributes']), true);
+ $uta = json_decode(unserialize($user_type['attributes']), true);
- if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['uid'])) {
- // Use Data Please
- foreach ($uta['auto_form_fields']['uid']['data'] as $key) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- }
+ if (isset($uta['auto_form_fields']) && isset($uta['auto_form_fields']['uid'])) {
+ // Use Data Please
+ foreach ($uta['auto_form_fields']['uid']['data'] as $key) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
}
+ }
- $uid = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
-
- $uid = strtolower($uid);
- $uid = str_replace(' ', '', $uid);
-
- $orig_uid = $uid;
+ $uid = iconv('UTF-8', 'ASCII//TRANSLIT', $postdata['sn']);
+ $uid = strtolower($uid);
+ $uid = str_replace(' ', '', $uid);
- $auth = Auth::get_instance($_SESSION['user']->get_domain());
+ $orig_uid = $uid;
- $user = $auth->user_find_by_attribute(Array('uid' => $uid));
+ $auth = Auth::get_instance($_SESSION['user']->get_domain());
- $x = 2;
- while ($auth->user_find_by_attribute(Array('uid' => $uid))) {
- $uid = $orig_uid . $x;
- $x++;
- }
+ $user = $auth->user_find_by_attribute(array('uid' => $uid));
- return Array('uid' => $uid);
+ $x = 2;
+ while ($auth->user_find_by_attribute(array('uid' => $uid))) {
+ $uid = $orig_uid . $x;
+ $x++;
}
+ return array('uid' => $uid);
}
+ }
- public function generate_userpassword($getdata, $postdata) {
- $password = $this->generate_password($getdata, $postdata);
- return Array('userpassword' => $password['password']);
- }
-
+ public function generate_userpassword($getdata, $postdata)
+ {
+ $password = $this->generate_password($getdata, $postdata);
+ return array('userpassword' => $password['password']);
}
-?>
+}
diff --git a/lib/api/kolab_group_actions.php b/lib/api/kolab_group_actions.php
index 4f9b632..ff0d59f 100644
--- a/lib/api/kolab_group_actions.php
+++ b/lib/api/kolab_group_actions.php
@@ -1,117 +1,122 @@
<?php
- /**
- *
- */
- class kolab_group_actions extends kolab_api_service
+/**
+ *
+ */
+class kolab_group_actions extends kolab_api_service
+{
+ public function capabilities($domain)
{
- public function capabilities($domain)
- {
- return array(
- 'add' => 'w',
- 'delete' => 'w',
- 'info' => 'r',
- 'members_list' => 'r',
- );
+ return array(
+ 'add' => 'w',
+ 'delete' => 'w',
+ 'info' => 'r',
+ 'members_list' => 'r',
+ );
+ }
+
+ public function group_add($getdata, $postdata)
+ {
+ if (!isset($postdata['group_type_id'])) {
+ throw new Exception("No group type ID specified", 346781);
}
- public function group_add($getdata, $postdata) {
- if (!isset($postdata['group_type_id'])) {
- throw new Exception("No group type ID specified", 346781);
- }
-
- $group_type = mysql_fetch_assoc(query("SELECT attributes FROM group_types WHERE id = '" . $postdata['group_type_id'] ."'"));
+ $group_type = mysql_fetch_assoc(query("SELECT attributes FROM group_types WHERE id = '" . $postdata['group_type_id'] ."'"));
- $gta = json_decode(unserialize($group_type['attributes']), true);
+ $gta = json_decode(unserialize($group_type['attributes']), true);
- $group_attributes = Array();
+ $group_attributes = Array();
- if (isset($gta['form_fields'])) {
- foreach ($gta['form_fields'] as $key => $value) {
- error_log("form field $key");
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- throw new Exception("Missing input value for $key", 345);
- } else {
- $group_attributes[$key] = $postdata[$key];
- }
+ if (isset($gta['form_fields'])) {
+ foreach ($gta['form_fields'] as $key => $value) {
+ error_log("form field $key");
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ throw new Exception("Missing input value for $key", 345);
+ }
+ else {
+ $group_attributes[$key] = $postdata[$key];
}
}
+ }
- if (isset($gta['auto_form_fields'])) {
- foreach ($gta['auto_form_fields'] as $key => $value) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- } else {
- $group_attributes[$key] = $postdata[$key];
- }
+ if (isset($gta['auto_form_fields'])) {
+ foreach ($gta['auto_form_fields'] as $key => $value) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ else {
+ $group_attributes[$key] = $postdata[$key];
}
}
+ }
- if (isset($gta['fields'])) {
- foreach ($gta['fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- $group_attributes[$key] = $gta['fields'][$key];
- } else {
- $group_attributes[$key] = $postdata[$key];
- }
+ if (isset($gta['fields'])) {
+ foreach ($gta['fields'] as $key => $value) {
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ $group_attributes[$key] = $gta['fields'][$key];
+ }
+ else {
+ $group_attributes[$key] = $postdata[$key];
}
}
+ }
- $auth = Auth::get_instance();
- $result = $auth->group_add($group_attributes, $postdata['group_type_id']);
- if ($result) {
- return $group_attributes;
- } else {
- return FALSE;
- }
+ $auth = Auth::get_instance();
+ $result = $auth->group_add($group_attributes, $postdata['group_type_id']);
+
+ if ($result) {
+ return $group_attributes;
}
- public function group_delete($getdata, $postdata) {
- // TODO: Input validation
- $auth = Auth::get_instance();
- if (!isset($postdata['group'])) {
- return FALSE;
- }
+ return FALSE;
+ }
- $result = $auth->group_delete($postdata['group']);
- if ($result) {
- return $result;
- } else {
- return FALSE;
- }
+ public function group_delete($getdata, $postdata)
+ {
+ if (empty($postdata['group'])) {
+ return FALSE;
}
- public function group_info($getdata, $postdata) {
- $auth = Auth::get_instance();
+ // TODO: Input validation
+ $auth = Auth::get_instance();
+ $result = $auth->group_delete($postdata['group']);
- if (!isset($getdata['group'])) {
- return FALSE;
- }
+ if ($result) {
+ return $result;
+ }
- $result = $auth->group_info($getdata['group']);
+ return FALSE;
+ }
- if ($result) {
- return $result;
- } else {
- return FALSE;
- }
+ public function group_info($getdata, $postdata)
+ {
+ if (empty($getdata['group'])) {
+ return FALSE;
}
- public function group_members_list($getdata, $postdata) {
- $auth = Auth::get_instance();
+ $auth = Auth::get_instance();
+ $result = $auth->group_info($getdata['group']);
- if (!isset($getdata['group'])) {
- return FALSE;
- }
+ if ($result) {
+ return $result;
+ }
- $result = $auth->group_members_list($getdata['group']);
+ return FALSE;
+ }
- if ($result) {
- return $result;
- } else {
- return FALSE;
- }
+ public function group_members_list($getdata, $postdata)
+ {
+ $auth = Auth::get_instance();
+
+ if (empty($getdata['group'])) {
+ return FALSE;
}
- }
-?>
+ $result = $auth->group_members_list($getdata['group']);
+
+ if ($result) {
+ return $result;
+ }
+ return FALSE;
+ }
+}
diff --git a/lib/api/kolab_group_types_actions.php b/lib/api/kolab_group_types_actions.php
index f72791b..8789a57 100644
--- a/lib/api/kolab_group_types_actions.php
+++ b/lib/api/kolab_group_types_actions.php
@@ -1,38 +1,37 @@
<?php
- /**
- *
- */
- class kolab_group_types_actions extends kolab_api_service
+/**
+ *
+ */
+class kolab_group_types_actions extends kolab_api_service
+{
+ public function capabilities($domain)
{
- public function capabilities($domain)
- {
- return array(
- 'list' => 'r',
- );
- }
+ return array(
+ 'list' => 'r',
+ );
+ }
- public function group_types_list($get, $post) {
- $result = query("SELECT * FROM group_types");
- $group_types = Array();
+ public function group_types_list($get, $post)
+ {
+ $result = query("SELECT * FROM group_types");
+ $group_types = Array();
- while ($row = mysql_fetch_assoc($result)) {
- $group_types[$row['id']] = Array();
+ while ($row = mysql_fetch_assoc($result)) {
+ $group_types[$row['id']] = array();
- foreach ($row as $key => $value) {
- if ($key != "id") {
- if ($key == "attributes") {
- $group_types[$row['id']][$key] = json_decode(unserialize($value), true);
- } else {
- $group_types[$row['id']][$key] = $value;
- }
+ foreach ($row as $key => $value) {
+ if ($key != "id") {
+ if ($key == "attributes") {
+ $group_types[$row['id']][$key] = json_decode(unserialize($value), true);
+ }
+ else {
+ $group_types[$row['id']][$key] = $value;
}
}
}
-
- return $group_types;
-
}
- }
-?>
+ return $group_types;
+ }
+}
diff --git a/lib/api/kolab_user_actions.php b/lib/api/kolab_user_actions.php
index b0b4e53..1849663 100644
--- a/lib/api/kolab_user_actions.php
+++ b/lib/api/kolab_user_actions.php
@@ -1,105 +1,109 @@
<?php
- /**
- *
- */
- class kolab_user_actions extends kolab_api_service
+/**
+ *
+ */
+class kolab_user_actions extends kolab_api_service
+{
+ public function capabilities($domain)
{
- public function capabilities($domain)
- {
- return array(
- 'add' => 'w',
- 'delete' => 'w',
-// 'edit' => 'w',
-// 'find' => 'r',
-// 'find_by_any_attribute' => 'r',
-// 'find_by_attribute' => 'r',
-// 'find_by_attributes' => 'r',
- 'info' => 'r',
- );
- }
+ return array(
+ 'add' => 'w',
+ 'delete' => 'w',
+// 'edit' => 'w',
+// 'find' => 'r',
+// 'find_by_any_attribute' => 'r',
+// 'find_by_attribute' => 'r',
+// 'find_by_attributes' => 'r',
+ 'info' => 'r',
+ );
+ }
- public function user_add($getdata, $postdata) {
- if (!isset($postdata['user_type_id'])) {
- throw new Exception("No user type ID specified", 346781);
- }
+ public function user_add($getdata, $postdata)
+ {
+ if (!isset($postdata['user_type_id'])) {
+ throw new Exception("No user type ID specified", 346781);
+ }
- $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
+ $user_type = mysql_fetch_assoc(query("SELECT attributes FROM user_types WHERE id = '" . $postdata['user_type_id'] ."'"));
- $uta = json_decode(unserialize($user_type['attributes']), true);
+ $uta = json_decode(unserialize($user_type['attributes']), true);
- $user_attributes = Array();
+ $user_attributes = array();
- if (isset($uta['form_fields'])) {
- foreach ($uta['form_fields'] as $key => $value) {
- error_log("form field $key");
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- throw new Exception("Missing input value for $key", 345);
- } else {
- $user_attributes[$key] = $postdata[$key];
- }
+ if (isset($uta['form_fields'])) {
+ foreach ($uta['form_fields'] as $key => $value) {
+ error_log("form field $key");
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ throw new Exception("Missing input value for $key", 345);
}
- }
-
- if (isset($uta['auto_form_fields'])) {
- foreach ($uta['auto_form_fields'] as $key => $value) {
- if (!isset($postdata[$key])) {
- throw new Exception("Key not set: " . $key, 12356);
- } else {
- $user_attributes[$key] = $postdata[$key];
- }
+ else {
+ $user_attributes[$key] = $postdata[$key];
}
}
+ }
- if (isset($uta['fields'])) {
- foreach ($uta['fields'] as $key => $value) {
- if (!isset($postdata[$key]) || empty($postdata[$key])) {
- $user_attributes[$key] = $uta['fields'][$key];
- } else {
- $user_attributes[$key] = $postdata[$key];
- }
+ if (isset($uta['auto_form_fields'])) {
+ foreach ($uta['auto_form_fields'] as $key => $value) {
+ if (!isset($postdata[$key])) {
+ throw new Exception("Key not set: " . $key, 12356);
+ }
+ else {
+ $user_attributes[$key] = $postdata[$key];
}
}
+ }
- $auth = Auth::get_instance();
- $result = $auth->user_add($user_attributes, $postdata['user_type_id']);
- if ($result) {
- return $user_attributes;
- } else {
- return FALSE;
+ if (isset($uta['fields'])) {
+ foreach ($uta['fields'] as $key => $value) {
+ if (!isset($postdata[$key]) || empty($postdata[$key])) {
+ $user_attributes[$key] = $uta['fields'][$key];
+ } else {
+ $user_attributes[$key] = $postdata[$key];
+ }
}
}
- public function user_delete($getdata, $postdata) {
- // TODO: Input validation
- $auth = Auth::get_instance();
- if (!isset($postdata['user'])) {
- return FALSE;
- }
+ $auth = Auth::get_instance();
+ $result = $auth->user_add($user_attributes, $postdata['user_type_id']);
- $result = $auth->user_delete($postdata['user']);
- if ($result) {
- return $result;
- } else {
- return FALSE;
- }
+ if ($result) {
+ return $user_attributes;
}
- public function user_info($getdata, $postdata) {
- $auth = Auth::get_instance();
+ return FALSE;
+ }
- if (!isset($getdata['user'])) {
- return FALSE;
- }
+ public function user_delete($getdata, $postdata)
+ {
+ if (!isset($postdata['user'])) {
+ return FALSE;
+ }
- $result = $auth->user_info($getdata['user']);
+ // TODO: Input validation
+ $auth = Auth::get_instance();
+ $result = $auth->user_delete($postdata['user']);
- if ($result) {
- return $result;
- } else {
- return FALSE;
- }
+ if ($result) {
+ return $result;
}
+
+ return FALSE;
}
-?>
+ public function user_info($getdata, $postdata)
+ {
+ if (!isset($getdata['user'])) {
+ return FALSE;
+ }
+
+ $auth = Auth::get_instance();
+ $result = $auth->user_info($getdata['user']);
+
+ if ($result) {
+ return $result;
+ }
+
+ return FALSE;
+ }
+}
diff --git a/lib/api/kolab_user_types_actions.php b/lib/api/kolab_user_types_actions.php
index 2742d27..e37ff90 100644
--- a/lib/api/kolab_user_types_actions.php
+++ b/lib/api/kolab_user_types_actions.php
@@ -1,38 +1,37 @@
<?php
- /**
- *
- */
- class kolab_user_types_actions extends kolab_api_service
+/**
+ *
+ */
+class kolab_user_types_actions extends kolab_api_service
+{
+ public function capabilities($domain)
{
- public function capabilities($domain)
- {
- return array(
- 'list' => 'r',
- );
- }
+ return array(
+ 'list' => 'r',
+ );
+ }
- public function user_types_list($get, $post) {
- $result = query("SELECT * FROM user_types");
- $user_types = Array();
+ public function user_types_list($get, $post)
+ {
+ $result = query("SELECT * FROM user_types");
+ $user_types = array();
- while ($row = mysql_fetch_assoc($result)) {
- $user_types[$row['id']] = Array();
+ while ($row = mysql_fetch_assoc($result)) {
+ $user_types[$row['id']] = array();
- foreach ($row as $key => $value) {
- if ($key != "id") {
- if ($key == "attributes") {
- $user_types[$row['id']][$key] = json_decode(unserialize($value), true);
- } else {
- $user_types[$row['id']][$key] = $value;
- }
+ foreach ($row as $key => $value) {
+ if ($key != "id") {
+ if ($key == "attributes") {
+ $user_types[$row['id']][$key] = json_decode(unserialize($value), true);
+ }
+ else {
+ $user_types[$row['id']][$key] = $value;
}
}
}
-
- return $user_types;
-
}
- }
-?>
+ return $user_types;
+ }
+}