2
//! This class handles the goFonMacroParameter
3
/*! In this class all parameters from goFonMacroContent \n
4
and all (if given) already defined parameters are managed \n
6
Parameters will be saved to openldap like this :\n
7
goFonMacroParameter: ID!NAME:!TYPE(string:combo:bool)!DEFAULT_VALUE\n
8
In Case of type=combo the DEFAULT_VALUE specifies the entries in the listbox, like this\n
9
"first:second:third:last" \n
11
class macroParameter extends plugin
18
/*! This array contains all Parameter defined for the macro*/
19
var $goFonMacroParameter =array();
21
/*! This are the available types for a macro */
22
var $type_shortcut= array("string" => array("selected", "", ""),
23
"combo" => array("", "selected", ""),
24
"bool" => array("", "", "selected"));
26
/*! attribute list for save action */
27
var $attributes= array("base","goFonMacroParameter");
29
/*! Objectclasses needed by the class*/
30
var $objectclasses= array("top", "goFonMacro");
32
//! The konstructor of macroParameter
33
/*! The konstructor of macroParameter...
34
- reads goFonMacroParameter and parses them to an array
35
- Set attributes from openldap (edit)
36
- Set attributes from default (new)
38
function macroParameter ($config, $dn= NULL, $parent= NULL)
40
plugin::plugin ($config, $dn, $parent);
42
$tmp = array(); // temporary Var
43
$tmp2 = array(); // temporary Var ...
45
$ldap= $config->get_ldap_link();
49
/* This is always an account */
50
$this->is_account= TRUE;
52
/* Edit or new one ?*/
53
if ($this->dn == "new"){
55
$this->base= dn2base($ui->dn);
57
$this->base= dn2base($this->dn);
60
/* initialising macro parameter */
61
if(isset($this->attrs['goFonMacroParameter']) &&
62
isset($this->attrs['goFonMacroParameter']['count'])){
63
unset($this->attrs['goFonMacroParameter']['count']);
66
/* Set Parameters, or a new array if ther are no parameters */
67
if(isset($this->attrs['goFonMacroParameter'])){
68
$this->goFonMacroParameter = $this->attrs['goFonMacroParameter'];
70
$this->goFonMacroParameter =array();
73
/* Create an array for parameters if not given yet */
74
if(!is_array($this->goFonMacroParameter)){
75
$tmp3 = $this->goFonMacroParameter;
76
$this->goFonMacroParameter =array();
78
$this->goFonMacroParameter[] = $tmp3;
82
/* Load parametersettings*/
83
foreach($this->goFonMacroParameter as $para){
84
$tmp = split("!",$para);
86
$tmp2[$num]['name'] = base64_decode($tmp[1]);
87
$tmp2[$num]['type'] = $tmp[2];
88
$tmp2[$num]['default'] = $tmp[3];
89
$tmp2[$num]['var'] = "var".$num;
93
/* Assign this array */
94
$this->goFonMacroParameter = $tmp2;
96
$this->para_count = count ($tmp2);
99
$acl= get_permissions ($ui->dn, $ui->subtreeACL);
100
$this->acl= get_module_permission($acl, "goFonMacro", $ui->dn);
103
//! Perform Parameter check
105
Compares the given parameters (goFonMacroParameters) with the parameters defined in goFonContent\n
106
-> Decide which attrs are new and which are unused\n
107
-> Sort result array (containing both parameters 'goFonMacroParameters/goFonContent' and new / unused info)\n
108
\param $content The given goFonContent for this macro\n
109
\param $goFonMacroParameter Array with the already given parameters \n
111
function check_paras($content,$goFonMacroParameter)
113
/* Check contents for parameters */
114
preg_match_all("/[$]\{ARG[0-9]*\}/",$content,$res,PREG_OFFSET_CAPTURE);
118
/* Detect parameters with positions */
119
foreach($res[0] as $val){
120
$num = preg_replace("/[^0-9]/","",$val[0]);
121
$new[$num]['val'] = $val[0];
122
$new[$num]['num'] = $num;
125
/* Compare content parameter and macro parameter */
126
foreach($goFonMacroParameter as $gokey => $goval){
127
foreach($new as $nkey => $nval){
128
if($gokey == $nval['num']){
129
/* sign this as OK */
130
$goFonMacroParameter[$gokey]['check']= true;
135
/* Now check if there is new parameter in the content, which is not assigned yet */
136
foreach($new as $key => $val){
137
/* Assign std values */
138
$goFonMacroParameter[$key]['var']="var".$key;
139
$goFonMacroParameter[$key]['check']= true;
141
/* If this is a new Parameter, name it ${ARG#} by default*/
142
if((!isset($goFonMacroParameter[$key]['name']))||(empty($goFonMacroParameter[$key]['name']))){
143
$goFonMacroParameter[$key]['name']="\${ARG".$key."}";
147
foreach($goFonMacroParameter as $key => $val){
148
/* All attributes with check == false, are unneeded so mark them with ['check']= false */
149
if(!isset($goFonMacroParameter[$key]['check'])){
150
$goFonMacroParameter[$key]['check']= false;
152
/* Ah no default given assign ="" to prevent unsigned index */
153
if(!isset($goFonMacroParameter[$key]['default'])){
154
$goFonMacroParameter[$key]['default'] = "";
158
/* Sort output for better reading */
159
asort($goFonMacroParameter);
160
return($goFonMacroParameter);
164
//! Execute this Plugin
166
Perform Parameter check \n
167
Draw paramter table\n
172
/* Call parent execute */
180
$content = $_SESSION['macroManagment']->macrotabs->by_object['macro']->goFonMacroContent;
182
if(strstr($content,"ARG")){
183
$vorpos = strpos($content,"ARG");
184
$rest = substr($content,$vorpos, strlen($content));
187
/* Do we represent a valid group? */
188
if (!$this->is_account && $this->parent == NULL){
189
$display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
190
_("This 'dn' is no phone macro.")."</b>";
194
/* Fill templating stuff */
195
$smarty= get_smarty();
197
/* Assign all vars to Smarty */
198
foreach($this->attributes as $ar){
199
$smarty->assign($ar, $this->$ar);
202
/* Add an empty Parameter */
203
if(isset($_POST['addvar'])){
204
if(!is_array($this->goFonMacroParameter)){
205
$vars = $this->goFonMacroParameter;
206
$this->goFonMacroParameter = array();
207
$this->goFonMacroParameter[]= $vars;
209
$number= count($this->goFonMacroParameter);
211
$this->goFonMacroParameter[]=array("var"=>"var","name"=>"new","type"=>"string","default"=>"test");
214
/*generate Table which shows als parameters */
215
$FonParas = $this->check_paras($content,$this->goFonMacroParameter);
217
/* Sort by Parameterid, and keep keys */
220
foreach($FonParas as $key=>$para) {
222
/* Select correct item of combobox */
223
if(isset($para['type'])){
224
list($sel1, $sel2, $sel3)= $this->type_shortcut[$para['type']];
226
list($sel1, $sel2, $sel3)= array("", "", "");
229
/* Assemble output table */
232
<input name=\"number".$key."\" value='".$key."' type='hidden'>
233
<input name='var".$key."' type='hidden' value='".$para['var']."'>ARG".$key."
235
<td><input size=\"45\" name='varname".$key."' value='".$para['name']."'></td>
237
<select name='vartype".$key."'>
238
<option value='string' ".$sel1.">"._("String")." </option>
239
<option value='combo' ".$sel2.">"._("Combobox")." </option>
240
<option value='bool' ".$sel3.">"._("Bool")." </option>
243
<td><input size=\"45\" name='default".$key."' value='".$para['default']."'></td>
245
if($para['check']==false) {
246
$vars.="<input name='del".$key."' value='"._("Delete unused")."' type='submit'>";
249
$vars.=" </td></tr>";
253
$smarty->assign("base_select", $this->base);
254
$smarty->assign("vars", $vars);
257
return($smarty->fetch (get_template_path('parameter.tpl', TRUE)));
262
Unused here because goFonMacro will remove this Macro\n
264
function remove_from_parent()
270
Save POST data to object \n
271
This gives us the possibility to leave a tab, without losing our typed informations\n
273
Read the POST fields for the parameters and saves their info the the class\n
275
function save_object()
277
if (isset($_POST['phoneparameters'])){
278
plugin::save_object();
280
/* read out post data, and assign it to the parameters */
282
foreach($_POST as $name=>$value){
284
/* Test if there is a variable begining with "del" */
285
if(preg_match("/del/",$name)){
287
/* Extract entry id to delete */
288
$nr = str_replace("del","",$name) ;
291
unset($this->goFonMacroParameter[$nr]);
293
}elseif(preg_match("/number/",$name)){
296
$key = $_POST[$name];
298
$this->goFonMacroParameter[$key]['var'] = $_POST["var".$key];
299
$this->goFonMacroParameter[$key]['name'] = $_POST["varname".$key];
300
$this->goFonMacroParameter[$key]['type'] = $_POST["vartype".$key];
301
$this->goFonMacroParameter[$key]['default']= $_POST["default".$key];
308
//! Checks given values
311
If a user enters an invalid value, then this function will output an error msg\n
312
(In better words :prepare the errormessages that will be put out )\n
316
/* Call common method to give check the hook */
317
$message= plugin::check();
319
foreach($this->attributes as $attr){
320
if(chkacl($this->acl,"edit")){
321
$str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro."),$attr) ;
327
foreach($this->goFonMacroParameter as $key=>$val){
328
if((strstr($val['default'],"!"))||(strstr($val['default'],"#"))) {
329
$message[] = sprintf(_("The parameter %s contains invalid char. '!,#' is used as delimiter"),$val['name']);
331
switch($val['type']){
332
case 'bool' : $possible = array("","0","1");
333
if(!in_array($val['default'],$possible)) {
334
$message[] = sprintf(_("The parameter %s has incorrect value for type bool."),$val['name']);
345
//! Save changes to openldap
348
This function saves given attributes to the ldap
356
$this->attrs['goFonMacroParameter']=array();
358
foreach($this->goFonMacroParameter as $key=>$fonpara){
359
$this->attrs['goFonMacroParameter'][]=$key."!".base64_encode($fonpara['name'])."!".$fonpara['type']."!".$fonpara['default'];
362
if($this->para_count != count($this->attrs['goFonMacroParameter'])){
363
print_red(_("Parameter count of the macro changed, you must update each user which are using this macro '%s'."),$this->dn);
366
unset($this->attrs['base']);
368
/* Write back to ldap */
369
$ldap= $this->config->get_ldap_link();
370
$ldap->cat($this->dn, array('dn'));
374
$ldap->cd($this->dn);
376
$ldap->modify ($this->attrs);
378
$this->handle_post_events("modify");
380
if(count($this->attrs['goFonMacroParameter']==0)){
381
unset($this->attrs['goFonMacroParameter']);
383
$ldap->cd($this->dn);
384
$ldap->create_missing_trees( $this->dn);
385
$ldap->cd($this->dn);
386
$ldap->add($this->attrs);
387
$this->handle_post_events("add");
389
show_ldap_error($ldap->get_error(), _("Saving phone macro parameters failed"));
393
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: