Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/group/UserGroup.php
<?php

if(!isset($msg)){
	
	
	
$namedest = "Destination";
	
	$structure = array (array("name" => "User Name", "align" => "left", "name_input" => "UserName", "width" => "180px"),array("name" => "Billing plan", "name_input" => "BillingPlan","align" => "left", "width" => "140px"),array("name" => "Type","name_input" => "Type", "align" => "left", "width" => "180px")
	);
	
$structure2 = array (array("name" => "User Name", "align" => "left", "name_input" => "UserNameSrc", "width" => "180px"),array("name" => "Billing plan", "name_input" => "BillingPlanSrc","align" => "left", "width" => "140px"),array("name" => "Type","name_input" => "TypeSrc", "align" => "left", "width" => "180px")
	);
	echo '<script type="text/javascript">';

	// création du tableau JS ici
	echo php2js($structure,'structure');
	echo php2js($structure2,'structure2');
	echo '</script>';
	
	if ($buttonID=="user_group_save") {
		//GENERAL
		
		$opt->location_id=$_SESSION['locID'];
		$opt->username=$_POST['UserName'];
		$opt->gp_id=$_POST['gp_id'];
		$opt->gp_name=$_POST['gp_name'];
                $err=$oreon->database->saveUserGroup($opt,$structure);

		if ($err=='')
		echo "<p class=\"information\">Configuration have been saved</p>";
		else
		echo "<p class=\"error\">".$err."</p>";

		unset($_POST['user_group_save']);
		exit();
	}
       
$lid=$_SESSION['locID'];	
$gp_id=$_POST['gp_id'];	
$gp_name=$_POST['gp_name'];	
	
	echo "
		<form action=\"phpmyprepaid.php\" id=\"selectform\" name=\"form_select\" method=\"post\" >
	<br
	<big  style=\"font-family: Aircut\"><span style=\"font-weight: bold;\"><b>Users for group ".$gp_name."</span></b></big><br>
	<hr>";
	
	
	echo "<script type='text/javascript'>
		
function addLigneToDestination(nom,nu,bpu,tu,rep) {
var i=0;
var str='';
var test='';
test='tr_'+nom+0;
if (rep==false) 
for( i=0; document.getElementById(test)!=null ;i++)
{
	test='tr_'+nom+i;
}

if (i>0)
	var j=i-1;
else
	var j=0;

str=document.getElementById('main_table_'+nom).innerHTML;
	 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=\"Check'+nom+'[]\" value=\"'+nu+'\" onClick=\'javascript:setEvenement(\"'+nom+'\",\"'+j+'\",\"click\",\"select_even\",\"ck\");\'  />';
 
 
	 strfinal=strfinal+'<td width=\"'+structure2[0]['width']+'\" align=\"'+structure2[0]['align']+'\"><input name=\"'+structure2[0]['name_input']+'[]\" style=\"width: 100%;\"  disabled=\"disabled\" value=\"'+nu+'\"></td><td width=\"'+structure2[1]['width']+'\" align=\"'+structure2[1]['align']+'\"><input name=\"'+structure2[1]['name_input']+'[]\" style=\"width: 100%;\" disabled=\"disabled\" value=\"'+bpu+'\"></td><td width=\"'+structure2[2]['width']+'\" align=\"'+structure2[2]['align']+'\"><input name=\"'+structure2[2]['name_input']+'[]\" style=\"width: 100%;\" disabled=\"disabled\" value=\"'+tu+'\"></td></tr></tbody>';
if (rep==true)	
	document.getElementById('main_table_'+nom).innerHTML=strfinal;
else
	document.getElementById('main_table_'+nom).innerHTML=str+strfinal;


}

function enableAll(form)
{
	var i=0;
	var tab=document.getElementsByName('".$structure[0]['name_input']."[]');
	for (i=0;i<tab.length;i++) {
		tab[i].disabled=false;
        }
}

function userFind(nom)
{
	var i=0;
	var tab=document.getElementsByName('".$structure[0]['name_input']."[]');
	for (i=0;i<tab.length;i++) {
		if (tab[i].value==nom) return true;
}
return false;
}

function addFromListSource(namesource,namedest) 
{
var i=0;
var j=0;
var str='';
var strdest='';
var test='';
var val_td;
test='tr_'+namedest+0;

for( i=0; document.getElementById(test)!=null ;i++)
{
	test='tr_'+namedest+i;
}

if (i>0)
	var j=i-1;
else
	var j=0;

var x=0;

strdest=document.getElementById('main_table_'+namedest).innerHTML;
for (i=0; document.getElementById(namesource + i)!=null; i++) {
	val_td=document.getElementById('tr_div_'+namesource+i).innerHTML;
		if (document.getElementById(namesource + i).checked==false)
		{
                       
			var reg=new RegExp(namesource+i, \"g\");
			var res=val_td.replace(reg,namesource+x);
			var reg2=new RegExp(',\"'+i+'\",', \"g\");
			var resf=res.replace(reg2,',\"'+x+'\",');
			str=str+'<tbody id=\"tr_div_'+namesource+x+'\">'+resf+'<tbody>';
			x=x+1;
                  }
               else
	        {
		       if (document.getElementsByName('".$structure2[0]['name_input']."'+'[]') && document.getElementsByName('".$structure2[0]['name_input']."'+'[]')[i]) 	
			       var nu=document.getElementsByName('".$structure2[0]['name_input']."'+'[]')[i].value;
		       if (userFind(nu)==true) alert('User '+nu+' already exist not added.');
		       else {
			  
			var reg=new RegExp(namesource, \"g\");
			var res=val_td.replace(reg,namedest);
			var regtmp;
			var restmp=res;
			for (v=0; v<structure2.length; v++) {
			     regtmp=new RegExp(structure2[v]['name_input'], \"g\");
			     restmp=restmp.replace(regtmp,structure[v]['name_input']);
                        }
			var reg2=new RegExp(namedest+i, \"g\");
			var res2=restmp.replace(reg2,namedest+j);
			var reg3=new RegExp(',\"'+i+'\",', \"g\");
			var resf=res2.replace(reg3,',\"'+j+'\",');
			strdest=strdest+'<tbody id=\"tr_div_'+namedest+j+'\">'+resf+'<tbody>';
			j=j+1;
                       } 

               } 
}
document.getElementById('main_table_'+namesource).innerHTML=str;
var reg2=new RegExp('<tbody></tbody>', \"g\");
var resf=document.getElementById('main_table_'+namesource).innerHTML.replace(reg2,'');
document.getElementById('main_table_'+namesource).innerHTML=resf;

document.getElementById('main_table_'+namedest).innerHTML=strdest;
var reg2=new RegExp('<tbody></tbody>', \"g\");
var resf=document.getElementById('main_table_'+namedest).innerHTML.replace(reg2,'');
document.getElementById('main_table_'+namedest).innerHTML=resf;
}

function findAccountGroup(nom)
{
	 var text=fileXml('include/divers/findAccountGroup.php?user='+document.getElementById('usernamegroup').value+'&&loc='+$lid);
	 var root = text.getElementsByTagName('users')[0];
	 var users = root.getElementsByTagName('user');
	 if (users.length==1) alert('Sorry, try again no result found.');
	 else {
	 ul=users.length-1;
	 for (var iNode = 0; iNode < ul; iNode++) {
		 var item = users[iNode];
		  nu=item.getElementsByTagName(\"name\")[0].firstChild.nodeValue;
		  bpu=item.getElementsByTagName(\"BillingPlan\")[0].firstChild.nodeValue;
		  tu=item.getElementsByTagName(\"Type\")[0].firstChild.nodeValue;
		  if (iNode==0) 
			  addLigneToDestination(nom,nu,bpu,tu,true);
		  else
			  addLigneToDestination(nom,nu,bpu,tu,false);
              }
      alert(\"Successfull find user(s) !\");
     }
}

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\" >";

$result=$oreon->database->database->query("SELECT usergroup.UserName,BillingPlan,Type FROM usergroup,userinfo WHERE usergroup.UserName=userinfo.UserName AND GroupName='$gp_name' AND location_id='$lid' GROUP BY usergroup.UserName");
if ($debug) print "SELECT usergroup.UserName,BillingPlan,Type FROM usergroup,userinfo WHERE usergroup.UserName=userinfo.UserName AND GroupName='$gp_name' AND location_id='$lid' GROUP BY usergroup.UserName";


  if ($debug)  print "<br>contenu                ".$oreon->database->database->result_num_rows($result);

$i=0;	
while ($row = mysql_fetch_array($result)) {
    $pln=get_plan_name($row[1]);
    if ($debug) print $pln;
    $contenu[$i] = array($row[0],get_plan_name($row[1]),$row[2]);
    $i++;
  }

echo '<div align="left" >';
if ($debug) print ' SIZEOF '.sizeof($contenu);
echo checkedSelect($namedest, $structure, $contenu, "disabled","");
echo '<br />';
echo '</div></td><td>';
print "<a href=\"JavaScript:deleteFromListGroup('$namedest')\"><img  src=\"images/delete.png\" title=\"Del user from group\"></a>";
echo '</td></tr></table>';
 
$nom="Source";
echo ('<br><hr><table>');		
echo('<tr>');
echo ('<td class="fieldcell" style="text-align: left">');
echo "<input type=\"text\" width=\"17\" id=\"usernamegroup\" class=\"text\" value=\"$username\" name=\"findAccountName\">";
echo ('</td>');
echo (' <td style="height: 33px; width: 33px;">');
print "<a href=\"JavaScript:findAccountGroup('$nom')\"><img  src=\"images/search.png\" title=\"Find account\"></a>";
echo "</table>";
echo '<br>';

echo "<table><tr><td colspan=\"5\" rowspan=\"1\" >";

$contenu2=array();
echo '<div align="left" >';
echo checkedSelect($nom, $structure2,$contenu2,true,"");
echo '<br />';
echo '</div></td><td>';
print "<a href=\"JavaScript:addFromListSource('$nom','$namedest')\"><img  src=\"images/insert.png\" title=\"Add user to group\"></a>";
echo '</td></tr></table>';
 
echo ('<hr><table>');		
			
	
	

echo "<input type=\"hidden\" name=\"buttonID\" value=\"user_group_save\">";
echo "<input type=\"hidden\" name=\"gp_id\" value=\"$gp_id\">";
echo "<input type=\"hidden\" name=\"gp_name\" value=\"$gp_name\">";
echo "<input type=\"hidden\" name=\"locationID\" value=\"$lid\">
	<input name=\"usersavegroup\" type=\"submit\"  class=\"smallButton\" value=\"Save Configuration\" onClick=\"enableAll(this.form);\" >

	<tr>
</form>
</table>

";
}
else echo $msg;
			
		
Return current item: phpMyPrepaid