Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. Not only that, but since I was updating just one column of a row, I should've used UPDATE...SET. It's fixed now, though.
  2. Using the same setup from my last thread, I have the following query I'm trying to execute: And, like always, it's giving me an error: Is it breaking on me because I only specify one value to insert? Or does it not like my WHERE clause? The column in question is a TINYINT(1) UNSIGNED NOT NULL.
  3. LOL, it's always the stupid mistakes that bite me. Thanks for the help! I'm not 100% sure if PHP Fusion uses any escaping. I'm going to add some to my registration form anyway once I get the second segment of my project finished. I'm not worried about it right now as I'm doing everything on a test site, so nothing on the live site runs the risk of being messed up.
  4. Using PHP Fusion's own dbquery() function and the following input: I get the following error: I can't see any obvious error, and the syntax looks correct when I output it to the screen:
  5. I'm currently trying to insert a host of data into a MySQL database with a custom built sticky form for a PHP Fusion product. This form is supposed to enable people to register for events that my client is hosting. The site has an event calendar addon, which I've modified to display a link if the event in question is supposed to have guest registration. If so, there's a link that brings the user to a relatively simple registration form. The link contains the event id, which it passes to the form via GET to help with the eventual insertation of values. Here's my table: My code (and forgive me, it's long): <?php require_once "maincore.php"; require_once "subheader.php"; require_once "side_left.php"; if(file_exists(INFUSIONS."aw_ecal_panel/locale/".$settings['locale'].".php")) { include INFUSIONS."aw_ecal_panel/locale/".$settings['locale'].".php"; } else { include INFUSIONS."aw_ecal_panel/locale/German.php"; } if(isset($_GET['evid'])){ $ev = dbquery("SELECT * FROM ".DB_PREFIX."aw_ec_events WHERE ev_id=". $_GET['evid']); $event = dbarray($ev); $ev_id = $event['ev_id']; $user_id = $userdata['user_id']; $ev_title = $event['ev_title']; $ev_start = $event['ev_start']; $ev_end = $event['ev_end']; } //Below is code I used for debugging my timestamp problems from my last PHP Help thread. //Please ignore everything that's in the comment block immediately below. /* echo "Event id = ". $event['ev_id'] .", User id = ". $userdata['user_id'] .", Event title = ". $event['ev_title'] ."<br />"; echo "Event start time = ". $event['ev_start'] .", Event end time = ". $event['ev_end'] ."<br />"; $start_timestamp = strtotime($event['ev_start']); $end_timestamp = strtotime($event['ev_end']); echo "Event start timestamp = $start_timestamp, Event end timestamp = $end_timestamp<br /><br />"; echo "Can we get the right thing back?<br /><br />"; echo "Event start time (after timestamp -> date conversion) = ". date("m-d-Y h:i:s T", $start_timestamp) .", Event end time (after timestamp -> date conversion) = ". date("m-d-Y h:i:s T", $end_timestamp) ."<br /><br />"; */ $errMessage = NULL; if(isset($_POST['submit'])){ $ev = dbquery("SELECT * FROM ".DB_PREFIX."aw_ec_events WHERE ev_id=". $_POST['evid']); $event = dbarray($ev); $ev_id = $event['ev_id']; $user_id = $userdata['user_id']; $ev_title = $event['ev_title']; $ev_start = $event['ev_start']; $ev_end = $event['ev_end']; if(!empty($_POST['regAgent']) && preg_match("/^[a-zA-Z]+([ a-zA-Z-]+)*$/i", $_POST['regAgent'])){ $regAgent = $_POST['regAgent']; $ra = TRUE; } else{ $errMessage .= "Please enter your name!<br />\n"; } if(!empty($_POST['agentWritingNum']) && preg_match("/^[0-9a-zA-Z]*$/i", $_POST['agentWritingNum'])){ $agentWritingNum = $_POST['agentWritingNum']; $awn = TRUE; } else{ $errMessage .= "Please enter your writing number!<br />\n"; } if(!empty($_POST['phoneNum'])){ $phoneNum = $_POST['phoneNum']; if(preg_match("/^[0-9]{3}$/i", $phoneNum[0]) && preg_match("/^[0-9]{3}$/i", $phoneNum[1]) && preg_match("/^[0-9]{4}$/i", $phoneNum[2])){ $areaCode = $phoneNum[0]; $firstPart = $phoneNum[1]; $secondPart = $phoneNum[2]; $phoneText = "$areaCode-$firstPart-$secondPart"; $phone = TRUE; } else{ $errMessage .= "Please enter your correct phone number!<br />\n"; } } else{ $errMessage .= "Please enter your phone number!<br />\n"; } if(!empty($_POST['emailAddress']) && preg_match("/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/i", $_POST['emailAddress'])){ $email = $_POST['emailAddress']; $e = TRUE; } else{ $errMessage .= "Please enter your e-mail address!<br />\n"; } if(!empty($_POST['regionalSales']) && preg_match("/^[a-zA-Z]+([ a-zA-Z-]+)*$/i", $_POST['regionalSales'])){ $regSales = $_POST['regionalSales']; $rs = TRUE; } else{ $errMessage .= "Please enter the name of your regional sales coordinator!<br />\n"; } if(!empty($_POST['districtSales']) && preg_match("/^[a-zA-Z]+([ a-zA-Z-]+)*$/i", $_POST['districtSales'])){ $disSales = $_POST['districtSales']; $ds = TRUE; } else{ $errMessage .= "Please enter the name of your district sales coordinator!<br />\n"; } if($ra && $awn && $phone && $email && $rs && $ds){ //start the big process of updating tables and e-mailing results $query = "INSERT INTO ".DB_PREFIX."aflac (registering_agent, agent_writing_number, phone, email, regional_sales_coordinator, district_sales_coordinator, ev_id, user_id, ev_title, ev_start, ev_end, login_timestamp, login_status) VALUES (". $regAgent .", ". $agentWritingNum .", ". $phoneText .", ". $email .", ". $regSales .", ". $disSales .", ". $ev_id .", ". $user_id .", ". $ev_title .", ". $ev_start .", ". $ev_end .", ". strtotime('now') .", 1)"; $result = mysql_query($query); if($result){ echo "Success!<br /><br />\n\n"; } else{ echo "Something went wrong with the insert!<br /><br />\n\n"; } } else{ echo "<div style='color: red;'>$errMessage</div><br />"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Registration Form</title> <link rel="stylesheet" type="text/css" href="formstyles.css"> </head> <body style="text-align: center;"> <div style="width: 400px; margin: 0 auto;"> Registration Form<br /><br /> <form action="<?php echo $_SERVER['PHP_SELF']; ?>?evid=<?php echo $ev_id; ?>" method="post"> <fieldset class="narrow"><legend>Please input your information</legend> <p><label for="regAgent">Registering Agent:</label><input type="text" name="regAgent" value="<?php if(isset($_POST['regAgent'])){echo $_POST['regAgent'];} ?>" /></p> <p><label for="agentWritingNum">Agent Writing Number:</label><input type="text" name="agentWritingNum" value="<?php if(isset($_POST['agentWritingNum'])){echo $_POST['agentWritingNum'];} ?>" /></p> <p><label for="phoneNum">Phone Number:</label>(<input type="text" name="phoneNum[]" size="3" maxlength="3" value="<?php if(isset($_POST['phoneNum'])){echo $_POST['phoneNum'][0];} ?>" />) - <input type="text" name="phoneNum[]" size="3" maxlength="3" value="<?php if(isset($_POST['phoneNum'])){echo $_POST['phoneNum'][1];} ?>" /> - <input type="text" name="phoneNum[]" size="4" maxlength="4" value="<?php if(isset($_POST['phoneNum'])){echo $_POST['phoneNum'][2];} ?>" /></p> <p><label for="emailAddress">E-mail Address:</label><input type="text" name="emailAddress" value="<?php if(isset($_POST['emailAddress'])){echo $_POST['emailAddress'];} ?>" /></p> <p><label for="regionalSales">Regional Sales Coordinator:</label><input type="text" name="regionalSales" value="<?php if(isset($_POST['regionalSales'])){echo $_POST['regionalSales'];} ?>" /></p> <p><label for="districtSales">District Sales Coordinator:</label><input type="text" name="districtSales" value="<?php if(isset($_POST['districtSales'])){echo $_POST['districtSales'];} ?>" /></p> </fieldset> <input type="hidden" name="evid" value="<?php echo $ev_id; ?>" /> <p><input type="submit" name="submit" value="Submit" /></p> </form> </div> </body> </html> <?php require_once "side_right.php"; require_once "footer.php"; ?> I'm not getting any MySQL syntax errors. Instead, I'm only getting the message I coded in the event that an insert didn't work ("Something went wrong with the insert!"). Any ideas?
  6. I finally got it to work. The problem stemmed from PHP Fusion's built-in database code. Works like a charm now.
  7. In know for a fact that the values for the datetime columns in question are indeed filled. They're looking at me in phpMyAdmin. To be honest, I'm not sure if the db query is even retrieving those columns. Trying to find where the actual query is made has been a real pain because, like I said above, I'm trying to tweak a PHP Fusion addon. The code isn't very obvious in that regard. I think they are being retrieved, however, as wouldn't MySQL give an error if I was trying to use a column not returned by a query?
  8. Since I'm trying to modify PHP Fusion AND an event calendar addon, it's somewhat difficult to put my code online. It's spread throughout many files due to the spaghetti-code nature of PHP Fusion.
  9. I thought I had the problem solved, but I guess not. Here's what's going on: I have dates stored in a MySQL database as a datetime data type. I need to extract them from the database and turn them into timestamps to be sent to a form via GET. Then, once that form has them, I need to convert them back into a human-sensible form, as my form will e-mail the site owner whenever someone submits the form. From what I can tell with my debugging, my problem lies in not being able to extract those datetimes from the database. I tried outputting them to screen as-is (that is, before I try converting them to a timestamp), and nothing shows up. Any ideas?
  10. date() <?php $timestamp = time(); echo date('Y-m-d h:i:s', $timestamp); ?> Thanks mang!
  11. Okay, thanks! Related question: is there a built-in function that does the opposite? That is, can I feed a function a timestamp and have it return a date and time? I don't see one after skimming over the PHP online manual, but I figured I'd ask anyway. If not, what would be the algorithm in transforming a timestamp into a normal date and time?
  12. Is there any built-in PHP function that can turn something like "2007-04-18 18:00:00" into a timestamp?
  13. Sweet, it worked perfectly! Thanks!
  14. I need to extract the text within anchor tags for use in building another hyperlink. In other words, if I have something like this: <a href="http://www.something.php?id=12">Blah blah blah</a> I need to get the 'Blah blah blah' part. I'm thinking that a regular expression is the way to go, but I'm having difficulty seeing how to deal with the stuff in the href attribute. Please help. Thanks!
  15. Thanks for the responses, guys!
  16. I know that one should escape input, especially if it's going to be put in a database, but I've never really understood why. Could someone please explain it to me? Also, if I escape input (say, by using mysql_real_escape_string()) and insert into a database, will it still be escaped if I read that information from the database and output it to the screen? Thanks!
  17. OOP is the answer to a programming problem. As programs grew more complex, they also grew inefficient and hard to maintain and debug. The reason is that procedural programs tend to have a lot of coupling, where one section of code is tightly bound to another section, and a change in one necessitates changes in others. Flexibiliy and extensibility were hard to come by in a procedural-programming-only environment. The whole point of OOP is to modularize code to facilitate extensibility while reducing dependencies on the core code. Each idea in a program is made into its own discrete system (classes and objects). These systems can be combined in many different ways at runtime (composition), which results in a very flexible system overall. If done correctly, addon modules can be plugged in or removed from a core program without negatively effecting the user's experience.
  18. Ah, gotcha. I've used anchors before, but I kept thinking that this particular case was something that had to do with GET. The GET syntax was throwing me off of what was really going on. Thanks!
  19. I'm currently trying to tweak some pre-existing code. The script in questions builds a page based on the value passed to it by the GET form method. While this, in and of itself, is pretty simple to figure out, there's something at the end of the URI that I'm not familiar with. The basic URI structure is like this: http://www.mywebsite.com/scriptname.php?id=1#somemodifier Does the part I bolded above have any significance?
  20. I'm using PHP-Fusion to power a client's site. In it, I'm using an event calendar infusion (addon). I'd like to modify it slightly, but first I need to know if the following is possible: The infusion's main processing is done by a sticky form, so that form's action is of the script itself. Is it possible to transmit some of that info to another script if the submit button is pressed? I need the functionality of the form to remain the same, so adding another submit button won't help me. In other words, can a form have two actions -- one explicit in the form's (X)HTML, and another implicitly declared somewhere else?
  21. I'm re-re-reading reading my copy of "PHP5: Objects, Patterns, and Practice" because, dammit, I'm going to figure out OOP (at least, as it pertains to PHP). I've come across the topic of delegation twice now: once when the author was describing a use of the __call() method, and once when he first introduces the Strategy pattern as an example of composition. Unfortunately, the author doesn't really go into why he used delegation in those two examples (at least, not explicitly). No mention of code smells, or anything along those lines. So, is there any general rule of thumb when it comes to deciding when to implement delegation? Any signs/code smells to watch for? Or is it more along the lines of "You'll know when to use it when you get to that point?" For any fellow newbie who may be lurking and reading along, delegation is more of less something like this: <?php class Example{ private $delegate; public function doSomething(Delegate $delegate){ return $this->delegate->something($this); } } class Delegate{ private $property; public function something(Example $example){ return $this->property . "blah blah blah\n"; } } ?>
  22. Interesting idea... Are your cell heights fixed too? Because that's where my frustration lies. I can fix the widths now, by putting the content in a div, but height remains a problem. Do you have any examples you wouldn't mind me looking at?
  23. Right...I want the physical size of the calendar's dates to be exact across the board. However, I know that each date that has an appointment set for it will have content that will be bigger than the size of the date-block itself, hence my desire for a vertical scrollbar so the user can scroll through those dates that have appointments. As it stands right now, my calendar is huge because the content stretches the dates vertically.
  24. Well, since I'm making the calendar days so small, so as to fit in with the live site's layout, their contents will always be bigger than what the layout can handle. It's my understanding that, since I don't want both a horizontal and vertical scroll bar for each date, setting the overflow to auto will only give me a vertical scroll bar while keeping the dates' sizes static, which is what I want.
  25. I can't believe that I didn't think of that! I've tried doing it that way twice, once on my test script, once on my live script. It works great for my test script, but the height is still an issue with my live script. This is odd, as I'm using more or less the same CSS in both cases. As always, I'm going to post my code. Please bear with me as some of it is large. Test JavaScript: var W3CDOM = (document.createElement && document.getElementsByTagName); function init(){ if(!W3CDOM) return; printCalendar(); } function printCalendar(){ var days = document.getElementsByTagName('td'); for(var i = 0; i < days.length; i++){ days[i].innerHTML = "<div>I'm making a long ass paragraph to see if the table cells expand, so blah blah blah blah</div>"; if(i / 2 == 0){ days[i].style.backgroundColor = "black"; days[i].style.color = "white"; } else if(i / 3 == 1){ days[i].style.backgroundColor = "red"; days[i].style.color = "white"; } else if(i / 5 == 1){ days[i].style.backgroundColor = "blue"; days[i].style.color = "white"; } else{ days[i].style.backgroundColor = "green"; days[i].style.color = "white"; } } } window.onload = init; Test HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Test</title> <script type="text/javascript" src="test.js"></script> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <table> <tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> <tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> <tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> <tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> <tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> </table> </body> </html> Test CSS: td div{ width: 80px; height: 80px; overflow: auto; } Live JavaScript: var W3CDOM = (document.createElement && document.getElementsByTagName); var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; //Number of days in each month...be sure to make February equal to 29 on leap years var firstDays = [2, 5, 5, 1, 3, 6, 1, 4, 7, 2, 5, 7]; //1 = Sunday, 2 = Monday, etc. var apps = [ [16, 4, 16, 4, "AMITY I 9:00 - 11:30", "amity"], [16, 4, 16, 4, "Word II 5:30 - 8:30", "amity"], [17, 4, 17, 4, "Excel II 9:00 - 4:00", "microsoft"], [17, 4, 17, 4, "PowerPoint II 5:30 - 8:30", "microsoft"], [18, 4, 18, 4, "PowerPoint I 9:00 - 4:00", "microsoft"], [18, 4, 18, 4, "Word II 5:30 - 8:30", "microsoft"], [19, 4, 19, 4, "AMITY II 9:00 - 11:30", "amity"], [19, 4, 19, 4, "PowerPoint II 9:00 - 4:00", "amity"], [20, 4, 20, 4, "Access III 9:00 - 4:00", "microsoft"], [21, 4, 21, 4, "Into to Vista I 9:00 - 11:00", "microsoft"], [23, 4, 23, 4, "Excel II 5:30 - 8:30", "microsoft"], [24, 4, 24, 4, "Access II 5:30 - 8:30", "microsoft"], [25, 4, 25, 4, "Excell II 5:30 - 8:30", "microsoft"], [26, 4, 26, 4, "BOSC 9:00 - 4:00", "bosc"], [26, 4, 26, 4, "Access II 5:30 - 8:30", "bosc"], [28, 4, 28, 4, "Intro to Vista I 9:00 - 11:00", "microsoft"], [30, 4, 30, 4, "AMITY I 9:00 - 11:30", "amity"], [30, 4, 30, 4, "Word I 9:00 - 4:00", "amity"], [30, 4, 30, 4, "Word I 5:30 - 8:30", "microsoft"], [1, 5, 1, 5, "Excel III 9:00 - 4:00", "microsoft"], [1, 5, 1, 5, "PowerPoint I 5:30 - 8:30", "microsoft"], [2, 5, 2, 5, "Powerpoint II 9:00 - 4:00", "microsoft"], [2, 5, 2, 5, "Word I 5:30 - 8:30", "microsoft"], [3, 5, 3, 5, "AMITY II 9:00 - 11:30", "amity"], [3, 5, 3, 5, "BOSC 9:00 - 4:00", "amity"], [3, 5, 3, 5, "PowerPoint I 5:30 - 8:30", "amity"], [4, 5, 4, 5, "Access I 9:00 - 4:00", "microsoft"], [5, 5, 5, 5, "Intro to Vista II 9:00 - 11:00", "microsoft"], [7, 5, 7, 5, "Word II 9:00 - 4:00", "microsoft"], [7, 5, 7, 5, "Excel I 5:30 - 8:30", "microsoft"], [8, 5, 8, 5, "Excel I 9:00 - 4:00", "microsoft"], [8, 5, 8, 5, "Access I 5:30 - 8:30", "microsoft"], [9, 5, 9, 5, "PowerPoint III 9:00 - 4:00", "microsoft"], [9, 5, 9, 5, "Excel I 5:30 - 8:30", "microsoft"], [10, 5, 10, 5, "BOSC 9:00 - 4:00", "bosc"], [10, 5, 10, 5, "Access I 5:30 - 8:30", "bosc"], [11, 5, 11, 5, "Access II 9:00 - 4:00", "microsoft"], [12, 5, 12, 5, "Intro to Vista II 9:00 - 11:00", "microsoft"], [14, 5, 14, 5, "Word III 9:00 - 4:00", "microsoft"], [14, 5, 14, 5, "Word II 5:30 - 8:30", "microsoft"], [15, 5, 15, 5, "Excel II 9:00 - 4:00", "microsoft"], [15, 5, 15, 5, "PowerPoint II 5:30 - 8:30", "microsoft"], [16, 5, 16, 5, "PowerPoint I 9:00 - 4:00", "microsoft"], [16, 5, 16, 5, "Word II 5:30 - 8:30", "microsoft"], [17, 5, 17, 5, "BOSC 9:00 - 4:00", "bosc"], [17, 5, 17, 5, "PowerPoint II 5:30 - 8:30", "bosc"], [18, 5, 18, 5, "Access III 9:00 - 4:00", "microsoft"], [19, 5, 19, 5, "Intro to Vista I 9:00 - 11:00", "microsoft"], [21, 5, 21, 5, "Excel II 5:30 - 8:30", "microsoft"], [22, 5, 22, 5, "Access II 5:30 - 8:30", "microsoft"], [23, 5, 23, 5, "Excel II 5:30 - 8:30", "microsoft"], [24, 5, 24, 5, "BOSC 9:00 - 4:00", "bosc"], [24, 5, 24, 5, "Access II 5:30 - 8:30", "bosc"], [26, 5, 26, 5, "Intro to Vista I 9:00 - 11:00", "microsoft"], [28, 5, 28, 5, "Word I 9:00 - 4:00", "microsoft"], [28, 5, 28, 5, "Word I 5:30 - 8:30", "microsoft"], [29, 5, 29, 5, "Excel III 9:00 - 4:00", "microsoft"], [29, 5, 29, 5, "PowerPoint I 5:30 - 8:30", "microsoft"], [30, 5, 30, 5, "PowerPoint II 9:00 - 4:00", "microsoft"], [30, 5, 30, 5, "Word I 5:30 - 8:30", "microsoft"], [31, 5, 31, 5, "BOSC 9:00 - 4:00", "bosc"], [31, 5, 31, 5, "PowerPoint I 6:00 - 9:00", "bosc"], [1, 6, 1, 6, "Access I 9:00 - 4:00", "microsoft"], [2, 6, 2, 6, "Intro to Vista II 9:00 - 11:00", "microsoft"], [4, 6, 4, 6, "Word II 9:00 - 4:00", "microsoft"], [4, 6, 4, 6, "Excel I 5:30 - 8:30", "microsoft"], [5, 6, 5, 6, "Excel I 9:00 - 4:00", "microsoft"], [5, 6, 5, 6, "Access I 5:30 - 8:30", "microsoft"], [6, 6, 6, 6, "PowerPoint III 9:00 - 4:00", "microsoft"], [6, 6, 6, 6, "Excel I 5:30 - 8:30", "microsoft"], [7, 6, 7, 6, "BOSC 9:00 - 4:00", "bosc"], [7, 6, 7, 6, "Access I 5:30 - 8:30", "bosc"], [8, 6, 8, 6, "Access II 9:00 - 4:00", "microsoft"], [9, 6, 9, 6, "Intro to Vista II 9:00 - 11:00", "microsoft"], [11, 6, 11, 6, "AMITY I 9:00 - 11:30", "amity"], [11, 6, 11, 6, "Word III 9:00 - 4:00", "amity"], [11, 6, 11, 6, "Word II 5:30 - 8:30", "amity"], [11, 6, 11, 6, "AMITY I 6:00 - 8:30", "amity"], [12, 6, 12, 6, "Excel II 9:00 - 4:00", "microsoft"], [12, 6, 12, 6, "PowerPoint II 5:30 - 8:30", "microsoft"], [13, 6, 13, 6, "PowerPoint I 9:00 - 4:00", "microsoft"], [13, 6, 13, 6, "Word II 5:30 - 8:30", "microsoft"], [14, 6, 14, 6, "AMITY II 9:00 - 11:30", "amity"], [14, 6, 14, 6, "BOSC 9:00 - 4:00", "amity"], [14, 6, 14, 6, "PowerPoint II 5:30 - 8:30", "amity"], [14, 6, 14, 6, "AMITY II 6:00 - 8:30", "amity"], [15, 6, 15, 6, "Access III 9:00 - 4:00", "microsoft"], [16, 6, 16, 6, "Intro to Vista I 9:00 - 11:00", "microsoft"], [18, 6, 18, 6, "AMITY I 9:00 - 11:30", "amity"], [18, 6, 18, 6, "Excel II 5:30 - 8:30", "amity"], [18, 6, 18, 6, "AMITY I 6:00 - 8:30", "amity"], [19, 6, 19, 6, "Access II 5:30 - 8:30", "microsoft"], [20, 6, 20, 6, "Excel II 5:30 - 8:30", "microsoft"], [21, 6, 21, 6, "AMITY II 9:00 - 11:30", "amity"], [21, 6, 21, 6, "BOSC 9:00 - 4:00", "amity"], [21, 6, 21, 6, "Access II 5:30 - 8:30", "amity"], [21, 6, 21, 6, "AMITY II 6:00 - 8:30", "amity"], [23, 6, 23, 6, "Intro to Vista I 9:00 - 11:00", "microsoft"], [25, 6, 25, 6, "Word I 9:00 - 4:00", "microsoft"], [25, 6, 25, 6, "Word I 5:30 - 8:30", "microsoft"], [26, 6, 26, 6, "Excel III 9:00 - 4:00", "microsoft"], [26, 6, 26, 6, "PowerPoint I 5:30 - 8:30", "microsoft"], [27, 6, 27, 6, "PowerPoint II 9:00 - 4:00", "microsoft"], [27, 6, 27, 6, "Word I 5:30 - 8:30", "microsoft"], [28, 6, 28, 6, "BOSC 9:00 - 4:00", "bosc"], [28, 6, 28, 6, "PowerPoint I 5:30 - 8:30", "bosc"], [29, 6, 29, 6, "Access I 9:00 - 4:00", "microsoft"], [30, 6, 30, 6, "Intro to Vista II 9:00 - 11:00", "microsoft"] ]; // Format is: Appt start day, appt start month, appt end day, appt end month, appt description, appt category function init(){ if(!W3CDOM) return; printCalendar(); } function printCalendar(){ for(var i = 0; i < 12; i++){ printMonth(i); } } function printMonth(monthNum){ var month = document.getElementById(months[monthNum]); var days = month.getElementsByTagName('td'); var date = 1; var start = firstDays[monthNum] - 1; var dayText; var dayInfo; var tmpText; for(var i = 0; i < days.length; i++){ //To make the bottom row look pretty if its cells are empty days[i].innerHTML = " "; } for (i = start; date <= numDays[monthNum]; i++){ dayInfo = checkDate(monthNum, date); days[i].style.backgroundColor = dayInfo[0]; days[i].style.color = dayInfo[1]; days[i].setAttribute("title", dayInfo[2]); days[i].innerHTML = '<span style="font-weight: bold;">' + date++ + '<br /><br /><div>'; for(var j = 0; j < dayInfo[2].length; j++){ tmpText = dayInfo[2][j]; days[i].innerHTML += tmpText + '<br /><br />'; } days[i].innerHTML += '</div>'; } } function checkDate(monthNum, dayNum){ var output = new Array(); var desc = new Array(); var bgColor = ""; var color = ""; var index = 0; for(var i = 0; i < apps.length; i++){ if((monthNum + 1) >= apps[i][1] && (monthNum + 1) <= apps[i][3]){ //if we're in the range of the appointment's months if(apps[i][1] == apps[i][3]){ // if the appointment takes place in just one month if(dayNum >= apps[i][0] && dayNum <= apps[i][2]){ // setting the range of dates in that month desc[index++] = apps[i][4]; bgColor = apps[i][5]; } } else if((monthNum + 1) == apps[i][1]){ //if we're in the first month of an appointment that goes over the end of the start month if(dayNum >= apps[i][0]){ // if the date is greater or equal to the starting date of the appointment desc[index++] = apps[i][4]; bgColor = apps[i][5]; } } else if((monthNum + 1) == apps[i][3]){ // if we're in the last month of an appointment that goes over the end of the start month if(dayNum <= apps[i][2]){ // if the date is less than or equal to the ending date of the appointment desc[index++] = apps[i][4]; bgColor = apps[i][5]; } } else{ // if we're somewhere in between a multi-month appointment desc[index++] = apps[i][4]; bgColor = apps[i][5]; } } } if(bgColor == "microsoft"){ bgColor = "#284DBF"; color = "#FFFFFF"; } else if(bgColor == "amity"){ bgColor = "#D10000"; color = "#FFFFFF"; } else if(bgColor == "bosc"){ bgColor = "#000000"; color = "#FFFFFF"; } else{ bgColor = "white"; } output[0] = bgColor; output[1] = color; output[2] = desc; return output; } window.onload = init; Live CSS: .calendar{ margin: 0 0 2px 0; width: 525px; } .calendar th{ padding: 5px; border: 1px solid #000000; text-align: center; } .calendar td{ border: 1px solid #000000; } .calendar td div{ width: 80px; height: 80px; overflow: auto; } #legend{ float: right; padding: 5px; border: 1px solid #000000; } #red{ background-color: #ff0000; height: 15px; width: 15px; float: left; } #green{ background-color: green; height: 15px; width: 15px; float: left; } #gray{ background-color: gray; height: 15px; width: 15px; float: left; } #yellow{ background-color: yellow; height: 15px; width: 15px; float: left; } #purple{ background-color: purple; height: 15px; width: 15px; float: left; } p .divs{ clear: left; margin: 0; padding: 5px 0 0 0; } I didn't post the live HTML as it's identical to the test HTML. Also, there's some stuff at the end of the live CSS that I don't use, but left in the file (the stuff from #legend to the end of the file).
×
×
  • 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.