This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class AjaxCompose{
var $sections = array();
var $crumbs = array('Home'=>'ModuleBuilder.main("Home")',/* 'Assistant'=>'Assistant.mbAssistant.xy=Array("650, 40"); Assistant.mbAssistant.show();'*/);
function addSection($name, $title, $content, $action='activate'){
$crumb = '';
if($name == 'center'){
$crumb = $this->getBreadCrumb();
}
$this->sections[$name] = array('title'=>$title,'crumb'=>$crumb, 'content'=>$content, 'action'=>$action);
}
function getJavascript(){
if(!empty($this->sections['center'])){
if(empty($this->sections['east']))$this->addSection('east', '', '', 'deactivate');
if(empty($this->sections['east2']))$this->addSection('east2', '', '', 'deactivate');
}
$json = getJSONobj();
return $json->encode($this->sections);
}
function addCrumb($name, $action){
$this->crumbs[$name] = $action;
}
function getBreadCrumb(){
$crumbs = '';
$actions = array();
$count = 0;
foreach($this->crumbs as $name=>$action){
if($name == 'Home'){
$crumbs .= "<a onclick='$action' href='javascript:void(0)'>". getStudioIcon('home', 'home', 16, 16) . '</a>';
}else if($name=='Assistant'){
$crumbs .= "<a id='showassist' onclick='$action' href='javascript:void(0)'>". getStudioIcon('assistant', 'assistant', 16, 16) . '</a>';
}else{
if($count > 0){
$crumbs .= '&nbsp;>&nbsp;';
}else{
$crumbs .= '&nbsp;|&nbsp;';
}
if(empty($action)){
$crumbs .="<span class='crumbLink'>$name</span>";
$actions[] = "";
}else {
$crumbs .="<a href='javascript:void(0);' onclick='$action' class='crumbLink'>$name</a>";
$actions[] = $action;
}
$count++;
}
}
if($count > 1 && $actions[$count-2] != ""){
$crumbs = "<a onclick='{$actions[$count-2]}' href='javascript:void(0)'>". getStudioIcon('back', 'back', 16, 16) . '</a>&nbsp;'. $crumbs;
}
return $crumbs . '<br><br>';
}
function echoErrorStatus($labelName=''){
$sections = array('failure'=>true,'failMsg'=>$labelName);
$json = getJSONobj();
echo $json->encode($sections);
}
}
?>

View File

@@ -0,0 +1,100 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class MBField{
var $type = 'varchar';
var $name = false;
var $label = false;
var $vname = false;
var $options = false;
var $length = false;
var $error = '';
var $required = false;
var $reportable = true;
var $default = 'MSI1';
var $comment = '';
function getFieldVardef(){
if(empty($this->name)){
$this->error = 'A name is required to create a field';
return false;
}
if(empty($this->label))$this->label = $this->name;
$this->name = strtolower($this->getDBName($this->name));
$vardef = array();
$vardef['name']=$this->name;
if(empty($this->vname))$this->vname = 'LBL_' . strtoupper($this->name);
$vardef['vname'] = $this->addLabel();
if(!empty($this->required))$vardef['required'] = $this->required;
if(empty($this->reportable))$vardef['reportable'] = false;
if(!empty($this->comment))$vardef['comment'] = $this->comment;
if($this->default !== 'MSI1')$vardef['default'] = $this->default;
switch($this->type){
case 'date':
case 'datetime':
case 'float':
case 'int':
$vardef['type']=$this->type;
return $vardef;
case 'bool':
$vardef['type'] = 'bool';
$vardef['default'] = (empty($vardef['default']))?0:1;
return $vardef;
case 'enum':
$vardef['type']='enum';
if(empty($this->options)){
$this->options = $this->name . '_list';
}
$vardef['options'] = $this->addDropdown();
return $vardef;
default:
$vardef['type']='varchar';
return $vardef;
}
}
function addDropDown(){
return $this->options;
}
function addLabel(){
return $this->vname;
}
}
?>

View File

@@ -0,0 +1,252 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class MBLanguage{
var $iTemplates = array();
var $templates = array();
function MBLanguage( $name, $path, $label, $key_name){
$this->path = $path;
$this->name = $name;
$this->key_name = $key_name;
$this->label = $label;
}
function load(){
$this->generateModStrings();
$this->generateAppStrings();
}
function loadStrings($file){
$module = strtoupper($this->name);
$object_name = strtoupper($this->key_name);
$_object_name = strtolower($this->name);
if(!file_exists($file))return;
$d = dir($file);
while($e = $d->read()){
if(substr($e, 0, 1) != '.' && is_file($file . '/' . $e)){
include($file.'/'. $e);
if(empty($this->strings[$e])){
$this->strings[$e] = $mod_strings;
}else{
$this->strings[$e] = array_merge($this->strings[$e], $mod_strings);
}
}
}
}
function loadAppListStrings($file){
if(!file_exists($file))return;
//we may not need this when loading in the app strings, but there is no harm
//in setting it.
$object_name = strtolower($this->key_name);
$d = dir($file);
while($e = $d->read()){
if(substr($e, 0, 1) != '.' && is_file($file . '/' . $e)){
include($file.'/'. $e);
if(empty($this->appListStrings[$e])){
$this->appListStrings[$e] = $app_list_strings;
}else{
$this->appListStrings[$e] = array_merge($this->appListStrings[$e], $app_list_strings);
}
}
}
}
function generateModStrings(){
$this->strings = array();
$this->loadTemplates();
foreach($this->iTemplates as $template=>$val){
$file = MB_IMPLEMENTS . '/' . $template . '/language';
$this->loadStrings($file);
}
foreach($this->templates as $template=>$val){
$file = MB_TEMPLATES . '/' . $template . '/language';
$this->loadStrings($file);
}
$this->loadStrings($this->path . '/language');
}
function getModStrings($language='en_us'){
$language .= '.lang.php';
if(!empty($this->strings[$language]) && $language != 'en_us.lang.php'){
return sugarArrayMerge($this->strings['en_us.lang.php'], $this->strings[$language]);
}
if(!empty($this->strings['en_us.lang.php']))return $this->strings['en_us.lang.php'];
$empty = array();
return $empty;
}
function getAppListStrings($language='en_us'){
$language .= '.lang.php';
if(!empty($this->appListStrings[$language]) && $language != 'en_us.lang.php'){
return sugarArrayMerge($this->appListStrings['en_us.lang.php'], $this->appListStrings[$language]);
}
if(!empty($this->appListStrings['en_us.lang.php']))return $this->appListStrings['en_us.lang.php'];
$empty = array();
return $empty;
}
function generateAppStrings($buildFromTemplate = true){
$this->appListStrings = array('en_us.lang.php'=>array());
//By default, generate app strings for the current language as well.
$this->appListStrings[$GLOBALS [ 'current_language' ] . ".lang.php"] = array();
$this->loadAppListStrings($this->path . '/../../language/application');
if($buildFromTemplate){
//go through the templates application strings and load anything that is needed
foreach($this->iTemplates as $template=>$val){
$file = MB_IMPLEMENTS . '/' . $template . '/language/application';
$this->loadAppListStrings($file);
}
foreach($this->templates as $template=>$val){
$file = MB_TEMPLATES . '/' . $template . '/language/application';
$this->loadAppListStrings($file);
}
}
}
function save($key_name, $duplicate=false, $rename=false){
$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
$save_path = $this->path . '/language';
mkdir_recursive($save_path);
foreach($this->strings as $lang=>$values){
//Check if the module Label has changed.
$renameLang = $rename || empty($values) || $this->label != $values['LBL_MODULE_NAME'];
$mod_strings = return_module_language(str_replace('.lang.php','',$lang), 'ModuleBuilder');
$required = array(
'LBL_LIST_FORM_TITLE'=>$this->label . " " . $mod_strings['LBL_LIST'],
'LBL_MODULE_NAME'=>$this->label,
'LBL_MODULE_TITLE'=>$this->label,
'LBL_HOMEPAGE_TITLE'=>$mod_strings['LBL_HOMEPAGE_PREFIX'] . " " . $this->label,
//FOR GENERIC MENU
'LNK_NEW_RECORD'=>$mod_strings['LBL_CREATE'] ." ". $this->label,
'LNK_LIST'=>$mod_strings['LBL_VIEW'] ." ". $this->label,
'LNK_IMPORT_'.strtoupper($this->key_name)=>translate('LBL_IMPORT') ." ". $this->label,
'LBL_SEARCH_FORM_TITLE'=>$mod_strings['LBL_SEARCH'] ." ". $this->label,
'LBL_HISTORY_SUBPANEL_TITLE'=>$mod_strings['LBL_HISTORY'],
'LBL_ACTIVITIES_SUBPANEL_TITLE'=>$mod_strings['LBL_ACTIVITIES'],
'LBL_'.strtoupper($this->key_name).'_SUBPANEL_TITLE'=>$this->label,
'LBL_NEW_FORM_TITLE' => $mod_strings['LBL_NEW'] ." ". $this->label,
);
foreach($required as $k=>$v){
if(empty($values[$k]) || $renameLang){
$values[$k] = $v;
}
}
write_array_to_file('mod_strings', $values, $save_path .'/'.$lang,'w', $header);
}
$app_save_path = $this->path . '/../../language/application';
mkdir_recursive($app_save_path);
$key_changed = ($this->key_name != $key_name);
foreach($this->appListStrings as $lang=>$values){
if(!$duplicate){
unset($values['moduleList'][$this->key_name]);
}
$values['moduleList'][$key_name]= $this->label;
$appFile = $header. "\n";
require_once('include/utils/array_utils.php');
$this->getGlobalAppListStringsForMB($values);
foreach($values as $key=>$array){
if($duplicate){
//keep the original when duplicating
$appFile .= override_value_to_string_recursive2 ('app_list_strings', $key, $array);
}
$okey = $key;
if($key_changed)$key = str_replace($this->key_name, $key_name, $key);
if($key_changed)$key = str_replace(strtolower($this->key_name), strtolower($key_name), $key);
// if we aren't duplicating or the key has changed let's add it
if(!$duplicate || $okey != $key){
$appFile .= override_value_to_string_recursive2 ('app_list_strings', $key, $array);
}
}
$fp = sugar_fopen($app_save_path . '/'. $lang, 'w');
fwrite($fp, $appFile);
fclose($fp);
}
}
/**
* If there is no this dropdown list in custom\modulebuilder\packages\$package\language\application\$lang.lang.php ,
* we will include it from global app_list_string array into custom\modulebuilder\packages\$package\language\application\$lang.lang.php
* when we create a dropdown filed and the value is created in MB.(#20728 )
**/
function getGlobalAppListStringsForMB(&$values){
//Ensure it comes from MB
if(!empty($_REQUEST['view_package']) && !empty($_REQUEST['type']) && $_REQUEST['type']='enum' && !empty($_REQUEST['options'])){
if(!isset($values[$_REQUEST['options']])){
global $app_list_strings;
if(!empty($app_list_strings[$_REQUEST['options']])){
$values[$_REQUEST['options']] = $app_list_strings[$_REQUEST['options']];
}
}
}
}
function build($path){
if(file_exists($this->path.'/language/'))
copy_recursive($this->path.'/language/', $path . '/language/');
}
function loadTemplates() {
if(empty($this->templates)){
if (file_exists("$this->path/config.php")) {
include "$this->path/config.php";
$this->templates = $config['templates'];
$this->iTemplates = array();
}
}
}
/**
* Reset the templates and load the language files again. This is called from
* MBModule->save() once the config file has been written.
*/
function reload(){
$this->templates = null;
$this->load();
}
}

