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-2013 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: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
48 $_REQUEST['method']; : options: 'SaveRelationship','Save','DeleteRelationship','Delete'
49 $_REQUEST['module']; : the module associated with this Bean instance (will be used to get the class name)
50 $_REQUEST['record']; : the id of the Bean instance
51 // $_REQUEST['related_field']; : the field name on the Bean instance that contains the relationship
52 // $_REQUEST['related_record']; : the id of the related record
53 // $_REQUEST['related_']; : the
54 // $_REQUEST['return_url']; : the URL to redirect to
55 //$_REQUEST['return_type']; : when set the results of a report will be linked with the parent.
59 require_once('include/formbase.php');
61 $refreshsubpanel=true;
62 if (isset($_REQUEST['return_type']) && $_REQUEST['return_type'] == 'report') {
63 save_from_report($_REQUEST['subpanel_id'] //report_id
64 ,$_REQUEST['record'] //parent_id
65 ,$_REQUEST['module'] //module_name
66 ,$_REQUEST['subpanel_field_name'] //link attribute name
68 } else if (isset($_REQUEST['return_type']) && $_REQUEST['return_type'] == 'addtoprospectlist') {
70 $GLOBALS['log']->debug(print_r($_REQUEST,true));
71 if(!empty($_REQUEST['prospect_list_id']) and !empty($_REQUEST['prospect_ids']))
73 add_prospects_to_prospect_list(
74 $_REQUEST['prospect_list_id'],
75 $_REQUEST['prospect_ids']
80 $parent = BeanFactory::getBean($_REQUEST['module'], $_REQUEST['record']);
81 add_to_prospect_list(urldecode($_REQUEST['subpanel_module_name']),$_REQUEST['parent_module'],$_REQUEST['parent_type'],$_REQUEST['subpanel_id'],
82 $_REQUEST['child_id'],$_REQUEST['link_attribute'],$_REQUEST['link_type'], $parent);
85 $refreshsubpanel=false;
86 }else if (isset($_REQUEST['return_type']) && $_REQUEST['return_type'] == 'addcampaignlog') {
87 //if param is set to "addcampaignlog", then we need to create a campaign log entry
88 //for each campaign id passed in.
90 // Get a list of campaigns selected.
91 if (isset($_REQUEST['subpanel_id']) && !empty($_REQUEST['subpanel_id'])) {
92 $campaign_ids = $_REQUEST['subpanel_id'];
95 //retrieve current bean
96 $bean_name = $beanList[$_REQUEST['module']];
97 require_once($beanFiles[$bean_name]);
98 $focus = new $bean_name();
99 $focus->retrieve($_REQUEST['record']);
101 require_once('modules/Campaigns/utils.php');
102 //call util function to create the campaign log entry
103 foreach($campaign_ids as $id){
104 create_campaign_log_entry($id, $focus, $focus->module_dir,$focus, $focus->id);
106 $refreshsubpanel=true;
111 global $beanFiles,$beanList;
112 $bean_name = $beanList[$_REQUEST['module']];
113 require_once($beanFiles[$bean_name]);
114 $focus = new $bean_name();
116 $focus->retrieve($_REQUEST['record']);
118 // If the user selected "All records" from the selection menu, we pull up the list
119 // based on the query they used on that popup to relate them to the parent record
120 if(!empty($_REQUEST['select_entire_list']) && $_REQUEST['select_entire_list'] != 'undefined' && isset($_REQUEST['current_query_by_page'])){
122 $current_query_by_page = $_REQUEST['current_query_by_page'];
123 $current_query_by_page_array = unserialize(base64_decode($current_query_by_page));
125 $module = $current_query_by_page_array['module'];
126 $seed = BeanFactory::getBean($module);
127 if(empty($seed)) sugar_die($GLOBALS['app_strings']['ERROR_NO_BEAN']);
129 require_once('include/SearchForm/SearchForm2.php');
131 if(file_exists('custom/modules/'.$module.'/metadata/metafiles.php')){
132 require('custom/modules/'.$module.'/metadata/metafiles.php');
133 }elseif(file_exists('modules/'.$module.'/metadata/metafiles.php')){
134 require('modules/'.$module.'/metadata/metafiles.php');
137 if (file_exists('custom/modules/'.$module.'/metadata/searchdefs.php'))
139 require_once('custom/modules/'.$module.'/metadata/searchdefs.php');
141 elseif (!empty($metafiles[$module]['searchdefs']))
143 require_once($metafiles[$module]['searchdefs']);
145 elseif (file_exists('modules/'.$module.'/metadata/searchdefs.php'))
147 require_once('modules/'.$module.'/metadata/searchdefs.php');
150 if(!empty($metafiles[$module]['searchfields'])){
151 require_once($metafiles[$module]['searchfields']);
153 elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php')){
154 require_once('modules/'.$module.'/metadata/SearchFields.php');
156 if(!empty($searchdefs) && !empty($searchFields)) {
157 $searchForm = new SearchForm($seed, $module);
158 $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl');
159 $searchForm->populateFromArray($current_query_by_page_array, 'advanced');
160 $where_clauses_arr = $searchForm->generateSearchWhere(true, $module);
161 if (count($where_clauses_arr) > 0 ) {
162 $where_clauses = '('. implode(' ) AND ( ', $where_clauses_arr) . ')';
166 $query = $seed->create_new_list_query($order_by, $where_clauses);
167 $result = $GLOBALS['db']->query($query,true);
169 while($val = $GLOBALS['db']->fetchByAssoc($result,false))
171 array_push($uids, $val['id']);
173 $_REQUEST['subpanel_id'] = $uids;
176 if($bean_name == 'Team'){
177 $subpanel_id = $_REQUEST['subpanel_id'];
178 if(is_array($subpanel_id)){
179 foreach($subpanel_id as $id){
180 $focus->add_user_to_team($id);
184 $focus->add_user_to_team($subpanel_id);
187 //find request paramters with with prefix of REL_ATTRIBUTE_
188 //convert them into an array of name value pairs add pass them as
189 //parameters to the add metod.
190 $add_values =array();
191 foreach ($_REQUEST as $key=>$value) {
192 if (strpos($key,"REL_ATTRIBUTE_") !== false) {
193 $add_values[substr($key,14)]=$value;
196 $focus->load_relationship($_REQUEST['subpanel_field_name']);
197 $focus->$_REQUEST['subpanel_field_name']->add($_REQUEST['subpanel_id'],$add_values);
202 if ($refreshsubpanel) {
203 //refresh contents of the sub-panel.
204 $GLOBALS['log']->debug("Location: index.php?sugar_body_only=1&module=".$_REQUEST['module']."&subpanel=".$_REQUEST['subpanel_module_name']."&action=SubPanelViewer&inline=1&record=".$_REQUEST['record']);
205 if( empty($_REQUEST['refresh_page']) || $_REQUEST['refresh_page'] != 1){
206 $inline = isset($_REQUEST['inline'])?$_REQUEST['inline']: $inline;
207 header("Location: index.php?sugar_body_only=1&module=".$_REQUEST['module']."&subpanel=".$_REQUEST['subpanel_module_name']."&action=SubPanelViewer&inline=$inline&record=".$_REQUEST['record']);