Hi Guys,
I'm working on a project and modifying it's code, I'm new to php, what I want is to speed up the process of the program, before it works like this, there is a page containing all the ID of purchase request, then there is a link to another page where you will have a choice to select within 3 suppliers, after that, there is a save selection page to update the database(SQL). The problem is if you have a lot of request it will take time for you to manually select the supplier one by one, What I want to do is put a checkbox in the first page, have a select all button, and upon submitting the request, the choice is the supplier 1, does removing the function of the 2nd page to select from supplier and automatically selecting supplier 1 and update the database. I can't figure out what's wrong, here is my code
<?php
//additional Code
//if ($_SESSION['userid'] != '02011739'){header("location: ./errormaintenance.php");}
$prid = $_GET['prid'];
$rowPR = mysql_fetch_array(mysql_query("SELECT purchstaff_id, pr_dept, pr_process, pr_reqname, pr_qty, pr_rdd, pr_status FROM tblpr WHERE pr_id='$prid'"));
$pstaff = $rowPR['purchstaff_id'];
$dept = $rowPR['pr_dept'];
$proc = $rowPR['pr_process'];
$req = $rowPR['pr_reqname'];
$itmq = $rowPR['pr_qty'];
$rdd = $rowPR['pr_rdd'];
$prstatus = $rowPR['pr_status'];
$rowtblUsers = mysql_fetch_array(mysql_query("SELECT user_fname, user_lname FROM tblusers WHERE user_id='$pstaff'"));
$staffname = $rowtblUsers['user_fname'].' '.$rowtblUsers['user_lname'];
$rowItemName = mysql_fetch_array(mysql_query("SELECT item_name, item_uom FROM tblitems WHERE item_id=(SELECT item_id FROM tblpr WHERE pr_id='$prid')"));
$itmn = $rowItemName['item_name'];
$itmu = $rowItemName['item_uom'];
$rowCVS = mysql_fetch_array(mysql_query("SELECT * FROM tblcanvass WHERE pr_id='$prid'"));
$canvassdt = $rowCVS['canvass_dt'];
$cvssel = $rowCVS['canvass_sel'];
$supid1 = ($rowCVS['supid1'] != '0000') ? $rowCVS['supid1']: 'N/A';
$cur1 = $rowCVS['cur1'];
$uprc1 = $rowCVS['uprc1'];
$dpcnt1 = $rowCVS['dpcnt1'];
$quote1 = $rowCVS['quote1'];
$rem1 = $rowCVS['rem1'];
//----->
$supid2 = ($rowCVS['supid2'] != '0000') ? $rowCVS['supid2']: 'N/A';
$cur2 = $rowCVS['cur2'];
$uprc2 = $rowCVS['uprc2'];
$dpcnt2 = $rowCVS['dpcnt2'];
$quote2 = $rowCVS['quote2'];
$rem2 = $rowCVS['rem2'];
//----->
$supid3 = ($rowCVS['supid3'] != '0000') ? $rowCVS['supid3']: 'N/A';
$cur3 = $rowCVS['cur3'];
$uprc3 = $rowCVS['uprc3'];
$dpcnt3 = $rowCVS['dpcnt3'];
$quote3 = $rowCVS['quote3'];
$rem3 = $rowCVS['rem3'];
//end of additional code
include("./includes/func_phpPaginate.php");
$col_heads = array("","" ,"pr_id"=>"prid", "pr_reqname"=>"requestor", "pr_reqdt"=>"date requested", "pr_rcvdt"=>"date received", "item_name"=>"item name");
$target_page = "./staff.php?page=9&sub=9";
$psub = $_GET['page'];
$table = "tblpr, tblitems";
$where1 = "WHERE purchstaff_id=$_SESSION[userid] AND pr_status='5' AND tblpr.item_id = tblitems.item_id AND";
$where2 = "WHERE purchstaff_id=$_SESSION[userid] AND pr_status='5' AND tblpr.item_id = tblitems.item_id";
$initial_order = "pr_rcvdt DESC";
$items_per_page = 20;
$arrPagination = phpPaginate($col_heads, $target_page, $psub, $table, $where1, $where2, $initial_order, $items_per_page);
$result = $arrPagination[0];
$pagination = $arrPagination[1];
?>
<script language="javascript">
//additional script
var bool = 0;
function selected(){
bool = 1;
}
function checkfields (form){
if (bool == 0){
alert('Please choose a supplier.');
return false;
}else{
if (confirm("Are you sure you want to submit this request with your selected supplier?") == 1){
return true;
}else{
return false;
}
}
}
//end of additional script
//function approve all2
function confirmApproveAll2(){
temp = document.form.elements.length ;
if( temp == 0){
alert('Please mark all the request you want to approve.');
return false;
}else{
if (confirm("Are you sure you want to approve all marked request?") == 1){
return true;
}else{
return false;
}
}
}
//end of function approveall2
//function selectAll
function selectAll(){
temp = document.form.elements.length ;
for (i=0; i < temp; i++) {
if(document.form.elements[i].checked == 1 )
{document.form.elements[i].checked = 1;
document.form.approveall.value = "Select All"; }
else {document.form.elements[i].checked = 1;
document.form.approveall.value = "Select All"; }
}
}
//end of function selectAll
function confirmSBack(){
if (confirm("Are you sure you want to send this back to purchasing staff?") == 1){
return true;
}else{
return false;
}
}
function confirmCancel(){
if (confirm("Are you sure you want to cancel this request?") == 1){
return true;
}else{
return false;
}
}
</script>
<!-- <form name="form" method="get" action="<?php //echo $_SERVER['PHP_SELF']; ?>"> -->
<form name ="form" method="POST" onsubmit="return checkfields(this)" action="?prid=<?php// echo $prid;?>&sub=9&action=saveselection">
<?php echo $pagination; ?>
<div style="border-bottom: 1px solid #666; margin-left: 1px; margin-top: 2px; float: left; width: 100%;">
<table id="tblcvs" style="border-collapse: collapse; width: 100%;">
<thead style="background-color: transparent; background-image: url(./images/sprite.png); background-repeat: repeat-x; background-attachment: scroll; background-position: 0px -5px;">
<tr><?php foreach($col_heads as $key=>$value) echo "<th style=\"border: 1px solid #666;\">".$value."</th>"; ?></tr>
</thead>
<?php
while($row = mysql_fetch_array($result)){
include('./includes/statuscodes.php');
//additional code
$rowSupplier = mysql_fetch_array(mysql_query("SELECT supplier_name FROM tblsuppliers WHERE supplier_id='$supid1'"));
$supname1 = ($rowSupplier['supplier_name'] != '') ? $rowSupplier['supplier_name'] : 'N/A';
// <!--end of additional code -->
echo '<tr style="border-left: 1px solid #666;">';
//additional
echo '<td style="border-right: 1px solid #666;"> <input type="checkbox" name="optSupplier" onclick="selected();" value="1" /></td>';
if ($supid1 == 'N/A'){ echo disabled;}
if($cvssel==1){ echo '<span style="color: red;">****** Selected Supplier ******</span>';} else{ echo ' ';}
//end of additional
echo '<td style="border-right: 1px solid #666;"><a href=?sub=9&prid='.$row['pr_id'].'&action=select ><img src="./images/btnSelectSupplier.png" title="select supplier"></img></a></td>';
echo '<td style="border-right: 1px solid #666;"><a href="#" onclick="viewreport_full(this,'.number_format($row['pr_id'],'','','').');">'.$row['pr_id'].'</a></td>';
echo '<td style="border-right: 1px solid #666;">'.$row['pr_reqname'].'</td>';
echo '<td style="border-right: 1px solid #666;">'.$row['pr_reqdt'].'</td>';
echo '<td style="border-right: 1px solid #666;">'.$row['pr_rcvdt'].'</td>';
echo '<td style="border-right: solid 1px #666;" ><a href=?sub=9&itmid='.$row['item_id'].'&action=viewitem >'.$row['item_name'].'</a></td>';
echo '</tr>';
}
$num_rows = mysql_num_rows($result);
if ($num_rows != 0){
echo '<tr class="lastrow">
<td colspan="10">
<input name="approveall" type="button" onclick="return selectAll()" value="Select All">
<!-- <input type = "submit" name = "optSupplier" value = "approve" onclick = " return confirmApproveAll2()"> -->
<input type="submit" value="submit" />
<!-- <input type="submit" name="optSupplier" value="approve" onclick="return confirmApproveAll()" /> -->
</td>
</tr>';
}
?>
</table>
</div>
</form>
Here is the save selection page
<?php
$prid = $_GET['prid'];
$prsupselname = $_SESSION['fullname'];
$prsupseldt = date("Y-m-d h:i:s A");
$cvssel = $_GET['optSupplier'];
/*
$rowVer2id = mysql_fetch_array(mysql_query("SELECT pr_ver2id FROM tblpr WHERE pr_id='$prid'"));
$ver2id = $rowVer2id['pr_ver2id'];
if($ver2id != ''){$prstatus = '55';}
else{$prstatus = '4';}
*/
$result = mysql_query("UPDATE tblcanvass SET canvass_sel=$cvssel WHERE pr_id='$prid'");
$result = mysql_query("UPDATE tblpr
SET pr_supselname='$prsupselname', pr_supseldt='$prsupseldt', pr_status='7'
WHERE pr_id='$prid'");
if (mysql_affected_rows() == 1) {
echo '<p><span class="notes">The selected supplier has been saved to the database.</span></p>';
echo '<p><span class="notes">click <a href="./staff.php?page=9&sub=9">here</a> to view other requests.</span></p>';
//Email the purchasing
//mail function - START
$toaddress = 'Chona.Lising@ph.nsg.com, mau@ph.nsg.com';
//$toaddress = 'KristofferRyan.David@ph.nsg.com';
$subject = 'New Canvass Approval';
// message
$mailcontent = '
<html>
<body>
<p>A canvass has been prepared for PR#: <b>'.$prid.'</b>.</p>
<p>Please check the canvass sheet by logging on to the e-Purchase Request system. </p>
<p>The link below will redirect you to the login page of the system. </p>
<p><a href="http://10.127.8.50/prsystem/index.php">http://10.127.8.50/prsystem/index.php</a></p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'BCC: KristofferRyan.David@ph.nsg.com';
mail($toaddress, $subject, $mailcontent, $headers);
//mail function - END
} else{
error_log(mysql_error());
echo '<p>Sorry, Information has not been recorded.</p>';
}
?>
please help.
Thank You