gearsgod Posted July 9, 2015 Share Posted July 9, 2015 Hi I just cant in over a week figure out how I would go about setting up this work time sheet, that displays my employees work times and find any conflicting work hours. But man I have been stumped on getting this code to work! Could anyone fix, or even better teach me a much better way to acomplish this? function time_sheet_day($DB){ $manager_id = $_SESSION['man_id']; $today = date('l'); $year = date('Y'); $ddate = @date(); $date = new DateTime($ddate); $week = $date->format("W"); $page = "<table><tbody><tr><th>ID</th><th>Crew</th><th>Position</th><th>Start Time</th><th>End Time</th></tr>"; $time_sheet_db = $DB->query("SELECT {$today},member_id FROM calendar WHERE manager_id = {$manager_id} AND Week = {$week} AND Year = {$year}"); $time_sheet = []; while($time = $time_sheet_db->fetcharray(SQLITE3_ASSOC)){ $hours = explode('-', $time[$today]); $time_sheet[] = array($time['member_id'], $hours[0], $hours[1]); } $member_info = []; $time_check = $time_sheet; $conflicts = []; $rater = 0; foreach($time_check as $checker){ if($checker[0] == $time_check[$rater][0]){ $rater = $rater + 1; continue; } if($checker[1] == $time_check[$rater][1]){ $conflicts[] = array($checker[0], $time_check[$rater][0], $checker[1]); } $rater = $rater + 1; } foreach($time_sheet as $member){ $member_info_db = $DB->query("SELECT username,crew,postion FROM Members WHERE ID = {$member[0]}"); $member_info = $member_info_db->fetcharray(SQLITE3_ASSOC); $found_conflict=array_find($conflicts, $member[0]); print_r($found_conflict); if($found_conflict == False){ $page .= "<tr><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } else { $page .= "<tr style='background-color:#FF0000'><td>{$member_info['username']}</td><td>{$member_info['crew']}</td><td>{$member_info['postion']}</td><td>{$member[1]}</td><td>{$member[2]}</td></tr>"; } } $page .= '</tbody></table>'; echo ($page); } function array_find($parents, $searched) { if (empty($searched) || empty($parents)) { return false; } foreach ($parents as $key => $value) { $exists = true; foreach ($searched as $skey => $svalue) { $exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue); } if($exists){ return $key; } } return false; } Quote Link to comment Share on other sites More sharing options...
Barand Posted July 9, 2015 Share Posted July 9, 2015 Could anyone fix, or even better teach me a much better way to acomplish this? How to accomplish what? If the code isn't working (whatever not working means) it only shows us what you don't want too do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.