Jump to content

Recommended Posts

<?php
$previous = "javascript:history.go(-1)";
if(isset($_SERVER['HTTP_REFERER'])) {
    $previous = $_SERVER['HTTP_REFERER'];
}

error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Connect to SQL Server database
include("connections/Connect.php");


	$strsID = null;

	if(isset($_GET["Id"]))
	{
		$strsID = $_GET["Id"];
	}

	$stmts = "SELECT b.AliasID,b.BidStatus,BidID,BidIDFile,Notes,AwardRecip1,
			ContactEmail,ContactPhone,TabSheet,SignInSheet,BidContact,Addend1,
			Addend2,Addend3,Addend4,Addend5, CONVERT(VARCHAR(11), BidDate, 106) BidDate,
			CONVERT(VARCHAR(11), DueDate, 106) DueDate,BidTitle,Description,DueTime,BidID,
			d.DeptName,BidType,cat.CategoryID, t.TeamID,
			CASE WHEN AwardDate ='01/01/1900' Then NULL ELSe CONVERT(VARCHAR(11), AwardDate, 106) END AS AwardDate,
			CONVERT(VARCHAR(11), LastUpdate, 106) LastUpdate,s.Status
			FROM bids b inner join DeptALIAS da on b.AliasID = da.AliasID
			left join Categories cat on b.CategoryID = cat.CategoryID left join Teams t on b.TeamID = t.TeamID
 			inner join Dept d on da.DeptCode =d.DeptCode inner join Status s on b.BidStatus=s.StatusId
 			WHERE ID = ? ";
//	echo $stmt;
	$params = array($strsID);

	$querys = sqlsrv_query( $conn, $stmts, $params);

			while($row = sqlsrv_fetch_array($querys,SQLSRV_FETCH_ASSOC))
			{
			    $iStatus = $row["BidStatus"];
				$iType = $row["BidType"];
				$depts = $row["AliasID"];
				$teams = $row["TeamID"];
				$cats = $row["CategoryID"];
			}

?>
<?php

	$strbidID = null;

	if(isset($_GET["Id"]))
	{
		$strbidID = $_GET["Id"];
	}

	$stmt = "SELECT BidID,BidIDFile,Notes,AwardRecip1,ContactEmail,ContactPhone,TabSheet,SignInSheet,BidContact,Addend1,Addend2,Addend3,Addend4,Addend5, CONVERT(VARCHAR(11), BidDate, 106) BidDate,CONVERT(VARCHAR(11), DueDate, 106) DueDate,BidTitle,Description,DueTime,BidID,d.DeptName,BidType,CASE WHEN AwardDate ='01/01/1900' Then NULL ELSe CONVERT(VARCHAR(11), AwardDate, 106) END AS AwardDate,CONVERT(VARCHAR(11), LastUpdate, 106) LastUpdate,s.Status  FROM bids b inner join DeptALIAS da on b.AliasID = da.AliasID inner join Dept d on da.DeptCode =d.DeptCode inner join Status s on b.BidStatus=s.StatusId WHERE ID = ? ";
//	echo $stmt;
	$params = array($strbidID);

	$query = sqlsrv_query( $conn, $stmt, $params);

	$result = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);

?>
<table class="main_table" cellpadding="10">
<tr>
<td valign="top">
<h3 class="onlyscreen" align="center"><b>Fulton County Bid Administration</b></h3>
<div class="style1">
<br>
</div>
<b><h3>Update an existing bid or quote</h3></b>
 <form id="form1" name="form1" method="POST" action="UpdateAndInsert.php" enctype="multipart/form-data">
 <input type="hidden" name="Id" value="<?php echo $strbidID;?>">
