]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MergeRecords/Step3.php
Release 6.4.0
[Github/sugarcrm.git] / modules / MergeRecords / Step3.php
1 <?php
2 if (!defined('sugarEntry') || !sugarEntry)
3     die('Not A Valid Entry Point');
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
8  * This program is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Affero General Public License version 3 as published by the
10  * Free Software Foundation with the addition of the following permission added
11  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14  * 
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
18  * details.
19  * 
20  * You should have received a copy of the GNU Affero General Public License along with
21  * this program; if not, see http://www.gnu.org/licenses or write to the Free
22  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301 USA.
24  * 
25  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27  * 
28  * The interactive user interfaces in modified source and object code versions
29  * of this program must display Appropriate Legal Notices, as required under
30  * Section 5 of the GNU Affero General Public License version 3.
31  * 
32  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33  * these Appropriate Legal Notices must retain the display of the "Powered by
34  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35  * technical reasons, the Appropriate Legal Notices must display the words
36  * "Powered by SugarCRM".
37  ********************************************************************************/
38
39 /*********************************************************************************
40
41  * Description:  TODO: To be written.
42  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
43  * All Rights Reserved.
44  * Contributor(s): ______________________________________..
45  ********************************************************************************/
46
47
48
49 require_once ('include/JSON.php');
50 $timedate = TimeDate::getInstance();
51 global $app_strings;
52 global $mod_strings;
53 global $app_list_strings;
54 global $current_language;
55 global $urlPrefix;
56 global $currentModule;
57 global $theme;
58 global $filter_for_valid_editable_attributes;
59 //filter condition for fields in vardefs that can participate in merge.
60 $filter_for_valid_editable_attributes =
61     array(
62                 array('type'=>'datetimecombo','source'=>'db'),
63          array('type'=>'datetime','source'=>'db'),
64          array('type'=>'varchar','source'=>'db'),
65          array('type'=>'enum','source'=>'db'),
66          array('type'=>'multienum','source'=>'db'),
67          array('type'=>'text','source'=>'db'),
68          array('type'=>'date','source'=>'db'),
69          array('type'=>'time','source'=>'db'),
70          array('type'=>'int','source'=>'db'),
71          array('type'=>'long','source'=>'db'),
72          array('type'=>'double','source'=>'db'),
73          array('type'=>'float','source'=>'db'),
74          array('type'=>'short','source'=>'db'),
75          array('dbType'=>'varchar','source'=>'db'),
76          array('dbType'=>'double','source'=>'db'),
77          array('type'=>'relate'),
78     );
79
80 $filter_for_valid_related_attributes   = array( array('type'=>'link'),);
81 $filter_for_invalid_related_attributes   = array(array('type'=>'link','link_type'=>'one'));
82
83 //following attributes will be ignored from the merge process.
84 $invalid_attribute_by_name= array('date_entered'=>'date_entered','date_modified'=>'date_modified','modified_user_id'=>'modified_user_id', 'created_by'=>'created_by','deleted'=>'deleted');
85
86 $merge_ids_array = array ();
87 if (isset($_REQUEST['change_parent']) && $_REQUEST['change_parent']=='1') {
88    $base_id=$_REQUEST['change_parent_id'];
89      foreach ($_REQUEST['merged_ids'] as $id) {
90         if ($id != $base_id) {
91             $merge_ids_array[] = $id;
92         }
93      }
94      //add the existing parent to merged_id array.
95      $merge_ids_array[] = $_REQUEST['record'];
96 } elseif (isset($_REQUEST['remove']) && $_REQUEST['remove']=='1') {
97     $base_id=$_REQUEST['record'];
98     $removed_id= $_REQUEST['remove_id'];
99      foreach ($_REQUEST['merged_ids'] as $id) {
100         if ($id != $removed_id) {
101             $merge_ids_array[] = $id;
102         }
103      }
104 } else {
105     $base_id=$_REQUEST['record'];
106      foreach ($_REQUEST['mass'] as $id) {
107         $merge_ids_array[] = $id;
108      }
109 }
110 $focus = new MergeRecord();
111 $focus->load_merge_bean($_REQUEST['merge_module'], true, $base_id);
112 $params = array();
113 $params[] = "<a href='index.php?module={$focus->merge_bean->module_dir}&action=index'>{$GLOBALS['app_list_strings']['moduleList'][$focus->merge_bean->module_dir]}</a>";
114 $params[] = "<a href='index.php?module={$focus->merge_bean->module_dir}&action=DetailView&record={$focus->merge_bean->id}'>{$focus->merge_bean->name}</a>";
115 $params[] = $mod_strings['LBL_MODULE_NAME'];
116 echo getClassicModuleTitle($focus->merge_bean->module_dir, $params, true);
117
118 $mergeBeanArray = array ();
119 $records=1;
120 //render a column for each record to merge
121 $merged_ids='';
122 $merge_records_names=array();
123 foreach ($merge_ids_array as $id) {
124     require_once ($focus->merge_bean_file_path);
125     $mergeBeanArray[$id] = new $focus->merge_bean_class();
126     $mergeBeanArray[$id]->retrieve($id);
127     $merge_records_names[]=$mergeBeanArray[$id]->get_summary_text();
128     $records++;
129     $merged_ids.="<input type='hidden' name='merged_ids[]' value='$id'>";
130 }
131
132 $col_width=floor(80/$records).'%';
133 global $max_data_length;
134 $max_data_length=floor(65/$records);
135 global $xtpl;
136 $xtpl = new XTemplate("modules/MergeRecords/Step3.html");
137 $xtpl->assign("MOD", $mod_strings);
138 $xtpl->assign("APP", $app_strings);
139
140 $xtpl->assign("ID", $focus->merge_bean->id);
141 $xtpl->assign("MERGE_MODULE", $focus->merge_module);
142
143 $xtpl->assign("MERGED_IDS", $merged_ids);
144
145 //set return parameters.
146 if (!empty ($_REQUEST['return_module'])) {
147     $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
148 }
149 if (!empty ($_REQUEST['return_action'])) {
150     $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
151 }
152 if (!empty ($_REQUEST['return_id'])) {
153     $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
154 }
155
156 $temp_field_array = $focus->merge_bean->field_defs;
157 $field_count = 1;
158 $json = new JSON(JSON_LOOSE_TYPE);
159 $diff_field_count=0;
160 foreach ($temp_field_array as $field_array) {
161
162
163     if (show_field($field_array)
164     ) {
165
166         $select_row_curr_field_value = null;
167         $b_values_different = false;
168         $section_name='merge_row_similar';
169
170         //Prcoess locaton of the field. if values are different show field in first section. else 2nd.
171         $select_row_curr_field_value = $focus->merge_bean->$field_array['name'];
172         foreach ($merge_ids_array as $id) {
173             if (($mergeBeanArray[$id]-> $field_array['name']=='' and $select_row_curr_field_value =='') or $mergeBeanArray[$id]-> $field_array['name'] == $select_row_curr_field_value ) {
174                 $section_name='merge_row_similar';
175             } else  {
176                 $section_name='merge_row_diff';
177                 $diff_field_count++;
178                 break; //foreach
179             }
180         }
181         //check for vname in mod strings first, then app, else just display name
182         $col_name = $field_array['name'];
183         if (isset ($focus->merge_bean_strings[$field_array['vname']]) && $focus->merge_bean_strings[$field_array['vname']] != '')
184             $xtpl->assign("FIELD_LABEL", $focus->merge_bean_strings[$field_array['vname']]);
185         elseif (isset ($app_strings[$field_array['vname']]) && $app_strings[$field_array['vname']] != '') $xtpl->assign("FIELD_LABEL", $app_strings[$field_array['vname']]);
186         else
187              $xtpl->assign("FIELD_LABEL", $field_array['name']);
188         //if required add signage.
189         if (!empty($focus->merge_bean->required_fields[$col_name]) or $col_name=='team_name') {
190             $xtpl->assign("REQUIRED_SYMBOL","<span class='required'>".$app_strings['LBL_REQUIRED_SYMBOL']."</span>");
191         } else {
192             $xtpl->assign("REQUIRED_SYMBOL","");
193         }
194
195         $xtpl->assign("CELL_WIDTH", "20%");
196         $xtpl->parse("main.".$section_name.".merge_cell_label");
197
198         if (isset ($field_array['custom_type']) && $field_array['custom_type'] != '')
199             $field_check = $field_array['custom_type'];
200         else
201             $field_check = $field_array['type'];
202
203
204         if(preg_match('/.*?_address_street$/', $field_array['name'])) {
205            $field_check = 'text';
206         }
207
208         $xtpl->assign("EDIT_FIELD_NAME", $field_array['name']);
209         $xtpl->assign("TAB_INDEX", $field_count);
210
211         switch ($field_check) {
212             case ('name') :
213             case ('varchar') :
214             case ('phone') :
215             case ('num') :
216             case ('email') :
217             case ('custom_fields') :
218             case ('url') :
219             case ('int') :
220             case ('float') :
221             case ('double') :
222             case ('currency') :
223
224                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
225                 $xtpl->assign("CELL_WIDTH", $col_width);
226                 $xtpl->parse("main.".$section_name.".merge_cell_edit_text");
227                 break;
228             case ('text') :
229                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
230                 $xtpl->assign("CELL_WIDTH", $col_width);
231                 $xtpl->parse("main.".$section_name.".merge_cell_edit_textarea");
232                 break;
233             case ('enum') :
234                 $xtpl->assign("SELECT_OPTIONS", get_select_options_with_id($app_list_strings[$field_array['options']], $select_row_curr_field_value));
235                 $xtpl->assign("CELL_WIDTH",$col_width);
236                 $xtpl->parse("main.".$section_name.".merge_cell_edit_dropdown");
237                 break;
238             case ('multienum') :
239                 $select_row_curr_field_value = unencodeMultienum($select_row_curr_field_value);
240                 $xtpl->assign("SELECT_OPTIONS", get_select_options_with_id($app_list_strings[$field_array['options']], $select_row_curr_field_value));
241                 $xtpl->assign("CELL_WIDTH",$col_width);
242                 $xtpl->parse("main.".$section_name.".merge_cell_edit_multidropdown");
243                 break;
244                 //popup fields need to be fixed.., cant automate with vardefs
245             case ('relate') :
246                 if(!empty($field_array['link'])) {
247                     $exclude[$field_array['link']] = $field_array['link'];
248                 }
249             case ('link') :
250                 //get_related_name
251                 if (empty($select_row_curr_field_value)) {
252                     $related_name=get_related_name($field_array,$focus->merge_bean->$field_array['id_name']);
253                     if ($related_name !== false ) {
254                        $select_row_curr_field_value=$related_name;
255                     }
256                 }
257                 if($field_check == 'link') {//relate type should not enter this.
258                     $exclude[$field_array['name']] = $field_array['name'];
259                 }
260                 $xtpl->assign("POPUP_ID_FIELD", $field_array['id_name']);
261                 $xtpl->assign("POPUP_NAME_FIELD", $field_array['name']);
262                 $xtpl->assign("POPUP_NAME_VALUE", $select_row_curr_field_value);
263                 $xtpl->assign("POPUP_ID_VALUE", $focus->merge_bean-> $field_array['id_name']);
264                 $xtpl->assign("POPUP_MODULE", $field_array['module']);
265                 $xtpl->assign("CELL_WIDTH", $col_width);
266                 $xtpl->assign("MERGED_LINKS", implode(',', $exclude));
267
268                 $popup_data = array ('call_back_function' => 'set_return', 'form_name' => 'EditView', 'field_to_name_array' => array ('id' => $field_array['id_name'], 'name' => $field_array['name'],),);
269                 $xtpl->assign('ENCODED_POPUP_DATA', $json->encode($popup_data));
270
271                 $xtpl->parse("main.".$section_name.".merge_cell_edit_popup");
272                 break;
273             case ('bool') :
274                 if (($select_row_curr_field_value == '1' || $select_row_curr_field_value == 'yes' || $select_row_curr_field_value == 'on') && !empty($select_row_curr_field_value))
275                     $xtpl->assign("EDIT_FIELD_VALUE", " checked");
276                 else
277                     $xtpl->assign("EDIT_FIELD_VALUE", "");
278
279                 $xtpl->assign("CELL_WIDTH", $col_width);
280                 $xtpl->parse("main.".$section_name.".merge_cell_edit_checkbox");
281                 break;
282             case ('date') :
283             case ('datetime') :
284                 $xtpl->assign("CALENDAR_LANG", "en");
285                 $xtpl->assign("USER_DATEFORMAT", '('.$timedate->get_user_date_format().')');
286                 $xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
287                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
288                 $xtpl->assign("CELL_WIDTH", $col_width);
289                 $xtpl->assign("THEME", $theme);
290                 $xtpl->parse("main.".$section_name.".merge_cell_edit_date");
291                 break;
292                         case ('datetimecombo') :
293                                 $xtpl->assign("CALENDAR_LANG", "en");
294                 $xtpl->assign("USER_DATEFORMAT", $timedate->get_user_time_format());
295                 $xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
296                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
297                 $xtpl->assign("CELL_WIDTH", $col_width);
298                 $xtpl->assign("THEME", $theme);
299                 $xtpl->parse("main.".$section_name.".merge_cell_edit_datetime");
300                 break;
301             default :
302                 break;
303         }
304
305         //render a column for each selected record to merge
306         foreach ($merge_ids_array as $id) {
307             $xtpl->assign("CELL_WIDTH", $col_width);
308             $field_name=null;
309             switch ($field_check) {
310                 case ('bool') :
311                     if (($mergeBeanArray[$id]->$field_array['name'] == '1' || $mergeBeanArray[$id]->$field_array['name'] == 'yes' || $mergeBeanArray[$id]->$field_array['name'] == 'on') && !empty($mergeBeanArray[$id]->$field_array['name'])) {
312                         $xtpl->assign("FIELD_VALUE", " checked");
313                     } else {
314                         $xtpl->assign("FIELD_VALUE", "");
315                     }
316                     $field_name="main.".$section_name.".merge_cell_field_value_checkbox";
317                     break;
318                 case ('enum') :
319                     if ($mergeBeanArray[$id]-> $field_array['name'] != '' and isset($field_array['options']) and isset($app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']])) {
320                         display_field_value( $app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']]);
321                     } else {
322                         display_field_value($mergeBeanArray[$id]-> $field_array['name']);
323                     }
324                     $field_name="main.".$section_name.".merge_cell_field_value";
325                     break;
326                 case ('multienum') :
327                     if ($mergeBeanArray[$id]-> $field_array['name'] != '' and isset($field_array['options']) and isset($app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']])) {
328                         display_field_value(str_replace("^","",$app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']]));
329                     } else {
330                         display_field_value(str_replace("^","",$mergeBeanArray[$id]-> $field_array['name']));
331                     }
332                     $field_name="main.".$section_name.".merge_cell_field_value";
333                     break;
334                 case ('relate') :
335                 case ('link') :
336                     $related_name=false;
337                     if (empty($mergeBeanArray[$id]-> $field_array['name']) && !empty($mergeBeanArray[$id]-> $field_array['id_name'])) {
338                        $related_name=get_related_name($field_array,$mergeBeanArray[$id]-> $field_array['id_name']);
339                        if ($related_name !== false) {
340                             $mergeBeanArray[$id]-> $field_array['name']=$related_name;
341                        }
342                     }
343                     display_field_value($mergeBeanArray[$id]-> $field_array['name']);
344                     $field_name="main.".$section_name.".merge_cell_field_value";
345                     break;
346                 default :
347                     display_field_value($mergeBeanArray[$id]-> $field_array['name']);
348                     $field_name="main.".$section_name.".merge_cell_field_value";
349                     break;
350             }
351
352             $json_data = array ('field_name' => $field_array['name'], 'field_type' => $field_check,);
353             //add an array of fields/values to the json array
354             //for setting all the values for merge
355             if ($field_check == 'relate' or $field_check == 'link') {
356                 $temp_array = Array ();
357                 $json_data['popup_fields'] = Array ($field_array['name'] => $mergeBeanArray[$id]-> $field_array['name'], $field_array['id_name'] => $mergeBeanArray[$id]-> $field_array['id_name'],);
358             } else if($field_check == 'teamset') {
359                 $json_data['field_value'] = TeamSetManager::getCommaDelimitedTeams($mergeBeanArray[$id]->team_set_id, $mergeBeanArray[$id]->team_id, true);
360                 $json_data['field_value2'] = TeamSetManager::getTeamsFromSet($mergeBeanArray[$id]->team_set_id);
361                 $json_data['field_value3'] =  $mergeBeanArray[$id]->team_set_id;
362             } else if($field_check == 'multienum') {
363                 $json_data['field_value'] = unencodeMultienum($mergeBeanArray[$id]-> $field_array['name']);
364             } else {
365                 $json_data['field_value'] = $mergeBeanArray[$id]-> $field_array['name'];
366             }
367             $encoded_json_data = $json->encode($json_data);
368             $xtpl->assign('ENCODED_JSON_DATA', $encoded_json_data);
369             $xtpl->parse($field_name);
370         }
371
372         $xtpl->parse("main.".$section_name);
373         $field_count ++;
374     }
375 }
376
377 $header_cols= array();
378 foreach ($merge_ids_array as $id) {
379   $td="<td width='$col_width' valign='top' class='dataLabel' align='left'><input type='button' class='button' id='$id' onclick=\"change_primary(this,'{$id}');\" value='<<'>&nbsp;{$mod_strings['LBL_CHANGE_PARENT']}";
380   if (count($merge_ids_array) > 1) {
381     $td.="&nbsp;|<a id='remove_$id' onclick=\"remove_me(this,'{$id}');\" href='#' >{$mod_strings['LBL_REMOVE_FROM_MERGE']}</a>";
382   }
383   $td.="</td>";
384   $header_cols[]=$td;
385 }
386
387 if ($diff_field_count>0) {
388     $xtpl->assign("DIFF_HEADER","<tr height='20'><td colspan=2><strong>{$mod_strings['LBL_DIFF_COL_VALUES']}</strong></td>".implode(' ',$header_cols)."</tr>");
389     $xtpl->assign("SIMILAR_HEADER","<tr height='20'><td colspan=20><strong>{$mod_strings['LBL_SAME_COL_VALUES']}</strong></td></tr>");
390     $xtpl->assign("GROUP_PARTITION","<tr height=3><td colspan=20' class='listViewHRS1'></td></tr>");
391 } else {
392     $xtpl->assign("SIMILAR_HEADER","<tr height='20'><td colspan=2><strong>{$mod_strings['LBL_SAME_COL_VALUES']}</strong></td>".implode(' ',$header_cols)."</tr>");
393 }
394 $merge_verify=$mod_strings['LBL_DELETE_MESSAGE'].'\\n';
395 foreach ($merge_records_names as $name) {
396         $merge_verify.= $name."\\n";
397 }
398 $merge_verify.='\\n'.$mod_strings['LBL_PROCEED'];
399 $xtpl->assign("MERGE_VERIFY",$merge_verify);
400
401 global $beanList;
402
403 //Jenny - Bug 8386 - The object_name couldn't be found because it was searching for
404 // 'Case' instead of 'aCase'.
405 if ($focus->merge_bean->object_name == 'Case') {
406     $focus->merge_bean->object_name = 'aCase';
407 }
408
409 $mod=array_search($focus->merge_bean->object_name,$beanList);
410 $mod_strings = return_module_language($current_language, $mod);
411
412 //add javascript for required fields enforcement.
413
414 $javascript = new javascript();
415 $javascript->setFormName('EditView');
416 $javascript->setSugarBean($focus->merge_bean);
417 $javascript->addAllFields('');
418 if (isset($focus->merge_bean->field_defs['team_name'])) {
419     $javascript->addFieldGeneric('team_name', 'varchar', $app_strings['LBL_TEAM'] ,'true');
420 }
421 $xtpl->assign("VALIDATION_JS", $javascript->getScript());
422
423 $xtpl->parse("main");
424 $xtpl->out("main");
425
426 /*
427  * function truncates values to max_data_legth and adds the complete value as hover text.
428  */
429 function display_field_value($value) {
430     global $xtpl, $max_data_length, $mod_strings;
431     if (strlen($value)-$max_data_length > 3) {
432         $xtpl->assign("FIELD_VALUE", substr($value,0,$max_data_length).'...');
433     } else {
434         $xtpl->assign("FIELD_VALUE", $value);
435     }
436     $xtpl->assign("HOVER_TEXT", $mod_strings['LBL_MERGE_VALUE_OVER'] .': ' . $value);
437 }
438 /*
439  * implements the rules that decide which fields will participate in a merge.
440  */
441 function show_field($field_def) {
442     global $filter_for_valid_editable_attributes,$invalid_attribute_by_name;
443     //field in invalid attributes list?
444     if (isset($invalid_attribute_by_name[$field_def['name']])) {
445         return false;
446     }
447     //field has 'duplicate_merge property set to disabled?'
448     if (isset($field_def['duplicate_merge']) ) {
449         if ($field_def['duplicate_merge']=='disabled' or $field_def['duplicate_merge']==false) {
450             return false;
451         }
452         if ($field_def['duplicate_merge']=='enabled' or $field_def['duplicate_merge']==true) {
453             return true;
454         }
455     }
456
457     //field has auto_increment set to true do not participate in merge.
458     //we have a unique index on that field.
459     if (isset($field_def['auto_increment']) and $field_def['auto_increment']==true) {
460         return false;
461     }
462
463     //set required attribute values in $field_def
464     if (!isset($field_def['source']) or empty($field_def['source'])) {
465         $field_def['source']='db';
466     }
467
468     if (!isset($field_def['dbType']) or empty($field_def['dbType']) and isset($field_def['type'])) {
469         $field_def['dbType']=$field_def['type'];
470     }
471
472     foreach ($filter_for_valid_editable_attributes as $attribute_set) {
473         $b_all=false;
474         foreach ($attribute_set as $attr=>$value) {
475             if (isset($field_def[$attr]) and $field_def[$attr]==$value) {
476                 $b_all=true;
477             } else {
478                 $b_all=false;
479                 break;
480             }
481         }
482         if ($b_all) {
483             return true;
484         }
485     }
486     return false;
487 }
488 /* if the attribute of type relate and name is empty fetch using the vardef entries.
489  *
490  */
491 function get_related_name($field_def,$id_value) {
492     if (!empty($field_def['rname']) && !empty($field_def['id_name']) && !empty($field_def['table'])) {
493         if (!empty($id_value)) {
494
495             //default the column name to rname in vardefs
496             $col_name = $field_def['rname'];
497             //if this module is non db and has a module set, then check to see if this field should be concatenated
498             if (!empty($field_def['module']) && $field_def['source'] == 'non-db'){
499                 global $beanList, $beanFiles;
500                   //get the bean field defs based on the module param
501                   $bean = $beanList[$field_def['module']];
502                   require_once ($beanFiles[$bean]);
503                   $focus = new $bean();
504                   if(!empty( $focus->field_defs[$field_def['rname']])){
505                         $related_def = $focus->field_defs[$field_def['rname']];
506                         //if field defs has concat field array set, then concatenate values
507                         if(isset($related_def['db_concat_fields']) && !empty($related_def['db_concat_fields'])){
508                         $col_name = $focus->db->concat($field_def['table'], $related_def['db_concat_fields']);
509                         }
510                   }
511             }
512
513             $query = "select ".$col_name." from " .$field_def['table'] ." where id='$id_value'";
514
515             $result=$GLOBALS['db']->query($query);
516             $row=$GLOBALS['db']->fetchByAssoc($result);
517             if (!empty($row[$field_def['rname']])) {
518                 return $row[$field_def['rname']];
519             }
520         }
521     }
522     return false;
523 }
524 ?>