944,183 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1215
  • Perl RSS
Nov 7th, 2009
-1

php coding

Expand Post »
<?php
session_start();
//Check User Session
include ("includes/check_session.php");

include 'includes/config.php';
$current_module = 'MATERIALREQ';
//$related_modules = array('BIDDINGENTRY','PIRRAISING','POLIST','BIDDINGSELECTION','GRV');
include ('includes/check_acl.php');

//include 'includes/config.php';
include 'includes/sqlquery.php';
include 'includes/message.php';
$valid = '';

$current_user_id = $_SESSION['associate_id'];

//if the session value is present, set whether the last transaction is stored or not
if (isset($_SESSION['mrmsg']) && ($_SESSION['mrmsg']!=''))
{
$valid = $_SESSION['mrmsg'];
$last_mr_id = $_SESSION['last_mr_id'];
$_SESSION['mrmsg']=''; //clear it
$_SESSION['last_mr_id']=''; //clear it
}

if(!empty($_POST['hdn_total'])){
try {
begin();

if(!$acl['MATERIALREQ']['write']) throw new Exception("You don't have rights to do Material Request");

$valid = 'failure';
//$getVal['MRNo'] = mysql_real_escape_string($_POST['txtMatReqNo']);
$getVal['MRDate'] = mysql_real_escape_string(DBdate($_POST['txtMatReqDate']));
$getVal['PreperdBy'] = mysql_real_escape_string($_POST['cmbRequestedBy']);
$getVal['StoreNo'] = mysql_real_escape_string($_POST['cmbStoreID']);
$getVal['RequiredAt'] = mysql_real_escape_string($_POST['cmbRequiredAt']);
$getVal['Remarks'] = mysql_real_escape_string($_POST['txtRemarks']);


$getError = addMaterialReq($getVal);

if(!empty($getError)) throw new Exception($getError);

if(empty($getError)){
$getVal["MRNo"] = mysql_insert_id();
$hdnId = explode(",", $_POST['hdn_total']);
$count = count($hdnId);
$j=1;
for($i=0;$i<$count;$i++){
$getVal['ItemCode'.$j] = mysql_real_escape_string($_POST['ItemCode'.$j]);
$getVal['ItemName'.$j] = mysql_real_escape_string($_POST['ItemName'.$j]);
$getVal['Description'.$j] = mysql_real_escape_string($_POST['Description'.$j]);
$getVal['Quantity'.$j] = mysql_real_escape_string($_POST['Quantity'.$j]);

$getError = addMaterialReqItems($getVal, $i);
if(!empty($getError)) throw new Exception($getError);
$j++;
}
$valid = 'success';
}

$_SESSION['mrmsg'] = $valid;
$_SESSION['last_mr_id'] = $getVal["MRNo"];
commit();
//header("Location: materialrequest.php");
echo "<META HTTP-EQUIV='Refresh' CONTENT='0;materialrequest.php'>";
}
catch(Exception $s)
{
rollback();
$errmsg = $s->getMessage();
myExceptionHandler($s);
$valid = false;
}
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MintHome</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="javascripts/autosuggest.js" charset="utf-8"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/autosuggest_inquisitor.css" rel="stylesheet" type="text/css" media="screen" charset="utf-8" />
<style type="text/css">
<!--
.style1 {color: #E78D2E}
-->
</style>


<script language="javascript" type="text/javascript" src="javascripts/datetimepicker_css.js">
</script>

<script language="javascript">

function checkForm()
{
return false;
}

function itemcode_checker()
{
var invalid = false;
DGrid.setTotalRow();
var rowNos = document.getElementById('hdn_total').value;
indivRow = rowNos.split(',');
cnt_rows = indivRow.length;
var cnt_itemTotalindb = itemIDS.length;
var itempresent_db = false;

for(i=0;i<cnt_rows;i++)
{
itemcode_rowID = 'ItemCode'+indivRow[i];
itemcode_val = document.getElementById(itemcode_rowID).value;
if (itemcode_val != '')
{
itempresent_db = false;
for(j=0;j<cnt_itemTotalindb;j++)
{
if (itemcode_val == itemIDS[j])
{
itempresent_db = true;
break;
}
}

if (itempresent_db == false)
{
alert('Item Code Not Correctly Entered');
document.getElementById(itemcode_rowID).focus();
break;
}
}
}
if (itempresent_db == false) return false;
return true;
}

function validateGrid()
{
var rowNos = document.getElementById('hdn_total').value;
//alert(rowNos);
indivRow = rowNos.split(',');
cnt_rows = indivRow.length;
atleast_oneitem = false;

for(i=0;i<cnt_rows;i++)
{
itemcode_rowID = 'ItemCode'+indivRow[i];
itemqty_rowID = 'Quantity'+indivRow[i];

itemcode_val = document.getElementById(itemcode_rowID).value;
itemqty_val = document.getElementById(itemqty_rowID).value;

if (itemqty_val > 0 && (itemcode_val == '' || itemcode_val <= 0))
{
document.getElementById(itemcode_rowID).focus();
alert('Enter Item code');
return false;
}


if (itemcode_val > 0 && (itemqty_val == '' || itemqty_val <= 0))
{
document.getElementById(itemqty_rowID).focus();
alert('Enter Item Code '+itemcode_val+': Quantity Level');
return false;
}

if (itemcode_val > 0 && itemqty_val > 0)
{
atleast_oneitem = true;
}
}

//Check atleast one item is added to Grid
if (atleast_oneitem == false)
{
alert('No Items is added in the Grid to raise Purchase Indent');
itemcode_rowID = 'ItemCode'+indivRow[0];
itemcode_val = document.getElementById(itemcode_rowID).value;
return false;
}
return true;
}

function CompareDates()
{
var str1 = document.getElementById("serverdate").value;
var str2 = document.getElementById("txtMatReqDate").value;
var date1 = str1.split("-", 3);
var dt1 = parseInt(date1[0]);
var mon1 = date1[1];
// mon1 = parseInt(mon1);
var yr1 = parseInt(date1[2]);
// alert(dt1+" "+mon1+" "+yr1);
var date2 = str2.split("-", 3);
var dt2 = parseInt(date2[0]);
var mon2 = date2[1];
// mon2 = parseInt(mon2);
var yr2 = parseInt(date2[2]);
// alert(dt2+" "+mon2+" "+yr2);
//var dt1 = parseInt(str1.substring(0,2),10);
//var mon1 = parseInt(str1.substring(3,5),10);
//var yr1 = parseInt(str1.substring(6,10),10);
//var dt2 = parseInt(str2.substring(0,2),10);
//var mon2 = parseInt(str2.substring(3,5),10);
//var yr2 = parseInt(str2.substring(6,10),10);
var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);

if(date2 < date1)
{
alert("Request Date should be current or future date");
document.getElementById("txtMatReqDate").focus();
return false;
}
return true;
}

function validateForm()
{
valid = true;

if ( document.MatReq_Form.txtMatReqDate.value == '')
{
alert ( "Please Select PIR Transaction Date" );
document.MatReq_Form.txtMatReqDate.focus();
return false;
}

if (!CompareDates()) return false;

if ( document.MatReq_Form.cmbRequestedBy.selectedIndex <= 0)
{
alert ( "Please Select a Requested By User" );
document.MatReq_Form.cmbRequestedBy.focus();
return false;
}
if ( document.MatReq_Form.cmbStoreID.selectedIndex <= 0)
{
alert ( "Please Select a Store name" );
document.MatReq_Form.cmbStoreID.focus();
return false;
}
if ( document.MatReq_Form.cmbRequiredAt.selectedIndex <= 0)
{
alert ( "Please Select a Requested At" );
document.MatReq_Form.cmbRequiredAt.focus();
return false;
}
if ( document.MatReq_Form.txtRemarks.value == '')
{
alert ( "Please Enter Remarks" );
document.MatReq_Form.txtRemarks.focus();
return false;
}

DGrid.setTotalRow();

if (!itemcode_checker()) return false;
if (!validateGrid()) return false;

document.MatReq_Form.action = "materialrequest.php";
document.MatReq_Form.submit();
//location.href='materialapproval.php';

}

function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 96 || charCode > 105))
{
if (charCode < 96 || charCode > 105)
{
var keychar = String.fromCharCode(charCode);
reg = /\d/;
return reg.test(keychar);
}
return false;
}
return true;
}

