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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: Defines the English language pack for the base application.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('include/Dashlets/DashletGeneric.php');
49 class SugarFeedDashlet extends DashletGeneric {
50 var $displayRows = 15;
54 var $selectedCategories = array();
56 function SugarFeedDashlet($id, $def = null) {
57 global $current_user, $app_strings, $app_list_strings;
58 require('modules/SugarFeed/metadata/dashletviewdefs.php');
59 $this->myItemsOnly = false;
60 parent::DashletGeneric($id, $def);
61 $this->myItemsOnly = false;
62 $this->isConfigurable = true;
63 $this->hasScript = true;
64 // Add in some default categories.
65 $this->categories['ALL'] = translate('LBL_ALL','SugarFeed');
66 // Need to get the rest of the active SugarFeed modules
67 $module_list = SugarFeed::getActiveFeedModules();
68 // Translate the category names
69 if ( ! is_array($module_list) ) { $module_list = array(); }
70 foreach ( $module_list as $module ) {
71 if ( $module == 'UserFeed' ) {
72 // Fake module, need to translate specially
73 $this->categories[$module] = translate('LBL_USER_FEED','SugarFeed');
75 $this->categories[$module] = $app_list_strings['moduleList'][$module];
79 if(empty($def['title'])) $this->title = translate('LBL_HOMEPAGE_TITLE', 'SugarFeed');
80 if(!empty($def['rows']))$this->displayRows = $def['rows'];
81 if(!empty($def['categories']))$this->selectedCategories = $def['categories'];
82 $this->searchFields = $dashletData['SugarFeedDashlet']['searchFields'];
83 $this->columns = $dashletData['SugarFeedDashlet']['columns'];
84 $catCount = count($this->categories);
85 ACLController::filterModuleList($this->categories, false);
86 if(count($this->categories) < $catCount){
87 if(!empty($this->selectedCategories)){
88 ACLController::filterModuleList($this->selectedCategories, true);
90 $this->selectedCategories = array_keys($this->categories);
91 unset($this->selectedCategories[0]);
94 $this->seedBean = new SugarFeed();
97 function process($lvsParams = array()) {
100 $currentSearchFields = array();
101 $configureView = true; // configure view or regular view
103 $whereArray = array();
104 $lvsParams['massupdate'] = false;
107 if(isset($this->filters) || $this->myItemsOnly) {
108 $whereArray = $this->buildWhere();
111 $this->lvs->export = false;
112 $this->lvs->multiSelect = false;
113 $this->lvs->quickViewLinks = false;
115 foreach($this->columns as $name => $val) {
116 if(!empty($val['default']) && $val['default']) {
117 $displayColumns[strtoupper($name)] = $val;
118 $displayColumns[strtoupper($name)]['label'] = trim($displayColumns[strtoupper($name)]['label'], ':');
122 $this->lvs->displayColumns = $displayColumns;
124 $this->lvs->lvd->setVariableName($this->seedBean->object_name, array());
126 $lvsParams['overrideOrder'] = true;
127 $lvsParams['orderBy'] = 'date_entered';
128 $lvsParams['sortOrder'] = 'DESC';
130 // Get the real module list
131 if (empty($this->selectedCategories)){
132 $mod_list = $this->categories;
134 $mod_list = array_flip($this->selectedCategories);//27949, here the key of $this->selectedCategories is not module name, the value is module name, so array_flip it.
137 $admin_modules = array();
138 $owner_modules = array();
139 $regular_modules = array();
140 foreach($mod_list as $module => $ignore) {
141 // Handle the UserFeed differently
142 if ( $module == 'UserFeed') {
143 $regular_modules[] = 'UserFeed';
146 if (ACLAction::getUserAccessLevel($current_user->id,$module,'view') <= ACL_ALLOW_NONE ) {
147 // Not enough access to view any records, don't add it to any lists
150 if ( ACLAction::getUserAccessLevel($current_user->id,$module,'view') == ACL_ALLOW_OWNER ) {
151 $owner_modules[] = $module;
153 $regular_modules[] = $module;
157 if(!empty($this->displayTpl))
161 if(!empty($whereArray)){
162 $where = '(' . implode(') AND (', $whereArray) . ')';
165 $module_limiter = " sugarfeed.related_module in ('" . implode("','", $regular_modules) . "')";
167 if ( count($owner_modules) > 0
169 $module_limiter = " ((sugarfeed.related_module IN ('".implode("','", $regular_modules)."') "
171 if ( count($owner_modules) > 0 ) {
172 $module_limiter .= "OR (sugarfeed.related_module IN('".implode("','", $owner_modules)."') AND sugarfeed.assigned_user_id = '".$current_user->id."' "
175 $module_limiter .= ")";
177 if(!empty($where)) { $where .= ' AND '; }
178 $where .= $module_limiter;
180 $this->lvs->setup($this->seedBean, $this->displayTpl, $where , $lvsParams, 0, $this->displayRows,
188 foreach($this->lvs->data['data'] as $row => $data) {
189 $this->lvs->data['data'][$row]['CREATED_BY'] = get_assigned_user_name($data['CREATED_BY']);
190 $this->lvs->data['data'][$row]['NAME'] = str_replace("{this.CREATED_BY}",$this->lvs->data['data'][$row]['CREATED_BY'],$data['NAME']);
193 // assign a baseURL w/ the action set as DisplayDashlet
194 foreach($this->lvs->data['pageData']['urls'] as $type => $url) {
195 // awu Replacing action=DisplayDashlet with action=DynamicAction&DynamicAction=DisplayDashlet
196 if($type == 'orderBy')
197 $this->lvs->data['pageData']['urls'][$type] = preg_replace('/(action=.*&)/Ui', 'action=DynamicAction&DynamicAction=displayDashlet&', $url);
199 $this->lvs->data['pageData']['urls'][$type] = preg_replace('/(action=.*&)/Ui', 'action=DynamicAction&DynamicAction=displayDashlet&', $url) . '&sugar_body_only=1&id=' . $this->id;
202 $this->lvs->ss->assign('dashletId', $this->id);
207 function deleteUserFeed() {
208 if(!empty($_REQUEST['record'])) {
209 $feed = new SugarFeed();
210 $feed->retrieve($_REQUEST['record']);
211 if(is_admin($GLOBALS['current_user']) || $feed->created_by == $GLOBALS['current_user']->id){
212 $feed->mark_deleted($_REQUEST['record']);
217 function pushUserFeed() {
218 if(!empty($_REQUEST['text'])) {
219 $text = htmlspecialchars($_REQUEST['text']);
220 //allow for bold and italic user tags
221 $text = preg_replace('/&lt;(\/*[bi])&gt;/i','<$1>', $text);
222 SugarFeed::pushFeed($text, 'UserFeed', $GLOBALS['current_user']->id,
223 $GLOBALS['current_user']->id,
224 $_REQUEST['link_type'], $_REQUEST['link_url']
229 function displayOptions() {
231 $ss = new Sugar_Smarty();
232 $ss->assign('titleLBL', translate('LBL_TITLE', 'SugarFeed'));
233 $ss->assign('categoriesLBL', translate('LBL_CATEGORIES', 'SugarFeed'));
234 $ss->assign('rowsLBL', translate('LBL_ROWS', 'SugarFeed'));
235 $ss->assign('saveLBL', $app_strings['LBL_SAVE_BUTTON_LABEL']);
236 $ss->assign('title', $this->title);
237 $ss->assign('categories', $this->categories);
238 if ( empty($this->selectedCategories) ) {
239 $this->selectedCategories['ALL'] = 'ALL';
241 $ss->assign('selectedCategories', $this->selectedCategories);
242 $ss->assign('rows', $this->displayRows);
243 $ss->assign('id', $this->id);
245 return $ss->fetch('modules/SugarFeed/Dashlets/SugarFeedDashlet/Options.tpl');
253 function saveOptions($req) {
254 global $sugar_config, $timedate, $current_user, $theme;
256 $options['title'] = $_REQUEST['title'];
257 $rows = intval($_REQUEST['rows']);
264 $options['rows'] = $rows;
265 $options['categories'] = $_REQUEST['categories'];
266 foreach($options['categories'] as $cat){
268 unset($options['categories']);
275 function sugarFeedDisplayScript() {
276 // Forces the quicksearch to reload anytime the dashlet gets refreshed
277 return '<script type="text/javascript">
283 * @return javascript including QuickSearch for SugarFeeds
285 function displayScript() {
286 require_once('include/QuickSearchDefaults.php');
288 $ss = new Sugar_Smarty();
289 $ss->assign('saving', translate('LBL_SAVING', 'SugarFeed'));
290 $ss->assign('saved', translate('LBL_SAVED', 'SugarFeed'));
291 $ss->assign('id', $this->id);
293 $str = $ss->fetch('modules/SugarFeed/Dashlets/SugarFeedDashlet/SugarFeedScript.tpl');
294 return $str; // return parent::display for title and such
299 * @return the fully rendered dashlet
303 $listview = parent::display();
304 $GLOBALS['current_sugarfeed'] = $this;
305 $listview = preg_replace_callback('/\{([^\}]+)\.([^\}]+)\}/', create_function(
307 'if($matches[1] == "this"){$var = $matches[2]; return $GLOBALS[\'current_sugarfeed\']->$var;}else{return translate($matches[2], $matches[1]);}'
309 $listview = preg_replace('/\[(\w+)\:([\w\-\d]*)\:([^\]]*)\]/', '<a href="index.php?module=$1&action=DetailView&record=$2"><img src="themes/default/images/$1.gif" border=0>$3</a>', $listview);
311 return $listview.'</div>';
317 * @return the title and the user post form
318 * @param $text Object
320 function getHeader($text='') {
321 return parent::getHeader($text) . $this->getPostForm().$this->getDisabledWarning().$this->sugarFeedDisplayScript().'<div class="sugarFeedDashlet">';
327 * @return a warning message if the sugar feed system is not enabled currently
329 function getDisabledWarning(){
330 /* Check to see if the sugar feed system is enabled */
331 if ( ! $this->shouldDisplay() ) {
332 // The Sugar Feeds are disabled, populate the warning message
333 return translate('LBL_DASHLET_DISABLED','SugarFeed');
341 * @return the form for users posting custom messages to the feed stream
343 function getPostForm(){
344 global $current_user;
346 if ( empty($this->categories['UserFeed']) ) {
347 // The user feed system isn't enabled, don't let them post notes
350 $user_name = ucfirst($GLOBALS['current_user']->user_name);
351 $moreimg = SugarThemeRegistry::current()->getImage('advanced_search' , 'onclick="toggleDisplay(\'more_' . $this->id . '\'); toggleDisplay(\'more_img_'.$this->id.'\'); toggleDisplay(\'less_img_'.$this->id.'\');"');
352 $lessimg = SugarThemeRegistry::current()->getImage('basic_search' , 'onclick="toggleDisplay(\'more_' . $this->id . '\'); toggleDisplay(\'more_img_'.$this->id.'\'); toggleDisplay(\'less_img_'.$this->id.'\');"');
353 $ss = new Sugar_Smarty();
354 $ss->assign('LBL_TO', translate('LBL_TO', 'SugarFeed'));
355 $ss->assign('LBL_POST', translate('LBL_POST', 'SugarFeed'));
356 $ss->assign('LBL_SELECT', translate('LBL_SELECT', 'SugarFeed'));
357 $ss->assign('LBL_IS', translate('LBL_IS', 'SugarFeed'));
358 $ss->assign('id', $this->id);
359 $ss->assign('more_img', $moreimg);
360 $ss->assign('less_img', $lessimg);
361 if($current_user->getPreference('use_real_names') == 'on'){
362 $ss->assign('user_name', $current_user->full_name);
365 $ss->assign('user_name', $user_name);
367 $linkTypesIn = SugarFeed::getLinkTypes();
368 $linkTypes = array();
369 foreach ( $linkTypesIn as $key => $value ) {
370 $linkTypes[$key] = translate('LBL_LINK_TYPE_'.$value,'SugarFeed');
372 $ss->assign('link_types', $linkTypes);
373 return $ss->fetch('modules/SugarFeed/Dashlets/SugarFeedDashlet/UserPostForm.tpl');
377 // This is called from the include/MySugar/DashletsDialog/DashletsDialog.php and determines if we should display the SugarFeed dashlet as an option or not
378 static function shouldDisplay() {
380 $admin = new Administration();
381 $admin->retrieveSettings();
383 if ( !isset($admin->settings['sugarfeed_enabled']) || $admin->settings['sugarfeed_enabled'] != '1' ) {