Code

de822bb544cabbcb8220243faf2991ebc0e3a8b9
[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();
36     $this->SetInformation(_("This menu allows you to add, edit and remove selected macros. You may want to use the range selector on top of the macro listbox, when working with a large number of macros."));
38     $this->EnableAplhabet   (true);
39   
40     /* Disable buttonsm */
41     $this->EnableCloseButton(false);
42     $this->EnableSaveButton (false);
44     /* Dynamic action col, depending on snapshot icons */
45     $action_col_size = 100;
46     if($this->parent->snapshotEnabled()){
47       $action_col_size += 20;
48     }
50     /* Toggle all selected / deselected */
51     $chk = "<input type='checkbox' id='select_all' name='select_all'
52                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
54     /* set Page header */
55     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
56     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
57     $this->AddHeader(array("string" => _("Macro name")." / "._("Department"), "attach" => "style=''"));
58     $this->AddHeader(array("string" => _("Visible"), "attach" => "style='width:50px;'"));
59     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
61     /* Add Checkboxes / SubSearch checkbox */
62     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
64     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
65     $this->AddRegex   ("Regex",     _("Regular expression for matching macro names"),"*" , true);
66   }
68   function GenHeader()
69   {
70     /* Prepare departments,
71        which are shown in the listbox on top of the listbox
72      */
73     $options= "";
75     /* Get all departments within this subtree */
76     $base = $this->config->current['BASE'];
77     $first = "";
78     $found = FALSE;
80     /* Add base */
81     $tmp = array();
82     $tmp[] = array("dn"=>$this->config->current['BASE']);
83     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
84                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
86     $deps = array();
87     foreach($tmp as $tm){
88       $deps[$tm['dn']] = $tm['dn'];
89     }
91     /* Load possible departments */
92     $ui= get_userinfo();
93     $tdeps= $ui->get_module_departments("gofonmacro");
94     $ids = $this->config->idepartments;
95     $first = "";
96     $found = FALSE;
97     foreach($ids as $dep => $name){
98       if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){
100         /* Keep first base dn in mind, we could need this
101          *  info if no valid base was found
102          */
103         if(empty($first)) {
104           $first = $dep['dn'];
105         }
107         $value = $ids[$dep];
108         if ($this->selectedBase == $dep){
109           $found = TRUE;
110           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
111         } else {
112           $options.= "<option value='".$dep."'>$value</option>";
113         }
114       }
115     }
117     /* The currently used base is not visible with your acl setup.
118      * Set base to first useable base.
119      */
120     if(!$found){
121       $this->selectedBase = $first;
122     }
124     $acls  = $ui->get_permissions($this->selectedBase,"gofonmacro/macro");
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/list_submit.png' align='middle' 
130       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
131     
132     /* Create Layers menu */
133     $s  = ".|"._("Actions")."|\n";
134     $s .= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
135       "&nbsp;"._("Create")."|\n";
137     /* Append create options */
138     if(preg_match("/c/",$acls)){
139       $s.= "...|<input class='center' type='image' src='images/list_new_macro.png' alt=''>".
140         "&nbsp;"._("Macro")."|goFonMacro_new|\n";
141     }
143     /* Multiple options */
144     $s.= "..|---|\n";
145     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
146       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
148     /* Add multiple copy & cut icons */
149     if(preg_match("/(c.*w|w.*c)/",$acls) && is_object( $this->parent->CopyPasteHandler)){
150       $s.= "..|---|\n";
151       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
152         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
153       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
154         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
156       if($this->parent->CopyPasteHandler->entries_queued()){
157         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
158         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
159       }else{
160         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
161         $s.="..|".$img."&nbsp;"._("Paste")."\n";
162       }
163     }
165     /* Add snapshot icons */
166     if(preg_match("/(c.*w|w.*c)/",$acls)){
167       $s .= "..|---|\n";
168       $s .= $this->get_snapshot_header(TRUE);
169     }
171     $this->SetDropDownHeaderMenu($s);
176     $this->SetListHeader($listhead);
177   }
179   function execute()
180   {
181     $this->ClearElementsList();
182     $this->GenHeader();
183   }
185   function setEntries($list)
186   {
187   
188     $empty      = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
189     $macroimg   = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
190     $visible    = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
191     $invisible  = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
192     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
194     /* Dynamic action col, depending on snapshot icons */
195     $action_col_size = 100;
196     if($this->parent->snapshotEnabled()){
197       $action_col_size += 20;
198     }
200     $ui = get_userinfo();
202     foreach($list as $key => $val){
203        
204       $sacl  = $ui->get_permissions($val['dn'],"gofonmacro/macro");
206       $action = "";
207       if(!preg_match("/r/",$sacl)){
208         continue;
209       }
211       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$sacl)){
212         $action.= "<input class='center' type='image'
213           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
214         $action.= "<input class='center' type='image'
215           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
216       }
218       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
219         name='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
221       if(preg_match("/c/",$sacl) && preg_match("/w/",$sacl)){
222         $action.= $this->GetSnapShotActions($val['dn']); 
223       }
225       if(preg_match("/d/",$sacl)){
226         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   
227           name='goFonMacro_del_%KEY%' title='"._("Delete macro")."'>";
228       }
230       if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
231         $pic1 = $visible;
232       }else{
233         $pic1 = $invisible;
234       }
236       $display= $val["displayName"][0]."&nbsp;(".$val["cn"][0].")";
237       if(isset($val['description'][0])){
239         $desc = $val['description'][0];
240         if(strlen($desc) > 55){
241           $desc = substr($desc,0,52)."...";
242         }
244         $display .= "&nbsp;[".$desc."]";
245       }
247       /* Cutted objects should be displayed in light grey */
248       if($this->parent->CopyPasteHandler){
249         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
250           if($queue_data['dn'] == $val['dn']) {
251             $display = "<font color='#999999'>".$display."</font>";
252             break;
253           }
254         }
255       }
257       /* Create each field */
258       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
259                       "attach" => "style='width:20px;'");
260       $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
261       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
262       $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
263       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
265       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
266     }
268     /* Create summary string for list footer */
269     $num_deps=0;
270     if(!$this->SubSearch){
271       $num_deps = count($this->Added_Departments);
272     }
273     $num_objs = count($list);
275     $num_obj_str = _("Number of listed macros");
276     $num_dep_str = _("Number of listed departments");
278     $str = "<img class='center' src='images/select_macro.png'
279               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
280     $str.= "<img class='center' src='images/folder.png'
281               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
283     $this->set_List_Bottom_Info($str);
284   }
286   function Save()
287   {
288     MultiSelectWindow :: Save();  
289   }
291   function save_object()
292   {
293     /* Save automatic created POSTs like regex, checkboxes */
294     MultiSelectWindow :: save_object();   
295   }
297 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
298 ?>