<table>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Issue Date </td>
      </tr>
     </table></td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text">
        <input type="text" name="txtBidDate" Id="txtBidDate" value="<?php echo $result["BidDate"];?>" style="width:150px;"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Due Date </td>
      </tr>
     </table></td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text">
        <input type="text" name="txtDueDate" Id="txtDueDate" value="<?php echo $result["DueDate"];?>" style="width:150px;"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">DueTime </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text">
       <input type="text" name="txtDueTime" Id="txtDueTime" maxlength="100" value="<?php echo $result["DueTime"];?>" style="width:151px;"></div></td>
       <td class="td_hint_form">
       </td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Project Title </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><div class="input text">
       <input type="text" name="BidTitle" style="width:430px;" maxlength="100" value="<?php echo $result["BidTitle"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*ID </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text">
       <input type="text" name="BidID" maxlength="100" value="<?php echo $result["BidID"];?>" style="width:150px;"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
 <tr>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_label_form">*Category </td>
    </tr>
   </table>
  </td>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_null_checkbox_form"></td>
    </tr>
   </table>
  </td>
  <td>
   <table border="0">
    <tr>
     <td class="td_input_form">
     <select name="CategoryID" Id="CategoryID" data-placeholder="Select category..." class="chosen-select" style="width:178px;">
     <option value=""></option>
  			<?php
			$tsql = "SELECT CategoryID, Category FROM Categories ORDER BY Category ASC";
			$stmt = sqlsrv_query( $conn, $tsql);
			while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
			{
				$strCats = $row["CategoryID"];
				if($strCats == $cats)
				{
					$sel = 'selected="selected"';
     			}
				else
				{
					$sel = "";
				}
			?>
			<option value="<?php echo $row["CategoryID"];?>" <?php echo $sel;?>><?php echo $row["Category"];?></option>
			<?php
			}
			?>
		 </select></td>
     <td class="td_hint_form"></td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_label_form">*Team </td>
    </tr>
   </table>
  </td>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_null_checkbox_form"></td>
    </tr>
   </table>
  </td>
  <td>
   <table border="0">
    <tr>
     <td class="td_input_form">
     <select name="TeamID" Id="TeamID" data-placeholder="Select team..." class="chosen-select" style="width:178px;">
     <option value=""></option>
  			<?php
			$tsql = "SELECT TeamID, Team FROM Teams ORDER BY Team ASC";
			$stmt = sqlsrv_query( $conn, $tsql);
			while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
			{
				$strTeam = $row["TeamID"];
				if($strTeam == $teams)
				{
					$sel = 'selected="selected"';
     			}
				else
				{
					$sel = "";
				}
			?>
			<option value="<?php echo $row["TeamID"];?>" <?php echo $sel;?>><?php echo $row["Team"];?></option>
			<?php
			}
			?>
		 </select></td>
     <td class="td_hint_form"></td>
    </tr>
   </table>
  </td>
 </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Description </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input textarea">
       <textarea cols="50" style="width:430px;" name="Description"><?php echo $result["Description"];?></textarea></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Bid File </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="BidIDFile[]" size="50"></td>
       <td class="td_hint_form"> </td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 1 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 2 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 3 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 4 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <tdclass="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 5 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Addendum 6 </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="item[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Department </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
        <select name="AliasID"  data-placeholder="Select department..." class="chosen-select" style="width:178px;">
        <option value=""></option>
  			<?php
			$tsql = "SELECT distinct da.AliasID, d.DeptName FROM DeptALIAS da inner join Dept d on da.DeptCode =d.DeptCode ORDER BY 1 ASC";
			$stmt = sqlsrv_query( $conn, $tsql);
			while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
			{
				$strDefault = $row["AliasID"];
				if($strDefault == $depts)
				{
					$sel = 'selected="selected"';
     			}
				else
				{
					$sel = "";
				}
			?>
			<option value="<?php echo $row["AliasID"];?>" <?php echo $sel;?>><?php echo $row["DeptName"];?></option>
			<?php
			}
			?>
		 </select></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">SignInSheet </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="SignInSheet[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Bid Contact </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><div class="input text">
       <input type="text" name="BidContact" style="width:330px;" maxlength="100" value="<?php echo $result["BidContact"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*Contact Email </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><div class="input text">
       <input type="text" name="ContactEmail" style="width:330px;" maxlength="100" value="<?php echo $result["ContactEmail"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Contact Phone </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text"><input type="text" style="width:150px;" name="ContactPhone" maxlength="100" value="<?php echo $result["ContactPhone"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Number of Bids Received </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text"><input type="text" style="width:150px;" name="NumofBids" maxlength="100" value="<?php echo $result["NumofBids"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Tabulation Sheet </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="TabSheet[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Award Date </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
       <div class="input text">
        <input type="text" name="txtAwardDate" Id="txtAwardDate" style="width:150px;" value="<?php echo $result["AwardDate"];?>"></div></td>
        <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Award Recipient(s) </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><div class="input text">
       <input type="text" name="AwardRecip1" style="width:330px;" maxlength="100" value="<?php echo $result["AwardRecip1"];?>"></div></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">Executed Contract </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form"><input type="file" name="Xcontract[]" size="50"></td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">*BidType </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"></td>
      </tr>
     </table>
    </td>
    <td>
     <table border="0">
      <tr>
       <td class="td_input_form">
        <select name="BidType"  data-placeholder="Select type..." class="chosen-select" style="width:178px;">
         <option value=""></option>
			<?php
			$tsql = "SELECT DISTINCT BidType FROM bids ORDER BY 1 ASC";
			$stmt = sqlsrv_query( $conn, $tsql);
			while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
			{
				$strDefault = $row["BidType"];
				if($strDefault == $iType)
				{
					$sel = 'selected="selected"';
     			}
				else
				{
					$sel = "";
				}
			?>
			<option value="<?php echo $row["BidType"];?>" <?php echo $sel;?>><?php echo $row["BidType"];?></option>
			<?php
			}
			?>
		  </select>
        </td>
       <td class="td_hint_form"></td>
      </tr>
     </table>
    </td>
   </tr>
   <tr>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_label_form">LastUpdate </td>
      </tr>
     </table>
    </td>
    <td align="right" valign="top">
     <table>
      <tr>
       <td class="td_null_checkbox_form"> </td>
      </tr>
     </table>
    </td>
    <td><table border="0">
     <tr>
      <td class="td_input_form"><div class="input text">
      <input type="text" name="txtLastUpdate" Id="txtLastUpdate" style="width:150px;" value="<?php echo $result["LastUpdate"];?>"></div></td>
      <td class="td_hint_form"></td>
     </tr>
    </table>
   </td>
  </tr>
  <tr>
   <td align="right" valign="top">
    <table>
     <tr>
      <td class="td_label_form">Notes </td>
     </tr>
    </table>
   </td>
   <td align="right" valign="top">
    <table>
     <tr>
      <td class="td_null_checkbox_form"> </td>
     </tr>
    </table>
   </td>
   <td><table border="0">
    <tr>
     <td class="td_input_form"><div class="input textarea">
     <textarea cols="50" style="width:430px;" name="Notes"><?php echo $result["Notes"];?></textarea></div></td>
     <td class="td_hint_form"></td>
    </tr>
   </table>
  </td>
 </tr>
 <tr>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_label_form">*Status </td>
    </tr>
   </table>
  </td>
  <td align="right" valign="top">
   <table>
    <tr>
     <td class="td_null_checkbox_form"></td>
    </tr>
   </table>
  </td>
  <td>
   <table border="0">
    <tr>
     <td class="td_input_form">
		  <select name="BidStatus" data-placeholder="Select status..." class="chosen-select" style="width:178px;">
            <option value=""></option>
			<?php
			$tsql = "SELECT DISTINCT s.StatusID, s.Status FROM status s inner join bids b on s.StatusID = b.BidStatus";
			$stmt = sqlsrv_query( $conn, $tsql);
			while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
			{
				$strDefault = $row["StatusID"];
				if($strDefault == $iStatus)
				{
					$sel = 'selected="selected"';
     			}
				else
				{
					$sel = "";
				}
			?>
			<option value="<?php echo $row["StatusID"];?>" <?php echo $sel;?>><?php echo $row["Status"];?></option>
			<?php
			}
			?>
		  </select> </td>
     <td class="td_hint_form"></td>
    </tr>
   </table>
  </td>
 </tr>
 </table>
 <div align="center">
 <table>
 <tr>
  <td class="tr_button_form"><input type="submit" class="button_form" value="Update a bid or quote"></td>
 </tr>
</table></div>
</form>

Hello experts,

 

Please forgive me as this code is very long. I didn't want to miss providing the important you may need to assist.

 

On the code posted above, a user can upload up to 10 different pdf files to the server.

 

The filename associated with each uploaded file is saved to the database.

 

This is how the uploaded file can be related to the filename on the database.

 

This works fine.

 

Issue I am faced with is how to delete (unlink) the filename on the server.

 

I will like each file upload box to have the unlink bit next to it.

 

This way, the unlink is only is only visible when there is an uploaded file.

 

I have been struggling for days now trying to figure out where to add the markup next to each file.

 

Any assistance is greatly appreciated.

 

That's a lot of code to wade through, but here's how I'd generally do it:

 

1) form is sent

2) data is validated, images saved, etc

3) Reshow form with data

