2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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 ********************************************************************************/
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']) || !in_array($this->type, $GLOBALS['modInvisListActivities']))){
55 $displayDashlet = false;
57 elseif (ACLController::moduleSupportsACL($this->type) && !ACLController::checkAccess($this->type,'list',true)) {
58 $displayDashlet = false;
61 $displayDashlet = true;
64 return $displayDashlet;
67 function addDashlet(){
68 if(!is_file($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php')) {
69 require_once('include/Dashlets/DashletCacheBuilder.php');
71 $dc = new DashletCacheBuilder();
74 require_once($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php');
78 if(isset($_REQUEST['id'])){
79 $pages = $current_user->getPreference('pages', $this->type);
81 $dashlets = $current_user->getPreference('dashlets', $this->type);
83 $guid = create_guid();
85 if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'web') {
86 $dashlet_module = 'Home';
87 $options['url'] = $_REQUEST['type_module'];
88 $fp = @fopen($options['url'],'r');
90 $page = fread($fp,8192);
92 preg_match("/<title>(.*)<\/title>/i",$page,$matches);
93 if ( isset($matches[1]) )
94 $options['title'] = str_replace('<![CDATA[','',str_replace(']]>','',$matches[1]));
98 elseif (isset($_REQUEST['type_module'])) {
99 $dashlet_module = $_REQUEST['type_module'];
101 elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
102 $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
105 $dashlet_module = 'Home';
108 $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'],
109 'module' => $dashlet_module,
110 'options' => $options,
111 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
113 // add to beginning of the array
114 array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
116 //check to see whether the preference is too large to store
117 if($current_user->isPreferenceSizeTooLarge($this->type)){
118 //user preference is too large, do not attempt to store. echo error string and return. This will be processed by mySugar.js
119 echo 'userpref_error';
122 //store preference and echo guid
123 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
132 function displayDashlet(){
133 global $current_user, $mod_strings;
135 if(!empty($_REQUEST['id'])) {
136 $id = $_REQUEST['id'];
137 $dashlets = $current_user->getPreference('dashlets', $this->type);
141 foreach($_REQUEST as $k => $v){
145 else if(preg_match('/Home2_.+_ORDER_BY/', $k)){
149 if(!empty($sortOrder) && !empty($orderBy)){
150 $dashlets[$id]['sort_options'] = array('sortOrder' => $sortOrder, 'orderBy' => $orderBy);
151 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
154 require_once($dashlets[$id]['fileLocation']);
155 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
156 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
157 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
158 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
160 if(!empty($_REQUEST['dynamic']) && $_REQUEST['dynamic'] == 'true' && $dashlet->hasScript) {
161 $dashlet->isConfigurable = false;
162 echo $dashlet->getTitle('') . $mod_strings['LBL_RELOAD_PAGE'];
165 $lvsParams = array();
166 if(!empty($dashlets[$id]['sort_options'])){
167 $lvsParams = $dashlets[$id]['sort_options'];
169 $dashlet->process($lvsParams);
170 $contents = $dashlet->display();
171 // Many dashlets expect to be able to initialize in the display() function, so we have to create the header second
172 echo $dashlet->getHeader();
174 echo $dashlet->getFooter();
178 header("Location: index.php?action=index&module=". $this->type);
182 function getPredefinedChartScript(){
183 global $current_user, $mod_strings;
185 if(!empty($_REQUEST['id'])) {
186 $id = $_REQUEST['id'];
187 $dashlets = $current_user->getPreference('dashlets', $this->type);
189 require_once($dashlets[$id]['fileLocation']);
190 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
192 echo $dashlet->displayScript();
195 header("Location: index.php?action=index&module=". $this->type);
201 function deleteDashlet(){
204 global $current_user;
206 if(!empty($_REQUEST['id'])) {
207 $pages = $current_user->getPreference('pages', $this->type);
208 $dashlets = $current_user->getPreference('dashlets', $this->type);
212 foreach($pages[$activePage]['columns'] as $colNum => $column) {
213 foreach($column['dashlets'] as $num => $dashletId) {
214 if($dashletId == $_REQUEST['id']) {
215 unset($pages[$activePage]['columns'][$colNum]['dashlets'][$num]);
220 foreach($dashlets as $dashletId => $data) {
221 if($dashletId == $_REQUEST['id']) {
222 unset($dashlets[$dashletId]);
226 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
227 $current_user->setPreference('pages', $pages, 0, $this->type);
236 function dashletsDialog(){
237 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
239 global $current_language, $app_strings;
241 $chartsList = array();
242 $DashletsDialog = new DashletsDialog();
244 $DashletsDialog->getDashlets();
245 $allDashlets = $DashletsDialog->dashlets;
247 $dashletsList = $allDashlets['Module Views'];
248 $chartsList = $allDashlets['Charts'];
249 $toolsList = $allDashlets['Tools'];
250 $sugar_smarty = new Sugar_Smarty();
252 $mod_strings = return_module_language($current_language, 'Home');
254 $sugar_smarty->assign('LBL_CLOSE_DASHLETS', $mod_strings['LBL_CLOSE_DASHLETS']);
255 $sugar_smarty->assign('LBL_ADD_DASHLETS', $mod_strings['LBL_ADD_DASHLETS']);
256 $sugar_smarty->assign('APP', $app_strings);
257 $sugar_smarty->assign('moduleName', $this->type);
259 if ($this->type == 'Home'){
260 $sugar_smarty->assign('modules', $dashletsList);
261 $sugar_smarty->assign('tools', $toolsList);
264 $sugar_smarty->assign('charts', $chartsList);
266 $html = $sugar_smarty->fetch('include/MySugar/tpls/addDashletsDialog.tpl');
267 // Bug 34451 - Added hack to make the "Add Dashlet" dialog window not look weird in IE6.
269 if (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie < 7) {
270 document.getElementById('dashletsList').style.width = '430px';
271 document.getElementById('dashletsList').style.overflow = 'hidden';
275 $json = getJSONobj();
276 echo 'response = ' . $json->encode(array('html' => $html, 'script' => $script));
280 function searchModuleToolsDashlets($searchStr, $category){
281 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
285 $DashletsDialog = new DashletsDialog();
289 $DashletsDialog->getDashlets('module');
290 $dashletIndex = 'Module Views';
291 $searchCategoryString = $app_strings['LBL_SEARCH_MODULES'];
294 $DashletsDialog->getDashlets('tools');
295 $dashletIndex = 'Tools';
296 $searchCategoryString = $app_strings['LBL_SEARCH_TOOLS'];
300 $allDashlets = $DashletsDialog->dashlets;
302 $searchResult = array();
303 $searchResult[$dashletIndex] = array();
305 foreach($allDashlets[$dashletIndex] as $dashlet){
306 if (stripos($dashlet['title'], $searchStr) !== false){
307 array_push($searchResult[$dashletIndex], $dashlet);
311 $sugar_smarty = new Sugar_Smarty();
313 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
314 $sugar_smarty->assign('lblSearchCategory', $searchCategoryString);
316 $sugar_smarty->assign('moduleName', $this->type);
317 $sugar_smarty->assign('searchString', $searchStr);
319 $sugar_smarty->assign('dashlets', $searchResult[$dashletIndex]);
321 return $sugar_smarty->fetch('include/MySugar/tpls/dashletsSearchResults.tpl');
324 function searchChartsDashlets($searchStr){
325 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
327 global $current_language, $app_strings;
329 $chartsList = array();
330 $DashletsDialog = new DashletsDialog();
332 $DashletsDialog->getDashlets('charts');
334 $allDashlets = $DashletsDialog->dashlets;
336 foreach($allDashlets as $category=>$dashlets){
337 $searchResult[$category] = array();
338 foreach($dashlets as $dashlet){
339 if (stripos($dashlet['title'], $searchStr) !== false){
340 array_push($searchResult[$category],$dashlet);
345 $sugar_smarty = new Sugar_Smarty();
347 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
348 $sugar_smarty->assign('searchString', $searchStr);
349 $sugar_smarty->assign('charts', $searchResult['Charts']);
351 return $sugar_smarty->fetch('include/MySugar/tpls/chartDashletsSearchResults.tpl');
354 function searchDashlets(){
355 $searchStr = $_REQUEST['search'];
356 $category = $_REQUEST['category'];
358 if ($category == 'module' || $category == 'tools'){
359 $html = $this->searchModuleToolsDashlets($searchStr, $category);
361 else if ($category == 'chart'){
362 $html = $this->searchChartsDashlets($searchStr);
365 $json = getJSONobj();
366 echo 'response = ' . $json->encode(array('html' => $html, 'script' => ''));
369 function configureDashlet(){
370 global $current_user, $app_strings, $mod_strings;
372 if(!empty($_REQUEST['id'])) {
373 $id = $_REQUEST['id'];
374 $dashletDefs = $current_user->getPreference('dashlets', $this->type); // load user's dashlets config
375 $dashletLocation = $dashletDefs[$id]['fileLocation'];
377 require_once($dashletDefs[$id]['fileLocation']);
379 $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
380 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
381 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
382 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
384 else { // display options
385 $json = getJSONobj();
386 return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $app_strings['LBL_OPTIONS'],
387 'body' => $dashlet->displayOptions())));
395 function saveLayout(){
396 global $current_user;
398 if(!empty($_REQUEST['layout'])) {
399 $newColumns = array();
401 $newLayout = explode('|', $_REQUEST['layout']);
403 $pages = $current_user->getPreference('pages', $this->type);
405 $newColumns = $pages[$_REQUEST['selectedPage']]['columns'];
406 foreach($newLayout as $col => $ids) {
407 $newColumns[$col]['dashlets'] = explode(',', $ids);
410 $pages[$_REQUEST['selectedPage']]['columns'] = $newColumns;
411 $current_user->setPreference('pages', $pages, 0, $this->type);