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