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);
41 /* Toggle all selected / deselected */
42 $chk = "<input type='checkbox' id='select_all' name='select_all'
43 onClick='toggle_all_(\"^item_selected_[a-zA-Z0-9\=]*$\",\"select_all\");' >";
45 /* set Page header */
46 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
47 $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"));
48 $this->AddHeader(array("string"=>_("Department name"), "attach" => "style=''"));
49 $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'"));
52 /* Add SubSearch checkbox */
53 $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Ignore subtrees"), false);
55 /* Name ,Text ,Default , Connect with alphabet */
56 $this->AddRegex ("Regex", _("Regular expression for matching department names"), "*" , true);
57 }
60 function GenHeader()
61 {
62 /* Prepare departments,
63 which are shown in the listbox on top of the listbox
64 */
65 $options= "";
67 /* Get all departments within this subtree */
68 $base = $this->config->current['BASE'];
69 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
70 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
72 /* Load possible departments */
73 $ui= get_userinfo();
74 $tdeps= $ui->get_module_departments("department");
76 $ids = $this->config->idepartments;
78 foreach($deps as $dep){
79 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
81 $value = $ids[$dep['dn']];
82 if ($this->selectedBase == $dep['dn']){
83 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
84 } else {
85 $options.= "<option value='".$dep['dn']."'>$value</option>";
86 }
87 }
88 }
91 /* Generate list head */
92 $ui = get_userinfo();
93 $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase ,"department/department");
95 /* Add default header */
96 $listhead = MultiSelectWindow::get_default_header();
98 if(preg_match("/c/",$acl)){
99 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
100 " <input class='center' type='image' src='images/list_new_department.png' ".
101 " align='middle' alt='"._("Create new department")."' name='dep_new'> ";
102 }
105 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' ".
106 " alt='' height='16' width='1'> ".
107 " "._("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
108 " <input class='center' type='image' src='images/list_submit.png' align='middle' ".
109 " title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
111 /* Multiple options */
112 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
113 title='"._("Remove selected departments")."' alt='"._("Remove departments")."' name='remove_multiple_departments'> ";
115 $listhead .="</div>";;
117 $this->SetListHeader($listhead);
118 }
120 function execute()
121 {
122 $this->ClearElementsList();
123 $this->GenHeader();
124 }
126 function setEntries($list)
127 {
128 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
130 $ui = get_userinfo();
131 foreach($list as $key => $val) {
133 $actions= "";
135 $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
136 if(preg_match("/r/",$acl)){
137 $actions.= "<input class='center' type='image' src='images/edit.png'
138 alt='"._("edit")."' name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
139 }
141 if(preg_match("/c/",$acl)){
142 $actions.= "<input class='center' type='image' src='images/edittrash.png'
143 alt='"._("delete")."' name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
144 }
146 if(!isset($this->config->departments[trim($key)])){
147 $this->config->departments[trim($key)]="";
148 }
150 $non_empty="";
151 $keys= str_replace("/","\/",$key);
152 foreach($this->config->departments as $keyd=>$vald ){
153 if(preg_match("/".$keys."\/.*/",$keyd)){
154 $non_empty="full";
155 }
156 }
158 $title = preg_replace('/ /', ' ', @LDAP::fix($this->config->departments[$key]));
160 if($val == "."){
161 $field01 = array("string" => " ",
162 "attach" => "style='width:20px;'");
163 }else{
164 $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."'
165 name='item_selected_".base64_encode($key)."'>" ,
166 "attach" => "style='width:20px;'");
167 }
169 $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
170 $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
171 $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
172 right;'");
174 $this->AddElement( array($field01,$field0,$field1,$field2));
175 }
176 }
178 function Save()
179 {
180 MultiSelectWindow::Save();
181 }
183 function save_object()
184 {
185 /* Save automatic created POSTs like regex, checkboxes */
186 MultiSelectWindow::save_object();
187 }
188 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>