translation fix for previous commit
[openemr.git] / library / calendar_nikki.inc
blobedcc6246fbe4ce54b97880f9360179625b58562e
1 <?php
3 /*
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';
23 $week_start = 0;
24 $default_language = 'en';
26 if (isset($_GET['lang']))
28         $lang = $_GET['lang'];
29 } else {
30         if (isset($_SESSION['lang']))
31         {
32                 $lang = $_SESSION['lang'];
33         } else {
34                 $lang = $GLOBALS['default_language'];
35         }
38 #$lang = isset($_GET['lang'])?$_GET['lang']:isset($_SESSION['lang'])?$_SESSION['lang']:$GLOBALS['default_language'];
40 switch($lang)
42         case 'de':
43                 $language_dir = 'de_DE';
44                 $_SESSION['lang'] = 'de';
45                 break;
46         case 'es':
47                 $language_dir = 'es_ES';
48                 $_SESSION['lang'] = 'es';
49                 break;
50         case 'it':
51                 $language_dir = 'it_IT';
52                 $_SESSION['lang'] = 'it';
53                 break;
54         case 'ja':
55                 $language_dir = 'ja_JP';
56                 $_SESSION['lang'] = 'ja';
57                 break;
58         case 'nl':
59                 $language_dir = 'nl_NL';
60                 $_SESSION['lang'] = 'nl';
61                 break;
62         case 'sv':
63                 $language_dir = 'sv_SE';
64                 $_SESSION['lang'] = 'sv';
65                 break;
66         case 'en':
67         default:
68                 $language_dir = 'en_US';
69                 $_SESSION['lang'] = 'en';
70                 break;
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";
84 $month[2] = "March";
85 $month[3] = "April";
86 $month[4] = "May";
87 $month[5] = "June";
88 $month[6] = "July";
89 $month[7] = "August";
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";
108 $month_days[0] = 31;
109 $month_days[1] = 28;
110 $month_days[2] = 31;
111 $month_days[3] = 30;
112 $month_days[4] = 31;
113 $month_days[5] = 30;
114 $month_days[6] = 31;
115 $month_days[7] = 31;
116 $month_days[8] = 30;
117 $month_days[9] = 31;
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']))
128         {
129                 mysql_query('USE '.$GLOBALS['mysql_database']);
130                 return $descriptor;
131         } else {
132                 return 0;
133         }
136 # display a month
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?  
152         if ($month == 2)
153         {
154                 $days_this_month = ($year/4 == (int)($year/4) && ($year/100 != (int)($year/100) || $year/400 == (int)($year/400)))?29:28;
155         }
157         $today = localtime(time(), 1);
159         echo '<table border="0" cellspacing="1" cellpadding="1" '.$bg_line.'>';
160         echo '<tr>';
161         echo '<td colspan="1">';
162         echo calendar_link_previous_month('&lt;');
163         echo '</td>';
164         echo '<td colspan="5" align=center class="text">';
165         echo $month_name.'&nbsp;('.$year.')&nbsp;';
166         echo '</td>';
167         echo '<td colspan="1">';
168         echo calendar_link_next_month('&gt;');
169         echo '</td>';
170         echo '</tr>';
172         # Print weekday abbreviations
173         echo '<tr>';
174         for ($column = 0; $column < 7; $column++)
175         {
176                 echo '<td class="small">';
177                 #echo $GLOBALS['week_day_abb'][$column];
178                 echo $GLOBALS['week_day_abb'][($column + $GLOBALS['week_start']) % 7];
179                 echo '</td>';
180         }
181         echo '</tr>';
183         $column = 0;
184         echo '<tr>';
185         while ($column < ($start_day - $GLOBALS['week_start']))
186         {
187                 echo '<td class="text">&nbsp;</td>';
188                 $column++;
189         }
192         for ($day = 1; $day <= $days_this_month; $day++)
193         {
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']))
203                 {
204                         $is_selected = abs(substr($_GET['day_id'],-2,2) == $day)?1:0;
205                 } else {
206                         $is_selected = ($today['tm_mday'] == $day)?1:0;
207                 }
209                 echo '<td>';
210                 //if (isset($calendar_id[$day_index]))
211                 //{
212                 //      echo '<a href="'.$GLOBALS['PHP_SELF'].'?lang='.$GLOBALS['lang'].'&day_id='.$day_index.'">'.$day.'</a>';
213                 //} else {
214                         echo '<a class=small href="'.$GLOBALS['PHP_SELF'].'?viewmode=daily&mode=settime&caltime='.$day_index.'">'.$day.'</a>';
215                 //}
216                 echo '</td>';
217                 $column++;
218         }
220         while ($column % 7 > 0)
221         {
222                 echo '<td class="text">&nbsp;</td>';
223                 $column++;
224         }
225         echo '</tr>';
226         echo '</table>';
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))
234         {
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);
239                 echo '<br><br>';
240                 $calendar_id = array();
241                 while ($object = mysql_fetch_object($entries))
242                 {
243                         echo $object->text.'<br><br>';
244                 }
245         }
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()
278         /*
279         if (isset($GLOBALS['day_id']))
280         {
281                 return $GLOBALS['day_id'];
282         } else {
283                 return isset($_GET['day_id'])?addslashes($_GET['day_id']):date('Ymd');
284         }
285         */
286         
287         return date("Ymd",strtotime($_SESSION["caltime"]));
288