******************************************************************************* * * Enhanced Studio for SugarCRM * * Plugin adding new customization capabilities to SugarCRM Studio and Module Builder. * * Developed by Patrizio Gelosi * * Version: 2.2.1 - Date : 01 Jan 2009 * ******************************************************************************* ****************************** INSTALLATION ****************************** Once logged as admin user, install the package using the "Administration -> Module Loader" tool. *********************** UNINSTALLATION / DISABLING *********************** Once logged as admin user, uninstall / disable the package using the "Administration -> Module Loader" tool. ************************* SUGARCRM COMPATIBILITY ************************* Enhanced Studio is compatible with all version/editions of SugarCRM 5.1. **************************** SUGARCRM UPGRADE **************************** To upgrade SugarCRM with Enhanced Studio installed : 1- Uninstall Enhanced Studio. 2- Install the SugarCRM upgrade. 3- Re-install Enhanced Studio. ******************************* DESCRIPTION ****************************** Enhanced Studio provides SugarCRM Studio and Module Builder with new customization features. It helps the users to add unlimited features to any module by programming the new CODE type field, that can be found among the default SugarCRM ones. THIS WAY SUGARCRM CAN BE EASILY CUSTOMIZED WITHOUT TOUCHING SUGARCRM PHP CODE. It may be used for the widest range of purposes, such as adding to the ListView / EditView / DetailView the following elements : - Images - Buttons - AJAX-based updating fields - AJAX-based autocomplete fields - Fields automatically evaluated from others - Embedded elements (Flash, Java, etc.) ...and whatever the user has in mind (there's virtually no limitation) FROM THE 2.0 RELEASE CODE FIELDS CAN BE STORED/RETRIEVED AS A COMMON CUSTOM FIELD WHOSE DB-TYPE CAN BE SELECTED BY THE USER. The new DB CODE type is availble to be : - Created - Viewed - Edited - Searched for (also with Enahnced Search Support for numeric fields) - Ordered by (*** New in 2.2 release ***) - Added to dashlet - Imported from a file Using the php code the Code field may be given a different behaviour for each Layout (see examples #4 and #5 below). ************************** SUGARCRM STUDIO USAGE ************************* TO CREATE A NEW CODE-TYPE FIELD. 1- Add a new CODE type field to any SugarCRM default module (Accounts, Contacts, ...). 2- Add the new CODE field to the desired Layouts : EditView, DetailView, ListView, QuickCreate, Basic and Advanced Search. TO MODIFY AN EXISTING CODE-TYPE FIELD. Edit the CODE field according to your preferences. *** WARNING : *** Be careful on changing the DB-Type of any CODE field to an incompatible type field (i.e. text => integer) when the related DB table of Sugar DB is not empty (that might also happen when no row is shown in SugarCRM, as rows are logically but not physically deleted ). This obviously leads to an error since such DB values cannot be automatically converted. So changing DB-type is allowed even after the start-up, but related tables must be manually emptied if DB types conversion is not supported by the DB Engine. TO MANAGE A CODE TYPE FIELD IN SUGARCRM STUDIO. If a CODE type field is selected on the SugarCRM Studio tool on the Fields page, the new specific CODE entries appear : 1- DB Type entry. DB Type value depends on the kind of CODE fields is to be generated. Two different kinds of CODE field are available : a. Non-DB field. To select a Non-DB field leave blank the DB Type entry. This kind of field is only run-time evaled and doesn't need to be stored/retrieved to/from DB. All the CODE fields of the previous versions belong to this category. An example is the GOOGLE MAP AUTOMATIC LINK reported below. b. DB field. From the 2.0 release, values of any DB type can be stored/retrieved to/from DB for each CODE field, exactly like other SugarCRM fields. The Code entry content is also run-time evaled and the field value can be used in the php code entered (a Sugar TEXT field is simulated in the Example #4 below). Field value can be referred to as "$bean->" in the php code ( is the user-defined Field Name with the "_c" postfix) The user can enter the SQL creation query directly into the DB Type entry, according to the DB Engine. For instance a valid entry for a MySQL DB can be the following : INT (11) NOT NULL DEFAULT 0 If the DB field value produces a SQL error, the new field isn't correctly saved. 2- Code entry. The content of the "Code" entry is a php code which is run-time evaled when the field is list-viewed, detail-viewed or edited. The new field can be added to any Studio Layout: EditView, DetailView, ListView, QuickCreate, Dashlet, Basic and Advanced Search. This means that a CODE DB field can be viewed, edited, and even searched for. Numeric CODE DB fields are also recognized by Enhanced Search v. 2.1 and can be searched for using the Enhanced Search numeric operator. See the Examples Section above for more details. ***************** MODULE BUILDER USAGE (FULL VERSION ONLY) *************** TO CREATE A NEW CODE-TYPE FIELD. 1- Add a new CODE type field to any user-generated module. 2- Add the new CODE field to the desired Layouts : EditView, DetailView, ListView, QuickCreate, Dashlet, Basic and Advanced Search. 3- Deploy the package. TO MODIFY AN EXISTING CODE-TYPE FIELD. 1- Edit the CODE field according to your preferences. 2- Deploy the package *** WARNING : *** Be careful on changing the DB-Type of any CODE field to an incompatible type field (i.e. text => integer) when the related DB table of Sugar DB is not empty (that might also happen when no row is shown in SugarCRM, as rows are logically but not physically deleted ). This obviously leads to an error since such DB values cannot be automatically converted. So changing DB-type is allowed even after the start-up, but related tables must be manually emptied if DB types conversion is not supported by the DB Engine. TO MANAGE A CODE TYPE FIELD IN SUGARCRM MODULE BUILDER. If a CODE type field is selected on the SugarCRM Module Builder tool on the Fields page, the new specific CODE entries appear : 1- Default Value entry. A default value can be entered for the DB field, according to the DB Type selected (the Default Value is ignored for Non-DB fields). This entry is disabled for "text", "longtext", "multienum" ,"blob" and "longblob" DB Types. 2- Max Size entry. A max length in bytes can be assigned to DB fields (the Max Size is ignored for Non-DB fields) 3- DB Type selection. DB Type value depends on the kind of CODE fields is to be generated. Two different kinds of CODE field are available : a. Non-DB field. Select "Non-DB" on DB Type selection to create / change into a Non-DB field. This kind of field is only run-time evaled and doesn't need to be stored/retrieved to/from DB. All the CODE fields of the previous versions belong to this category. An example is the GOOGLE MAP AUTOMATIC LINK reported below. b. DB field entry. From the 2.0 release, values of any DB type can be stored/retrieved to/from DB for each CODE field, exactly like other SugarCRM fields. The Code entry content is also run-time evaled and the field value can be used in the php code entered (a Sugar TEXT field is simulated in the Example #4 below). Field value can be referred to as "$bean->" in the php code . *** WARNING : *** is the user-defined Field Name WITHOUT the "_c" postfix (which is required in SugarCRM Studio). 4- Code entry. The content of the "Code" entry is a php code which is run-time evaled when the field is list-viewed, detail-viewed or edited. The new field can be added to any MB Layout: EditView, DetailView, ListView, QuickCreate, Dashlet, Basic and Advanced Search. This means that a CODE DB field can be viewed, edited, searched for and ordered by in the ListView. Numeric CODE DB fields are also recognized by Enhanced Search v. 2.1 and can be searched for using the Enhanced Search numeric operator. See the Examples Section above for more details. ******************************** EXAMPLES ******************************** 1- PROGRESSIVE ID CODE. Add a progressive ID code to the listview. HOW-TO: create a new CODE field on Admin -> (Studio / Module Builder) -> with the values below, then add it to Layouts -> ListView. DB Type : CODE: $GLOBALS['count_cc']++; echo '
'.$GLOBALS['count_cc'].'
' N.B.: A semicolon (";") is automatically added at the end of the CODE string by default, so it can be omitted on the last code line 2- OPPORTUNITIES WARNING ON AMOUNT Add a warning field that show different images depending on the amount value. HOW-TO: create a new CODE field on Admin -> Studio -> Opportunities with the values below, then add it to Layouts -> ListView. DB Type : CODE: if ($bean->amount_usdollar > 60000) echo ""; elseif ($bean->amount_usdollar < 20000) echo ""; 3- GOOGLE MAP AUTOMATIC LINK Add a link on Contacts / Accounts modules to the map of the customer address HOW-TO: create a new CODE field on Studio -> (Contacts / Accounts) with the values below, then add it to Layouts -> EditView or DetailView. DB Type : CODE for Accounts: $search_string = urlencode("$bean->billing_address_street $bean->billing_address_city - $bean->billing_address_country"); echo <<Click here to view the map END ; CODE for Contacts: $search_string = urlencode("$bean->primary_address_street $bean->primary_address_city - $bean->primary_address_country"); echo <<Click here to view the map END ; 4- STORE/RETRIEVE A COMMON TEXT FIELD This example shows how to add a custom CODE field that act like a text one. The effect is the same of adding ad SugarCRM text field, but it can be used as a base to develop new features (such as AJAX spellcheck, auto-complete or validate HTML for instance). HOW-TO: create a new CODE field on Admin -> (Studio / Module Builder) -> with the values below, then add it to Layouts -> ListView, EditView and DetailView. The in the CODE must be replaced with your field name. *** The "_c" postfix to the field name is required on Studio. *** DB Type : TEXT CODE: if ($GLOBALS['app']->controller->action == 'EditView') echo << END ; else echo $bean-> 5- IMAGE FIELD. Add a common image field with a web link. HOW-TO: create a new CODE field on Admin -> Studio -> with the values below, then add it to Layouts -> EditView and DetailView. Field Name : web_image Display Label: web image System Label: LBL_WEB_IMAGE DB Type : VARCHAR(255) CODE: if ($GLOBALS['app']->controller->action == 'EditView') echo <<
END ; if ($bean->web_image_c) echo '
' 6- AJAX CALL. Perform an ajax call. Field Name : CODE: echo << function ajax_action () { var callback = { success: function(o) { } } var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", , callback); } END ; 7- EXTERNAL DB QUERY Connects to an external DB , execute a query and dump result. CODE: $res = mysql_connect(, , ); mysql_select_db(, $res); $sql = ; $res = mysql_query($sql, $res); $value = mysql_result($res, ); echo $value;