]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Home/Dashlets/InvadersDashlet/InvadersDashlet.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Home / Dashlets / InvadersDashlet / InvadersDashlet.php
1 <?php
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-2012 SugarCRM Inc.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38
39 require_once('include/Dashlets/Dashlet.php');
40
41
42 class InvadersDashlet extends Dashlet {
43     var $savedText; // users's saved text
44     var $height = '100'; // height of the pad
45
46     /**
47      * Constructor
48      *
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
52      */
53     function InvadersDashlet($id, $def) {
54         $this->loadLanguage('InvadersDashlet'); // load the language strings here
55
56         if(!empty($def['height'])) // set a default height if none is set
57             $this->height = $def['height'];
58
59         parent::Dashlet($id); // call parent constructor
60
61         $this->isConfigurable = false; // dashlet is configurable
62         $this->hasScript = true;  // dashlet has javascript attached to it
63
64         // if no custom title, use default
65         if(empty($def['title'])) $this->title = $this->dashletStrings['LBL_TITLE'];
66         else $this->title = $def['title'];
67     }
68
69     /**
70      * Displays the dashlet
71      *
72      * @return string html to display dashlet
73      */
74     function display() {
75         $ss = new Sugar_Smarty();
76         $ss->assign('id', $this->id);
77         $ss->assign('height', $this->height);
78         $ss->assign('dashletStrings', $this->dashletStrings);
79
80         $str = $ss->fetch('modules/Home/Dashlets/InvadersDashlet/InvadersDashlet.tpl');
81         return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str . '<br />'; // return parent::display for title and such
82     }
83
84     /**
85      * Displays the javascript for the dashlet
86      *
87      * @return string javascript to use with this dashlet
88      */
89     function displayScript() {
90         $ss = new Sugar_Smarty();
91         $ss->assign('id', $this->id);
92         $ss->assign('dashletStrings', $this->dashletStrings);
93
94         $str = $ss->fetch('modules/Home/Dashlets/InvadersDashlet/InvadersDashletScript.tpl');
95         return $str; // return parent::display for title and such
96     }
97
98     /**
99      * Displays the configuration form for the dashlet
100      *
101      * @return string html to display form
102      */
103     function displayOptions() {
104         global $app_strings;
105
106         $ss = new Sugar_Smarty();
107         $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']);
108         $ss->assign('heightLbl', $this->dashletStrings['LBL_CONFIGURE_HEIGHT']);
109         $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']);
110         $ss->assign('clearLbl', $app_strings['LBL_CLEAR_BUTTON_LABEL']);
111         $ss->assign('title', $this->title);
112         $ss->assign('height', $this->height);
113         $ss->assign('id', $this->id);
114
115         return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/InvadersDashlet/InvadersOptions.tpl');
116     }
117
118     /**
119      * called to filter out $_REQUEST object when the user submits the configure dropdown
120      *
121      * @param array $req $_REQUEST
122      * @return array filtered options to save
123      */
124     function saveOptions($req) {
125         global $sugar_config, $timedate, $current_user, $theme;
126         $options = array();
127         $options['title'] = $_REQUEST['title'];
128         if(is_numeric($_REQUEST['height'])) {
129             if($_REQUEST['height'] > 0 && $_REQUEST['height'] <= 300) $options['height'] = $_REQUEST['height'];
130             elseif($_REQUEST['height'] > 300) $options['height'] = '300';
131             else $options['height'] = '100';
132         }
133
134 //        $options['savedText'] = br2nl($this->savedText);
135         $options['savedText'] = $this->savedText;
136
137         return $options;
138     }
139
140     /**
141      * Used to save text on textarea blur. Accessed via Home/CallMethodDashlet.php
142      * This is an example of how to to call a custom method via ajax
143      */
144     function saveText() {
145         if(isset($_REQUEST['savedText'])) {
146             $optionsArray = $this->loadOptions();
147 //            _pp($_REQUEST['savedText']);
148             $optionsArray['savedText'] = nl2br($_REQUEST['savedText']);
149             $this->storeOptions($optionsArray);
150
151         }
152         else {
153             $optionsArray['savedText'] = '';
154         }
155         $json = getJSONobj();
156         echo 'result = ' . $json->encode(array('id' => $_REQUEST['id'],
157                                        'savedText' => $optionsArray['savedText']));
158     }
159 }
160
161 ?>