Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
index 4b71080..429df7b 100644
--- a/lib/api/kolab_api_service_type.php
+++ b/lib/api/kolab_api_service_type.php
@@ -1,174 +1,228 @@
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab Web Admin Panel |
| |
| Copyright (C) 2011-2012, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
| Author: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
- * Service providing user data management
+ * Service providing object types management
*/
class kolab_api_service_type extends kolab_api_service
{
/**
* Returns service capabilities.
*
* @param string $domain Domain name
*
* @return array Capabilities list
*/
public function capabilities($domain)
{
$auth = Auth::get_instance();
//$effective_rights = $auth->list_rights('user');
$rights = array();
// @TODO: set rights according to user group or sth
if ($_SESSION['user']->get_userid() == 'cn=Directory Manager') {
$rights['add'] = "w";
$rights['delete'] = "w";
$rights['edit'] = "w";
}
+ $rights['info'] = "r";
$rights['effective_rights'] = "r";
return $rights;
}
/**
- * Create user.
+ * Create type.
*
- * @param array $get GET parameters
- * @param array $post POST parameters
+ * @param array $get GET parameters
+ * @param array $post POST parameters
*
- * @return array|bool User attributes or False on error.
+ * @return array|bool Type attributes or False on error.
*/
public function type_add($getdata, $postdata)
{
- //console("type_add()", $postdata);
+ if (!in_array($postdata['type'], $this->supported_types_db)) {
+ return false;
+ }
+
+ if (empty($postdata['name']) || empty($postdata['key'])) {
+ return false;
+ }
+
+ if (empty($postdata['attributes']) || !is_array($postdata['attributes'])) {
+ return false;
+ }
+
+ // @TODO: check privileges
- $type_attributes = $this->parse_input_attributes('type', $postdata);
+ $type = $postdata['type'];
+ $query = array(
+ 'key' => $postdata['key'],
+ 'name' => $postdata['name'],
+ 'description' => $postdata['description'] ? $postdata['description'] : '',
+ 'attributes' => json_encode($postdata['attributes']),
+ );
- //console("type_add()", $type_attributes);
+ if ($postdata['type'] == 'user') {
+ $query['used_for'] = $postdata['used_for'] == 'hosted' ? 'hosted' : null;
+ }
-// $auth = Auth::get_instance();
-// $result = $auth->type_add($type_attributes, $postdata['type_id']);
+ $query = array_map(array($this->db, 'escape'), $query);
- if ($result) {
- return $type_attributes;
+ $this->db->query("INSERT INTO {$type}_types"
+ . " (" . implode(',', array_keys($query)) . ")"
+ . " VALUES (" . implode(',', $query) . ")");
+
+ if (!($id = $this->db->last_insert_id())) {
+ return false;
}
- return false;
+ // update cache
+ $this->cache['object_types'][$type][$id] = $postdata;
+
+ $postdata['id'] = $id;
+
+ return $postdata;
}
/**
* Detete type.
*
* @param array $get GET parameters
* @param array $post POST parameters
*
* @return bool True on success, False on failure
*/
public function type_delete($getdata, $postdata)
{
if (empty($postdata['type']) || empty($postdata['id'])) {
return false;
}
if (!in_array($postdata['type'], $this->supported_types_db)) {
return false;
}
$object_name = $postdata['type'];
$object_id = $postdata['id'];
+ // @TODO: check privileges
+
$this->db->query("DELETE FROM {$object_name}_types WHERE id = ?", array($object_id));
return (bool) $this->db->affected_rows();
}
/**
* Update type.
*
* @param array $get GET parameters
* @param array $post POST parameters
*
* @return bool True on success, False on failure
*/
public function type_edit($getdata, $postdata)
{
- //console("\$postdata to type_edit()", $postdata);
+ if (empty($postdata['type']) || empty($postdata['id'])) {
+ return false;
+ }
+
+ if (empty($postdata['name']) || empty($postdata['key'])) {
+ return false;
+ }
+
+ if (empty($postdata['attributes']) || !is_array($postdata['attributes'])) {
+ return false;
+ }
- $type_attributes = $this->parse_input_attributes('type', $postdata);
- $type = $postdata['id'];
+ // @TODO: check privileges
-// $auth = Auth::get_instance();
-// $result = $auth->type_edit($type, $type_attributes, $postdata['type_id']);
+ $type = $postdata['type'];
+ $query = array(
+ 'key' => $postdata['key'],
+ 'name' => $postdata['name'],
+ 'description' => $postdata['description'] ? $postdata['description'] : '',
+ 'attributes' => json_encode($postdata['attributes']),
+ );
- // Return the $mod_array
- if ($result) {
- return $result;
+ if ($postdata['type'] == 'user') {
+ $query['used_for'] = $postdata['used_for'] == 'hosted' ? 'hosted' : null;
}
- return false;
+ foreach ($query as $idx => $value) {
+ $query[$idx] = $idx . " = " . $this->db->escape($value);
+ }
+ $this->db->query("UPDATE {$type}_types SET "
+ . implode(', ', $query) . " WHERE id = ?", array($postdata['id']));
+
+ if (!($id = $this->db->last_insert_id())) {
+ return false;
+ }
+
+ // update cache
+ $this->cache['object_types'][$type][$id] = $postdata;
+
+ $postdata['id'] = $id;
+
+ return $postdata;
}
public function type_effective_rights($getdata, $postdata)
{
// $auth = Auth::get_instance();
// $effective_rights = $auth->list_rights(empty($getdata['user']) ? 'user' : $getdata['user']);
// return $effective_rights;
return array();
}
/**
- * User information.
+ * Type information.
*
* @param array $get GET parameters
* @param array $post POST parameters
*
- * @return array|bool User attributes, False on error
+ * @return array|bool Type data, False on error
*/
public function type_info($getdata, $postdata)
{
- if (!isset($getdata['type'])) {
+ if (empty($getdata['type']) || empty($getdata['id'])) {
return false;
}
-// $auth = Auth::get_instance();
-// $result = $auth->type_info($getdata['type']);
-
-// Log::trace("type.info on " . $getdata['type'] . " result: " . var_export($result, TRUE));
- // normalize result
-// $result = $this->parse_result_attributes('type', $result);
-
-// Log::trace("type.info on " . $getdata['type'] . " parsed result: " . var_export($result, TRUE));
-
- if ($result) {
- return $result;
+ if (!in_array($getdata['type'], $this->supported_types_db)) {
+ return false;
}
- return false;
+ $object_name = $getdata['type'];
+ $object_id = $getdata['id'];
+ $types = $this->object_types($object_name);
+
+ return !empty($types[$object_id]) ? $types[$object_id] : false;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Apr 24, 1:20 PM (1 d, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18888649
Default Alt Text
(9 KB)

Event Timeline