Code

682e9606aa9446ad28b6be5106d0f1a77a7c5c15
[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 = 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();
129     /* Get copy & paste icon */
130     $Copy_Paste ="";
131     if(preg_match("/(c.*w|w.*c)/",$acls) &&  $this->parent->CopyPasteHandler){
132       $Copy_Paste = $this->parent->CopyPasteHandler->generatePasteIcon();
133       $addsep = true;
134     }
136     if(preg_match("/w/",$acls) && preg_match("/c/",$acls)){
137       $listhead .= $this->get_snapshot_header($this->selectedBase);
138     }
140     $listhead .= $Copy_Paste;      
142     if(preg_match("/c/",$acls)){
143       $listhead .=  " <input class='center' type='image' align='middle' src='images/list_new_macro.png' 
144         title='"._("Create new phone macro")."' alt='"._("New")."' name='goFonMacro_new'>&nbsp;";
145       $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;";
146     }
147     $listhead .= _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
148       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
149       title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;";
150     
151     /* Multiple options */
152     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
153         title='"._("Remove selected macros")."' alt='"._("Remove macros")."' name='remove_multiple_macros'>&nbsp;";
155     /* Add multiple copy & cut icons */
156     if(is_object($this->parent->CopyPasteHandler)){
157       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcopy.png'
158         title='"._("Copy selected objects")."' alt='"._("Copy objects")."' name='multiple_copy_objects'>&nbsp;";
159       $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/editcut.png'
160         title='"._("cut selected objects")."' alt='"._("Cut objects")."' name='multiple_cut_objects'>&nbsp;";
161       $listhead .= "</div>";
162     }
164     $listhead .="</div>";
165     $this->SetListHeader($listhead);
166   }
168   function execute()
169   {
170     $this->ClearElementsList();
171     $this->GenHeader();
172   }
174   function setEntries($list)
175   {
176   
177     $empty      = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
178     $macroimg   = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
179     $visible    = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
180     $invisible  = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
181     $editlink   = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
183     /* Dynamic action col, depending on snapshot icons */
184     $action_col_size = 100;
185     if($this->parent->snapshotEnabled()){
186       $action_col_size += 20;
187     }
189     $ui = get_userinfo();
191     foreach($list as $key => $val){
192        
193       $sacl  = $ui->get_permissions($val['dn'],"gofonmacro/macro");
195       $action = "";
196       if(!preg_match("/r/",$sacl)){
197         continue;
198       }
200       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$sacl)){
201         $action.= "<input class='center' type='image'
202           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
203         $action.= "<input class='center' type='image'
204           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
205       }
207       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     
208         name='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
210       if(preg_match("/c/",$sacl) && preg_match("/w/",$sacl)){
211         $action.= $this->GetSnapShotActions($val['dn']); 
212       }
214       if(preg_match("/d/",$sacl)){
215         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   
216           name='goFonMacro_del_%KEY%' title='"._("Delete macro")."'>";
217       }
219       if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
220         $pic1 = $visible;
221       }else{
222         $pic1 = $invisible;
223       }
225       $display= $val["displayName"][0]."&nbsp;(".$val["cn"][0].")";
226       if(isset($val['description'][0])){
228         $desc = $val['description'][0];
229         if(strlen($desc) > 55){
230           $desc = substr($desc,0,52)."...";
231         }
233         $display .= "&nbsp;[".$desc."]";
234       }
236       /* Cutted objects should be displayed in light grey */
237       if($this->parent->CopyPasteHandler){
238         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
239           if($queue_data['dn'] == $val['dn']) {
240             $display = "<font color='#999999'>".$display."</font>";
241             break;
242           }
243         }
244       }
246       /* Create each field */
247       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
248                       "attach" => "style='width:20px;'");
249       $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
250       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
251       $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
252       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
254       $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
255     }
257     /* Create summary string for list footer */
258     $num_deps=0;
259     if(!$this->SubSearch){
260       $num_deps = count($this->Added_Departments);
261     }
262     $num_objs = count($list);
264     $num_obj_str = _("Number of listed macros");
265     $num_dep_str = _("Number of listed departments");
267     $str = "<img class='center' src='images/select_macro.png'
268               title='".$num_obj_str."' alt='".$num_obj_str."'>&nbsp;".$num_objs."&nbsp;&nbsp;&nbsp;&nbsp;";
269     $str.= "<img class='center' src='images/folder.png'
270               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
272     $this->set_List_Bottom_Info($str);
273   }
275   function Save()
276   {
277     MultiSelectWindow :: Save();  
278   }
280   function save_object()
281   {
282     /* Save automatic created POSTs like regex, checkboxes */
283     MultiSelectWindow :: save_object();   
284   }
286 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
287 ?>