diff --git a/plugins/gofon/macro/class_gofonMacroParameters.inc b/plugins/gofon/macro/class_gofonMacroParameters.inc
index 65f6614ca3034af6bc8a65b580d641f665669056..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]);
+ $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){
+ /* 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);
}
$number= count($this->goFonMacroParameter);
$number++;
- $this->goFonMacroParameter[]=array("name"=>"new","type"=>"string","default"=>"test");
+ $this->goFonMacroParameter[]=array("var"=>"var","name"=>"new","type"=>"string","default"=>"test");
}
/*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 */
/* Assemble output table */
$vars .="<tr>
- <td><input name=\"number".$key."\" value='".$key."' type='hidden'> </td>
- <td><input name='varname".$key."' type='hidden' value='".$para['name']."'>".$para['name']."</td>
+ <input name=\"number".$key."\" value='".$key."' type='hidden'>
+ <td><input name='var".$key."' type='hidden' value='".$para['var']."'>".$para['var']."</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.=_("Ok");
- $vars.=" <td></td>";
- }else{
- $vars.="<b>"._("Unused")."</b>";
- $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){
/* Set Post vars */
$key = $_POST[$name];
+
+ $this->goFonMacroParameter[$key]['var'] = $_POST["var".$key];
$this->goFonMacroParameter[$key]['name'] = $_POST["varname".$key];
$this->goFonMacroParameter[$key]['type'] = $_POST["vartype".$key];
$this->goFonMacroParameter[$key]['default']= $_POST["default".$key];
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");
+ if(!in_array($val['default'],$possible)) {
+ $message[] = sprintf(_("The parameter %s has incorrect value for type bool."),$val['name']);
+ };break;
+ case 'string' :
+ case 'combo' :
+ default : ;
+
+ }
+ }
return $message;
}