summaryrefslogtreecommitdiffstats
path: root/lib/api/kolab_group_actions.php
blob: 4f9b632fcba40d8ab1e64c2d49cd2819cfad8f0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

    /**
     *
     */
    class kolab_group_actions extends kolab_api_service
    {
        public function capabilities($domain)
        {
            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);
            }

            $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);

            $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['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];
                    }
                }
            }

            $auth = Auth::get_instance();
            $result = $auth->group_add($group_attributes, $postdata['group_type_id']);
            if ($result) {
                return $group_attributes;
            } else {
                return FALSE;
            }
        }

        public function group_delete($getdata, $postdata) {
            // TODO: Input validation
            $auth = Auth::get_instance();
            if (!isset($postdata['group'])) {
                return FALSE;
            }

            $result = $auth->group_delete($postdata['group']);
            if ($result) {
                return $result;
            } else {
                return FALSE;
            }
        }

        public function group_info($getdata, $postdata) {
            $auth = Auth::get_instance();

            if (!isset($getdata['group'])) {
                return FALSE;
            }

            $result = $auth->group_info($getdata['group']);

            if ($result) {
                return $result;
            } else {
                return FALSE;
            }
        }

        public function group_members_list($getdata, $postdata) {
            $auth = Auth::get_instance();

            if (!isset($getdata['group'])) {
                return FALSE;
            }

            $result = $auth->group_members_list($getdata['group']);

            if ($result) {
                return $result;
            } else {
                return FALSE;
            }
        }
   }

?>