3 nikkipost.php - Control panel for O-Kiraku Nikki
4 Copyright (C) 2003 Javi Lavandeira (http://www.ag0ny.com)
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //require 'nikki.conf.php';
23 $default_language = 'en';
25 if (isset($_GET['lang']))
27 $lang = $_GET['lang'];
29 if (isset($_SESSION['lang']))
31 $lang = $_SESSION['lang'];
33 $lang = $GLOBALS['default_language'];
37 #$lang = isset($_GET['lang'])?$_GET['lang']:isset($_SESSION['lang'])?$_SESSION['lang']:$GLOBALS['default_language'];
42 $language_dir = 'de_DE';
43 $_SESSION['lang'] = 'de';
46 $language_dir = 'es_ES';
47 $_SESSION['lang'] = 'es';
50 $language_dir = 'it_IT';
51 $_SESSION['lang'] = 'it';
54 $language_dir = 'ja_JP';
55 $_SESSION['lang'] = 'ja';
58 $language_dir = 'nl_NL';
59 $_SESSION['lang'] = 'nl';
62 $language_dir = 'sv_SE';
63 $_SESSION['lang'] = 'sv';
67 $language_dir = 'en_US';
68 $_SESSION['lang'] = 'en';
72 //putenv("LANG=$language_dir");
73 //setlocale(LC_ALL, "$language_dir");
74 //bindtextdomain("nikki", $GLOBALS['prefix']."/locale");
75 //textdomain("nikki");
77 $program_version = "program_name";
79 //header('Content-Type: text/html; charset=UTF-8');
81 $month[0] = "January";
82 $month[1] = "February";
89 $month[8] = "September";
90 $month[9] = "October";
91 $month[10] = "November";
92 $month[11] = "December";
93 $week_day[0] = "Sunday";
94 $week_day[1] = "Monday";
95 $week_day[2] = "Tuesday";
96 $week_day[3] = "Wednesday";
97 $week_day[4] = "Thursday";
98 $week_day[5] = "Friday";
99 $week_day[6] = "Saturday";
100 $week_day_abb[0] = "Sun";
101 $week_day_abb[1] = "Mon";
102 $week_day_abb[2] = "Tue";
103 $week_day_abb[3] = "Wed";
104 $week_day_abb[4] = "Thu";
105 $week_day_abb[5] = "Fri";
106 $week_day_abb[6] = "Sat";
117 $month_days[10] = 30;
118 $month_days[11] = 31;
120 $border_color = '#000000';
122 //connect_to_database();
124 function connect_to_database()
126 if ($descriptor = mysql_connect($GLOBALS['mysql_host'], $GLOBALS['mysql_user'], $GLOBALS['mysql_password']))
128 mysql_query('USE '.$GLOBALS['mysql_database']);
136 # Input: $year Year in 4 digits format (ie: 2000, 1999...)
137 # $month Month (1-12)
138 function calendar_display_month($bg_line)
140 $day_id = calendar_get_date();
141 $year = abs(substr($day_id,0,4));
142 $month = abs(substr($day_id,4,2));
144 $attributes = localtime(mktime(0,0,1, $month, 1, $year), 1);
145 $start_day = $attributes['tm_wday'];
146 $month_name = date("F",strtotime($_SESSION["caltime"]));
147 //$GLOBALS['month'][$month-1];
148 $days_this_month = $GLOBALS['month_days'][$month-1];
150 # is this a leap year?
153 $days_this_month = ($year/4 == (int)($year/4) && ($year/100 != (int)($year/100) || $year/400 == (int)($year/400)))?29:28;
156 $today = localtime(time(), 1);
158 echo '<table border="0" cellspacing="1" cellpadding="1" '.$bg_line.'>';
160 echo '<td colspan="1">';
161 echo calendar_link_previous_month('<');
163 echo '<td colspan="5" align=center class="text">';
164 echo $month_name.' ('.$year.') ';
166 echo '<td colspan="1">';
167 echo calendar_link_next_month('>');
171 # Print weekday abbreviations
173 for ($column = 0; $column < 7; $column++)
175 echo '<td class="small">';
176 #echo $GLOBALS['week_day_abb'][$column];
177 echo $GLOBALS['week_day_abb'][($column + $GLOBALS['week_start']) % 7];
184 while ($column < ($start_day - $GLOBALS['week_start']))
186 echo '<td class="text"> </td>';
191 for ($day = 1; $day <= $days_this_month; $day++)
193 $day_index = date("Y-m",strtotime($_SESSION["caltime"]))."-".$time.substr('00'.abs($day), -2, 2);
194 if (($column>0) && ($column%7 == 0)) echo '</tr><tr>';
196 $check_wend = getdate(mktime(0,0,0,$month, $day, $year));
197 $weekend = (($check_wend['wday'] == 0) || ($check_wend['wday'] == 6))?1:0;
199 $its_today = ($today['tm_mday'] == $day && $today['tm_mon'] == ($month-1) && ($today['tm_year'] + 1900) == $year)?1:0;
200 $theres_text = isset($calendar_id[$day_index])?1:0;
201 if (isset($_GET['day_id']))
203 $is_selected = abs(substr($_GET['day_id'],-2,2) == $day)?1:0;
205 $is_selected = ($today['tm_mday'] == $day)?1:0;
209 //if (isset($calendar_id[$day_index]))
211 // echo '<a href="'.$GLOBALS['PHP_SELF'].'?lang='.$GLOBALS['lang'].'&day_id='.$day_index.'">'.$day.'</a>';
213 echo '<a class=small href="'.$GLOBALS['PHP_SELF'].'?viewmode=daily&mode=settime&caltime='.$day_index.'">'.$day.'</a>';
219 while ($column % 7 > 0)
221 echo '<td class="text"> </td>';
228 function calendar_display_entries()
230 $day_id = calendar_get_date();
231 $entries = mysql_query('SELECT * FROM nikki WHERE timestamp=\''.$day_id.'\' ORDER BY id');
232 if (mysql_num_rows($entries))
234 $year = abs(substr($day_id, 0, 4));
235 $month = abs(substr($day_id, 4, 2));
236 $day = abs(substr($day_id, 6, 2));
237 printf("today_date", $year, $month, $day);
239 $calendar_id = array();
240 while ($object = mysql_fetch_object($entries))
242 echo $object->text.'<br><br>';
247 function calendar_link_previous_month($text)
249 $day_id = calendar_get_date();
250 $year = abs(substr($day_id, 0, 4));
251 $month = abs(substr($day_id, 4, 2));
252 $day = abs(substr($day_id, 6, 2));
254 $month = ($month == 1)?12:$month-1;
255 $year = ($month == 12)?$year-1:$year;
257 $day_index = substr('0000'.$year,-4,4)."-".substr('00'.$month,-2,2)."-".substr('00'.$day,-2,2);
258 echo '<a class=bold href="'.$GLOBALS['PHP_SELF'].'?mode=settime&caltime='.$day_index.'">'.$text.'</a>';
261 function calendar_link_next_month($text)
263 $day_id = calendar_get_date();
264 $year = abs(substr($day_id, 0, 4));
265 $month = abs(substr($day_id, 4, 2));
266 $day = abs(substr($day_id, 6, 2));
268 $month = ($month == 12)?1:$month+1;
269 $year = ($month == 1)?$year+1:$year;
271 $day_index = substr('0000'.$year,-4,4)."-".substr('00'.$month,-2,2)."-".substr('00'.$day,-2,2);
272 echo '<a class=bold href="'.$GLOBALS['PHP_SELF'].'?mode=settime&caltime='.$day_index.'">'.$text.'</a>';
275 function calendar_get_date()
278 if (isset($GLOBALS['day_id']))
280 return $GLOBALS['day_id'];
282 return isset($_GET['day_id'])?addslashes($_GET['day_id']):date('Ymd');
286 return date("Ymd",strtotime($_SESSION["caltime"]));