<?PHP
include_once("config.php");
$form1=$_GET["form"];
$action=$_POST["command"];
$id=$_POST["rolelist"] ;
if ($form1=="role_edit"){
if ($action == "Cancel") {
header('Location: role_list.php');
} else{
$id=$_POST["id"] ;
$rolename = $_POST["rolename"] ;
$error_txt = '';
if ($rolename =="" ){
$error_txt = "Role-name can not be blank";
} else{
if ($id==0){
$sql = "select * from erprole where upper(rolename)=upper('$rolename')" ;
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows ==0){
$sql="INSERT INTO erprole (rolename) VALUES ( '$rolename')";
$result = mysql_query($sql);
}
} else{
$sql="UPDATE erptrole SET rolename='$rolename' WHERE roleid = $id";
$result = mysql_query($sql);
}
}
header('Location: role_list.php');
}
} else {
if ($form1<>"role_list"){
header('Location: role_list.php');
}
if ($action == "New"){
$id = 0;
$rolename="";
}
if ($action == "Delete"){
$sql="select * from erpuser where roleid=$id";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows>0){
die("Role is still in use and cannot be deleted");
}
$sql="delete from erprole where roleid = $id";
$result = mysql_query($sql);
header('Location: role_list.php');
}
if ($action == "Edit"){
$sql="SELECT * FROM erprole WHERE roleid = $id";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows <>0){
$row = mysql_fetch_row($result);
$id = $row[0];
$rolename = $row[1];
}
}
}
?>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="<?PHP echo $style ?>" >
<script language="JavaScript1.2" src="js/coolmenus4.js">
</script>
</HEAD>
<body bgcolor="#ffffff">
<script language="JavaScript1.2" src="js/erpsod.js">
</script><br><br>
<center>
<h3>Roles</h3>
<?php
if ($error_txt <>""){
echo $error_txt ;
echo "<br>";
}
?>
<FORM ACTION="role_edit.php?form=role_edit" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="id" VALUE="<?php echo $id ?>">
<table border=0 cellpadding=4 cellspacing=0 bgcolor="AQUA"><tr><td>
<tr>
<td>Role name</td>
<td><Input Name="rolename" MaxLength="50" Size="50" Value="<?php echo $rolename ?>"></td>
</tr>
<br>
<br>
<tr>
<td colspan=2 align="center">
<?php if (role_check("Updater")) { ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Submit">
<?PHP } ?>
<INPUT TYPE="SUBMIT" NAME="command" VALUE="Cancel">
</td></tr>
</table>
</td></tr></table>
</center>
</FORM>
</BODY>
<?php
include_once("footer.php");
?>
</HTML>