Code

Rworked tagging && moving behavior, must be TESTED
[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");
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 size 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);
39     /* set Page header */
40     $this->AddHeader(array("string" => "&nbsp;", "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:80px;border-right:0px;text-align:right;'"));
44     /* Add SubSearch checkbox */    
45     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
47     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
48     $this->AddRegex   ("Regex",     _("Regular expression for matching group names"), "*" , true);
49   }
52   function GenHeader()
53   {
54     /* Prepare departments,
55        which are shown in the listbox on top of the listbox
56      */
57     $options= "";
58     foreach ($this->config->idepartments as $key => $value){
59       if ($this->selectedBase == $key){
60         $options.= "<option selected='selected' value='$key'>$value</option>";
61       } else {
62         $options.= "<option value='$key'>$value</option>";
63       }
64     }
66     /* Generate list head */
67     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
68       " <input type='image' class='center' src='images/list_root.png' align='middle' 
69         title='"._("Go to root department")."' name='dep_root' alt='".       _("Root")."'>&nbsp;".
70       " <input type='image' class='center' src='images/list_up.png' align='middle' 
71         title='"._("Go up one department")."' name='dep_back' alt='"._("Up").  "'>&nbsp;".
72       " <input type='image' class='center' src='images/list_home.png' align='middle' 
73         title='"._("Go to users home department")."' name='dep_home' alt='". _("Home")."'>&nbsp;".
74       " <input class='center' type='image' src='images/list_reload.png' align='middle' 
75         title='"._("Reload list")."' name='submit_department' alt='".      _("Submit")."'>&nbsp;".
76       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
78     if($this->parent->snapshotEnabled()){
79       $listhead .= "  <input class='center' type='image' align='middle' src='images/restore.png'        
80         title='"._("Restore snapshopts of already deleted objects")."' alt='"._("Restore")."' name='RestoreDeletedSnapShot'>".
81         " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
82     }
84     $listhead .=  " <input class='center' type='image' src='images/list_new_department.png' 
85         align='middle' alt='"._("Create new department")."' name='dep_new'>&nbsp; ".
86       " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
87       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
88       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
89         title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
90       "</div>";
92     $this->SetListHeader($listhead);
93   }
95   function execute()
96   {
97     $this->ClearElementsList();
98     $this->GenHeader();
99   }
101   function setEntries($list)
102   {
104     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
106     foreach($list as $key => $val) {
107   
108       $cdn= convert_department_dn($val['dn']);  
109       if(isset($val["description"][0])) {
110         $disp = get_sub_department($cdn)." - [".$val["description"][0]."]";
111       }else{
112         $disp = get_sub_department($cdn);
113       }
114   
115       $actions = $this->GetSnapShotActions($val['dn']);
116       $actions.= "<input class='center' type='image' src='images/edit.png'
117         alt='"._("edit")."'   name='dep_edit_%KEY%' title='"._("Edit this entry")."'>";
118       $actions.= "<input class='center' type='image' src='images/edittrash.png'
119         alt='"._("delete")."'   name='dep_del_%KEY%' title='"._("Delete this entry")."'>";
121       if(!isset($this->config->departments[trim($key)])){
122         $this->config->departments[trim($key)]="";
123       }
125       $non_empty="";
126       $keys= str_replace("/","\/",$key);
127       foreach($this->config->departments as $keyd=>$vald ){
128         if(preg_match("/".$keys."\/.*/",$keyd)){
129           $non_empty="full";
130         }
131       }
133       $title = preg_replace('/ /', '&nbsp;', @LDAP::fix($this->config->departments[$key]));
134       $field0 = array("string" => "<img src='images/".$non_empty."folder.png' title='"._("department")."' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
135       $field1 = array("string" => sprintf($linkopen,base64_encode($cdn),$disp), "attach" => "style='' title='".$title."'");
136       $field2 = array("string" => preg_replace("/%KEY%/", base64_encode($key), $actions), "attach" => "style='width:80px;border-right:0px;text-align:
137           right;'");
139       $this->AddElement( array($field0,$field1,$field2));
140     }
141   }
143   function Save()
144   {
145     MultiSelectWindow::Save();
146   }
148   function save_object()
149   {
150     /* Save automatic created POSTs like regex, checkboxes */
151     MultiSelectWindow::save_object();   
152   }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>