3a) When generating the FILE inputs, if one has a file already uploaded, don't show the FILE input for that one. Instead show a checkbox to delete the file and show the filename.

 

So if 3 pdf's/whatever were uploaded, the first 3 spots where you'd normally see the upload button would instead have a checkbox. The other remaining 7 inputs would show the upload.

 

Checking some or all of the checkboxes and resubmitting the form would delete/unlink() those files during step #1 above, and when the form is redisplayed, the upload slots would show up again in their place.

Edited by CroNiX

First, sorry (again) for the long code.

 

Sometimes, trying to show relevant code, you end up missing the really relevant code.

 

What you described is exactly what I am trying to do and I know that using unlink is the way to go but I am just not sure *where* to place the code given the code I showed above.

 

Any additional help is greatly appreciated.

Ok looking at your code I assume only the file paths are stored in the following fields?

BidIDFile     <--- stores the filepath for BidFile 	
TabSheet      <---    "    "     "      "  TabSheet	
SignInSheet   <---    "    "     "      "  SignIn Sheet
Addend1       <---    "    "     "      "  Addendum 1 
Addend2       <---    "    "     "      "      "	2 
Addend3       <---    "    "     "      "      "	3 
Addend4       <---    "    "     "      "      "	4 
Addend5       <---    "    "     "      "      "	5 

