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 ********************************************************************************/
39 require_once('include/Dashlets/Dashlet.php');
42 class JotPadDashlet extends Dashlet {
43 var $savedText; // users's saved text
44 var $height = '200'; // height of the pad
49 * @global string current language
50 * @param guid $id id for the current dashlet (assigned from Home module)
51 * @param array $def options saved for this dashlet
53 function JotPadDashlet($id, $def) {
54 $this->loadLanguage('JotPadDashlet'); // load the language strings here
56 if(!empty($def['savedText'])) // load default text is none is defined
57 $this->savedText = $def['savedText'];
59 $this->savedText = $this->dashletStrings['LBL_DEFAULT_TEXT'];
61 if(!empty($def['height'])) // set a default height if none is set
62 $this->height = $def['height'];
64 parent::Dashlet($id); // call parent constructor
66 $this->isConfigurable = true; // dashlet is configurable
67 $this->hasScript = true; // dashlet has javascript attached to it
69 // if no custom title, use default
70 if(empty($def['title'])) $this->title = $this->dashletStrings['LBL_TITLE'];
71 else $this->title = $def['title'];
75 * Displays the dashlet
77 * @return string html to display dashlet
80 $ss = new Sugar_Smarty();
81 $xss = clean_xss($this->savedText, false);
83 $this->savedText = str_replace($xss, "", $this->savedText);
85 $ss->assign('savedText', $this->savedText);
86 $ss->assign('saving', $this->dashletStrings['LBL_SAVING']);
87 $ss->assign('saved', $this->dashletStrings['LBL_SAVED']);
88 $ss->assign('id', $this->id);
89 $ss->assign('height', $this->height);
91 $str = $ss->fetch('modules/Home/Dashlets/JotPadDashlet/JotPadDashlet.tpl');
92 return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str . '<br />'; // return parent::display for title and such
96 * Displays the javascript for the dashlet
98 * @return string javascript to use with this dashlet
100 function displayScript() {
101 $ss = new Sugar_Smarty();
102 $ss->assign('saving', $this->dashletStrings['LBL_SAVING']);
103 $ss->assign('saved', $this->dashletStrings['LBL_SAVED']);
104 $ss->assign('id', $this->id);
106 $str = $ss->fetch('modules/Home/Dashlets/JotPadDashlet/JotPadDashletScript.tpl');
107 return $str; // return parent::display for title and such
111 * Displays the configuration form for the dashlet
113 * @return string html to display form
115 function displayOptions() {
118 $ss = new Sugar_Smarty();
119 $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']);
120 $ss->assign('heightLbl', $this->dashletStrings['LBL_CONFIGURE_HEIGHT']);
121 $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']);
122 $ss->assign('title', $this->title);
123 $ss->assign('height', $this->height);
124 $ss->assign('id', $this->id);
126 return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/JotPadDashlet/JotPadDashletOptions.tpl');
130 * called to filter out $_REQUEST object when the user submits the configure dropdown
132 * @param array $req $_REQUEST
133 * @return array filtered options to save
135 function saveOptions($req) {
136 global $sugar_config, $timedate, $current_user, $theme;
138 $options['title'] = $_REQUEST['title'];
139 if(is_numeric($_REQUEST['height'])) {
140 if($_REQUEST['height'] > 0 && $_REQUEST['height'] <= 300) $options['height'] = $_REQUEST['height'];
141 elseif($_REQUEST['height'] > 300) $options['height'] = '300';
142 else $options['height'] = '100';
145 // $options['savedText'] = br2nl($this->savedText);
146 $options['savedText'] = $this->savedText;
152 * Used to save text on textarea blur. Accessed via Home/CallMethodDashlet.php
153 * This is an example of how to to call a custom method via ajax
155 function saveText() {
156 $json = getJSONobj();
157 if(isset($_REQUEST['savedText'])) {
158 $optionsArray = $this->loadOptions();
159 // _pp($_REQUEST['savedText']);
160 $optionsArray['savedText']=$json->decode(html_entity_decode($_REQUEST['savedText']));
161 $optionsArray['savedText']=nl2br($optionsArray['savedText']['jsonObject']);
162 $xss = clean_xss($optionsArray['savedText'], false);
164 $optionsArray['savedText'] = str_replace($xss, "", $optionsArray['savedText']);
166 $this->storeOptions($optionsArray);
170 $optionsArray['savedText'] = '';
172 echo 'result = ' . $json->encode(array('id' => $_REQUEST['id'],
173 'savedText' => $optionsArray['savedText']));