diff --git a/include/fields/DateTimeField.php b/include/fields/DateTimeField.php index de2d15fcf64baf70bbb1be5e35858c857b13cfdb..02d6160ae1e4546c0533414ed2fea646162020e8 100644 --- a/include/fields/DateTimeField.php +++ b/include/fields/DateTimeField.php @@ -68,54 +68,74 @@ class DateTimeField { public function getFullcalenderDateTimevalue ($user = null) { return $this->getDisplayDate($user) . ' ' . $this->getFullcalenderTime($user); } - /** - * - * @global Users $current_user - * @param type $date - * @param Users $user - * @return type - */ - public static function convertToDBFormat($date, $user = null) { - global $current_user; - if(empty($user)) { - $user = $current_user; - } - - $format = $current_user->date_format; - if(empty($format)) { - $format = 'dd-mm-yyyy'; - } - return self::__convertToDBFormat($date, $format); - } - - /** - * - * @param type $date - * @param string $format - * @return string - */ - public static function __convertToDBFormat($date, $format) { - - if ($format == '') { - $format = 'dd-mm-yyyy'; - } - $dbDate = ''; - if ($format == 'dd-mm-yyyy') { - list($d, $m, $y) = explode('-', $date); - } elseif ($format == 'mm-dd-yyyy') { - list($m, $d, $y) = explode('-', $date); - } elseif ($format == 'yyyy-mm-dd') { - list($y, $m, $d) = explode('-', $date); - } - - if (!$y && !$m && !$d) { - $dbDate = ''; - } else { - $dbDate = $y . '-' . $m . '-' . $d; - } - return $dbDate; - } + /** + * + * @param string $date + * @param Users $user + * + * @return string + * @global Users $current_user + */ + public static function convertToDBFormat($date, $user = null) + { + global $current_user; + if (empty($user)) { + $user = $current_user; + } + + $format = $current_user->date_format; + if (empty($format)) { + if (false === strpos($date, '-')) { + $format = 'dd.mm.yyyy'; + } else { + $format = 'dd-mm-yyyy'; + } + } + + return self::__convertToDBFormat($date, $format); + } + + /** + * + * @param string $date + * @param string $format + * + * @return string + */ + public static function __convertToDBFormat($date, $format) + { + $dbDate = ''; + + if (empty($format)) { + if (false === strpos($date, '-')) { + $format = 'dd.mm.yyyy'; + } else { + $format = 'dd-mm-yyyy'; + } + } + + switch ($format) { + case 'dd.mm.yyyy': + list($d, $m, $y) = explode('.', $date); + break; + case 'dd-mm-yyyy': + list($d, $m, $y) = explode('-', $date); + break; + case 'mm-dd-yyyy': + list($m, $d, $y) = explode('-', $date); + break; + case 'yyyy-mm-dd': + list($y, $m, $d) = explode('-', $date); + break; + } + + if (!empty($y) && !empty($m) && !empty($d)) { + $dbDate = $y . '-' . $m . '-' . $d; + } + + return $dbDate; + } /** * @@ -148,30 +168,41 @@ class DateTimeField { return self::__convertToUserFormat($date, $format); } - /** - * - * @param type $date - * @param type $format - * @return type - */ - public static function __convertToUserFormat($date, $format) { - $date = self::convertToInternalFormat($date); - list($y, $m, $d) = explode('-', $date[0]); - - if ($format == 'dd-mm-yyyy') { - $date[0] = $d . '-' . $m . '-' . $y; - } elseif ($format == 'mm-dd-yyyy') { - $date[0] = $m . '-' . $d . '-' . $y; - } elseif ($format == 'yyyy-mm-dd') { - $date[0] = $y . '-' . $m . '-' . $d; - } - if ($date[1] != '') { - $userDate = $date[0] . ' ' . $date[1]; - } else { - $userDate = $date[0]; - } - return $userDate; - } + /** + * + * @param type $date + * @param type $format + * + * @return string + */ + public static function __convertToUserFormat($date, $format) + { + $date = self::convertToInternalFormat($date); + list($y, $m, $d) = explode('-', $date[0]); + + switch ($format) { + case 'dd.mm.yyyy': + $date[0] = $d . '.' . $m . '.' . $y; + break; + case 'dd-mm-yyyy': + $date[0] = $d . '-' . $m . '-' . $y; + break; + case 'mm-dd-yyyy': + $date[0] = $m . '-' . $d . '-' . $y; + break; + case 'yyyy-mm-dd': + $date[0] = $y . '-' . $m . '-' . $d; + break; + } + + if ($date[1] != '') { + $userDate = $date[0] . ' ' . $date[1]; + } else { + $userDate = $date[0]; + } + + return $userDate; + } /** * diff --git a/include/utils/CommonUtils.php b/include/utils/CommonUtils.php index 1ef02a99ab153c2e3632fad41934308ff7ee8733..bc741db18238384d257b0e664dba528293b89b1c 100755 --- a/include/utils/CommonUtils.php +++ b/include/utils/CommonUtils.php @@ -32,8 +32,8 @@ function is_admin($user) { return Vtiger_Functions::userIsAdministrator($user); } -function parse_calendardate($local_format) { - return Vtiger_Functions::currentUserJSDateFormat($local_format); +function parse_calendardate() { + return Vtiger_Functions::currentUserJSDateFormat(); } function from_html($string, $encode = true) { diff --git a/include/utils/utils.php b/include/utils/utils.php index 1ccbf5d6d7f4088c32daee7ab7625e7dbf7ac127..3266e04dc1738ac973d3df95db23e1ae06ebacaa 100755 --- a/include/utils/utils.php +++ b/include/utils/utils.php @@ -1792,11 +1792,17 @@ function getValidDBInsertDateValue($value) { $x = strpos($value, $delimiter); if($x === false) continue; else{ - $value=str_replace($delimiter, '-', $value); + if (false !== strpos($value, '-')) { + $value = str_replace($delimiter, '-', $value); + } break; } } - list($y,$m,$d) = explode('-',$value); + if (false === strpos($value, '-')) { + list($y, $m, $d) = explode('.', $value); + } else { + list($y, $m, $d) = explode('-', $value); + } if(strlen($y) == 1) $y = '0'.$y; if(strlen($m) == 1) $m = '0'.$m; if(strlen($d) == 1) $d = '0'.$d; diff --git a/layouts/v7/resources/helper.js b/layouts/v7/resources/helper.js index 55191eb7dcc89f00edcb1685014e41cf4ae4fd66..0a9e127a39d08d9e0a42b7a485f412df075709d4 100644 --- a/layouts/v7/resources/helper.js +++ b/layouts/v7/resources/helper.js @@ -87,12 +87,26 @@ jQuery.Class("Vtiger_Helper_Js",{ var timeComponent = dateTimeComponents[1]; var seconds = '00'; - var splittedDate = dateComponent.split("-"); + var splittedDate = ''; + var splittedDateFormat = ''; + + if (dateFormat.indexOf('-') !== -1) { + splittedDate = dateComponent.split('-'); + } else { + splittedDate = dateComponent.split('.'); + } + if(splittedDate.length > 3) { var errorMsg = app.vtranslate("JS_INVALID_DATE"); throw errorMsg; } - var splittedDateFormat = dateFormat.split("-"); + + if (dateFormat.indexOf('-') !== -1) { + splittedDateFormat = dateFormat.split('-'); + } else { + splittedDateFormat = dateFormat.split('.'); + } + var year = splittedDate[splittedDateFormat.indexOf("yyyy")]; var month = splittedDate[splittedDateFormat.indexOf("mm")]; var date = splittedDate[splittedDateFormat.indexOf("dd")]; diff --git a/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js b/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js index 7947ac249a5eea4ae27b5def449286d4208bfb66..24692ac0072abf533282e409dde13988aecf0e94 100644 --- a/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js +++ b/layouts/vlayout/modules/Vtiger/resources/dashboards/Widget.js @@ -84,11 +84,13 @@ jQuery.Class('Vtiger_Widget_Js',{ }, convertToDateRangePicketFormat : function(userDateFormat) { - if(userDateFormat == 'yyyy-mm-dd') { + if ('dd.mm.yyyy' === userDateFormat) { + return 'dd.MM.yyyy'; + } else if ('yyyy-mm-dd' === userDateFormat) { return 'yyyy-MM-dd'; - }else if( userDateFormat == 'mm-dd-yyyy') { + } else if ('mm-dd-yyyy' === userDateFormat) { return 'MM-dd-yyyy'; - }else if(userDateFormat == 'dd-mm-yyyy') { + } else if ('dd-mm-yyyy' === userDateFormat) { return 'dd-MM-yyyy'; } }, diff --git a/modules/Calendar/RepeatEvents.php b/modules/Calendar/RepeatEvents.php index 0b4d54b73cca9ea84065e773d77aa1b2df2b4123..b1fd36736ec92d443fd4c5a3de34fb399755259a 100644 --- a/modules/Calendar/RepeatEvents.php +++ b/modules/Calendar/RepeatEvents.php @@ -39,6 +39,7 @@ class Calendar_RepeatEvents { global $current_user; $format_string = 'Y-m-d H:i'; switch($current_user->date_format) { + case 'dd.mm.yyyy': $format_string = 'd.m.Y H:i'; break; case 'dd-mm-yyyy': $format_string = 'd-m-Y H:i'; break; case 'mm-dd-yyyy': $format_string = 'm-d-Y H:i'; break; case 'yyyy-mm-dd': $format_string = 'Y-m-d H:i'; break; diff --git a/modules/Migration/schema/720_to_721.php b/modules/Migration/schema/720_to_721.php index e2eda9a1ac0525934106bf906e43fe2acceff116..051d5b25792cfb3b860c424652efca18b9fff4cd 100644 --- a/modules/Migration/schema/720_to_721.php +++ b/modules/Migration/schema/720_to_721.php @@ -76,4 +76,6 @@ if (defined('VTIGER_UPGRADE')) { //#1184 => Register field delete event handler $em = new VTEventsManager($db); $em->registerHandler('vtiger.field.afterdelete', 'modules/Vtiger/handlers/FieldEventHandler.php', 'FieldEventHandler'); + + $db->pquery('INSERT INTO vtiger_date_format (date_format, sortorderid, presence) VALUES (?, ?, ?)', ['dd.mm.yyyy', 3, 1]); } \ No newline at end of file diff --git a/modules/Reports/ReportSharing.php b/modules/Reports/ReportSharing.php index 30fcc9daec8b9900adc04079e6f0c10bceb503ee..e29a00f3c577764ee9c223ef505a29e4498d9557 100644 --- a/modules/Reports/ReportSharing.php +++ b/modules/Reports/ReportSharing.php @@ -32,7 +32,7 @@ $report_std_filter->assign("MOD", $mod_strings); $report_std_filter->assign("APP", $app_strings); $report_std_filter->assign("IMAGE_PATH",$image_path); $report_std_filter->assign("DATEFORMAT",$current_user->date_format); -$report_std_filter->assign("JS_DATEFORMAT",parse_calendardate($app_strings['NTC_DATE_FORMAT'])); +$report_std_filter->assign('JS_DATEFORMAT', parse_calendardate()); $roleid = $current_user->column_fields['roleid']; $user_array = getAllUserName(); diff --git a/modules/com_vtiger_workflow/edittask.php b/modules/com_vtiger_workflow/edittask.php index 0c8dc2f69b0d6ac63fe6a310d0541b84ef478bf9..2f598d9866dcec854c2d28adfd510d7f025bca58 100644 --- a/modules/com_vtiger_workflow/edittask.php +++ b/modules/com_vtiger_workflow/edittask.php @@ -115,7 +115,7 @@ require_once("VTWorkflowUtils.php"); return_module_language($current_language, 'Calendar'), return_module_language($current_language, $module->name))); $smarty->assign("APP", $app_strings); - $smarty->assign("dateFormat", parse_calendardate($app_strings['NTC_DATE_FORMAT'])); + $smarty->assign('dateFormat', parse_calendardate()); $smarty->assign("IMAGE_PATH",$image_path); $smarty->assign("THEME", $theme); $smarty->assign("MODULE_NAME", $module->label); diff --git a/pkg/vtiger/modules/Import/modules/Import/actions/Data.php b/pkg/vtiger/modules/Import/modules/Import/actions/Data.php index 30175a0f2ac61514f8a5382dd22f8e01e8e799ed..e14ae6297ab5724a46f3a05fbab4f880caa2cb8d 100644 --- a/pkg/vtiger/modules/Import/modules/Import/actions/Data.php +++ b/pkg/vtiger/modules/Import/modules/Import/actions/Data.php @@ -710,9 +710,11 @@ class Import_Data_Action extends Vtiger_Action_Controller { } $userDateFormat = $current_user->column_fields['date_format']; - if ($userDateFormat == 'dd-mm-yyyy') { + if ('dd.mm.yyyy' === $userDateFormat) { + $dateFormat = 'd.m.Y'; + } else if ('dd-mm-yyyy' === $userDateFormat) { $dateFormat = 'd-m-Y'; - } else if ($userDateFormat == 'mm-dd-yyyy') { + } else if ('mm-dd-yyyy' === $userDateFormat) { $dateFormat = 'm-d-Y'; } else { $dateFormat = 'Y-m-d'; diff --git a/pkg/vtiger/modules/MailManager/modules/MailManager/views/Folder.php b/pkg/vtiger/modules/MailManager/modules/MailManager/views/Folder.php index 83e4ca0f0e444537747f7b1cf123a7a79720f52d..9e59d3d8e4de431967ac634a6116aef6edd63af8 100644 --- a/pkg/vtiger/modules/MailManager/modules/MailManager/views/Folder.php +++ b/pkg/vtiger/modules/MailManager/modules/MailManager/views/Folder.php @@ -62,7 +62,7 @@ class MailManager_Folder_View extends MailManager_Abstract_View { $viewer->assign('FOLDER', $folder); $viewer->assign('FOLDERLIST', $folderList); $viewer->assign('SEARCHOPTIONS' ,self::getSearchOptions()); - $viewer->assign("JS_DATEFORMAT",parse_calendardate(getTranslatedString('NTC_DATE_FORMAT'))); + $viewer->assign('JS_DATEFORMAT', parse_calendardate()); $viewer->assign('USER_DATE_FORMAT', $currentUserModel->get('date_format')); $viewer->assign('MODULE', $moduleName); $response->setResult($viewer->view( 'FolderOpen.tpl', $moduleName, true )); diff --git a/resources/app.js b/resources/app.js index fe235381ad42dcc6cd07188f95dc3f367e62f769..f5970f101e06ed87153530211ebe66d36fb440a8 100644 --- a/resources/app.js +++ b/resources/app.js @@ -535,12 +535,14 @@ var app = { } }, - convertToDatePickerFormat: function(dateFormat){ - if(dateFormat == 'yyyy-mm-dd'){ + convertToDatePickerFormat: function (dateFormat) { + if ('dd.mm.yyyy' === dateFormat) { + return 'd.m.Y'; + } else if ('yyyy-mm-dd' === dateFormat) { return 'Y-m-d'; - } else if(dateFormat == 'mm-dd-yyyy') { + } else if ('mm-dd-yyyy' === dateFormat) { return 'm-d-Y'; - } else if (dateFormat == 'dd-mm-yyyy') { + } else if ('dd-mm-yyyy' === dateFormat) { return 'd-m-Y'; } }, diff --git a/resources/helper.js b/resources/helper.js index 831f09ca83c78895b28c4ba2072c532bb33f1553..8034507904f46cab413b9038f3490cef2c944137 100644 --- a/resources/helper.js +++ b/resources/helper.js @@ -56,12 +56,26 @@ jQuery.Class("Vtiger_Helper_Js",{ var timeComponent = dateTimeComponents[1]; var seconds = '00'; - var splittedDate = dateComponent.split("-"); + var splittedDate = ''; + var splittedDateFormat = ''; + + if (dateFormat.indexOf('-') !== -1) { + splittedDate = dateComponent.split('-'); + } else { + splittedDate = dateComponent.split('.'); + } + if (splittedDate.length > 3) { var errorMsg = app.vtranslate("JS_INVALID_DATE"); throw errorMsg; } - var splittedDateFormat = dateFormat.split("-"); + + if (dateFormat.indexOf('-') !== -1) { + splittedDateFormat = dateFormat.split('-'); + } else { + splittedDateFormat = dateFormat.split('.'); + } + var year = splittedDate[splittedDateFormat.indexOf("yyyy")]; var month = splittedDate[splittedDateFormat.indexOf("mm")]; var date = splittedDate[splittedDateFormat.indexOf("dd")]; diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php index 9dbd03e8959d8c8218d3592030a6c624029bf9d8..e51904345d5af7647cbb7330b2ac05f18087aefe 100644 --- a/vtlib/Vtiger/Functions.php +++ b/vtlib/Vtiger/Functions.php @@ -20,17 +20,33 @@ class Vtiger_Functions { return (isset($user->is_admin) && $user->is_admin == 'on'); } - static function currentUserJSDateFormat($localformat) { - global $current_user; - if ($current_user->date_format == 'dd-mm-yyyy') { - $dt_popup_fmt = "%d-%m-%Y"; - } elseif ($current_user->date_format == 'mm-dd-yyyy') { - $dt_popup_fmt = "%m-%d-%Y"; - } elseif ($current_user->date_format == 'yyyy-mm-dd') { - $dt_popup_fmt = "%Y-%m-%d"; - } - return $dt_popup_fmt; - } + /** + * this function returns JS date format of current user + * + * return string + */ + public static function currentUserJSDateFormat() + { + $datePopupFormat = ''; + $currentUser = Users_Record_Model::getCurrentUserModel(); + + switch ($currentUser->get('date_format')) { + case 'dd.mm.yyyy': + $datePopupFormat = '%d.%m.%Y'; + break; + case 'dd-mm-yyyy': + $datePopupFormat = '%d-%m-%Y'; + break; + case 'mm-dd-yyyy': + $datePopupFormat = '%m-%d-%Y'; + break; + case 'yyyy-mm-dd': + $datePopupFormat = '%Y-%m-%d'; + break; + } + + return $datePopupFormat; + } /** * This function returns the date in user specified format. @@ -350,7 +366,7 @@ class Vtiger_Functions { if ($module == 'Groups') { $metainfo = array('tablename' => 'vtiger_groups','entityidfield' => 'groupid','fieldname' => 'groupname'); } else if ($module == 'DocumentFolders') { - $metainfo = array('tablename' => 'vtiger_attachmentsfolder','entityidfield' => 'folderid','fieldname' => 'foldername'); + $metainfo = array('tablename' => 'vtiger_attachmentsfolder','entityidfield' => 'folderid','fieldname' => 'foldername'); } else { $metainfo = self::getEntityModuleInfo($module); } @@ -561,7 +577,7 @@ class Vtiger_Functions { if (!is_dir($filepath . $year . "/" . $month)) { //create new folder - $monthFilePath = "$year/$month"; + $monthFilePath = "$year/$month"; $monthPath = $filepath.$monthFilePath; mkdir($filepath . $monthFilePath); exec("chown -R $permissions $monthPath"); @@ -598,7 +614,7 @@ class Vtiger_Functions { if (!$ok) return false; } } else { - if (stripos($data, $short ? "<?" : "<?php") !== false) { // suspicious dynamic content + if (stripos($data, $short ? "<?" : "<?php") !== false) { // suspicious dynamic content return false; } } @@ -1031,8 +1047,8 @@ class Vtiger_Functions { return $result; } - /** - * Function to determine mime type of file. + /** + * Function to determine mime type of file. * Compatible with mime_magic or fileinfo php extension. */ static function mime_content_type($filename) { @@ -1057,7 +1073,7 @@ class Vtiger_Functions { static function verifyClaimedMIME($targetFile,$claimedMime) { $fileMimeContentType= self::mime_content_type($targetFile); if (in_array(strtolower($fileMimeContentType), $claimedMime)) { - return false; + return false; } return true; } @@ -1109,9 +1125,9 @@ class Vtiger_Functions { return array('Invoice', 'Quotes', 'PurchaseOrder', 'SalesOrder', 'Products', 'Services'); } - /** + /** * Function to encode an array to json with all the options - * @param <Array> $array + * @param <Array> $array * @return <sting> Json String */ static function jsonEncode($array) { @@ -1334,9 +1350,9 @@ class Vtiger_Functions { /** * Function which will determine whether the table contains user specific field - * @param type $tableName -- name of the table + * @param type $tableName -- name of the table * @param type $moduleName -- moduleName - * @return boolean + * @return boolean */ public static function isUserSpecificFieldTable($tableName, $moduleName) { $moduleName = strtolower($moduleName); @@ -1361,7 +1377,7 @@ class Vtiger_Functions { static function jwtDecode($id_token) { $token_parts = explode(".", $id_token); - // First, in case it is url-encoded, fix the characters to be + // First, in case it is url-encoded, fix the characters to be // valid base64 $encoded_token = str_replace('-', '+', $token_parts[1]); $encoded_token = str_replace('_', '/', $encoded_token); @@ -1389,14 +1405,14 @@ class Vtiger_Functions { $encryption = new Encryption(); return '$ve$'.$encryption->encrypt($text); } - - /* + + /* * Function to determine if text is masked. */ static function isProtectedText($text) { return !empty($text) && (strpos($text, '$ve$') === 0); } - + /* * Function to unmask the text. */ @@ -1425,7 +1441,7 @@ class Vtiger_Functions { /** * Function to check if a module($sourceModule) is related to Documents module. * @param <string> $sourceModule - Source module - * @return <boolean> Returns TRUE if $sourceModule is related to Documents module and + * @return <boolean> Returns TRUE if $sourceModule is related to Documents module and * Documents module is active else returns FALSE. */ static function isDocumentsRelated($sourceModule) { @@ -1454,10 +1470,10 @@ class Vtiger_Functions { $value = $db->sql_escape_string($value); return $value; } - + /** * Request parameters and it's type. - * @var type + * @var type */ protected static $type = array( 'record' => 'id', @@ -1510,7 +1526,7 @@ class Vtiger_Functions { } return $ok; } - + /** * Function to get file public url to access outside of CRM (from emails) * @param <Integer> $fileId