'; } function spacer($w = 1, $h = 1) { return 'blank'; } function round_table($body, $center = 0) { $bi = blank_image(); return <<< EOE
tl $bi tr
$bi $body $bi
bl $bi br
EOE; } /* return a footer for the page */ function footer() { return round_table(' Generated by PHP at ' . date('Y-m-d H:i:s') . '', 1); } /* connect to the database, return a handle */ function connect_db() { global $MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DB; $dbc = mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD); if (!$dbc) die('Could not connect to MySQL server: ' . mysql_error()); if (!mysql_select_db($MYSQL_DB)) die('Could not select database: ' . mysql_error()); return $dbc; } /* perform a query on the MySQL database */ function do_query($query, $dbc) { $qr = mysql_query($query, $dbc); if (!$qr) die('Invalid query: ' . mysql_error()); return $qr; } /* returns the user's ID */ function get_userID($user) { $dbc = connect_db(); $qr = do_query("SELECT * FROM `users` WHERE `name` = '$user'", $dbc); $ra = mysql_fetch_assoc($qr); if (!$ra) return -1; return $ra['id']; mysql_close($dbc); } /* Returns a 31-element array of tip values for the given month */ function get_tips($month, $year, $userID) { $month = sprintf("%02d", $month); $tips = array(); for ($i = 0; $i < 31; $i++) $tips[] = 0.0; $dbc = connect_db(); $q = do_query("SELECT * FROM `tips` WHERE `user` = '$userID' AND `date` LIKE '$year-$month%'", $dbc); while ($ra = mysql_fetch_assoc($q)) { $dt = substr($ra['date'], 8, 2); $tips[$dt - 1] = $ra['amount']; } mysql_free_result($q); mysql_close($dbc); return $tips; } /* Returns an assoc-array of check values * (hours1, amount1, hours2, amount2) for the given month */ function get_checks($month, $year, $userID) { $month = sprintf("%02d", $month); if (strlen($month) < 2) $month = '0' . $month; $checks = array(); $dbc = connect_db(); $q = do_query("SELECT * FROM `checks` WHERE `user` = '$userID' AND `date` LIKE '$year-$month%'", $dbc); $dim = date('t', mktime(0, 0, 0, $month, 1, $year)); while ($ra = mysql_fetch_assoc($q)) { $dt = substr($ra['date'], 8, 2); if ($dt == 15) { $checks['hours1'] = $ra['hours']; $checks['amount1'] = $ra['amount']; } elseif ($dt == $dim) { $checks['hours2'] = $ra['hours']; $checks['amount2'] = $ra['amount']; } } mysql_free_result($q); mysql_close($dbc); return $checks; } /* Return a string for the previous month */ function get_back_month($month) { $mth = substr($month, 0, 2); $yr = substr($month, 2, 4); $mth = (($mth + 10) % 12) + 1; if ($mth == 12) $yr--; if (strlen($mth) < 2) $mth = "0$mth"; return $mth . $yr; } /* Return a string for the next month */ function get_next_month($month) { $mth = substr($month, 0, 2); $yr = substr($month, 2, 4); $mth = ($mth % 12) + 1; if ($mth == 1) $yr++; if (strlen($mth) < 2) $mth = "0$mth"; return $mth . $yr; } ?>