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-2011 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 ********************************************************************************/
42 * This is a utility base class to provide further refinement when converting
43 * pre 5.x files to the new meta-data rules. Address fields defined in the
44 * address panel will be removed as the new metadata definition will be merged later.
45 * If the address fields are outside the address panel, we will keep them as is, but
46 * ensure that they are not defined as Arrays.
50 require_once('include/SugarFields/Parsers/Rules/BaseRule.php');
52 class AddressRule extends BaseRule {
54 function AddressRule() {
58 function parsePanels($panels, $view) {
59 $searchedAddressPanel = array();
61 foreach($panels as $name=>$panel) {
63 $isAddressPanel = $name == 'lbl_address_information';
65 foreach($panel as $rowCount=>$row) {
66 foreach($row as $key=>$column) {
68 if($this->matches($column, '/_address_(city|state|country|postalcode)$/si')) {
69 if($view == 'DetailView' && !is_array($column)) {
70 $panels[$name][$rowCount][$key] = '';
71 } else if($view == 'DetailView' && $this->matches($column, '/_address_country$/') && is_array($column)) {
72 $match = $this->getMatch($column, '/(.*?)_address_country$/');
73 $panels[$name][$rowCount][$key]['name'] = $match[1] . '_address_street';
74 $panels[$name][$rowCount][$key]['label'] = 'LBL_' . strtoupper($match[1]) . '_ADDRESS';
75 } else if($view == 'EditView' && $isAddressPanel) {
77 $field = is_array($column) ? $column['name'] : $column;
78 preg_match('/^(.*?)_address_/si', $field, $matches);
80 if(empty($searchedAddressPanel[$matches[1]])) {
81 $intact = $this->hasAddressFieldsIntact($panel, $matches[1]);
83 //now we actually have to go back in and replace the street field
85 $panels = $this->removeStreetFieldOverride($panels, $matches[1]);
88 $addressFieldsIntact[$matches[1]] = $intact;
89 $searchedAddressPanel[$matches[1]] = true;
92 //Only remove in address panel if the street field is in there by itself
93 if($addressFieldsIntact[$matches[1]]) {
94 $panels[$name][$rowCount][$key] = '';
97 } else if($this->matches($column, '/^push_.*?_(shipping|billing)$/si')) {
98 $panels[$name][$rowCount][$key] = '';
107 * hasAddressFieldsIntact
108 * This function checks to see if the address fields for the given street key is
109 * intact. This means that all five fields (street, city, state, country and postalcode)
110 * have not been moved from the address panel
112 * @param $addressPanel Array of address panel contents
113 * @param $suffix The address suffix (billing, shipping, primary, alternate) to check for
116 function hasAddressFieldsIntact($addressPanel, $suffix) {
117 $expression = '/^' . $suffix . '_address_(street|city|state|country|postalcode)$/si';
119 foreach($addressPanel as $rowCount=>$row) {
120 foreach($row as $key=>$column) {
121 if($this->matches($column, $expression)) {
131 * removeStreetFieldOverride
132 * This function scans the panels and locates the street address field for the given key
133 * and replaces the Array definition (from the merging process) with a String value.
134 * @param $panels Array of the view's panels
135 * @param $street String key value of the street to search for
136 * @returns $panels Array of view's panels with street value substituted
138 function removeStreetFieldOverride($panels, $street) {
139 $expression = '/^' . $street . '_address_street$/si';
140 foreach($panels as $name=>$panel) {
141 foreach($panel as $rowCount=>$row) {
142 foreach($row as $key=>$column) {
143 if($this->matches($column, $expression)) {
144 $panels[$name][$rowCount][$key] = $street . '_address_street';