Jump to content

Php Help


Guest wasantha
 Share

Recommended Posts

Guest wasantha

Dear all, :) I have some problem when executing following codes in a project of mine.I want get the relevant data only for user_level=2, not the other user levels.Because only user level 2 does the calculation after user level five enters the department score.How can you inactivate the codes of other while not harming to functioning of the page.Pl help me to sort this out as the final presentation will on the 10th of this month; the Wendesday.codes are:<?php// Initialize the session.session_start();if(!isset($_SESSION["Emp_No"])||!isset($_SESSION["Dep_Name"])||!isset($_SESSION["User_Level"])||!isset($_SESSION["Email"])) { header("Location:./error.php");}if($_SESSION["User_Level"]=='1'||$_SESSION["User_Level"]=='3') { header("Location:./error.php");}//assisgn variable $supeno for the $_SESSION['epf_no'];$supeno=$_SESSION["epf_no"];//define the configuration of database properties$dbhost='localhost';$dbuser='root';$dbpass='';$dbname='metrosite';//assisgn "Approve" or "Submit" for $_POST["Update"]if($_POST["Update"]=="Approve"||$_POST["Update"]=="Submit"){ //connecting,selecting the database $conn = mysql_connect($dbhost,$dbuser,$dbpass)or die (mysql_error()); mysql_select_db($dbname, $conn) or die (mysql_error ()); ///assigning variables to the post variables $increment = $_POST["increment"]; $empno = $_POST["hiddenField"]; $Mem_Epf_No=$_POST["Mem_Epf_No"]; echo "the increment value is =".$increment; // make an argument if user_level is 5 if($_SESSION["User_Level"]=='5') { // make a query $query ="UPDATE `appraiser` SET `Increment` = '$increment',`submit`='CEO approved' WHERE `Mem_Epf_No` ='$empno' LIMIT 1 "; // make an argument if user_level is 4 or 6 //$sql = "UPDATE `appraiser` SET `Increment` = '5000' WHERE CONVERT( `Sup_Epf_No` USING utf8 ) = '2123' AND CONVERT( `Mem_Epf_No` USING utf8 ) = '1111' LIMIT 1"; } elseif($_SESSION["User_Level"]=='4'||$_SESSION["User_Level"]=='6') { $query="UPDATE `appraiser` SET `Increment`= '$increment',`submit`='submitted' WHERE `Sup_Epf_No` ='$supeno' AND `Mem_Epf_No` ='$empno' LIMIT 1 "; } mysql_query($query ,$conn) or die (mysql_error()); mysql_close($conn);}/*elseif($_POST["Delete"]=="Delete"){ $conn = mysql_connect($dbhost,$dbuser,$dbpass)or die (mysql_error()); mysql_select_db($dbname, $conn) or die (mysql_error ()); $increment = $_POST["increment"]; $empno = $_POST["hiddenField"]; $query ="DELETE FROM `appraiser` WHERE `Sup_Epf_No` ='$supeno' AND `Mem_Epf_No` ='$empno' "; mysql_query($query ,$conn) or die (mysql_error()); mysql_close($conn); }*//*echo "<script>alert('aaa')</script>";*/?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Increment</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><script language="javascript"><!--I.E only-->if (document.all){with(window.document.body.style){borderWidth=10;; borderStyle='solid'; borderColor='green';}}<!-- change border width here!--><!-- change color here!--></script><table width="933" border="3"> <tr> <th width="690" scope="col"> </th> <th width="107" scope="col"><a href="file:///C|/wamp/www/NEW/login.php">logout</a></th> <th width="110" scope="col"><a href=<?php echo $_SESSION['file:///C|/wamp/www/NEW/url']; ?>>home</a></th> </tr></table><br /><br /><?phpif($_SESSION["User_Level"]=='5') { ?><a href="file:///C|/wamp/www/NEW/dept_score_page.php">Edit Department Scores</a><br /><br /> <? } ?> <?php $conn = mysql_connect($dbhost,$dbuser,$dbpass)or die (mysql_error()); mysql_select_db($dbname, $conn) or die (mysql_error ()); if($_SESSION["User_Level"]=='2') { $sql="select Mem_Epf_No,First_Name,Last_Name,Dep_Name,salary,Total_Avg_Points,Increment,submit from appraiser a ,emp e where e.Emp_No IN(SELECT a.Mem_Epf_No FROM appraiser) AND submit='CEO approved' ORDER BY e.Dep_Name"; print "\t<td>"."<font class=\"style1\" color=\"#FF9966\" size=\"+1\"><u>"."Increment"."</u></font></td>\n"; // CALCULATE INCREMENT if(isset($_POST["calc_increment"]) && $_POST["calc_increment"]=="Calculate"){ $memEpf = $_POST["memEpf"]; $inc_Val = $_POST["inc_Val"]; $sql_str = "UPDATE `appraiser` SET `Increment`='".$inc_Val."' WHERE Mem_Epf_No='".$memEpf."'"; $qury = mysql_query($sql_str,$conn); if($qury){ echo "<script>alert('Succussfully Updated...!')</script>"; echo "<script>window.location.href='Increment.php';</script>"; }else{ echo "<script>alert('Error: Not Updated.')</script>"; echo "<script>window.location.href='Increment.php';</script>"; } } // } elseif($_SESSION["User_Level"]=='5') { $sql ="select Mem_Epf_No,First_Name,Last_Name,Dep_Name,salary,Total_Avg_Points,Increment,submit from appraiser a ,emp e where e.Emp_No IN(SELECT a.Mem_Epf_No FROM appraiser) ORDER BY Dep_Name"; } else { $sql ="select Mem_Epf_No,First_Name,Last_Name,Dep_Name,salary,Total_Avg_Points,Increment,submit from appraiser a ,emp e where e.Emp_No IN(SELECT a.Mem_Epf_No FROM appraiser WHERE a.Sup_Epf_No ='$supeno')"; } $result=mysql_query($sql,$conn); if(!$result) { echo mysql_error(); exit; } mysql_close($conn); $colName = Array(); $num = mysql_num_fields($result); //create table border print "<table border=\"1\" width='100%' id='tab_inc'>\n"; for($c=0;$c < $num ; $c++){ //fetch the data one by one and create table fileds as per query select $object = mysql_fetch_field($result,$c); $colName[$c] = $object->name; print "\t<td>"."<font class=\"style1\" color=\"#GF9966\" size=\"+1\">".$object->name."</font></td>\n"; } // if user_level ==2 create an another field as letter if($_SESSION["User_Level"]=='2') echo("<td><font class=\"style1\" color=\"#FF9966\" size=\"+1\">Department Score</font></td>". "<td>Calculate Increment</td>"."<td><font class=\"style1\" color=\"#FF9966\" size=\"+1\">Letter</font></td>"); //print "\t<td>"."<font class=\"style1\" color=\"#FF9966\" size=\"+1\">"."Increment Letter"."</font></td>\n"; //print "<tr>\n"; //print "</tr>\n"; //define a varaible $n $n=0; //fetch $result to a variable $row while($row =mysql_fetch_assoc($result)){ print "<tr>\n"; $n++; print "\t<form name=\"form".$n."\" method=\"post\" action=\"\" onsubmit=\"return Calc_Increment('".$n."');\">"; //define a varaible $i $i = 0; //assisgn $v to $row["Mem_Epf_No"]; $v=$row["Mem_Epf_No"]; //echo $row["Mem_Epf_No"]; //print into a hidden field print "\t<input type=\"hidden\" name=\"hiddenField\" value='$v'>"; //$ss = ""; //foreach loop foreach($row as $field) { /*echo "<script>alert('$field')</script>";*/ $i++; //TRUE if both $_POST["Edit"] and $_POST["hiddenField"] are TRUE. //if($_POST["Edit"]=="Edit" && $v == $_POST["hiddenField"] ){ if($_POST["Edit"]=="Edit" && $v == $_REQUEST["hiddenField"] ){ echo $_REQUEST["hiddenField"] ; //if($_POST["Edit"]=="Edit" && $v == 4789 ){ //put the fetch $row data to $field if($row["Increment"]==$field) print "\t<td><input name=\"increment\" type=\"text\" value=\"".stripslashes($field)."\"></td>\n"; else print "\t<td><input name=\"textfield\" type=\"text\" value=\"".stripslashes($field)."\"></td>\n"; } ////////// //if updated elseif($_POST["Update"]=="Update"){ $x =$_POST['increment']; //TRUE if both $row["Increment"] and $_POST["hiddenField"] are TRUE. if($row["Increment"]==$field && $v == $_POST["hiddenField"]) //print and show them as disabled print "\t<td><input name=\"textfield\" type=\"text\" value=\"".$x."\" disabled ></td>\n"; else print "\t<td><input name=\"textfield\" type=\"text\" value=\"".stripslashes($field)."\" disabled ></td>\n"; } //TRUE if both $_POST["Delete"] and $_POST["hiddenField"] are TRUE. elseif($_POST["Delete"]=="Delete"&& $v != $_POST["hiddenField"]){ if($row["Increment"]==$field) print "\t<td><input name=\"increment\" type=\"text\" value=\"".stripslashes($field)."\"></td>\n"; else print "\t<td><input name=\"textfield\" type=\"text\" value=\"".stripslashes($field)."\"></td>\n"; } else{ // Getting Department Name if($i==1){ $memEpf = stripslashes($field); } // Getting Department Name if($i==4){ $dep_name = stripslashes($field); } // Getting Total Average Point if($i==6){ $total_avg_point = stripslashes($field); } // Getting the Salary if($i==5){ $salary_amt = stripslashes($field); } print "\t<td><input name=\"textfield\" type=\"text\" value=\"".stripslashes($field)."\" disabled ></td>\n"; } } if($_SESSION["User_Level"]=='5') { print "\t<td><input type=\"submit\" name=\"Edit\" value=\"Edit\">"; // print "\t<input type=\"submit\" name=\"Delete\" value=\"Delete\">"; print "\t<input type=\"submit\" name=\"Update\" value=\"Approve\">"; } elseif($_SESSION["User_Level"]=='4'||$_SESSION["User_Level"]=='6') { if($row["submit"]=="pending") { print "\t<td><input type=\"submit\" name=\"Edit\" value=\"Edit\">"; print "\t<input type=\"submit\" name=\"Update\" value=\"Submit\">"; } } if($_SESSION["User_Level"]=='2'){ // Show Department Score according to the Departments $conn = mysql_connect($dbhost,$dbuser,$dbpass)or die (mysql_error()); mysql_select_db($dbname, $conn) or die (mysql_error ()); $qry = "SELECT * FROM department WHERE dept_name='$dep_name'"; $rst=mysql_query($qry,$conn) or die('Query failed. '.mysql_error()); if(mysql_num_rows($rst)==1){ $rw=mysql_fetch_assoc($rst); $dept_score = $rw["dept_score"]; $increment_amount = $rw["increment_amount"]; } $Yi = $dept_score + $total_avg_point; $X += $Yi; $Pi = ($Yi / $X) * $salary_amt; /*echo "<script>alert('$Yi')</script>";*/ echo "<td align=\"center\">".$dept_score."<input type=\"hidden\" value=\"".$memEpf."\" name=\"memEpf\" /><input type=\"hidden\" value=\"".$Yi."\" name=\"Yi".$n."\" id=\"Yi".$n."\" /><input type=\"hidden\" value=\"".$salary_amt."\" name=\"salary_amt".$n."\" id=\"salary_amt".$n."\" /></td>"; echo "<td align=\"center\"><input type=\"submit\" value=\"Calculate\" name=\"calc_increment\" /></td>"; //hyperlink of the file Letter.php echo("<td><a href='Letter.php?epf=".$v."'>Click Here</a></td>"); echo "<input type=\"hidden\" name=\"inc_Val\" id=\"inc_Val".$n."\" />"; print "</form></td>\n"; print "</tr>\n"; } } echo "<input type=\"hidden\" value=\"".$increment_amount."\" name=\"increment_amount\" id=\"increment_amount\" />"; echo "<input type=\"hidden\" value=\"".$X."\" name=\"Xi\" id=\"Xi\" />"; ?></body></html><script language="javascript">function Calc_Increment(n){ var Yi = document.getElementById('Yi'+n).value; var Xi = document.getElementById('Xi').value; var B = document.getElementById('increment_amount').value; var Si = document.getElementById('salary_amt'+n).value; var arr1 = Si.split(','); var newSi = arr1[0] + '' + arr1[1]; var Pi = (Yi / Xi) * newSi; var Pj=0; var n_row = document.getElementById('tab_inc').rows.length; for(var k=1;k<n_row;k++){ var Yj = document.getElementById('Yi'+k).value; var Sj = document.getElementById('salary_amt'+k).value; var arr2 = Sj.split(','); var newSj = arr2[0] + '' + arr2[1]; Pj += (Yj / Xi) * newSj; // Sum of Pi } var inc = (Pi / Pj) * B; var inc_Val = inc.toFixed(2); //alert(inc_Val); if(!isNaN(inc_Val)){ document.getElementById('inc_Val'+n).value = inc_Val; return true; }else{ return false; } }</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...