Add php files
This commit is contained in:
289
include/Dashlets/Dashlet.php
Executable file
289
include/Dashlets/Dashlet.php
Executable file
@@ -0,0 +1,289 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
class Dashlet {
|
||||
/**
|
||||
* Id of the Dashlet
|
||||
* @var guid
|
||||
*/
|
||||
var $id;
|
||||
/**
|
||||
* Title of the Dashlet
|
||||
* @var string
|
||||
*/
|
||||
var $title = 'Generic Dashlet';
|
||||
/**
|
||||
* true if the Dashlet has configuration options.
|
||||
* @var bool
|
||||
*/
|
||||
var $isConfigurable = false;
|
||||
/**
|
||||
* true if the Dashlet is refreshable (ie charts that provide their own refresh)
|
||||
* @var bool
|
||||
*/
|
||||
var $isRefreshable = true;
|
||||
/**
|
||||
* true if the Dashlet contains javascript
|
||||
* @var bool
|
||||
*/
|
||||
var $hasScript = false;
|
||||
/**
|
||||
* Language strings, must be loaded at the Dashlet level w/ loadLanguage
|
||||
* @var array
|
||||
*/
|
||||
var $dashletStrings;
|
||||
/**
|
||||
* extra button
|
||||
* @param unknown $id
|
||||
*/
|
||||
var $extabutton;
|
||||
|
||||
function Dashlet($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
function setConfigureIcon(){
|
||||
|
||||
|
||||
if($this->isConfigurable)
|
||||
$additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet"><a href="#" onclick="SUGAR.mySugar.configureDashlet(\''
|
||||
. $this->id . '\'); return false;">'
|
||||
. SugarThemeRegistry::current()->getImage('dashlet-header-edit','title="' . translate('LBL_DASHLET_EDIT', 'Home') . '" alt="' . translate('LBL_DASHLET_EDIT', 'Home') . '" border="0" align="absmiddle"').'</a>'
|
||||
. '';
|
||||
else
|
||||
$additionalTitle = '<td nowrap width="1%" style="padding-right: 0px;"><div class="dashletToolSet">';
|
||||
|
||||
return $additionalTitle;
|
||||
}
|
||||
|
||||
function setFileIcon(){
|
||||
$additionalTitle = '';
|
||||
if($this->isRefreshable)
|
||||
$additionalTitle .= '<a href="#" onclick="$( \'#bankcsv_'. $this->id .'\' ).dialog( \'open\' );">
|
||||
<img src="themes/Sugar5/images/csv-128.png">'
|
||||
|
||||
. '</a><div id="bankcsv_'. $this->id .'" title="Przelewy do banku">
|
||||
<p>Wybierz format: <select name="bankType_'. $this->id . '" id="bankType_'. $this->id . '"><option value="1">BGŻ</option></select></p>
|
||||
<p><input type="button" value="Pobierz" onClick="SUGAR.mySugar.getFileDashlet(\''
|
||||
. $this->id . '\'); return false;"></p>
|
||||
</div>
|
||||
';
|
||||
$additionalTitle.=' <script>
|
||||
$(function() {
|
||||
$( "#bankcsv_'. $this->id .'" ).dialog({
|
||||
autoOpen: false,
|
||||
show: {
|
||||
effect: "blind",
|
||||
duration: 1000
|
||||
},
|
||||
hide: {
|
||||
effect: "explode",
|
||||
duration: 1000
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>';
|
||||
return $additionalTitle;
|
||||
}
|
||||
|
||||
function setRefreshIcon(){
|
||||
|
||||
|
||||
$additionalTitle = '';
|
||||
if($this->isRefreshable)
|
||||
$additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
|
||||
. $this->id . '\'); return false;">'
|
||||
. SugarThemeRegistry::current()->getImage('dashlet-header-refresh','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '"')
|
||||
. '</a>';
|
||||
return $additionalTitle;
|
||||
}
|
||||
|
||||
function setDeleteIcon(){
|
||||
global $image_path, $sugar_config, $current_user;
|
||||
if (!empty($sugar_config['lock_homepage']) && $sugar_config['lock_homepage'] == true)
|
||||
return '</div></td></tr></table>';
|
||||
$additionalTitle = '';
|
||||
$additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.deleteDashlet(\''
|
||||
. $this->id . '\'); return false;">'
|
||||
. SugarThemeRegistry::current()->getImage('dashlet-header-close','border="0" align="absmiddle" title="' . translate('LBL_DASHLET_DELETE', 'Home') . '" alt="' . translate('LBL_DASHLET_DELETE', 'Home') . '"')
|
||||
. '</a></div></td></tr></table>';
|
||||
return $additionalTitle;
|
||||
}
|
||||
|
||||
// No longer needed, replaced with getHeader/getFooter
|
||||
function getTitle($text = '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Dashlet is displayed
|
||||
*
|
||||
* @param string $text text after the title
|
||||
* @return string Header html
|
||||
*/
|
||||
function getHeader($text = '') {
|
||||
global $app_strings, $sugar_config,$guzik;
|
||||
|
||||
$title = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td width="99%">' . $text . '</td>';
|
||||
$title .= $this->setConfigureIcon();
|
||||
|
||||
$title .= $this->setRefreshIcon();
|
||||
if($this->extabutton==1){
|
||||
$title .= $this->setFileIcon();
|
||||
}
|
||||
$title .= $this->setDeleteIcon();
|
||||
|
||||
if(!function_exists('get_form_header')) {
|
||||
global $theme;
|
||||
|
||||
}
|
||||
|
||||
$str = '<div ';
|
||||
if(empty($sugar_config['lock_homepage']) || $sugar_config['lock_homepage'] == false) $str .= ' onmouseover="this.style.cursor = \'move\';"';
|
||||
$str .= 'id="dashlet_header_' . $this->id . '" class="hd"><div class="tl"></div><div class="hd-center">' . get_form_header($this->title, $title, false) . '</div><div class="tr"></div></div><div class="bd"><div class="ml"></div><div class="bd-center">';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Dashlet is displayed
|
||||
*
|
||||
* @param string $text text after the title
|
||||
* @return string footer html
|
||||
*/
|
||||
function getFooter($text = '') {
|
||||
//$footer = '</div>';
|
||||
|
||||
$footer = '</div><div class="mr"></div></div><div class="ft"><div class="bl"></div><div class="ft-center"></div><div class="br"></div></div>';
|
||||
return $footer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Dashlet is displayed, override this
|
||||
*
|
||||
* @param string $text text after the title
|
||||
* @return string title html
|
||||
*/
|
||||
function display($text = '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Dashlets configuration options are called
|
||||
*
|
||||
*/
|
||||
function displayOptions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* override if you need to do pre-processing before display is called
|
||||
*
|
||||
*/
|
||||
function process() {
|
||||
}
|
||||
|
||||
function save() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if your dashlet is configurable (this is called when the the configureDashlet form is shown)
|
||||
* Filters the array for only the parameters it needs to save
|
||||
*
|
||||
* @param array $req the array to pull options from
|
||||
*
|
||||
* @return array options array
|
||||
*/
|
||||
function saveOptions($req) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language strings
|
||||
*
|
||||
* @param string $dashletClassname classname of the dashlet
|
||||
*
|
||||
*/
|
||||
function loadLanguage($dashletClassname, $dashletDirectory = 'modules/Home/Dashlets/') {
|
||||
global $current_language, $dashletStrings;
|
||||
|
||||
if(!isset($dashletStrings[$dashletClassname])) {
|
||||
// load current language strings for current language, else default to english
|
||||
if(is_file($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php'))
|
||||
require_once($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.' . $current_language . '.lang.php');
|
||||
else
|
||||
require_once($dashletDirectory . $dashletClassname . '/' . $dashletClassname . '.en_us.lang.php');
|
||||
}
|
||||
|
||||
$this->dashletStrings = $dashletStrings[$dashletClassname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic way to store an options array into UserPreferences
|
||||
*
|
||||
* @param array $optionsArray the array to save
|
||||
*/
|
||||
function storeOptions($optionsArray) {
|
||||
global $current_user;
|
||||
$dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
|
||||
$dashletDefs[$this->id]['options'] = $optionsArray;
|
||||
$current_user->setPreference('dashlets', $dashletDefs, 0, 'Home');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic way to retrieve options array from UserPreferences
|
||||
*
|
||||
* @return array options array stored in UserPreferences
|
||||
*/
|
||||
function loadOptions() {
|
||||
global $current_user;
|
||||
$dashletDefs = $current_user->getPreference('dashlets', 'Home'); // load user's dashlets config
|
||||
if(isset($dashletDefs[$this->id]['options']))
|
||||
return $dashletDefs[$this->id]['options'];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this in the subclass. It is used to determine whether the dashlet can be displayed.
|
||||
*
|
||||
* @return bool indicating whether or not the current user has access to display this Dashlet.
|
||||
*/
|
||||
function hasAccess(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
87
include/Dashlets/DashletCacheBuilder.php
Executable file
87
include/Dashlets/DashletCacheBuilder.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Handles Generic Widgets
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
class DashletCacheBuilder {
|
||||
|
||||
/**
|
||||
* Builds the cache of Dashlets by scanning the system
|
||||
*/
|
||||
function buildCache() {
|
||||
global $beanList;
|
||||
$dashletFiles = array();
|
||||
$dashletFilesCustom = array();
|
||||
|
||||
getFiles($dashletFiles, 'modules', '/^.*\/Dashlets\/[^\.]*\.php$/');
|
||||
getFiles($dashletFilesCustom, 'custom/modules', '/^.*\/Dashlets\/[^\.]*\.php$/');
|
||||
$cacheDir = create_cache_directory('dashlets/');
|
||||
$allDashlets = array_merge($dashletFiles, $dashletFilesCustom);
|
||||
$dashletFiles = array();
|
||||
foreach($allDashlets as $num => $file) {
|
||||
if(substr_count($file, '.meta') == 0) { // ignore meta data files
|
||||
$class = substr($file, strrpos($file, '/') + 1, -4);
|
||||
$dashletFiles[$class] = array();
|
||||
$dashletFiles[$class]['file'] = $file;
|
||||
$dashletFiles[$class]['class'] = $class;
|
||||
if(is_file(preg_replace('/(.*\/.*)(\.php)/Uis', '$1.meta$2', $file))) { // is there an associated meta data file?
|
||||
$dashletFiles[$class]['meta'] = preg_replace('/(.*\/.*)(\.php)/Uis', '$1.meta$2', $file);
|
||||
require($dashletFiles[$class]['meta']);
|
||||
if ( isset($dashletMeta[$class]['module']) )
|
||||
$dashletFiles[$class]['module'] = $dashletMeta[$class]['module'];
|
||||
}
|
||||
|
||||
$filesInDirectory = array();
|
||||
getFiles($filesInDirectory, substr($file, 0, strrpos($file, '/')), '/^.*\/Dashlets\/[^\.]*\.icon\.(jpg|jpeg|gif|png)$/i');
|
||||
if(!empty($filesInDirectory)) {
|
||||
$dashletFiles[$class]['icon'] = $filesInDirectory[0]; // take the first icon we see
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write_array_to_file('dashletsFiles', $dashletFiles, $cacheDir . 'dashlets.php');
|
||||
}
|
||||
}
|
||||
?>
|
||||
490
include/Dashlets/DashletGeneric.php
Executable file
490
include/Dashlets/DashletGeneric.php
Executable file
@@ -0,0 +1,490 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
require_once('include/Dashlets/Dashlet.php');
|
||||
require_once('include/ListView/ListViewSmarty.php');
|
||||
require_once('include/generic/LayoutManager.php');
|
||||
|
||||
class DashletGeneric extends Dashlet {
|
||||
/**
|
||||
* Fields that are searchable
|
||||
* @var array
|
||||
*/
|
||||
var $searchFields;
|
||||
/**
|
||||
* Displayable columns (ones available to display)
|
||||
* @var array
|
||||
*/
|
||||
var $columns;
|
||||
/**
|
||||
* Bean file used in this Dashlet
|
||||
* @var bean
|
||||
*/
|
||||
var $seedBean;
|
||||
/**
|
||||
* collection of filters to apply
|
||||
* @var array
|
||||
*/
|
||||
var $filters = null;
|
||||
/**
|
||||
* Number of Rows to display
|
||||
* @var int
|
||||
*/
|
||||
var $displayRows = '5';
|
||||
/**
|
||||
* Actual columns to display, will be a subset of $columns
|
||||
* @var array
|
||||
*/
|
||||
var $displayColumns = null;
|
||||
/**
|
||||
* Flag to display only the current users's items.
|
||||
* @var bool
|
||||
*/
|
||||
var $myItemsOnly = true;
|
||||
/**
|
||||
* Flag to display "myItemsOnly" checkbox in the DashletGenericConfigure.
|
||||
* @var bool
|
||||
*/
|
||||
var $showMyItemsOnly = true;
|
||||
/**
|
||||
* location of Smarty template file for display
|
||||
* @var string
|
||||
*/
|
||||
var $displayTpl = 'include/Dashlets/DashletGenericDisplay.tpl';
|
||||
/**
|
||||
* location of smarty template file for configuring
|
||||
* @var string
|
||||
*/
|
||||
var $configureTpl = 'include/Dashlets/DashletGenericConfigure.tpl';
|
||||
/**
|
||||
* smarty object for the generic configuration template
|
||||
* @var string
|
||||
*/
|
||||
var $configureSS;
|
||||
/** search inputs to be populated in configure template.
|
||||
* modify this after processDisplayOptions, but before displayOptions to modify search inputs
|
||||
* @var array
|
||||
*/
|
||||
var $currentSearchFields;
|
||||
/**
|
||||
* ListView Smarty Class
|
||||
* @var Smarty
|
||||
*/
|
||||
var $lvs;
|
||||
var $layoutManager;
|
||||
|
||||
function DashletGeneric($id, $options = null) {
|
||||
parent::Dashlet($id);
|
||||
$this->isConfigurable = true;
|
||||
if(isset($options)) {
|
||||
if(!empty($options['filters'])) $this->filters = $options['filters'];
|
||||
if(!empty($options['title'])) $this->title = $options['title'];
|
||||
if(!empty($options['displayRows'])) $this->displayRows = $options['displayRows'];
|
||||
if(!empty($options['displayColumns'])) $this->displayColumns = $options['displayColumns'];
|
||||
if(isset($options['myItemsOnly'])) $this->myItemsOnly = $options['myItemsOnly'];
|
||||
if(isset($options['extabutton'])) $this->extabutton = $options['extabutton'];
|
||||
}
|
||||
|
||||
$this->layoutManager = new LayoutManager();
|
||||
$this->layoutManager->setAttribute('context', 'Report');
|
||||
// fake a reporter object here just to pass along the db type used in many widgets.
|
||||
// this should be taken out when sugarwidgets change
|
||||
$temp = (object) array('db' => &$GLOBALS['db'], 'report_def_str' => '');
|
||||
$this->layoutManager->setAttributePtr('reporter', $temp);
|
||||
$this->lvs = new ListViewSmarty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the display options template
|
||||
*
|
||||
* @return string HTML that shows options
|
||||
*/
|
||||
function processDisplayOptions() {
|
||||
require_once('include/templates/TemplateGroupChooser.php');
|
||||
|
||||
$this->configureSS = new Sugar_Smarty();
|
||||
// column chooser
|
||||
$chooser = new TemplateGroupChooser();
|
||||
|
||||
$chooser->args['id'] = 'edit_tabs';
|
||||
$chooser->args['left_size'] = 5;
|
||||
$chooser->args['right_size'] = 5;
|
||||
$chooser->args['values_array'][0] = array();
|
||||
$chooser->args['values_array'][1] = array();
|
||||
|
||||
$this->loadCustomMetadata();
|
||||
$this->addCustomFields();
|
||||
if($this->displayColumns) {
|
||||
// columns to display
|
||||
foreach($this->displayColumns as $num => $name) {
|
||||
// defensive code for array being returned
|
||||
$translated = translate($this->columns[$name]['label'], $this->seedBean->module_dir);
|
||||
if(is_array($translated)) $translated = $this->columns[$name]['label'];
|
||||
$chooser->args['values_array'][0][$name] = trim($translated, ':');
|
||||
}
|
||||
// columns not displayed
|
||||
foreach(array_diff(array_keys($this->columns), array_values($this->displayColumns)) as $num => $name) {
|
||||
// defensive code for array being returned
|
||||
$translated = translate($this->columns[$name]['label'], $this->seedBean->module_dir);
|
||||
if(is_array($translated)) $translated = $this->columns[$name]['label'];
|
||||
$chooser->args['values_array'][1][$name] = trim($translated, ':');
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach($this->columns as $name => $val) {
|
||||
// defensive code for array being returned
|
||||
$translated = translate($this->columns[$name]['label'], $this->seedBean->module_dir);
|
||||
if(is_array($translated)) $translated = $this->columns[$name]['label'];
|
||||
if(!empty($val['default']) && $val['default'])
|
||||
$chooser->args['values_array'][0][$name] = trim($translated, ':');
|
||||
else
|
||||
$chooser->args['values_array'][1][$name] = trim($translated, ':');
|
||||
}
|
||||
}
|
||||
|
||||
$chooser->args['left_name'] = 'display_tabs';
|
||||
$chooser->args['right_name'] = 'hide_tabs';
|
||||
$chooser->args['max_left'] = '6';
|
||||
|
||||
$chooser->args['left_label'] = $GLOBALS['app_strings']['LBL_DISPLAY_COLUMNS'];
|
||||
$chooser->args['right_label'] = $GLOBALS['app_strings']['LBL_HIDE_COLUMNS'];
|
||||
$chooser->args['title'] = '';
|
||||
$this->configureSS->assign('columnChooser', $chooser->display());
|
||||
|
||||
$query = false;
|
||||
$count = 0;
|
||||
|
||||
if(!is_array($this->filters)) {
|
||||
// use default search params
|
||||
$this->filters = array();
|
||||
foreach($this->searchFields as $name => $params) {
|
||||
if(!empty($params['default']))
|
||||
$this->filters[$name] = $params['default'];
|
||||
}
|
||||
}
|
||||
foreach($this->searchFields as $name=>$params) {
|
||||
if(!empty($name)) {
|
||||
$name = strtolower($name);
|
||||
$currentSearchFields[$name] = array();
|
||||
$widgetDef = $this->seedBean->field_defs[$name];
|
||||
if($widgetDef['type'] == 'enum') $widgetDef['remove_blank'] = true; // remove the blank option for the dropdown
|
||||
if($widgetDef['name'] == 'assigned_user_name') $widgetDef['name'] = 'assigned_user_id';
|
||||
$widgetDef['input_name0'] = empty($this->filters[$name]) ? '' : $this->filters[$name];
|
||||
$currentSearchFields[$name]['label'] = !empty($params['label']) ? translate($params['label'], $this->seedBean->module_dir) : translate($widgetDef['vname'], $this->seedBean->module_dir);
|
||||
$currentSearchFields[$name]['input'] = $this->layoutManager->widgetDisplayInput($widgetDef, true, (empty($this->filters[$name]) ? '' : $this->filters[$name]));
|
||||
}
|
||||
else { // ability to create spacers in input fields
|
||||
$currentSearchFields['blank' + $count]['label'] = '';
|
||||
$currentSearchFields['blank' + $count]['input'] = '';
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$this->currentSearchFields = $currentSearchFields;
|
||||
|
||||
$this->configureSS->assign('strings', array('general' => $GLOBALS['mod_strings']['LBL_DASHLET_CONFIGURE_GENERAL'],
|
||||
'filters' => $GLOBALS['mod_strings']['LBL_DASHLET_CONFIGURE_FILTERS'],
|
||||
'myItems' => $GLOBALS['mod_strings']['LBL_DASHLET_CONFIGURE_MY_ITEMS_ONLY'],
|
||||
'displayRows' => $GLOBALS['mod_strings']['LBL_DASHLET_CONFIGURE_DISPLAY_ROWS'],
|
||||
'title' => $GLOBALS['mod_strings']['LBL_DASHLET_CONFIGURE_TITLE'],
|
||||
'save' => $GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL']));
|
||||
$this->configureSS->assign('id', $this->id);
|
||||
$this->configureSS->assign('showMyItemsOnly', $this->showMyItemsOnly);
|
||||
$this->configureSS->assign('myItemsOnly', $this->myItemsOnly);
|
||||
$this->configureSS->assign('searchFields', $this->currentSearchFields);
|
||||
// title
|
||||
$this->configureSS->assign('dashletTitle', $this->title);
|
||||
|
||||
// display rows
|
||||
$displayRowOptions = $GLOBALS['sugar_config']['dashlet_display_row_options'];
|
||||
$this->configureSS->assign('displayRowOptions', $displayRowOptions);
|
||||
$this->configureSS->assign('displayRowSelect', $this->displayRows);
|
||||
}
|
||||
/**
|
||||
* Displays the options for this Dashlet
|
||||
*
|
||||
* @return string HTML that shows options
|
||||
*/
|
||||
function displayOptions() {
|
||||
$this->processDisplayOptions();
|
||||
return parent::displayOptions() . $this->configureSS->fetch($this->configureTpl);
|
||||
}
|
||||
|
||||
function buildWhere() {
|
||||
global $current_user;
|
||||
|
||||
$returnArray = array();
|
||||
|
||||
if(!is_array($this->filters)) {
|
||||
// use defaults
|
||||
$this->filters = array();
|
||||
foreach($this->searchFields as $name => $params) {
|
||||
if(!empty($params['default']))
|
||||
$this->filters[$name] = $params['default'];
|
||||
}
|
||||
}
|
||||
foreach($this->filters as $name=>$params) {
|
||||
if(!empty($params)) {
|
||||
if($name == 'assigned_user_id' && $this->myItemsOnly) continue; // don't handle assigned user filter if filtering my items only
|
||||
$widgetDef = $this->seedBean->field_defs[$name];
|
||||
|
||||
$widgetClass = $this->layoutManager->getClassFromWidgetDef($widgetDef, true);
|
||||
$widgetDef['table'] = $this->seedBean->table_name;
|
||||
$widgetDef['table_alias'] = $this->seedBean->table_name;
|
||||
if(!empty($widgetDef['source']) && $widgetDef['source'] == 'custom_fields'){
|
||||
$widgetDef['table'] = $this->seedBean->table_name."_cstm";
|
||||
$widgetDef['table_alias'] = $widgetDef['table'];
|
||||
}
|
||||
switch($widgetDef['type']) {// handle different types
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
case 'datetimecombo':
|
||||
if(is_array($params) && !empty($params)) {
|
||||
if(!empty($params['date']))
|
||||
$widgetDef['input_name0'] = $params['date'];
|
||||
$filter = 'queryFilter' . $params['type'];
|
||||
}
|
||||
else {
|
||||
$filter = 'queryFilter' . $params;
|
||||
}
|
||||
array_push($returnArray, $widgetClass->$filter($widgetDef, true));
|
||||
break;
|
||||
case 'assigned_user_name':
|
||||
// This type runs through the SugarWidgetFieldname class, and needs a little extra help to make it through
|
||||
if ( ! isset($widgetDef['column_key']) ) {
|
||||
$widgetDef['column_key'] = $name;
|
||||
}
|
||||
// No break here, we want to run through the default handler
|
||||
default:
|
||||
$widgetDef['input_name0'] = $params;
|
||||
if(is_array($params) && !empty($params)) { // handle array query
|
||||
array_push($returnArray, $widgetClass->queryFilterone_of($widgetDef, false));
|
||||
}
|
||||
else {
|
||||
array_push($returnArray, $widgetClass->queryFilterStarts_With($widgetDef, true));
|
||||
}
|
||||
$widgetDef['input_name0'] = $params;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($this->myItemsOnly) array_push($returnArray, $this->seedBean->table_name . '.' . "assigned_user_id = '" . $current_user->id . "'");
|
||||
|
||||
return $returnArray;
|
||||
}
|
||||
|
||||
private function loadCustomMetadata(){
|
||||
$customMetadate = 'custom/modules/'.$this->seedBean->module_dir.'/metadata/dashletviewdefs.php';
|
||||
if ( file_exists ( $customMetadate )){
|
||||
require_once($customMetadate);
|
||||
$this->searchFields = $dashletData[$this->seedBean->module_dir.'Dashlet']['searchFields'];
|
||||
foreach($this->searchFields as $key =>$def){
|
||||
if($key == 'assigned_user_name'){
|
||||
$this->searchFields['assigned_user_id'] = $def;
|
||||
unset($this->searchFields['assigned_user_name'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->columns = $dashletData[$this->seedBean->module_dir.'Dashlet']['columns'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does all dashlet processing, here's your chance to modify the rows being displayed!
|
||||
*/
|
||||
function process($lvsParams = array()) {
|
||||
$currentSearchFields = array();
|
||||
$configureView = true; // configure view or regular view
|
||||
$query = false;
|
||||
$whereArray = array();
|
||||
$lvsParams['massupdate'] = false;
|
||||
|
||||
$this->loadCustomMetadata();
|
||||
$this->addCustomFields();
|
||||
// apply filters
|
||||
if(isset($this->filters) || $this->myItemsOnly) {
|
||||
$whereArray = $this->buildWhere();
|
||||
}
|
||||
|
||||
$this->lvs->export = false;
|
||||
$this->lvs->multiSelect = false;
|
||||
// columns
|
||||
$displayColumns = array();
|
||||
if(!empty($this->displayColumns)) { // use user specified columns
|
||||
foreach($this->displayColumns as $name => $val) {
|
||||
$displayColumns[strtoupper($val)] = $this->columns[$val];
|
||||
$displayColumns[strtoupper($val)]['label'] = trim($displayColumns[strtoupper($val)]['label'], ':');// strip : at the end of headers
|
||||
}
|
||||
}
|
||||
else if (isset($this->columns)){
|
||||
// use the default
|
||||
foreach($this->columns as $name => $val) {
|
||||
if(!empty($val['default']) && $val['default']) {
|
||||
$displayColumns[strtoupper($name)] = $val;
|
||||
$displayColumns[strtoupper($name)]['label'] = trim($displayColumns[strtoupper($name)]['label'], ':');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->lvs->displayColumns = $displayColumns;
|
||||
|
||||
$this->lvs->lvd->setVariableName($this->seedBean->object_name, array());
|
||||
$lvdOrderBy = $this->lvs->lvd->getOrderBy(); // has this list been ordered, if not use default
|
||||
if(empty($lvdOrderBy['orderBy'])) {
|
||||
foreach($displayColumns as $colName => $colParams) {
|
||||
if(!empty($colParams['defaultOrderColumn'])) {
|
||||
$lvsParams['overrideOrder'] = true;
|
||||
$lvsParams['orderBy'] = $colName;
|
||||
$lvsParams['sortOrder'] = $colParams['defaultOrderColumn']['sortOrder'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!empty($this->displayTpl))
|
||||
{
|
||||
//MFH BUG #14296
|
||||
$where = '';
|
||||
if(!empty($whereArray)){
|
||||
$where = '(' . implode(') AND (', $whereArray) . ')';
|
||||
}
|
||||
$this->lvs->setup($this->seedBean, $this->displayTpl, $where , $lvsParams, 0, $this->displayRows/*, $filterFields*/);
|
||||
foreach($this->lvs->data['data'] as $row => $data) {
|
||||
|
||||
$this->lvs->data['data'][$row]['VALUE'] = format_number($data['VALUE']);
|
||||
}
|
||||
if(in_array('CREATED_BY', array_keys($displayColumns))) { // handle the created by field
|
||||
foreach($this->lvs->data['data'] as $row => $data) {
|
||||
$this->lvs->data['data'][$row]['CREATED_BY'] = get_assigned_user_name($data['CREATED_BY']);
|
||||
}
|
||||
}
|
||||
// assign a baseURL w/ the action set as DisplayDashlet
|
||||
foreach($this->lvs->data['pageData']['urls'] as $type => $url) {
|
||||
// awu Replacing action=DisplayDashlet with action=DynamicAction&DynamicAction=DisplayDashlet
|
||||
if($type == 'orderBy')
|
||||
$this->lvs->data['pageData']['urls'][$type] = preg_replace('/(action=.*&)/Ui', 'action=DynamicAction&DynamicAction=displayDashlet&', $url);
|
||||
else
|
||||
$this->lvs->data['pageData']['urls'][$type] = preg_replace('/(action=.*&)/Ui', 'action=DynamicAction&DynamicAction=displayDashlet&', $url) . '&sugar_body_only=1&id=' . $this->id;
|
||||
}
|
||||
|
||||
$this->lvs->ss->assign('dashletId', $this->id);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Dashlet, must call process() prior to calling this
|
||||
*
|
||||
* @return string HTML that displays Dashlet
|
||||
*/
|
||||
function display() {
|
||||
return parent::display() . $this->lvs->display(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the $_REQUEST and only save only the needed options
|
||||
* @param array $req the array to pull options from
|
||||
*
|
||||
* @return array options array
|
||||
*/
|
||||
function saveOptions($req) {
|
||||
$options = array();
|
||||
|
||||
$this->loadCustomMetadata();
|
||||
foreach($req as $name => $value) {
|
||||
if(!is_array($value)) $req[$name] = trim($value);
|
||||
}
|
||||
$options['filters'] = array();
|
||||
foreach($this->searchFields as $name=>$params) {
|
||||
$widgetDef = $this->seedBean->field_defs[$name];
|
||||
if($widgetDef['type'] == 'datetimecombo' || $widgetDef['type'] == 'datetime' || $widgetDef['type'] == 'date') { // special case datetime types
|
||||
$options['filters'][$widgetDef['name']] = array();
|
||||
if(!empty($req['type_' . $widgetDef['name']])) { // save the type of date filter
|
||||
$options['filters'][$widgetDef['name']]['type'] = $req['type_' . $widgetDef['name']];
|
||||
}
|
||||
if(!empty($req['date_' . $widgetDef['name']])) { // save the date
|
||||
$options['filters'][$widgetDef['name']]['date'] = $req['date_' . $widgetDef['name']];
|
||||
}
|
||||
}
|
||||
elseif(!empty($req[$widgetDef['name']])) {
|
||||
$options['filters'][$widgetDef['name']] = $req[$widgetDef['name']];
|
||||
}
|
||||
}
|
||||
if(!empty($req['dashletTitle'])) {
|
||||
$options['title'] = $req['dashletTitle'];
|
||||
}
|
||||
|
||||
if(!empty($req['myItemsOnly'])) {
|
||||
$options['myItemsOnly'] = $req['myItemsOnly'];
|
||||
}
|
||||
else {
|
||||
$options['myItemsOnly'] = false;
|
||||
}
|
||||
$options['displayRows'] = empty($req['displayRows']) ? '5' : $req['displayRows'];
|
||||
// displayColumns
|
||||
if(!empty($req['displayColumnsDef'])) {
|
||||
$options['displayColumns'] = explode('|', $req['displayColumnsDef']);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to add custom fields
|
||||
*
|
||||
*/
|
||||
function addCustomFields() {
|
||||
foreach($this->seedBean->field_defs as $fieldName => $def) {
|
||||
if(!empty($def['type']) && $def['type'] == 'html')
|
||||
continue;
|
||||
if(isset($def['vname'])) {
|
||||
$translated = translate($def['vname'], $this->seedBean->module_dir);
|
||||
if(is_array($translated)) $translated = $def['vname'];
|
||||
if(!empty($def['source']) && $def['source'] == 'custom_fields') {
|
||||
if(isset($this->columns[$fieldName]['default']) && $this->columns[$fieldName]['default']){
|
||||
$this->columns[$fieldName] = array('width' => '10',
|
||||
'label' => $translated,
|
||||
'default' => 1);
|
||||
}else{
|
||||
$this->columns[$fieldName] = array('width' => '10',
|
||||
'label' => $translated);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
296
include/Dashlets/DashletGenericChart.php
Executable file
296
include/Dashlets/DashletGenericChart.php
Executable file
@@ -0,0 +1,296 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
require_once('include/Dashlets/Dashlet.php');
|
||||
require_once('include/generic/LayoutManager.php');
|
||||
|
||||
abstract class DashletGenericChart extends Dashlet
|
||||
{
|
||||
/**
|
||||
* The title of the dashlet
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* @see Dashlet::$isConfigurable
|
||||
*/
|
||||
public $isConfigurable = true;
|
||||
|
||||
/**
|
||||
* @see Dashlet::$isRefreshable
|
||||
*/
|
||||
public $isRefreshable = true;
|
||||
|
||||
/**
|
||||
* location of smarty template file for configuring
|
||||
* @var string
|
||||
*/
|
||||
protected $_configureTpl = 'include/Dashlets/DashletGenericChartConfigure.tpl';
|
||||
|
||||
/**
|
||||
* Bean file used in this Dashlet
|
||||
* @var object
|
||||
*/
|
||||
private $_seedBean;
|
||||
|
||||
/**
|
||||
* Module used in this Dashlet
|
||||
* @var string
|
||||
*/
|
||||
protected $_seedName;
|
||||
|
||||
/**
|
||||
* Array of fields and thier defintions that we are searching on
|
||||
* @var array
|
||||
*/
|
||||
protected $_searchFields;
|
||||
|
||||
/**
|
||||
* smarty object for the generic configuration template
|
||||
* @var object
|
||||
*/
|
||||
private $_configureSS;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(
|
||||
$id,
|
||||
array $options = null
|
||||
)
|
||||
{
|
||||
parent::Dashlet($id);
|
||||
|
||||
if ( isset($options) ) {
|
||||
foreach ( $options as $key => $value ) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// load searchfields
|
||||
$classname = get_class($this);
|
||||
if ( is_file("modules/Charts/Dashlets/$classname/$classname.data.php") ) {
|
||||
require("modules/Charts/Dashlets/$classname/$classname.data.php");
|
||||
$this->_searchFields = $dashletData[$classname]['searchFields'];
|
||||
}
|
||||
|
||||
// load language files
|
||||
$this->loadLanguage($classname, 'modules/Charts/Dashlets/');
|
||||
|
||||
if ( empty($options['title']) )
|
||||
$this->title = $this->dashletStrings['LBL_TITLE'];
|
||||
|
||||
$this->layoutManager = new LayoutManager();
|
||||
$this->layoutManager->setAttribute('context', 'Report');
|
||||
// fake a reporter object here just to pass along the db type used in many widgets.
|
||||
// this should be taken out when sugarwidgets change
|
||||
$temp = (object) array('db' => &$GLOBALS['db'], 'report_def_str' => '');
|
||||
$this->layoutManager->setAttributePtr('reporter', $temp);
|
||||
}
|
||||
|
||||
public function setRefreshIcon()
|
||||
{
|
||||
$additionalTitle = '';
|
||||
if($this->isRefreshable)
|
||||
$additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
|
||||
. $this->id . '\',\'predefined_chart\'); return false;"><img border="0" align="absmiddle" title="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" alt="' . translate('LBL_DASHLET_REFRESH', 'Home') . '" src="'
|
||||
. SugarThemeRegistry::current()->getImageURL('dashlet-header-refresh.png').'"/></a>';
|
||||
return $additionalTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the javascript for the dashlet
|
||||
*
|
||||
* @return string javascript to use with this dashlet
|
||||
*/
|
||||
public function displayScript()
|
||||
{
|
||||
global $sugar_config, $current_user, $current_language;
|
||||
|
||||
$xmlFile = $sugar_config['tmp_dir']. $current_user->id . '_' . $this->id . '.xml';
|
||||
$chartStringsXML = $GLOBALS['sugar_config']['tmp_dir'].'chart_strings.' . $current_language .'.lang.xml';
|
||||
|
||||
$ss = new Sugar_Smarty();
|
||||
$ss->assign('chartName', $this->id);
|
||||
$ss->assign('chartXMLFile', $xmlFile);
|
||||
|
||||
$ss->assign('chartStyleCSS', SugarThemeRegistry::current()->getCSSURL('chart.css'));
|
||||
$ss->assign('chartColorsXML', SugarThemeRegistry::current()->getImageURL('sugarColors.xml'));
|
||||
$ss->assign('chartStringsXML', $chartStringsXML);
|
||||
|
||||
$str = $ss->fetch('include/Dashlets/DashletGenericChartScript.tpl');
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the smarty object for the config window. Designed to allow lazy loading the object
|
||||
* when it's needed.
|
||||
*/
|
||||
protected function getConfigureSmartyInstance()
|
||||
{
|
||||
if ( !($this->_configureSS instanceof Sugar_Smarty) ) {
|
||||
|
||||
$this->_configureSS = new Sugar_Smarty();
|
||||
}
|
||||
|
||||
return $this->_configureSS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the chart config options
|
||||
* Filter the $_REQUEST and only save only the needed options
|
||||
*
|
||||
* @param array $req
|
||||
* @return array
|
||||
*/
|
||||
public function saveOptions(
|
||||
$req
|
||||
)
|
||||
{
|
||||
global $timedate;
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach($req as $name => $value)
|
||||
if(!is_array($value)) $req[$name] = trim($value);
|
||||
|
||||
foreach($this->_searchFields as $name => $params) {
|
||||
$widgetDef = $params;
|
||||
if ( isset($this->getSeedBean()->field_defs[$name]) )
|
||||
$widgetDef = $this->getSeedBean()->field_defs[$name];
|
||||
if ( $widgetDef['type'] == 'date') // special case date types
|
||||
$options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
|
||||
elseif ( $widgetDef['type'] == 'time') // special case time types
|
||||
$options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_time_format(), $timedate->dbTimeFormat);
|
||||
elseif ( $widgetDef['type'] == 'datepicker') // special case datepicker types
|
||||
$options[$widgetDef['name']] = $timedate->swap_formats($req[$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
|
||||
elseif (!empty($req[$widgetDef['name']]))
|
||||
$options[$widgetDef['name']] = $req[$widgetDef['name']];
|
||||
}
|
||||
|
||||
if (!empty($req['dashletTitle']))
|
||||
$options['title'] = $req['dashletTitle'];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles displaying the chart dashlet configuration popup window
|
||||
*
|
||||
* @return string HTML to return to the browser
|
||||
*/
|
||||
public function displayOptions()
|
||||
{
|
||||
$currentSearchFields = array();
|
||||
|
||||
if ( is_array($this->_searchFields) ) {
|
||||
foreach($this->_searchFields as $name=>$params) {
|
||||
if(!empty($name)) {
|
||||
$name = strtolower($name);
|
||||
$currentSearchFields[$name] = array();
|
||||
|
||||
$widgetDef = $params;
|
||||
if ( isset($this->getSeedBean()->field_defs[$name]) )
|
||||
$widgetDef = $this->getSeedBean()->field_defs[$name];
|
||||
|
||||
if($widgetDef['type'] == 'enum' || $widgetDef['type'] == 'singleenum') $widgetDef['remove_blank'] = true; // remove the blank option for the dropdown
|
||||
|
||||
if ( empty($widgetDef['input_name0']) )
|
||||
$widgetDef['input_name0'] = empty($this->$name) ? '' : $this->$name;
|
||||
$currentSearchFields[$name]['label'] = translate($widgetDef['vname'], $this->getSeedBean()->module_dir);
|
||||
if ( $currentSearchFields[$name]['label'] == $widgetDef['vname'] )
|
||||
$currentSearchFields[$name]['label'] = translate($widgetDef['vname'], 'Charts');
|
||||
$currentSearchFields[$name]['input'] = $this->layoutManager->widgetDisplayInput($widgetDef, true, (empty($this->$name) ? '' : $this->$name));
|
||||
}
|
||||
else { // ability to create spacers in input fields
|
||||
$currentSearchFields['blank' + $count]['label'] = '';
|
||||
$currentSearchFields['blank' + $count]['input'] = '';
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->currentSearchFields = $currentSearchFields;
|
||||
$this->getConfigureSmartyInstance()->assign('title',translate('LBL_TITLE','Charts'));
|
||||
$this->getConfigureSmartyInstance()->assign('save',$GLOBALS['app_strings']['LBL_SAVE_BUTTON_LABEL']);
|
||||
$this->getConfigureSmartyInstance()->assign('id', $this->id);
|
||||
$this->getConfigureSmartyInstance()->assign('searchFields', $this->currentSearchFields);
|
||||
$this->getConfigureSmartyInstance()->assign('dashletTitle', $this->title);
|
||||
$this->getConfigureSmartyInstance()->assign('dashletType', 'predefined_chart');
|
||||
$this->getConfigureSmartyInstance()->assign('module', $_REQUEST['module']);
|
||||
|
||||
return parent::displayOptions() . $this->getConfigureSmartyInstance()->fetch($this->_configureTpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DashletGenericChart::_seedBean object. Designed to allow lazy loading the object
|
||||
* when it's needed.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function getSeedBean()
|
||||
{
|
||||
if ( !($this->_seedBean instanceof $this->_seedName) )
|
||||
$this->_seedBean = loadBean($this->_seedName);
|
||||
|
||||
return $this->_seedBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the built query read to feed into SugarChart::getData()
|
||||
*
|
||||
* @return string SQL query
|
||||
*/
|
||||
protected function constructQuery()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of group by parameters for SugarChart::$group_by
|
||||
*
|
||||
* @return string SQL query
|
||||
*/
|
||||
protected function constructGroupBy()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user