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 ********************************************************************************/
40 * Homepage dashlet manager
46 function MySugar($type){
50 function checkDashletDisplay () {
52 if((!in_array($this->type, $GLOBALS['moduleList'])
53 && !in_array($this->type, $GLOBALS['modInvisList']))
54 && (!in_array('Activities', $GLOBALS['moduleList']))){
55 $displayDashlet = false;
57 elseif (ACLController::moduleSupportsACL($this->type) ) {
58 $bean = SugarModule::get($this->type)->loadBean();
59 if ( !ACLController::checkAccess($this->type,'list',true,$bean->acltype)) {
60 $displayDashlet = false;
62 $displayDashlet = true;
65 $displayDashlet = true;
68 return $displayDashlet;
71 function addDashlet(){
72 if(!is_file(sugar_cached('dashlets/dashlets.php'))) {
73 require_once('include/Dashlets/DashletCacheBuilder.php');
75 $dc = new DashletCacheBuilder();
78 require_once sugar_cached('dashlets/dashlets.php');
82 if(isset($_REQUEST['id'])){
83 $pages = $current_user->getPreference('pages', $this->type);
85 $dashlets = $current_user->getPreference('dashlets', $this->type);
87 $guid = create_guid();
89 if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'web') {
90 $dashlet_module = 'Home';
91 require_once('include/Dashlets/DashletRssFeedTitle.php');
92 $options['url'] = $_REQUEST['type_module'];
93 $webDashlet = new DashletRssFeedTitle($options['url']);
94 $options['title'] = $webDashlet->generateTitle();
97 elseif (!empty($_REQUEST['type_module'])) {
98 $dashlet_module = $_REQUEST['type_module'];
100 elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
101 $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
104 $dashlet_module = 'Home';
107 $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'],
108 'module' => $dashlet_module,
109 'options' => $options,
110 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
112 // add to beginning of the array
113 array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
115 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
124 function displayDashlet(){
125 global $current_user, $mod_strings;
127 if(!empty($_REQUEST['id'])) {
128 $id = $_REQUEST['id'];
129 $dashlets = $current_user->getPreference('dashlets', $this->type);
133 foreach($_REQUEST as $k => $v){
137 else if(preg_match('/Home2_.+_ORDER_BY/', $k)){
141 if(!empty($sortOrder) && !empty($orderBy)){
142 $dashlets[$id]['sort_options'] = array('sortOrder' => $sortOrder, 'orderBy' => $orderBy);
143 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
146 require_once($dashlets[$id]['fileLocation']);
147 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
148 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
149 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
150 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
152 if(!empty($_REQUEST['dynamic']) && $_REQUEST['dynamic'] == 'true' && $dashlet->hasScript) {
153 $dashlet->isConfigurable = false;
154 echo $dashlet->getTitle('') . $mod_strings['LBL_RELOAD_PAGE'];
157 $lvsParams = array();
158 if(!empty($dashlets[$id]['sort_options'])){
159 $lvsParams = $dashlets[$id]['sort_options'];
161 $dashlet->process($lvsParams);
162 $contents = $dashlet->display();
163 // Many dashlets expect to be able to initialize in the display() function, so we have to create the header second
164 echo $dashlet->getHeader();
166 echo $dashlet->getFooter();
170 header("Location: index.php?action=index&module=". $this->type);
174 function getPredefinedChartScript(){
175 global $current_user, $mod_strings;
177 if(!empty($_REQUEST['id'])) {
178 $id = $_REQUEST['id'];
179 $dashlets = $current_user->getPreference('dashlets', $this->type);
181 require_once($dashlets[$id]['fileLocation']);
182 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
184 echo $dashlet->displayScript();
187 header("Location: index.php?action=index&module=". $this->type);
193 function deleteDashlet(){
196 global $current_user;
198 if(!empty($_REQUEST['id'])) {
199 $pages = $current_user->getPreference('pages', $this->type);
200 $dashlets = $current_user->getPreference('dashlets', $this->type);
204 foreach($pages[$activePage]['columns'] as $colNum => $column) {
205 foreach($column['dashlets'] as $num => $dashletId) {
206 if($dashletId == $_REQUEST['id']) {
207 unset($pages[$activePage]['columns'][$colNum]['dashlets'][$num]);
212 foreach($dashlets as $dashletId => $data) {
213 if($dashletId == $_REQUEST['id']) {
214 unset($dashlets[$dashletId]);
218 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
219 $current_user->setPreference('pages', $pages, 0, $this->type);
228 function dashletsDialog(){
229 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
231 global $current_language, $app_strings;
233 $chartsList = array();
234 $DashletsDialog = new DashletsDialog();
236 $DashletsDialog->getDashlets();
237 $allDashlets = $DashletsDialog->dashlets;
239 $dashletsList = $allDashlets['Module Views'];
240 $chartsList = $allDashlets['Charts'];
241 $toolsList = $allDashlets['Tools'];
242 $sugar_smarty = new Sugar_Smarty();
244 $mod_strings = return_module_language($current_language, 'Home');
246 $sugar_smarty->assign('LBL_CLOSE_DASHLETS', $mod_strings['LBL_CLOSE_DASHLETS']);
247 $sugar_smarty->assign('LBL_ADD_DASHLETS', $mod_strings['LBL_ADD_DASHLETS']);
248 $sugar_smarty->assign('APP', $app_strings);
249 $sugar_smarty->assign('moduleName', $this->type);
251 if ($this->type == 'Home'){
252 $sugar_smarty->assign('modules', $dashletsList);
253 $sugar_smarty->assign('tools', $toolsList);
256 $sugar_smarty->assign('charts', $chartsList);
258 $html = $sugar_smarty->fetch('include/MySugar/tpls/addDashletsDialog.tpl');
259 // Bug 34451 - Added hack to make the "Add Dashlet" dialog window not look weird in IE6.
261 if (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie < 7) {
262 document.getElementById('dashletsList').style.width = '430px';
263 document.getElementById('dashletsList').style.overflow = 'hidden';
267 $json = getJSONobj();
268 echo 'response = ' . $json->encode(array('html' => $html, 'script' => $script));
272 function searchModuleToolsDashlets($searchStr, $category){
273 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
277 $DashletsDialog = new DashletsDialog();
281 $DashletsDialog->getDashlets('module');
282 $dashletIndex = 'Module Views';
283 $searchCategoryString = $app_strings['LBL_SEARCH_MODULES'];
286 $DashletsDialog->getDashlets('tools');
287 $dashletIndex = 'Tools';
288 $searchCategoryString = $app_strings['LBL_SEARCH_TOOLS'];
292 $allDashlets = $DashletsDialog->dashlets;
294 $searchResult = array();
295 $searchResult[$dashletIndex] = array();
297 foreach($allDashlets[$dashletIndex] as $dashlet){
298 if (stripos($dashlet['title'], $searchStr) !== false){
299 array_push($searchResult[$dashletIndex], $dashlet);
303 $sugar_smarty = new Sugar_Smarty();
305 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
306 $sugar_smarty->assign('lblSearchCategory', $searchCategoryString);
308 $sugar_smarty->assign('moduleName', $this->type);
309 $sugar_smarty->assign('searchString', $searchStr);
311 $sugar_smarty->assign('dashlets', $searchResult[$dashletIndex]);
313 return $sugar_smarty->fetch('include/MySugar/tpls/dashletsSearchResults.tpl');
316 function searchChartsDashlets($searchStr){
317 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
319 global $current_language, $app_strings;
321 $chartsList = array();
322 $DashletsDialog = new DashletsDialog();
324 $DashletsDialog->getDashlets('charts');
326 $allDashlets = $DashletsDialog->dashlets;
328 foreach($allDashlets as $category=>$dashlets){
329 $searchResult[$category] = array();
330 foreach($dashlets as $dashlet){
331 if (stripos($dashlet['title'], $searchStr) !== false){
332 array_push($searchResult[$category],$dashlet);
337 $sugar_smarty = new Sugar_Smarty();
339 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
340 $sugar_smarty->assign('searchString', $searchStr);
341 $sugar_smarty->assign('charts', $searchResult['Charts']);
343 return $sugar_smarty->fetch('include/MySugar/tpls/chartDashletsSearchResults.tpl');
346 function searchDashlets(){
347 $searchStr = $_REQUEST['search'];
348 $category = $_REQUEST['category'];
350 if ($category == 'module' || $category == 'tools'){
351 $html = $this->searchModuleToolsDashlets($searchStr, $category);
353 else if ($category == 'chart'){
354 $html = $this->searchChartsDashlets($searchStr);
357 $json = getJSONobj();
358 echo 'response = ' . $json->encode(array('html' => $html, 'script' => ''));
361 function configureDashlet(){
362 global $current_user, $app_strings, $mod_strings;
364 if(!empty($_REQUEST['id'])) {
365 $id = $_REQUEST['id'];
366 $dashletDefs = $current_user->getPreference('dashlets', $this->type); // load user's dashlets config
367 $dashletLocation = $dashletDefs[$id]['fileLocation'];
369 require_once($dashletDefs[$id]['fileLocation']);
371 $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
372 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
373 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
374 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
376 else { // display options
377 $json = getJSONobj();
378 return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $app_strings['LBL_OPTIONS'],
379 'body' => $dashlet->displayOptions())));
387 function saveLayout(){
388 global $current_user;
390 if(!empty($_REQUEST['layout'])) {
391 $newColumns = array();
393 $newLayout = explode('|', $_REQUEST['layout']);
395 $pages = $current_user->getPreference('pages', $this->type);
397 $newColumns = $pages[$_REQUEST['selectedPage']]['columns'];
398 foreach($newLayout as $col => $ids) {
399 $newColumns[$col]['dashlets'] = explode(',', $ids);
402 $pages[$_REQUEST['selectedPage']]['columns'] = $newColumns;
403 $current_user->setPreference('pages', $pages, 0, $this->type);