diff --git a/vtlib/Vtiger/AppMenu.php b/vtlib/Vtiger/AppMenu.php new file mode 100644 index 0000000000000000000000000000000000000000..8ae3e09d0dda1b2aed4a708da64b60e582f092d6 --- /dev/null +++ b/vtlib/Vtiger/AppMenu.php @@ -0,0 +1,111 @@ +<?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 diff --git a/vtlib/Vtiger/ModuleBasic.php b/vtlib/Vtiger/ModuleBasic.php index ecd3d5cab751701b7b10e91ac72f167e46db958e..d6b83a8ce44477156183da0868671cc3696bf2bb 100644 --- a/vtlib/Vtiger/ModuleBasic.php +++ b/vtlib/Vtiger/ModuleBasic.php @@ -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); } diff --git a/vtlib/Vtiger/PackageExport.php b/vtlib/Vtiger/PackageExport.php index 8d7663d09ac21e1783df6a7ba6b182bf8e562a43..3b1730ef8ff05581b7f10679d3d1a4032bd179d5 100644 --- a/vtlib/Vtiger/PackageExport.php +++ b/vtlib/Vtiger/PackageExport.php @@ -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 +?> diff --git a/vtlib/Vtiger/PackageImport.php b/vtlib/Vtiger/PackageImport.php index 3ab7b0c40d7dbaebec0c6985dcb5361ceeb18039..9a0d65a6633a139fa13edb1b4be18d2d2b3d04fa 100644 --- a/vtlib/Vtiger/PackageImport.php +++ b/vtlib/Vtiger/PackageImport.php @@ -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);