X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fgofon%2Fmacro%2Fclass_gofonMacroParameters.inc;h=19085a904b758a40a356499e508cff574633ff9d;hb=3082209baacc737659b444a6de4ed6ef5588faaf;hp=9eaaab93460a3d7f1744ba1e445079c8775cbe09;hpb=44d11c625d5f7c76e6cb83822e64aab9d4d63c15;p=gosa.git diff --git a/plugins/gofon/macro/class_gofonMacroParameters.inc b/plugins/gofon/macro/class_gofonMacroParameters.inc index 9eaaab934..19085a904 100755 --- a/plugins/gofon/macro/class_gofonMacroParameters.inc +++ b/plugins/gofon/macro/class_gofonMacroParameters.inc @@ -1,24 +1,47 @@ "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* application attributes */ + /* Parameter Count*/ + var $para_count = 0 ; + /*! macro base */ var $base= ""; + + /*! This array contains all Parameter defined for the macro*/ var $goFonMacroParameter =array(); + + /*! This are the available types for a macro */ var $type_shortcut= array("string" => array("selected", "", ""), - "combo" => array("", "selected", ""), - "bool" => array("", "", "selected")); + "combo" => array("", "selected", ""), + "bool" => array("", "", "selected")); - /* attribute list for save action */ + /*! attribute list for save action */ var $attributes= array("base","goFonMacroParameter"); + + /*! Objectclasses needed by the class*/ var $objectclasses= array("top", "goFonMacro"); - + //! The konstructor of macroParameter + /*! The konstructor of macroParameter... + - reads goFonMacroParameter and parses them to an array + - Set attributes from openldap (edit) + - Set attributes from default (new) + */ function macroParameter ($config, $dn= NULL) { plugin::plugin ($config, $dn); @@ -42,7 +65,10 @@ class macroParameter extends plugin } /* initialising macro parameter */ - unset($this->attrs['goFonMacroParameter']['count']); + if(isset($this->attrs['goFonMacroParameter']) && + isset($this->attrs['goFonMacroParameter']['count'])){ + unset($this->attrs['goFonMacroParameter']['count']); + } /* Set Parameters, or a new array if ther are no parameters */ if(isset($this->attrs['goFonMacroParameter'])){ @@ -60,68 +86,100 @@ 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'] = base64_decode($tmp[1]); + $tmp2[$num]['type'] = $tmp[2]; + $tmp2[$num]['default'] = $tmp[3]; + $tmp2[$num]['var'] = "var".$num; } + /* Assign this array */ $this->goFonMacroParameter = $tmp2; + + $this->para_count = count ($tmp2); + } + //! Perform Parameter check + /*! + Compares the given parameters (goFonMacroParameters) with the parameters defined in goFonContent\n + -> Decide which attrs are new and which are unused\n + -> Sort result array (containing both parameters 'goFonMacroParameters/goFonContent' and new / unused info)\n + \param $content The given goFonContent for this macro\n + \param $goFonMacroParameter Array with the already given parameters \n + */ 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); } - + //! Execute this Plugin + /*! + Perform Parameter check \n + Draw paramter table\n + Show tpl \n + */ function execute() { + /* Call parent execute */ + plugin::execute(); /* Variables */ $vars = ""; $tmp = array(); $number = 0; - + $content = $_SESSION['macroManagment']->macrotabs->by_object['macro']->goFonMacroContent; if(strstr($content,"ARG")){ @@ -157,9 +215,11 @@ class macroParameter extends plugin } /*generate Table which shows als parameters */ - $FonParas = $this->check_paras($content,$this->goFonMacroParameter); + /* Sort by Parameterid, and keep keys */ + ksort($FonParas); + foreach($FonParas as $key=>$para) { /* Select correct item of combobox */ @@ -171,15 +231,17 @@ class macroParameter extends plugin /* Assemble output table */ $vars .="