home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / edit_calendar.php < prev    next >
Encoding:
PHP Script  |  2003-12-22  |  9.9 KB  |  273 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/edit_calendar.php
  5. //
  6. //    (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL 
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE: source/edit_calendar.php
  19.     PURPOSE:
  20.         Provide an interface for viewing/adding/updating calendar items.
  21.     PRE-CONDITIONS:
  22.         $user - Session ID
  23.         [$edit] - $id of item to modify or update (-1 means "new")
  24.     POST-CONDITIONS:
  25.         POST's data to calendar.php, which makes the requested changes.
  26.     COMMENTS:
  27.         This program is essentially a wrapper/shell for other scripts that provide
  28.         actual functionality.
  29.  
  30. ********************************************************/
  31.  
  32. function ShowTimeWiget($hour_name, $hour, $minute_name, $minute){
  33.     global $my_prefs, $lang_datetime;
  34.     
  35.     $system = $my_prefs["clock_system"];
  36.     $ampm = $lang_datetime["ampm"];
  37.     $format = $lang_datetime["hour_format"];
  38.     
  39.     echo "<select name=\"$hour_name\">\n";
  40.     for ($i=0;$i<24;$i++){
  41.         echo "<option value=\"$i\" ".($i==$hour?"SELECTED":"").">";
  42.         echo LangFormatIntTime($i."00", $system, $ampm, $format)."\n";
  43.     }
  44.     echo "</select>\n";
  45.     echo ":<select name=\"$minute_name\">\n";
  46.     for ($i=0;$i<60;$i=$i+5){
  47.         echo "<option ".($i==$minute?"SELECTED":"").">".($i<10?"0":"")."$i\n";
  48.     }
  49.     echo "</select>\n";
  50. }
  51.  
  52. include("../include/super2global.inc");
  53. include("../include/header_main.inc");
  54. include("../lang/".$my_prefs["lang"]."dates.inc");
  55. include("../lang/".$my_prefs["lang"]."calendar.inc");
  56.  
  57. //include calendar commons
  58. include("../include/calendar.inc");
  59.  
  60. //authenticate
  61. include_once("../include/icl.inc");
  62. $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  63. if ($conn){
  64.     iil_Close($conn);
  65. }else{
  66.     echo "Authentication failed.";
  67.     echo "</html>\n";
  68.     exit;
  69. }
  70.  
  71.  
  72. //open backend connection
  73. include_once("../conf/db_conf.php");
  74. include_once("../include/idba.$DB_TYPE.inc");
  75. include_once("../include/array2sql.inc");
  76.  
  77. $db = new idba_obj;
  78. if (!$db->connect()){
  79.     echo "DB connection failed.";
  80.     exit;
  81. }
  82.  
  83.  
  84. //do calendar stuff
  85. if (isset($date)){
  86.     $start_year = substr($date, 0, 4);
  87.     $start_month = substr($date, 4, 2);
  88.     $start_day = substr($date, 6, 2);
  89.             
  90.     $end_year = $start_year;
  91.     $end_month = $start_month;
  92.     $end_day = $start_day;
  93. }
  94.  
  95.     if ($edit>0){
  96.         $backend_result = false;
  97.         $backend_query = "SELECT * FROM $DB_CALENDAR_TABLE WHERE userID='$session_dataID' and id='$edit'";;
  98.         $backend_result = $db->query($backend_query);
  99.                 
  100.         if (($backend_result) && ($db->num_rows($backend_result)>0)){
  101.             $data = $db->fetch_row($backend_result); 
  102.             extract($data);
  103.             //while ( list($var,$val) = each($data) ) $$var=$val;
  104.             
  105.             $start_hour = (int)($beginTime / 100);
  106.             $start_minute = $beginTime % 100;
  107.  
  108.             $end_hour = (int)($endTime / 100);
  109.             $end_minute = $endTime % 100;
  110.             
  111.             $start_year = substr($beginDate, 0, 4);
  112.             $start_month = substr($beginDate, 4, 2);
  113.             $start_day = substr($beginDate, 6, 2);
  114.  
  115.             $end_year = substr($endDate, 0, 4);
  116.             $end_month = substr($endDate, 4, 2);
  117.             $end_day = substr($endDate, 6, 2);
  118.  
  119.             if (!empty($pattern)){
  120.                 $words = explode(" ", $pattern);
  121.                 while( list($k,$w)=each($words) ){
  122.                     if ($w[0]=="d") $dowpat=$w;
  123.                     if ($w[0]=="w") $wompat=$w;
  124.                 }
  125.  
  126.                 //days of week
  127.                 $dowpat = substr($dowpat, 2);
  128.                 $dows = explode(",", $dowpat);
  129.                 while( list($k, $d)=each($dows) ) $repeat_d[$d]=1;
  130.  
  131.                 //weeks in month
  132.                 $woms = explode(",", $wompat);
  133.                 while( list($k, $d)=each($woms) ) $repeat_w[$d[1]]=1;
  134.                 
  135.                 if (strpos($pattern, "m:")!==false) $repeat_monthly = 1;
  136.                 if (strpos($pattern, "y:")!==false) $repeat_yearly = 1;
  137.             }
  138.         }else{
  139.             echo $error;
  140.             if (empty($error)) "Invalid item, or access denied";
  141.             $edit="";
  142.         }
  143.     }
  144.  
  145. $cal_colors = array("#990000"=>"Dark Red", "#FF0000"=>"Red", "#000099"=>"Deep Blue", "#0000FF"=>"Blue", 
  146.                     "#006600"=>"Dark Green", "#00FF00"=>"Green", "#9900FF"=>"Purple", "#00FFFF"=>"Cyan",
  147.                     "#FF6600"=>"Orange", "#FFFF00"=>"Yellow", "#FF00FF"=>"Magenta", ""=>"No color");
  148. $cal_colors = $calStr["colors"];
  149.  
  150. ?>
  151. <table width="100%" cellpadding=2 cellspacing=0><tr bgcolor="<?php echo $my_colors["main_head_bg"]?>">
  152. <td align=left valign=bottom>
  153. <span class="bigTitle">
  154. <?php echo ($edit>0?$calStr["edit_schedule"]:$calStr["add_schedule"]); ?>
  155. </span>
  156. </td></tr></table>    
  157.  
  158. <FORM ACTION="calendar.php" METHOD=POST>
  159.     <input type="hidden" name="user" value="<?php echo $user; ?>">
  160.     <input type="hidden" name="delete_item" value="<?php echo $edit; ?>">    
  161.     <input type="hidden" name="edit" value="<?php echo $edit; ?>">
  162. <table>
  163.     <tr>
  164.         <td class=mainLight align="right" valign="top"><?php echo $calStr["title"]?></td>
  165.         <td class=mainLight valign="top" valign="top"><input type="text" name="title" value="<?php echo $title ?>"></td>
  166.         <td class=mainLight align="right" valign="top"><?php echo $calStr["color"]?></td>
  167.         <td class=mainLight valign="top" valign="top">
  168.         <select name="color">
  169.         <?php
  170.         while ( list($value,$label)=each($cal_colors) ){
  171.             echo "<option value=\"$value\" ".($value==$color?"SELECTED":"").">$label\n";
  172.         }
  173.         ?>
  174.         </select>
  175.         </td>
  176.     </tr>
  177.     <tr>
  178.         <td class=mainLight align="right" valign="top"><?php echo $calStr["starts"]?></td>
  179.         <td class=mainLight align="left" valign="top">
  180.             <input type="text" name="start_month" value="<?php echo $start_month ?>" size=2>
  181.             /<input type="text" name="start_day" value="<?php echo $start_day ?>" size=2>
  182.             /<input type="text" name="start_year" value="<?php echo $start_year ?>" size=4>
  183.         </td>
  184.         <td class=mainLight align="right" valign="top"><?php echo $calStr["ends"]?></td>
  185.         <td class=mainLight align="left" valign="top">
  186.             <input type="text" name="end_month" value="<?php echo $end_month ?>" size=2>
  187.             /<input type="text" name="end_day" value="<?php echo $end_day ?>" size=2>
  188.             /<input type="text" name="end_year" value="<?php echo $end_year ?>" size=4>
  189.         </td>        
  190.     </tr>
  191.     <tr>
  192.         <td class=mainLight align="right" valign="top"><?php echo $calStr["from"]?></td>
  193.         <td class=mainLight align="left" valign="top">
  194.             <?php
  195.             ShowTimeWiget("start_hour", $start_hour, "start_minute", $start_minute);
  196.             ?>
  197.         </td>
  198.         <td class=mainLight align="right" valign="top"><?php echo $calStr["until"]?></td>
  199.         <td class=mainLight align="left" valign="top">
  200.             <?php
  201.             ShowTimeWiget("end_hour", $end_hour, "end_minute", $end_minute);
  202.             ?>
  203.         </td>        
  204.     </tr>
  205.     <tr>
  206.         <td class=mainLight align="right" valign="top"> </td>
  207.         <td class=mainLight align="left" valign="top" colspan="3">
  208.         <hr>
  209.         </td>        
  210.     </tr>
  211.     <tr>
  212.         <td class=mainLight align="right" valign="top"><?php echo $calStr["repeat_on"]?></td>
  213.         <td class=mainLight align="left" valign="top">
  214.             <input type="checkbox" name="repeat_d[0]" value=1 <?php echo ($repeat_d[0]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][0]?>
  215.             <br><input type="checkbox" name="repeat_d[1]" value=1 <?php echo ($repeat_d[1]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][1]?>
  216.             <br><input type="checkbox" name="repeat_d[2]" value=1 <?php echo ($repeat_d[2]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][2]?>
  217.             <br><input type="checkbox" name="repeat_d[3]" value=1 <?php echo ($repeat_d[3]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][3]?>
  218.             <br><input type="checkbox" name="repeat_d[4]" value=1 <?php echo ($repeat_d[4]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][4]?>
  219.             <br><input type="checkbox" name="repeat_d[5]" value=1 <?php echo ($repeat_d[5]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][5]?>
  220.             <br><input type="checkbox" name="repeat_d[6]" value=1 <?php echo ($repeat_d[6]?"CHECKED":"") ?>><?php echo $lang_datetime["dsowl"][6]?>
  221.         </td>
  222.         <td class=mainLight align="right" valign="top"><?php echo $calStr["of"]?></td>
  223.         <td class=mainLight align="left" valign="top">
  224.             <input type="checkbox" name="repeat_w[1]" value="1" <?php echo ($repeat_w[1]?"CHECKED":"") ?>><?php echo $calStr["weeks"][1]?>
  225.             <br><input type="checkbox" name="repeat_w[2]" value="1" <?php echo ($repeat_w[2]?"CHECKED":"") ?>><?php echo $calStr["weeks"][2]?>
  226.             <br><input type="checkbox" name="repeat_w[3]" value="1" <?php echo ($repeat_w[3]?"CHECKED":"") ?>><?php echo $calStr["weeks"][3]?>
  227.             <br><input type="checkbox" name="repeat_w[4]" value="1" <?php echo ($repeat_w[4]?"CHECKED":"") ?>><?php echo $calStr["weeks"][4]?>
  228.             <br><?php echo $calStr["week_blurb"]?>
  229.         </td>
  230.     </tr>
  231.     <tr>
  232.         <td class=mainLight align="right" valign="top"> </td>
  233.         <td class=mainLight align="left" valign="top" colspan="3">
  234.         <hr>
  235.         </td>        
  236.     </tr>
  237.     <tr>
  238.         <td class=mainLight align="right" valign="top"></td>
  239.         <td class=mainLight align="left" valign="top" colspan="3">
  240.             <input type="checkbox" name="repeat_monthly" value=1 <?php echo ($repeat_monthly?"CHECKED":"") ?>><?php echo $calStr["monthly"]?>
  241.             <br><input type="checkbox" name="repeat_yearly" value=1 <?php echo ($repeat_yearly?"CHECKED":"") ?>><?php echo $calStr["yearly"]?>
  242.         </td>
  243.     </tr>
  244.     <tr>
  245.         <td class=mainLight align="right" valign="top"> </td>
  246.         <td class=mainLight align="left" valign="top" colspan="3">
  247.         <hr>
  248.         </td>        
  249.     </tr>
  250.     <tr>
  251.         <td class=mainLight align="right" valign="top"><?php echo $calStr["place"]?></td>
  252.         <td class=mainLight align="left" valign="top" colspan="3">
  253.             <textarea name="place" cols="50" rows="4"><?php echo htmlspecialchars($place) ?></textarea>
  254.         </td>
  255.     </tr>
  256.     <tr>
  257.         <td class=mainLight align="right" valign="top"><?php echo $calStr["description"]?></td>
  258.         <td class=mainLight align="left" valign="top" colspan="3">
  259.             <textarea name="description" cols="50" rows="6"><?php echo htmlspecialchars($description) ?></textarea>
  260.         </td>
  261.     </tr>
  262. <table>
  263. <table width="50%"><tr>
  264. <td align="left"><input type="submit" name="edit_cal" value="<?php echo ($edit>0?$calStr["update"]:$calStr["add"])?>"></td>
  265. <td align="right">
  266. <?php
  267. if ($edit>0) echo '<input type="submit" name="delete_cal" value="'.$calStr["Delete"].'">';
  268. ?>
  269. </td>
  270. </tr></table>
  271. </FORM>
  272. </body>
  273. </html>