array("selected", "", ""),
"combo" => array("", "selected", ""),
"bool" => array("", "", "selected"));
/*! attribute list for save action */
var $attributes= array("base","goFonMacroParameter");
/*! Objectclasses needed by the class*/
var $objectclasses= array("top", "goFonMacro");
var $ui;
//! 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, $parent= NULL)
{
plugin::plugin ($config, $dn, $parent);
$tmp = array(); // temporary Var
$tmp2 = array(); // temporary Var ...
$tmp3 = "";
$ldap= $config->get_ldap_link();
$this->dn = $dn;
/* This is always an account */
$this->is_account= TRUE;
/* Edit or new one ?*/
if ($this->dn == "new"){
$ui= get_userinfo();
$this->base= dn2base($ui->dn);
} else {
$this->base= dn2base($this->dn);
}
/* initialising macro parameter */
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'])){
$this->goFonMacroParameter = $this->attrs['goFonMacroParameter'];
}else{
$this->goFonMacroParameter =array();
}
/* Create an array for parameters if not given yet */
if(!is_array($this->goFonMacroParameter)){
$tmp3 = $this->goFonMacroParameter;
$this->goFonMacroParameter =array();
if(!empty($tmp3)) {
$this->goFonMacroParameter[] = $tmp3;
}
}
/* Load parametersettings*/
foreach($this->goFonMacroParameter as $para){
$tmp = split("!",$para);
$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);
$this->ui= get_userinfo();
}
//! 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);
$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);
}
//! 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;
/* Get acls for this tab,
there is only one attribute to write,
so we use the acls from gofon/marco */
$ACLs = $this->ui->get_permissions($this->dn,"gofonmacro/macro","goFonMarcoContent");
/* get current content */
$macroManagment = session::get('macroManagment') ;
$content = $macroManagment->macrotabs->by_object['macro']->goFonMacroContent;
if(strstr($content,"ARG")){
$vorpos = strpos($content,"ARG");
$rest = substr($content,$vorpos, strlen($content));
}
/* Do we represent a valid group? */
if (!$this->is_account && $this->parent === NULL){
$display= " ".
msgPool::noValidExtension(_("Phone macro"))."";
return ($display);
}
/* Fill templating stuff */
$smarty= get_smarty();
/* Add an empty Parameter */
if(isset($_POST['addvar']) && preg_match("/w/",$ACLs)){
if(!is_array($this->goFonMacroParameter)){
$vars = $this->goFonMacroParameter;
$this->goFonMacroParameter = array();
$this->goFonMacroParameter[]= $vars;
}
$number= count($this->goFonMacroParameter);
$number++;
$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);
if(!preg_match("/r/",$ACLs)){
$smarty->assign("readable",false);
}else{
$smarty->assign("readable",true);
foreach($FonParas as $key=>$para) {
/* Select correct item of combobox */
if(isset($para['type'])){
list($sel1, $sel2, $sel3)= $this->type_shortcut[$para['type']];
}else{
list($sel1, $sel2, $sel3)= array("", "", "");
}
/* Disable all input fields if we are not allowed to change the parameters */
$disabled = "";
if(!preg_match("/w/",$ACLs)){
$key = "";
$disabled = " disabled ";
}
/* Assemble output table */
$vars .="