Code

Some fixes for trunk from 2.5
[gosa.git] / plugins / 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 = 50;
46     if($this->parent->snapshotEnabled()){
47       $action_col_size += 20;
48     }
50     /* set Page header */
51     $this->AddHeader(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"));
52     $this->AddHeader(array("string" => _("Macro name")." / "._("Department"), "attach" => "style=''"));
53     $this->AddHeader(array("string" => _("Visible"), "attach" => "style='width:50px;'"));
54     $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" ));
56     /* Add Checkboxes / SubSearch checkbox */
57     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Ignore subtrees"), false);
59     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
60     $this->AddRegex   ("Regex",     _("Regular expression for matching macro names"),"*" , true);
61   }
63   function GenHeader()
64   {
65     /* Prepare departments,
66        which are shown in the listbox on top of the listbox
67      */
68     $options= "";
70     /* Get all departments within this subtree */
71     $base = $this->config->current['BASE'];
72     $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
73                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
75     /* Load possible departments */
76     $ui= get_userinfo();
77     $tdeps= $ui->get_module_departments("gofonmacro");
79     $ids = $this->config->idepartments;
81     foreach($deps as $dep){
82       if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
84         $value = $ids[$dep['dn']];
85         if ($this->selectedBase == $dep['dn']){
86           $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
87         } else {
88           $options.= "<option value='".$dep['dn']."'>$value</option>";
89         }
90       }
91     }
93     $acls  = $ui->get_permissions($this->selectedBase,"gofonmacro/macro");
95     /* Add default header */
96     $listhead = MultiSelectWindow::get_default_header();
98     if(preg_match("/w/",$acls) && preg_match("/c/",$acls)){
99       $listhead .= $this->get_snapshot_header($this->selectedBase);
100     }
101     if(preg_match("/c/",$acls)){
102       $listhead .=  " <input class='center' type='image' align='middle' src='images/list_new_macro.png' 
103         title='"._("Create new phone macro")."' alt='"._("New")."' name='goFonMacro_new'>&nbsp;";
104       $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
105     }
106     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
107       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
108       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
109       "</div>";
111     $this->SetListHeader($listhead);
112   }
114   function execute()
115   {
116     $this->ClearElementsList();
117     $this->GenHeader();
118   }
120   function setEntries($list)
121   {
122   
123     $empty      = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
124     $macroimg   = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
125     $visible    = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
126     $invisible  = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
127     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
129     /* Dynamic action col, depending on snapshot icons */
130     $action_col_size = 50;
131     if($this->parent->snapshotEnabled()){
132       $action_col_size += 20;
133     }
135     $ui = get_userinfo();
137     foreach($list as $key => $val){
138        
139       $sacl  = $ui->get_permissions($val['dn'],"gofonmacro/macro");
141       $action = "";
142       if(!preg_match("/r/",$sacl)){
143         continue;
144       }
146       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
147         name='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
149       if(preg_match("/c/",$sacl) && preg_match("/w/",$sacl)){
150         $action.= $this->GetSnapShotActions($val['dn']); 
151       }
153       if(preg_match("/d/",$sacl)){
154         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   
155           name='goFonMacro_del_%KEY%' title='"._("Delete macro")."'>";
156       }
158       if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
159         $pic1 = $visible;
160       }else{
161         $pic1 = $invisible;
162       }
164       $display= $val["displayName"][0]."&nbsp;(".$val["cn"][0].")";
165       if(isset($val['description'][0])){
167         $desc = $val['description'][0];
168         if(strlen($desc) > 55){
169           $desc = substr($desc,0,52)."...";
170         }
172         $display .= "&nbsp;[".$desc."]";
173       }
176       $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
177       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
178       $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
179       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
181       $this->AddElement(array($field1,$field2,$field3,$field4));
182     }
183   }
185   function Save()
186   {
187     MultiSelectWindow :: Save();  
188   }
190   function save_object()
191   {
192     /* Save automatic created POSTs like regex, checkboxes */
193     MultiSelectWindow :: save_object();   
194   }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>