]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/MVC/View/views/view.popup.php
Release 6.5.9
[Github/sugarcrm.git] / include / MVC / View / views / view.popup.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 class ViewPopup extends SugarView{
38     protected $override_popup = array();
39         var $type ='list';
40         function ViewPopup(){
41                 parent::SugarView();
42         }
43
44         function display(){
45                 global $popupMeta, $mod_strings;
46
47         if(($this->bean instanceOf SugarBean) && !$this->bean->ACLAccess('list')){
48             ACLController::displayNoAccess();
49             sugar_cleanup(true);
50         }
51
52                 if(isset($_REQUEST['metadata']) && strpos($_REQUEST['metadata'], "..") !== false)
53                         die("Directory navigation attack denied.");
54                 if(!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined'
55                         && file_exists('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) // if custom metadata is requested
56                         require_once('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php');
57                 elseif(file_exists('custom/modules/' . $this->module . '/metadata/popupdefs.php'))
58                 require_once('custom/modules/' . $this->module . '/metadata/popupdefs.php');
59             elseif(file_exists('modules/' . $this->module . '/metadata/popupdefs.php'))
60                 require_once('modules/' . $this->module . '/metadata/popupdefs.php');
61
62             if(!empty($popupMeta) && !empty($popupMeta['listviewdefs'])){
63                 if(is_array($popupMeta['listviewdefs'])){
64                         //if we have an array, then we are not going to include a file, but rather the
65                         //listviewdefs will be defined directly in the popupdefs file
66                         $listViewDefs[$this->module] = $popupMeta['listviewdefs'];
67                 }else{
68                         //otherwise include the file
69                         require_once($popupMeta['listviewdefs']);
70                 }
71             }elseif(file_exists('custom/modules/' . $this->module . '/metadata/listviewdefs.php')){
72                         require_once('custom/modules/' . $this->module . '/metadata/listviewdefs.php');
73                 }elseif(file_exists('modules/' . $this->module . '/metadata/listviewdefs.php')){
74                         require_once('modules/' . $this->module . '/metadata/listviewdefs.php');
75                 }
76
77                 //check for searchdefs as well
78                 if(!empty($popupMeta) && !empty($popupMeta['searchdefs'])){
79                 if(is_array($popupMeta['searchdefs'])){
80                         //if we have an array, then we are not going to include a file, but rather the
81                         //searchdefs will be defined directly in the popupdefs file
82                         $searchdefs[$this->module]['layout']['advanced_search'] = $popupMeta['searchdefs'];
83                 }else{
84                         //otherwise include the file
85                         require_once($popupMeta['searchdefs']);
86                 }
87             }else if(empty($searchdefs) && file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php')){
88                         require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php');
89                 }else if(empty($searchdefs) && file_exists('modules/'.$this->module.'/metadata/searchdefs.php')){
90                 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
91                 }
92
93                 //if you click the pagination button, it will populate the search criteria here
94         if(!empty($this->bean) && isset($_REQUEST[$this->module.'2_'.strtoupper($this->bean->object_name).'_offset'])) {
95             if(!empty($_REQUEST['current_query_by_page'])) {
96                 $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount',
97                     'sortOrder', 'orderBy', 'request_data', 'current_query_by_page');
98                 $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
99                 foreach($current_query_by_page as $search_key=>$search_value) {
100                     if($search_key != $this->module.'2_'.strtoupper($this->bean->object_name).'_offset'
101                         && !in_array($search_key, $blockVariables)) {
102                         if (!is_array($search_value)) {
103                             $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value);
104                         }
105                         else {
106                             foreach ($search_value as $key=>&$val) {
107                                 $val = $GLOBALS['db']->quote($val);
108                             }
109                             $_REQUEST[$search_key] = $search_value;
110                         }
111                     }
112                 }
113             }
114         }
115
116                 if(!empty($listViewDefs) && !empty($searchdefs)){
117                         require_once('include/Popups/PopupSmarty.php');
118                         $displayColumns = array();
119                         $filter_fields = array();
120                         $popup = new PopupSmarty($this->bean, $this->module);
121                         foreach($listViewDefs[$this->module] as $col => $params) {
122                         $filter_fields[strtolower($col)] = true;
123                                  if(!empty($params['related_fields'])) {
124                     foreach($params['related_fields'] as $field) {
125                         //id column is added by query construction function. This addition creates duplicates
126                         //and causes issues in oracle. #10165
127                         if ($field != 'id') {
128                             $filter_fields[$field] = true;
129                         }
130                     }
131                 }
132                         if(!empty($params['default']) && $params['default'])
133                                 $displayColumns[$col] = $params;
134                 }
135                 $popup->displayColumns = $displayColumns;
136                 $popup->filter_fields = $filter_fields;
137                 $popup->mergeDisplayColumns = true;
138                 //check to see if popupdefs contains searchdefs
139                 $popup->_popupMeta = $popupMeta;
140             $popup->listviewdefs = $listViewDefs;
141                 $popup->searchdefs = $searchdefs;
142
143                 if(isset($_REQUEST['query'])){
144                                 $popup->searchForm->populateFromRequest();
145                 }
146
147                         $massUpdateData = '';
148                         if(isset($_REQUEST['mass'])) {
149                                 foreach(array_unique($_REQUEST['mass']) as $record) {
150                                         $massUpdateData .= "<input style='display: none' checked type='checkbox' name='mass[]' value='$record'>\n";
151                                 }
152                         }
153                         $popup->massUpdateData = $massUpdateData;
154
155             $tpl = 'include/Popups/tpls/PopupGeneric.tpl';
156             if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl")))
157             {
158                 $tpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl");
159             }
160
161             if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl")))
162             {
163                 $popup->headerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl");
164             }
165
166             if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl")))
167             {
168                 $popup->footerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl");
169             }
170
171                         $popup->setup($tpl);
172
173             //We should at this point show the header and javascript even if to_pdf is true.
174             //The insert_popup_header javascript is incomplete and shouldn't be relied on.
175             if (isset($this->options['show_all']) && $this->options['show_all'] == false)
176             {
177                 unset($this->options['show_all']);
178                 $this->options['show_javascript'] = true;
179                 $this->options['show_header'] = true;
180                 $this->_displayJavascript();
181             }
182             insert_popup_header(null, false);
183             if(isset($this->override_popup['template_data']) && is_array($this->override_popup['template_data']))
184             {
185                  $popup->th->ss->assign($this->override_popup['template_data']);
186             }
187                         echo $popup->display();
188
189                 }else{
190                         if(file_exists('modules/' . $this->module . '/Popup_picker.php')){
191                                 require_once('modules/' . $this->module . '/Popup_picker.php');
192                         }else{
193                                 require_once('include/Popups/Popup_picker.php');
194                         }
195
196                         $popup = new Popup_Picker();
197                         $popup->_hide_clear_button = true;
198                         echo $popup->process_page();
199                 }
200         }
201 }
202 ?>