<?
/-----------------------------------------------------------------------------------------------------
Purpose: The user can add new sections for the
-----------------------------------------------------------------------------------------------------/
session_start();
header("Cache-control: private"); // IE6 fix
include ($DOCUMENT_ROOT."/mySQL_config.php");
include ($DOCUMENT_ROOT."/functions.php");
include ($DOCUMENT_ROOT."/config.php");
check_admin();
$FilePath = $_SERVER['DOCUMENT_ROOT']."/employee/materials/training/files/";
//if we have a file ID then we're updating a record.
if (isset($Submit)) {
// if we're updating, we don't need to upload a new file.
if(!empty($DocID)) {
//if any of these fields are empty, then we cannot continue
if(empty($DocName) || empty($SectionID)) {
$msg = 'One or more fields were left blank. Please review the information you have entered and resubmit.';
} else {
// update the record
$upd_query = "UPDATE materials_training
SET DocName = '".$DocName."',
SectionID = '".$SectionID."'
WHERE DocID = ".$DocID;
$result = mysql_query($upd_query) or die("The database was not successfully updated. <br><br> Query: ".$upd_query);
}
} else {
//if any of these fields are empty, then we cannot continue
if(empty($DocName) || empty($SectionID) || empty($UserFile)) {
$msg = 'One or more fields were left blank. Please review the information you have entered and resubmit.';
} else {
// move our uploaded file
$SearchChar = array(" ", "'", "@", "#", "$", "&", "*");
$filename = str_replace($SearchChar,"_",$HTTP_POST_FILES['UserFile']['name']);
if (move_uploaded_file($_FILES['UserFile']['tmp_name'], $FilePath.$filename)) {
// insert record into DB
$query = "INSERT INTO materials_training (DocName, SectionID, Filename) VALUES ('".$DocName."', '".$SectionID."', '".$filename."')";
$result = mysql_query($query);
$msg = "Your file has been uploaded successfully.";
} else {
$msg = "There was a problem uploadinig your file.";
}
}
}
}
if (!empty($DocID)) {
$query = "SELECT * FROM materials_training WHERE DocID = ".$DocID;
$result = mysql_query($query);
$result_ar = mysql_fetch_assoc($result);
}
// header("Location: index.php?curSection=7&curPage=5");
?>
<HTML>
<HEAD>
<? include($DOCUMENT_ROOT."/meta.php"); ?>
<link href="/quantum.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY background="http://www.quantumhp.com/images/pattern_leaves_tan.gif" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<table width="95%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="page_border">
<tr>
<td height="91" align="right" bgcolor="#64211f"><img src="/images/splash_logo.gif" width="734" height="91"></td>
</tr>
<tr>
<td class="top_menu_shell" height="26" align="left" valign="middle" nowrap bgcolor="#000000"><? include($_SERVER['DOCUMENT_ROOT'].'/top_menu.php'); ?></td>
</tr>
<tr>
<td height="88" bgcolor="#000000" class="photo_border"><img src="/images/sample-photo02.gif" alt="" width="740" height="88"></td>
</tr>
<tr>
<td valign="top">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="231" valign="top" background="/images/pattern_leaves_brown.gif"><? include("include_Menu.php"); ?></td>
<td valign="top"><br>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="26" class="title-bold">ADD <span class="title-italic">document</span> </td>
</tr>
<tr>
<td align="center" class="content-body">
<br><blockquote><p align="left" class="error"><? echo $Msg; unset($Msg);?></p></blockquote><br>
<form action="<? echo $PHP_SELF."?curPage=4&curSection=7&DocID=".$DocID; ?>" method="post" enctype="multipart/form-data" name="form1">
<table border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="right" width="138" class="form-fieldLabels">Document Name: </td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="40000000" /><input name="DocName" type="text" id="keyword_input" value="<? echo $result_ar['DocName']; ?>" size="35" maxlength="120"></td>
</tr>
<tr>
<td align="right" class="form-fieldLabels">Section: </td>
<td><select name="SectionID" id="SectionID">
<?
//Query database for a list of all sections
$opt_query = "SELECT * FROM materials_training_sections WHERE SectionID > 0 ORDER BY SectionName";
$opt_result = mysql_query($opt_query);
while ( $opt_result_ar=mysql_fetch_assoc($opt_result) ) {
if ($opt_result_ar['SectionID'] == $result_ar['SectionID']) {
print '<option selected value='.$opt_result_ar['SectionID'].'>'.$opt_result_ar['SectionName'].'</option>';
} else {
print '<option value='.$opt_result_ar['SectionID'].'>'.$opt_result_ar['SectionName'].'</option>';
}
}
?>
</select></td>
</tr>
<? if(empty($DocID)) { ?>
<tr>
<td align="right" class="form-fieldLabels">File: * </td>
<td><input name="UserFile" type="file" id="UserFile"></td>
</tr>
<? } ?>
<tr>
<td> </td>
<td align="right"> </td>
</tr>
<tr>
<td> </td>
<td align="right"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
<p align="center" class="form-fieldLabels">* - Required Fields</p>
</form>
<script type="text/javascript">
document.form1.SectionName.focus();
</script>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="35" valign="middle" align="center" bgcolor="#64211f"><? include($DOCUMENT_ROOT."/footer.php");?></td>
</tr>
</table>
</BODY>
</HTML>
<? mysql_close($connection); ?>