0e3600bd4f8af8f3ec101d5bd65ad0827a1813a5
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");
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);
40 /* Disable buttonsm */
41 $this->EnableCloseButton(false);
42 $this->EnableSaveButton (false);
44 /* Dynamic action col, depending on snapshot icons */
45 $action_col_size = 60;
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" => " ", "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"), _("Ignore 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;
79 $deps= get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
80 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH);
82 /* Add base */
83 $deps[] = array("dn"=>$this->config->current['BASE']);
85 /* Load possible departments */
86 $ui= get_userinfo();
87 $tdeps= $ui->get_module_departments("gofonmacro");
89 $ids = $this->config->idepartments;
91 foreach($deps as $dep){
92 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
94 /* Keep first base dn in mind, we could need this
95 * info if no valid base was found
96 */
97 if(empty($first)) {
98 $first = $dep['dn'];
99 }
101 $value = $ids[$dep['dn']];
102 if ($this->selectedBase == $dep['dn']){
103 $options.= "<option selected='selected' value='".$dep['dn']."'>$value</option>";
104 } else {
105 $options.= "<option value='".$dep['dn']."'>$value</option>";
106 }
107 }
108 }
110 /* The currently used base is not visible with your acl setup.
111 * Set base to first useable base.
112 */
113 if(!$found){
114 $this->selectedBase = $first;
115 }
117 $acls = $ui->get_permissions($this->selectedBase,"gofonmacro/macro");
119 /* Add default header */
120 $listhead = MultiSelectWindow::get_default_header();
122 if(preg_match("/w/",$acls) && preg_match("/c/",$acls)){
123 $listhead .= $this->get_snapshot_header($this->selectedBase);
124 }
125 if(preg_match("/c/",$acls)){
126 $listhead .= " <input class='center' type='image' align='middle' src='images/list_new_macro.png'
127 title='"._("Create new phone macro")."' alt='"._("New")."' name='goFonMacro_new'> ";
128 $listhead .= " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
129 }
130 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
131 " <input class='center' type='image' src='images/list_submit.png' align='middle'
132 title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ";
134 /* Multiple options */
135 $listhead .= " <input class='center' type='image' align='middle' src='images/edittrash.png'
136 title='"._("Remove selected macros")."' alt='"._("Remove macros")."' name='remove_multiple_macros'> ";
138 $listhead .="</div>";
139 $this->SetListHeader($listhead);
140 }
142 function execute()
143 {
144 $this->ClearElementsList();
145 $this->GenHeader();
146 }
148 function setEntries($list)
149 {
151 $empty = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
152 $macroimg = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
153 $visible = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
154 $invisible = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
155 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
157 /* Dynamic action col, depending on snapshot icons */
158 $action_col_size = 60;
159 if($this->parent->snapshotEnabled()){
160 $action_col_size += 20;
161 }
163 $ui = get_userinfo();
165 foreach($list as $key => $val){
167 $sacl = $ui->get_permissions($val['dn'],"gofonmacro/macro");
169 $action = "";
170 if(!preg_match("/r/",$sacl)){
171 continue;
172 }
174 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
175 name='goFonMacro_edit_%KEY%' title='"._("Edit macro")."'>";
177 if(preg_match("/c/",$sacl) && preg_match("/w/",$sacl)){
178 $action.= $this->GetSnapShotActions($val['dn']);
179 }
181 if(preg_match("/d/",$sacl)){
182 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
183 name='goFonMacro_del_%KEY%' title='"._("Delete macro")."'>";
184 }
186 if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
187 $pic1 = $visible;
188 }else{
189 $pic1 = $invisible;
190 }
192 $display= $val["displayName"][0]." (".$val["cn"][0].")";
193 if(isset($val['description'][0])){
195 $desc = $val['description'][0];
196 if(strlen($desc) > 55){
197 $desc = substr($desc,0,52)."...";
198 }
200 $display .= " [".$desc."]";
201 }
203 /* Create each field */
204 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
205 "attach" => "style='width:20px;'");
206 $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
207 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
208 $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
209 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
211 $this->AddElement(array($field0,$field1,$field2,$field3,$field4));
212 }
213 }
215 function Save()
216 {
217 MultiSelectWindow :: Save();
218 }
220 function save_object()
221 {
222 /* Save automatic created POSTs like regex, checkboxes */
223 MultiSelectWindow :: save_object();
224 }
225 }
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>