This is an old revision of the document!


PopUp Relations

Require vtigerCRM 6.1

This modification could decrease the frontend performance a little.
In modern Browsers this won't recognizable.
It execute 2 database Queries on the EditView/CreateView and one in the PopUp.

At first please install

Create DB Table

CREATE TABLE IF NOT EXISTS `vtiger_popup_relation` (
`id` INT(11) NOT NULL,
`src_module` VARCHAR(30) NOT NULL,
`src_field` VARCHAR(50) NOT NULL,
`module` VARCHAR(30) NOT NULL,
`search_key` VARCHAR(50) NOT NULL
) ENGINE=InnoDB ;
 
ALTER TABLE `vtiger_popup_relation`
 ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `src_module` (`src_module`,`src_field`,`module`);
 
ALTER TABLE `vtiger_popup_relation`
MODIFY `id` INT(11) NOT NULL AUTO_INCREMENT;

Open: /modules/Vtiger/views/Popup.php

Search: [~Line 106]

if(empty($cvId)) {

Insert Before:

/**
 * START swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */
$swpopup_search= $request->get('swpopup_search');
if(empty($searchKey) === true && empty($swpopup_search) === false) {
    $searchValue = Vtiger_Util_Helper::getRecordName(intval($request->get('swpopup_value')));
    $searchKey = $swpopup_search;
}
/**
 * END swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */

Open: /module/Vtiger/views/Edit.php

Search: [~Line 106]

$viewer->view('EditView.tpl', $moduleName);

Insert After:

/**
 * START swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */
$adb = \PearDatabase::getInstance();
 
$result = $adb->pquery(
    'SELECT src_field, search_key, search_value FROM vtiger_popup_relation WHERE src_module = ?',
    array($moduleName)
);
if($adb->num_rows($result) > 0) {
    $additionalParameters = array();
    while($row = $adb->fetchByAssoc($result)) {
        $additionalParameters[$row['src_field']] = array($row['search_key'], $row['search_value']);
    }
    echo '<script type="text/javascript">
        var $additionalSearchParameters = '.json_encode($additionalParameters).';
        jQuery(function() {
            if(typeof SWVtigerTools !== "undefined") {
                SWVtigerTools.registerFilter("PopUpParams", function(params) {
                    if(typeof $additionalSearchParameters[params.src_field] !== "undefined") {
                        var value = $additionalSearchParameters[params.src_field];
                        var fieldValue = jQuery(\'[name="\' + value[1] + \'"]\').val();
                        if(fieldValue == "") return params;
                        params["swpopup_search"] = value[0];
                        params["swpopup_value"] = fieldValue
                    }
                    return params;
                });
            }
        });
    </script>';
}
/**
 * END swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */

Open: /layouts/vlayout/modules/Vtiger/resources/Edit.js

Search: [~Line 109]

if(isMultiple) {
    params.multi_select = true ;
}

Insert After:

/**
 * START swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */
if(typeof SWVtigerTools === 'object' && typeof SWVtigerTools.filter === 'function') {
    params = SWVtigerTools.filter('PopUpParams', params);
}
/**
 * END swarnat Modification
 * https://support.stefanwarnat.de/en:modifications:popup_relations
 */