DirtySnipe Posted July 6, 2010 Share Posted July 6, 2010 I have a bit of code for a 1 day availability. Not the best but it works. It is now in much need to an alteration. I need to modify it to a 7 day availability. Can anyone help. <?php function onlineTime() { // We need funky globals! global $DB; global $MySelf; global $TIMEMARK; /* * The change form. */ $MySetting = $DB->query("SELECT * FROM onlinetime WHERE userid='" . $MySelf->getID() . "'"); $MySetting = $MySetting->numRows(); if ($MySetting == 0 || $_GET[edit]) { $setTable = new table(3, true); $setTable->addHeader(">> Set your online time"); // Fetch el grande saved array. Ole! $myOnlineTime = $DB->getAssoc("SELECT * FROM onlinetime WHERE userid='" . $MySelf->getID() . "' LIMIT 1"); $myOnlineTime = $myOnlineTime[$MySelf->getID()]; // Loop through the hours. $j = 0; for ($i = 0; $i <= 23; $i++) { // Add a new row every 3rd time we are here, startign with first. if ($j == 0) { $setTable->addRow(); $j = 3; } // 01-02, 02-03.. etc $p = str_pad($i, 2, "0", STR_PAD_LEFT) . "-" . str_pad(($i +1), 2, "0", STR_PAD_LEFT); // Wow this is ugly. Pre-select all values that are stored in the db. $ppdv0 = "<option value=\"0\">0</option>"; $ppdv1 = "<option value=\"1\">1</option>"; $ppdv2 = "<option value=\"2\">2</option>"; $ppdv3 = "<option value=\"3\">3</option>"; $column = "h" . str_pad($i, 2, "0", STR_PAD_LEFT); switch ($myOnlineTime[$column]) { case ("0") : $ppdv0 = "<option selected value=\"0\">0</option>"; break; case ("01") : $ppdv1 = "<option selected value=\"1\">1</option>"; break; case ("2") : $ppdv2 = "<option selected value=\"2\">2</option>"; break; case ("3") : $ppdv3 = "<option selected value=\"3\">3</option>"; break; } $ppd = $ppdv0 . $ppdv1 . $ppdv2 . $ppdv3; $s = "<select name=\"$i\">"; $setTable->addCol($p . $s . $ppd . "</select>"); // Substract one. $j--; } // explain: $setTable->addRow(); $setTable->addCol("Code 0: You cant play at all. (sleep, work)", array ( "colspan" => 3 )); $setTable->addRow(); $setTable->addCol("Code 1: You could, but normaly wouldnt, except for extreme cases.", array ( "colspan" => 3 )); $setTable->addRow(); $setTable->addCol("Code 2: You can easily be online, but normaly are not.", array ( "colspan" => 3 )); $setTable->addRow(); $setTable->addCol("Code 3: Your preffered online time.", array ( "colspan" => 3 )); $submitbutton = "<input type=\"hidden\" name=\"check\" value=\"true\">" . "<input type=\"hidden\" value=\"modonlinetime\" name=\"action\">" . "<input type=\"submit\" value=\"Update your OnlineTime\" name=\"submit\">"; $setTable->addHeaderCentered("All times are EvE time!"); $setTable->addHeaderCentered($submitbutton); $form .= "<form action=\"index.php\" method=\"POST\">"; $form .= $setTable->flush(); $form .= "</form>"; } else { $editLink = "<br>[<a href=\"index.php?action=onlinetime&edit=true\">Edit your times</a>]"; } $page = "<h2>Online Time</h2>" . $form; /* * Okay pheew. That was the table to set your own time. Now lets create * a table to show everyones online time. */ $onlineTime = new table(25, true); $onlineTime->addHeader(">> Online Time of your corporation"); $onlineTime->addRow("#060622"); $onlineTime->addCol("Member"); $onlineTime->addCol("00"); $onlineTime->addCol("01"); $onlineTime->addCol("02"); $onlineTime->addCol("03"); $onlineTime->addCol("04"); $onlineTime->addCol("05"); $onlineTime->addCol("06"); $onlineTime->addCol("07"); $onlineTime->addCol("08"); $onlineTime->addCol("09"); $onlineTime->addCol("10"); $onlineTime->addCol("11"); $onlineTime->addCol("12"); $onlineTime->addCol("13"); $onlineTime->addCol("14"); $onlineTime->addCol("15"); $onlineTime->addCol("16"); $onlineTime->addCol("17"); $onlineTime->addCol("18"); $onlineTime->addCol("19"); $onlineTime->addCol("20"); $onlineTime->addCol("21"); $onlineTime->addCol("22"); $onlineTime->addCol("23"); // Ask the oracle. $cutOff =$TIMEMARK - 2592000; // 30 days. $OT = $DB->getCol("select distinct id from users where canLogin='1' and lastlogin >= '$cutOff' AND deleted='0'"); // Pilots names are not store in the onlinetable. So we have to translate. foreach ($OT as $pilotID) { $pilots[] = idToUsername($pilotID); } // Anyone published his online time yet? if (count($pilots) >= 1) { $haveOnlineTime = true; } // Sort the pilots by name. asort($pilots); // Create a row for each pilot. foreach ($pilots as $pilot) { // Get the pilots online times. $id = usernameToID($pilot); $ot = $DB->query("SELECT * FROM onlinetime WHERE userid='" . $id . "'"); // break off here if the user has not publishes his online time yet. if ($ot->numRows() == 0) { continue; } $ot = $ot->fetchRow(); $onlineTime->addRow(); // Pilot name $onlineTime->addCol(ucfirst($pilot)); // And go through each hour, creating a nice coloured box. for ($i = 0; $i <= 23; $i++) { $column = "h" . str_pad($i, 2, "0", STR_PAD_LEFT); // #222733 | #4f646e | #c2c957 | #e6f137 switch ($ot[$column]) { case ("0") : $onlineTime->addCol(" ", array ( "bgcolor" => "#222733" )); break; case ("01") : $onlineTime->addCol(" ", array ( "bgcolor" => "#4f646e" )); break; case ("2") : $onlineTime->addCol(" ", array ( "bgcolor" => "#c2c957" )); break; case ("3") : $onlineTime->addCol(" ", array ( "bgcolor" => "#e6f137" )); break; } } } // Return the hard labor. /* Return the Online Table, or, If no one published his online time yet, * print a message saying just that. */ if ($haveOnlineTime) { // We have at least one person who sent in his times. return ($page . $onlineTime->flush() . $editLink); } else { // Noone ever sent in his times. return ($page . "<b>Noone sent in his/her onlinetimes yet. But you can be the first! </b><br>" . $editLink); } } ?> Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 7, 2010 Author Share Posted July 7, 2010 BUMP Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 Could you please elaborate. From what I can tell, it looks like this is part of a scheduling function, and the code you really need to look at is more in the table class which isn't displayed here. You may need to do a trace through your code where something is being defined, go and review that function/class in whichever file it's located. The population of the current day is not really clear here either, so if you wrote the code, please define where you are putting the current day in, or highlighting the day... whatever this function is doing ^.^ Thanks Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 7, 2010 Author Share Posted July 7, 2010 This is a screen dump of what this function displays atm. This is what i mean there is no current day it just displays a one day schedule. A 24 hour block of time. I need to change it to a 168 hour block of time displayed like mon 0-1 1-2 and so on tues 0-1 1-2 wed 0-1 1-2 for a 7 day week. There are other things in there aswell like user stuff that relates to other code but that is not really needed here for what i want to do. I just want to change this from a single day to a full week. Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 7, 2010 Author Share Posted July 7, 2010 here is the code from table class. <?php class table { // Variable declarations private $html; // The container for the html private $bgc; // Array with row colors private $bgi; // Index used to alternate the bgc array private $current_row; // Current row counter private $current_col; // Current col counter private $columns; // Total number of columns. private $rowIsOpen; // bool to mem if a row is open. private $alternating; // If we use alteranting row colors. private $hasContent; // Set to true when the first row has been completed. private $width; // Width. // Constructator!!1 public function __construct($cols, $alt = false, $width = "%%WIDTH%%", $align = false) { // The $cols (columns) must be a positive integer greater of equal one. if ($cols <= 0) { makeNotice("Invalid column count given to constructor", "error", "Internal Error"); } // Default values for new tables. $this->bgc = array ( "#333344", "#444455" ); // Array of background colors $this->bgi = 1; // Index used in conjunction with above array. $this->current_col = 0; // Counts the current columns in the current row $this->current_row = 0; // Counts the number of rows $this->alternating = $alt; // True if we use alternating colors. $this->columns = $cols; // Defines the max number of columns. $this->html = "<table " . $align . $width . " cellpadding=\"2\" cellspacing=\"0\">"; // Open up the table. } public function addRow($bgcolor = false, $valign = false) { // Close current row, if applicable. $this->closeRow(); if (!$bgcolor) { $bgcolor = $this->bgc[$this->bgi]; $this->bgi = 1 - $this->bgi; } if ($valign) { $valign = "valign=\"" . $valign . "\""; } // Do we want alternating table colors? if ($this->alternating) { $this->html .= "<tr bgcolor=\"" . $bgcolor . "\" $valign>"; } else { $this->html .= "<tr>"; } // Reset the column count (new row) $this->current_col = 0; // Reset the column counter. $this->rowIsOpen = true; // Mark the table as open. $this->current_row++; // Increase row count. } private function closeRow() { if ($this->rowIsOpen) { // Do we have an open row? if ($this->current_col != $this->columns) { // Is the row filled? $BT = nl2br(print_r($this, true) . "<br>" . print_r(debug_backtrace(), true)); makeNotice("Current row not finished feeding yet!<br><br>" . $BT, "error", "Internal Error"); } else { // Its opened and filled. Close the row, and mark it as closed, too. $this->html .= "</tr>"; // Close row. $this->rowIsOpen = false; // Mark row as closed. } } } public function hasContent() { return ($this->hasContent); } public function addHeader($text) { $this->addRow("#222233"); $cols = $this->columns; $this->addCol("$text", array ( "bold" => true, "colspan" => $cols )); } public function addHeaderCentered($text) { $this->addRow("#222233"); $cols = $this->columns; $this->addCol("$text", array ( "bold" => true, "colspan" => $cols, "align" => "center" )); } public function addCol($cont, $modes) { // Do we have an open row? if (!$this->rowIsOpen) { makeNotice("Row not opened.", "error", "Internal Error"); } // Do we have a valid modes array? if (isset ($modes) && is_array($modes)) { // set the colspanning right. if ($modes[colspan]) { $colspan = $modes[colspan]; } else { $colspan = 1; } // rowspanning! if ($modes[rowspan]) { $rowspan = $modes[rowspan]; } else { $rowspan = 1; } // Bold ? if ($modes[bold]) { $bold = "<b>"; $bold_end = "</b>"; } // Width ? if ($modes[width]) { $width = $modes[width]; } // Align? if (isset ($modes[align])) { $align = "align=\"" . $modes[align] . "\""; } // Valign? if (isset ($modes[valign])) { $valign = "valign=\"" . $modes[valign] . "\""; } // Color? if (isset ($modes[bgcolor])) { $bgcolor = "bgcolor=\"" . $modes[bgcolor] . "\""; } } else { // Default Values go here (if no array set) $colspan = 1; } // Are we over-doing it? if ($this->current_col + $colspan > $this->columns) { debug($this); makeNotice("Too many columns requested.", "error", "Internal Error"); } // Add the content. $this->html .= "<td rowspan=\"" . $rowspan . "\" colspan=\"" . $colspan . "\" $bgcolor width=\"$width\" $align $valign>" . $bold . $cont . $bold_end . "</td>"; $this->current_col = $this->current_col + $colspan; $this->hasContent = true; } public function flush() { // Close and opened rows, if any. $this->closeRow(); // Finnish up. $this->html .= "</table>"; return ($this->html); } } ?> Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 I believe I have the concept of what you are trying to accomplish. You wish to either have that table repeat on the same page, broken down with headers "Monday, Tuesday, ....", or you wish to have a header accross the top, and choose the day. Either of those options would require a different mechanism for storing information in the database. This does seem to be something that could be fairly intense. Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 7, 2010 Author Share Posted July 7, 2010 intense.. sounds like trouble. how much would it cost if i were to say could you rewrite it? Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 7, 2010 Share Posted July 7, 2010 DirtySnipe, I am not on these forums to make money. I am here to contribute back to the community the same support that I have received, and would like to receive myself. By "intense", I didn't imply that it would require a complete rewrite, as it can be done with what you have provided. Probably with very little modification, but would take some time to study how the information is being loaded, what fields are available from the database (aka, can we display 7 days, and filter each into it's own group ?). The drawing of the HTML using php doesn't appear that it would pose much of a barrier. Just seems like I am missing something so I can see the whole picture. I would definitely be happy to provide further assistance. Perhaps you have a "test" environment that I could experiment with to get this project fixed up for you, or maybe wait and see what other people on the forums here have to say that may be able to resolve the problem faster. If you wish, you can send me a PM for more information. Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 8, 2010 Author Share Posted July 8, 2010 I can hook you up with a temp account to login to the system and a temp ftp. Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 13, 2010 Author Share Posted July 13, 2010 myrddinwylt what can I say. You are a star... Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted July 14, 2010 Author Share Posted July 14, 2010 Is it possible to display Mon, Tue, Wed and so on instead of day1, day2, day3? 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.