I couldn't find what fields stores the filepath for the form fields labelled Addendum 6 and Executed Contract in your form?

 

 

I wont post the code for all 10 fields in your form. I will show an example for the Bid File field.

       <td class="td_input_form"><input type="file" name="BidIDFile[]" size="50"></td> 

Change the Bid File upload field (shown above) to to this

       <td class="td_input_form">
        <?php 
        // if the BidIDFile is empty, 
        if(empty($result["BidIDFile"]))
        {
            //then show file upload field for Bid File
            echo '<input type="file" name="BidIDFile[]" size="50">';
        }
        else
        {
            // Bid file already upload, show checkbox to delete it. 
            echo '<input type="checkbox" name="delete[]" value="BidIDFile"> Delete ' . $result["BidIDFile"];
        }
        ?>
       </td>

This will show the file upload field if a Bid File has not been uploaded (the BidIDFile column is empty in the table row). If there is a value then it will show a checkbox for deleting the file.

 

You will apply this code logic for the remaining upload fields. Changing BidIDFile to the corresponding column in your table for each field.

 

To delete the file you need to loop over $_POST['delete'] array when the form has been deleted. This array contains the table columns for each uploaded files. You would perform a select query to get the file paths from these columns in your table. From the result of the query you would pass each file path to unlink to delete the file. Then to remove the file paths from the table you would run an update query setting the columns to an empty value. Example code

// Connect to SQL Server database
include("connections/Connect.php");

