Changes

Links update and some minor fixes. Moreover the new syntax highlight extension was enabled
Line 2: Line 2:       −
Languages: '''English''' - [http://www.giustetti.net/wiki/index.php?title=vtigercrm_modificare_il_comportamento_dei_campi_data Italiano]
+
Languages: '''English''' - [[vtigercrm_modificare_il_comportamento_dei_campi_data | Italiano]]
    
----
 
----
   −
== '''datefield''' standard behavior ==
+
== '''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'''.
 
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 ==
+
== 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:
 
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
+
   bash-4.1# '''ls''' ''-la'' ./Smarty
 
   total 64
 
   total 64
 
   drwxr-xr-x  8 apache apache  4096 Nov 15  2010 .
 
   drwxr-xr-x  8 apache apache  4096 Nov 15  2010 .
Line 42: Line 42:  
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.
 
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 ===
+
=== Original Source Code ===
 +
<syntaxhighlight lang="php">
 
   /** This function returns the date in user specified format.
 
   /** This function returns the date in user specified format.
 
   * Takes no param, receives the date format from current user object
 
   * Takes no param, receives the date format from current user object
Line 76: Line 77:  
       return $display_date;
 
       return $display_date;
 
   }
 
   }
 +
</syntaxhighlight>
   −
=== Updated source code ===
+
=== Updated Source Code ===
 +
<syntaxhighlight lang="php">
 
   /** This function returns the date in user specified format.
 
   /** This function returns the date in user specified format.
 
   * Takes no param, receives the date format from current user object
 
   * Takes no param, receives the date format from current user object
Line 91: Line 94:  
       return $display_date;
 
       return $display_date;
 
   }
 
   }
 +
</syntaxhighlight>
   −
=== Restrict the update to some modules only ===
+
=== 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:
 
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:
 +
<syntaxhighlight lang="php">
 
   /** This function returns the date in user specified format.
 
   /** This function returns the date in user specified format.
 
   * Takes no param, receives the date format from current user object
 
   * Takes no param, receives the date format from current user object
Line 129: Line 134:  
       return $display_date;
 
       return $display_date;
 
   }
 
   }
 
+
</syntaxhighlight>
 
Line:
 
Line:
 +
<syntaxhighlight lang="php">
 
       $module_name = $_REQUEST['module'];
 
       $module_name = $_REQUEST['module'];
 +
</syntaxhighlight>
 
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
 
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
 +
<syntaxhighlight lang="php">
 
       case "Policy":
 
       case "Policy":
 
         $display_date = '';
 
         $display_date = '';
Line 139: Line 147:  
         $display_date = '';
 
         $display_date = '';
 
       break;
 
       break;
 +
</syntaxhighlight>
 
initialize modules "Policy" and "Project" date fields with a null value during data inserts or updates.
 
initialize modules "Policy" and "Project" date fields with a null value during data inserts or updates.
 
The last code lines
 
The last code lines
 +
<syntaxhighlight lang="php">
 
       default:
 
       default:
 
         global $current_user;
 
         global $current_user;
Line 155: Line 165:  
         }
 
         }
 
       }
 
       }
 +
</syntaxhighlight>
 
set calendar control standard behavior for each other module in VtigerCRM.
 
set calendar control standard behavior for each other module in VtigerCRM.
   Line 165: Line 176:  
----
 
----
   −
Languages: '''English''' - [http://www.giustetti.net/wiki/index.php?title=vtigercrm_modificare_il_comportamento_dei_campi_data Italiano]
+
Languages: '''English''' - [[vtigercrm_modificare_il_comportamento_dei_campi_data | Italiano]]