1 <?php
3 class divListDepartment extends MultiSelectWindow
4 {
6 /* Current base */
7 var $selectedBase = "";
8 var $departments = array();
10 /* Regex */
11 var $Regex = "*";
13 /* Subsearch checkbox */
14 var $SubSearch = false;
16 var $parent ;
17 var $ui ;
19 function divListDepartment ($config,$parent)
20 {
21 MultiSelectWindow::MultiSelectWindow($config, "Department", "department");
23 $this->parent = $parent;
24 $this->ui = get_userinfo();
26 /* Set list strings */
27 $this->SetTitle(_("List of departments"));
28 $this->SetSummary(_("List of departments"));
29 $this->EnableAplhabet (true);
31 /* Result page will look like a headpage */
32 $this->SetHeadpageMode();
33 $this->SetInformation(_("This menu allows you to create, delete and edit selected departments. Having a large number of departments, you might prefer the range selectors on top of the department list."));
35 /* Disable buttonsm */
36 $this->EnableCloseButton(false);
37 $this->EnableSaveButton (false);
39 /* set Page header */
40 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
41 $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
42 $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
45 /* Add SubSearch checkbox */
46 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
48 /* Name ,Text ,Default , Connect with alphabet */
49 $this->AddRegex ("Regex", _("Regular expression for matching department names"), "*" , true);
50 }
53 function GenHeader()
54 {
55 /* Prepare departments,
56 which are shown in the listbox on top of the listbox
57 */
58 $options= "";
60 /* Get all departments within this subtree */
61 $base = $this->config->current['BASE'];
62 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
63 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
65 /* Load possible departments */
66 $ui= get_userinfo();
67 $tdeps= $ui->get_module_departments("department");
69 $ids = $this->config->idepartments;
71 foreach($deps as $dep){
72 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
74 $value = $ids[$dep['dn']];
75 if ($this->selectedBase == $dep['dn']){
76 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
77 } else {
78 $options.= "<option value='".$dep['dn']."'>$value</option>";
79 }
80 }
81 }
84 /* Generate list head */
85 $ui = get_userinfo();
86 $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/department");
88 /* Add default header */
89 $listhead = MultiSelectWindow::get_default_header();
91 if(preg_match("/c/",$acl)){
92 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
93 " <input class='center' type='image' src='images/list_new_department.png' ".
94 " align='middle' alt='"._("Create new department")."' name='dep_new'> ";
95 }
98 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' ".
99 " alt='' height='16' width='1'> ".
100 " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
101 " <input class='center' type='image' src='images/list_submit.png' align='middle' ".
102 " title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
103 "</div>";
105 $this->SetListHeader($listhead);
106 }
108 function execute()
109 {
110 $this->ClearElementsList();
111 $this->GenHeader();
112 }
114 function setEntries($list)
115 {
116 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
118 $ui = get_userinfo();
119 foreach($list as $key => $val) {
121 $actions= "";
123 $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
124 if(preg_match("/r/",$acl)){
125 $actions.= "<input class='center' type='image' src='images/edit.png'
126 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
127 }
129 if(preg_match("/c/",$acl)){
130 $actions.= "<input class='center' type='image' src='images/edittrash.png'
131 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
132 }
134 if(!isset($this->config->departments[trim($key)])){
135 $this->config->departments[trim($key)]="";
136 }
138 $non_empty="";
139 $keys= str_replace("/","\/",$key);
140 foreach($this->config->departments as $keyd=>$vald ){
141 if(preg_match("/".$keys."\/.*/",$keyd)){
142 $non_empty="full";
143 }
144 }
146 $title = preg_replace('/ /', ' ', @LDAP::fix($this->config->departments[$key]));
147 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
148 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
149 $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
150 right;'");
152 $this->AddElement( array($field0,$field1,$field2));
153 }
154 }
156 function Save()
157 {
158 MultiSelectWindow::Save();
159 }
161 function save_object()
162 {
163 /* Save automatic created POSTs like regex, checkboxes */
164 MultiSelectWindow::save_object();
165 }
166 }
167 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
168 ?>