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