$strsID = isset($_GET["Id"]) ? $_GET["Id"] : null;

if(isset($_POST['delete']))
{
    // whilelisted table columns
    $fileColumnsInTable = array( 'BidIDFile', 'TabSheet', 'SignInSheet', 'XConnect',
                                 'Addend1', 'Addend2','Addend3','Addend4','Addend5', 'Addend6');

    $fileColumns = array();
    foreach ($_POST['delete'] as $fileColumn)
    {
        if(in_array($fileColumn, $fileColumnsInTable))
            $fileColumns[] = $fileColumn;
    }

    // get the file paths for each file to be deleted
    $stmts = "SELECT " . implode(', ', $fileColumns) . " FROM bids WHERE ID = ? ";
    $querys = sqlsrv_query( $conn, $stmts, array($strsID));
    $files = sqlsrv_fetch_array($querys,SQLSRV_FETCH_ROW);
    
    // loop over the files returned by the query
    foreach ($files as $file )
    {
        //delete file
        unlink($file);
    }

    // now remove the values from the table
    $stmts = "UPDATE bids SET " . impload(' = '', ', $fields) . " WHERE ID = ? ";
    $querys = sqlsrv_query( $conn, $stmts, array($strsID));
}
    <a href="http://uploads/<?php echo $result["Addend4"]; ?>" target="_blank" onclick="window.open (this.href, 'child', 'height=800,width=850,scrollbars'); return false" type="application/octet-stream"><?php echo $result["Addend4"];?></a>

Man, if this works, I owe YOU my life.

 

I have been working on this for days and I am supposed to give progress status on Monday during a meeting.

 

To answer your question as to whether path to the PDF files are stored on the DB, the answer is no.

 

Each is linked to the pdf file by fieldname. Above shows how each is linked.

 

This is just one:

 

 

 

Be back shortly with feedback...

 

Thank you so much

Delete ' . $result["BidIDFile"];
<a href="http://uploads/<?php echo $result["BidFile"]; ?>" target="_blank" onclick="window.open (this.href, 'child', 'height=800,width=850,scrollbars'); return false" type="application/octet-stream"><?php echo $result["Addend4"];?></a>

Hi again,

 

How do I convert this part from your solution to link above?

Not quite understanding you. I guess you want to replace the   Delete ' . $result["BidIDFile"];   after the checkbox with your link?

 

You can replace the checkbox line with this

            echo '<input type="checkbox" name="delete[]" value="BidIDFile">
            <a href="http://uploads/'.$result["BidFile"].'" target="_blank" onclick="window.open (this.href, \'child\', \'height=800,width=850,scrollbars\'); return false" type="application/octet-stream">'.$result["Addend4"].'</a>';
<?php
error_reporting(E_ALL);