View File

@@ -0,0 +1,800 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
define ( 'MB_TEMPLATES', 'include/SugarObjects/templates' ) ;
define ( 'MB_IMPLEMENTS', 'include/SugarObjects/implements' ) ;
require_once ('modules/ModuleBuilder/MB/MBVardefs.php') ;
require_once ('modules/ModuleBuilder/MB/MBRelationship.php') ;
require_once ('modules/ModuleBuilder/MB/MBLanguage.php') ;
class MBModule
{
public $name = '' ;
public $config = array (
'assignable' => 1 , 'acl' => 1 , 'has_tab' => 1 , 'studio' => 1 , 'audit' => 1 ) ;
public $mbpublicdefs ;
public $errors = array ( ) ;
public $path = '' ;
public $implementable = array (
'has_tab' => 'Navigation Tab' ) ;
public $always_implement = array ( 'assignable' => 'Assignable' , 'acl' => 'Access Controls' , 'studio' => 'Studio Support' , 'audit' => 'Audit Table' ) ;
public $iTemplate = array (
'assignable' ) ;
public $config_md5 = null ;
function __construct ($name , $path , $package , $package_key)
{
global $mod_strings;
$this->config [ 'templates' ] = array ( 'basic' => 1 ) ;
$this->name = MBModule::getDBName ( $name ) ;
$this->key_name = $package_key . '_' . $name ;
$this->package = $package ;
$this->package_key = $package_key ;
$this->package_path = $path ;
$this->implementable = array (
'has_tab' => !empty($mod_strings[ 'LBL_NAV_TAB' ]) ? $mod_strings[ 'LBL_NAV_TAB' ] : false) ;
$this->path = $this->getModuleDir () ;
// $this->mbrelationship = new MBRelationship($this->name, $this->path, $this->key_name);
$this->relationships = new UndeployedRelationships ( $this->path ) ;
$this->mbvardefs = new MBVardefs ( $this->name, $this->path, $this->key_name ) ;
$this->load () ;
}
function getDBName ($name)
{
return preg_replace ( "/[^\w]+/", "_", $name ) ;
}
function getModuleName()
{
return $this->name;
}
function getPackageName()
{
return $this->package;
}
function getRelationships()
{
return $this->relationships;
}
/**
* Loads the module based on the module name
*
*/
function load ()
{
if (file_exists ( $this->path . '/config.php' ))
{
include ($this->path . '/config.php') ;
$this->config = $config ;
}
$label = (! empty ( $this->config [ 'label' ] )) ? $this->config [ 'label' ] : $this->name ;
$this->mblanguage = new MBLanguage ( $this->name, $this->path, $label, $this->key_name ) ;
foreach ( $this->iTemplate as $temp )
{
if (! empty ( $this->config [ $temp ] ))
{
$this->mbvardefs->iTemplates [ $temp ] = 1 ;
$this->mblanguage->iTemplates [ $temp ] = $temp ;
}
}
$this->mbvardefs->templates = $this->config [ 'templates' ] ;
$this->mblanguage->templates = $this->config [ 'templates' ] ;
$this->mbvardefs->load () ;
$this->mblanguage->load () ;
}
function addTemplate ($template)
{
$this->config [ 'templates' ] [ $template ] = 1 ;
}
function getModuleDir ()
{
return $this->package_path . '/modules/' . $this->name ;
}
function removeTemplate ($template)
{
unset ( $this->config [ 'templates' ] [ $template ] ) ;
}
function getVardefs ($by_group = false)
{
$this->mbvardefs->updateVardefs ( $by_group ) ;
return $this->mbvardefs->getVardefs () ;
}
function addField ($vardef)
{
$this->mbvardefs->addFieldVardef ( $vardef ) ;
}
function addFieldObject ($field)
{
$vardef = $field->get_field_def () ;
$this->mbvardefs->mergeVardefs();
$existingVardefs = $this->mbvardefs->getVardefs () ;
//Merge with the existing vardef if it already exists
if(!empty($existingVardefs['fields'][$vardef['name']])){
$vardef = array_merge( $existingVardefs['fields'][$vardef['name']], $vardef);
}
if (! empty ( $vardef [ 'source' ] ) && $vardef [ 'source' ] == 'custom_fields')
unset ( $vardef [ 'source' ] ) ;
$this->mbvardefs->load();
$this->addField ( $vardef ) ;
$this->mbvardefs->save();
}
function deleteField ($name)
{
$this->mbvardefs->deleteField ( $name ) ;
}
function fieldExists ($name = '' , $type = '')
{
$vardefs = $this->mbvardefs->getVardef () ;
if (! empty ( $vardefs ))
{
if (empty ( $type ) && empty ( $name ))
return false ; else if (empty ( $type ))
return ! empty ( $vardefs [ 'fields' ] [ $name ] ) ; else if (empty ( $name ))
{
foreach ( $vardefs [ 'fields' ] as $def )
{
if ($def [ 'type' ] == $type)
return true ;
}
return false ;
} else
return (! empty ( $vardefs [ 'fields' ] [ $name ] ) && ($vardefs [ 'fields' ] [ $name ] [ 'type' ] == $type)) ;
} else
{
return false ;
}
}
function getModStrings ($language = 'en_us')
{
return $this->mblanguage->getModStrings ( $language ) ;
}
function setModStrings ($language = 'en_us' , $mod_strings)
{
$language .= '.lang.php' ;
$this->mblanguage->strings [ $language ] = $mod_strings ;
}
function setLabel ($language = 'en_us' , $key , $value)
{
$language .= '.lang.php' ;
$this->mblanguage->strings [ $language ] [ $key ] = $value ;
//Ensure this key exists in all languages
foreach ($this->mblanguage->strings as $lang => $values) {
if (empty($values[$key])) {
$this->mblanguage->strings[$lang][$key] = $value;
}
}
}
function deleteLabel ($language = 'en_us' , $key)
{
foreach ($this->mblanguage->strings as $lang => $values) {
if (!empty($values[$key])) {
unset($this->mblanguage->strings[$lang][$key]);
}
}
}
/**
* Required for an MB module to work with Dynamic fields
*/
function addLabel ( $displayLabel)
{
$this->setLabel('en_us', $this->getDBName($displayLabel, false), translate($displayLabel));
$this->save();
}
function getLabel ($language = 'en_us' , $key)
{
$language .= '.lang.php' ;
if (empty ( $this->mblanguage->strings [ $language ] [ $key ] ))
{
return '' ;
}
return $this->mblanguage->strings [ $language ] [ $key ] ;
}
function getAppListStrings ($language = 'en_us')
{
return $this->mblanguage->getAppListStrings ( $language ) ;
}
function setAppListStrings ($language = 'en_us' , $app_list_strings)
{
$language .= '.lang.php' ;
$this->mblanguage->appListStrings [ $language ] = $app_list_strings ;
}
function setDropDown ($language = 'en_us' , $key , $value)
{
$language .= '.lang.php' ;
$this->mblanguage->appListStrings [ $language ] [ $key ] = $value ;
}
function deleteDropDown ($language = 'en_us' , $key)
{
$language .= '.lang.php' ;
unset ( $this->mblanguage->appListStrings [ $language ] [ $key ] ) ;
}
function save ()
{
$this->path = $this->getModuleDir () ;
if (mkdir_recursive ( $this->path ))
{
$this->setConfigMD5 () ;
$old_config_md5 = $this->config_md5 ;
$this->saveConfig () ;
$this->getVardefs () ;
$this->mbvardefs->save ( $this->key_name ) ;
// $this->mbrelationship->save ( $this->key_name ) ;
$this->relationships->save () ;
$this->copyMetaData () ;
$this->copyDashlet () ;
$this->copyViews() ;
if (0 != strcmp ( $old_config_md5, $this->config_md5 ))
{
$this->mblanguage->reload () ;
}
$this->mblanguage->label = $this->config [ 'label' ] ;
//pass in the key_name incase it has changed mblanguage will check if it is different and handle it accordingly
$this->mblanguage->save ( $this->key_name ) ;
if (! file_exists ( $this->package_path . "/icons/icon_" . ucfirst ( $this->key_name ) . ".gif" ))
{
$this->createIcon () ;
}
$this->errors = array_merge ( $this->errors, $this->mbvardefs->errors ) ;
}
}
function copyDashlet() {
$templates = array_reverse ( $this->config [ 'templates' ], true ) ;
foreach ( $templates as $template => $a )
{
if (file_exists ( MB_TEMPLATES . '/' . $template . '/Dashlets/Dashlet' ))
{
$this->copyMetaRecursive ( MB_TEMPLATES . '/' . $template . '/Dashlets/Dashlet', $this->path . '/Dashlets/' . $this->key_name . 'Dashlet/' ) ;
}
}
}
function copyViews() {
$templates = array_reverse ( $this->config [ 'templates' ], true ) ;
foreach ( $templates as $template => $a )
{
if (file_exists ( MB_TEMPLATES . '/' . $template . '/views' ))
{
$this->copyMetaRecursive ( MB_TEMPLATES . '/' . $template . '/views', $this->path . '/views/' ) ;
}
}
}
function copyCustomFiles ( $from , $to )
{
$d = dir ( $from ) ;
while ( $filename = $d->read () )
{
if (substr ( $filename, 0, 1 ) == '.')
continue ;
if ( $filename != 'metadata' && $filename != 'Dashlets' && $filename != 'relationships' && $filename != 'language' && $filename != 'config.php' && $filename != 'relationships.php' && $filename != 'vardefs.php' )
copy_recursive ( "$from/$filename" , "$to/$filename" ) ;
}
}
function copyMetaData ()
{
$templates = array_reverse ( $this->config [ 'templates' ], true ) ;
foreach ( $templates as $template => $a )
{
if (file_exists ( MB_TEMPLATES . '/' . $template . '/metadata' ))
{
$this->copyMetaRecursive ( MB_TEMPLATES . '/' . $template . '/metadata', $this->path . '/metadata/' ) ;
}
}
}
function copyMetaRecursive ($from , $to , $overwrite = false)
{
if (! file_exists ( $from ))
return ;
if (is_dir ( $from ))
{
$findArray = array ( '<module_name>' , '<_module_name>' , '<MODULE_NAME>' , '<object_name>' , '<_object_name>' , '<OBJECT_NAME>' );
$replaceArray = array ( $this->key_name , strtolower ( $this->key_name ) , strtoupper ( $this->key_name ) ,
$this->key_name , strtolower ( $this->key_name ) , strtoupper ( $this->key_name ) );
mkdir_recursive ( $to ) ;
$d = dir ( $from ) ;
while ( $e = $d->read () )
{
if (substr ( $e, 0, 1 ) == '.')
continue ;
$nfrom = $from . '/' . $e ;
$nto = $to . '/' . str_replace ( 'm-n-', $this->key_name, $e ) ;
if (is_dir ( $nfrom ))
{
$this->copyMetaRecursive ( $nfrom, $nto, $overwrite ) ;
} else
{
if ($overwrite || ! file_exists ( $nto ))
{
$contents = file_get_contents ( $nfrom ) ;
$contents = str_replace ( $findArray, $replaceArray, $contents ) ;
$fw = sugar_fopen ( $nto, 'w' ) ;
fwrite ( $fw, $contents ) ;
fclose ( $fw ) ;
}
}
}
}
}
function saveConfig ()
{
$header = file_get_contents ( 'modules/ModuleBuilder/MB/header.php' ) ;
if (! write_array_to_file ( 'config', $this->config, $this->path . '/config.php', 'w', $header ))
{
$this->errors [] = 'Could not save config to ' . $this->path . '/config.php' ;
}
$this->setConfigMD5 () ;
}
function setConfigMD5 ()
{
if (file_exists ( $this->path . '/config.php' ))
$this->config_md5 = md5 ( base64_encode ( serialize ( $this->config ) ) ) ;
}
function build ($basepath)
{
$path = $basepath . '/modules/' . $this->key_name ;
if (mkdir_recursive ( $path ))
{
$this->createClasses ( $path ) ;
if( $this->config['importable'] || in_array ( 'person', array_keys($this->config[ 'templates' ]) ) )
$this->createMenu ( $path ) ;
$this->copyCustomFiles ( $this->path , $path ) ;
$this->copyMetaRecursive ( $this->path . '/metadata/', $path . '/metadata/', true ) ;
$this->copyMetaRecursive ( $this->path . '/Dashlets/' . $this->key_name . 'Dashlet/',
$path . '/Dashlets/' . $this->key_name . 'Dashlet/', true ) ;
$this->relationships->build ( $basepath ) ;
$this->mblanguage->build ( $path ) ;
}
}
function createClasses ($path)
{
$class = array ( ) ;
$class [ 'name' ] = $this->key_name ;
$class [ 'table_name' ] = strtolower ( $class [ 'name' ] ) ;
$class [ 'extends' ] = 'Basic' ;
$class [ 'requires' ] [] = MB_TEMPLATES . '/basic/Basic.php' ;
$class [ 'requires' ] = array ( ) ;
$class [ 'audited' ] = (! empty ( $this->config [ 'audit' ] )) ? 'true' : 'false' ;
$class [ 'acl' ] = ! empty ( $this->config [ 'acl' ] ) ;
$class [ 'templates' ] = "'basic'" ;
foreach ( $this->iTemplate as $template )
{
if (! empty ( $this->config [ $template ] ))
{
$class [ 'templates' ] .= ",'$template'" ;
}
}
foreach ( $this->config [ 'templates' ] as $template => $a )
{
if ($template == 'basic')
continue ;
$class [ 'templates' ] .= ",'$template'" ;
$class [ 'extends' ] = ucFirst ( $template ) ;
$class [ 'requires' ] [] = MB_TEMPLATES . '/' . $template . '/' . ucfirst ( $template ) . '.php' ;
}
$class [ 'importable' ] = $this->config [ 'importable' ] ;
$this->mbvardefs->updateVardefs () ;
$class [ 'fields' ] = $this->mbvardefs->vardefs [ 'fields' ] ;
$class [ 'fields_string' ] = var_export_helper ( $this->mbvardefs->vardef [ 'fields' ] ) ;
$relationship = array ( ) ;
$class [ 'relationships' ] = var_export_helper ( $this->mbvardefs->vardef [ 'relationships' ] ) ;
$smarty = new Sugar_Smarty ( ) ;
$smarty->left_delimiter = '{{' ;
$smarty->right_delimiter = '}}' ;
$smarty->assign ( 'class', $class ) ;
//write sugar generated class
$fp = sugar_fopen ( $path . '/' . $class [ 'name' ] . '_sugar.php', 'w' ) ;
fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Class.tpl' ) ) ;
fclose ( $fp ) ;
//write vardefs
$fp = sugar_fopen ( $path . '/vardefs.php', 'w' ) ;
fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/vardef.tpl' ) ) ;
fclose ( $fp ) ;
if (! file_exists ( $path . '/' . $class [ 'name' ] . '.php' ))
{
$fp = sugar_fopen ( $path . '/' . $class [ 'name' ] . '.php', 'w' ) ;
fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/DeveloperClass.tpl' ) ) ;
fclose ( $fp ) ;
}
if (! file_exists ( $path . '/metadata' ))
mkdir_recursive ( $path . '/metadata' ) ;
if (! empty ( $this->config [ 'studio' ] ))
{
$fp = sugar_fopen ( $path . '/metadata/studio.php', 'w' ) ;
fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Studio.tpl' ) ) ;
fclose ( $fp ) ;
} else
{
if (file_exists ( $path . '/metadata/studio.php' ))
unlink ( $path . '/metadata/studio.php' ) ;
}
}
function createMenu ($path)
{
$smarty = new Sugar_Smarty ( ) ;
$smarty->assign ( 'moduleName', $this->key_name ) ;
$smarty->assign ( 'showvCard', in_array ( 'person', array_keys($this->config[ 'templates' ]) ) ) ;
$smarty->assign ( 'showimport', $this->config['importable'] );
//write sugar generated class
$fp = sugar_fopen ( $path . '/' . 'Menu.php', 'w' ) ;
fwrite ( $fp, $smarty->fetch ( 'modules/ModuleBuilder/tpls/MBModule/Menu.tpl' ) ) ;
fclose ( $fp ) ;
}
function addInstallDefs (&$installDefs)
{
$name = $this->key_name ;
$installDefs [ 'copy' ] [] = array ( 'from' => '<basepath>/SugarModules/modules/' . $name , 'to' => 'modules/' . $name ) ;
$installDefs [ 'beans' ] [] = array ( 'module' => $name , 'class' => $name , 'path' => 'modules/' . $name . '/' . $name . '.php' , 'tab' => $this->config [ 'has_tab' ] ) ;
$this->relationships->addInstallDefs ( $installDefs ) ;
}
function getNodes ()
{
$lSubs = array ( ) ;
$psubs = $this->getProvidedSubpanels () ;
foreach ( $psubs as $sub )
{
$subLabel = $sub ;
if ($subLabel == 'default')
{
$subLabel = $GLOBALS [ 'mod_strings' ] [ 'LBL_DEFAULT' ] ;
}
$lSubs [] = array ( 'name' => $subLabel , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=ListView&view_module=' . $this->name . '&view_package=' . $this->package . '&subpanel=' . $sub . '&subpanelLabel=' . $subLabel . '&local=1' ) ;
}
$searchSubs = array ( ) ;
$searchSubs [] = array ( 'name' => translate('LBL_BASIC_SEARCH') , 'type' => 'list' , 'action' => "module=ModuleBuilder&MB=true&action=editLayout&view=basic_search&view_module={$this->name}&view_package={$this->package}" ) ;
$searchSubs [] = array ( 'name' => translate('LBL_ADVANCED_SEARCH') , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=advanced_search&view_module=' . $this->name . '&view_package=' . $this->package ) ;
$dashlets = array( );
$dashlets [] = array('name' => translate('LBL_DASHLETLISTVIEW') , 'type' => 'dashlet' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=dashlet&view_module=' . $this->name . '&view_package=' . $this->package );
$dashlets [] = array('name' => translate('LBL_DASHLETSEARCHVIEW') , 'type' => 'dashletsearch' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view=dashletsearch&view_module=' . $this->name . '&view_package=' . $this->package );
$popups = array( );
$popups [] = array('name' => translate('LBL_POPUPLISTVIEW') , 'type' => 'popuplistview' , 'action' => 'module=ModuleBuilder&action=editLayout&view=popuplist&view_module=' . $this->name . '&view_package=' . $this->package );
$popups [] = array('name' => translate('LBL_POPUPSEARCH') , 'type' => 'popupsearch' , 'action' => 'module=ModuleBuilder&action=editLayout&view=popupsearch&view_module=' . $this->name . '&view_package=' . $this->package );
$layouts = array (
array ( 'name' => translate('LBL_EDITVIEW') , 'type' => 'edit' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view='.MB_EDITVIEW.'&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_DETAILVIEW') , 'type' => 'detail' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view='.MB_DETAILVIEW.'&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_LISTVIEW') , 'type' => 'list' , 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view='.MB_LISTVIEW.'&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_QUICKCREATE') , 'type' => MB_QUICKCREATE, 'action' => 'module=ModuleBuilder&MB=true&action=editLayout&view='.MB_QUICKCREATE.'&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_DASHLET') , 'type' => 'Folder', 'children' => $dashlets, 'action' => 'module=ModuleBuilder&MB=true&action=wizard&view=dashlet&view_module=' . $this->name . '&view_package=' . $this->package ),
array ( 'name' => translate('LBL_POPUP') , 'type' => 'Folder', 'children' => $popups, 'action' => 'module=ModuleBuilder&MB=true&action=wizard&view=popup&view_module=' . $this->name . '&view_package=' . $this->package ),
array ( 'name' => translate('LBL_SEARCH_FORMS') , 'action' => 'module=ModuleBuilder&MB=true&action=wizard&view=search&view_module=' . $this->name . '&view_package=' . $this->package , 'type' => 'folder' , 'children' => $searchSubs )
) ;
$children = array (
array ( 'name' => translate('LBL_FIELDS') , 'action' => 'module=ModuleBuilder&action=modulefields&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_LABELS') , 'action' => 'module=ModuleBuilder&action=modulelabels&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_RELATIONSHIPS') , 'action' => 'module=ModuleBuilder&action=relationships&view_module=' . $this->name . '&view_package=' . $this->package ) ,
array ( 'name' => translate('LBL_LAYOUTS') , 'type' => 'Folder' , 'action' => "module=ModuleBuilder&action=wizard&view_module={$this->name}&view_package={$this->package}&MB=1" , 'children' => $layouts ) ,
) ;
if (count ( $lSubs ) > 0)
{
$children [] = array ( 'name' => translate('LBL_AVAILABLE_SUBPANELS') , 'type' => 'folder' , 'children' => $lSubs ) ;
}
$nodes = array ( 'name' => $this->name , 'children' => $children , 'action' => 'module=ModuleBuilder&action=module&view_module=' . $this->name . '&view_package=' . $this->package ) ;
return $nodes ;
}
function getProvidedSubpanels ()
{
$this->providedSubpanels = array () ;
$subpanelDir = $this->getModuleDir () . '/metadata/subpanels/' ;
if (file_exists ( $subpanelDir ))
{
$f = dir ( $subpanelDir ) ;
require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php' ;
while ( $g = $f->read () )
{
// sanity check to confirm that this is a usable subpanel...
if (substr ( $g, 0, 1 ) != '.' && AbstractRelationships::validSubpanel ( $subpanelDir . $g ))
{
$subname = str_replace ( '.php', '', $g ) ;
$this->providedSubpanels [ $subname ] = $subname ;
}
}
}
return $this->providedSubpanels;
}
function getTypes ()
{
$types = array ( ) ;
$d = dir ( MB_TEMPLATES ) ;
while ( $e = $d->read () )
{
if (substr ( $e, 0, 1 ) != '.')
{
$types [ $e ] = $e ;
}
}
return $types ;
}
function rename ($new_name)
{
$old = $this->getModuleDir () ;
$old_name = $this->key_name;
$this->name = $new_name ;
$this->key_name = $this->package_key . '_' . $this->name ;
$new = $this->getModuleDir () ;
if (file_exists ( $new ))
{
return false ;
}
$renamed = rename ( $old, $new ) ;
if ($renamed)
{
$this->renameMetaData ( $new , $old_name) ;
$this->renameLanguageFiles ( $new ) ;
}
return $renamed ;
}
function renameLanguageFiles ($new_dir , $duplicate = false)
{
$this->mblanguage->name = $this->name ;
$this->mblanguage->path = $new_dir ;
$this->mblanguage->generateAppStrings () ;
$this->mblanguage->save ( $this->key_name, $duplicate, true) ;
}
function renameMetaData ($new_dir, $old_name)
{
$GLOBALS [ 'log' ]->debug ( 'MBModule.php->renameMetaData: new_dir=' . $new_dir ) ;
if (! file_exists ( $new_dir ))
return ;
$dir = dir ( $new_dir ) ;
while ( $e = $dir->read () )
{
if (substr ( $e, 0, 1 ) != '.')
{
if (is_dir ( $new_dir . '/' . $e ))
{
$this->renameMetaData ( $new_dir . '/' . $e, $old_name) ;
}
if (is_file ( $new_dir . '/' . $e ))
{
$contents = file_get_contents ( $new_dir . '/' . $e ) ;
$contents = preg_replace ( '/(\$module_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . $this->key_name . '$3', $contents ) ;
$contents = preg_replace ( '/(\$_module_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtolower ( $this->key_name ) . '$3', $contents ) ;
$contents = preg_replace ( '/(\$MODULE_NAME[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtoupper ( $this->key_name ) . '$3', $contents ) ;
$contents = preg_replace ( '/(\$object_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . $this->key_name . '$3', $contents ) ;
$contents = preg_replace ( '/(\$_object_name[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtolower ( $this->key_name ) . '$3', $contents ) ;
$contents = preg_replace ( '/(\$OBJECT_NAME[ ]*=[ ]*\')(.*)(\'[ ]*;)/', '$1' . strtoupper ( $this->key_name ) . '$3', $contents ) ;
$contents = str_replace ( "{$old_name}_", $this->key_name . "_", $contents ) ;
$fp = sugar_fopen ( $new_dir . '/' . $e, 'w' ) ;
fwrite ( $fp, $contents ) ;
fclose ( $fp ) ;
}
}
}
}
function copy ($new_name)
{
$old = $this->getModuleDir () ;
$count = 0 ;
$old_name = $this->key_name;
$this->name = $new_name ;
$this->key_name = $this->package_key . '_' . $this->name ;
$new = $this->getModuleDir () ;
while ( file_exists ( $new ) )
{
$count ++ ;
$this->name = $new_name . $count ;
$this->key_name = $this->package_key . '_' . $this->name ;
$new = $this->getModuleDir () ;
}
$new = $this->getModuleDir () ;
$copied = copy_recursive ( $old, $new ) ;
if ($copied)
{
$this->renameMetaData ( $new , $old_name) ;
$this->renameLanguageFiles ( $new, true ) ;
}
return $copied ;
}
function delete ()
{
return rmdir_recursive ( $this->getModuleDir () ) ;
}
function populateFromPost ()
{
foreach ( $this->implementable as $key => $value )
{
$this->config [ $key ] = ! empty ( $_REQUEST [ $key ] ) ;
}
foreach ( $this->always_implement as $key => $value )
{
$this->config [ $key ] = true ;
}
if (! empty ( $_REQUEST [ 'type' ] ))
{
$this->addTemplate ( $_REQUEST [ 'type' ] ) ;
}
if (! empty ( $_REQUEST [ 'label' ] ))
{
$this->config [ 'label' ] = $_REQUEST [ 'label' ] ;
}
$this->config [ 'importable' ] = ! empty( $_REQUEST[ 'importable' ] ) ;
}
function getAvailibleSubpanelDef ($panelName)
{
$filepath = $this->getModuleDir () . "/metadata/subpanels/{$panelName}.php" ;
if (file_exists ( $filepath ))
{
include ($filepath) ;
return $subpanel_layout ;
}
return array ( ) ;
}
function saveAvailibleSubpanelDef ($panelName , $layout)
{
$dir = $this->getModuleDir () . "/metadata/subpanels" ;
$filepath = "$dir/{$panelName}.php" ;
if (mkdir_recursive ( $dir ))
{
// preserve any $module_name entry if one exists
if (file_exists ( $filepath ))
{
include ($filepath) ;
}
$module_name = (isset ( $module_name )) ? $module_name : $this->key_name ;
$layout = "<?php\n" . '$module_name=\'' . $module_name . "';\n" . '$subpanel_layout = ' . var_export_helper ( $layout ) . ";" ;
$GLOBALS [ 'log' ]->debug ( "About to save this file to $filepath" ) ;
$GLOBALS [ 'log' ]->debug ( $layout ) ;
$fw = sugar_fopen ( $filepath, 'w' ) ;
fwrite ( $fw, $layout ) ;
fclose ( $fw ) ;
}
}
function getLocalSubpanelDef ($panelName)
{
}
function createIcon ()
{
$icondir = $this->package_path . "/icons" ;
mkdir_recursive ( $icondir ) ;
$template = "" ;
foreach ( $this->config [ 'templates' ] as $temp => $val )
$template = $temp ;
copy ( "themes/default/images/icon_$template.gif", "$icondir/icon_" . ucfirst ( $this->key_name ) . ".gif" ) ;
copy ( "include/SugarObjects/templates/$template/icons/$template.gif", "$icondir/" . $this->key_name . ".gif" ) ;
if (file_exists("include/SugarObjects/templates/$template/icons/Create$template.gif"))
copy ( "include/SugarObjects/templates/$template/icons/Create$template.gif", "$icondir/Create" . $this->key_name . ".gif" ) ;
if (file_exists("include/SugarObjects/templates/$template/icons/{$template}_32.gif"))
copy ( "include/SugarObjects/templates/$template/icons/{$template}_32.gif", "$icondir/icon_" . $this->key_name . "_32.gif" ) ;
}
function removeFieldFromLayouts ( $fieldName )
{
// hardcoded list of types for now, as also hardcoded in a different form in getNodes
// TODO: replace by similar mechanism to StudioModule to determine the list of available views for this module
$views = array ( 'editview' , 'detailview' , 'listview' , 'basic_search' , 'advanced_search' , 'dashlet' , 'popuplist');
foreach ($views as $type )
{
$parser = ParserFactory::getParser( $type , $this->name , $this->package ) ;
if ($parser->removeField ( $fieldName ) )
$parser->handleSave(false) ; // don't populate from $_REQUEST, just save as is...
}
//Remove the fields in subpanel
$psubs = $this->getProvidedSubpanels() ;
foreach ( $psubs as $sub )
{
$parser = ParserFactory::getParser( MB_LISTVIEW , $this->name, $this->package , $sub) ;
if ($parser->removeField ( $fieldName ) )
$parser->handleSave(false) ;
}
}
}
?>

View File

@@ -0,0 +1,786 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('modules/ModuleBuilder/MB/MBModule.php');
class MBPackage{
var $name;
var $is_uninstallable = true;
var $description = '';
var $has_images = true;
var $modules = array();
var $date_modified = '';
var $author = '';
var $key = '';
var $readme='';
function MBPackage($name){
$this->name = $name;
$this->load();
}
function loadModules($force=false){
if(!file_exists(MB_PACKAGE_PATH . '/' . $this->name .'/modules'))return;
$d = dir(MB_PACKAGE_PATH . '/' . $this->name .'/modules');
while($e = $d->read()){
if(substr($e, 0, 1) != '.' && is_dir(MB_PACKAGE_PATH . '/'. $this->name. '/modules/' . $e)){
$this->getModule($e, $force);
}
}
}
/**
* Loads the translated module titles from the selected language into.
* Will override currently loaded string to reflect undeployed label changes.
* $app_list_strings
* @return
* @param $languge String language identifyer
*/
function loadModuleTitles($languge = '')
{
if (empty($language))
{
$language = $GLOBALS['current_language'];
}
global $app_list_strings;
$packLangFilePath = $this->getPackageDir() . "/language/application/" . $language . ".lang.php";
if (file_exists($packLangFilePath))
{
require($packLangFilePath);
}
}
function getModule($name, $force=true){
if(!$force && !empty($this->modules[$name]))return;
$path = $this->getPackageDir();
$this->modules[$name] = new MBModule($name, $path, $this->name, $this->key);
}
function deleteModule($name){
$this->modules[$name]->delete();
unset($this->modules[$name]);
}
function getManifest($version_specific = false, $for_export = false){
//If we are exporting the package, we must ensure a different install key
$pre = $for_export ? MB_EXPORTPREPEND : "";
$date = gmdate($GLOBALS['timedate']->get_db_date_time_format());
$time = time();
$this->description = to_html($this->description);
$is_uninstallable = ($this->is_uninstallable ? 'true' : 'false');
$flavor = "'" . $GLOBALS['sugar_flavor'] . "'";
if($GLOBALS['sugar_flavor'] == 'CE')$flavor = "'CE', 'PRO','ENT'";
$version = (!empty($version_specific))?"'" . $GLOBALS['sugar_version'] . "'" : '';
$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
return <<<EOQ
$header
\$manifest = array (
'acceptable_sugar_versions' =>
array (
$version
),
'acceptable_sugar_flavors' =>
array(
$flavor
),
'readme'=>'$this->readme',
'key'=>'$this->key',
'author' => '$this->author',
'description' => '$this->description',
'icon' => '',
'is_uninstallable' => $is_uninstallable,
'name' => '$pre$this->name',
'published_date' => '$date',
'type' => 'module',
'version' => '$time',
'remove_tables' => 'prompt',
);
EOQ;
}
function buildInstall($path){
$installdefs = array ('id' => $this->name,
'beans'=>array(),
'layoutdefs'=>array(),
'relationships'=>array(),
);
if($this->has_images){
$installdefs['image_dir'] = '<basepath>/icons';
}
foreach(array_keys($this->modules) as $module){
$this->modules[$module]->build($path);
$this->modules[$module]->addInstallDefs($installdefs);
}
$this->path = $this->getPackageDir();
if(file_exists($this->path . '/language')){
$d= dir($this->path . '/language');
while($e = $d->read()){
$lang_path = $this->path .'/language/' . $e;
if(substr($e, 0, 1) != '.' && is_dir($lang_path)){
$f = dir($lang_path);
while($g = $f->read()){
if(substr($g, 0, 1) != '.' && is_file($lang_path.'/'. $g)){
$lang = substr($g, 0, strpos($g, '.'));
$installdefs['language'][] = array(
'from'=> '<basepath>/SugarModules/language/'.$e . '/'. $g,
'to_module'=> $e,
'language'=> $lang
);
}
}
}
}
copy_recursive( $this->path . '/language/', $path . '/language/');
$icon_path = $path . '/../icons/default/images/';
mkdir_recursive($icon_path);
copy_recursive($this->path . '/icons/', $icon_path);
}
return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
}
function getPackageDir(){
return MB_PACKAGE_PATH . '/' . $this->name;
}
function getBuildDir(){
return MB_PACKAGE_BUILD . '/' . $this->name;
}
function getZipDir(){
return $this->getPackageDir() . '/zips';
}
function load(){
$path = $this->getPackageDir();
if(file_exists($path .'/manifest.php')){
require($path . '/manifest.php');
if(!empty($manifest)){
$this->date_modified = $manifest['published_date'];
$this->is_uninstallable = $manifest['is_uninstallable'];
$this->author = $manifest['author'];
$this->key = $manifest['key'];
$this->description = $manifest['description'];
if(!empty($manifest['readme']))
$this->readme = $manifest['readme'];
}
}
$this->loadModules(true);
}
function save(){
$path = $this->getPackageDir();
if(mkdir_recursive($path)){
$fp = sugar_fopen($path .'/manifest.php', 'w');
//Save all the modules when we save a package
$this->updateModulesMetaData(true);
fwrite($fp, $this->getManifest() );
fclose($fp);
}
}
function build($export=true, $clean = false){
$this->loadModules();
require_once('include/utils/zip_utils.php');
$package_path = $this->getPackageDir();
$path = $this->getBuildDir() . '/SugarModules';
if($clean && file_exists($path))rmdir_recursive($path);
if(mkdir_recursive($path)){
$manifest = $this->getManifest().$this->buildInstall($path);
$fp = sugar_fopen($this->getBuildDir() .'/manifest.php', 'w');
fwrite($fp, $manifest);
fclose($fp);
}
if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
copy('modules/ModuleBuilder/MB/LICENSE.txt', $this->getBuildDir() . '/LICENSE.txt');
}else if(file_exists('LICENSE.txt')){
copy('LICENSE.txt', $this->getBuildDir() . '/LICENSE.txt');
}
$package_dir = $this->getPackageDir();
$date = date('Y_m_d_His');
$zipDir = $this->getZipDir();
if(!file_exists($zipDir))mkdir_recursive($zipDir);
$cwd = getcwd();
chdir($this->getBuildDir());
zip_dir('.',$cwd . '/'. $zipDir. '/'. $this->name. $date. '.zip');
chdir($cwd);
if($export){
header('Location:' . $zipDir. '/'. $this->name. $date. '.zip');
}
return array(
'zip'=>$zipDir. '/'. $this->name. $date. '.zip',
'manifest'=>$this->getBuildDir(). '/manifest.php',
'name'=>$this->name. $date,
);
}
function getNodes(){
$this->loadModules();
$node = array('name'=>$this->name, 'action'=>'module=ModuleBuilder&action=package&package=' . $this->name, 'children'=>array());
foreach(array_keys($this->modules) as $module){
$node['children'][] = $this->modules[$module]->getNodes();
}
return $node;
}
function populateFromPost(){
$this->description = $_REQUEST['description'];
$this->author = $_REQUEST['author'];
$this->key = $_REQUEST['key'];
$this->readme = $_REQUEST['readme'];
}
function rename($new_name){
$old= $this->getPackageDir();
$this->name = $new_name;
$new = $this->getPackageDir();
if(file_exists($new)){
return false;
}
if(rename($old, $new)){
return true;
}
return false;
}
function updateModulesMetaData($save=false){
foreach(array_keys($this->modules) as $module){
$old_name = $this->modules[$module]->key_name;
$this->modules[$module]->key_name = $this->key . '_' . $this->modules[$module]->name;
$this->modules[$module]->renameMetaData($this->modules[$module]->getModuleDir(), $old_name);
$this->modules[$module]->renameLanguageFiles($this->modules[$module]->getModuleDir());
if($save)$this->modules[$module]->save();
}
}
function copy($new_name){
$old= $this->getPackageDir();
$count = 0;
$this->name = $new_name;
$new= $this->getPackageDir();
while(file_exists($new)){
$count++;
$this->name = $new_name . $count;
$new= $this->getPackageDir();
}
$new = $this->getPackageDir();
if(copy_recursive($old, $new)){
$this->updateModulesMetaData();
return true;
}
return false;
}
function delete(){
return rmdir_recursive($this->getPackageDir());
}
//creation of the installdefs[] array for the manifest when exporting customizations
function customBuildInstall($modules, $path, $extensions = array()){
$columns=$this->getColumnsName();
$installdefs = array ('id' => $this->name);
$include_path="$path/SugarModules/include/language";
if(file_exists($include_path) && is_dir($include_path)){
$dd= dir($include_path);
while($gg = $dd->read()){
if(substr($gg, 0, 1) != '.' && is_file($include_path . '/' . $gg)){
$lang = substr($gg, 0, strpos($gg, '.'));
$installdefs['language'][] = array(
'from'=> '<basepath>/SugarModules/include/language/'. $gg,
'to_module'=> 'application',
'language'=>$lang
);
}
}
}
foreach($modules as $value){
$custom_module = $this->getCustomModules($value);
foreach($custom_module as $va){
if ($va == 'language'){
$this->getLanguageManifestForModule($value, $installdefs);
$this->getCustomFieldsManifestForModule($value, $installdefs);
}//fi
if($va == 'metadata'){
$this->getCustomMetadataManifestForModule($value, $installdefs);
}//fi
}//foreach
}//foreach
if (is_dir("$path/Extension"))
{
$this->getExtensionsManifestForPackage($path, $installdefs);
}
return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
}
private function getLanguageManifestForModule($module, &$installdefs)
{
$lang_path = 'custom/modules/' . $module . '/language';
foreach(scandir($lang_path) as $langFile)
{
if(substr($langFile, 0, 1) != '.' && is_file($lang_path . '/' . $langFile)){
$lang = substr($langFile, 0, strpos($langFile, '.'));
$installdefs['language'][] = array(
'from'=> '<basepath>/SugarModules/modules/' . $module . '/language/'. $langFile,
'to_module'=> $module,
'language'=>$lang
);
}
}
}
private function getCustomFieldsManifestForModule($module, &$installdefs)
{
$db = DBManagerFactory::getInstance();
$result=$db->query("SELECT * FROM fields_meta_data where custom_module='$module'");
while($row = $db->fetchByAssoc($result)){
$name = $row['id'];
foreach($row as $col=>$res){
switch ($col) {
case 'custom_module':
$installdefs['custom_fields'][$name]['module'] = $res;
break;
case 'required':
$installdefs['custom_fields'][$name]['require_option'] = $res;
break;
case 'vname':
$installdefs['custom_fields'][$name]['label'] = $res;
break;
case 'required':
$installdefs['custom_fields'][$name]['require_option'] = $res;
break;
case 'massupdate':
$installdefs['custom_fields'][$name]['mass_update'] = $res;
break;
case 'comments':
$installdefs['custom_fields'][$name]['comments'] = $res;
break;
case 'help':
$installdefs['custom_fields'][$name]['help'] = $res;
break;
case 'len':
$installdefs['custom_fields'][$name]['max_size'] = $res;
break;
default:
$installdefs['custom_fields'][$name][$col] = $res;
}//switch
}//foreach
}//while
}
private function getCustomMetadataManifestForModule($module, &$installdefs)
{
$meta_path = 'custom/modules/' . $module . '/metadata';
foreach(scandir($meta_path) as $meta_file)
{
if(substr($meta_file, 0, 1) != '.' && is_file($meta_path . '/' . $meta_file)){
if($meta_file == 'listviewdefs.php'){
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
'to'=> 'custom/modules/'. $module . '/metadata/' . $meta_file,
);
}
else{
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
'to'=> 'custom/modules/'. $module . '/metadata/' . $meta_file,
);
$installdefs['copy'][] = array(
'from'=> '<basepath>/SugarModules/modules/'. $module . '/metadata/'. $meta_file,
'to'=> 'custom/working/modules/'. $module . '/metadata/' . $meta_file,
);
}
}
}
}
private function getExtensionsManifestForPackage($path, &$installdefs)
{
$extPath = "$path/Extension/modules";
foreach(scandir($extPath) as $moduleDir)
{
if(substr($moduleDir, 0, 1) != '.' && is_dir("$extPath/$moduleDir/Ext")){
foreach(scandir("$extPath/$moduleDir/Ext") as $type)
{
if(substr($type, 0, 1) != '.' && is_dir("$extPath/$moduleDir/Ext/$type")){
foreach(scandir("$extPath/$moduleDir/Ext/$type") as $file)
{
if(substr($file, 0, 1) != '.' && strtolower(substr($file, -4)) == ".php")
{
$installdefs['copy'][] = array(
'from'=> "<basepath>/Extension/modules/$moduleDir/Ext/$type/$file",
'to'=> "custom/Extension/modules/$moduleDir/Ext/$type/$file",
);
}
}
}
}
}
}
}
//return an array which contain the name of fields_meta_data table's columns
function getColumnsName(){
$meta = new FieldsMetaData();
$arr = array();
foreach($meta->getFieldDefinitions() as $key=>$value) {
$arr[] = $key;
}
return $arr;
}
//creation of the custom fields ZIP file (use getmanifest() and customBuildInstall() )
function exportCustom($modules, $export=true, $clean = true){
$path=$this->getBuildDir();
if($clean && file_exists($path))rmdir_recursive($path);
//Copy the custom files to the build dir
foreach($modules as $mod){
$extensions = $this->getExtensionsList($mod);
$pathmod="$path/SugarModules/modules/$mod";
if(mkdir_recursive($pathmod)){
if(file_exists("custom/modules/$mod")){
copy_recursive("custom/modules/$mod", "$pathmod");
//Don't include cached extension files
if (is_dir("$pathmod/Ext"))
rmdir_recursive("$pathmod/Ext");
}
//Convert modstring files to extension compatible arrays
$this->convertLangFilesToExtensions("$pathmod/language");
}
$pathext="$path/Extension/modules/$mod/Ext";
if (!empty($extensions) && mkdir_recursive($pathext))
{
foreach($extensions as $type => $files)
{
sugar_mkdir("$pathext/$type");
foreach($files as $file => $filePath)
{
copy ($filePath, "$pathext/$type/$file");
}
}
}
}
$this->copyCustomDropdownValuesForModules($modules,$path);
if(file_exists($path)){
$manifest = $this->getManifest(true).$this->customBuildInstall($modules,$path);
sugar_file_put_contents($path .'/manifest.php', $manifest);;
}
if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
copy('modules/ModuleBuilder/MB/LICENSE.txt', $path . '/LICENSE.txt');
}
else if(file_exists('LICENSE.txt')){
copy('LICENSE.txt', $path . '/LICENSE.txt');
}
require_once('include/utils/zip_utils.php');
$date = date('Y_m_d_His');
$zipDir = $this->getZipDir();
if(!file_exists($zipDir))mkdir_recursive($zipDir);
$cwd = getcwd();
chdir($this->getBuildDir());
zip_dir('.',$cwd . '/'. $zipDir. '/'. $this->name. $date. '.zip');
chdir($cwd);
if($clean && file_exists($this->getBuildDir()))rmdir_recursive($this->getBuildDir());
if($export){
header('Location:' . $zipDir. '/'. $this->name. $date. '.zip');
}
return $zipDir. '/'. $this->name. $date. '.zip';
}
private function convertLangFilesToExtensions($langDir)
{
if (is_dir($langDir))
{
foreach(scandir($langDir) as $langFile)
{
$mod_strings = array();
if (strcasecmp(substr($langFile, -4), ".php") != 0)
continue;
include("$langDir/$langFile");
$out = "<?php \n // created: " . date('Y-m-d H:i:s') . "\n";
foreach($mod_strings as $lbl_key => $lbl_val )
{
$out .= override_value_to_string("mod_strings", $lbl_key, $lbl_val) . "\n";
}
$out .= "\n?>\n";
sugar_file_put_contents("$langDir/$langFile", $out);
}
}
}
private function copyCustomDropdownValuesForModules($modules, $path)
{
if(file_exists("custom/include/language")){
if(mkdir_recursive("$path/SugarModules/include")){
global $app_list_strings;
$backStrings = $app_list_strings;
foreach(scandir("custom/include/language") as $langFile)
{
$app_list_strings = array();
if (strcasecmp(substr($langFile, -4), ".php") != 0)
continue;
include("custom/include/language/$langFile");
$out = "<?php \n";
$lang = substr($langFile, 0, -9);
$options = $this->getCustomDropDownStringsForModules($modules, $app_list_strings);
foreach($options as $name => $arr) {
$out .= override_value_to_string('app_list_strings', $name, $arr);
}
mkdir_recursive("$path/SugarModules/include/language/");
sugar_file_put_contents("$path/SugarModules/include/language/$lang.$this->name.php", $out);
}
$app_list_strings = $backStrings;
}
}
}
function getCustomDropDownStringsForModules($modules, $list_strings) {
global $beanList, $beanFiles;
$options = array();
foreach($modules as $module)
{
if (!empty($beanList[$module]))
{
require_once($beanFiles[$beanList[$module]]);
$bean = new $beanList[$module]();
foreach($bean->field_defs as $field => $def)
{
if (isset($def['options']) && isset($list_strings[$def['options']]))
{
$options[$def['options']] = $list_strings[$def['options']];
}
}
}
}
return $options;
}
//if $module=false : return an array with custom module and there customizations.
//if $module=!false : return an array with the directories of custom/module/$module.
function getCustomModules($module=false){
global $mod_strings;
$path='custom/modules/';
$extPath = 'custom/Extension/modules/';
if(!file_exists($path) || !is_dir($path)){
return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
}
else{
if ($module != false ){
$path=$path . $module . '/';
}
$scanlisting = scandir($path);
$dirlisting = array();
foreach ($scanlisting as $value){
if(is_dir($path . $value) == true && $value != '.' && $value != '..') {
$dirlisting[] = $value;
}
}
if(empty($dirlisting)){
return array($mod_strings['LBL_EC_NOCUSTOM'] => "");
}
if ($module == false ){
foreach ($dirlisting as $value){
if(!file_exists('modules/' . $value . '/metadata/studio.php'))
continue;
$custommodules[$value]=$this->getCustomModules($value);
foreach ($custommodules[$value] as $va){
switch ($va) {
case 'language':
$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
break;
case 'metadata':
$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMLAYOUT'];
break;
case 'Ext':
$return[$value][$va] = $mod_strings['LBL_EC_CUSTOMFIELD'];
break;
case '':
$return[$value . " " . $mod_strings['LBL_EC_EMPTYCUSTOM']] = "";
break;
default:
$return[$value][$va] = $mod_strings['LBL_UNDEFINED'];
}
}
}
return $return;
}
else{
return $dirlisting;
}
}
}
private function getExtensionsList($module, $excludeRelationships = true)
{
require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php' ;
$extPath = 'custom/Extension/modules/';
$modExtPath = $extPath . $module . '/Ext';
$rels = new DeployedRelationships($module);
$relList = $rels->getRelationshipList ();
$ret = array();
if (is_dir($modExtPath))
{
$extFolders = scandir($modExtPath);
foreach($extFolders as $extFolder)
{
if (!is_dir("$modExtPath/$extFolder") || substr($extFolder, 0, 1) == ".")
continue;
foreach( scandir("$modExtPath/$extFolder") as $extFile)
{
if (substr($extFile, 0, 1) == "." || strtolower(substr($extFile, -4)) != ".php")
continue;
//Exclude relattionship extension files
if ($excludeRelationships && (
(substr($extFile, 0, 6) == "custom" && isset($relList[substr($extFile, 6, strlen($extFile) - 10)])) ||
(substr($extFile, 6, 6) == "custom" && isset($relList[substr($extFile, 12, strlen($extFile) - 16)]))
)) {
continue;
}
if (!isset($ret[$extFolder]))
$ret[$extFolder] = array();
$ret[$extFolder][$extFile ] = "$modExtPath/$extFolder/$extFile";
}
}
}
return $ret;
}
/**
* Returns a set of field defs for fields that will exist when this package is deployed
* based on the relationships in all of its modules.
*
* @param $moduleName (module must be from whithin this package)
* @return array Field defs
*/
function getRelationshipsForModule($moduleName) {
$ret = array();
if (isset($this->modules[$moduleName])) {
$keyName = $this->modules[$moduleName]->key_name;
foreach($this->modules as $mName => $module) {
$rels = $module->getRelationships();
$relList = $rels->getRelationshipList();
foreach($relList as $rName ) {
$rel = $rels->get ( $rName ) ;
if ($rel->lhs_module == $keyName || $rel->rhs_module == $keyName) {
$ret[$rName] = $rel;
}
}
}
}
return $ret;
}
function exportProjectInstall($package, $for_export){
$pre = $for_export ? MB_EXPORTPREPEND : "";
$installdefs = array ('id' => $pre . $this->name);
$installdefs['copy'][] = array(
'from'=> '<basepath>/' . $this->name,
'to'=> 'custom/modulebuilder/packages/'. $this->name,
);
return "\n".'$installdefs = ' . var_export_helper($installdefs). ';';
}
function exportProject($package, $export=true, $clean = true){
$tmppath="custom/modulebuilder/projectTMP/";
if(file_exists($this->getPackageDir())){
if(mkdir_recursive($tmppath)){
copy_recursive($this->getPackageDir(), $tmppath ."/". $this->name);
$manifest = $this->getManifest(true, $export).$this->exportProjectInstall($package, $export);
$fp = sugar_fopen($tmppath .'/manifest.php', 'w');
fwrite($fp, $manifest);
fclose($fp);
if(file_exists('modules/ModuleBuilder/MB/LICENSE.txt')){
copy('modules/ModuleBuilder/MB/LICENSE.txt', $tmppath . '/LICENSE.txt');
}
else if(file_exists('LICENSE.txt')){
copy('LICENSE.txt', $tmppath . '/LICENSE.txt');
}
$readme_contents = $this->readme;
$readmefp = sugar_fopen($tmppath.'/README.txt','w');
fwrite($readmefp, $readme_contents);
fclose($readmefp);
}
}
require_once('include/utils/zip_utils.php');
$date = date('Y_m_d_His');
$zipDir = "custom/modulebuilder/packages/ExportProjectZips";
if(!file_exists($zipDir))mkdir_recursive($zipDir);
$cwd = getcwd();
chdir($tmppath);
zip_dir('.',$cwd . '/'. $zipDir. '/project_'. $this->name. $date. '.zip');
chdir($cwd);
if($clean && file_exists($tmppath))rmdir_recursive($tmppath);
if($export){
header('Location:' . $zipDir. '/project_'. $this->name. $date. '.zip');
}
return $zipDir. '/project_'. $this->name. $date. '.zip';
}
}
?>

View File

@@ -0,0 +1,78 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/ytree/Tree.php');
require_once('include/ytree/Node.php');
class MBPackageTree{
function MBPackageTree(){
$this->tree = new Tree('package_tree');
$this->tree->id = 'package_tree';
$this->mb = new ModuleBuilder();
$this->populateTree($this->mb->getNodes(), $this->tree);
}
function getName(){
return 'Packages';
}
function populateTree($nodes, &$parent){
foreach($nodes as $node){
if(empty($node['label']))$node['label'] = $node['name'];
$yn = new Node($parent->id . '/' . $node['name'],$node['label']);
if(!empty($node['action']))
$yn->set_property('action', $node['action']);
$yn->set_property('href', 'javascript:void(0);');
$yn->id = $parent->id . '/' . $node['name'];
if(!empty($node['children']))$this->populateTree($node['children'], $yn);
$parent->add_node($yn);
}
}
function fetch(){
//return $this->tree->generate_header() . $this->tree->generate_nodes_array();
return $this->tree->generate_nodes_array();
}
function fetchNodes(){
return $this->tree->generateNodesRaw();
}
}
?>

View File

@@ -0,0 +1,175 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php' ;
require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationships.php' ;
require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationship.php' ;
require_once 'modules/ModuleBuilder/parsers/relationships/ManyToManyRelationship.php' ;
/*
* This is an Adapter for the new UndeployedRelationships Class to allow ModuleBuilder to use the new class without change
* As ModuleBuilder is updated, references to this MBRelationship class should be replaced by direct references to UndeployedRelationships
*/
class MBRelationship
{
public $relatableModules = array ( ) ; // required by MBModule
public $relationships = array ( ) ; // required by view.relationships.php; must be kept in sync with the implementation
/*
* Constructor
* @param string $name The name of this module (not used)
* @param string $path The base path of the module directory within the ModuleBuilder package directory
* @param string $key_name The Fully Qualified Name for this module - that is, $packageName_$name
*/
function MBRelationship ($name , $path , $key_name)
{
$this->implementation = new UndeployedRelationships ( $path ) ;
$this->moduleName = $key_name ;
$this->path = $path ;
$this->updateRelationshipVariable();
}
function findRelatableModules ()
{
// do not call findRelatableModules in the constructor as it leads to an infinite loop if the implementation calls getPackage() which loads the packages which loads the module which findsRelatableModules which...
$this->relatableModules = $this->implementation->findRelatableModules () ;
}
/*
* Originally in 5.0 this method expected $_POST variables keyed in the "old" format - lhs_module, relate, msub, rsub etc
* At 5.1 this has been changed to the "new" format of lhs_module, rhs_module, lhs_subpanel, rhs_subpanel, label
* @return AbstractRelationship
*/
function addFromPost ()
{
return $this->implementation->addFromPost () ;
}
/*
* New function to replace the old MBModule subpanel property - now we obtain the 'subpanels' (actually related modules) from the relationships object
*/
function getRelationshipList ()
{
return $this->implementation->getRelationshipList () ;
}
function get ($relationshipName)
{
return $this->implementation->get ( $relationshipName ) ;
}
/*
* Deprecated
* Add a relationship to this set
* Original MBRelationships could only support one relationship between this module and any other
*/
/*
function addRelationship ($name , $relatedTo , $relatedSubpanel = 'default' , $mysubpanel = 'default' , $type)
{
$this->implementation->add ( new ManyToManyRelationship ( $name, $this->moduleName, $relatedTo, $mysubpanel, $relatedSubpanel ) ) ;
$this->updateRelationshipVariable () ;
}
*/
/* Add a relationship to this set
* Original MBRelationships could only support one relationship between this module and any other
* @param array $rel Relationship definition in the old format (defined by self::oldFormatKeys)
*/
function add ($rel)
{
// convert old format definition to new format
if (! isset ( $rel [ 'lhs_module' ] ))
$rel [ 'lhs_module' ] = $this->moduleName ;
$definition = AbstractRelationships::convertFromOldFormat ( $rel ) ;
if (! isset ( $definition ['relationship_type']))
$definition ['relationship_type'] = 'many-to-many';
// get relationship object from RelationshipFactory
$relationship = RelationshipFactory::newRelationship ( $definition ) ;
// add relationship to the set of relationships
$this->implementation->add ( $relationship ) ;
$this->updateRelationshipVariable () ;
return $relationship;
}
function delete ($name)
{
$this->implementation->delete ( $name ) ;
$this->updateRelationshipVariable () ;
}
function save ()
{
$this->implementation->save () ;
}
function build ($path)
{
$this->implementation->build () ;
}
function addInstallDefs (&$installDef)
{
$this->implementation->addInstallDefs ( $installDef ) ;
}
/*
function load ()
{
$this->implementation->load () ;
$this->updateRelationshipVariable () ;
}
*/
/*
* Transitional function to keep the public relationship variable in sync with the implementation master copy
* We have to do this as various things refer directly to MBRelationship->relationships...
*/
private function updateRelationshipVariable ()
{
foreach ( $this->implementation->getRelationshipList () as $relationshipName )
{
$rel = $this->implementation->getOldFormat ( $relationshipName ) ;
$this->relationships [ $relationshipName ] = $rel ;
}
}
}
?>

View File

@@ -0,0 +1,145 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class MBVardefs{
var $templates = array();
var $iTemplates = array();
var $vardefs = array();
var $vardef = array();
var $path = '';
var $name = '';
var $errors = array();
function MBVardefs($name, $path, $key_name){
$this->path = $path;
$this->name = $name;
$this->key_name = $key_name;
$this->load();
}
function loadTemplate($by_group, $template, $file){
$module = $this->name;
$table_name = $this->name;
$object_name = $this->key_name;
$_object_name = strtolower($this->key_name);
// required by the vardef template for team security in SugarObjects
$table_name = strtolower($module);
if(file_exists($file)){
include($file);
if($by_group){
$this->vardefs['fields'] [$template]= $vardefs['fields'];
}else{
$this->vardefs['fields']= array_merge($this->vardefs['fields'], $vardefs['fields']);
if(!empty($vardefs['relationships'])){
$this->vardefs['relationships']= array_merge($this->vardefs['relationships'], $vardefs['relationships']);
}
}
}
}
function mergeVardefs($by_group=false){
$this->vardefs = array(
'fields'=>array(),
'relationships'=>array(),
);
// $object_name = $this->key_name;
// $_object_name = strtolower($this->name);
$module_name = $this->name;
$this->loadTemplate($by_group,'basic', MB_TEMPLATES . '/basic/vardefs.php');
foreach($this->iTemplates as $template=>$val){
$file = MB_IMPLEMENTS . '/' . $template . '/vardefs.php';
$this->loadTemplate($by_group,$template, $file);
}
foreach($this->templates as $template=>$val){
if($template == 'basic')continue;
$file = MB_TEMPLATES . '/' . $template . '/vardefs.php';
$this->loadTemplate($by_group,$template, $file);
}
if($by_group){
$this->vardefs['fields'][$this->name] = $this->vardef['fields'];
}else{
$this->vardefs['fields'] = array_merge($this->vardefs['fields'], $this->vardef['fields']);
}
}
function updateVardefs($by_group=false){
$this->mergeVardefs($by_group);
}
function getVardefs(){
return $this->vardefs;
}
function getVardef(){
return $this->vardef;
}
function addFieldVardef($vardef){
if(empty($vardef['default']))unset($vardef['default']);
$this->vardef['fields'][$vardef['name']] = $vardef;
}
function deleteField($field){
unset($this->vardef['fields'][$field->name]);
}
function save(){
$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
write_array_to_file('vardefs', $this->vardef, $this->path . '/vardefs.php','w', $header);
}
function build($path){
$header = file_get_contents('modules/ModuleBuilder/MB/header.php');
write_array_to_file('dictionary["' . $this->name . '"]', $this->getVardefs(), $path . '/vardefs.php', 'w', $header);
}
function load(){
$this->vardef = array('fields'=>array(), 'relationships'=>array());
if(file_exists($this->path . '/vardefs.php')){
include($this->path. '/vardefs.php');
$this->vardef = $vardefs;
}
}
}
?>

View File

@@ -0,0 +1,147 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*********************************************************************************
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
* All Rights Reserved.
* Contributor(s): ______________________________________..
********************************************************************************/
define ( 'MB_PACKAGE_PATH', 'custom/modulebuilder/packages' ) ;
define ( 'MB_PACKAGE_BUILD', 'custom/modulebuilder/builds' ) ;
require_once ('modules/ModuleBuilder/MB/MBPackage.php') ;
class ModuleBuilder
{
var $packages = array ( ) ;
function getPackageList ()
{
static $list = array ( ) ;
if (! empty ( $list ) || ! file_exists ( MB_PACKAGE_PATH ))
return $list ;
$d = dir ( MB_PACKAGE_PATH ) ;
while ( $e = $d->read () )
{
if (file_exists ( MB_PACKAGE_PATH . '/' . $e . '/manifest.php' ))
{
$list [] = $e ;
}
}
sort ( $list ) ; // order important as generate_nodes_array in Tree.php later loops over this by foreach to generate the package list
return $list ;
}
function getPackage ($name)
{
if (! empty ( $this->packages [ $name ] ))
return $this->packages [ $name ] ;
$this->packages [ $name ] = new MBPackage ( $name ) ;
}
function getPackageKey ($name)
{
$manifestPath = MB_PACKAGE_PATH . '/' . $name . '/manifest.php' ;
if (file_exists ( $manifestPath ))
{
require( $manifestPath ) ;
if(!empty($manifest))
return $manifest['key'];
}
return false ;
}
function &getPackageModule ($package , $module)
{
$this->getPackage ( $package ) ;
$this->packages [ $package ]->getModule ( $module ) ;
return $this->packages [ $package ]->modules [ $module ] ;
}
function save ()
{
$packages = array_keys ( $this->packages ) ;
foreach ( $packages as $package )
{
$this->packages [ $package ]->save () ;
}
}
function build ()
{
$packages = array_keys ( $this->packages ) ;
foreach ( $packages as $package )
{
if (count ( $packages ) == 1)
{
$this->packages [ $package ]->build ( true ) ;
} else
{
$this->packages [ $package ]->build ( false ) ;
}
}
}
function getPackages ()
{
if (empty ( $this->packages ))
{
$list = $this->getPackageList () ;
foreach ( $list as $package )
{
if (! empty ( $this->packages [ $package ] ))
continue ;
$this->packages [ $package ] = new MBPackage ( $package ) ;
}
}
}
function getNodes ()
{
$this->getPackages () ;
$nodes = array ( ) ;
foreach ( array_keys ( $this->packages ) as $name )
{
$nodes [] = $this->packages [ $name ]->getNodes () ;
}
return $nodes ;
}
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/