2013-09-23 19:30:44 +00:00
< ? php
2018-08-01 19:14:25 +00:00
/**
*
2013-09-23 19:30:44 +00:00
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM , Inc . Copyright ( C ) 2004 - 2013 SugarCRM Inc .
2018-08-01 19:14:25 +00:00
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd .
* Copyright ( C ) 2011 - 2018 SalesAgility Ltd .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* 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 .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* 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
2018-08-01 19:14:25 +00:00
* FOR A PARTICULAR PURPOSE . See the GNU Affero General Public License for more
2013-09-23 19:30:44 +00:00
* details .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* 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 .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* You can contact SugarCRM , Inc . headquarters at 10050 North Wolfe Road ,
* SW2 - 130 , Cupertino , CA 95014 , USA . or at email address contact @ sugarcrm . com .
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* 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.
2014-07-07 15:33:23 +00:00
*
2013-09-23 19:30:44 +00:00
* 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
2014-07-07 15:33:23 +00:00
* SugarCRM " logo and " Supercharged by SuiteCRM " logo. If the display of the logos is not
2018-08-01 19:14:25 +00:00
* reasonably feasible for technical reasons , the Appropriate Legal Notices must
* display the words " Powered by SugarCRM " and " Supercharged by SuiteCRM " .
*/
2013-09-23 19:30:44 +00:00
require_once ( 'modules/ModuleBuilder/MB/AjaxCompose.php' );
2023-06-01 13:10:03 +00:00
#[\AllowDynamicProperties]
2013-09-23 19:30:44 +00:00
class ViewDropdown extends SugarView
{
2019-01-25 13:51:46 +00:00
/**
2019-01-25 14:07:05 +00:00
* @ see SugarView :: _getModuleTitleParams ()
*/
2019-01-25 13:51:46 +00:00
protected function _getModuleTitleParams ( $browserTitle = false )
{
global $mod_strings ;
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
return array (
2019-01-25 14:14:52 +00:00
translate ( 'LBL_MODULE_NAME' , 'Administration' ),
2019-01-25 14:07:05 +00:00
ModuleBuilderController :: getModuleTitle (),
);
2013-09-23 19:30:44 +00:00
}
2019-01-25 14:28:56 +00:00
public function display ()
2019-01-25 13:51:46 +00:00
{
$ajax = new AjaxCompose ();
$smarty = $this -> generateSmarty ();
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
if ( isset ( $_REQUEST [ 'refreshTree' ])) {
2019-01-25 14:22:15 +00:00
require_once ( 'modules/ModuleBuilder/Module/DropDownTree.php' );
2019-01-25 13:51:46 +00:00
$mbt = new DropDownTree ();
$ajax -> addSection ( 'west' , $mbt -> getName (), $mbt -> fetchNodes ());
2019-01-25 14:14:52 +00:00
$smarty -> assign ( 'refreshTree' , true );
2019-01-25 13:51:46 +00:00
}
2013-09-23 19:30:44 +00:00
global $mod_strings ;
2019-01-25 14:22:15 +00:00
$smarty -> assign ( 'deleteImage' , SugarThemeRegistry :: current () -> getImage ( 'delete_inline' , '' , null , null , '.gif' , $mod_strings [ 'LBL_MB_DELETE' ]));
$smarty -> assign ( 'editImage' , SugarThemeRegistry :: current () -> getImage ( 'edit_inline' , '' , null , null , '.gif' , $mod_strings [ 'LBL_EDIT' ], true , '.gif' ));
2019-01-25 13:51:46 +00:00
$smarty -> assign ( 'action' , 'savedropdown' );
$body = $smarty -> fetch ( 'modules/ModuleBuilder/tpls/MBModule/dropdown.tpl' );
2019-01-25 14:22:15 +00:00
$ajax -> addSection ( 'east2' , $mod_strings [ 'LBL_SECTION_DROPDOWNED' ], $body );
2019-01-25 13:51:46 +00:00
echo $ajax -> getJavascript ();
}
2019-01-25 14:07:05 +00:00
2019-01-25 14:28:56 +00:00
public function generateSmarty ()
2019-01-25 13:51:46 +00:00
{
2023-06-01 13:10:03 +00:00
$module = null ;
2019-01-25 13:51:46 +00:00
//get the selected language
$selected_lang = ( ! empty ( $_REQUEST [ 'dropdown_lang' ]) ? $_REQUEST [ 'dropdown_lang' ] : $_SESSION [ 'authenticated_user_language' ]);
$vardef = array ();
$package_name = 'studio' ;
$package_strings = array ();
$new = false ;
2019-01-25 14:22:15 +00:00
$my_list_strings = return_app_list_strings_language ( $selected_lang ) ;
2019-01-25 13:51:46 +00:00
// $my_list_strings = $GLOBALS['app_list_strings'];
2013-09-23 19:30:44 +00:00
$smarty = new Sugar_Smarty ();
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
//if we are using ModuleBuilder then process the following
if ( ! empty ( $_REQUEST [ 'view_package' ]) && $_REQUEST [ 'view_package' ] != 'studio' ) {
require_once ( 'modules/ModuleBuilder/MB/ModuleBuilder.php' );
$mb = new ModuleBuilder ();
$module = $mb -> getPackageModule ( $_REQUEST [ 'view_package' ], $_REQUEST [ 'view_module' ]);
$package = $mb -> packages [ $_REQUEST [ 'view_package' ]];
$package_name = $package -> name ;
$module -> getVardefs ();
if ( empty ( $_REQUEST [ 'dropdown_name' ]) && ! empty ( $_REQUEST [ 'field' ])) {
$new = true ;
$_REQUEST [ 'dropdown_name' ] = $_REQUEST [ 'field' ] . '_list' ;
}
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
$vardef = ( ! empty ( $module -> mbvardefs -> fields [ $_REQUEST [ 'dropdown_name' ]])) ? $module -> mbvardefs -> fields [ $_REQUEST [ 'dropdown_name' ]] : array ();
$module -> mblanguage -> generateAppStrings ( false ) ;
2019-01-25 14:22:15 +00:00
$my_list_strings = array_merge ( $my_list_strings , $module -> mblanguage -> appListStrings [ $selected_lang . '.lang.php' ]);
2013-09-23 19:30:44 +00:00
$smarty -> assign ( 'module_name' , $module -> name );
2019-01-25 13:51:46 +00:00
}
2013-09-23 19:30:44 +00:00
$module_name = ! empty ( $module -> name ) ? $module -> name : '' ;
$module_name = ( empty ( $module_name ) && ! empty ( $_REQUEST [ 'view_module' ])) ? $_REQUEST [ 'view_module' ] : $module_name ;
2019-01-25 13:51:46 +00:00
foreach ( $my_list_strings as $key => $value ) {
if ( ! is_array ( $value )) {
unset ( $my_list_strings [ $key ]);
}
}
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
$dropdowns = array_keys ( $my_list_strings );
asort ( $dropdowns );
$keys = array_keys ( $dropdowns );
$first_string = $my_list_strings [ $dropdowns [ $keys [ 0 ]]];
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
$name = '' ;
$selected_dropdown = array ();
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
$json = getJSONobj ();
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
if ( ! empty ( $_REQUEST [ 'dropdown_name' ]) && ! $new ) {
$name = $_REQUEST [ 'dropdown_name' ];
2019-01-25 14:07:05 +00:00
2019-01-25 13:51:46 +00:00
// handle the case where we've saved a dropdown in one language, and now attempt to edit it for another language. The $name exists, but $my_list_strings[$name] doesn't
2013-09-23 19:30:44 +00:00
// for now, we just treat it as if it was new. A better approach might be to use the first language version as a template for future languages
2019-01-25 13:51:46 +00:00
if ( ! isset ( $my_list_strings [ $name ])) {
2019-01-25 14:22:15 +00:00
$my_list_strings [ $name ] = array () ;
2019-01-25 13:51:46 +00:00
}
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
$selected_dropdown = ( ! empty ( $vardef [ 'options' ]) && ! empty ( $my_list_strings [ $vardef [ 'options' ]])) ? $my_list_strings [ $vardef [ 'options' ]] : $my_list_strings [ $name ];
$smarty -> assign ( 'ul_list' , 'list = ' . $json -> encode ( array_keys ( $selected_dropdown )));
$smarty -> assign ( 'dropdown_name' , ( ! empty ( $vardef [ 'options' ]) ? $vardef [ 'options' ] : $_REQUEST [ 'dropdown_name' ]));
$smarty -> assign ( 'name' , $_REQUEST [ 'dropdown_name' ]);
$smarty -> assign ( 'options' , $selected_dropdown );
} else {
$smarty -> assign ( 'ul_list' , 'list = {}' );
//we should try to find a name for this dropdown based on the field name.
$pre_pop_name = '' ;
if ( ! empty ( $_REQUEST [ 'field' ])) {
$pre_pop_name = $_REQUEST [ 'field' ];
}
//ensure this dropdown name does not already exist
$use_name = $pre_pop_name . '_list' ;
for ( $i = 0 ; $i < 100 ; $i ++ ) {
if ( empty ( $my_list_strings [ $use_name ])) {
break ;
} else {
$use_name = $pre_pop_name . '_' . $i ;
}
}
$smarty -> assign ( 'prepopulated_name' , $use_name );
}
2013-09-23 19:30:44 +00:00
2019-01-25 13:51:46 +00:00
$smarty -> assign ( 'module_name' , $module_name );
$smarty -> assign ( 'APP' , $GLOBALS [ 'app_strings' ]);
$smarty -> assign ( 'MOD' , $GLOBALS [ 'mod_strings' ]);
$smarty -> assign ( 'selected_lang' , $selected_lang );
2019-01-25 14:14:52 +00:00
$smarty -> assign ( 'available_languages' , get_languages ());
2019-01-25 13:51:46 +00:00
$smarty -> assign ( 'package_name' , $package_name );
return $smarty ;
}
2019-01-25 14:26:18 +00:00
}