File: asteriskExt.inc

package info (click to toggle)
ldap-account-manager 9.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84,712 kB
  • sloc: php: 226,230; javascript: 83,487; pascal: 41,693; perl: 414; sh: 273; xml: 228; makefile: 188
file content (191 lines) | stat: -rw-r--r-- 4,858 bytes parent folder | download
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php

/*

  This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
  Copyright (C) 2009 - 2012  Pozdnyak Pavel
                2010 - 2024  Roland Gruber

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 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 General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */

/**
 * The account type for Asterisk extensions.
 *
 * @package types
 * @author Pozdnyak Pavel
 * @author Roland Gruber
 */

/**
 * The account type for Asterisk extensions.
 *
 * @package types
 */
class asteriskExt extends baseType {

	/**
	 * Constructs a new domain type object.
	 *
	 * @param ConfiguredType $type configuration
	 */
	public function __construct($type) {
		parent::__construct($type);
		$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another extension');
		$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to extensions list');
	}

	/**
	 * Returns the alias name of this account type.
	 *
	 * @return string alias name
	 */
	function getAlias() {
		return _("Asterisk extensions");
	}

	/**
	 * Returns the description of this account type.
	 *
	 * @return string description
	 */
	function getDescription() {
		return _("Asterisk extensions entries");
	}

	/**
	 * Returns the class name for the list object.
	 *
	 * @return string class name
	 */
	function getListClassName() {
		return "lamAsteriskExtList";
	}

	/**
	 * Returns the default attribute list for this account type.
	 *
	 * @return string attribute list
	 */
	function getDefaultListAttributes() {
		return "#AstExtension;#AstContext;#member";
	}

	/**
	 * Returns the the title text for the title bar on the new/edit page.
	 *
	 * @param accountContainer $container account container
	 * @return String title text
	 */
	public function getTitleBarTitle($container) {
		$attributes = null;
		if ($container->getAccountModule('asteriskExtension') != null) {
			$attributes = $container->getAccountModule('asteriskExtension')->getAttributes();
		}
		// check if a common name is set
		if (isset($attributes['AstExtension'][0])) {
			return htmlspecialchars($attributes['AstExtension'][0]);
		}
		// new account
		if ($container->isNewAccount) {
			return _("New extension");
		}
		// fall back to default
		return parent::getTitleBarTitle($container);
	}

}

/**
 * Generates the list view.
 *
 * @package lists
 * @author Pozdnyak Pavel
 *
 */
class lamAsteriskExtList extends lamList {

	/**
	 * Constructor
	 *
	 * @param string $type account type
	 * @return lamList list object
	 */
	function __construct($type) {
		parent::__construct($type);
		$this->labels = [
			'nav' => _("Extension count: %s"),
			'error_noneFound' => _("No Asterisk extensions found."),
			'newEntry' => _("New extension"),
			'deleteEntry' => _("Delete selected extensions")
		];
	}

	/**
	 * Forces the list view to show only specific attributes.
	 *
	 * @see lamList::listGetParams()
	 */
	protected function listGetParams() {
		// check if only PDF should be shown
		parent::listGetParams();
		$this->attrArray = ["astextension", "astcontext", "member"];
		$this->descArray = [_("Extension name"), _("Account context"), _("Owner")];
	}

	/**
	 * Groups the extensions.
	 *
	 * (non-PHPdoc)
	 * @see lamList::listRefreshData()
	 */
	protected function listRefreshData() {
		// configure search filter
		$module_filter = get_ldap_filter($this->type->getId());  // basic filter is provided by modules
		$filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
		$attrs = $this->attrArray;
		$attrs[] = "astpriority";
		$entries = searchLDAP($this->suffix, $filter, $attrs);
		$lastError = getLastLDAPError();
		if ($lastError != null) {
			call_user_func_array('StatusMessage', $lastError);
		}

		$this->ldapEntries = $this->normalizeLdapOutput($entries);
		$this->entries = [];
		foreach ($this->ldapEntries as $index => &$attrs) {
			$this->entries[$index] = &$attrs;
		}
		// generate list of possible suffixes
		$this->possibleSuffixes = $this->type->getSuffixList();
	}

	/**
	 * Groups the extensions.
	 *
	 * @param array $entries extension entries
	 */
	private function normalizeLdapOutput($entries) {
		$filteredEntries = [];
		foreach ($entries as $entry) {
			if ($entry["astpriority"][0] == '1') {
				$filteredEntries[] = $entry;
			}
		}
		return $filteredEntries;
	}

}