Adding a default page to user preferences

Adding a default page to user preferences

Vtiger 7.3 brought us many performance and functionality improvements. Among other things, an interesting feature has been added - in the settings of an individual user, choose which page to open by default after authorization. Previously, this could only be done globally from the system settings.

Vtiger 7.3 brought us many performance and functionality improvements. Among other things, an interesting feature has been added - in the settings of an individual user, choose which page to open by default after authorization. Previously, this could only be done globally from the system settings.

If for some reason you cannot upgrade to version 7.3, then you can implement this separate functionality in Vtiger. To do this, you will need to run the script for adding a field, as well as make changes to the Vtiger code. So let's get started.

The first thing to do is add the field we need. We write the script we need:

<?php

 

// Turn on debugging level

$Vtiger_Utils_Log = true;

chdir('../');

require_once('vtlib/Vtiger/Menu.php');

require_once('vtlib/Vtiger/Block.php');

require_once('vtlib/Vtiger/Field.php');

 

// Include necessary classes

include_once('vtlib/Vtiger/Module.php');

 

// Define instances

$users = Vtiger_Module::getInstance('Users');

$blockInstance = new Vtiger_Block();

 

// Nouvelle instance pour le nouveau bloc

$block = Vtiger_Block::getInstance('LBL_MORE_INFORMATION', $users);

 

 

// Add Default User Module

$fieldInstance = new Vtiger_Field();

$fieldInstance->name = 'user_default_module';

$fieldInstance->table = 'vtiger_users';

$fieldInstance->column = 'user_default_module';

$fieldInstance->label = 'User Default Module ';

$fieldInstance->columntype = 'varchar(50)';

$fieldInstance->uitype = 15;

$fieldInstance->typeofdata = 'V~O';

$block->addField($fieldInstance);

 

?>

We put the script in the scripts folder at the root of the CRM system with the name add_lp_field.php. If this folder does not exist, create it. Next, run this file once from the browser at scripts / add_lp_field.php.

Now we need to make a number of changes to the CRM files.

Change the file includes / main / WebUI.php

After these lines (around 104-105):

  $currentUser = $this->getLogin();

  vglobal('current_user', $currentUser);

 

Add following:

        $user_default_module = $currentUser->user_default_module;

        if (empty($user_default_module)) {

            $user_default_module = vglobal('default_module');

        }

vglobal('user_default_module', $user_default_module);

 

Then go to lines 165-166, try to find following:

 

if(empty($module)) {

  if ($this->hasLogin()) {

$defaultModule = vglobal('default_module');

 

Remove line $defaultModule = vglobal('default_module');

Instead add following:

$defaultModule = vglobal('user_default_module');

Then go to file modules/Vtiger/models/Field.php.

Add new function near line 248:

    public function getModulesList(){

        global $adb;

        // vtlib customization: Ignore disabled and Tools modules

        $query = 'select distinct vtiger_tab.tablabel, vtiger_tab.name as tabname from vtiger_tab where (vtiger_tab.presence != 1 and vtiger_tab.parent != "Tools" and vtiger_tab.parent != "")';

 

        // END

        $result = $adb->pquery($query, array());

        while($row = $adb->fetch_array($result)){

            $modules[$row['tablabel']] = $row['tabname'];

        }

        return $modules;

    }

Then you need to call this function in в getPicklistValues.

Go to line 317, try to find this lines:

}else{

  $picklistValues = Vtiger_Util_Helper::getPickListValues($fieldName);

  }

 

 After them add following code:

            $fieldName = $this->getName();

            if ($fieldName === 'user_default_module'){

             $picklistValues = $this->getModulesList();

            }

 

If you have successfully completed the above actions, then you should have a new field shown in the picture in the user settings. And after authorization, this user should go to the page specified in the settings