Commit cb8cc533 authored by Uma's avatar Uma
Browse files

Fixes #89 Default module can be set for all users from MyPreferences page

parent 48fb4cd8
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -336,6 +336,7 @@ class WebserviceField{

	function getPicklistDetails(){
		$cache = Vtiger_Cache::getInstance();
        $fieldName = $this->getFieldName();
		if($cache->getPicklistDetails($this->getTabId(),$this->getFieldName())){
			return $cache->getPicklistDetails($this->getTabId(),$this->getFieldName());
		} else {
@@ -346,6 +347,25 @@ class WebserviceField{
				foreach ($allRegions as $regionId => $regionDetails) {
					$picklistDetails[] = array('value' => $regionId, 'label' => $regionDetails['name']);
				}
			}elseif ($fieldName == 'defaultlandingpage') {
                $picklistDetails = array(); 
                $presence = array(0);
                $restrictedModules = array('Emails', 'Dashboard', 'ModComments', 'PBXManager');
                $query = 'SELECT name, tablabel, tabid FROM vtiger_tab WHERE presence IN (' . generateQuestionMarks($presence) . ') AND isentitytype = ? AND name NOT IN (' . generateQuestionMarks($restrictedModules) . ')';

                $result = $this->pearDB->pquery($query, array($presence, '1', $restrictedModules));
                $numOfRows = $this->pearDB->num_rows($result);

                $picklistDetails[] = array('value' => 'Home', 'label' => vtranslate('Home', 'Home'));
                for ($i = 0; $i < $numOfRows; $i++) {
                    $moduleName = $this->pearDB->query_result($result, $i, 'name');

                    // check the module access permission, if user has permission then show it in default module list
                    if (vtlib_isModuleActive($moduleName)) {
                        $moduleLabel = $this->pearDB->query_result($result, $i, 'tablabel');
                        $picklistDetails[] = array('value' => $moduleName, 'label' => vtranslate($moduleLabel, $moduleName));
                    }
                }
            } else {
				$hardCodedPickListNames = array('hdntaxtype','email_flag');
				$hardCodedPickListValues = array('hdntaxtype'=> array(	array('label' => 'Individual',	'value' => 'individual'),
+2 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ function vtlib_toggleModuleAccess($modules, $enable_disable) {
	} else if($enable_disable === false) {
		$enable_disable = 1;
		$event_type = Vtiger_Module::EVENT_MODULE_DISABLED;
        //Update default landing page to dashboard if module is disabled.
        $adb->pquery('UPDATE vtiger_users SET defaultlandingpage = ? WHERE defaultlandingpage IN(' . generateQuestionMarks($modules) . ')', array_merge(array('Home'), $modules));
	}

	$checkResult = $adb->pquery('SELECT name FROM vtiger_tab WHERE name IN ('. generateQuestionMarks($modules) .')', array($modules));
+1 −1
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ class Vtiger_WebUI extends Vtiger_EntryPoint {

			if(empty($module)) {
				if ($this->hasLogin()) {
					$defaultModule = vglobal('default_module');
					$defaultModule = $currentUser->defaultlandingpage;
					$moduleModel = Vtiger_Module_Model::getInstance($defaultModule);
					if(!empty($defaultModule) && $defaultModule != 'Home' && $moduleModel && $moduleModel->isActive()) {
						$module = $defaultModule; $qualifiedModuleName = $defaultModule; $view = 'List';
+4 −0
Original line number Diff line number Diff line
@@ -107,7 +107,11 @@
											{/if}

											<span class="value textOverflowEllipsis" data-field-type="{$FIELD_MODEL->getFieldDataType()}" {if $FIELD_MODEL->get('uitype') eq '19' or $FIELD_MODEL->get('uitype') eq '20' or $FIELD_MODEL->get('uitype') eq '21'} style="white-space:normal;" {/if} {if $fieldDataType eq 'email'}title='{$FIELD_MODEL->get('fieldvalue')}'{/if} >
                                                                                            {if $FIELD_MODEL->getName() neq 'defaultlandingpage'}
												{include file=vtemplate_path($FIELD_MODEL->getUITypeModel()->getDetailViewTemplateName(),$MODULE_NAME) FIELD_MODEL=$FIELD_MODEL USER_MODEL=$USER_MODEL MODULE=$MODULE_NAME RECORD=$RECORD}
                                                                                            {else}
                                                                                                {vtranslate($FIELD_MODEL->get('fieldvalue'),$FIELD_MODEL->get('fieldvalue'))}
                                                                                            {/if}
											</span>
											{if $IS_AJAX_ENABLED && $FIELD_MODEL->isEditable() eq 'true' && $FIELD_MODEL->isAjaxEditable() eq 'true'}
												<span class="hide edit pull-left">
+45 −0
Original line number Diff line number Diff line
@@ -92,4 +92,49 @@ if (defined('VTIGER_UPGRADE')) {
    $db->pquery('UPDATE vtiger_emailtemplates SET module=? WHERE templatename IN ('. generateQuestionMarks($defaultContactTemplates).')', $updateContactParams);
    
    echo 'Email templates default moduleName updated';
    
    //Migrate default module data from config editor to database
    $moduleModel = Settings_Vtiger_ConfigModule_Model::getInstance();
    $configFieldData = $moduleModel->getViewableData();
    $defaultModule = $configFieldData['default_module'];
    if(empty($defaultModule)){
        $defaultModule = 'Home';
    }

    $moduleInstance = Vtiger_Module_Model::getInstance('Users');
    $blockInstance = Vtiger_Block::getInstance('LBL_MORE_INFORMATION', $moduleInstance);
    if ($blockInstance) {
        $fieldInstance = Vtiger_Field::getInstance('defaultlandingpage', $moduleInstance);
        if (!$fieldInstance) {
            $fieldInstance = new Vtiger_Field();
            $fieldInstance->name		= 'defaultlandingpage';
            $fieldInstance->column		= 'defaultlandingpage';
            $fieldInstance->label		= 'Default Landing Page';
            $fieldInstance->table		= 'vtiger_users';
            $fieldInstance->columntype = 'VARCHAR(100)';
            $fieldInstance->defaultvalue = $defaultModule;
            $fieldInstance->typeofdata = 'V~O';
            $fieldInstance->uitype		= '32';
            $fieldInstance->presence	= '0';

            $blockInstance->addField($fieldInstance);
            $configModuleInstance = Settings_Vtiger_ConfigModule_Model::getInstance();
            $defaultModules = $configModuleInstance->getPicklistValues('default_module');
            $fieldInstance->setPicklistValues($defaultModules);
            echo "<br> Default landing page field added <br>";
        }
    }

    $allUsers = Users_Record_Model::getAll(true);
    $allUserIds = array_keys($allUsers);

    $db->pquery('UPDATE vtiger_users SET defaultlandingpage = ? WHERE id in ('. generateQuestionMarks($allUserIds) .')', array($defaultModule, $allUserIds));
    echo "Default landing page updated for all active users <br>";
    
    //Recalculating user-preivilege file, as defaultlandingpage and other preference changes should be updated
    foreach ($allUserIds as $userId) {
        createUserPrivilegesfile($userId);
        createUserSharingPrivilegesfile($userId);
    }
    echo "Re-calculated user privilege and sharing privileges files";
}
 No newline at end of file
Loading