Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Conditions/QueryFields/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getOrderBy($order = false)
public function getCondition()
{
$fn = 'operator' . ucfirst($this->operator);
if (isset(\App\Condition::DATE_OPERATORS[$this->operator])) {
if (isset(\App\Condition::DATE_OPERATORS[$this->operator]) && !method_exists($this, $fn)) {
$fn = 'getStdOperator';
}
if (!($methodExists = method_exists($this, $fn))) {
Expand Down
42 changes: 42 additions & 0 deletions app/Fields/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,46 @@ public static function getHolidays(string $start = '', string $end = '')
\App\Cache::save('Date::getHolidays', $start . $end, $holidays);
return $holidays;
}

/**
* Function changes the date format to the database format without changing the time zone.
*
* @param string $date
* @param string $fromFormat
*
* @return string
*/
public static function sanitizeDbFormat(string $date, string $fromFormat)
{
$dbDate = '';
[$y, $m, $d] = self::explode($date, $fromFormat);
if (!$y || !$m || !$d) {
if (false !== strpos($date, '-')) {
$separator = '-';
} elseif (false !== strpos($date, '.')) {
$separator = '.';
} elseif (false !== strpos($date, '/')) {
$separator = '/';
}
$formatToConvert = str_replace(['/', '.'], '-', $fromFormat);
$dateToConvert = str_replace($separator, '-', $date);
switch ($formatToConvert) {
case 'dd-mm-yyyy':
[$d, $m, $y] = explode('-', $dateToConvert, 3);
break;
case 'mm-dd-yyyy':
[$m, $d, $y] = explode('-', $dateToConvert, 3);
break;
case 'yyyy-mm-dd':
[$y, $m, $d] = explode('-', $dateToConvert, 3);
break;
default:
break;
}
$dbDate = $y . '-' . $m . '-' . $d;
} else {
$dbDate = $y . '-' . $m . '-' . $d;
}
return $dbDate;
}
}
23 changes: 23 additions & 0 deletions app/Fields/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,27 @@ public static function timeToDecimal(string $time)
$hms = explode(':', $time);
return $hms[0] + ($hms[1] / 60) + ($hms[2] / 3600);
}

/**
* Function changes the time format to the database format without changing the time zone.
*
* @param string $time
*
* @return string
*/
public static function sanitizeDbFormat(string $time)
{
if ($time) {
$timeDetails = array_pad(explode(' ', $time), 2, '');
[$hours, $minutes, $seconds] = array_pad(explode(':', $timeDetails[0]), 3, '00');
if ('PM' === $timeDetails[1] && '12' !== $hours) {
$hours = $hours + 12;
}
if ('AM' === $timeDetails[1] && '12' === $hours) {
$hours = '00';
}
$time = "$hours:$minutes:$seconds";
}
return $time;
}
}
4 changes: 0 additions & 4 deletions app/QueryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,10 +1294,6 @@ public function parseBaseSearchParamsToCondition($searchParams)
if (('tree' === $field->getFieldDataType() || 'categoryMultipicklist' === $field->getFieldDataType()) && $specialOption) {
$fieldValue = \Settings_TreesManager_Record_Model::getChildren($fieldValue, $fieldName, $this->moduleModel);
}
//Request will be having in terms of AM and PM but the database will be having in 24 hr format so converting
if ('time' === $field->getFieldDataType()) {
$fieldValue = \Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
}
if ('date_start' === $fieldName || 'due_date' === $fieldName || 'datetime' === $field->getFieldDataType()) {
$dateValues = explode(',', $fieldValue);
//Indicate whether it is fist date in the between condition
Expand Down
60 changes: 15 additions & 45 deletions include/fields/DateTimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,7 @@ public static function __convertToDBFormat($date, $format)
if ('' == $format) {
$format = 'yyyy-mm-dd';
}
$dbDate = '';
[$y, $m, $d] = App\Fields\Date::explode($date, $format);
if (!$y || !$m || !$d) {
if (false !== strpos($date, '-')) {
$separator = '-';
} elseif (false !== strpos($date, '.')) {
$separator = '.';
} elseif (false !== strpos($date, '/')) {
$separator = '/';
}
$formatToConvert = str_replace(['/', '.'], ['-', '-'], $format);
$dateToConvert = str_replace($separator, '-', $date);
switch ($formatToConvert) {
case 'dd-mm-yyyy':
[$d, $m, $y] = explode('-', $dateToConvert, 3);
break;
case 'mm-dd-yyyy':
[$m, $d, $y] = explode('-', $dateToConvert, 3);
break;
case 'yyyy-mm-dd':
[$y, $m, $d] = explode('-', $dateToConvert, 3);
break;
default:
break;
}
$dbDate = $y . '-' . $m . '-' . $d;
} elseif (!$y && !$m && !$d) {
$dbDate = '';
} else {
$dbDate = $y . '-' . $m . '-' . $d;
}
return $dbDate;
return \App\Fields\Date::sanitizeDbFormat($date, $format);
}

