This is the report.php view
if(isset($_POST["addReport"])) {
$report = new Report();
$report->employee_id = $_POST["employee_id"];
$report->date = $_POST["date"];
$report->job_id = $_POST["job_id"];
$report->description = $_POST["description"];
$report->attachment = file_get_contents($_FILES['attachment']['tmp_name']);
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->request_date[$i] = $_POST["request_date"];
}
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->quantity[$i] = $_POST["quantity"];
}
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->ms_num[$i] = $_POST["ms_num"];
}
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->info[$i] = $_POST["info"];
}
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->description[$i] = $_POST["description"];
}
for($i = 0; $i < count($_POST['date_range']); $i++) {
$report->date_recieved[$i] = $_POST["date_recieved"];
}
$report->addReport();
redirect_to("index.php#tabs-3");
}
?>
<script>
var counter = 1;
var limit = 10;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]'>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
</script>
<h2>Daily Reports</h2>
<h3>Add a Report</h3>
<form action="report.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
<strong>Project Name:</strong><select name="job_id" id="job_id">
<?php echo $catlist_job; ?>
</select>
<br />
<strong>Today's Date: <?php echo $today; ?></strong><?php echo "<input type ='hidden' value='". $today ."' name='created_on' id='created_on' />" ?>
<br />
<strong>Energy Wise:</strong><select name="energy_wise" id="energy_wise">
<?php echo $catlist_job; ?>
</select>
<br />
<strong>P.I.C Name: <?php echo $profile->first_name ." ". $profile->last_name ; ?></strong><?php echo "<input type ='hidden' value='".$profile->employee_id."' name='employee_id' id='employee_id' />" ?>
<br />
<strong>Project Oversight: Enersol</strong>
<br />
<strong>Report Generated at</strong>
<br />
<div class="hours">
<strong>ECC IN -</strong><select name="ecc_in" id="ecc_in"> </select>
<strong> , OUT -</strong><select name="ecc_out" id="ecc_out"> </select>
<br />
<strong>DCC IN -</strong><select name="dcc_in" id="dcc_in"> </select>
<strong> , OUT -</strong><select name="dcc_out" id="dcc_out"> </select>
<strong> , Dispatcher - </strong><select name="dispatcher" id="dispatcher"> </select>
</div>
<br />
<br />
<strong>Dailey Notes:</strong><input type="text" name="notes" id="notes" />
<br />
<strong>Extra Work Today:</strong><input type="text" name="extra" id="extra" />
<br />
<strong>Missing material:</strong>
<br />
<script language="Javascript" type="text/javascript">
var counter = 1;
var limit = 10;
function addInput(divName){
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = " <table><tr><td><input type='text' name='request_date[]'></td><td><input type='text' name='quantity[]'></td><td><input type='text' name='quantity[]'></td><td><input type='text' name='ms_num[]'></td><td><input type='text' name='info[]'></td><td><input type='text' name='description[]'></td><td><input type='text' name='date_recieved[]'></td></tr></table>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
</script>
<form method="POST">
<div id="dynamicInput">
<table>
<thead>
<tr>
<td>Date Requested</td>
<th>QTY</th>
<th>M&S#</th>
<th>PLATE NUMBER/REASON</th>
<th>DESCRIPTION</th>
<th>Date Received</th>
</tr>
</thead>
<tr>
<td><input type='text' name='request_date[]' id=""></td>
<td><input type='text' name='quantity[]' id=""></td>
<td><input type='text' name='ms_num[]' id=""></td>
<td><input type='text' name='info[]' id=""></td>
<td><input type='text' name='description[]' id=""></td>
<td><input type='text' name='date_recieved[]' id=""></td>
</tr>
<input type="button" value="Add another text input" onClick="addInput('dynamicInput');">
</form>
</table>
</div>
<br />
<strong>Visitors on Site :</strong><input type="text" name="visitors" id="visitors" />
<br />
<strong>Weather:</strong><input type="text" name="weather" id="weather" />
<br />
<strong>Resources:</strong>
<br />
<strong>Number Of Contractors On site:</strong><input type="text" name="contractors_on" id="contractors_on" />
<br />
<strong> Hours Worked:</strong><input type="text" name="hours_worked" id="hours_worked" />
<br />
<strong>Equipment :</strong><input type="text" name="equipment" id="equipment" />
<br />
<strong>Schedule</strong>
<br />
<strong>Percent Complete: </strong><input type="text" name="percent_complete" id="percent_complete" />
<br />
<strong>CMI:</strong><input type="text" name="cmi" id="cmi" />
<br />
<strong>Estimated Date Of Completion: </strong><input type="text" name="est_complete" id="est_complete" />
<br />
<strong>Safety Topic of Day:</strong>
<br />
<strong>Near Misses:</strong><input type="text" name="misses" id="misses" />
<br />
<strong>Accidents:</strong><input type="text" name="accidents" id="accidents" />
<br />
<strong>Observations :</strong><input type="text" name="observations" id="observations" />
<br />
<input type="submit" name="addReport" id="addReport" value="Create" />
</td>
</tr>
</table>
</form>
and this is the report.php class
<?php
class Report {
public $job_id;
public $created_on;
public $energy_wise;
public $employee_id;
public $ecc_in;
public $ecc_out;
public $dcc_in;
public $dcc_out;
public $dispatcher;
public $notes;
public $visitors;
public $weather;
public $contractors_on;
public $hours_worked;
public $equipment;
public $percent_complete;
public $cmi;
public $est_complete;
public $misses;
public $accidents;
public $observations;
public static function find_all() {
return self::find_by_sql ( "SELECT * FROM report ORDER BY date ASC" );
}
public static function find_by_id($employee_id) {
return self::find_by_sql ( "SELECT * FROM report WHERE employee_id={$employee_id} ORDER BY date ASC" );
}
public static function get_count() {
global $database;
$result_array = $database->query("SELECT * FROM report");
return $database->num_rows($result_array);
}
public static function find_by_sql($sql = "") {
global $database;
$result_set = $database->query ( $sql );
$object_array = array();
while ($row = $database->fetch_array($result_set)){
$object_array[] = self::instantiate($row);
}
return $object_array;
}
private static function instantiate($record) {
$object = new self;
foreach($record as $attribute=>$value) {
if($object->has_attribute($attribute)) {
$object->$attribute = $value;
}
}
return $object;
}
private function has_attribute($attribute) {
$object_vars = get_object_vars($this);
return array_key_exists($attribute, $object_vars);
}
public function addReport() {
global $database;
$job_id = $database->escape_value ($this->job_id);
$created_on = $database->escape_value ($this->created_on);
$energy_wise = $database->escape_value ($this->energy_wise);
$employee_id = $database->escape_value ($this->employee_id);
$ecc_in = $database->escape_value ($this->ecc_in);
$ecc_out = $database->escape_value ($this->ecc_out);
$dcc_in = $database->escape_value ($this->dcc_in);
$dcc_out = $database->escape_value ($this->dcc_out);
$dispatcher = $database->escape_value ($this->dispatcher);
$notes = $database->escape_value ($this->notes);
$visitors = $database->escape_value ($this->visitors);
$weather = $database->escape_value ($this->weather);
$contractors_on = $database->escape_value ($this->contractors_on);
$hours_worked = $database->escape_value ($this->hours_worked);
$equipment = $database->escape_value ($this->equipment);
$percent_co = $database->escape_value ($this->percent_co);
$cmi = $database->escape_value ($this->cmi);
$est_complete = $database->escape_value ($this->est_complete);
$misses = $database->escape_value ($this->misses);
$accidents = $database->escape_value ($this->accidents);
$observations = $database->escape_value ($this->observations);
$sql = "INSERT INTO report (job_id, created_on, energy_wise, employee_id, ecc_in, ecc_out, dcc_in, dcc_out, dispatcher, notes, extra, visitors, weather, contractors_on, hours_worked, equipment, percent_complete, cmi, est_complete, misses, accidents, observations) VALUES ";
$sql .= "('{$job_id}', '{$created_on}', '{$energy_wise}', '{$employee_id}', '{$ecc_in}', '{$ecc_out}', '{$dcc_in}', '{$dcc_out}', '{$dispatcher}', '{$notes}', '{$extra}', '{$visitors}', '{$weather}', '{$contractors_on}', '{$hours_worked}', '{$equipment}', '{$percent_complete}', '{$cmi}', '{$est_complete}', '{$misses}', '{$accidents}', '{$observations}')";
echo $employee_id;
}
public static function delete_report($id) {
global $database;
$database->query("DELETE FROM report WHERE id='{$id}'");
}
}
Thank you ahead of time,
Jason