Code

Updated move and create checks
[gosa.git] / gosa-plugins / gofon / gofon / macro / class_divListMacros.inc
1 <?php
3 class divListMacro extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
13   /* checkboxes */
14   var $ShowSendBocklists      ;
15   var $ShowReceiveMacros  ;
17   /* Subsearch checkbox */
18   var $SubSearch;
20   var $parent             ;
21   var $ui                 ;
23   function divListMacro (&$config,$parent)
24   {
25     MultiSelectWindow::MultiSelectWindow($config,"Macros", "gofonmacro");
26     
27     $this->parent       = $parent;
28     $this->ui           = get_userinfo();
30     /* Set list strings */
31     $this->SetTitle(_("List of macros"));
32     $this->SetSummary(_("List of macros"));
34     /* Result page will look like a headpage */
35     $this->SetHeadpageMode();
37     $this->EnableAplhabet   (true);
38   
39     /* Disable buttonsm */
40     $this->EnableCloseButton(false);
41     $this->EnableSaveButton (false);
43     /* Dynamic action col, depending on snapshot icons */
44     $action_col_size = 100;
45     if($this->parent->snapshotEnabled()){
46       $action_col_size += 20;
47     }
49     /* Toggle all selected / deselected */
50     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
51                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
53     /* set Page header */
54     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
55     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
56     $this->AddHeader(array("string" => _("Name")." / "._("Department"), "attach" => "style=''"));
57     $this->AddHeader(array("string" => _("Visible"), "attach" => "style='width:50px;'"));
58     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
60     /* Add Checkboxes / SubSearch checkbox */
61     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
63     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
64     $this->AddRegex   ("Regex",     _("Regular expression for matching macro names"),"*" , true);
65   }
67   function GenHeader()
68   {
69     /* Prepare departments,
70        which are shown in the listbox on top of the listbox
71      */
72     $options= "";
74     /* Get all departments within this subtree */
75     $base = $this->config->current['BASE'];
76     $first = "";
77     $found = FALSE;
79     /* Add base */
80     $tmp = array();
81     $tmp[] = array("dn"=>$this->config->current['BASE']);
82     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
83                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
85     $deps = array();
86     foreach($tmp as $tm){
87       $deps[$tm['dn']] = $tm['dn'];
88     }
90     /* Load possible departments */
91     $ui= get_userinfo();
92     $tdeps= $ui->get_module_departments("gofonmacro");
93     $ids = $this->config->idepartments;
94     $first = "";
95     $found = FALSE;
96     foreach($ids as $dep => $name){
97       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
99         /* Keep first base dn in mind, we could need this
100          *  info if no valid base was found
101          */
102         if(empty($first)) {
103           $first = $dep['dn'];
104         }
106         $value = $ids[$dep];
107         if ($this->selectedBase == $dep){
108           $found = TRUE;
109           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
110         } else {
111           $options.= "<option value='".$dep."'>$value</option>";
112         }
113       }
114     }
116     /* The currently used base is not visible with your acl setup.
117      * Set base to first useable base.
118      */
119     if(!$found){
120       $this->selectedBase = $first;
121     }
123     $acl    = $ui->get_permissions($this->selectedBase,"gofonmacro/macro");
124     $acl_all= $ui->has_complete_category_acls($this->selectedBase,"gofonmacro");
126     /* Add default header */
127     $listhead = MultiSelectWindow::get_default_header();
128     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
129       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
130       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
131     
132     /* Create Layers menu */
133     $s  = ".|"._("Actions")."|\n";
135     /* Append create options */
136     if(preg_match("/c/",$acl)){
137       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
138         "&nbsp;"._("Create")."|\n";
139       $s.= "...|<input class='center' type='image' src='images/list_new_macro.png' alt=''>".
140         "&nbsp;"._("Macro")."|goFonMacro_new|\n";
141       $s.= "..|---|\n";
142     }
144     /* Multiple options */
145     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
146       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
149     if(is_object($this->parent->CopyPasteHandler) && preg_match("/r/",$acl_all)){
150       $s.= "..|---|\n";
151       $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
152         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
153       $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
154         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
155     }
157     /* Copy & paste icons */
158     if(is_object($this->parent->CopyPasteHandler) && $this->parent->CopyPasteHandler->entries_queued()){
159       $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
160       $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
161     }else{
162       $img = "<img border='0' class='center' src='images/lists/paste-grey.png' alt=''>";
163       $s.="..|".$img."&nbsp;"._("Paste")."\n";
164     }
166     /* Add snapshot icons */
167     if(preg_match("/(c.*w|w.*c)/",$acl_all)){
168       $s .= "..|---|\n";
169       $s .= $this->get_snapshot_header(TRUE);
170     }
172     $this->SetDropDownHeaderMenu($s);
173     $this->SetListHeader($listhead);
174   }
176   function execute()
177   {
178     $this->ClearElementsList();
179     $this->GenHeader();
180   }
182   function setEntries($list)
183   {
184   
185     $empty      = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
186     $macroimg   = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
187     $visible    = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
188     $invisible  = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
189     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
191     /* Dynamic action col, depending on snapshot icons */
192     $action_col_size = 100;
193     if($this->parent->snapshotEnabled()){
194       $action_col_size += 20;
195     }
197     $ui = get_userinfo();
199     foreach($list as $key => $val){
200        
201       $acl    = $ui->get_permissions($val['dn'],"gofonmacro/macro");
202       $acl_all= $ui->has_complete_category_acls($val['dn'],"gofonmacro");
204       $action = "";
205       if(!preg_match("/r/",$acl)){
206         continue;
207       }
209       if(preg_match("/(r.*d|r.*d)/",$acl_all) && $this->parent->CopyPasteHandler){
210         $action .= "<input class='center' type='image'
211           src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
212       }else{
213         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
214       }
216       if(preg_match("/r/",$acl_all) && $this->parent->CopyPasteHandler){
217         $action.= "<input class='center' type='image'
218           src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
219       }else{
220         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
221       }
223       $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'     
224         name='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
226       /* Add snapshot icon */
227       if(preg_match("/(r.*w|w.*r)/",$acl_all)){
228         $action.= $this->GetSnapShotActions($val['dn']);
229       }else{
230         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
231         $action.="<img src='images/empty.png' alt=' ' class='center'>&nbsp;";
232       }
235       if(preg_match("/d/",$acl)){
236         $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'   
237           name='goFonMacro_del_%KEY%' title='"._("Delete macro")."'>";
238       }
240       if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
241         $pic1 = $visible;
242       }else{
243         $pic1 = $invisible;
244       }
246       $display= $val["displayName"][0]."&nbsp;(".$val["cn"][0].")";
247       if(isset($val['description'][0])){
249         $desc = $val['description'][0];
250         if(strlen($desc) > 55){
251           $desc = substr($desc,0,52)."...";
252         }
254         $display .= "&nbsp;[".$desc."]";
255       }
257       /* Cutted objects should be displayed in light grey */
258       if($this->parent->CopyPasteHandler){
259         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
260           if($queue_data['dn'] == $val['dn']) {
261             $display = "<font color='#999999'>".$display."</font>";
262             break;
263           }
264         }
265       }
267       /* Create each field */
268       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
269                       "attach" => "style='width:20px;'");
270       $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
271       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
272       $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
273       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
275       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
276     }
278     /* Create summary string for list footer */
279     $num_deps=0;
280     if(!$this->SubSearch){
281       $num_deps = count($this->Added_Departments);
282     }
283     $num_objs = count($list);
285     $num_obj_str = sprintf(_("Number of listed %s"),_("macros"));
286     $num_dep_str = sprintf(_("Number of listed %s"),_("departments"));
288     $str = "<img class='center' src='images/select_macro.png'
289               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
290     $str.= "<img class='center' src='images/lists/folder.png'
291               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
293     $this->set_List_Bottom_Info($str);
294   }
296   function Save()
297   {
298     MultiSelectWindow :: Save();  
299   }
301   function save_object()
302   {
303     /* Save automatic created POSTs like regex, checkboxes */
304     MultiSelectWindow :: save_object();   
305   }
307 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
308 ?>