Removed outdated phpmyadmin
[openemr.git] / library / formatting.inc.php
blob92ba19405214e56097c9a28b213d05e4ea4f1469
1 <?php
2 // Copyright (C) 2010 Rod Roark <rod@sunsetsystems.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 function oeFormatMoney($amount, $symbol=false) {
10 $s = number_format($amount,
11 $GLOBALS['currency_decimals'],
12 $GLOBALS['currency_dec_point'],
13 $GLOBALS['currency_thousands_sep']);
14 // If the currency symbol exists and is requested, prepend it.
15 if ($symbol && !empty($GLOBALS['gbl_currency_symbol']))
16 $s = $GLOBALS['gbl_currency_symbol'] . " $s";
17 return $s;
20 function oeFormatShortDate($date='today') {
21 if ($date === 'today') $date = date('Y-m-d');
22 if (strlen($date) == 10) {
23 // assume input is yyyy-mm-dd
24 if ($GLOBALS['date_display_format'] == 1) // mm/dd/yyyy
25 $date = substr($date, 5, 2) . '/' . substr($date, 8, 2) . '/' . substr($date, 0, 4);
26 else if ($GLOBALS['date_display_format'] == 2) // dd/mm/yyyy
27 $date = substr($date, 8, 2) . '/' . substr($date, 5, 2) . '/' . substr($date, 0, 4);
29 return $date;
32 // 0 - Time format 24 hr
33 // 1 - Time format 12 hr
34 function oeFormatTime( $time, $format = "" )
36 $formatted = $time;
37 if ( $format == "" ) {
38 $format = $GLOBALS['time_display_format'];
41 if ( $format == 0 ) {
42 $formatted = date( "H:i", strtotime( $time ) );
43 } else if ( $format == 1 ) {
44 $formatted = date( "g:i a", strtotime( $time ) );
47 return $formatted;
50 // Format short date from time.
51 function oeFormatSDFT($time) {
52 return oeFormatShortDate(date('Y-m-d', $time));
55 // Format the body of a patient note.
56 function oeFormatPatientNote($note) {
57 $i = 0;
58 while ($i !== false) {
59 if (preg_match('/^\d\d\d\d-\d\d-\d\d/', substr($note, $i))) {
60 $note = substr($note, 0, $i) . oeFormatShortDate(substr($note, $i, 10)) . substr($note, $i + 10);
62 $i = strpos("\n", $note, $i);
63 if ($i !== false) ++$i;
65 return $note;
68 function oeFormatClientID($id) {
70 // TBD
72 return $id;
74 //----------------------------------------------------
75 function DateFormatRead()
76 {//For the 3 supported date format,the javascript code also should be twicked to display the date as per it.
77 //Output of this function is given to 'ifFormat' parameter of the 'Calendar.setup'.
78 //This will show the date as per the global settings.
79 if($GLOBALS['date_display_format']==0)
81 return "%Y-%m-%d";
83 else if($GLOBALS['date_display_format']==1)
85 return "%m/%d/%Y";
87 else if($GLOBALS['date_display_format']==2)
89 return "%d/%m/%Y";
92 function DateToYYYYMMDD($DateValue)
93 {//With the help of function DateFormatRead() now the user can enter date is any of the 3 formats depending upon the global setting.
94 //But in database the date can be stored only in the yyyy-mm-dd format.
95 //This function accepts a date in any of the 3 formats, and as per the global setting, converts it to the yyyy-mm-dd format.
96 if(trim($DateValue)=='')
98 return '';
101 if($GLOBALS['date_display_format']==0)
103 return $DateValue;
105 else if($GLOBALS['date_display_format']==1 || $GLOBALS['date_display_format']==2)
107 $DateValueArray=split('/',$DateValue);
108 if($GLOBALS['date_display_format']==1)
110 return $DateValueArray[2].'-'.$DateValueArray[0].'-'.$DateValueArray[1];
112 if($GLOBALS['date_display_format']==2)
114 return $DateValueArray[2].'-'.$DateValueArray[1].'-'.$DateValueArray[0];