Jump to content

Moorcam

Members
  • Posts

    197
  • Joined

  • Last visited

Everything posted by Moorcam

  1. Had the sandwich and the coffee. No smoke because I gave them up about 2 weeks ago (God help everyone around me) and had a look at the first line. Changed it to the following: if(!empty($_FILES['image']['name'])) { Works perfectly. No idea why that didn't shout at me earlier. Thank you kindly.
  2. Hi guys, Using the following code to upload an image to a directory. It aint being funky... if ($_FILES['image']['error'] = UPLOAD_ERR_OK) { // image file directory $target = "images/uploads/".basename($_FILES['image']['name']); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; $post['image'] = $target; }else{ $msg = "Failed to upload image"; $post['image'] = null; } } else { $post['image'] = null; } Can anyone tell me what's up? Thanks guys
  3. Thanks mate. Will do. Bit of a massive learning curve but no doubt I will get there. Thanks for your help guys.
  4. Just saw this now. Thanks heaps mate. It works. I will get there eventually
  5. Ok, I am having a crack here so please be gentle. include_once('includes/header.php'); if(isset($_POST['submit'])){ $id = trim($_SESSION['id']); //$trn_date = trim($db, date("Y-m-d H:i:s")); //$password = $db->real_escape_string(md5($_POST['password'])); $image = trim($_FILES['image']['name']); $name = trim($_POST['name']); $phone = trim($_POST['phone']); $email = trim($_POST['email']); $address = trim($_POST['address']); $license_number = trim($_POST['license_number']); $position = trim($_POST['position']); $role = trim($_POST['role']); $submittedby = trim($_SESSION["username"]); // image file directory $target = "images/".basename($image); if(!empty($_FILES['image']['name'])) { $stmt = $db->prepare("UPDATE users SET name = ?, email = ?, phone = ?, address = ?, license_number = ?, position = ?, role = ?, submittedby = ?, image = ? WHERE id = ?"); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } }else{ $stmt = $db->prepare("UPDATE users SET name = ?, email = ?, phone = ?, address = ?, license_number = ?, position = ?, role = ?, submittedby = ? WHERE id = ?"); } $stmt = $db->execute(array($name, $email, $phone, $address, $license_number, $position, $role, $submittedby, $image)); if($stmt->execute()){ echo 'Done'; }else{ echo 'Not Done'; } } The above gives an error: Fatal error: Uncaught Error: Call to undefined method PDO::execute() That's this line: $stmt = $db->execute(array($name, $email, $phone, $address, $license_number, $position, $role, $submittedby, $image)); I am at a complete roadblock here.
  6. Howdy folks, I have decided, after a discussion with Barand, to finally hang up the MySQLi shoes and move over to the dark side of PDO. I am trying to Update a profile, for example, but it is not working. No errors or anything. New to PDO so would love some help on figuring out where I am going wrong. Probably everywhere knowing me lol. Here is the dreaded code: if(isset($_POST['submit'])){ $id = trim($_SESSION['id']); //$trn_date = trim($db, date("Y-m-d H:i:s")); //$password = $db->real_escape_string(md5($_POST['password'])); $image = trim($_FILES['image']['name']); $name = trim($_POST['name']); $phone = trim($_POST['phone']); $email = trim($_POST['email']); $address = trim($_POST['address']); $license_number = trim($_POST['license_number']); $position = trim($_POST['position']); $role = trim($_POST['role']); $submittedby = trim($_SESSION["username"]); // image file directory $target = "images/".basename($image); if(!empty($_FILES['image']['name'])) { $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby, image = :image"; }else{ $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby"; } $stmt= $db->prepare($sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } if(!$stmt){ if ($stmt->execute()){ $message = ' <i class="fa fa-check text-danger"> Something went wrong please contact the server admin.</i>'; } else{ $message = ' <i class="fa fa-check text-success"> Record Updated!</i>'; } } } Any help folks would be appreciated
  7. Working. Mate you are a legend. $sql = "INSERT INTO timesheets (user_id, week_ending, timesheet_comment) VALUES ('$user_id', '$week_ending', '$timesheet_comment')"; if (mysqli_multi_query($con, $sql)) { $last_id = $con->insert_id; } $sql2 = "INSERT INTO stafftime (sheet_id, staff_date, time_start, time_end, break_time) VALUES ('$last_id', '$staff_date', '$time_start', '$time_end', '$break_time')"; if (mysqli_multi_query($con, $sql2)) { $message = '<p class="text-success"><i class="fa fa-check"></i> - Timesheet Submitted Successfully</p>'; } else { $message = '<p class="text-danger"><i class="fa fa-check"> Error:'. $sql2 . '<br>' . mysqli_error($con).'</p>'; } mysqli_close($con); }
  8. That's what I was wondering how I do. How do I get those IDs to be the same in different tables? I did search Google about that but could find nothing.
  9. *Red Faced* Sorry. I thought you meant a Var dump Here you go. Hope this is what you are after: CREATE TABLE `stafftime` ( `time_id` int(11) NOT NULL, `sheet_id` int(11) NOT NULL, `staff_date` date NOT NULL, `time_start` varchar(20) NOT NULL, `time_end` varchar(20) NOT NULL, `break_time` varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `stafftime` -- INSERT INTO `stafftime` (`time_id`, `sheet_id`, `staff_date`, `time_start`, `time_end`, `break_time`) VALUES (1040, 141826, '2021-09-19', '06:00', '17:00', '1:00'), (1041, 671766, '2021-09-19', '09:30', '17:30', '1:00'), (1042, 1080, '2021-09-19', '09:30', '17:30', '1:00'); -- -------------------------------------------------------- -- -- Table structure for table `timesheets` -- CREATE TABLE `timesheets` ( `timesheet_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `week_ending` datetime NOT NULL, `timesheet_comment` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `timesheets` -- INSERT INTO `timesheets` (`timesheet_id`, `user_id`, `week_ending`, `timesheet_comment`) VALUES (1050, 9, '2021-10-10 00:00:00', 'Just a test'), (1051, 9, '2021-09-19 00:00:00', 'Just a test'), (1052, 9, '2021-09-19 00:00:00', 'Just a test'); -- -- Indexes for dumped tables -- -- -- Indexes for table `stafftime` -- ALTER TABLE `stafftime` ADD PRIMARY KEY (`time_id`), ADD KEY `timesheet_id` (`sheet_id`); -- -- Indexes for table `timesheets` -- ALTER TABLE `timesheets` ADD PRIMARY KEY (`timesheet_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `stafftime` -- ALTER TABLE `stafftime` MODIFY `time_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1043; -- -- AUTO_INCREMENT for table `timesheets` -- ALTER TABLE `timesheets` MODIFY `timesheet_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1053; COMMIT;
  10. Here is a var_dump of the $result object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } And a var_dump of $sql string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" I really appreciate your time and effort man.
  11. Thanks mate. Great reading. Very informative. It appears my query is not getting the data from stafftime. Populating from the other two tables fine but anything from stafftime is just not happening. $session = $_SESSION['ID']; $sql = "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) {
  12. Moorcam

    Video script

    You will probably need something like this. But will need to work out the actual outline of the Frame to make it look like a TV: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_responsive_iframe_169
  13. if(isset($row['time_start']) && $row['time_end'] && $row['break_time'] != "") { $time_start = new DateTime($row['time_start']); $time_end = new DateTime($row['time_end']); list($h, $m) = explode(":", $row['break_time']); $break_time = new DateInterval("PT{$h}H{$m}M"); $time_worked = $time_start->add($break_time)->diff($time_end); echo $time_worked; } Have also tried this and nothing.
  14. Howdy guys, First of all, thanks so much for your help so far, especially yesterday. My wife and kids would tell you I was ropeable. Following Barand's advice and idea on my previous post, I have decided to break things up and put them into separate tables to make it easier to process. All is working fine but Hours Worked do not WERK (work), I am trying an accent Here's the code that called the timesheet submitted by a driver for one day. It is showing to the submitter based on their session id. $session = $_SESSION['ID']; $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.sheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Here is where I am trying to display the hours worked: <td><?php echo $row['hrs_worked']; ?></td> But nothing shows. No errors, nothing in Console either. I am obviously doing this wrong. As mentioned in my last post, I am new to this JOIN thingy-ma-jig. I know this following piece is meant to calculate between start, end and break. Not sure if that's happening either. timediff(timediff(time_end, time_start), break_time) as hrs_worked Any guidance, as always is appreciated.
  15. Got it: $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.timesheet_id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Thanks guys for your patience etc. Had never heard of JOIN this and that until it was mentioned on these forums a couple months ago :D
  16. $sql = "SELECT timesheets.*, users.*, staff_time.* FROM timesheets INNER JOIN users ON users.user_id = timesheets.user_id INNER JOIN staff_time ON staff_time.timesheet_id = timesheet.timesheet_id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Still no good.
  17. I can't get it. Been fiddling, moving, swapping, searching google, trying what other people have tried, and my Irish Brain Syndrome, coupled with the lack thereof said Guinness fix, results in a Nadda approach. 😕
  18. Ok, have tried what was suggested and just getting errors: Warning: Attempt to read property "num_rows" on bool in D:\xampp\htdocs\protour\admin\timesheets.php on line 60 All tables have a value. Have also tried the following with same error: $sql = "SELECT timesheets.*, users.*, st.* FROM staff_time AS st LEFT JOIN users LEFT JOIN timesheets ON st.time_id ON users.user_id = timesheets.timesheet_id WHERE timesheet_id = $timesheet_id LIMIT 1"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { I give up
  19. Ignore above post. My brain is still fried
  20. Afternoon, Now that I have refreshed the brain cells, which don't work anyway, I decided to have a crack at this. At the moment I am trying to get data as below (suggested by your good self), and getting an error of Parse error: syntax error, unexpected identifier "concat" Here is the code I am using to get the data, which is just a modify of what Barand posted above: <?php SELECT concat(firstname,' ', lastname) as name , dayname(staff_date) as day , date_format(staff_date, '%b %d') as date , time_start , time_end , break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM driver_time JOIN timesheets USING (timesheet_id) JOIN users USING (user_id) WHERE week_ending = date ORDER BY user_id, staff_date; ?> Doing this the way Barand suggested, I think is definitely the way to go. If I can get past this I am having Guinness tonight
  21. Thanks mate. Will have a look at all this in the next day or so. It's like 1:30am now and my brain has literally fried.
  22. Awesome news. Now, what have you tried already?
  23. This is getting annoying now. If I fill in the Start, Break and Finish times for Monday and Tuesday, it shows the correct Total Hours. But, if I add in Wednesday, it goes bonkers. Here is the full code. If anyone can figure it our, please be my guest. In the meantime, I feel like filling the Recycling Bin with diff this and diff that, <?php include_once('includes/header.php'); if(isset($_POST['submit_timesheet'])){//if the submit button is clicked $week_ending = mysqli_real_escape_string($con, $_POST['week_ending']); $staff_name = mysqli_real_escape_string($con, $_SESSION["USERNAME"]); $monday_start = mysqli_real_escape_string($con, $_POST['monday_start']); $monday_finish = mysqli_real_escape_string($con, $_POST['monday_finish']); $tuesday_start = mysqli_real_escape_string($con, $_POST['tuesday_start']); $tuesday_finish = mysqli_real_escape_string($con, $_POST['tuesday_finish']); $wednesday_start = mysqli_real_escape_string($con, $_POST['wednesday_start']); $wednesday_finish = mysqli_real_escape_string($con, $_POST['wednesday_finish']); $thursday_start = mysqli_real_escape_string($con, $_POST['thursday_start']); $thursday_finish = mysqli_real_escape_string($con, $_POST['thursday_finish']); $friday_start = mysqli_real_escape_string($con, $_POST['friday_start']); $friday_finish = mysqli_real_escape_string($con, $_POST['friday_finish']); $saturday_start = mysqli_real_escape_string($con, $_POST['saturday_start']); $saturday_finish = mysqli_real_escape_string($con, $_POST['saturday_finish']); $sunday_start = mysqli_real_escape_string($con, $_POST['sunday_start']); $sunday_finish = mysqli_real_escape_string($con, $_POST['sunday_finish']); $total_hours = mysqli_real_escape_string($con, $_POST['total_hours']); $timesheet_comment = mysqli_real_escape_string($con, $_POST['timesheet_comment']); $ins_query="insert into timesheets (`week_ending`, `staff_name`, `monday_start`, `monday_finish`, `tuesday_start`, `tuesday_finish`, `wednesday_start`, `wednesday_finish`, `thursday_start`, `thursday_finish`, `friday_start`, `friday_finish`, `saturday_start`, `saturday_finish`, `sunday_start`, `sunday_finish`, `total_hours`, `timesheet_comment`) values ( '$week_ending', '$staff_name', '$monday_start', '$monday_finish', '$tuesday_start', '$tuesday_finish', '$wednesday_start', '$wednesday_finish', '$thursday_start', '$thursday_finish', '$friday_start', '$friday_finish', '$saturday_start', '$saturday_finish', '$sunday_start', '$sunday_finish', '$total_hours', '$timesheet_comment' )"; mysqli_query($con,$ins_query) or die(mysqli_error($con)); if(mysqli_affected_rows($con)== 1 ){ $message = '<p class="text-success"><i class="fa fa-check"></i> - Timesheet Submitted Successfully</p>'; } } ?> <!-- Header--> <div class="breadcrumbs"> <div class="col-sm-4"> <div class="page-header float-left"> <div class="page-title"> <h1><i class="fa fa-clock"></i> Timesheets</h1> </div> </div> </div> <div class="col-sm-8"> </div> </div> <div class="content mt-3"> <div class="animated fadeIn"> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-header"><strong>Add </strong><small>Timesheet <?php if($message = isset($message) ? $message : ''){ printf($message); } ?></small></div> <div class="card-body card-block"> <form role="form" method="post" action=""> <input type="hidden" name="new" value="1" /> <div class="modal-body"> <p>Please make sure your start times and finish times are correct as it will effect your payments. Start time is start time at Depot and finish time is finish at Depot.<br />For days not worked please place 00:00 in time fields. </p> <div class="row form-group"> <div class="col-6"> <label for="driver_name" class=" form-control-label">Driver Name (required)</label> <input type="text" class="form-control" id="driver_name" name="driver_name" placeholder="" value="<?php echo $_SESSION['NAME']; ?>" required > </div> <div class="col-6"> <label for="week_ending" class=" form-control-label">Week Ending (required)</label> <input type="date" class="form-control" id="week_ending" name="week_ending" placeholder="" value="<?php echo isset($_POST['week_ending']) ? $_POST['week_ending'] : '' ?>" required > </div> </div> <hr> <h3>Monday</h3> <div class="row form-group"> <div class="col-4"> <label for="monday_start" class=" form-control-label">Start Time</label> <input type="text" class="form-control" id="monday_start" name="monday_start" placeholder="" value="<?php echo isset($_POST['monday_start']) ? $_POST['monday_start'] : '' ?>" > </div> <div class="col-4"> <label for="monday_break" class=" form-control-label">Break Period</label> <input type="text" class="form-control" id="monday_break" name="monday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['monday_break']) ? $_POST['monday_break'] : '' ?>" > </div> <div class="col-4"> <label for="monday_finish" class=" form-control-label">Finish Time</label> <input type="text" class="form-control" id="monday_finish" name="monday_finish" placeholder="" value="<?php echo isset($_POST['monday_finish']) ? $_POST['monday_finish'] : '' ?>" > </div> </div> <?php // MONDAY CALCULATIONS if(isset($_POST['monday_start']) && $_POST['monday_finish'] && $_POST['monday_break'] != "") { $monday_start = new DateTime($_POST['monday_start']); $monday_finish = new DateTime($_POST['monday_finish']); list($h, $m) = explode(":", $_POST['monday_break']); $monday_break = new DateInterval("PT{$h}H{$m}M"); $mondiff = $monday_start->add($monday_break)->diff($monday_finish); ?> <div class="form-group"> <label for="mondiff" class=" form-control-label">Monday Hours</label> <input type="text" readonly class="form-control" name="mondiff" value="<?php echo $mondiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Tuesday</h3> <div class="row form-group"> <div class="col-4"> <label for="tuesday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="tuesday_start" name="tuesday_start" placeholder="" value="<?php echo isset($_POST['tuesday_start']) ? $_POST['tuesday_start'] : '' ?>" > </div> <div class="col-4"> <label for="tuesday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="tuesday_break" name="tuesday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['tuesday_break']) ? $_POST['tuesday_break'] : '' ?>" > </div> <div class="col-4"> <label for="tuesday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="tuesday_finish" name="tuesday_finish" placeholder="" value="<?php echo isset($_POST['tuesday_finish']) ? $_POST['tuesday_finish'] : '' ?>" > </div> </div> <?php // TUESDAY CALCULATIONS if(isset($_POST['tuesday_start']) && $_POST['tuesday_finish'] && $_POST['tuesday_break'] != "") { $tuesday_start = new DateTime($_POST['tuesday_start']); $tuesday_finish = new DateTime($_POST['tuesday_finish']); list($h, $m) = explode(":", $_POST['tuesday_break']); $tuesday_break = new DateInterval("PT{$h}H{$m}M"); $tuediff = $tuesday_start->add($tuesday_break)->diff($tuesday_finish); ?> <div class="form-group"> <label for="tuediff" class=" form-control-label">Tuesday Hours</label> <input type="text" readonly class="form-control" name="tuediff" value="<?php echo $tuediff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Wednesday</h3> <div class="row form-group"> <div class="col-4"> <label for="wednesday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="wednesday_start" name="wednesday_start" placeholder="" value="<?php echo isset($_POST['wednesday_start']) ? $_POST['wednesday_start'] : '' ?>" > </div> <div class="col-4"> <label for="wednesday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="wednesday_break" name="wednesday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['wednesday_break']) ? $_POST['wednesday_break'] : '' ?>" > </div> <div class="col-4"> <label for="wednesday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="wednesday_finish" name="wednesday_finish" placeholder="" value="<?php echo isset($_POST['wednesday_finish']) ? $_POST['wednesday_finish'] : '' ?>" > </div> </div> <?php // WEDNESDAY CALCULATIONS if(isset($_POST['wednesday_start']) && $_POST['wednesday_finish'] && $_POST['wednesday_break'] != "") { $wednesday_start = new DateTime($_POST['wednesday_start']); $wednesday_finish = new DateTime($_POST['wednesday_finish']); list($h, $m) = explode(":", $_POST['wednesday_break']); $wednesday_break = new DateInterval("PT{$h}H{$m}M"); $weddiff = $wednesday_start->add($wednesday_break)->diff($wednesday_finish); ?> <div class="form-group"> <label for="weddiff" class=" form-control-label">Wednesday Hours</label> <input type="text" readonly class="form-control" name="weddiff" value="<?php echo $weddiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Thursday</h3> <div class="row form-group"> <div class="col-4"> <label for="thursday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="thursday_start" name="thursday_start" placeholder="" value="<?php echo isset($_POST['thursday_start']) ? $_POST['thursday_start'] : '' ?>" > </div> <div class="col-4"> <label for="thursday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="thursday_break" name="thursday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['thursday_break']) ? $_POST['thursday_break'] : '' ?>" > </div> <div class="col-4"> <label for="thursday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="thursday_finish" name="thursday_finish" placeholder="" value="<?php echo isset($_POST['thursday_finish']) ? $_POST['thursday_finish'] : '' ?>" > </div> </div> <?php // THURSDAY CALCULATIONS if(isset($_POST['thursday_start']) && $_POST['thursday_finish'] && $_POST['thursday_break'] != "") { $thursday_start = new DateTime($_POST['thursday_start']); $thursday_finish = new DateTime($_POST['thursday_finish']); list($h, $m) = explode(":", $_POST['thursday_break']); $thursday_break = new DateInterval("PT{$h}H{$m}M"); $thurdiff = $thursday_start->add($thursday_break)->diff($thursday_finish); ?> <div class="form-group"> <label for="thurdiff" class=" form-control-label">Thursday Hours</label> <input type="text" readonly class="form-control" name="thurdiff" value="<?php echo $thurdiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Friday</h3> <div class="row form-group"> <div class="col-4"> <label for="friday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="friday_start" name="friday_start" placeholder="" value="<?php echo isset($_POST['friday_start']) ? $_POST['friday_start'] : '' ?>" > </div> <div class="col-4"> <label for="friday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="friday_break" name="friday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['friday_break']) ? $_POST['friday_break'] : '' ?>" > </div> <div class="col-4"> <label for="friday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="friday_finish" name="friday_finish" placeholder="" value="<?php echo isset($_POST['friday_finish']) ? $_POST['friday_finish'] : '' ?>" > </div> </div> <?php // FRIDAY CALCULATIONS if(isset($_POST['friday_start']) && $_POST['friday_finish'] && $_POST['friday_break'] != "") { $friday_start = new DateTime($_POST['friday_start']); $friday_finish = new DateTime($_POST['friday_finish']); list($h, $m) = explode(":", $_POST['friday_break']); $friday_break = new DateInterval("PT{$h}H{$m}M"); $fridiff = $friday_start->add($friday_break)->diff($friday_finish); ?> <div class="form-group"> <label for="fridiff" class=" form-control-label">Friday Hours</label> <input type="text" readonly class="form-control" name="fridiff" value="<?php echo $fridiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Saturday</h3> <div class="row form-group"> <div class="col-4"> <label for="saturday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="saturday_start" name="saturday_start" placeholder="" value="<?php echo isset($_POST['saturday_start']) ? $_POST['saturday_start'] : '' ?>" > </div> <div class="col-4"> <label for="saturday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="saturday_break" name="saturday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['saturday_break']) ? $_POST['saturday_break'] : '' ?>" > </div> <div class="col-4"> <label for="saturday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="saturday_finish" name="saturday_finish" placeholder="" value="<?php echo isset($_POST['saturday_finish']) ? $_POST['saturday_finish'] : '' ?>" > </div> </div> <?php // SATURDAY CALCULATIONS if(isset($_POST['saturday_start']) && $_POST['saturday_finish'] && $_POST['saturday_break'] != "") { $saturday_start = new DateTime($_POST['saturday_start']); $saturday_finish = new DateTime($_POST['saturday_finish']); list($h, $m) = explode(":", $_POST['saturday_break']); $saturday_break = new DateInterval("PT{$h}H{$m}M"); $satdiff = $saturday_start->add($saturday_break)->diff($saturday_finish); ?> <div class="form-group"> <label for="satdiff" class=" form-control-label">Saturday Hours</label> <input type="text" readonly class="form-control" name="satdiff" value="<?php echo $satdiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <h3>Sunday</h3> <div class="row form-group"> <div class="col-4"> <label for="sunday_start" class=" form-control-label">Start</label> <input type="text" class="form-control" id="sunday_start" name="sunday_start" placeholder="" value="<?php echo isset($_POST['sunday_start']) ? $_POST['sunday_start'] : '' ?>" > </div> <div class="col-4"> <label for="sunday_break" class=" form-control-label">Break</label> <input type="text" class="form-control" id="sunday_break" name="sunday_break" placeholder="Example: 1:30 = 1hr 30min" value="<?php echo isset($_POST['sunday_break']) ? $_POST['sunday_break'] : '' ?>" > </div> <div class="col-4"> <label for="sunday_finish" class=" form-control-label">Finish</label> <input type="text" class="form-control" id="sunday_finish" name="sunday_finish" placeholder="" value="<?php echo isset($_POST['sunday_finish']) ? $_POST['sunday_finish'] : '' ?>" > </div> </div> <?php // SATURDAY CALCULATIONS if(isset($_POST['sunday_start']) && $_POST['sunday_finish'] && $_POST['sunday_break'] != "") { $sunday_start = new DateTime($_POST['sunday_start']); $sunday_finish = new DateTime($_POST['sunday_finish']); list($h, $m) = explode(":", $_POST['sunday_break']); $sunday_break = new DateInterval("PT{$h}H{$m}M"); $sundiff = $sunday_start->add($sunday_break)->diff($sunday_finish); ?> <div class="form-group"> <label for="sundiff" class=" form-control-label">Sunday Hours</label> <input type="text" readonly class="form-control" name="sundiff" value="<?php echo $sundiff->format('%H:%I'); ?>"> </div> <?php } ?> <hr> <?php if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += (int)$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tuediff->format('%H:%I'), $weddiff->format('%H:%I'), $thurdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); ?> <div class="row form-group"> <div class="col-6"> <div class="form-group"> <label for="total_hours" class=" form-control-label">Total Hours (required)</label> <input name="total_hours" id="total_hours" readonly class="form-control" value= "<?php echo $counter->get_total_time(); ?>" /> </div> </div> <?php } ?> <div class="col-6"> <div class="form-group"> <label for="timesheet_comment" class=" form-control-label">Comment (optional)</label> <input type="text" class="form-control" id="timesheet_comment" name="timesheet_comment" placeholder="" value="<?php echo isset($_POST['timesheet_comment']) ? $_POST['timesheet_comment'] : '' ?>" > </div> </div> </div> <div class="modal-footer"> <button type="submit" name="calculate" id="calculate" class="btn btn-primary">Calculate Hours</button> <button type="submit" name="submit_timesheet" id="submit_timesheet" class="btn btn-primary">Submit Timesheet</button> </div> </form> </div> </div> </div><!-- .animated --> </div><!-- .content --> </div><!-- /#right-panel --> <!-- Right Panel --> <script src="assets/js/vendor/jquery-2.1.4.min.js"></script> <script src="assets/js/popper.min.js"></script> <script src="assets/js/plugins.js"></script> <script src="assets/js/main.js"></script> <script src="assets/js/lib/data-table/datatables.min.js"></script> <script src="assets/js/lib/data-table/dataTables.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script> <script src="assets/js/lib/data-table/buttons.bootstrap.min.js"></script> <script src="assets/js/lib/data-table/jszip.min.js"></script> <script src="assets/js/lib/data-table/pdfmake.min.js"></script> <script src="assets/js/lib/data-table/vfs_fonts.js"></script> <script src="assets/js/lib/data-table/buttons.html5.min.js"></script> <script src="assets/js/lib/data-table/buttons.print.min.js"></script> <script src="assets/js/lib/data-table/buttons.colVis.min.js"></script> <script src="assets/js/lib/data-table/datatables-init.js"></script> </body> </html> Have a good day/evening/night/morning etc....
  24. Yeah seems to be ok if times are inserted in 24hr format. I am on localhost (xampp) so the error shows as Undefined Array Key but loaded onto live server and it shows as Undefined Variable. Bit strange but hey. So is Covid
×
×
  • 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.