login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Kalenders > Weekkalender

Weekkalender

Auteur: vinTage - 01 januari 2012 - 21:39 - Gekeurd door: Stijn - Hits: 6113 - Aantal punten: 5.00 (1 stem)




Een 'makkelijke' weekkalender.
De database:
  1. CREATE TABLE `planning` (
  2. `datum` VARCHAR(10) NOT NULL,
  3. `adres` VARCHAR(250) NOT NULL,
  4. `msg` VARCHAR(750) NOT NULL
  5. )


Het script is gewoon copy/pasten en de database gegevenns aanpassen en gaan met die banaan kalender

Code:
  1. <?php
  2. //onderstaande 2 regels aanpassen
  3. mysql_connect('host', 'usernaam', 'password');
  4. mysql_select_db('database');
  5.  
  6. //af! :P
  7. $jaar = isset($_GET['jaar']) ? $_GET['jaar'] : date('Y');
  8. $week = isset($_GET['week']) ? $_GET['week'] : date('W');
  9. if ($week < 1)
  10. {
  11. $jaar -= 1;
  12. $week = date("W", mktime(0, 0, 0, 12, 28, $jaar));
  13. }
  14. elseif ($week > date("W", mktime(0, 0, 0, 12, 28, $jaar)))
  15. {
  16. $week = 1;
  17. $jaar += 1;
  18. }
  19. if (isset($_POST['opslaan']))
  20. {
  21. $qry = mysql_query("select datum from planning where datum = '" . mysql_real_escape_string($_GET['edit']) . "'") or die(mysql_error());
  22. if (mysql_num_rows($qry) > 0)
  23. {
  24. mysql_query("update planning set adres = '" . mysql_real_escape_string($_POST['adres']) . "',
  25. msg = '" . mysql_real_escape_string($_POST['msg']) . "' where datum ='" . mysql_real_escape_string($_POST['datum']) . "'") or die(mysql_error());
  26. header("location: ?jaar=" . $jaar . "&week=" . $week);
  27. }
  28. else
  29. {
  30. mysql_query("insert into planning (datum, adres, msg)
  31. values('" . mysql_real_escape_string($_GET['edit']) . "',
  32. '" . mysql_real_escape_string($_POST['adres']) . "',
  33. '" . mysql_real_escape_string($_POST['msg']) . "')") or die(mysql_error());
  34. header("location: ?jaar=" . $jaar . "&week=" . $week);
  35. }
  36. }
  37. //de html en css hieronder mag je editen, van de php afblijven als je niet weet waar het over gaat :p
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml">
  41. <head>
  42. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  43. <title>planning</title>
  44. <style type="text/css">
  45. *{ margin:0; padding:0;}
  46. body{font-family:Verdana, Geneva, sans-serif; font-size:small;}
  47. .border{border:solid 2px #000;}
  48. .br{border-right:solid 1px #000;}
  49. .bl{border-left:solid 1px #000;}
  50. .bb{border-bottom:solid 1px #000;}
  51. .bbd{border-bottom:solid 2px #000;}
  52. td{padding-left:2px; padding-right:2px;}
  53. .active{background-color:#f5f5f5;}
  54. #wrap{
  55. width:1004px;
  56. margin:0 auto;
  57. margin-top: 10px;
  58. }
  59. a:link {
  60. color: #EA960B;;
  61. text-decoration: none;
  62. }
  63. a:visited {
  64. color: #EA960B;;
  65. text-decoration: none;
  66. }
  67. a:hover {
  68. text-decoration: underline;
  69. color: #EA960B;
  70. }
  71. a:active {
  72. text-decoration: underline;
  73. color: #EA960B;
  74. }
  75. b{color: #39f;}
  76. </style>
  77.  
  78. <style type="text/css" media="print">
  79. .noprint{display:none;}
  80. input[type=text]{display:none}
  81. b{color:#000}
  82. </style>
  83. </head>
  84.  
  85. <body>
  86. <div id="wrap">
  87. <div class="noprint">
  88. Week nr: <a href="?jaar=<?php echo $jaar?>&amp;week=<?php echo $week-1?>">&laquo; </a><?php echo $week?><a href="?jaar=<?php echo $jaar?>&amp;week=<?php echo $week+1?>"> &raquo;</a>
  89. <br />
  90. Jaar: <a href="?jaar=<?php echo $jaar-1?>&amp;week=<?php echo $week?>">&laquo; </a><?php echo $jaar?><a href="?jaar=<?php echo $jaar+1?>&amp;week=<?php echo $week?>"> &raquo;</a>
  91. <?php
  92. if($jaar != date("Y") || $week != date("W"))
  93. {
  94. ?>
  95. <br />
  96. <a href="<?php echo $_SERVER['SCRIPT_NAME']?>">Terug naar huidige week</a>
  97. <?php
  98. }
  99. ?>
  100. <br />
  101. <br />
  102. </div>
  103. <?php
  104. function maak_datums($year, $weeknr, $dag, $dagnaam = false)
  105. {
  106. $dagen = array("maandag", "dinsdag", "woensdag", "donderdag", "vrijdag");
  107. $w = $weeknr - 1;
  108. return $dagnaam != false ? $dagen[$dag] . '<br />' . date("d-m-Y", strtotime("first monday January $year + $w weeks + $dag days")) : date("d-m-Y", strtotime("first monday January $year + $w weeks + $dag days"));
  109. }
  110.  
  111. if (isset($_GET['edit']))
  112. {
  113. ?>
  114. <form method="post" action="<?php echo htmlentities($_SERVER['REQUEST_URI'])?>">
  115. <?php
  116. }
  117. ?>
  118. <table width="1000" border="0" cellspacing="0" cellpadding="0" class="border">
  119. <tr>
  120. <td class="br bbd" width="80" valign="top"><b>Datum</b></td>
  121. <td class="br bbd" width="300"><b>Wie &amp; waar</b></td>
  122. <td class="bbd"><b>Werkzaamheden</b></td>
  123. </tr>
  124. <?php
  125. for ($i = 0; $i < 5; $i++)
  126. {
  127. $adres = '';
  128. $msg = '';
  129. $link_datum = maak_datums($jaar, $week, $i);
  130.  
  131. $q = mysql_query("select * from planning where datum = '" . $link_datum . "'") or die(mysql_error());
  132. while ($row = mysql_fetch_array($q))
  133. {
  134. $adres = isset($_GET['edit']) ? $row['adres'] : nl2br(htmlentities($row['adres']));
  135. $msg = isset($_GET['edit']) ? $row['msg'] : nl2br(htmlentities($row['msg']));
  136. }
  137. ?>
  138. <tr<?php if(isset($_GET['edit']) && $_GET['edit'] == $link_datum){?> class="active"<?php } ?> style="height:130px">
  139. <td class="br <?php if($i <4){echo 'bbd';}?>" valign="top">
  140. <?php echo maak_datums($jaar, $week, $i) == date("d-m-Y") ? "<b class='noprint'>vandaag<br /><br /></b>".maak_datums($jaar, $week, $i, true)."<br />" : maak_datums($jaar, $week, $i, true)."<br />";
  141. if(isset($_GET['week']) && isset($_GET['jaar']))
  142. {
  143. ?>
  144. <a href="?jaar=<?php echo $_GET['jaar']?>&amp;week=<?php echo $_GET['week']?>&amp;edit=<?php echo $link_datum?>" class="noprint">edit</a>
  145. <?php
  146. }
  147. else
  148. {
  149. ?>
  150. <a href="?edit=<?php echo $link_datum?>" class="noprint">edit</a>
  151. <?php
  152. }
  153. if(isset($_GET['edit']) && $_GET['edit'] == $link_datum)
  154. {
  155. ?>
  156. <input name="opslaan" type="submit" value="bijwerken" /><input type="hidden" name="datum" value="<?php echo $link_datum?>" />
  157. <?php
  158. }
  159. ?>
  160. </td>
  161. <td class="br <?php if($i <4){echo 'bbd';}?>" valign="top"><?php if(isset($_GET['edit']) && $_GET['edit'] == $link_datum){?><textarea name="adres" rows="4" cols="25"><?php echo stripslashes($adres);?></textarea><?php } else { echo stripslashes($adres);}?></td>
  162. <td class="<?php if($i <4){echo 'bbd';}?>" valign="top"><?php if(isset($_GET['edit']) && $_GET['edit'] == $link_datum){?><textarea name="msg" rows="4" cols="25"><?php echo stripslashes($msg);?></textarea><?php } else { echo stripslashes($msg);}?></td>
  163. </tr>
  164. <?php
  165. }
  166. ?>
  167. </table>
  168. <?php
  169. if(isset($_GET['edit']))
  170. {
  171. ?>
  172. </form>
  173. <?php
  174. }
  175. ?>
  176. </div>
  177. </body>
  178. </html>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (3)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.039s