~ubuntu-branches/ubuntu/intrepid/ldap-account-manager/intrepid

« back to all changes in this revision

Viewing changes to lib/modules/phpGroupwareGroup.inc

  • Committer: Bazaar Package Importer
  • Author(s): Roland Gruber
  • Date: 2008-04-28 16:44:55 UTC
  • mfrom: (1.1.10 upstream) (4.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080428164455-m3hoydrs0xbse1ns
Tags: 2.3.0-1
* Installation fails if php4 is not installed (Closes: #471953)
* password quality checking (Closes: #462336)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
$Id: phpGroupwareGroup.inc,v 1.3 2008/04/15 14:33:01 gruberroland Exp $
 
4
 
 
5
  This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
 
6
  Copyright (C) 2008  Roland Gruber
 
7
 
 
8
  This program is free software; you can redistribute it and/or modify
 
9
  it under the terms of the GNU General Public License as published by
 
10
  the Free Software Foundation; either version 2 of the License, or
 
11
  (at your option) any later version.
 
12
 
 
13
  This program is distributed in the hope that it will be useful,
 
14
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
  GNU General Public License for more details.
 
17
 
 
18
  You should have received a copy of the GNU General Public License
 
19
  along with this program; if not, write to the Free Software
 
20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
*/
 
22
 
 
23
/**
 
24
* Manages phpGroupware groups.
 
25
*
 
26
* @package modules
 
27
* @author Roland Gruber
 
28
*/
 
29
 
 
30
/**
 
31
* Manages phpGroupware groups.
 
32
*
 
33
* @package modules
 
34
*/
 
35
class phpGroupwareGroup extends baseModule {
 
36
        
 
37
        /**
 
38
        * Creates a new kolabUser object.
 
39
        *
 
40
        * @param string $scope account type (user, group, host)
 
41
        */
 
42
        public function __construct($scope) {
 
43
                parent::__construct($scope);
 
44
                $this->autoAddObjectClasses = false;
 
45
        }
 
46
        
 
47
        /**
 
48
        * Returns meta data that is interpreted by parent class
 
49
        *
 
50
        * @return array array with meta data
 
51
        * 
 
52
        * @see baseModule::get_metaData()
 
53
        */
 
54
        public function get_metaData() {
 
55
                $return = array();
 
56
                // icon
 
57
                $return['icon'] = 'phpGroupware.png';
 
58
                // manages host accounts
 
59
                $return["account_types"] = array("group");
 
60
                // alias name
 
61
                $return["alias"] = "phpGroupWare";
 
62
                // module dependencies
 
63
                $return['dependencies'] = array('depends' => array('posixGroup'), 'conflicts' => array());
 
64
                // LDAP filter
 
65
                $return["ldap_filter"] = array('or' => "(objectClass=phpgwGroup)");
 
66
                // managed object classes
 
67
                $return['objectClasses'] = array('phpgwGroup');
 
68
                // managed attributes
 
69
                $return['attributes'] = array('phpgwGroupID');
 
70
                // help Entries
 
71
                $return['help'] = array(
 
72
                        'extension' => array(
 
73
                                "Headline" => _("Add phpGroupWare extension"),
 
74
                                "Text" => _("If you set this to \"true\" then the phpGroupware extension will be added.")
 
75
                        )
 
76
                );
 
77
                // upload dependencies
 
78
                $return['upload_preDepends'] = array('posixGroup');
 
79
                // upload fields
 
80
                $return['upload_columns'] = array(
 
81
                        array(
 
82
                                'name' => 'phpGroupwareGroup_extension',
 
83
                                'description' => _('Add phpGroupWare extension'),
 
84
                                'help' => 'extension',
 
85
                                'example' => 'true',
 
86
                                'values' => 'true, false'
 
87
                        )
 
88
                );
 
89
                return $return;
 
90
        }
 
91
        
 
92
        /**
 
93
         * Returns the HTML meta data for the main account page.
 
94
         * 
 
95
         * @return array HTML meta data
 
96
         */
 
97
        public function display_html_attributes() {
 
98
                $return = array();
 
99
                if (isset($this->attributes['objectClass']) && in_array('phpgwGroup', $this->attributes['objectClass'])) {
 
100
                        $return[] = array(
 
101
                                array('kind' => 'input', 'type' => 'submit', 'name' => 'form_subpage_phpGroupwareGroup_attributes_remObjectClass', 'value' => _('Remove phpGroupWare extension'))
 
102
                        );
 
103
                }
 
104
                else {
 
105
                        $return[] = array(
 
106
                                array('kind' => 'input', 'type' => 'submit', 'name' => 'form_subpage_phpGroupwareGroup_attributes_addObjectClass', 'value' => _('Add phpGroupWare extension'))
 
107
                        );                      
 
108
                }
 
109
                return $return;
 
110
        }
 
111
        
 
112
        /**
 
113
        * Processes user input of the primary module page.
 
114
        * It checks if all input values are correct and updates the associated LDAP attributes.
 
115
        *
 
116
        * @return array list of info/error messages
 
117
        */
 
118
        public function process_attributes() {
 
119
                if (isset($_POST['form_subpage_phpGroupwareGroup_attributes_addObjectClass'])) {
 
120
                        $this->attributes['objectClass'][] = 'phpgwGroup';
 
121
                }
 
122
                elseif (isset($_POST['form_subpage_phpGroupwareGroup_attributes_remObjectClass'])) {
 
123
                        for ($i = 0; $i < sizeof($this->attributes['objectClass']); $i++) {
 
124
                                if ($this->attributes['objectClass'][$i] == 'phpgwGroup') {
 
125
                                        unset($this->attributes['objectClass'][$i]);
 
126
                                        break;
 
127
                                }
 
128
                        }
 
129
                }
 
130
                return array();
 
131
        }
 
132
 
 
133
        
 
134
        /**
 
135
        * Returns a list of modifications which have to be made to the LDAP account.
 
136
        *
 
137
        * @return array list of modifications
 
138
        * <br>This function returns an array with 3 entries:
 
139
        * <br>array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... )
 
140
        * <br>DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid)
 
141
        * <br>"add" are attributes which have to be added to LDAP entry
 
142
        * <br>"remove" are attributes which have to be removed from LDAP entry
 
143
        * <br>"modify" are attributes which have to been modified in LDAP entry
 
144
        */
 
145
        function save_attributes() {
 
146
                if (!in_array('phpgwGroup', $this->attributes['objectClass'])) {
 
147
                        return parent::save_attributes();
 
148
                }
 
149
                // set phpgwGroupID to GID number for new accounts
 
150
                $attrs = $this->getAccountContainer()->getAccountModule('posixGroup')->getAttributes();
 
151
                $this->attributes['phpgwGroupID'][0] = $attrs['gidNumber'][0];
 
152
                return parent::save_attributes();
 
153
        }
 
154
        
 
155
        /**
 
156
         * Allows the module to run commands after the LDAP entry is changed or created.
 
157
         * 
 
158
         * Calling this method requires the existence of an enclosing {@link accountContainer}.
 
159
         *
 
160
         * @param boolean $newAccount new account
 
161
         */
 
162
        public function postModifyActions($newAccount) {
 
163
                // check if extension was removed
 
164
                if (!$newAccount &&
 
165
                        (in_array('phpgwGroup', $this->orig['objectClass']) && !in_array('phpgwGroup', $this->attributes['objectClass']))) {
 
166
                        $dn = $this->getAccountContainer()->finalDN;
 
167
                        $attributes = array(
 
168
                                'objectClass' => array('phpgwGroup'),
 
169
                                'phpgwGroupID' => $this->attributes['phpgwGroupID']
 
170
                        );
 
171
                        $success = @ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes);
 
172
                        if (!$success) {
 
173
                                StatusMessage('ERROR', sprintf(_('Was unable to remove attribtues from DN: %s.'), $dn), ldap_error($_SESSION['ldap']->server()));
 
174
                        }
 
175
                }
 
176
                return;
 
177
        }
 
178
 
 
179
        /**
 
180
        * In this function the LDAP account is built up.
 
181
        *
 
182
        * @param array $rawAccounts list of hash arrays (name => value) from user input
 
183
        * @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
 
184
        * @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
 
185
        * @return array list of error messages if any
 
186
        */
 
187
        function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
 
188
                for ($i = 0; $i < sizeof($rawAccounts); $i++) {
 
189
                        if (isset($rawAccounts[$i][$ids['phpGroupwareGroup_extension']]) 
 
190
                                && (strtolower($rawAccounts[$i][$ids['phpGroupwareGroup_extension']]) == "true")) {
 
191
                                        $partialAccounts[$i]['objectClass'][] = 'phpgwGroup';
 
192
                                        $partialAccounts[$i]['phpgwGroupID'][0] = $partialAccounts[$i]['gidNumber'];
 
193
                        }
 
194
                }
 
195
                return array();
 
196
        }
 
197
 
 
198
}
 
199
 
 
200
?>
 
 
b'\\ No newline at end of file'