2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 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 ********************************************************************************/
38 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
41 * Vardef Handler Object
47 var $target_meta_array = false;
48 var $start_none = false;
49 var $extra_array = array(); //used to add custom items
50 var $options_array = array();
52 var $start_none_lbl = null;
54 function VarDefHandler(& $module, $meta_array_name=null){
55 $this->module_object = $module;
56 if($meta_array_name!=null){
57 global $vardef_meta_array;
58 include("include/VarDefHandler/vardef_meta_arrays.php");
59 $this->target_meta_array = $vardef_meta_array[$meta_array_name];
65 function get_vardef_array($use_singular=false, $remove_dups = false, $use_field_name = false, $use_field_label = false){
67 global $current_language;
69 global $app_list_strings;
71 $temp_module_strings = return_module_language($current_language, $this->module_object->module_dir);
73 $base_array = $this->module_object->field_defs;
74 //$base_array = $dictionary[$this->module_object->object_name]['fields'];
76 ///Inclue empty none set or not
77 if($this->start_none==true){
78 if(!empty($this->start_none_lbl)){
79 $this->options_array[''] = $this->start_none_lbl;
81 $this->options_array[''] = $app_strings['LBL_NONE'];
85 ///used for special one off items added to filter array ex. would be href link for alert templates
86 if(!empty($this->extra_array)){
88 foreach($this->extra_array as $key => $value){
89 $this->options_array[$key] = $value;
92 /////////end special one off//////////////////////////////////
95 foreach($base_array as $key => $value_array){
96 $compare_results = $this->compare_type($value_array);
98 if($compare_results == true){
100 if($value_array['type'] == 'link' && !$use_field_label){
101 $this->module_object->load_relationship($value_array['name']);
102 if(!empty($app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()])){
103 $label_name = $app_list_strings['moduleList'][$this->module_object->$value_array['name']->getRelatedModuleName()];
105 $label_name = $this->module_object->$value_array['name']->getRelatedModuleName();
108 else if(!empty($value_array['vname'])){
109 $label_name = $value_array['vname'];
111 $label_name = $value_array['name'];
115 $label_name = get_label($label_name, $temp_module_strings);
117 if(!empty($value_array['table'])){
119 $column_table = $value_array['table'];
122 $column_table = $this->module_object->table_name;
125 if($value_array['type'] == 'link'){
127 $index = $value_array['name'];
130 $index = $this->module_object->$key->getRelatedModuleName();
136 $value = trim($label_name, ':');
138 if(!in_array($value, $this->options_array))
139 $this->options_array[$index] = $value;
142 $this->options_array[$index] = $value;
144 //end if field is included
149 if($use_singular == true){
150 return convert_module_to_singular($this->options_array);
152 return $this->options_array;
155 //end get_vardef_array
159 function compare_type($value_array){
162 if(!is_array($this->target_meta_array)){
166 ////////Use the $target_meta_array;
167 if(isset($this->target_meta_array['inc_override'])){
168 foreach($this->target_meta_array['inc_override'] as $attribute => $value){
170 foreach($value as $actual_value){
171 if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return true;
173 if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return true;
177 if(isset($this->target_meta_array['ex_override'])){
178 foreach($this->target_meta_array['ex_override'] as $attribute => $value){
181 foreach($value as $actual_value){
182 if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
184 if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return false;
187 //end foreach inclusion array
191 if(isset($this->target_meta_array['inclusion'])){
192 foreach($this->target_meta_array['inclusion'] as $attribute => $value){
194 if($attribute=="type"){
195 foreach($value as $actual_value){
196 if(isset($value_array[$attribute]) && $value_array[$attribute] != $actual_value) return false;
199 if(isset($value_array[$attribute]) && $value_array[$attribute] != $value) return false;
201 //end foreach inclusion array
205 if(isset($this->target_meta_array['exclusion'])){
206 foreach($this->target_meta_array['exclusion'] as $attribute => $value){
208 foreach($value as $actual_value){
209 if ( $attribute == 'reportable' ) {
210 if ( $actual_value == 'true' ) $actual_value = 1;
211 if ( $actual_value == 'false' ) $actual_value = 0;
213 if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
216 //end foreach inclusion array
223 //end function compare_type
226 //end class VarDefHandler