/**
Expand Down Expand Up @@ -275,7 +244,7 @@ public static function convertTimeZone($time, $sourceTimeZoneName, $targetTimeZo
{
\App\Log::trace('Start ' . __METHOD__ . "($time, $sourceTimeZoneName, $targetTimeZoneName)");
$sourceTimeZone = new DateTimeZone($sourceTimeZoneName);
if ($time == '24:00') {
if ('24:00' == $time) {
$time = '00:00';
}
$time = str_replace('.', '-', $time);
Expand All @@ -290,10 +259,12 @@ public static function convertTimeZone($time, $sourceTimeZoneName, $targetTimeZo
return $myDateTime;
}

/** Function to set timee values compatible to database (GMT)
* @param $user -- value :: Type Users
/**
* Function to set time values compatible to database (GMT).
*
* @param bool $convertTimeZone
* @returns $insert_date -- insert_date :: Type string
*
* @return string
*/
public function getDBInsertTimeValue(bool $convertTimeZone = true)
{
Expand Down Expand Up @@ -362,12 +333,12 @@ public function getFullcalenderTime($user = null)
}

/**
* Sanitize date
* Sanitize date.
*
* @param string $value
* @param \App\User|null $user
* @param string $value
* @param \App\User|null $user
*
* @return string $value
* @return string $value
*/
private static function sanitizeDate(string $value, $user): string
{
Expand All @@ -377,13 +348,12 @@ private static function sanitizeDate(string $value, $user): string
if (\strlen($value) < 8) {
return $value;
}
$value = str_replace('T', ' ', $value);
[$date, $time, $formatTime] = array_pad(explode(' ', $value), 3, '');
if (!empty($date) && !\in_array($formatTime, ['AM', 'PM'])) {
$date = self::__convertToDBFormat($date, $user->getDetail('date_format'));
[$date, $time] = array_pad(explode(' ', $value, 2), 2, '');
if (!empty($date)) {
$date = \App\Fields\Date::sanitizeDbFormat($date, $user->getDetail('date_format'));
$value = $date;
if (!empty($time)) {
$value .= ' ' . rtrim($time);
$value .= ' ' . \App\Fields\Time::sanitizeDbFormat($time);
}
}
return $value;
Expand Down
28 changes: 15 additions & 13 deletions layouts/basic/modules/Vtiger/Edit/Field/DateTime.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{*<!--
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
-->*}
{*<!-- {[The file is published on the basis of YetiForce Public License 3.0 that can be found in the following directory: licenses/LicenseEN.txt or yetiforce.com]} -->*}
{strip}
<!-- tpl-Base-Edit-Field-DateTime -->
{assign var="FIELD_INFO" value=\App\Purifier::encodeHtml(\App\Json::encode($FIELD_MODEL->getFieldInfo()))}
{assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
{assign var="dateFormat" value=$USER_MODEL->get('date_format')}
<input name="{$FIELD_MODEL->getFieldName()}" class="tpl-Edit-Field-DateTime form-control-lg dateTimeField form-control" value="{$FIELD_MODEL->getEditViewDisplayValue($FIELD_MODEL->get('fieldvalue'),$RECORD)}" id="{$MODULE}_editView_fieldName_{$FIELD_MODEL->getName()}" type="text" data-date-format="{$dateFormat}" type="text" data-validation-engine="validate[{if $FIELD_MODEL->isMandatory() eq true} required,{/if}funcCall[Vtiger_Base_Validator_Js.invokeValidation]]" {if !empty($SPECIAL_VALIDATOR)}data-validator="{\App\Purifier::encodeHtml(\App\Json::encode($SPECIAL_VALIDATOR))}"{/if} data-fieldinfo='{$FIELD_INFO}' {if $FIELD_MODEL->isEditableReadOnly()}readonly="readonly"{/if} autocomplete="off"/>
<div class="input-group dateTime">
<input name="{$FIELD_MODEL->getFieldName()}" class="dateTimePickerField form-control"
value="{$FIELD_MODEL->getEditViewDisplayValue($FIELD_MODEL->get('fieldvalue'),$RECORD)}"
id="{$MODULE_NAME}_editView_fieldName_{$FIELD_MODEL->getName()}" type="text" data-hour-format="{$USER_MODEL->get('hour_format')}"
data-date-format="{$USER_MODEL->get('date_format')}" type="text"
data-validation-engine="validate[{if $FIELD_MODEL->isMandatory() eq true} required,{/if}funcCall[Vtiger_Base_Validator_Js.invokeValidation]]"
{if !empty($SPECIAL_VALIDATOR)}data-validator='{\App\Json::encode($SPECIAL_VALIDATOR)}'{/if}
data-fieldinfo='{$FIELD_INFO}' {if $FIELD_MODEL->isEditableReadOnly()}readonly="readonly"{/if} autocomplete="off"/>
<span class="input-group-text u-cursor-pointer">
<span class="fas fa-clock"></span> &nbsp; <span class="far fa-calendar-alt"></span>
</span>
</div>
<!-- /tpl-Base-Edit-Field-DateTime -->
{/strip}
19 changes: 0 additions & 19 deletions layouts/basic/modules/Vtiger/Edit/Field/DateTimeField.tpl

This file was deleted.

33 changes: 16 additions & 17 deletions modules/Calendar/models/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Calendar_Field_Model extends Vtiger_Field_Model
public function getValidator()
{
$validator = [];
if ($this->getName() === 'due_date') {
if ('due_date' === $this->getName()) {
$funcName = ['name' => 'greaterThanDependentField',
'params' => ['date_start'], ];
array_push($validator, $funcName);
Expand All @@ -35,9 +35,10 @@ public function getValidator()
*/
public function getFieldDataType()
{
if ($this->getName() == 'date_start' || $this->getName() == 'due_date') {
if ('date_start' == $this->getName() || 'due_date' == $this->getName()) {
return 'datetime';
} elseif ($this->getUIType() === 30) {
}
if (30 === $this->getUIType()) {
return 'reminder';
}
return parent::getFieldDataType();
Expand All @@ -49,16 +50,17 @@ public function getFieldDataType()
public function getDisplayValue($value, $record = false, $recordModel = false, $rawText = false, $length = false)
{
if ($recordModel) {
if ($this->getName() === 'date_start') {
if ('date_start' === $this->getName()) {
$dateTimeValue = $value . ' ' . $recordModel->get('time_start');
$value = $this->getUITypeModel()->getDisplayValue($dateTimeValue);
list($startDate, $startTime) = explode(' ', $value);
[$startDate, $startTime] = explode(' ', $value);

return $startDate . ' ' . $startTime;
} elseif ($this->getName() === 'due_date') {
}
if ('due_date' === $this->getName()) {
$dateTimeValue = $value . ' ' . $recordModel->get('time_end');
$value = $this->getUITypeModel()->getDisplayValue($dateTimeValue);
list($startDate, $startTime) = explode(' ', $value);
[$startDate, $startTime] = explode(' ', $value);

return $startDate . ' ' . $startTime;
}
Expand All @@ -67,19 +69,16 @@ public function getDisplayValue($value, $record = false, $recordModel = false, $
}

/**
* Function to get Edit view display value.
*
* @param string Data base value
*
* @return string value
* {@inheritdoc}
*/
public function getEditViewDisplayValue($value, $recordModel = false)
{
if (empty($value)) {
$fieldName = $this->getName();
if ($fieldName === 'date_start') {
if ('date_start' === $fieldName) {
return DateTimeField::convertToUserFormat(date('Y-m-d'));
} elseif ($fieldName === 'due_date') {
}
if ('due_date' === $fieldName) {
$userModel = \App\User::getCurrentUserModel();
$defaultType = $userModel->getDetail('defaultactivitytype');
$typeByDuration = \App\Json::decode($userModel->getDetail('othereventduration'));
Expand Down Expand Up @@ -108,7 +107,7 @@ public static function getAdvancedFilterOpsByFieldType()
*/
public function isEmptyPicklistOptionAllowed()
{
if ($this->getFieldName() == 'visibility') {
if ('visibility' == $this->getFieldName()) {
return false;
}
return true;
Expand All @@ -123,11 +122,11 @@ public function getFieldInfo()
{
parent::getFieldInfo();
//Change the default search operator
if ($this->get('name') == 'date_start') {
if ('date_start' == $this->get('name')) {
$searchParams = App\Condition::validSearchParams('Calendar', \App\Request::_getArray('search_params'));
if (!empty($searchParams)) {
foreach ($searchParams[0] as $value) {
if ($value[0] == 'date_start') {
if ('date_start' == $value[0]) {
$this->fieldInfo['searchOperator'] = $value[1];
}
}
Expand Down
12 changes: 6 additions & 6 deletions modules/Calendar/models/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public function getDetailViewUrl()
return 'index.php?module=Calendar&view=' . $this->getModule()->getDetailViewName() . '&record=' . $this->getId();
}

/**
* {@inheritdoc}
*/
public function saveToDb()
{
//Time should changed to 24hrs format
\App\Request::_set('time_start', Vtiger_Time_UIType::getTimeValueWithSeconds(\App\Request::_get('time_start')));
\App\Request::_set('time_end', Vtiger_Time_UIType::getTimeValueWithSeconds(\App\Request::_get('time_end')));
parent::saveToDb();
$this->updateActivityReminder();
$this->insertIntoInviteTable();
Expand Down Expand Up @@ -227,7 +227,7 @@ public function insertIntoActivityReminderPopup()
->scalar();
$currentStates = Calendar_Module_Model::getComponentActivityStateLabel('current');
$state = Calendar_Module_Model::getCalendarState($this->getData());
if (in_array($state, $currentStates)) {
if (\in_array($state, $currentStates)) {
$status = self::REMNDER_POPUP_ACTIVE;
} else {
$status = self::REMNDER_POPUP_INACTIVE;
Expand Down Expand Up @@ -363,7 +363,7 @@ public function getRecordListViewLinksLeftSide()
$links = parent::getRecordListViewLinksLeftSide();
$recordLinks = [];
$statuses = Calendar_Module_Model::getComponentActivityStateLabel('current');
if ($this->isEditable() && in_array($this->getValueByField('activitystatus'), $statuses)) {
if ($this->isEditable() && \in_array($this->getValueByField('activitystatus'), $statuses)) {
$recordLinks[] = [
'linktype' => 'LIST_VIEW_ACTIONS_RECORD_LEFT_SIDE',
'linklabel' => 'LBL_SET_RECORD_STATUS',
Expand All @@ -386,7 +386,7 @@ public function getRecordRelatedListViewLinksLeftSide(Vtiger_RelationListView_Mo
{
$links = parent::getRecordRelatedListViewLinksLeftSide($viewModel);
if ($viewModel->getRelationModel()->isEditable() && $this->isEditable()) {
if (in_array($this->getValueByField('activitystatus'), Calendar_Module_Model::getComponentActivityStateLabel('current'))) {
if (\in_array($this->getValueByField('activitystatus'), Calendar_Module_Model::getComponentActivityStateLabel('current'))) {
$links['LBL_SET_RECORD_STATUS'] = Vtiger_Link_Model::getInstanceFromValues([
'linklabel' => 'LBL_SET_RECORD_STATUS',
'linkhref' => true,
Expand Down
Loading