<?php
if(!isset($msg)){
$nom = "Group";
$structure = array (array("name" => "Attribute", "name_input" => "Attribute", "align" => "left", "width" => "220px"),array("name" => "Op","name_input" => "Op","align" => "left", "width" => "20px"),array("name" => "Value", "name_input" => "Value", "align" => "left", "width" => "380px")
);
echo '<script type="text/javascript">';
// création du tableau JS ici
echo php2js($structure,'structure');
echo '</script>';
if ($buttonID=="group_save" and $_POST['gp_name']!='' and $_POST['gp_description']!='') {
//GENERAL
$opt->gp_name=$_POST['gp_name'];
$opt->gp_description=$_POST['gp_description'];
$opt->location_id=$_SESSION['locID'];
$opt->Attribute=$_POST['Attribute'];
$opt->Op=$_POST['Op'];
$opt->Value=$_POST['Value'];
$err=$oreon->database->saveGroup($opt,$structure);
if ($err=='')
echo "<p class=\"information\">Configuration have been saved</p>";
else
echo "<p class=\"error\">".$err."</p>";
unset($_POST['group_save']);
exit();
}
if ($buttonID=="group_save" and ($_POST['gp_name']=='' or $_POST['gp_description']=='')) {
echo "<p class=\"error\">You got to enter a group name and group description</p>";
}
if (isset($_POST['load_default']))
{
$lid=-1;
unset($_POST['load_default']);
}
else
$lid=$_SESSION['locID'];
echo "
<form action=\"phpmyprepaid.php\" id=\"selectform\" name=\"form_select\" method=\"post\" >
<br>
<big style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Group add</span></b></big><br>
<hr>";
echo "
<table>
<tr>
<td>Group name : </td>
<td><input name=\"gp_name\" id=\"gp_name\" value=\"".$opt['name']."\"></td>
</tr><tr>
<td>Group description : </td>
<td><input name=\"gp_description\" id=\"gp_description\" style=\"width: 400px;\" value=\"".$opt['description']."\"></td>
</tr></table><br>";
echo "<script type='text/javascript'>
function addLigneToLC(nom) {
var i=0;
var str='';
var test='';
test='tr_'+nom+0;
for( i=0; document.getElementById(test)!=null ;i++)
{
test='tr_Group'+i;
}
if (i>0)
var j=i-1;
else
var j=0;
str=document.getElementById('main_table_'+nom).innerHTML;
var attr=document.getElementById('attr').value;
var op=document.getElementById('op').value;
var val=document.getElementById('value').value;
if (val!='') {
var strfinal='<tbody id=\"tr_div_'+nom+j+'\"><tr id=\"tr_'+nom+j+'\" class=\"select_even\" onMouseOver=\'javascript:setEvenement(\"'+nom+'\",\"'+j+'\",\"over\",\"select_even\",\"td\");\' onMouseOut=\'javascript:setEvenement(\"'+nom+'\",\"'+j+'\",\"out\",\"select_even\",\"td\");\' onClick=\'javascript:setEvenement(\"'+nom+'\",\"'+j+'\",\"click\", \"select_even\",\"td\");\' ><td width=\"7\" ><input type=\"checkbox\" id=\"'+nom+j+'\" name=\"'+nom+'[]\" value=\"'+attr+'\" onClick=\'javascript:setEvenement(\"'+nom+'\",\"'+j+'\",\"click\",\"select_even\",\"ck\");\' />';
strfinal=strfinal+'<td width=\"'+structure[0]['width']+'\" align=\"'+structure[0]['align']+'\"><input name=\"'+structure[0]['name']+'[]\" style=\"width: 100%;\" value=\"'+attr+'\"></td><td width=\"'+structure[1]['width']+'\" align=\"'+structure[1]['align']+'\"><input name=\"'+structure[1]['name']+'[]\" style=\"width: 100%;\" value=\"'+op+'\"></td><td width=\"'+structure[2]['width']+'\" align=\"'+structure[2]['align']+'\"><input name=\"'+structure[2]['name']+'[]\" style=\"width: 100%;\" value=\"'+val+'\"></td></tr></tbody>';
document.getElementById('main_table_'+nom).innerHTML=str+strfinal;
document.getElementById('value').value='';
}
else
alert(\"You didnt put anything in field value.\");
}
function get_attribute()
{
var text=file('include/divers/get_attribute.php?default_cat='+document.getElementById('cat').value);
var reg=new RegExp(\"[ ;]+\", \"g\");
var tableau=text.split(reg);
var str='';
for (var i=0; i<tableau.length; i++) {
str=str+'<option value=\"'+tableau[i]+'\" >'+tableau[i]+'</option>';
}
document.getElementById('attr').innerHTML=str;
get_value();
}
function get_value()
{
var text=file('include/divers/get_value_group.php?default_attr='+document.getElementById('attr').value);
if (text!='' && text!=';') {
var reg=new RegExp(\"[ ;]+\", \"g\");
var tableau=text.split(reg);
var str='<select id=\"value\" style=\"width: 220px\" name=\"value\">';
for (var i=0; i<tableau.length; i++) {
str=str+'<option value=\"'+tableau[i]+'\" >'+tableau[i]+'</option>';
}
}
else
str='<input style=\"width: 220px;\" id=\"value\" name=\"value\" >';
document.getElementById('td_val').innerHTML=str;
}
function deleteFromListGroup(nom)
{
var i=0;
var j=0;
var str='';
var test='';
var val_td;
for (i=0; document.getElementById(nom + i)!=null; i++) {
val_td=document.getElementById('tr_div_'+nom+i).innerHTML;
if (document.getElementById(nom + i).checked==false)
{
var reg=new RegExp(nom+i, \"g\");
var res=val_td.replace(reg,nom+j);
var reg2=new RegExp(',\"'+i+'\",', \"g\");
var resf=res.replace(reg2,',\"'+j+'\",');
str=str+'<tbody id=\"tr_div_'+nom+j+'\">'+resf+'<tbody>';
j=j+1;
}
}
document.getElementById('main_table_'+nom).innerHTML=str;
var reg2=new RegExp('<tbody></tbody>', \"g\");
var resf=document.getElementById('main_table_'+nom).innerHTML.replace(reg2,'');
document.getElementById('main_table_'+nom).innerHTML=resf;
}
</script>";
echo "<table><tr><td colspan=\"5\" rowspan=\"1\" >";
echo '<div align="left" >';
echo checkedSelect($nom, $structure, $contenu, $_POST[$nom],"");
echo '<br />';
echo '</div></td><td>';
print "<a href=\"JavaScript:deleteFromListGroup('$nom')\"><img src=\"images/delete.png\" title=\"Del attribute\"></a>";
echo '</td></tr></table><table><tr>';
echo '<hr>';
echo '<td style="text-align: left; width: 80px;">';
echo 'Category';
echo '</td><td>';
echo 'Attribute';
echo '</td><td>';
echo 'Op';
echo '</td><td>';
echo 'Value';
echo '</td><td></tr><tr>';
echo '<td style="text-align: left; width: 80px;">';
$result = $_SESSION["oreon"]->database->database->query("SELECT category FROM radius_attribute GROUP BY category");
echo '<select name="cat" id="cat" style=\"width: 80px;\" onChange=\'get_attribute()\'>';
$default_cat="Divers";
while ($row = $oreon->database->database->fetch_object($result)) {
if ($row->category==$default_cat)
echo "<option selected=\"selected\" value=\"".$row->category."\">".$row->category."</option>";
else
echo "<option value=\"".$row->category."\">".$row->category."</option>";
}
echo '</select></td>';
echo '<td style="text-align: left; width: 140px;">';
$result = $_SESSION["oreon"]->database->database->query("SELECT attribute,default_value,enum_value FROM radius_attribute WHERE category='$default_cat'");
echo '<select id="attr" name="cat" style=\"width: 120px;\" onChange=\'get_value()\'>';
while ($row = $oreon->database->database->fetch_object($result)) {
if ($row->category==$default_cat)
echo "<option selected=\"selected\" value=\"".$row->attribute."\">".$row->attribute."</option>";
else
echo "<option value=\"".$row->attribute."\">".$row->attribute."</option>";
}
echo '</select></td>';
echo '<td style="text-align: left; width: 20px;">';
echo '<select id="op" name="op">';
$tab2=split(';',$operator);
foreach ($tab2 as $val)
if ($tab['operator']==$val)
echo "<option selected=\"selected\" value=\"$val\">$val</option>";
else
echo "<option value=\"$val\">$val</option>";
echo '</select></td>';
echo '<td id="td_val" style="text-align: left; width: 220px;">
<input style="width: 220px;" id="value" name="value" ></td><td style="text-align: left;">';
print "<a href=\"JavaScript:addLigneToLC('".$nom."')\"><img src=\"images/insert.png\" title=\"Add Ligne\"></a>";
echo "<script type='text/javascript'>
get_value();
</script>";
echo "</td></tr></table>
<hr>";
echo "<table><tr>";
echo "<input type=\"hidden\" name=\"buttonID\" value=\"group_save\">
<input name=\"savegroup\" type=\"submit\" class=\"smallButton\" value=\"Save Configuration\" >
<tr>
</form>
</table>
";
}
else echo $msg;