What this form will eventually do is create a SQL code to add and update documents to our intranet. I want to be able to fill the form before the submit button. The submit button is function updateFILE(). The table that is being displayed with the data is in a hidden div the function gtdoc() is just checking to see if the radio button is checked and then displaying the div. In order the while loop is called but inside a hidden div, there is a text box that onChange will appear after its searches the table that the while loop has formed. Then it will create the sql code from the selected values.
HTML Code:
<script>
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#kwd_search").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#my-table tbody>tr").hide();
$("#my-table td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#my-table tbody>tr").hide();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
function showdoc()
{
document.getElementById("HiddenDoc").style.display = 'block';
}
function gtdoc()
{
for(var i=0; i < document.myform.tog.length; i++)
{
if(document.myform.tog[i].checked)
{
document.getElementById("HiddenDoc2").style.display = 'block'
}
}
}
function updateFILE() {
sCode = document.myform.sqlCode.value;
iFileID = document.myform.DocFileID.value;
iObjectID = document.myform.DocID.value;
iCurrentVersion = document.myform.CurrVer.value;
iFileName = document.myform.DocFileName.value;
iObjectName = document.myform.DocName.Value
iDashPosition = iFileName.search( "-" + iFileID);
iDatePosition = iDashPosition - 8;
iDotsPosition = iDashPosition + iFileID.length + 1;
iDateYYYYMMDD = document.myform.DateValue.value;
iDateYYYYMMDD = iDateYYYYMMDD.replace(/-/g, "");
iFileName = iFileName.substring(0, iDatePosition) + iDateYYYYMMDD + "-" + document.myform.NextFileIndex.value + iFileName.substring(iDotsPosition, iFileName.length);
document.myform.RevisedFileName.value = iFileName;
sCode = sCode + "UPDATE `iDocuments`.`File` SET `FileStatus` = '0' WHERE `FileIndex` = ' " + iFileID + "'; ";
sCode = sCode + "INSERT INTO `iDocuments`.`File` (`FileIndex`, `FileStatus`, `FileName`, `FileDesc`, `UploadDate`, `UploadTime`, `UploadUserID`) VALUES (' " + document.myform.NextFileIndex.value + "', '1', ' " + iFileName + "', '', ' " + document.myform.DateValue.value + "', '12:00:00', '1'); ";
sCode = sCode + "INSERT INTO `iDocuments`.`Version` (`Index`, `ObjectIndex`, `Version`, `FileIndex`) VALUES ('', ' " + iObjectID + "', ' " + iCurrentVersion.toString() + "', ' " + document.myform.NextFileIndex.value + "'); ";
sCode = sCode + "INSERT INTO `iUpdates`.`Updates` (`UpdateID`, `UpdateDate`, `InputDateTime`, `InputUserID`, `InputUserName`, `UpdateTitle`, `UpdateText`, `LinkURL`, `LinkWindowID`) VALUES ('', ' " + document.myform.DateValue.value + "', ' " + document.myform.DateValue.value + " 12:00:00', '2', ' " + document.myform.WindowsUser.value + "', ' " + iObjectName + "', '', 'download.php?object= " + iObjectID + "', '2'); ";
sCode = sCode + " \n ";
sCode = sCode + " \n ";
document.myform.sqlCode.value = sCode;
iNextFileID = document.myform.NextFileIndex.value * 1;
iNextFileID++;
document.myform.NextFileIndex.value = iNextFileID.toString(); }
</script>
<body>
<form name="myform" actiopn="<?php $_PHP_SELF ?>" method="get">
<table width='100%'>
<tr>
<td>DATE</td>
<td>USER</td>
<td>File</td>
<td>Object</td>
<td>Next ID</td>
<td>New File Name</td>
</tr>
<tr>
<td><input type="text" name="DateValue" value="" size=10 readonly="true"></input></td>
<td><input type="text" name="WindowsUser" value="" size=12></input></td>
<td><input type="text" name="NextFileIndex" value="<?php echo $row2[0]; ?>" size=5 readonly="true"></input></td>
<td><input type="text" name="NextObjectIndex" value="<?php echo $row3[0]; ?>" size=5 readonly="true"></input></td>
<td><input type="text" name="UniqueObjects" value="<?php echo $row6[0]; ?>" size=5 readonly="true"></input></td>
<td><input type="text" name="RevisedFileName" value="" size=130 readonly="true"></input></td>
</tr>
</table>
<textarea name="sqlCode" value="" rows="5" cols="100" wrap="soft" readonly="true"></textarea>
<label for="kwd_search">Search:</label>
<input type="text" id="kwd_search" onChange="showdoc();" value=""/>
<div id="HiddenDoc" style="display:none;">
<table id="my-table"><tr><textarea name="showit" id="showit" value=""></textarea>
<?php
while( $row1 = mysql_fetch_array($myQ1) )
{
echo "<td><input type='radio' name='tog' id='tog' onClick='gtdoc()' value='$row1[2]'>$row1[3]</input></td></tr>";
}
?>
</table>
</div>
PHP Code:
<div id="HiddenDoc2" style="display:none;">
<?php
foreach($tog as $ObjIndex) {
$myQ7 = mysql_query("SELECT DISTINCT `iIndex`.`TypeDef`.`Name` FROM `iIndex`.`TypeIndex` JOIN `iIndex`.`TypeDef` ON `iIndex`.`TypeDef`.`Index` = `iIndex`.`TypeIndex`.`TypeID` WHERE `iIndex`.`TypeIndex`.`ObjIndex` = '$ObjIndex' ");
$myQ8 = mysql_query("SELECT DISTINCT `iIndex`.`TopicDef`.`Name` FROM `iIndex`.`TopicIndex` JOIN `iIndex`.`TopicDef` ON `iIndex`.`TopicDef`.`Index` = `iIndex`.`TopicIndex`.`TopicID` WHERE `iIndex`.`TopicIndex`.`ObjIndex` = '$ObjIndex' ");
$myQ9 = mysql_query("SELECT `iDocuments`.`File`.`FileIndex`, `iDocuments`.`File`.`FileName`, `iDocuments`.`Object`.`ObjectIndex`, `iDocuments`.`Object`.`ObjectName`, `iDocuments`.`Version`.`Version`, `iDocuments`.`File`.`UploadDate` FROM `iDocuments`.`Version` INNER JOIN `iDocuments`.`Object` ON `iDocuments`.`Object`.`ObjectIndex` = `iDocuments`.`Version`.`ObjectIndex` JOIN `iDocuments`.`File` ON `iDocuments`.`Version`.`FileIndex` = `iDocuments`.`File`.`FileIndex` WHERE `Object`.`ObjectStatus` = '1' AND `Version`.`Version` = ( SELECT MAX(`Version`) FROM `iDocuments`.`Version` WHERE `Version`.`ObjectIndex` = `Object`.`ObjectIndex` ) AND `Object`.`ObjectIndex` = '$ObjIndex'");
if (!$myQ7)
{
echo 'Could not run query 7: ' . mysql_error();
}
if (!$myQ8)
{
echo 'Could not run query 8: ' . mysql_error();
}
if (!$myQ9)
{
echo 'Could not run query 9: ' . mysql_error();
}
else
{
$row7 = mysql_query($myQ7);
$row8 = mysql_query($myQ8);
$row9 = mysql_query($myQ9);
$aID = 0;
}
while( $row9 = mysql_fetch_array($myQ9) )
{
echo "<table name='doclist'>
<tr><td>FileID</td><td><input name='DocFileID' type='text' readonly='true' value='$row9[0]'></input></td></tr>
<tr><td>File Name</td><td><input name='DocFileName' type='text' readonly='true' value='$row9[1]'></input></td></tr>
<tr><td>ObjectID</td><td><input name='DocID' type='text' readonly='true' value='$row9[2]'></input></td></tr>
<tr><td>Object Name</td><td><input name='DocName' type='text' readonly='true' value='$row9[3]'></input></td></tr>
<tr><td>Current Version</td><td><input name='CurrVer' type='text' readonly='true' value='$row9[4]'></input></td></tr>
<tr><td>Update Date</td><td><input name='lstupdate' type='text' readonly='true' value='$row9[5]'></input></td> </tr>
</table>";
}
while( $row8 = mysql_fetch_array($myQ8) )
{
echo "<input type='checkbox' name='topicdef'>$row8[0]</input>";
}
while( $row7 = mysql_fetch_array($myQ7) )
{
echo $row7[0];
}
}
?>
</div>
<input type="button" value="SUBMIT FOR APPROVAL" onClick="updateFILE()"/></input> </br>
</div>
</body>
Bookmarks