home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / calendar-2010-08-23.tar.gz / calendar-2010-08-23.tar / calendar / preferences.php < prev    next >
PHP Script  |  2003-10-12  |  14KB  |  328 lines

  1. <?php
  2.  
  3. define('BASE','./');
  4. include(BASE.'functions/ical_parser.php');
  5. $display_date = $preferences_lang;
  6.  
  7. if ($cookie_uri == '') {
  8.     $cookie_uri = $HTTP_SERVER_VARS['SERVER_NAME'].substr($HTTP_SERVER_VARS['PHP_SELF'],0,strpos($HTTP_SERVER_VARS['PHP_SELF'], '/'));
  9. }
  10.  
  11. $current_view = "preferences";
  12. $back_page = BASE.$default_view.'.php?cal='.$cal.'&getdate='.$getdate;
  13. if ($allow_preferences == 'no') header("Location: $back_page");
  14.  
  15. if (isset($HTTP_GET_VARS['action'])) {
  16.     $action = $HTTP_GET_VARS['action'];
  17. } else {
  18.     $action = '';
  19.  
  20. $startdays = array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  21.  
  22. if ($action == 'setcookie') { 
  23.     $cookie_language     = $HTTP_POST_VARS['cookie_language'];
  24.     $cookie_calendar     = $HTTP_POST_VARS['cookie_calendar'];
  25.     $cookie_view         = $HTTP_POST_VARS['cookie_view'];
  26.     $cookie_style         = $HTTP_POST_VARS['cookie_style'];
  27.     $cookie_startday    = $HTTP_POST_VARS['cookie_startday'];
  28.     $cookie_time        = $HTTP_POST_VARS['cookie_time'];
  29.     $cookie_unset        = $HTTP_POST_VARS['unset'];
  30.     $the_cookie = array ("cookie_language" => "$cookie_language", "cookie_calendar" => "$cookie_calendar", "cookie_view" => "$cookie_view", "cookie_startday" => "$cookie_startday", "cookie_style" => "$cookie_style", "cookie_time" => "$cookie_time");
  31.     $the_cookie         = serialize($the_cookie);
  32.     if ($cookie_unset) { 
  33.         setcookie("phpicalendar","$the_cookie",time()-(60*60*24*7) ,"/","$cookie_uri",0);
  34.     } else {
  35.         setcookie("phpicalendar","$the_cookie",time()+(60*60*24*7*12*10) ,"/","$cookie_uri",0);
  36.     }
  37.     $HTTP_COOKIE_VARS['phpicalendar'] = $the_cookie;
  38. }
  39.  
  40. if (isset($HTTP_COOKIE_VARS['phpicalendar'])) {
  41.     $phpicalendar         = unserialize(stripslashes($HTTP_COOKIE_VARS['phpicalendar']));
  42.     $cookie_language     = $phpicalendar['cookie_language'];
  43.     $cookie_calendar     = $phpicalendar['cookie_calendar'];
  44.     $cookie_view         = $phpicalendar['cookie_view'];
  45.     $cookie_style         = $phpicalendar['cookie_style'];
  46.     $cookie_startday    = $phpicalendar['cookie_startday'];
  47.     $cookie_time        = $phpicalendar['cookie_time'];
  48.     if ($cookie_unset) { 
  49.         unset ($cookie_language, $cookie_calendar, $cookie_view, $cookie_style,$cookie_startday);
  50.     }
  51. }
  52. #echo "$cookie_uri";
  53. #print_r(unserialize($HTTP_COOKIE_VARS['phpicalendar']));
  54. #print_r($phpicalendar);
  55.  
  56.  
  57. if ((!isset($HTTP_COOKIE_VARS['phpicalendar'])) || ($cookie_unset)) {
  58.     # No cookie set -> use defaults from config file.
  59.     $cookie_language = ucfirst($language);
  60.     $cookie_calendar = $default_cal;
  61.     $cookie_view = $default_view;
  62.     $cookie_style = $style_sheet;
  63.     $cookie_startday = $week_start_day;
  64.     $cookie_time = $day_start;
  65. }
  66.  
  67. include (BASE.'includes/header.inc.php'); 
  68.  
  69. ?>
  70. <center>
  71. <table border="0" width="700" cellspacing="0" cellpadding="0">
  72.     <tr>
  73.         <td width="520" valign="top" align="center">
  74.             <table width="640" border="0" cellspacing="0" cellpadding="0" class="calborder">
  75.                 <tr>
  76.                     <td align="center" valign="middle">
  77.                         <table width="100%" border="0" cellspacing="0" cellpadding="0">
  78.                             <tr>
  79.                                 <td align="left" width="120" class="navback"><?php echo '<a href="'.$back_page.'"><img src="'.BASE.'styles/'.$style_sheet.'/back.gif" alt=" " border="0" align="left"></a>'; ?></td>
  80.                                 <td class="navback">
  81.                                     <table width="100%" border="0" cellspacing="0" cellpadding="0">
  82.                                         <tr>
  83.                                             <td align="center" class="navback" nowrap valign="middle"><font class="H20"><?php echo "$preferences_lang"; ?></font></td>
  84.                                         </tr>
  85.                                     </table>
  86.                                 </td>
  87.                                 <td align="right" width="120" class="navback">    
  88.                                     <table width="120" border="0" cellpadding="0" cellspacing="0">
  89.                                         <tr>
  90.                                             <td><?php echo '<a class="psf" href="'.BASE.'day.php?cal='.$cal.'&getdate='.$getdate.'"><img src="'.BASE.'styles/'.$style_sheet.'/day_on.gif" alt=" " border="0"></a></td>'; ?>
  91.                                             <td><?php echo '<a class="psf" href="'.BASE.'week.php?cal='.$cal.'&getdate='.$getdate.'"><img src="'.BASE.'styles/'.$style_sheet.'/week_on.gif" alt=" " border="0"></a></td>'; ?>
  92.                                             <td><?php echo '<a class="psf" href="'.BASE.'month.php?cal='.$cal.'&getdate='.$getdate.'"><img src="'.BASE.'styles/'.$style_sheet.'/month_on.gif" alt=" " border="0"></a></td>'; ?>
  93.                                             <td><?php echo '<a class="psf" href="'.BASE.'year.php?cal='.$cal.'&getdate='.$getdate.'"><img src="'.BASE.'styles/'.$style_sheet.'/year_on.gif" alt=" " border="0"></a></td>'; ?>
  94.                                         </tr>
  95.                                     </table>
  96.                                 </td>
  97.                             </tr>
  98.                           </table>
  99.                     </td>
  100.                 </tr>
  101.                 <tr>
  102.                     <td class="dayborder"><img src="images/spacer.gif" width="1" height="5" alt=" "></td>
  103.                 </tr>
  104.                 <tr>
  105.                     <td>
  106.                         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="G10B">    
  107.                             <?php
  108.                             if ($action == 'setcookie') { 
  109.                                 if (!$cookie_unset) {
  110.                                     $message = $prefs_set_lang;
  111.                                 } else {
  112.                                     $message = $prefs_unset_lang;
  113.                                 }
  114.                             ?>
  115.                             <tr>
  116.                                 <td colspan="2" align="center"><font class="G10BOLD"><?php echo "$message"; ?></font></td>
  117.                             </tr>
  118.                             <?php } ?>
  119.                             <tr>
  120.                                 <td width="2%"></td>
  121.                                 <td width="98%" valign="top" align="left">
  122.                                 <form action="preferences.php?action=setcookie" METHOD="post">
  123.                                 <table border="0" width="620" cellspacing="2" cellpadding="2" align="center">
  124.                                     <tr>
  125.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_lang_lang"; ?></td>
  126.                                         <td align="left" valign="top" width="20"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  127.                                         <td align="left" valign="top" width="300">
  128.                                             <?php
  129.                                             
  130.                                                 // Begin Language Selection
  131.                                                 //
  132.                                                 print "<select name=\"cookie_language\" class=\"query_style\">\n";
  133.                                                 $dir_handle = @opendir(BASE.'languages/');
  134.                                                 $tmp_pref_language = urlencode(ucfirst($language));
  135.                                                 while ($file = readdir($dir_handle)) {
  136.                                                     if (substr($file, -8) == ".inc.php") {
  137.                                                         $language_tmp = urlencode(ucfirst(substr($file, 0, -8)));
  138.                                                         if ($language_tmp == $cookie_language) {
  139.                                                             print "<option value=\"$language_tmp\" selected>$language_tmp</option>\n";
  140.                                                         } else {
  141.                                                             print "<option value=\"$language_tmp\">$language_tmp</option>\n";
  142.                                                         }
  143.                                                     }
  144.                                                 }
  145.                                                 closedir($dir_handle);
  146.                                                 print "</select>\n";
  147.                                             ?>
  148.                                         </td>
  149.                                     </tr>
  150.                                     <tr>
  151.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_cal_lang"; ?></td>
  152.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  153.                                         <td align="left" valign="top">
  154.                                             <?php
  155.                                             
  156.                                                 // Begin Calendar Selection
  157.                                                 //
  158.                                                 print "<select name=\"cookie_calendar\" class=\"query_style\">\n";
  159.                                                 $dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename));
  160.                                                 $filelist = array();
  161.                                                 while ($file = readdir($dir_handle)) {
  162.                                                     if (preg_match("/^[^.].+\.ics$/", $file)) {
  163.                                                         array_push($filelist, $file);
  164.                                                     }
  165.                                                 }
  166.                                                 natcasesort($filelist);
  167.                                                 foreach ($filelist as $file) {
  168.                                                     $cal_filename_tmp = substr($file,0,-4);
  169.                                                     $cal_tmp = urlencode($cal_filename_tmp);
  170.                                                     $cal_displayname_tmp = str_replace("32", " ", $cal_filename_tmp);
  171.                                                     if (!in_array($cal_filename_tmp, $blacklisted_cals)) {
  172.                                                         if ($cal_tmp == $cookie_calendar) {
  173.                                                             print "<option value=\"$cal_tmp\" selected>$cal_displayname_tmp $calendar_lang</option>\n";
  174.                                                         } else {
  175.                                                             print "<option value=\"$cal_tmp\">$cal_displayname_tmp $calendar_lang</option>\n";    
  176.                                                         }        
  177.                                                     }    
  178.                                                 }
  179.                                                 // add option to open all (non-web) calenders together
  180.                                                 // Todo: add $all_calenders_combined_lang (plural) in the language-specific files and use it here
  181.                                                 if ($cookie_calendar == $ALL_CALENDARS_COMBINED) {
  182.                                                     print "<option value=\"$ALL_CALENDARS_COMBINED\" selected>$all_cal_comb_lang</option>\n";
  183.                                                 } else {
  184.                                                     print "<option value=\"$ALL_CALENDARS_COMBINED\">$all_cal_comb_lang</option>\n";
  185.                                                 }
  186.             
  187.                                                 foreach($list_webcals as $cal_tmp) {
  188.                                                     if ($cal_tmp != '') {
  189.                                                         $cal_displayname_tmp = basename($cal_tmp);
  190.                                                         $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp);
  191.                                                         $cal_displayname_tmp = substr($cal_displayname_tmp,0,-4);
  192.                                                         $cal_encoded_tmp = urlencode($cal_tmp);
  193.                                                         if ($cal_tmp == $cal_httpPrefix || $cal_tmp == $cal_webcalPrefix) {
  194.                                                             print "<option value=\"$cal_encoded_tmp\" selected>$cal_displayname_tmp Webcal</option>\n";
  195.                                                         } else {
  196.                                                             print "<option value=\"$cal_encoded_tmp\">$cal_displayname_tmp Webcal</option>\n";    
  197.                                                         }        
  198.                                                     }
  199.                                                 }
  200.                                                 closedir($dir_handle);
  201.                                                 print "</select>\n";
  202.                                             ?>
  203.                                         </td>
  204.                                     </tr>
  205.                                     <tr>
  206.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_view_lang"; ?></td>
  207.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  208.                                         <td align="left" valign="top">
  209.                                             <?php
  210.                                             
  211.                                                 // Begin View Selection
  212.                                                 //
  213.                                                 print "<select name=\"cookie_view\" class=\"query_style\">\n";
  214.                                                 print "<option value=\"day\"";
  215.                                                 if ($cookie_view == "day") print " selected";
  216.                                                 print ">$day_lang</option>\n";
  217.                                                 print "<option value=\"week\"";
  218.                                                 if ($cookie_view == "week") print " selected";
  219.                                                 print ">$week_lang</option>\n";
  220.                                                 print "<option value=\"month\"";
  221.                                                 if ($cookie_view == "month") print " selected";
  222.                                                 print ">$month_lang</option>\n";
  223.                                                 //print "<option value=\"print\"";
  224.                                                 //if ($cookie_view == "print") print " selected";
  225.                                                 //print ">$printer_lang</option>\n";
  226.                                                 print "</select>\n";
  227.                                             ?>
  228.                                         </td>
  229.                                     </tr>
  230.                                     <tr>
  231.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_time_lang"; ?></td>
  232.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  233.                                         <td align="left" valign="top">
  234.                                             <?php
  235.                                             
  236.                                                 // Begin Time Selection
  237.                                                 //
  238.                                                 print "<select name=\"cookie_time\" class=\"query_style\">\n";
  239.                                                 for ($i = 500; $i <= 900; $i += 100) {
  240.                                                     $s = sprintf("%04d", $i);
  241.                                                     print "<option value=\"$s\"";
  242.                                                     if ($s == $cookie_time) {
  243.                                                         print " selected";
  244.                                                     }
  245.                                                     print ">$s</option>\n";
  246.                                                 }
  247.                                                 print "</select>\n";
  248.                                             ?>
  249.                                         </td>
  250.                                     </tr>
  251.                                     <tr>
  252.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_day_lang"; ?></td>
  253.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  254.                                         <td align="left" valign="top">
  255.                                             <?php
  256.                                                 
  257.                                                 // Begin Day Start Selection
  258.                                                 //
  259.                                                 print "<select name=\"cookie_startday\" class=\"query_style\">\n";
  260.                                                 $i=0;
  261.                                                 foreach ($daysofweek_lang as $daysofweek) {
  262.                                                     if ($startdays[$i] == "$cookie_startday") {
  263.                                                         print "<option value=\"$startdays[$i]\" selected>$daysofweek</option>\n";
  264.                                                     } else {
  265.                                                         print "<option value=\"$startdays[$i]\">$daysofweek</option>\n";
  266.                                                     }
  267.                                                     $i++;
  268.                                                 }
  269.                                                 print "</select>\n";
  270.                                             ?>
  271.                                         </td>
  272.                                     </tr>
  273.                                     <tr>
  274.                                         <td align="left" valign="top" width="300" nowrap><?php echo "$select_style_lang"; ?></td>
  275.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  276.                                         <td align="left" valign="top">
  277.                                             <?php
  278.                                             
  279.                                                 // Begin Style Selection
  280.                                                 //
  281.                                                 print "<select name=\"cookie_style\" class=\"query_style\">\n";
  282.                                                 $dir_handle = @opendir(BASE.'styles/');
  283.                                                 while ($file = readdir($dir_handle)) {
  284.                                                     if (($file != ".") && ($file != "..") && ($file != "CVS")) {
  285.                                                         if (!is_file($file)) {
  286.                                                             $file_disp = ucfirst($file);
  287.                                                             if ($file == "$cookie_style") {
  288.                                                                 print "<option value=\"$file\" selected>$file_disp</option>\n";
  289.                                                             } else {
  290.                                                                 print "<option value=\"$file\">$file_disp</option>\n";
  291.                                                             }
  292.                                                         }
  293.                                                     }
  294.                                                 }
  295.                                                 closedir($dir_handle);
  296.                                                 print "</select>\n";
  297.                                             ?>
  298.                                         </td>
  299.                                     </tr>
  300.                                     <?php if (isset($HTTP_COOKIE_VARS['phpicalendar'])) { ?>
  301.                                     <tr>
  302.                                         <td align="left" valign="top" nowrap><?php echo "$unset_prefs_lang"; ?></td>
  303.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  304.                                         <td align="left" valign="top"><INPUT TYPE="checkbox" NAME="unset" VALUE="true"></td>
  305.                                     </tr>
  306.                                     <?php } ?>
  307.                                     <tr>
  308.                                         <td align="left" valign="top" nowrap> </td>
  309.                                         <td align="left" valign="top"><img src="images/spacer.gif" alt=" " width="20" height="1" border="0"></td>
  310.                                         <td align="left" valign="top"><input type="submit" name="set" value="<?php echo "$set_prefs_lang"; ?>"></button></td>
  311.                                     </tr>
  312.                                 </table>
  313.                                 </form>
  314.                                 <br>
  315.                                 </td>
  316.                             </tr>
  317.                         </table>
  318.                     </td>
  319.                 </tr>
  320.             </table>
  321.         </td>
  322.     </tr>
  323. </table>
  324. </center>
  325. <?php include (BASE.'includes/footer.inc.php'); ?>
  326.  
  327.