function isNumberKey2(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
{
return false;
}
return true;
}

function checkForInvalid(obj)
{
if( /[^0-9\-]|-{2,}/gi.test(obj.value) )
{
alert("Only Numbers Allowed !")
obj.value="";
obj.focus();
obj.select();
return false;
}
return true;
}

function editpirForm()
{
window.location.href= ("editmrlist.php");
document.formname.submit();
}

</script>

</head>
<body>
<form name= "MatReq_Form" method="post" onsubmit="return checkForm();">
<div style="text-align:left; width:760px !important;">
<table border="0" cellpadding="0" cellspacing="0" align="left">
<tr id="header">
<td width="481">
<?php include ('banner.php'); ?>
</td>
<td width="519" align="right">
<?php include ('background.php'); ?>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<table id="main" width="1000" height="333" border="0" cellpadding="0" cellspacing="0" align="left">
<tr>
<td height="331" valign="top" id="leftside"><div class="box1"><?php include'leftmenu.php' ?></div>
</td>
<td valign="top">
<table align="center" >
<tr>
<th scope="row"><font color="#000000" size="2"><strong>Material Request Screen</strong></font></th>
</tr>
</table>
<br />
<fieldset>
<table width="597" border="0" cellspacing="0" cellpadding="0">
<?php
if($valid!='')
{
if($valid=='failure') $Msg = "FAIL";
if($valid=='success') $Msg = "SUCCESS";
if ($valid == 'success')
{
?>
<div align="center" class="<?php echo $Msg;?>" >
<?php echo $MRMessage['WARNNING']["MR".$Msg].", Your Request Number is <strong>".$last_mr_id."</strong>";?></div>
<?php
}
else if ($valid == 'failure')
{
?>
<div align="center" class="<?php echo $Msg;?>" >
<?php echo $MRMessage['WARNNING']["MR".$Msg];?></div>
<?php
}
}
?>
<?php if ($errmsg != '') { ?>
<div align="center" class="FAIL">
<?php echo $errmsg;?>
</div>
<?php } ?>
<tr>

