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