Changes

From Studiosg
Jump to navigationJump to search
Created page with 'Welcome to Simone Giustetti's wiki pages. Languages: '''English''' - [http://www.giustetti.net/wiki/index.php?title=vtigercrm_modificare_il_comportamento_dei_campi_data Italian…'
Welcome to Simone Giustetti's wiki pages.


Languages: '''English''' - [http://www.giustetti.net/wiki/index.php?title=vtigercrm_modificare_il_comportamento_dei_campi_data Italiano]

----

== '''datefield''' standard behavior ==
Dates are managed through a '''dedicated calendar control''' in VtigerCRM. The control '''automatically suggests the current date''' while inserting new data or updating old ones. The suggestion is usually useful, but could prove annoying in specific contexts: forms containing a lot of date fields for example. Were the form filled with many date fields the user would be pressed to enter each one to correct or remove the unwanted suggestion. A similar scenario requires '''to update the calendar control standard behavior into suggesting a null value'''. The current date should be suggested only upon control explicit selection. Let's see how to update the standard date field behavior in '''release 5.2.1 of VtigerCRM'''.


== VtigerCRM internals ==
Data processing code is split apart from presentation one in VtigerCRM. Information are retrieved from database, configuration files and other sources, processed then passed to sections of code dedicated to HTML page formatting. '''All web pages provided by the software are based on template models'''. VtigerCRM uses template engine '''Smarty''' to manage templates. All templates consist of text files with a syntax reminiscent of '''HTML''' with the addition of variables and control structures. All template files are saved in directory '''Smarty/templates''' a sub-directory of the VtigerCRM installation tree. The directory contains:
bash-4.1# ls -la ./Smarty
total 64
drwxr-xr-x 8 apache apache 4096 Nov 15 2010 .
drwxr-xr-x 28 apache apache 4096 Sep 7 01:32 ..
-rw-r--r-- 1 apache apache 24389 Nov 15 2010 COPYING.lib
drwxrwxr-x 2 apache apache 4096 May 5 2011 cache
drwxr-xr-x 2 apache apache 4096 Nov 15 2010 configs
drwxr-xr-x 4 apache apache 4096 Nov 15 2010 libs
drwxr-xr-x 2 apache apache 4096 Nov 15 2010 misc
drwxr-xr-x 8 apache apache 4096 Nov 15 2010 templates
drwxrwxr-x 2 apache apache 12288 Sep 16 00:25 templates_c
Directory '''templates''' contains source code files for standard controls, forms and web pages.<BR>
Directory '''templates_c''' contains pre-compiled template documents ready to be used by the software engine.

File '''Smarty/templates/EditViewUI.tpl''' contains templates used by the software forms while inserting or updating data.

File '''Smarty/templates/DetailView.tpl''' contains templates for standard controls. Templates are ordered by module.

File '''include/utils/utils.php''' contains function '''get_textdateField'''. The function sets default formatting / value for date fields.

File '''include/utils/CommonUtils.php''' contains function '''getNewDisplayDate()'''. The function assigns the current date value to date fields. The function is intended for variable initialization and as such ''responsible for date field behavior during insert and update operations''.

Function '''getNewDisplayDate()''' is called in some other source files:
* '''include/utils/EditViewUtils.php'''
* '''include/utils/utils.php'''
* '''modules/Emails/Save.php'''
* '''modules/com_vtiger_workflow/VTSimpleTemplate.inc'''

The function source code will be updated to change calendar controls standard behavior throughout the software modules. The purpose of the update is to ensure that date fields are initialized with a null value instead of the current date. The original source code and the updated one are listed below.

=== Original source code ===
/** This function returns the date in user specified format.
* Takes no param, receives the date format from current user object
*/

function getNewDisplayDate()
{
global $log;
$log->debug("Entering getNewDisplayDate() method ...");
$log->info("in getNewDisplayDate ");

global $current_user;
$dat_fmt = $current_user->date_format;
if($dat_fmt == '')
{
$dat_fmt = 'dd-mm-yyyy';
}
$display_date='';
if($dat_fmt == 'dd-mm-yyyy')
{
$display_date = date('d-m-Y');
}
elseif($dat_fmt == 'mm-dd-yyyy')
{
$display_date = date('m-d-Y');
}
elseif($dat_fmt == 'yyyy-mm-dd')
{
$display_date = date('Y-m-d');
}

$log->debug("Exiting getNewDisplayDate method ...");
return $display_date;
}

=== Updated source code ===
/** This function returns the date in user specified format.
* Takes no param, receives the date format from current user object
*/

function getNewDisplayDate() {
global $log;
$log->debug("Entering getNewDisplayDate() method ...");
$log->info("in getNewDisplayDate ");

$display_date='';
$log->debug("Exiting getNewDisplayDate method ...");
return $display_date;
}

=== Restrict the update to some modules only ===
The updated code will affect all of VtigerCRM modules. Some could prefer a more confined approach: update the behavior of the calendar controls '''for some modules only''', for example. Suppose the update should affect two modules only: standard module "Project" and custom one "Policy". The updated source code is available below:
/** This function returns the date in user specified format.
* Takes no param, receives the date format from current user object
*/

function getNewDisplayDate() {
global $log;
$log->debug("Entering getNewDisplayDate() method ...");
$log->info("in getNewDisplayDate ");

$display_date='';
$module_name = $_REQUEST['module'];
switch($module_name) {
case "Policy":
$display_date = '';
break;
case "Project":
$display_date = '';
break;
default:
global $current_user;
$dat_fmt = $current_user->date_format;
if($dat_fmt == '') {
$dat_fmt = 'dd-mm-yyyy';
}
if($dat_fmt == 'dd-mm-yyyy') {
$display_date = date('d-m-Y');
} elseif($dat_fmt == 'mm-dd-yyyy') {
$display_date = date('m-d-Y');
} elseif($dat_fmt == 'yyyy-mm-dd') {
$display_date = date('Y-m-d');
}
}
$log->debug("Exiting getNewDisplayDate method ...");
return $display_date;
}

Line:
$module_name = $_REQUEST['module'];
saves the active module name into a local variable for later filtering. Control structure "case" filters modules based on their name and executes specific code for each entry. Lines
case "Policy":
$display_date = '';
break;
case "Project":
$display_date = '';
break;
initialize modules "Policy" and "Project" date fields with a null value during data inserts or updates.
The last code lines
default:
global $current_user;
$dat_fmt = $current_user->date_format;
if($dat_fmt == '') {
$dat_fmt = 'dd-mm-yyyy';
}
if($dat_fmt == 'dd-mm-yyyy') {
$display_date = date('d-m-Y');
} elseif($dat_fmt == 'mm-dd-yyyy') {
$display_date = date('m-d-Y');
} elseif($dat_fmt == 'yyyy-mm-dd') {
$display_date = date('Y-m-d');
}
}
set calendar control standard behavior for each other module in VtigerCRM.

The above code update is a rather simple one, but can be further modified to execute checks for the suggested values, force a specific behavior for each module or execute some data processing. It is a starting point for further customizations.


For any feedback, questions, errors and such, please e-mail me at ''studiosg [at] giustetti [dot] net''


----

Languages: '''English''' - [http://www.giustetti.net/wiki/index.php?title=vtigercrm_modificare_il_comportamento_dei_campi_data Italiano]

Navigation menu