class	ProcessBid
	{
		public		$data;
		public		$statement;
		public		$where_vals;

		protected	$keyname;
		protected	$conn;

		public	function __construct($conn = false)
			{
				$this->conn	=	$conn;
			}

		public	function SaveData($request = array(),$skip = false,$keyname = 'post')
			{
				$this->keyname				=	$keyname;
				$this->data[$this->keyname]	=	$this->FilterRequest($request,$skip);

				return $this;
			}

		public	function FilterRequest($request = array(), $skip = false)
			{
				// See how many post variables are being sent
				if(count($request) > 0) {
						// Loop through post
						foreach($request as $key => $value) {
								// Use the skip
								if($skip == false || (is_array($skip) && !in_array($key,$skip))) {
										// Create insert values
										$vals['vals'][]   =   "'".ms_escape_string($value)."'";

										// Create insert columns
										$vals['cols'][]   =   "".str_replace("txt","",$key)."";

										// For good measure, create an update string
										$vals['update'][] =   "".str_replace("txt","",$key)."".' = '."'".ms_escape_string($value)."'";

										// For modern day binding, you can use this array
										$vals['bind']['cols'][]           =   "".$key."";
										$vals['bind']['cols_bind'][]      =   ":".$key;
										$vals['bind']['vals'][":".$key]   =   $value;
										$vals['bind']['update'][]         =   "".$key.' = :'.$key;
									}
							}
					}

				return (isset($vals))? $vals:false;
			}

		public	function AddFiles($name = 'item')
			{
				// If the files array has been set
				if(isset($_FILES[$name]['name']) && !empty($_FILES[$name]['name'])) {

						// Remove empties
						$_FILES[$name]['name']      =   array_filter($_FILES[$name]['name']);
						$_FILES[$name]['type']      =   array_filter($_FILES[$name]['type']);
						$_FILES[$name]['size']      =   array_filter($_FILES[$name]['size']);
						$_FILES[$name]['tmp_name']  =   array_filter($_FILES[$name]['tmp_name']);

						// we need to differentiate our type array names
						$use_name   =   ($name == 'item')? 'Addend':$name;
						// To start at Addend1, create an $a value of 1

						$a = 1;
						if(!empty($_FILES[$name]['tmp_name'])) {

								 foreach($_FILES[$name]['name'] as $i => $value ) {
										$file_name  =   ms_escape_string($_FILES[$name]['name'][$i]);
										$file_size  =   $_FILES[$name]['size'][$i];
										$file_tmp   =   $_FILES[$name]['tmp_name'][$i];
										$file_type  =   $_FILES[$name]['type'][$i];

										if(move_uploaded_file($_FILES[$name]['tmp_name'][$i], $this->target.$file_name)) {
												// Format the key values for addendum
												if($name == 'item')
													$arr[$use_name.$a]      =   $file_name;
												// Format the key values for others
												else
													$arr[$use_name] =   $file_name;

												$sql	=   $this->FilterRequest($arr);

												// Auto increment the $a value
												$a++;
											}
									}
							}
					}

				if(isset($sql) && (isset($i) && $i == (count($_FILES[$name]['tmp_name'])-1)))
					$this->data[$name]	=	$sql;

				return $this;
			}

		public	function SaveFolder($target = '../uploads/')
			{
				$this->target	=	$target;

				// Makes the folder if not already made.
				if(!is_dir($this->target))
					mkdir($this->target,0755,true);

				return $this;
			}

		public	function where($array = array())
			{
				$this->where_vals	=	NULL;

				if(is_array($array) && !empty($array)) {
						foreach($array as $key => $value) {
								$this->where_vals[]	=	$key." = '".ms_escape_string($value)."'";
							}
					}

				return $this;
			}

		public	function UpdateQuery()
			{
				$this->data			=	array_filter($this->data);

				if(empty($this->data)) {
						$this->statement	=	false;
						return $this;
					}

				if(isset($this->data) && !empty($this->data)) {

						foreach($this->data as $name => $arr) {
								$update[] =   implode(",",$arr['update']);
							}
					}

				$vars		=	(isset($update) && is_array($update))? implode(",",$update):"";

				// Check that both columns and values are set
				$this->statement	=	(isset($update) && !empty($update))? "update bids set ".implode(",",$update):false;

				if(isset($this->where_vals) && !empty($this->where_vals)) {
						$this->statement	.=	" where ".implode(" and ",$this->where_vals);
					}

				return $this;
			}

		public	function SelectQuery($select = "*",$table = 'bids')
			{
				$stmt				=	(is_array($select) && !empty($select))? implode(",",$select):$select;

				$this->statement	=	"select ".$stmt." from ".$table;

				return $this;
			}

		public	function InsertQuery($table = 'bids')
			{
				$this->data			=	array_filter($this->data);

				if(empty($this->data)) {
						$this->statement	=	false;
						return $this;
					}

				$this->statement	=	"insert into ".$table;

				if(isset($this->data) && !empty($this->data)) {

						foreach($this->data as $name => $arr) {
								$insert['cols'][] =   implode(",",$arr['cols']);
								$insert['vals'][] =   implode(",",$arr['vals']);
							}
					}

				$this->statement	.=	'(';
				$this->statement	.=	(isset($insert['cols']) && is_array($insert['cols']))? implode(",",$insert['cols']):"";
				$this->statement	.=	") VALUES (";
				$this->statement	.=	(isset($insert['vals']) && is_array($insert['vals']))? implode(",",$insert['vals']):"";
				$this->statement	.=	")";

				return $this;
			}
	}

