2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
37 class ViewPopup extends SugarView{
38 protected $override_popup = array();
45 global $popupMeta, $mod_strings;
47 if(($this->bean instanceOf SugarBean) && !$this->bean->ACLAccess('list')){
48 ACLController::displayNoAccess();
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('custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) {
56 require 'custom/modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php';
57 } elseif (!empty($_REQUEST['metadata']) && $_REQUEST['metadata'] != 'undefined'
58 && file_exists('modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php')) {
59 require 'modules/' . $this->module . '/metadata/' . $_REQUEST['metadata'] . '.php';
60 } elseif (file_exists('custom/modules/' . $this->module . '/metadata/popupdefs.php')) {
61 require 'custom/modules/' . $this->module . '/metadata/popupdefs.php';
62 } elseif (file_exists('modules/' . $this->module . '/metadata/popupdefs.php')) {
63 require 'modules/' . $this->module . '/metadata/popupdefs.php';
66 if(!empty($popupMeta) && !empty($popupMeta['listviewdefs'])){
67 if(is_array($popupMeta['listviewdefs'])){
68 //if we have an array, then we are not going to include a file, but rather the
69 //listviewdefs will be defined directly in the popupdefs file
70 $listViewDefs[$this->module] = $popupMeta['listviewdefs'];
72 //otherwise include the file
73 require_once($popupMeta['listviewdefs']);
75 }elseif(file_exists('custom/modules/' . $this->module . '/metadata/listviewdefs.php')){
76 require_once('custom/modules/' . $this->module . '/metadata/listviewdefs.php');
77 }elseif(file_exists('modules/' . $this->module . '/metadata/listviewdefs.php')){
78 require_once('modules/' . $this->module . '/metadata/listviewdefs.php');
81 //check for searchdefs as well
82 if(!empty($popupMeta) && !empty($popupMeta['searchdefs'])){
83 if(is_array($popupMeta['searchdefs'])){
84 //if we have an array, then we are not going to include a file, but rather the
85 //searchdefs will be defined directly in the popupdefs file
86 $searchdefs[$this->module]['layout']['advanced_search'] = $popupMeta['searchdefs'];
88 //otherwise include the file
89 require_once($popupMeta['searchdefs']);
91 }else if(empty($searchdefs) && file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php')){
92 require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php');
93 }else if(empty($searchdefs) && file_exists('modules/'.$this->module.'/metadata/searchdefs.php')){
94 require_once('modules/'.$this->module.'/metadata/searchdefs.php');
97 //if you click the pagination button, it will populate the search criteria here
98 if(!empty($this->bean) && isset($_REQUEST[$this->module.'2_'.strtoupper($this->bean->object_name).'_offset'])) {
99 if(!empty($_REQUEST['current_query_by_page'])) {
100 $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount',
101 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page');
102 $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
103 foreach($current_query_by_page as $search_key=>$search_value) {
104 if($search_key != $this->module.'2_'.strtoupper($this->bean->object_name).'_offset'
105 && !in_array($search_key, $blockVariables)) {
106 if (!is_array($search_value)) {
107 $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value);
110 foreach ($search_value as $key=>&$val) {
111 $val = $GLOBALS['db']->quote($val);
113 $_REQUEST[$search_key] = $search_value;
120 if(!empty($listViewDefs) && !empty($searchdefs)){
121 require_once('include/Popups/PopupSmarty.php');
122 $displayColumns = array();
123 $filter_fields = array();
124 $popup = new PopupSmarty($this->bean, $this->module);
125 foreach($listViewDefs[$this->module] as $col => $params) {
126 $filter_fields[strtolower($col)] = true;
127 if(!empty($params['related_fields'])) {
128 foreach($params['related_fields'] as $field) {
129 //id column is added by query construction function. This addition creates duplicates
130 //and causes issues in oracle. #10165
131 if ($field != 'id') {
132 $filter_fields[$field] = true;
136 if(!empty($params['default']) && $params['default'])
137 $displayColumns[$col] = $params;
139 $popup->displayColumns = $displayColumns;
140 $popup->filter_fields = $filter_fields;
141 $popup->mergeDisplayColumns = true;
142 //check to see if popupdefs contains searchdefs
143 $popup->_popupMeta = $popupMeta;
144 $popup->listviewdefs = $listViewDefs;
145 $popup->searchdefs = $searchdefs;
147 if(isset($_REQUEST['query'])){
148 $popup->searchForm->populateFromRequest();
151 $massUpdateData = '';
152 if(isset($_REQUEST['mass'])) {
153 foreach(array_unique($_REQUEST['mass']) as $record) {
154 $massUpdateData .= "<input style='display: none' checked type='checkbox' name='mass[]' value='$record'>\n";
157 $popup->massUpdateData = $massUpdateData;
159 $tpl = 'include/Popups/tpls/PopupGeneric.tpl';
160 if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl")))
162 $tpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupGeneric.tpl");
165 if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl")))
167 $popup->headerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupHeader.tpl");
170 if(file_exists($this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl")))
172 $popup->footerTpl = $this->getCustomFilePathIfExists("modules/{$this->module}/tpls/popupFooter.tpl");
177 //We should at this point show the header and javascript even if to_pdf is true.
178 //The insert_popup_header javascript is incomplete and shouldn't be relied on.
179 if (isset($this->options['show_all']) && $this->options['show_all'] == false)
181 unset($this->options['show_all']);
182 $this->options['show_javascript'] = true;
183 $this->options['show_header'] = true;
184 $this->_displayJavascript();
186 insert_popup_header(null, false);
187 if(isset($this->override_popup['template_data']) && is_array($this->override_popup['template_data']))
189 $popup->th->ss->assign($this->override_popup['template_data']);
191 echo $popup->display();
194 if(file_exists('modules/' . $this->module . '/Popup_picker.php')){
195 require_once('modules/' . $this->module . '/Popup_picker.php');
197 require_once('include/Popups/Popup_picker.php');
200 $popup = new Popup_Picker();
201 $popup->_hide_clear_button = true;
202 echo $popup->process_page();