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-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 ********************************************************************************/
41 require_once('include/generic/SugarWidgets/SugarWidgetSubPanelTopButton.php');
42 require_once('include/generic/SugarWidgets/SugarWidgetReportField.php');
51 var $widget_prefix = 'SugarWidget';
52 var $default_widget_name = 'Field';
55 function LayoutManager()
57 // set a sane default for context
58 $this->defs['context'] = 'Detail';
59 $this->DBHelper = $GLOBALS['db'];
62 function setAttribute($key,$value)
64 $this->defs[$key] = $value;
67 function setAttributePtr($key,&$value)
69 $this->defs[$key] = $value;
72 function getAttribute($key)
74 if ( isset($this->defs[$key]))
76 return $this->defs[$key];
82 // Take the class name from the widget definition and use the class to look it up
83 // $use_default will default classes to SugarWidgetFieldxxxxx
84 function getClassFromWidgetDef($widget_def, $use_default = false)
86 static $class_map = array(
87 'SugarWidgetSubPanelTopCreateButton' => array(
88 'widget_class'=>'SugarWidgetSubPanelTopButton',
89 'title'=>'LBL_NEW_BUTTON_TITLE',
90 'access_key'=>'LBL_NEW_BUTTON_KEY',
91 'form_value'=>'LBL_NEW_BUTTON_LABEL',
94 'SugarWidgetSubPanelTopButtonQuickCreate' => array(
95 'widget_class'=>'SugarWidgetSubPanelTopButtonQuickCreate',
96 'title'=>'LBL_NEW_BUTTON_TITLE',
97 'access_key'=>'LBL_NEW_BUTTON_KEY',
98 'form_value'=>'LBL_NEW_BUTTON_LABEL',
101 'SugarWidgetSubPanelTopScheduleMeetingButton' => array(
102 'widget_class'=>'SugarWidgetSubPanelTopScheduleMeetingButton',
103 'module'=>'Meetings',
104 'title'=>'LBL_NEW_BUTTON_TITLE',
105 'access_key'=>'LBL_NEW_BUTTON_KEY',
106 'form_value'=>'LNK_NEW_MEETING',
109 'SugarWidgetSubPanelTopScheduleCallButton' => array(
110 'widget_class'=>'SugarWidgetSubPanelTopScheduleCallButton',
112 'title'=>'LBL_NEW_BUTTON_TITLE',
113 'access_key'=>'LBL_NEW_BUTTON_KEY',
114 'form_value'=>'LNK_NEW_CALL',
117 'SugarWidgetSubPanelTopCreateTaskButton' => array(
118 'widget_class'=>'SugarWidgetSubPanelTopCreateTaskButton',
120 'title'=>'LBL_NEW_BUTTON_TITLE',
121 'access_key'=>'LBL_NEW_BUTTON_KEY',
122 'form_value'=>'LNK_NEW_TASK',
125 'SugarWidgetSubPanelTopCreateNoteButton' => array(
126 'widget_class'=>'SugarWidgetSubPanelTopCreateNoteButton',
128 'title'=>'LBL_NEW_BUTTON_TITLE',
129 'access_key'=>'LBL_NEW_BUTTON_KEY',
130 'form_value'=>'LNK_NEW_NOTE',
133 'SugarWidgetSubPanelTopCreateContactAccountButton' => array(
134 'widget_class'=>'SugarWidgetSubPanelTopButton',
135 'module'=>'Contacts',
136 'title'=>'LBL_NEW_BUTTON_TITLE',
137 'access_key'=>'LBL_NEW_BUTTON_KEY',
138 'form_value'=>'LBL_NEW_BUTTON_LABEL',
139 'additional_form_fields' => array(
140 'primary_address_street' => 'shipping_address_street',
141 'primary_address_city' => 'shipping_address_city',
142 'primary_address_state' => 'shipping_address_state',
143 'primary_address_country' => 'shipping_address_country',
144 'primary_address_postalcode' => 'shipping_address_postalcode',
145 'to_email_addrs' => 'email1'
149 'SugarWidgetSubPanelTopCreateContact' => array(
150 'widget_class'=>'SugarWidgetSubPanelTopButton',
151 'module'=>'Contacts',
152 'title'=>'LBL_NEW_BUTTON_TITLE',
153 'access_key'=>'LBL_NEW_BUTTON_KEY',
154 'form_value'=>'LBL_NEW_BUTTON_LABEL',
155 'additional_form_fields' => array(
156 'account_id' => 'account_id',
157 'account_name' => 'account_name',
161 'SugarWidgetSubPanelTopCreateRevisionButton'=> array(
162 'widget_class'=>'SugarWidgetSubPanelTopButton',
163 'module'=>'DocumentRevisions',
164 'title'=>'LBL_NEW_BUTTON_TITLE',
165 'access_key'=>'LBL_NEW_BUTTON_KEY',
166 'form_value'=>'LBL_NEW_BUTTON_LABEL',
167 'additional_form_fields' => array(
168 'parent_name'=>'document_name',
169 'document_name' => 'document_name',
170 'document_revision' => 'latest_revision',
171 'document_filename' => 'filename',
172 'document_revision_id' => 'document_revision_id',
177 'SugarWidgetSubPanelTopCreateDirectReport' => array(
178 'widget_class'=>'SugarWidgetSubPanelTopButton',
179 'module'=>'Contacts',
180 'title'=>'LBL_NEW_BUTTON_TITLE',
181 'access_key'=>'LBL_NEW_BUTTON_KEY',
182 'form_value'=>'LBL_NEW_BUTTON_LABEL',
183 'additional_form_fields' => array(
184 'reports_to_name' => 'name',
185 'reports_to_id' => 'id',
189 'SugarWidgetSubPanelTopSelectFromReportButton' => array(
190 'widget_class'=>'SugarWidgetSubPanelTopSelectButton',
192 'title'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
193 'access_key'=>'LBL_SELECT_BUTTON_KEY',
194 'form_value'=>'LBL_SELECT_REPORTS_BUTTON_LABEL',
196 'add_to_passthru_data'=>array (
197 'return_type'=>'report',
200 'SugarWidgetSubPanelAddToProspectListButton' => array(
201 'widget_class'=>'SugarWidgetSubPanelTopSelectButton',
202 'module'=>'ProspectLists',
203 'title'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
204 'access_key'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_KEY',
205 'form_value'=>'LBL_ADD_TO_PROSPECT_LIST_BUTTON_LABEL',
207 'add_to_passthru_data'=>array (
208 'return_type'=>'addtoprospectlist',
209 'parent_module'=>'ProspectLists',
210 'parent_type'=>'ProspectList',
211 'child_id'=>'target_id',
212 'link_attribute'=>'target_type',
213 'link_type'=>'polymorphic', //polymorphic or default
218 $fieldDef = $this->getFieldDef($widget_def);
219 if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum'){
220 $widget_def['widget_class'] = 'Fieldmultienum';
222 if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'bool'){
223 $widget_def['widget_class'] = 'Fieldbool';
227 switch($widget_def['name']) {
228 case 'assigned_user_id':
231 case 'modified_user_id':
233 $widget_def['widget_class'] = 'Fielduser_name';
236 if ( isset($widget_def['type']) ) {
237 $widget_def['widget_class'] = 'Field' . $widget_def['type'];
239 $widget_def['widget_class'] = 'Field' . $this->DBHelper->getFieldType($widget_def);
244 if(!empty($widget_def['name']) && $widget_def['name'] == 'team_set_id'){
245 $widget_def['widget_class'] = 'Fieldteam_set_id';
248 if(empty($widget_def['widget_class']))
250 // Default the class to SugarWidgetField
251 $class_name = $this->widget_prefix.$this->default_widget_name;
255 $class_name = $this->widget_prefix.$widget_def['widget_class'];
258 // Check to see if this is one of the known class mappings.
259 if(!empty($class_map[$class_name]))
261 if (empty($class_map[$class_name]['widget_class'])) {
262 $widget = new SugarWidgetSubPanelTopButton($class_map[$class_name]);
265 if (!class_exists($class_map[$class_name]['widget_class'])) {
266 require_once('include/generic/SugarWidgets/'.$class_map[$class_name]['widget_class'].'.php');
269 $widget = new $class_map[$class_name]['widget_class']($class_map[$class_name]);
276 // At this point, we have a class name and we do not have a valid class defined.
277 if(!class_exists($class_name))
280 // The class does not exist. Try including it.
281 if (file_exists('custom/include/generic/SugarWidgets/'.$class_name.'.php'))
282 require_once('custom/include/generic/SugarWidgets/'.$class_name.'.php');
283 else if (file_exists('include/generic/SugarWidgets/'.$class_name.'.php'))
284 require_once('include/generic/SugarWidgets/'.$class_name.'.php');
286 if(!class_exists($class_name))
288 // If we still do not have a class, oops....
289 die("LayoutManager: Class not found:".$class_name);
293 $widget = new $class_name($this); // cache disabled $this->getClassFromCache($class_name);
298 function getFieldDef($widget_def){
300 if(!empty($widget_def['module']) &&!empty($GLOBALS['beanList'][$widget_def['module']]) && !empty($GLOBALS['beanFiles'][$GLOBALS['beanList'][$widget_def['module']]])){
301 if (!isset($beanCache[$widget_def['module']])){
302 $beanCache[$widget_def['module']] = new $GLOBALS['beanList'][$widget_def['module']]();
304 $bean = $beanCache[$widget_def['module']];
305 if(!empty($widget_def['name']) && !empty($bean->field_name_map) &&!empty($bean->field_name_map[$widget_def['name']]) ){
306 return $bean->field_name_map[$widget_def['name']];
313 function widgetDisplay($widget_def, $use_default = false)
315 $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
316 $label = isset($widget_def['module']) ? $widget_def['module'] : '';
317 if (is_subclass_of($theclass, 'SugarWidgetSubPanelTopButton')) {
318 $label = $theclass->get_subpanel_relationship_name($widget_def);
320 $theclass->setWidgetId($label);
323 $fieldDef = $this->getFieldDef($widget_def);
324 if(!empty($fieldDef) && !empty($fieldDef['type']) && strtolower(trim($fieldDef['type'])) == 'multienum'){
325 $widget_def['fields'] = sugarArrayMerge($widget_def['fields'] , $fieldDef);
326 $widget_def['fields']['module'] = $label;
330 return $theclass->display($widget_def);
333 function widgetQuery($widget_def, $use_default = false)
335 $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
337 return $theclass->query($widget_def);
340 // display an input field
341 // module is the parent module of the def
342 function widgetDisplayInput($widget_def, $use_default = false)
344 $theclass = $this->getClassFromWidgetDef($widget_def, $use_default);
345 return $theclass->displayInput($widget_def);