From de616e64ac2eb3e6d7e653c821dfb751df1cdf14 Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 23 Jun 2005 07:43:11 +0000 Subject: [PATCH] added some comments and some changes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@809 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/gofon/macro/class_gofonMacro.inc | 6 +- .../macro/class_gofonMacroParameters.inc | 48 ++++++++++----- .../gofon/phoneaccount/class_phoneAccount.inc | 60 +++++++++---------- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/plugins/gofon/macro/class_gofonMacro.inc b/plugins/gofon/macro/class_gofonMacro.inc index 373a4838e..81f676686 100755 --- a/plugins/gofon/macro/class_gofonMacro.inc +++ b/plugins/gofon/macro/class_gofonMacro.inc @@ -117,7 +117,11 @@ class macro extends plugin function check() { $message = array(); - + + if(empty($this->displayName)){ + $message[] = _("You must specify the 'Display Name' in order to save this macro"); + } + foreach($this->attributes as $attr){ if(chkacl($this->acl,$attr)){ $str = sprintf( _("Insufficient permissions, can't change attribute '%s' in goFonMacro"),$attr) ; diff --git a/plugins/gofon/macro/class_gofonMacroParameters.inc b/plugins/gofon/macro/class_gofonMacroParameters.inc index 9eaaab934..74b0a6b72 100755 --- a/plugins/gofon/macro/class_gofonMacroParameters.inc +++ b/plugins/gofon/macro/class_gofonMacroParameters.inc @@ -11,8 +11,8 @@ class macroParameter extends plugin var $base= ""; var $goFonMacroParameter =array(); var $type_shortcut= array("string" => array("selected", "", ""), - "combo" => array("", "selected", ""), - "bool" => array("", "", "selected")); + "combo" => array("", "selected", ""), + "bool" => array("", "", "selected")); /* attribute list for save action */ var $attributes= array("base","goFonMacroParameter"); @@ -60,13 +60,14 @@ class macroParameter extends plugin } } + /* Load parametersettings*/ foreach($this->goFonMacroParameter as $para){ $tmp = split("!",$para); - $num = preg_replace("/[^0-9]/","",$tmp[1]); - $tmp2[$num]['var'] = $tmp[1]; - $tmp2[$num]['name'] = $tmp[2]; - $tmp2[$num]['type'] = $tmp[3]; - $tmp2[$num]['default'] = $tmp[4]; + $num = $tmp[0]; + $tmp2[$num]['name'] = $tmp[1]; + $tmp2[$num]['type'] = $tmp[2]; + $tmp2[$num]['default'] = $tmp[3]; + $tmp2[$num]['var'] = "var".$num; } /* Assign this array */ @@ -74,41 +75,53 @@ class macroParameter extends plugin } function check_paras($content,$goFonMacroParameter) - { + { + /* Check contents for parameters */ preg_match_all("/[$]\{ARG[0-9]*\}/",$content,$res,PREG_OFFSET_CAPTURE); - $anz = count($res[0]); $new = array(); + /* Detect parameters with positions */ foreach($res[0] as $val){ $num = preg_replace("/[^0-9]/","",$val[0]); $new[$num]['val'] = $val[0]; $new[$num]['num'] = $num; } + /* Compare content parameter and macro parameter */ foreach($goFonMacroParameter as $gokey => $goval){ foreach($new as $nkey => $nval){ if($gokey == $nval['num']){ + /* sign this as OK */ $goFonMacroParameter[$gokey]['check']= true; } } } + + /* Now check if there is new parameter in the content, which is not assigned yet */ foreach($new as $key => $val){ - $goFonMacroParameter[$key]['var']="\${ARG".$key."}"; + /* Assign std values */ + $goFonMacroParameter[$key]['var']="var".$key; $goFonMacroParameter[$key]['check']= true; + + /* If this is a new Parameter, name it ${ARG#} by default*/ if((!isset($goFonMacroParameter[$key]['name']))||(empty($goFonMacroParameter[$key]['name']))){ $goFonMacroParameter[$key]['name']="\${ARG".$key."}"; } } foreach($goFonMacroParameter as $key => $val){ + /* All attributes with check == false, are unneeded so mark them with ['check']= false */ if(!isset($goFonMacroParameter[$key]['check'])){ $goFonMacroParameter[$key]['check']= false; } + /* Ah no default given assign ="" to prevent unsigned index */ if(!isset($goFonMacroParameter[$key]['default'])){ $goFonMacroParameter[$key]['default'] = ""; } } + + /* Sort output for better reading */ asort($goFonMacroParameter); return($goFonMacroParameter); @@ -210,7 +223,7 @@ class macroParameter extends plugin if (isset($_POST['phoneparameters'])){ plugin::save_object(); } - /* read out post data, and assign it to the parameters */ + /* read out post data, and assign it to the parameters */ /* And or delete */ foreach($_POST as $name=>$value){ @@ -249,18 +262,21 @@ class macroParameter extends plugin return(array($str)); } } + + foreach($this->goFonMacroParameter as $key=>$val){ + if(strstr($val['default'],"!")) { + $message[] = sprintf(_("The parameter %s contains invalid char. '!' is used as delimiter"),$val['name']); + } switch($val['type']){ case 'bool' : $possible = array("","0","1","true","false"); if(!in_array($val['default'],$possible)) { $message[] = sprintf(_("The parameter %s has incorrect value for type bool."),$val['name']); };break; case 'string' : - case 'combo' : if(strstr($val['default'],"!")){ - $message[] = sprintf(_("The parameter %s contains invalid char. '!' is used as delimiter"),$val['name']); - };break; + case 'combo' : default : ; - + } } return $message; @@ -277,7 +293,7 @@ class macroParameter extends plugin $this->attrs['goFonMacroParameter']=array(); foreach($this->goFonMacroParameter as $key=>$fonpara){ - $this->attrs['goFonMacroParameter'][]=$key."!".$fonpara['var']."!".$fonpara['name']."!".$fonpara['type']."!".$fonpara['default']; + $this->attrs['goFonMacroParameter'][]=$key."!".$fonpara['name']."!".$fonpara['type']."!".$fonpara['default']; } unset($this->attrs['base']); diff --git a/plugins/gofon/phoneaccount/class_phoneAccount.inc b/plugins/gofon/phoneaccount/class_phoneAccount.inc index a72200c63..2659d43e8 100644 --- a/plugins/gofon/phoneaccount/class_phoneAccount.inc +++ b/plugins/gofon/phoneaccount/class_phoneAccount.inc @@ -24,7 +24,7 @@ class phoneAccount extends plugin var $macros = array(); // List of macros for smarty select box var $macroarray = array(); // All needed macro informations var $macrostillavailable = false; - + /* CLI vars */ var $cli_summary = "Manage users phone account"; var $cli_description = "Some longer text\nfor help"; @@ -32,7 +32,7 @@ class phoneAccount extends plugin /* attribute list for save action */ var $attributes = array("goFonDeliveryMode", "goFonForwarding", "goFonFormat", - "goFonHardware", "goFonPIN", "telephoneNumber", "goFonMacro","macro"); + "goFonHardware", "goFonPIN", "telephoneNumber", "goFonMacro","macro"); var $objectclasses= array("goFonAccount"); function phoneAccount ($config, $dn= NULL) @@ -86,7 +86,7 @@ class phoneAccount extends plugin $description= ""; } $this->hardware_list[$cn]= "$cn$description"; - + } /* Prepare templating */ @@ -103,23 +103,23 @@ class phoneAccount extends plugin /* Fetch all Macros*/ while ($attrs= $ldap->fetch()){ - + /* Only visisble */ if((isset($attrs['goFonMacroVisible'][0]))&&($attrs['goFonMacroVisible'][0] ==1)){ - + /* unset Count, we don't need that here */ unset($attrs['displayName']['count']); - + /* fill Selectfield variable with Macros */ if(isset($attrs['displayName'][0])){ - $this->macros[$attrs['dn']] = $attrs['displayName'][0]; + $this->macros[$attrs['dn']] = $attrs['displayName'][0]." (".$attrs['cn'][0].")"; }else{ $this->macros[$attrs['dn']] = _("undefined"); } /* Parse macro data, unset count for parameterarrays */ unset($attrs['goFonMacroParameter']['count']); - + /* Go through available parameters and parse all attributes, like parametername, type, default ...*/ if((isset($attrs['goFonMacroParameter']))&&(is_array($attrs['goFonMacroParameter']))){ @@ -127,7 +127,7 @@ class phoneAccount extends plugin /* Split Data in readable values, by delimiter ! */ $data = split("!",$attrs['goFonMacroParameter'][$pkey]); - + /* Set all attrs */ $id = $data[0]; $this->macroarray[$attrs['dn']][$id]['var'] ="var".$id; @@ -136,19 +136,19 @@ class phoneAccount extends plugin $this->macroarray[$attrs['dn']][$id]['name'] =$data[1]; $this->macroarray[$attrs['dn']][$id]['type'] =$data[2]; $this->macroarray[$attrs['dn']][$id]['default']=$data[3]; - }//foreach - }//is_array - }//visible = 1 - }//while + }//foreach + }//is_array + }//visible = 1 + }//while /* Go through already saved values, for a parameter */ $tmp = split("!",$this->goFonMacro); /* it is possible that nothing has been saved yet */ if(is_array($tmp)){ - + /* First value is the macroname */ $this->macro = $tmp[0]; - + /* Macroname saved, delete that index */ unset($tmp[0]); @@ -161,18 +161,18 @@ class phoneAccount extends plugin /* for each parametervalues ( parameterID#value like 25#twentyfive) */ foreach($tmp as $var){ - + /* Split this, so we have $varar[0] = parameterID $varar[1] = SelectedValue */ $varar = split("#",$var); - + /* Only insert if the parameter still exists */ if(isset($this->macroarray[$this->macro][$varar[0]])){ - + /* Assign value */ $this->macroarray[$this->macro][$varar[0]]['choosen']=$varar[1]; - } } } + } /* Eventually colorize phones */ $ldap->cd($this->config->current['BASE']); @@ -214,12 +214,12 @@ class phoneAccount extends plugin /* Assing macroselectbox values */ $smarty->assign("macros",$this->macros); $smarty->assign("macro", $this->macro); - + /* Create parameter table, skip if no parameters given */ if(!isset($this->macroarray[$this->macro])){ $macrotab=""; }else{ - + $macrotab =""; /* for every single parameter-> display textfile,combo, or true false switch*/ foreach($this->macroarray[$this->macro] as $paras){ @@ -244,10 +244,10 @@ class phoneAccount extends plugin } $str.=""; } - + /* Display switch for true false*/ if($type == "bool"){ - + $str=""; } - + /* display simple textfield */ if($type=="string"){ $str=""; } - + /* create table entry*/ $macrotab.= "\n"; - + } $macrotab.="
".$name."".$str."
"; }//is_array() @@ -341,7 +341,7 @@ class phoneAccount extends plugin $smarty->assign ("phoneNumbers", $this->phoneNumbers); } $hl= "