<?php /*?> <td><font size="2">Material Request No</font></td>
<td><input type="text" name="txtMatReqNo" id="txtMatReqNo" value="<?=$row['MRNO']?>" onkeypress="return isNumberKey2(event)" onkeyup="checkForInvalid(this)"></td><?php */?>
<td><font size="2">Transaction Date</font></td>
<td><p><input type="text" name="txtMatReqDate" id="txtMatReqDate" value="<?php echo date('d-m-Y');?>" readonly onclick="alert('Click the image to change Date')">
<a href="javascript:NewCssCal('txtMatReqDate','ddmmyyy','arrow')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></p></td
>
<td><font size="2" color="">Requested By</font></td>
<?php
$qry = "select ASSOCIATEID,ASSOCIATENAME FROM associatemst WHERE STATUS = 1";
$result2 = mysql_query($qry);
?>
<td><p><select name="cmbRequestedBy" readonly style="background-color:
#ababab" onFocus="this.blur(); return false;"> <option>Select Name</option>
<?php

if (mysql_affected_rows()>0)
{
while (list($k,$v) = mysql_fetch_array($result2))
{
$selected = ($current_user_id == $k ) ? ' selected="selected"' : '';
echo "<option value='".$k."' ".$selected."> (Id: $k) ".$v."</option>";
}
}
?>
</select></p> </td>

</tr>
<tr>
<td><font size="2" >Store No&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
<?php
$qry = "select STORENO,STORENAME FROM storemst WHERE STATUS = 1";
$result2 = mysql_query($qry);
?>
<td><select name="cmbStoreID"> <option>Select Name</option>
<?php

if (mysql_affected_rows()>0)
{
while (list($k,$v) = mysql_fetch_array($result2))
{
echo "<option value='".$k."'> (Id: $k) ".$v."</option>";
}
}
?>
</select> </td>
<td><font size="2" >Required At</font></td>
<?php
$qry = "select LOCATIONID,LOCATIONNAME FROM location WHERE STATUS = 1";
$result2 = mysql_query($qry);
?>
<td><p><select name="cmbRequiredAt"> <option>Select Name</option>
<?php

if (mysql_affected_rows()>0)
{
while (list($k,$v) = mysql_fetch_array($result2))
{
echo "<option value='".$k."'> (Id : $k) ".$v."</option>";
}
}
?>
</select></p>
</td>
</tr>
<table width="817">
<tr>
<td width="225"><font size="2">Remarks</font></td>
<td width="651"><input type="text" name="txtRemarks" id="txtRemarks" size="106"value="<?=$row['REMARKS']?>"></td>
<td width="22"><p><input type="hidden" name="hdn_total" id="hdn_total" value="test">
<input type="hidden" value="<?=date('d-m-Y')?>" name="serverdate" id="serverdate"/>
</p></td>
</tr>
</table>
<br />
<table>
<tr>
<td>
<div style="overflow:auto;width:820px;auto;height:280px;border:#E78D2E solid 1px;">
<table width="100%" border="0" id="tableId" cellspacing="0" class='' cellpadding="0">
<tr class="table_heading">
<td width="2%">&nbsp;&nbsp;</td>
<td width="22%">Item Code</td>
<td width="22%">Item Name</td>
<td width="22%">Description</td>
<td width="22%">Unit</td>
<td width="22%">Quantity</td>
</tr>
</table>
<script src="javascripts/dGrid.js"></script>
<script language="javascript">
var itemIDS = new Array();
<?php
$sqlQry2 = "select ITEMCODE from itemmaster";
$getQry2 = mysql_query($sqlQry2);
$count2 = mysql_num_rows($getQry2);
$itr = 0;
while ($rows2 = mysql_fetch_array($getQry2))
{
echo "itemIDS[$itr] = '".$rows2['ITEMCODE']."';\n";
$itr++;
}
?>
var error_onfield = null;


