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']))){
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($GLOBALS['sugar_config']['cache_dir'].'dashlets/dashlets.php')) {
73 require_once('include/Dashlets/DashletCacheBuilder.php');
75 $dc = new DashletCacheBuilder();
78 require_once($GLOBALS['sugar_config']['cache_dir'].'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 $options['url'] = $_REQUEST['type_module'];
92 $fp = @fopen($options['url'],'r');
94 $page = fread($fp,8192);
96 preg_match("/<title>(.*)<\/title>/i",$page,$matches);
97 if ( isset($matches[1]) )
98 $options['title'] = str_replace('<![CDATA[','',str_replace(']]>','',$matches[1]));
102 elseif (!empty($_REQUEST['type_module'])) {
103 $dashlet_module = $_REQUEST['type_module'];
105 elseif (isset($dashletsFiles[$_REQUEST['id']]['module'])) {
106 $dashlet_module = $dashletsFiles[$_REQUEST['id']]['module'];
109 $dashlet_module = 'Home';
112 $dashlets[$guid] = array('className' => $dashletsFiles[$_REQUEST['id']]['class'],
113 'module' => $dashlet_module,
114 'options' => $options,
115 'fileLocation' => $dashletsFiles[$_REQUEST['id']]['file']);
117 // add to beginning of the array
118 array_unshift($pages[$_REQUEST['activeTab']]['columns'][0]['dashlets'], $guid);
120 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
129 function displayDashlet(){
130 global $current_user, $mod_strings;
132 if(!empty($_REQUEST['id'])) {
133 $id = $_REQUEST['id'];
134 $dashlets = $current_user->getPreference('dashlets', $this->type);
138 foreach($_REQUEST as $k => $v){
142 else if(preg_match('/Home2_.+_ORDER_BY/', $k)){
146 if(!empty($sortOrder) && !empty($orderBy)){
147 $dashlets[$id]['sort_options'] = array('sortOrder' => $sortOrder, 'orderBy' => $orderBy);
148 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
151 require_once($dashlets[$id]['fileLocation']);
152 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
153 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
154 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
155 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
157 if(!empty($_REQUEST['dynamic']) && $_REQUEST['dynamic'] == 'true' && $dashlet->hasScript) {
158 $dashlet->isConfigurable = false;
159 echo $dashlet->getTitle('') . $mod_strings['LBL_RELOAD_PAGE'];
162 $lvsParams = array();
163 if(!empty($dashlets[$id]['sort_options'])){
164 $lvsParams = $dashlets[$id]['sort_options'];
166 $dashlet->process($lvsParams);
167 $contents = $dashlet->display();
168 // Many dashlets expect to be able to initialize in the display() function, so we have to create the header second
169 echo $dashlet->getHeader();
171 echo $dashlet->getFooter();
175 header("Location: index.php?action=index&module=". $this->type);
179 function getPredefinedChartScript(){
180 global $current_user, $mod_strings;
182 if(!empty($_REQUEST['id'])) {
183 $id = $_REQUEST['id'];
184 $dashlets = $current_user->getPreference('dashlets', $this->type);
186 require_once($dashlets[$id]['fileLocation']);
187 $dashlet = new $dashlets[$id]['className']($id, (isset($dashlets[$id]['options']) ? $dashlets[$id]['options'] : array()));
189 echo $dashlet->displayScript();
192 header("Location: index.php?action=index&module=". $this->type);
198 function deleteDashlet(){
201 global $current_user;
203 if(!empty($_REQUEST['id'])) {
204 $pages = $current_user->getPreference('pages', $this->type);
205 $dashlets = $current_user->getPreference('dashlets', $this->type);
209 foreach($pages[$activePage]['columns'] as $colNum => $column) {
210 foreach($column['dashlets'] as $num => $dashletId) {
211 if($dashletId == $_REQUEST['id']) {
212 unset($pages[$activePage]['columns'][$colNum]['dashlets'][$num]);
217 foreach($dashlets as $dashletId => $data) {
218 if($dashletId == $_REQUEST['id']) {
219 unset($dashlets[$dashletId]);
223 $current_user->setPreference('dashlets', $dashlets, 0, $this->type);
224 $current_user->setPreference('pages', $pages, 0, $this->type);
233 function dashletsDialog(){
234 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
236 global $current_language, $app_strings;
238 $chartsList = array();
239 $DashletsDialog = new DashletsDialog();
241 $DashletsDialog->getDashlets();
242 $allDashlets = $DashletsDialog->dashlets;
244 $dashletsList = $allDashlets['Module Views'];
245 $chartsList = $allDashlets['Charts'];
246 $toolsList = $allDashlets['Tools'];
247 $sugar_smarty = new Sugar_Smarty();
249 $mod_strings = return_module_language($current_language, 'Home');
251 $sugar_smarty->assign('LBL_CLOSE_DASHLETS', $mod_strings['LBL_CLOSE_DASHLETS']);
252 $sugar_smarty->assign('LBL_ADD_DASHLETS', $mod_strings['LBL_ADD_DASHLETS']);
253 $sugar_smarty->assign('APP', $app_strings);
254 $sugar_smarty->assign('moduleName', $this->type);
256 if ($this->type == 'Home'){
257 $sugar_smarty->assign('modules', $dashletsList);
258 $sugar_smarty->assign('tools', $toolsList);
261 $sugar_smarty->assign('charts', $chartsList);
263 $html = $sugar_smarty->fetch('include/MySugar/tpls/addDashletsDialog.tpl');
264 // Bug 34451 - Added hack to make the "Add Dashlet" dialog window not look weird in IE6.
266 if (YAHOO.env.ua.ie > 5 && YAHOO.env.ua.ie < 7) {
267 document.getElementById('dashletsList').style.width = '430px';
268 document.getElementById('dashletsList').style.overflow = 'hidden';
272 $json = getJSONobj();
273 echo 'response = ' . $json->encode(array('html' => $html, 'script' => $script));
277 function searchModuleToolsDashlets($searchStr, $category){
278 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
282 $DashletsDialog = new DashletsDialog();
286 $DashletsDialog->getDashlets('module');
287 $dashletIndex = 'Module Views';
288 $searchCategoryString = $app_strings['LBL_SEARCH_MODULES'];
291 $DashletsDialog->getDashlets('tools');
292 $dashletIndex = 'Tools';
293 $searchCategoryString = $app_strings['LBL_SEARCH_TOOLS'];
297 $allDashlets = $DashletsDialog->dashlets;
299 $searchResult = array();
300 $searchResult[$dashletIndex] = array();
302 foreach($allDashlets[$dashletIndex] as $dashlet){
303 if (stripos($dashlet['title'], $searchStr) !== false){
304 array_push($searchResult[$dashletIndex], $dashlet);
308 $sugar_smarty = new Sugar_Smarty();
310 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
311 $sugar_smarty->assign('lblSearchCategory', $searchCategoryString);
313 $sugar_smarty->assign('moduleName', $this->type);
314 $sugar_smarty->assign('searchString', $searchStr);
316 $sugar_smarty->assign('dashlets', $searchResult[$dashletIndex]);
318 return $sugar_smarty->fetch('include/MySugar/tpls/dashletsSearchResults.tpl');
321 function searchChartsDashlets($searchStr){
322 require_once('include/MySugar/DashletsDialog/DashletsDialog.php');
324 global $current_language, $app_strings;
326 $chartsList = array();
327 $DashletsDialog = new DashletsDialog();
329 $DashletsDialog->getDashlets('charts');
331 $allDashlets = $DashletsDialog->dashlets;
333 foreach($allDashlets as $category=>$dashlets){
334 $searchResult[$category] = array();
335 foreach($dashlets as $dashlet){
336 if (stripos($dashlet['title'], $searchStr) !== false){
337 array_push($searchResult[$category],$dashlet);
342 $sugar_smarty = new Sugar_Smarty();
344 $sugar_smarty->assign('lblSearchResults', $app_strings['LBL_SEARCH_RESULTS']);
345 $sugar_smarty->assign('searchString', $searchStr);
346 $sugar_smarty->assign('charts', $searchResult['Charts']);
348 return $sugar_smarty->fetch('include/MySugar/tpls/chartDashletsSearchResults.tpl');
351 function searchDashlets(){
352 $searchStr = $_REQUEST['search'];
353 $category = $_REQUEST['category'];
355 if ($category == 'module' || $category == 'tools'){
356 $html = $this->searchModuleToolsDashlets($searchStr, $category);
358 else if ($category == 'chart'){
359 $html = $this->searchChartsDashlets($searchStr);
362 $json = getJSONobj();
363 echo 'response = ' . $json->encode(array('html' => $html, 'script' => ''));
366 function configureDashlet(){
367 global $current_user, $app_strings, $mod_strings;
369 if(!empty($_REQUEST['id'])) {
370 $id = $_REQUEST['id'];
371 $dashletDefs = $current_user->getPreference('dashlets', $this->type); // load user's dashlets config
372 $dashletLocation = $dashletDefs[$id]['fileLocation'];
374 require_once($dashletDefs[$id]['fileLocation']);
376 $dashlet = new $dashletDefs[$id]['className']($id, (isset($dashletDefs[$id]['options']) ? $dashletDefs[$id]['options'] : array()));
377 if(!empty($_REQUEST['configure']) && $_REQUEST['configure']) { // save settings
378 $dashletDefs[$id]['options'] = $dashlet->saveOptions($_REQUEST);
379 $current_user->setPreference('dashlets', $dashletDefs, 0, $this->type);
381 else { // display options
382 $json = getJSONobj();
383 return 'result = ' . $json->encode((array('header' => $dashlet->title . ' : ' . $app_strings['LBL_OPTIONS'],
384 'body' => $dashlet->displayOptions())));
392 function saveLayout(){
393 global $current_user;
395 if(!empty($_REQUEST['layout'])) {
396 $newColumns = array();
398 $newLayout = explode('|', $_REQUEST['layout']);
400 $pages = $current_user->getPreference('pages', $this->type);
402 $newColumns = $pages[$_REQUEST['selectedPage']]['columns'];
403 foreach($newLayout as $col => $ids) {
404 $newColumns[$col]['dashlets'] = explode(',', $ids);
407 $pages[$_REQUEST['selectedPage']]['columns'] = $newColumns;
408 $current_user->setPreference('pages', $pages, 0, $this->type);