2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
43 function MySugar($type){
47 function checkDashletDisplay () {
49 if((!in_array($this->type, $GLOBALS['moduleList'])
50 && !in_array($this->type, $GLOBALS['modInvisList']))
51 && (!in_array('Activities', $GLOBALS['moduleList']))){
52 $displayDashlet = false;
54 elseif (ACLController::moduleSupportsACL($this->type) ) {
55 $bean = SugarModule::get($this->type)->loadBean();
56 if ( !ACLController::checkAccess($this->type,'list',true,$bean->acltype)) {
57 $displayDashlet = false;
59 $displayDashlet = true;
62 $displayDashlet = true;
65 return $displayDashlet;
68 function addDashlet(){
69 if(!is_file(sugar_cached('dashlets/dashlets.php'))) {
70 require_once('include/Dashlets/DashletCacheBuilder.php');
72 $dc = new DashletCacheBuilder();
75 require_once sugar_cached('dashlets/dashlets.php');
79 if(isset($_REQUEST['id'])){
80 $pages = $current_user->getPreference('pages', $this->type);
82 $dashlets = $current_user->getPreference('dashlets', $this->type);
84 $guid = create_guid();
86 if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'web') {
87 $dashlet_module = 'Home';
88 require_once('include/Dashlets/DashletRssFeedTitle.php');
89 $options['url'] = $_REQUEST['type_module'];
90 $webDashlet = new DashletRssFeedTitle($options['url']);
91 $options['title'] = $webDashlet->generateTitle();
94 elseif (!empty($_REQUEST['type_module'])) {
95 $dashlet_module = $_REQUEST['type_module'];
97 elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
98 $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
101 $dashlet_module = 'Home';
104 $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'],
105 'module' => $dashlet_module,
106 'options' => $options,
107 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
109 // add to beginning of the array
110 array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
112 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
121 function displayDashlet(){
122 global $current_user, $mod_strings;
124 if(!empty($_REQUEST['id'])) {
125 $id = $_REQUEST['id'];
126 $dashlets = $current_user->getPreference('dashlets', $this->type);
130 foreach($_REQUEST as $k => $v){
134 else if(preg_match('/Home2_.+_ORDER_BY/', $k)){
138 if(!empty($sortOrder) && !empty($orderBy)){
139 $dashlets[$id]['sort_options'] = array('sortOrder' => $sortOrder, 'orderBy' => $orderBy);
140 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
143 require_once($dashlets[$id]['fileLocation']);
144 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
145 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
146 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
147 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
149 if(!empty($_REQUEST['dynamic']) && $_REQUEST['dynamic'] == 'true' && $dashlet->hasScript) {
150 $dashlet->isConfigurable = false;
151 echo $dashlet->getTitle('') . $mod_strings['LBL_RELOAD_PAGE'];
154 $lvsParams = array();
155 if(!empty($dashlets[$id]['sort_options'])){
156 $lvsParams = $dashlets[$id]['sort_options'];
158 $dashlet->process($lvsParams);
159 $contents = $dashlet->display();
160 // Many dashlets expect to be able to initialize in the display() function, so we have to create the header second
161 echo $dashlet->getHeader();
163 echo $dashlet->getFooter();
167 header("Location: index.php?action=index&module=". $this->type);
171 function getPredefinedChartScript(){
172 global $current_user, $mod_strings;
174 if(!empty($_REQUEST['id'])) {
175 $id = $_REQUEST['id'];
176 $dashlets = $current_user->getPreference('dashlets', $this->type);
178 require_once($dashlets[$id]['fileLocation']);
179 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
181 echo $dashlet->displayScript();
184 header("Location: index.php?action=index&module=". $this->type);
190 function deleteDashlet(){
193 global $current_user;
195 if(!empty($_REQUEST['id'])) {
196 $pages = $current_user->getPreference('pages', $this->type);
197 $dashlets = $current_user->getPreference('dashlets', $this->type);
201 foreach($pages[$activePage]['columns'] as $colNum => $column) {
202 foreach($column['dashlets'] as $num => $dashletId) {
203 if($dashletId == $_REQUEST['id']) {
204 unset($pages[$activePage]['columns'][$colNum]['dashlets'][$num]);
209 foreach($dashlets as $dashletId => $data) {
210 if($dashletId == $_REQUEST['id']) {
211 unset($dashlets[$dashletId]);
215 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
216 $current_user->setPreference('pages', $pages, 0, $this->type);
225 function dashletsDialog(){
226 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
228 global $current_language, $app_strings;
230 $chartsList = array();
231 $DashletsDialog = new DashletsDialog();
233 $DashletsDialog->getDashlets();
234 $allDashlets = $DashletsDialog->dashlets;
236 $dashletsList = $allDashlets['Module Views'];
237 $chartsList = $allDashlets['Charts'];
238 $toolsList = $allDashlets['Tools'];
239 $sugar_smarty = new Sugar_Smarty();
241 $mod_strings = return_module_language($current_language, 'Home');
243 $sugar_smarty->assign('LBL_CLOSE_DASHLETS', $mod_strings['LBL_CLOSE_DASHLETS']);
244 $sugar_smarty->assign('LBL_ADD_DASHLETS', $mod_strings['LBL_ADD_DASHLETS']);
245 $sugar_smarty->assign('APP', $app_strings);
246 $sugar_smarty->assign('moduleName', $this->type);
248 if ($this->type == 'Home'){
249 $sugar_smarty->assign('modules', $dashletsList);
250 $sugar_smarty->assign('tools', $toolsList);
253 $sugar_smarty->assign('charts', $chartsList);
255 $html = $sugar_smarty->fetch('include/MySugar/tpls/addDashletsDialog.tpl');
256 // Bug 34451 - Added hack to make the "Add Dashlet" dialog window not look weird in IE6.
258 if (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie < 7) {
259 document.getElementById('dashletsList').style.width = '430px';
260 document.getElementById('dashletsList').style.overflow = 'hidden';
264 $json = getJSONobj();
265 echo 'response = ' . $json->encode(array('html' => $html, 'script' => $script));
269 function searchModuleToolsDashlets($searchStr, $category){
270 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
274 $DashletsDialog = new DashletsDialog();
278 $DashletsDialog->getDashlets('module');
279 $dashletIndex = 'Module Views';
280 $searchCategoryString = $app_strings['LBL_SEARCH_MODULES'];
283 $DashletsDialog->getDashlets('tools');
284 $dashletIndex = 'Tools';
285 $searchCategoryString = $app_strings['LBL_SEARCH_TOOLS'];
289 $allDashlets = $DashletsDialog->dashlets;
291 $searchResult = array();
292 $searchResult[$dashletIndex] = array();
294 foreach($allDashlets[$dashletIndex] as $dashlet){
295 if (stripos($dashlet['title'], $searchStr) !== false){
296 array_push($searchResult[$dashletIndex], $dashlet);
300 $sugar_smarty = new Sugar_Smarty();
302 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
303 $sugar_smarty->assign('lblSearchCategory', $searchCategoryString);
305 $sugar_smarty->assign('moduleName', $this->type);
306 $sugar_smarty->assign('searchString', $searchStr);
308 $sugar_smarty->assign('dashlets', $searchResult[$dashletIndex]);
310 return $sugar_smarty->fetch('include/MySugar/tpls/dashletsSearchResults.tpl');
313 function searchChartsDashlets($searchStr){
314 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
316 global $current_language, $app_strings;
318 $chartsList = array();
319 $DashletsDialog = new DashletsDialog();
321 $DashletsDialog->getDashlets('charts');
323 $allDashlets = $DashletsDialog->dashlets;
325 foreach($allDashlets as $category=>$dashlets){
326 $searchResult[$category] = array();
327 foreach($dashlets as $dashlet){
328 if (stripos($dashlet['title'], $searchStr) !== false){
329 array_push($searchResult[$category],$dashlet);
334 $sugar_smarty = new Sugar_Smarty();
336 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
337 $sugar_smarty->assign('searchString', $searchStr);
338 $sugar_smarty->assign('charts', $searchResult['Charts']);
340 return $sugar_smarty->fetch('include/MySugar/tpls/chartDashletsSearchResults.tpl');
343 function searchDashlets(){
344 $searchStr = $_REQUEST['search'];
345 $category = $_REQUEST['category'];
347 if ($category == 'module' || $category == 'tools'){
348 $html = $this->searchModuleToolsDashlets($searchStr, $category);
350 else if ($category == 'chart'){
351 $html = $this->searchChartsDashlets($searchStr);
354 $json = getJSONobj();
355 echo 'response = ' . $json->encode(array('html' => $html, 'script' => ''));
358 function configureDashlet(){
359 global $current_user, $app_strings, $mod_strings;
361 if(!empty($_REQUEST['id'])) {
362 $id = $_REQUEST['id'];
363 $dashletDefs = $current_user->getPreference('dashlets', $this->type); // load user's dashlets config
364 $dashletLocation = $dashletDefs[$id]['fileLocation'];
366 require_once($dashletDefs[$id]['fileLocation']);
368 $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
369 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
370 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
371 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
373 else { // display options
374 $json = getJSONobj();
375 return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $app_strings['LBL_OPTIONS'],
376 'body' => $dashlet->displayOptions())));
384 function saveLayout(){
385 global $current_user;
387 if(!empty($_REQUEST['layout'])) {
388 $newColumns = array();
390 $newLayout = explode('|', $_REQUEST['layout']);
392 $pages = $current_user->getPreference('pages', $this->type);
394 $newColumns = $pages[$_REQUEST['selectedPage']]['columns'];
395 foreach($newLayout as $col => $ids) {
396 $newColumns[$col]['dashlets'] = explode(',', $ids);
399 $pages[$_REQUEST['selectedPage']]['columns'] = $newColumns;
400 $current_user->setPreference('pages', $pages, 0, $this->type);