4 nikkipost.php - Control panel for O-Kiraku Nikki
5 Copyright (C) 2003 Javi Lavandeira (http://www.ag0ny.com)
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //require 'nikki.conf.php';
24 $default_language = 'en';
26 if (isset($_GET['lang']))
28 $lang = $_GET['lang'];
30 if (isset($_SESSION['lang']))
32 $lang = $_SESSION['lang'];
34 $lang = $GLOBALS['default_language'];
38 #$lang = isset($_GET['lang'])?$_GET['lang']:isset($_SESSION['lang'])?$_SESSION['lang']:$GLOBALS['default_language'];
43 $language_dir = 'de_DE';
44 $_SESSION['lang'] = 'de';
47 $language_dir = 'es_ES';
48 $_SESSION['lang'] = 'es';
51 $language_dir = 'it_IT';
52 $_SESSION['lang'] = 'it';
55 $language_dir = 'ja_JP';
56 $_SESSION['lang'] = 'ja';
59 $language_dir = 'nl_NL';
60 $_SESSION['lang'] = 'nl';
63 $language_dir = 'sv_SE';
64 $_SESSION['lang'] = 'sv';
68 $language_dir = 'en_US';
69 $_SESSION['lang'] = 'en';
73 //putenv("LANG=$language_dir");
74 //setlocale(LC_ALL, "$language_dir");
75 //bindtextdomain("nikki", $GLOBALS['prefix']."/locale");
76 //textdomain("nikki");
78 $program_version = "program_name";
80 //header('Content-Type: text/html; charset=UTF-8');
82 $month[0] = "January";
83 $month[1] = "February";
90 $month[8] = "September";
91 $month[9] = "October";
92 $month[10] = "November";
93 $month[11] = "December";
94 $week_day[0] = "Sunday";
95 $week_day[1] = "Monday";
96 $week_day[2] = "Tuesday";
97 $week_day[3] = "Wednesday";
98 $week_day[4] = "Thursday";
99 $week_day[5] = "Friday";
100 $week_day[6] = "Saturday";
101 $week_day_abb[0] = "Sun";
102 $week_day_abb[1] = "Mon";
103 $week_day_abb[2] = "Tue";
104 $week_day_abb[3] = "Wed";
105 $week_day_abb[4] = "Thu";
106 $week_day_abb[5] = "Fri";
107 $week_day_abb[6] = "Sat";
118 $month_days[10] = 30;
119 $month_days[11] = 31;
121 $border_color = '#000000';
123 //connect_to_database();
125 function connect_to_database()
127 if ($descriptor = mysql_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_user'], $GLOBALS['mysql_password']))
129 mysql_query('USE '.$GLOBALS['mysql_database']);
137 # Input: $year Year in 4 digits format (ie: 2000, 1999...)
138 # $month Month (1-12)
139 function calendar_display_month($bg_line)
141 $day_id = calendar_get_date();
142 $year = abs(substr($day_id,0,4));
143 $month = abs(substr($day_id,4,2));
145 $attributes = localtime(mktime(0,0,1, $month, 1, $year), 1);
146 $start_day = $attributes['tm_wday'];
147 $month_name = date("F",strtotime($_SESSION["caltime"]));
148 //$GLOBALS['month'][$month-1];
149 $days_this_month = $GLOBALS['month_days'][$month-1];
151 # is this a leap year?
154 $days_this_month = ($year/4 == (int)($year/4) && ($year/100 != (int)($year/100) || $year/400 == (int)($year/400)))?29:28;
157 $today = localtime(time(), 1);
159 echo '<table border="0" cellspacing="1" cellpadding="1" '.$bg_line.'>';
161 echo '<td colspan="1">';
162 echo calendar_link_previous_month('<');
164 echo '<td colspan="5" align=center class="text">';
165 echo $month_name.' ('.$year.') ';
167 echo '<td colspan="1">';
168 echo calendar_link_next_month('>');
172 # Print weekday abbreviations
174 for ($column = 0; $column < 7; $column++)
176 echo '<td class="small">';
177 #echo $GLOBALS['week_day_abb'][$column];
178 echo $GLOBALS['week_day_abb'][($column + $GLOBALS['week_start']) % 7];
185 while ($column < ($start_day - $GLOBALS['week_start']))
187 echo '<td class="text"> </td>';
192 for ($day = 1; $day <= $days_this_month; $day++)
194 $day_index = date("Y-m",strtotime($_SESSION["caltime"]))."-".$time.substr('00'.abs($day), -2, 2);
195 if (($column>0) && ($column%7 == 0)) echo '</tr><tr>';
197 $check_wend = getdate(mktime(0,0,0,$month, $day, $year));
198 $weekend = (($check_wend['wday'] == 0) || ($check_wend['wday'] == 6))?1:0;
200 $its_today = ($today['tm_mday'] == $day && $today['tm_mon'] == ($month-1) && ($today['tm_year'] + 1900) == $year)?1:0;
201 $theres_text = isset($calendar_id[$day_index])?1:0;
202 if (isset($_GET['day_id']))
204 $is_selected = abs(substr($_GET['day_id'],-2,2) == $day)?1:0;
206 $is_selected = ($today['tm_mday'] == $day)?1:0;
210 //if (isset($calendar_id[$day_index]))
212 // echo '<a href="'.$GLOBALS['PHP_SELF'].'?lang='.$GLOBALS['lang'].'&day_id='.$day_index.'">'.$day.'</a>';
214 echo '<a class=small href="'.$GLOBALS['PHP_SELF'].'?viewmode=daily&mode=settime&caltime='.$day_index.'">'.$day.'</a>';
220 while ($column % 7 > 0)
222 echo '<td class="text"> </td>';
229 function calendar_display_entries()
231 $day_id = calendar_get_date();
232 $entries = mysql_query('SELECT * FROM nikki WHERE timestamp=\''.$day_id.'\' ORDER BY id');
233 if (mysql_num_rows($entries))
235 $year = abs(substr($day_id, 0, 4));
236 $month = abs(substr($day_id, 4, 2));
237 $day = abs(substr($day_id, 6, 2));
238 printf("today_date", $year, $month, $day);
240 $calendar_id = array();
241 while ($object = mysql_fetch_object($entries))
243 echo $object->text.'<br><br>';
248 function calendar_link_previous_month($text)
250 $day_id = calendar_get_date();
251 $year = abs(substr($day_id, 0, 4));
252 $month = abs(substr($day_id, 4, 2));
253 $day = abs(substr($day_id, 6, 2));
255 $month = ($month == 1)?12:$month-1;
256 $year = ($month == 12)?$year-1:$year;
258 $day_index = substr('0000'.$year,-4,4)."-".substr('00'.$month,-2,2)."-".substr('00'.$day,-2,2);
259 echo '<a class=bold href="'.$GLOBALS['PHP_SELF'].'?mode=settime&caltime='.$day_index.'">'.$text.'</a>';
262 function calendar_link_next_month($text)
264 $day_id = calendar_get_date();
265 $year = abs(substr($day_id, 0, 4));
266 $month = abs(substr($day_id, 4, 2));
267 $day = abs(substr($day_id, 6, 2));
269 $month = ($month == 12)?1:$month+1;
270 $year = ($month == 1)?$year+1:$year;
272 $day_index = substr('0000'.$year,-4,4)."-".substr('00'.$month,-2,2)."-".substr('00'.$day,-2,2);
273 echo '<a class=bold href="'.$GLOBALS['PHP_SELF'].'?mode=settime&caltime='.$day_index.'">'.$text.'</a>';
276 function calendar_get_date()
279 if (isset($GLOBALS['day_id']))
281 return $GLOBALS['day_id'];
283 return isset($_GET['day_id'])?addslashes($_GET['day_id']):date('Ymd');
287 return date("Ymd",strtotime($_SESSION["caltime"]));