diff --git a/plugins/gofon/macro/class_gofonMacroParameters.inc b/plugins/gofon/macro/class_gofonMacroParameters.inc
index d8e5d69929f9042559f9adbda91d2a6af3057590..3aaa420f37ded51e8c64c6fdb73fda37e5f196ac 100755 (executable)
<?php
+
class macroParameter extends plugin
{
/* CLI vars */
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");
}
}
+ /* 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 */
}
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);
}
/*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 */
$vars .="<tr>
<input name=\"number".$key."\" value='".$key."' type='hidden'>
<td><input name='var".$key."' type='hidden' value='".$para['var']."'>".$para['var']."</td>
- <td><input name='varname".$key."' value='".$para['name']."'></td>
+ <td><input size=\"45\" name='varname".$key."' value='".$para['name']."'></td>
<td>
<select name='vartype".$key."'>
<option name='vartype".$key."' value='string' ".$sel1.">"._("String")."</option>
<option name='vartype".$key."' value='bool' ".$sel3.">"._("Bool")."</option>
</select>
</td>
- <td><input name='default".$key."' value='".$para['default']."'></td>
- <td>";
- if($para['check']==true) {
- $vars.="</td><td></td>";
- }else{
- $vars.="<b>"._("Unused")."</b></td>";
- $vars.=" <td><input name='del".$key."' value='delete' type='submit'></td>";
+ <td><input size=\"45\" name='default".$key."' value='".$para['default']."'></td>
+ <td> ";
+ if($para['check']==false) {
+ $vars.="<input name='del".$key."' value='"._("Delete unused")."' type='submit'>";
}
- $vars.=" </tr>";
+ $vars.=" </td></tr>";
}
/* Checkboxes */
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){
return(array($str));
}
}
+
+
foreach($this->goFonMacroParameter as $key=>$val){
+ if((strstr($val['default'],"!"))||(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");
+ case 'bool' : $possible = array("","0","1");
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;
$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']);