include("../Connections/CWDevConnect.php");
function render_error($settings = array("title"=>"Failed","body"=>"Sorry, your submission failed. Please go back and fill out all required information."))
	{ ?>
<h2><?php echo (isset($settings['title']))? $settings['title']:"Error"; ?></h2>
<p><?php echo (isset($settings['body']))? $settings['body']:"An unknown error occurred."; ?></p>
<?php
	}

// this function is used to sanitize code against sql injection attack.
function ms_escape_string($data)
	{
        if(!isset($data) || empty($data))
			return "";

		if(is_numeric($data))
			return $data;

		$non_displayables[]	=	'/%0[0-8bcef]/';	// url encoded 00-08, 11, 12, 14, 15
		$non_displayables[]	=	'/%1[0-9a-f]/';		// url encoded 16-31
		$non_displayables[]	=	'/[\x00-\x08]/';	// 00-08
		$non_displayables[]	=	'/\x0b/';			// 11
		$non_displayables[]	=	'/\x0c/';			// 12
		$non_displayables[]	=	'/[\x0e-\x1f]/';	// 14-31

        foreach($non_displayables as $regex)
            $data	=	preg_replace($regex,'',$data);
	        $data	=	str_replace("'","''",$data);
        return $data;
    }

	// New bid save engine is required for both sql statement generations
	$BidSet	=	new ProcessBid($conn);
	$strId = null;

	if(isset($_POST["Id"]))
	{
		$strId = $_POST["Id"];
		//echo $strId;
	}
	If ($strId == "") {
	//echo "This is an insert statement";
	// This will generate an insert query
	$insert	=	$BidSet->SaveData($_POST)
						->SaveFolder('../uploads/')
						->AddFiles('BidIDFile')
						->AddFiles('item')
						->AddFiles('SignInSheet')
						->AddFiles('TabSheet')
						->AddFiles('Xcontract')
						->InsertQuery()
						->statement;

	// Check that statement is not empty
	if($insert != false) {
			sqlsrv_query($conn,$insert);
			render_error(array("title"=>"Bid Successfully Saved!","body"=>'Go back to <a href="admin.php">admin screen</a>'));
			$err	=	false;
		}


	//echo '<pre>';
	//print_r($insert);
//	echo '</pre>';
    }
    else
    {
    //echo "This is an update statement";
	// This will generate an update query
	$update	=	$BidSet->SaveData($_POST,array("Id"))
						->SaveFolder('../uploads/')
						->AddFiles('BidIDFile')
						->AddFiles('item')
						->AddFiles('SignInSheet')
						->AddFiles('TabSheet')
						->AddFiles('Xcontract')
						->where(array("Id"=>$_POST["Id"]))
						->UpdateQuery()
						->statement;

	//echo '<pre>';
	//print_r($update);
	//echo '</pre>';
	// Check that statement is not empty
	if($update != false) {
			sqlsrv_query($conn,$update);
			render_error(array("title"=>"Bid Successfully Saved!","body"=>'Go back to <a href="admin.php">admin screen</a>'));
			$err	=	false;
		}
    }
	// This will post an error if the query fails
	if((isset($err) && $err == true) || !isset($err))
		render_error();

		?>

This is incredible. You are awesome. I feel like singing.

 

Amazing how someone you don't know can bring you some joy.

 

Only one issue I have left, if you don't mind is integrating your SELECT and UPDATE code into mine.

 

I do already have a code that either INSERTs or UPDATES depending on what operation a user wishes to perform.

 

I am having problem with that last bit.

 

I posted above (sorry long).  Or at least point in the right direction of where to fit your code in.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.