Skip to content
Snippets Groups Projects
Commit f363e10e authored by Prasad's avatar Prasad
Browse files

Fixes #1898: Entry to app2tab handled for create, export and import

parent 921c19aa
No related branches found
No related tags found
No related merge requests found
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
/**
* Provides API to work with vtiger CRM App Menu
* @package vtlib
*/
class Vtiger_AppMenu {
var $appname;
var $tabid;
var $sequence;
var $visibile;
/**
* Constructor
*/
function __construct() {
}
/**
* Initialize this instance
* @param Array Map
* @access private
*/
function initialize($valuemap) {
$this->appname = $valuemap['appname'];
$this->tabid = $valuemap['tabid'];
$this->sequence = $valuemap['sequence'];
$this->visibile = $valuemap['visible'];
}
/**
* Get relation sequence to use
* @access private
*/
function __getNextSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(sequence) AS max_seq FROM vtiger_app2tab WHERE appname=?",
Array($this->appname));
$maxseq = $adb->query_result($result, 0, 'max_seq');
return ++$maxseq;
}
/**
* Add module to this menu instance
* @param Vtiger_Module Instance of the module
*/
function addModule($moduleInstance) {
if($this->appname) {
global $adb;
// check existing
$checkrs = $adb->pquery("SELECT * FROM vtiger_app2tab WHERE appname = ? and tabid = ? LIMIT 1", array(
$this->appname, $moduleInstance->id));
if ($row = $adb->fetch_row($checkrs)) {
$this->initialize($row);
self::log("Found appmenu in $this->appname ... DONE");
} else {
// add new
$sequence = $this->__getNextSequence();
$adb->pquery("INSERT INTO vtiger_app2tab (appname,tabid,sequence,visible) VALUES(?,?,?,?)",
Array($this->appname, $moduleInstance->id, $sequence, 1));
self::log("Added to appmenu $this->appname ... DONE");
}
} else {
self::log("AppMenu could not be found!");
}
}
/**
* Detach module from menu
* @param Vtiger_Module Instance of the module
*/
static function detachModule($moduleInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_app2tab WHERE tabid=?", Array($moduleInstance->id));
self::log("Detaching from appmenu ... DONE");
}
/**
* Get instance of menu by appname
* @param String AppMenu
*/
static function getInstance($value) {
global $adb;
$instance = false;
$query = "SELECT appname FROM vtiger_app2tab WHERE appname=? LIMIT 1"; /* existing appname */
$result = $adb->pquery($query, Array($value));
if($adb->num_rows($result)) {
$instance = new self();
$instance->initialize($adb->fetch_array($result));
}
return $instance;
}
/**
* Helper function to log messages
* @param String Message to log
* @param Boolean true appends linebreak, false to avoid it
* @access private
*/
static function log($message, $delim=true) {
Vtiger_Utils::Log($message, $delim);
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ include_once('vtlib/Vtiger/Field.php');
include_once('vtlib/Vtiger/Filter.php');
include_once('vtlib/Vtiger/Profile.php');
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/AppMenu.php');
include_once('vtlib/Vtiger/Link.php');
include_once('vtlib/Vtiger/Event.php');
include_once('vtlib/Vtiger/Webservice.php');
......@@ -202,7 +203,10 @@ class Vtiger_ModuleBasic {
if (!empty($parentTab)) {
$menuInstance = Vtiger_Menu::getInstance($parentTab);
$menuInstance->addModule($moduleInstance);
if ($menuInstance) $menuInstance->addModule($moduleInstance);
$appmenuInstance = Vtiger_AppMenu::getInstance($parentTab);
if ($appmenuInstance) $appmenuInstance->addModule($moduleInstance);
}
self::log("Creating Module $this->name ... DONE");
......@@ -273,6 +277,7 @@ class Vtiger_ModuleBasic {
Vtiger_Profile::deleteForModule($this);
Vtiger_Link::deleteAll($this->id);
Vtiger_Menu::detachModule($this);
Vtiger_AppMenu::detachModule($this);
self::syncfile();
Vtiger_Cache::flushModuleCache($this->name);
}
......
......@@ -244,11 +244,19 @@ class Vtiger_PackageExport {
global $adb;
$moduleid = $moduleInstance->id;
$parent_name = '';
$sqlresult = $adb->pquery("SELECT * FROM vtiger_parenttabrel WHERE tabid = ?", array($moduleid));
$parenttabid = $adb->query_result($sqlresult, 0, 'parenttabid');
$menu = Vtiger_Menu::getInstance($parenttabid);
$parent_name = $menu->label;
if ($menu) {
$parent_name = $menu->label;
} else {
$sqlresult = $adb->pquery("SELECT * FROM vtiger_app2tab WHERE tabid = ? LIMIT 1", array($moduleid));
if ($adb->num_rows($sqlresult)) {
$parent_name = $adb->query_result($sqlresult, 0, 'appname');
}
}
$sqlresult = $adb->pquery("SELECT * FROM vtiger_tab WHERE tabid = ?", array($moduleid));
$tabresultrow = $adb->fetch_array($sqlresult);
......@@ -261,7 +269,7 @@ class Vtiger_PackageExport {
$this->outputNode(date('Y-m-d H:i:s'),'exporttime');
$this->outputNode($tabname, 'name');
$this->outputNode($tablabel, 'label');
$this->outputNode($parent_name, 'parent');
if ($parent_name) $this->outputNode($parent_name, 'parent');
if(!$moduleInstance->isentitytype) {
$this->outputNode('extension', 'type');
......@@ -722,4 +730,4 @@ class Vtiger_PackageExport {
Vtiger_Utils::Log($message, $delim);
}
}
?>
\ No newline at end of file
?>
......@@ -501,7 +501,10 @@ class Vtiger_PackageImport extends Vtiger_PackageExport {
if(!empty($parenttab)) {
$parenttab = $parentTabs[0];
$menuInstance = Vtiger_Menu::getInstance($parenttab);
$menuInstance->addModule($moduleInstance);
if ($menuInstance) $menuInstance->addModule($moduleInstance);
$appMenuInstance = Vtiger_AppMenu::getInstance($parenttab);
if ($appMenuInstance) $appMenuInstance->addModule($moduleInstance);
}
$this->import_Tables($this->_modulexml, $moduleInstance);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment