]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/SugarFields/Fields/Parent/SugarFieldParent.php
Release 6.5.0
[Github/sugarcrm.git] / include / SugarFields / Fields / Parent / SugarFieldParent.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 require_once('include/SugarFields/Fields/Relate/SugarFieldRelate.php');
38
39 class SugarFieldParent extends SugarFieldRelate {
40    
41         function getDetailViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
42                 $nolink = array('Users', 'Teams');
43                 if(in_array($vardef['module'], $nolink)){
44                         $this->ss->assign('nolink', true);
45                 }else{
46                         $this->ss->assign('nolink', false);
47                 }
48         $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);
49         return $this->fetch($this->findTemplate('DetailView'));
50     }
51     
52     function getEditViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
53         $form_name = 'EditView';
54         if(isset($displayParams['formName'])) {
55                 $form_name = $displayParams['formName'];
56         }
57
58         $popup_request_data = array(
59                         'call_back_function' => 'set_return',
60                         'form_name' => $form_name,
61                         'field_to_name_array' => array(
62                                                                                         'id' => $vardef['id_name'],
63                                                                                         'name' => $vardef['name'],
64                                                                          ),
65                 );
66
67
68                 global $app_list_strings;
69                 $parent_types = $app_list_strings['record_type_display'];
70                 
71                 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
72                 foreach($disabled_parent_types as $disabled_parent_type){
73                         if($disabled_parent_type != $focus->parent_type){
74                                 unset($parent_types[$disabled_parent_type]);
75                         }
76                 }
77                 asort($parent_types);
78                 $json = getJSONobj();
79                 $displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data).'{/literal}';
80         $displayParams['disabled_parent_types'] = '<script>var disabledModules='. $json->encode($disabled_parent_types).';</script>';
81         $this->ss->assign('quickSearchCode', $this->createQuickSearchCode($form_name, $vardef));
82
83         $keys = $this->getAccessKey($vardef,'PARENT',$vardef['module']);
84         $displayParams['accessKeySelect'] = $keys['accessKeySelect'];
85         $displayParams['accessKeySelectLabel'] = $keys['accessKeySelectLabel'];
86         $displayParams['accessKeySelectTitle'] = $keys['accessKeySelectTitle'];
87         $displayParams['accessKeyClear'] = $keys['accessKeyClear'];
88         $displayParams['accessKeyClearLabel'] = $keys['accessKeyClearLabel'];
89         $displayParams['accessKeyClearTitle'] = $keys['accessKeyClearTitle'];
90
91         $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);        
92         return $this->fetch($this->findTemplate('EditView'));
93     }
94         
95     function getSearchViewSmarty($parentFieldArray, $vardef, $displayParams, $tabindex) {
96                 $form_name = 'search_form';
97                                 
98         if(isset($displayParams['formName'])) {
99                 $form_name = $displayParams['formName'];
100         }
101         
102         if(preg_match('/(_basic|_advanced)$/', $vardef['name'], $match))
103         {
104            $vardef['type_name'] = $vardef['type_name'] . $match[1];
105         }
106         
107         $this->ss->assign('form_name', $form_name);
108
109         $popup_request_data = array(
110                         'call_back_function' => 'set_return',
111                         'form_name' => $form_name,
112                         'field_to_name_array' => array(
113                                                                                         'id' => $vardef['id_name'],
114                                                                                         'name' => $vardef['name'],
115                                                                          ),
116                 );
117
118
119                 global $app_list_strings;
120                 $parent_types = $app_list_strings['record_type_display'];
121                 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
122                 foreach($disabled_parent_types as $disabled_parent_type){
123                         if($disabled_parent_type != $focus->parent_type){
124                                 unset($parent_types[$disabled_parent_type]);
125                         }
126                 }
127
128                 $json = getJSONobj();
129                 $displayParams['popupData'] = '{literal}'.$json->encode($popup_request_data).'{/literal}';
130         $displayParams['disabled_parent_types'] = '<script>var disabledModules='. $json->encode($disabled_parent_types).';</script>';
131         $this->setup($parentFieldArray, $vardef, $displayParams, $tabindex);        
132         return $this->fetch($this->findTemplate('SearchView'));
133     }
134     
135     /**
136      * @see SugarFieldBase::importSanitize()
137      */
138     public function importSanitize(
139         $value,
140         $vardef,
141         $focus,
142         ImportFieldSanitize $settings
143         )
144     {
145         global $beanList;
146         
147         if ( isset($vardef['type_name']) ) {
148             $moduleName = $vardef['type_name'];
149             if ( isset($focus->$moduleName) && isset($beanList[$focus->$moduleName]) ) {
150                 $vardef['module'] = $focus->$moduleName;
151                 $vardef['rname'] = 'name';
152                 $relatedBean = loadBean($focus->$moduleName);
153                 $vardef['table'] = $relatedBean->table_name;
154                 return parent::importSanitize($value,$vardef,$focus,$settings);
155             }
156         }
157         
158         return false;
159     }
160     
161     function createQuickSearchCode($formName = 'EditView', $vardef){
162         
163         require_once('include/QuickSearchDefaults.php');
164         $json = getJSONobj();
165         
166         $dynamicParentTypePlaceHolder = "**@**"; //Placeholder for dynamic parent so smarty tags are not escaped in json encoding.
167         $dynamicParentType = '{/literal}{if !empty($fields.parent_type.value)}{$fields.parent_type.value}{else}Accounts{/if}{literal}';
168         
169         //Get the parent sqs definition
170         $qsd = QuickSearchDefaults::getQuickSearchDefaults();
171         $qsd->setFormName($formName);
172         $sqsFieldArray = $qsd->getQSParent($dynamicParentTypePlaceHolder);
173         $qsFieldName = $formName . "_" . $vardef['name'];
174         
175         //Build the javascript
176         $quicksearch_js = '<script language="javascript">';
177         $quicksearch_js.= "if(typeof sqs_objects == 'undefined'){var sqs_objects = new Array;}";
178         $quicksearch_js .= "sqs_objects['$qsFieldName']=" . str_replace($dynamicParentTypePlaceHolder, $dynamicParentType,$json->encode($sqsFieldArray)) .';';
179
180         return $quicksearch_js .= '</script>';
181     }
182     
183     /**
184      * getSearchInput
185      * 
186      * This function allows the SugarFields to handle returning the search input value given arguments (typically from $_REQUEST/$_POST)
187      * and a search string.
188      * 
189      * @param $key String value of key to search for
190      * @param $args Mixed value containing haystack to search for value in
191      * @return $value Mixed value that the SugarField should return
192      */    
193     function getSearchInput($key='', $args=array()) 
194     {
195         //Nothing specified return empty string
196         if(empty($key) || empty($args))
197         {
198                 return ''; 
199         }
200         
201         //We are probably getting "parent_type" as the $key value, but this is likely not set since there are
202         //advanced and basic tabs.  This next section attempts to resolve this issue.
203         $isBasicSearch = isset($args['searchFormTab']) && $args['searchFormTab'] == 'basic_search' ? true : false;
204         $searchKey = $isBasicSearch ? "{$key}_basic" : "{$key}_advanced";
205         
206         if(isset($args[$searchKey]))
207         {
208            return $args[$searchKey];  
209         }
210         
211         return isset($args[$key]) ? $args[$key] : '';
212     }    
213 }
214 ?>