$_POST['theme'] = clean_file_name($_POST['theme']);
$chg_theme = user_theme() != $_POST['theme'];
$chg_lang = $_SESSION['language']->code != $_POST['language'];
+ $chg_date_format = user_date_format() != $_POST['date_format'];
+ $chg_date_sep = user_date_sep() != $_POST['date_sep'];
set_user_prefs(get_post(
array('prices_dec', 'qty_dec', 'rates_dec', 'percent_dec',
if ($chg_theme && $allow_demo_mode)
$_SESSION["wa_current_user"]->prefs->theme = $_POST['theme'];
-
- if ($chg_theme || $chg_lang)
+ if ($chg_theme || $chg_lang || $chg_date_format || $chg_date_sep)
meta_forward($_SERVER['PHP_SELF']);
/* suppress tax rates on documents. 0 = no, 1 = yes. */
$suppress_tax_rates = 0;
- $dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD");
+ $dateformats = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD");
$dateseps = array("/", ".", "-", " ");
$thoseps = array(",", ".", " ");
$decseps = array(".", ",");
$dflt_date_fmt = 0;
$dflt_date_sep = 0;
+ /* This month array is for use with the last 3 dateformats. */
+ $tmonths = array("", _("Jan"),_("Feb"),_("Mar"),_("Apr"),_("May"),_("Jun"),_("Jul"),_("Aug"),_("Sep"),_("Oct"),_("Nov"),_("Dec"));
+
$pagesizes = array("Letter", "A4"); // default PDF pagesize
/* Accounts Payable */
function __date($year, $month, $day)
{
- global $dateseps;
+ global $dateseps, $tmonths;
$how = user_date_format();
$sep = $dateseps[user_date_sep()];
$day = (int)$day;
$month = (int)$month;
- if ($day < 10)
- $day = "0".$day;
- if ($month < 10)
- $month = "0".$month;
+ if ($how < 3)
+ {
+ if ($day < 10)
+ $day = "0".$day;
+ if ($month < 10)
+ $month = "0".$month;
+ }
if ($how == 0)
return $month.$sep.$day.$sep.$year;
elseif ($how == 1)
return $day.$sep.$month.$sep.$year;
- else
+ elseif ($how == 2)
return $year.$sep.$month.$sep.$day;
+ elseif ($how == 3)
+ return $tmonths[$month].$sep.$day.$sep.$year;
+ elseif ($how == 4)
+ return $day.$sep.$tmonths[$month].$sep.$year;
+ else
+ return $year.$sep.$tmonths[$month].$sep.$day;
}
function is_date($date_)
$sep = $dateseps[user_date_sep()];
$date_ = trim($date_);
- $date_ = str_replace($sep, "", $date_);
+ $date = str_replace($sep, "", $date_);
if (strlen($date_) == 6)
{
if ($how == 0)
{
- $day = substr($date_,2,2);
- $month = substr($date_,0,2);
- $year = substr($date_,4,2);
+ $day = substr($date,2,2);
+ $month = substr($date,0,2);
+ $year = substr($date,4,2);
}
elseif ($how == 1)
{
- $day = substr($date_,0,2);
- $month = substr($date_,2,2);
- $year = substr($date_,4,2);
+ $day = substr($date,0,2);
+ $month = substr($date,2,2);
+ $year = substr($date,4,2);
}
else
{
- $day = substr($date_,4,2);
- $month = substr($date_,2,2);
- $year = substr($date_,0,2);
+ $day = substr($date,4,2);
+ $month = substr($date,2,2);
+ $year = substr($date,0,2);
}
}
elseif (strlen($date_) == 8)
{
if ($how == 0)
{
- $day = substr($date_,2,2);
- $month = substr($date_,0,2);
- $year = substr($date_,4,4);
+ $day = substr($date,2,2);
+ $month = substr($date,0,2);
+ $year = substr($date,4,4);
}
elseif ($how == 1)
{
- $day = substr($date_,0,2);
- $month = substr($date_,2,2);
- $year = substr($date_,4,4);
+ $day = substr($date,0,2);
+ $month = substr($date,2,2);
+ $year = substr($date,4,4);
}
else
{
- $day = substr($date_,6,2);
- $month = substr($date_,4,2);
- $year = substr($date_,0,4);
+ $day = substr($date,6,2);
+ $month = substr($date,4,2);
+ $year = substr($date,0,4);
}
}
+ elseif ($how > 2)
+ {
+ global $tmonths;
+ $dd = explode($sep, $date_);
+ if ($how == 3)
+ {
+ $day = $dd[1];
+ $month = array_search($dd[0], $tmonths);
+ $year = $dd[2];
+ }
+ elseif ($how == 4)
+ {
+ $day = $dd[0];
+ $month = array_search($dd[1], $tmonths);
+ $year = $dd[2];
+ }
+ else
+ {
+ $day = $dd[2];
+ $month = array_search($dd[1], $tmonths);
+ $year = $dd[0];
+ }
+ if ($year < 1000)
+ return 0;
+ }
if (!isset($year)|| (int)$year > 9999)
{
return 0;
}
-
if (is_long((int)$day) && is_long((int)$month) && is_long((int)$year))
{
global $date_system;
function date2sql($date_)
{
- global $dateseps, $date_system;
+ global $dateseps, $date_system, $tmonths;
/* takes a date in a the format specified in $DefaultDateFormat
and converts to a yyyy/mm/dd format */
$date_ = trim($date_);
$year = $month = $day = 0;
-
// Split up the date by the separator based on "how" to split it
- if ($how == 0) // MMDDYYYY
+ if ($how == 0 || $how == 3) // MMDDYYYY or MmmDDYYYY
list($month, $day, $year) = explode($sep, $date_);
- elseif ($how == 1) // DDMMYYYY
+ elseif ($how == 1 || $how == 4) // DDMMYYYY or DDMmYYYY
list($day, $month, $year) = explode($sep, $date_);
- else // $how == 2, YYYYMMDD
+ else // $how == 2 || $how == 5, YYYYMMDD or YYYYMmmDD
list($year, $month, $day) = explode($sep, $date_);
-
+ if ($how > 2)
+ {
+ global $tmonths;
+ $month = array_search($month, $tmonths);
+ }
//to modify assumption in 2030
if ($date_system == 0 || $date_system == 3)
{
return "m".$sep."d".$sep."Y";
elseif ($this->date_format == 1)
return "d".$sep."m".$sep."Y";
- else
+ elseif ($this->date_format == 2)
return "Y".$sep."m".$sep."d";
+ elseif ($this->date_format == 3)
+ return "M".$sep."j".$sep."Y";
+ elseif ($this->date_format == 4)
+ return "j".$sep."M".$sep."Y";
+ else
+ return "Y".$sep."M".$sep."j";
}
function tho_sep()
$aspect .= ' style="color:#FF0000"';
default_focus($name);
- echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"10\" maxlength=\"12\" value=\""
+ $size = (user_date_format()>3)?11:10;
+ echo "<input type=\"text\" name=\"$name\" class=\"$class\" $aspect size=\"$size\" maxlength=\"12\" value=\""
. $_POST[$name]. "\""
.($title ? " title='$title'": '')." > $post_label";
echo "</td>\n";
if (!file_exists($fpath) || $go_debug) {
- global $dateseps, $date_system;
+ global $dateseps, $date_system, $tmonths;
$how = user_date_format(); // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
$sep = $dateseps[user_date_sep()]; // date separator
- $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
+ $wstart = (($date_system == 1 || $date_system == 2 || $date_system == 3) ? 6 : ($how == 0 || $how == 3 ? 0 : 1)); // weekstart (sun = 0, mon = 1)
$months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
$wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
$wno = _("W"); // week no
var selectedDay = 0;
var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]'];
var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
+ var tmonths = ['$tmonths[0]','$tmonths[1]','$tmonths[2]','$tmonths[3]','$tmonths[4]','$tmonths[5]','$tmonths[6]','$tmonths[7]','$tmonths[8]','$tmonths[9]','$tmonths[10]','$tmonths[11]','$tmonths[12]'];
var dateField = null;
function getProperty(p_property){
var p_elm = calendarId;
this.getWeek = getWeek;
function getWeek(year, month, day) {
";
- if ($how == 0)
+ if ($how == 0 || $how == 3)
$js .= " day++;";
$js .= "
var date = new Date(year,month-1,day);
}
this.setDate = setDate;
function setDate(year, month, day) {
- if (dateField) {
+ if (dateField){
+";
+ if ($how < 3)
+ $js .= "
if (month < 10) {month = '0' + month;}
if (day < 10) {day = '0' + day;}
";
- if ($how == 0)
+ else
+ $js .= "
+ month = tmonths[month];
+";
+ if ($how == 0 || $how == 3)
$js .= "
var dateString = month+'$sep'+day+'$sep'+year;
";
- else if ($how == 1)
+ else if ($how == 1 || $how == 4)
$js .= "
var dateString = day+'$sep'+month+'$sep'+year;
";
- else
+ else if ($how == 2 || $how == 5)
$js .= "
var dateString = year+'$sep'+month+'$sep'+day;
";
selectedMonth = parseInt(dateParts[1],10);
selectedYear = parseInt(dateParts[2],10);
";
- else
+ else if ($how == 2)
$js .= "
selectedYear = parseInt(dateParts[0],10);
selectedMonth = parseInt(dateParts[1],10);
selectedDay = parseInt(dateParts[2],10);
+";
+ else if ($how == 3)
+ $js .= "
+ selectedDay = parseInt(dateParts[1],10);
+ selectedMonth = parseInt(tmonths.indexOf(dateParts[0]),10);
+ selectedYear = parseInt(dateParts[2],10);
+";
+ else if ($how == 4)
+ $js .= "
+ selectedDay = parseInt(dateParts[0],10);
+ selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10);
+ selectedYear = parseInt(dateParts[2],10);
+";
+ else
+ $js .= "
+ selectedYear = parseInt(dateParts[0],10);
+ selectedMonth = parseInt(tmonths.indexOf(dateParts[1]),10);
+ selectedDay = parseInt(dateParts[2],10);
";
$js .= "
} catch(e) {}
*/
function fix_date(date, last)
{
- var regex = /(\d+)[^\d]*(\d+)*[^\d]*(\d+)*/;
- var dat = regex.exec(last);
- var cur = regex.exec(date);
+ var dat = last.split(user.datesep);
+ var cur = date.split(user.datesep);
var day, month, year;
+ var day1, month1, year1;
// TODO: user.date as default?
// TODO: user.datesys
- if (!dat || !cur) return date;
-
- if (cur[3] != undefined) // full date entered
- dat = cur;
-
- if (user.datefmt == 0) // set defaults
+ if (date == "" || date == last) // should we return an empty date or should we return last?
+ return date;
+ if (user.datefmt == 0 || user.datefmt == 3) // set defaults
{
- day = dat[2]; month = dat[1]; year = dat[3];
- } else if (user.datefmt == 1)
- {
- day = dat[1]; month = dat[2]; year = dat[3];
+ day = dat[1]; month = dat[0]; year = dat[2];
+ day1 = cur[1]; month1 = cur[0]; year1 = cur[2];
+ } else if (user.datefmt == 1 || user.datefmt == 4){
+ day = dat[0]; month = dat[1]; year = dat[2];
+ day1 = cur[0]; month1 = cur[1]; year1 = cur[2];
} else {
- day = dat[3]; month = dat[2]; year = dat[1];
- }
-
- if (cur[2] == undefined) // only day entred
- day = cur[1];
- else // day + month
- if (cur[2] != undefined)
- {
- if (user.datefmt==1)
- { day = cur[1]; month = cur[2] }
- else
- { day = cur[2]; month = cur[1] }
- }
-
- if (day<10) day = '0'+parseInt(day, 10);
- if (month<10) month = '0'+parseInt(month, 10);
+ day = dat[2]; month = dat[1]; year = dat[0];
+ day1 = cur[2]; month1 = cur[1]; year1 = cur[0];
+ }
+ if (day1 != undefined && day1 != "") // day entered
+ day = day1;
+ if (month1 != undefined && month1 != "") // month entered
+ month = month1;
+ if (year1 != undefined && year1 != "") // year entered
+ year = year1;
+ if (user.datefmt<3 && day<10) day = '0'+parseInt(day, 10);
+ if (user.datefmt<3 && month<10) month = '0'+parseInt(month, 10);
if (year<100) year = year<60 ? (2000+parseInt(year,10)) : (1900+parseInt(year,10));
// console.info(day,month,year)
- if (user.datefmt == 0)
+ if (user.datefmt == 0 || user.datefmt==3)
return month+user.datesep+day+user.datesep+year;
- if (user.datefmt == 1)
+ if (user.datefmt == 1 || user.datefmt==4)
return day+user.datesep+month+user.datesep+year;
return year+user.datesep+month+user.datesep+day;
}