Home arrow PHP arrow Page 7 - Time Is Money (part 2)

Exercising Restraint - PHP

In this concluding article, explore the scripts which add andremove timesheet entries to the system, and get a crash course instatistics by using these entries to generate useful resource allocationand usage reports.

  1. Time Is Money (part 2)
  2. Getting Creative
  3. Split Personality
  4. In...
  5. ...And Out
  6. The Number Game
  7. Exercising Restraint
  8. The Big Picture...
  9. ...And The Little Brush Strokes
  10. When Things Go Wrong
  11. Happy Endings
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 4
November 16, 2001

print this article


No, I didn't really do that - I still need a paycheck. But every dog has his day, and mine will come soon...

Anyway, disturbing though that conversation was, I still managed to get some useful data from it. I can now state with certainty that the system should generate the following three types of reports:

a big-picture overview of the time spent by users on all active projects for a specific period of time,

a big-picture overview of the time spent on different tasks over a specific period of time;

a focused report of time spent by different users on the different components of a project for a specific period.

With this in mind, let's quickly review the code for the report generation menu item in "menu.php"

<!-- menu.php --> <li> <!-- generate report option --> <form name="report" action="report.php" method="post"> <a href="javascript:submitForm(1)">Generate activity reports</a> between <? generateDateSelector("s"); ?> and <? generateDateSelector("e"); ?> for <select name="pid"> <option value="0">&lt;all projects&gt;</option> <? // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // get project list $query = "SELECT pid, pname from projects"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); while (list($pid, $pname) = mysql_fetch_row($result)) { echo "<option value=$pid>$pname</option>"; } mysql_free_result($result); ?> </select> </form> <p> <? } ?>
This has all the data I need to build any of the three report types - a starting date (created from the date variables $sd, $sm and $sy), an ending date (created from the date variables $ed, $em and $ey) and a project identifier (which may be 0 for "all projects"). When this form is submitted, it sends these variables to the script "report.php", which performs the actual report generation.

If you look at "report.php", you'll see that it's basically one gigantic "if" loop - the first part generates big-picture type reports, while the second part generates more specific reports.

<? // report.php - generate reports // includes // check for valid session and valid administrator // check for valid dates if (!checkdate($sm, $sd, $sy) || !checkdate($em, $ed, $ey)) { header("Location: error.php?ec=2"); exit; } // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // create start and end datestamp $sdate = $sy . "-" . $sm . "-" . $sd; $edate = $ey . "-" . $em . "-" . $ed; ?> <? // main "if" loop begins // if report required for ALL projects if ($pid == 0) { // code goes here } // report required for a specific project else { // code goes here snip! } // main "if" loop done - now clean up and print page footer mysql_close($connection); ?> <? include("footer.inc.php"); ?> </body> </html>
Let's write some code for the general report first - once that's done, writing code to build a report for a specific project should be a piece of cake.

>>> More PHP Articles          >>> More By The Disenchanted Developer, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: