]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/generic/SugarWidgets/SugarWidgetSubPanelTopSelectUsersButton.php
Release 6.5.0
[Github/sugarcrm.git] / include / generic / SugarWidgets / SugarWidgetSubPanelTopSelectUsersButton.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
40
41
42
43 class SugarWidgetSubPanelTopSelectUsersButton extends SugarWidgetSubPanelTopSelectButton
44 {
45         //button_properties is a collection of properties associated with the widget_class definition. layoutmanager
46         function SugarWidgetSubPanelTopSelectUsersButton($button_properties=array())
47         {
48                 $this->button_properties=$button_properties;
49         }
50
51     function getDisplayName()
52     {
53         return $GLOBALS['app_strings']['LBL_SELECT_USER_BUTTON_LABEL'];
54     }
55         //widget_data is the collection of attributes associated with the button in the layout_defs file.
56         function display(&$widget_data)
57         {
58                 global $app_strings;
59                 $initial_filter = '';
60
61                 $this->title = $app_strings['LBL_SELECT_USER_BUTTON_TITLE'];
62                 //$this->accesskey = $app_strings['LBL_SELECT_USER_BUTTON_KEY'];
63                 $this->value = $this->getDisplayName();
64
65                 $this->module_name = 'Users';
66
67                 if (is_array($this->button_properties)) {
68                         if( isset($this->button_properties['title'])) {
69                                 $this->title = $app_strings[$this->button_properties['title']];
70                         }
71                         if( isset($this->button_properties['accesskey'])) {
72                                 //$this->accesskey = $app_strings[$this->button_properties['accesskey']];
73                         }
74                         if( isset($this->button_properties['form_value'])) {
75                                 $this->value = $app_strings[$this->button_properties['form_value']];
76                         }
77                         if( isset($this->button_properties['module'])) {
78                                 $this->module_name = $this->button_properties['module'];
79                         }
80                 }
81
82                 $focus = $widget_data['focus'];
83                 if(ACLController::moduleSupportsACL($widget_data['module']) && !ACLController::checkAccess($widget_data['module'], 'list', true)){
84                         $button = ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
85                         . ' title="' . $this->title . '"'
86                         . ' value="' . $this->value . "\"\n"
87                         .' disabled />';
88                         return $button;
89                 }
90
91                 //refresh the whole page after end of action?
92                 $refresh_page = 0;
93                 if(!empty($widget_data['subpanel_definition']->_instance_properties['refresh_page'])){
94                         $refresh_page = 1;
95                 }
96
97                 $subpanel_definition = $widget_data['subpanel_definition'];
98
99                 $button_definition = $subpanel_definition->get_buttons();
100                 $subpanel_name = $subpanel_definition->get_module_name();
101                 if (empty($this->module_name)) {
102                         $this->module_name = $subpanel_name;
103                 }
104
105                 if ($subpanel_name == 'Project'){
106                         $link_field_name = 'user_resources';
107                 }
108                 else{
109                         $link_field_name = $subpanel_definition->get_data_source_name(true);
110                 }
111
112                 $popup_mode='Single';
113                 if(isset($widget_data['mode'])){
114                         $popup_mode=$widget_data['mode'];
115                 }
116                 if(isset($widget_data['initial_filter_fields'])){
117                         if (is_array($widget_data['initial_filter_fields'])) {
118                                 foreach ($widget_data['initial_filter_fields'] as $value=>$alias) {
119                                         if (isset($focus->$value) and !empty($focus->$value)) {
120                                                 $initial_filter.="&".$alias . '='.urlencode($focus->$value);
121                                         }
122                                 }
123                         }
124                 }
125
126                 if (!empty($widget_data['filter_out_is_admin'])) {
127             $initial_filter.="&is_admin_advanced=0";
128         }
129
130                 $create="true";
131                 if(isset($widget_data['create'])){
132                         $create=$widget_data['create'];
133                 }
134                 $return_module = $_REQUEST['module'];
135                 $return_action = 'SubPanelViewer';
136                 $return_id = $_REQUEST['record'];
137
138                 //field_to_name_array
139                 $fton_array= array('id' => 'subpanel_id');
140                 if(isset($widget_data['field_to_name_array']) && is_array($widget_data['field_to_name_array'])){
141                         $fton_array=array_merge($fton_array,$widget_data['field_to_name_array']);
142                 }
143
144                 $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel_name&record=$return_id&sugar_body_only=1";
145
146                 $popup_request_data = array(
147                         'call_back_function' => 'set_return_and_save_background',
148                         'form_name' => 'DetailView',
149                         'field_to_name_array' => $fton_array,
150                         'passthru_data' => array(
151                                 'child_field' => $this->module_name,
152                                 'return_url' => urlencode($return_url),
153                                 'link_field_name' => $link_field_name,
154                                 'module_name' => $this->module_name,
155                                 'refresh_page'=>true,
156                         ),
157                 );
158
159                 if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data'])) {
160                         $popup_request_data['passthru_data']= array_merge($popup_request_data['passthru_data'],$this->button_properties['add_to_passthru_data']);
161                 }
162
163                 if (is_array($this->button_properties) && !empty($this->button_properties['add_to_passthru_data']['return_type'])) {
164
165                         if ($this->button_properties['add_to_passthru_data']['return_type']=='report') {
166                                 $initial_filter = "&module_name=". urlencode($widget_data['module']);
167                         }
168                         if ($this->button_properties['add_to_passthru_data']['return_type']=='addtoprospectlist') {
169                                 if (isset($widget_data['query'])) {
170                                         $popup_request_data['passthru_data']['query']=$widget_data['query'];
171                                 }
172                         }
173                 }
174                 $json_encoded_php_array = $this->_create_json_encoded_popup_request($popup_request_data);
175
176                 return '<form action="index.php">' . "\n"
177                         . ' <input type="button" name="' .$this->getWidgetId() . '" id="' .$this->getWidgetId() . '" class="button"' . "\"\n"
178                                 . ' title="' . $this->title . '"'
179                         . ' value="' . $this->value . "\"\n"
180                         . " onclick='open_popup(\"$this->module_name\",600,400,\"$initial_filter\",true,true,$json_encoded_php_array,\"$popup_mode\",$create);' /></form>\n";
181         }
182 }
183 ?>