Code

Added a first set of reference changes - nearly untested
[gosa.git] / plugins / admin / departments / class_divListDepartment.inc
1 <?php
3 class divListDepartment extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   
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");
22     
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."));
34   
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" => "&nbsp;", "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"), _("Search in 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     $ui= get_userinfo();
69     $first = "";
70     $found = FALSE;
71     $base = $this->config->current['BASE'];
73     /* Add base */
74     $tmp = array();
75     $tmp[] = array("dn"=>$this->config->current['BASE']);
76     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
77                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
79     $deps = array();
80     foreach($tmp as $tm){
81       $deps[$tm['dn']] = $tm['dn'];
82     }
84     /* Load possible departments */
85     $ui= get_userinfo();
86     $tdeps= $ui->get_module_departments("department");
87     $ids = $this->config->idepartments;
88     $first = "";
89     $found = FALSE;
90     foreach($ids as $dep => $name){
91       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
93         /* Keep first base dn in mind, we could need this
94          *  info if no valid base was found
95          */
96         if(empty($first)) {
97           $first = $dep['dn'];
98         }
100         $value = $ids[$dep];
101         if ($this->selectedBase == $dep){
102           $found = TRUE;
103           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
104         } else {
105           $options.= "<option value='".$dep."'>$value</option>";
106         }
107       }
108     }
110     /* The currently used base is not visible with your acl setup.
111      * Set base to first useable base.
112      */
113     if(!$found){
114       $this->selectedBase = $first;
115     }
117     /* Generate list head */
118     $ui = get_userinfo();
119     $acl = $ui->get_permissions("ou=dummy,".$this->selectedBase  ,"department/department");
120       
121     /* Add default header */
122     $listhead = MultiSelectWindow::get_default_header();
124     if(preg_match("/c/",$acl)){
125       $listhead .=  " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
126         " <input class='center' type='image' src='images/list_new_department.png' ".
127         "   align='middle' alt='"._("Create new department")."' name='dep_new'>&nbsp; ";
128     }
129   
131     $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' ".
132       " alt='' height='16' width='1'>&nbsp;".
133       " "._("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
134       " <input class='center' type='image' src='images/list_submit.png' align='middle' ".
135       "   title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
137     /* Multiple options */
138     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
139         title='"._("Remove selected departments")."' alt='"._("Remove departments")."' name='remove_multiple_departments'>&nbsp;";
141     $listhead .="</div>";;
143     $this->SetListHeader($listhead);
144   }
146   function execute()
147   {
148     $this->ClearElementsList();
149     $this->GenHeader();
150   }
152   function setEntries($list)
153   {
154     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
156     $ui = get_userinfo();
157     foreach($list as $key => $val) {
159       $actions= "";      
161       $acl = $ui->get_permissions($this->config->departments[$key] ,"department/department");
162       if(preg_match("/r/",$acl)){
163         $actions.= "<input class='center' type='image' src='images/edit.png'
164           alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
165       }
167       if(preg_match("/c/",$acl)){
168         $actions.= "<input class='center' type='image' src='images/edittrash.png'
169           alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
170       }
172       if(!isset($this->config->departments[trim($key)])){
173         $this->config->departments[trim($key)]="";
174       }
176       /* check if this department contains sub-departments
177          Display different image in this case
178        */
179       $non_empty="";
180       $nkey= normalizePreg($key);
181       foreach($this->config->departments as $keyd=>$vald ){
182         if(preg_match('/$nkey\/.*/',$keyd)){
183           $non_empty="full";
184         }
185       }
187       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
189       if($val == "."){
190         $field01 = array("string" => "&nbsp;",
191             "attach" => "style='width:20px;'");
192       }else{
193         $field01 = array("string" => "<input type='checkbox' id='item_selected_".base64_encode($key)."' 
194             name='item_selected_".base64_encode($key)."'>" ,
195             "attach" => "style='width:20px;'");
196       }
198       $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
199       $field1 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style='' title='".$title."'");
200       $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:60px;border-right:0px;text-align:
201           right;'");
203       $this->AddElement( array($field01,$field0,$field1,$field2));
204     }
206     /* Create summary string for list footer */
207     $num_deps=count($list);
208     $num_dep_str = _("Number of listed departments");
209     $str = "<img class='center' src='images/folder.png'
210               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
211     $this->set_List_Bottom_Info($str);
213   }
214   function Save()
215   {
216     MultiSelectWindow::Save();
217   }
219   function save_object()
220   {
221     /* Save automatic created POSTs like regex, checkboxes */
222     MultiSelectWindow::save_object();   
223   }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>