var Fileds = ['ItemCode','ItemName','Description','Unit','Quantity'];
var Functions = ['showItemcode','showItemName',,'checkforerror','isNumberKey'];
//var Fileds = ['ItemCode','ItemName','Description','unit','Quantity'];
//var Functions = ['showItemcode','showItemName','showDescription','showUnit'];
var DefaultRows = 5;
//var UDefaultRows= 1;

var Tbl = new DGrid("tableId", DefaultRows, Fileds, Functions);

function showItemcode(obj){

var RowIndex = obj.id.split('ItemCode');
var fillValue = "ItemName"+RowIndex[1];
var descr = "Description"+RowIndex[1];
var unit = "Unit"+RowIndex[1];
var options ={
script:"autosuggest.php?limit=6&searchby=ITEMCODE,ITEMNAME,DESCRIPTION,UNIT&tablename=itemmaster&orderby=ITEMCODE&",
varname:"input",
json:false,
shownoresults:false,
maxresults:6,
callback: function (obj)
{
document.getElementById(fillValue).value = obj.info;
document.getElementById(descr).value = obj.desc;
document.getElementById(unit).value = obj.unit;
document.getElementById(unit).focus();

}
};

var as_json = new bsn.AutoSuggest(obj.id, options);
//alert(obj.name);
}

function checkforerror()
{
if (error_onfield!= null)
{
error_onfield.focus();
error_onfield = null;
}
}

function showItemName(obj){

var RowIndex = obj.id.split('ItemName');
var fillValue = "ItemCode"+RowIndex[1];
var descr = "Description"+RowIndex[1];
var unit = "Unit"+RowIndex[1];
var options ={
script:"autosuggest.php?limit=6&searchby=ITEMNAME,ITEMCODE,DESCRIPTION,UNIT&tablename=itemmaster&orderby=ITEMCODE&",
varname:"input",
json:false,
shownoresults:false,
maxresults:6,
callback: function (obj)
{
document.getElementById(fillValue).value = obj.info;
document.getElementById(descr).value = obj.desc;
document.getElementById(unit).value = obj.unit;
document.getElementById(unit).focus();

}
};

var as_json = new bsn.AutoSuggest(obj.id, options);
//alert(obj.name);
}
</script>

</div>



<table align="center">
<tr>
<td width="1%"><div name="addtoGrid" title="Add New Row" onclick="javascriptGrid.addToGrid(UDefaultRows);" id="addtoGrid2" value="Add Row"><a class="actions"><img src="images/addrow.jpg" width="20" height="20"></a></div></td>

<td width="9%"><div name="addtoGrid" title="Add New Row" onclick="javascriptGrid.addToGrid(UDefaultRows);" id="addtoGrid2" value="Add Row">
<a class="actions">Add Row</a></div></td>
<td width="1%"><div onclick="validateForm();" title="Raise Material Request"><a class="actions"><img src="images/add.jpg" width="20" height="20"></a></div></td>
<td width="15%"><div onclick="validateForm();" title="Raise Material Request"><a class="actions">Raise Request</a></div></td>
<td width="1%"><div onClick="editpirForm()" title="Edit a Material Request"><a class="actions"><img src="images/edit.jpg" width="20" height="20"></a></div></td>
<td width="8%"><div onClick="editpirForm()" title="Edit a Material Request"><a class="actions">Edit</a></div></td>
<td width="1%"><div title="Close this Screen"><a class="actions"><img src="images/close.jpg" width="20" height="20"></a></div></td>
<td><div width="73%" title="Close this Screen"><a class="actions">Close</a></div></td>
</tr>
</table>
</td>
</tr>

</table>

</table>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><?php include'footer.php' ?></td>
</tr>
</table>

</div>
</form>
</body>
</html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sen1978 is offline Offline
1 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: LaTex::parser module problem
Next Thread in Perl Forum Timeline: variable concat and exec cmd question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC