3
* This code is part of GOsa (http://www.gosa-project.org)
4
* Copyright (C) 2003-2010 GONICUS GmbH
6
* ID: $$Id: class_listing.inc 15296 2010-01-26 08:27:39Z cajus $$
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.
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.
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
23
class releaseSelector {
29
public $submitButton= true;
36
function __construct($bases, $base, $releaseBase)
39
$this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE));
41
// Get list of used IDs
42
if(!session::is_set('releaseSelector_USED_IDS')){
43
session::set('releaseSelector_USED_IDS',array());
45
$usedIds = session::get('releaseSelector_USED_IDS');
47
// Generate instance wide unique ID
49
while($pid == "" || in_array($pid, $usedIds)){
51
// Wait 1 msec to ensure that we definately get a new id
52
if($pid != "") usleep(1);
54
$pid = 'l'.md5(microtime().$tmp['sec']);
57
// Only keep the last 10 list IDsi
58
$usedIds = array_slice($usedIds, count($usedIds) -10, 10);
60
session::set('releaseSelector_USED_IDS',$usedIds);
64
$this->releaseBase = $releaseBase;
65
$this->setBases($bases);
66
$this->setBase($base);
70
function setSubmitButton($flag)
72
$this->submitButton= $flag;
76
function setHeight($value)
78
$this->height= $value;
82
function setBase($base)
85
if (isset($this->pathMapping[$base])) {
90
function setRootBase($base)
92
$this->releaseBase = $base;
96
function checkBase($base)
98
return isset($this->pathMapping[$base]);
102
function checkLastBaseUpdate()
104
return $this->lastState;
108
function setBases($bases)
111
$this->releaseInfo = array();
112
$this->pathMapping= array();
113
$selected= $this->base == $this->releaseBase?"Selected":"";
117
foreach ($bases as $base => $dummy) {
119
// Build path style display
120
$elements= explode(',', substr($base, 0, strlen($base) - strlen($this->releaseBase)));
121
$elements= array_reverse($elements, true);
122
$this->pathMapping[$base]= $base == $this->releaseBase? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements)));
124
$this->releaseInfo[$base]['name'] = ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '', $elements[0]));
125
$this->releaseInfo[$base]['description'] = $dummy;
128
// Save bases to session for autocompletion
129
session::global_set('pathMapping', $this->pathMapping);
130
session::global_set('department_info', $this->releaseInfo);
134
function update($force= false)
138
// Analyze for base changes if needed
140
$last_base= $this->base;
141
if(isset($_REQUEST["BPID_{$this->pid}"]) && $_REQUEST["BPID_{$this->pid}"] == $this->pid) {
142
if (isset($_POST['bs_rebase_'.$this->pid]) && !empty($_POST['bs_rebase_'.$this->pid])) {
143
$new_base= base64_decode(get_post('bs_rebase_'.$this->pid));
144
if (isset($this->pathMapping[$new_base])) {
145
$this->base= $new_base;
146
$this->action= 'rebase';
148
$this->lastState= false;
153
if (isset($_POST['bs_input_'.$this->pid])) {
155
// Take over input field base
156
if ($this->submitButton && isset($_POST['submit_base_'.$this->pid]) || !$this->submitButton) {
158
// Check if base is available
159
$this->lastState= false;
160
foreach ($this->pathMapping as $key => $path) {
161
if (mb_strtolower($path) == mb_strtolower(get_post('bs_input_'.$this->pid))) {
163
$this->lastState= true;
173
/* Skip if there's no change */
174
if (($this->tree && $this->base == $last_base) && !$force) {
178
$link= "onclick=\"\$('bs_rebase_".$this->pid."').value='".base64_encode($this->releaseBase)."';
179
$('submit_tree_base_".$this->pid."').click();\"";
181
$this->tree= "<input style='width:160px' type='text' size='35'
182
name='bs_input_{$this->pid}' id='bs_input_{$this->pid}'
184
onkeydown=\" \$('bs_{$this->pid}').hide(); \"
185
onfocus=\" \$('bs_{$this->pid}').hide(); \"
186
onmouseover=\" mouseIsStillOver = true;
189
if(mouseIsStillOver){
190
\$('bs_".$this->pid."').show();
193
Element.clonePosition(\$('bs_".$this->pid."'),
194
'bs_input_".$this->pid."',
195
{setHeight: false, setWidth: false, offsetTop:(Element.getHeight('bs_input_".$this->pid."'))});
196
rtimer=showIt.delay(0.25); \"
198
onmouseout=\" mouseIsStillOver=false;
199
rtimer=Element.hide.delay(0.25,'bs_".$this->pid."')\"
201
value=\"".preg_replace('/"/','"',$this->pathMapping[$this->base])."\">";
204
$this->tree.= "<div id='autocomplete_".$this->pid."' class='autocomplete'></div>".
205
"<script type='text/javascript'>".
206
"var mouseIsStillOver = false;".
207
"new Ajax.Autocompleter('bs_input_".$this->pid."', 'autocomplete_".$this->pid."', 'autocomplete.php?type=base', { minChars: 3, frequency: 0.5 });";
208
if ($this->submitButton) {
209
$this->tree.= "$('bs_input_".$this->pid."').observe('keypress', function(event) { if(event.keyCode == Event.KEY_RETURN) { $('submit_base_".$this->pid."').click(); } });";
211
$this->tree.= "</script>";
213
$selected= $this->base == $this->releaseBase?"Selected":"";
214
$this->tree.= "<div class='treeList' style='display:none;max-height:".$this->height."px' id='bs_".$this->pid."' onmouseover=\"window.clearTimeout(rtimer);\" onmouseout=\"rtimer= Element.hide.delay(0.25, 'bs_".$this->pid."')\"><a class='treeList$selected' $link>/ ["._("Root")."]</a><ul class='treeList'>\n";
218
foreach ($this->pathMapping as $base => $dummy) {
220
// Skip root for tree
221
if ($base == $this->releaseBase) {
225
// Build path style display
226
$elements= explode(',', substr($base, 0, strlen($base) - strlen($this->releaseBase)));
228
$indent= count($elements);
229
if (!$first && ($indent == $last_indent)) {
230
$this->tree.= "</li>\n";
232
if ($indent > $last_indent) {
233
$this->tree.= "<ul>\n";
235
if ($indent < $last_indent) {
236
for ($i= 0; $i < ($last_indent-$indent); $i++) {
237
$this->tree.= "</li></ul>\n";
239
$this->tree.= "</li>\n";
241
$selected= $this->base == $base?" class='treeListSelected'":"";
242
$link= "onclick=\"\$('bs_rebase_".$this->pid."').value='".base64_encode($base)."';$('submit_tree_base_".$this->pid."').click();\"";
244
$this->tree.= "<li>".
245
"<a$selected $link>".
246
$this->gennonbreaks($this->releaseInfo[$base]['name']).
247
($this->releaseInfo[$base]['description']==''?'':' <span class="informal">['.$this->gennonbreaks($this->releaseInfo[$base]['description']).']</span>').
250
$last_indent= $indent;
255
for ($i= 1; $i<$last_indent; $i++) {
256
$this->tree.= "</li></ul>\n";
258
$this->tree.= "</div>\n";
260
// Draw submitter if required
261
if ($this->submitButton) {
262
$this->tree.= image('images/lists/submit.png', "submit_base_".$this->pid, _("Submit"));
264
$this->tree.= "<input type='submit' style='display:none' name='submit_tree_base_".$this->pid."' id='submit_tree_base_".$this->pid."'>";
265
$this->tree.= "<input type='hidden' name='bs_rebase_".$this->pid."' id='bs_rebase_".$this->pid."'>";
266
$this->tree.= "<input type='hidden' name='BPID_{$this->pid}' id='BPID_{$this->pid}' value='".$this->pid."'>";
268
$this->lastState= true;
273
function gennonbreaks($string)
275
return str_replace('-', '‑', str_replace(' ', ' ', $string));
293
// Do not do anything if this is not our BPID, or there's even no BPID available...
294
if(!isset($_REQUEST["BPID_{$this->pid}"]) || $_REQUEST["BPID_{$this->pid}"] != $this->pid) {
299
return array("targets" => array($this->base), "action" => $this->action);