]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MergeRecords/Step3.php
Release 6.5.16
[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-2013 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[] = $mod_strings['LBL_MODULE_NAME'];
115 $params[] = $focus->merge_bean->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
212         //check to see if the value of the field is from a function
213         $valueFormatted = false;
214         if(!empty($field_array['function'])){
215
216             //process the function array if it exists
217             $function = $field_array['function'];
218             if(is_array($function) && isset($function['name'])){
219                 $function = $field_array['function']['name'];
220             }else{
221                 $function = $field_array['function'];
222             }
223             if(!empty($field_array['function']['include']) && file_exists($field_array['function']['include']))
224             {
225                 require_once($field_array['function']['include']);
226             }
227
228             //if field is enum or multi enum, lets make sure we are returning options as html, as this is what
229             //merge step3 expects
230             if($field_check == 'multienum' || $field_check == 'enum'){
231                 if(!empty($field_array['function']['returns']) && $field_array['function']['returns'] == 'html'){
232
233                     //use valueformatted to hold the returned options
234                     $valueFormatted = call_user_func($function,  $focus->merge_bean, $field_array['name'], $select_row_curr_field_value, 'Import');
235
236                 }else{
237                     //if no html was returned, we have an array of options, lets create the html markup
238                     $field_array['options'] = call_user_func($function);
239
240                     foreach( $field_array['options'] as $k=>$v){
241                         //process and mark the field as selected if needed
242                         if($field_check == 'enum' && $select_row_curr_field_value == $k){
243                             $valueFormatted .="<option value='$k' selected>$v</option>";
244                         }elseif($field_check == 'multienum' && !empty($k) && strpos($select_row_curr_field_value, $k) !== false){
245                             $valueFormatted .="<option value='$k' selected>$v</option>";
246                         }else{
247                             
248                             $valueFormatted .="<option value='$k'>$v</option>";
249                         }
250                     }
251                 }
252
253             }else{
254             
255                 $select_row_curr_field_value = call_user_func($function);
256             }
257         }
258
259         switch ($field_check) {
260             case ('name') :
261             case ('varchar') :
262             case ('phone') :
263             case ('num') :
264             case ('email') :
265             case ('custom_fields') :
266             case ('url') :
267             case ('int') :
268             case ('float') :
269             case ('double') :
270             case ('currency') :
271
272                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
273                 $xtpl->assign("CELL_WIDTH", $col_width);
274                 $xtpl->parse("main.".$section_name.".merge_cell_edit_text");
275                 break;
276             case ('text') :
277                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
278                 $xtpl->assign("CELL_WIDTH", $col_width);
279                 $xtpl->parse("main.".$section_name.".merge_cell_edit_textarea");
280                 break;
281             case ('enum') :
282
283                 //assign value(s) directly if it is derived from a function
284                 if(empty($field_array['function'])){
285                     $xtpl->assign("SELECT_OPTIONS", get_select_options_with_id($app_list_strings[$field_array['options']], $select_row_curr_field_value));
286                 }elseif(is_string($valueFormatted)){
287                     //if this field has a function, then assign values directly
288                     $xtpl->assign("SELECT_OPTIONS", $valueFormatted);
289                 }
290                 $xtpl->assign("CELL_WIDTH",$col_width);
291                 $xtpl->parse("main.".$section_name.".merge_cell_edit_dropdown");
292                 break;
293             case ('multienum') :
294
295                 //assign value(s) directly if it is derived from a function
296                 if(empty($field_array['function'])){
297                     $select_row_curr_field_value = unencodeMultienum($select_row_curr_field_value);
298                     $xtpl->assign("SELECT_OPTIONS", get_select_options_with_id($app_list_strings[$field_array['options']], $select_row_curr_field_value));
299                 }elseif(is_string($valueFormatted)){
300                     $xtpl->assign("SELECT_OPTIONS", $valueFormatted);
301                 }
302
303                 $xtpl->assign("CELL_WIDTH",$col_width);
304                 $xtpl->parse("main.".$section_name.".merge_cell_edit_multidropdown");
305                 break;
306                 //popup fields need to be fixed.., cant automate with vardefs
307             case ('relate') :
308                 if(!empty($field_array['link'])) {
309                     $exclude[$field_array['link']] = $field_array['link'];
310                 }
311             case ('link') :
312                 //get_related_name
313                 if (empty($select_row_curr_field_value)) {
314                     $related_name=get_related_name($field_array,$focus->merge_bean->$field_array['id_name']);
315                     if ($related_name !== false ) {
316                        $select_row_curr_field_value=$related_name;
317                     }
318                 }
319                 if($field_check == 'link') {//relate type should not enter this.
320                     $exclude[$field_array['name']] = $field_array['name'];
321                 }
322                 $xtpl->assign("POPUP_ID_FIELD", $field_array['id_name']);
323                 $xtpl->assign("POPUP_NAME_FIELD", $field_array['name']);
324                 $xtpl->assign("POPUP_NAME_VALUE", $select_row_curr_field_value);
325                 $xtpl->assign("POPUP_ID_VALUE", $focus->merge_bean-> $field_array['id_name']);
326                 $xtpl->assign("POPUP_MODULE", $field_array['module']);
327                 $xtpl->assign("CELL_WIDTH", $col_width);
328                 $xtpl->assign("MERGED_LINKS", implode(',', $exclude));
329
330                 $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'],),);
331                 $xtpl->assign('ENCODED_POPUP_DATA', $json->encode($popup_data));
332
333                 $xtpl->parse("main.".$section_name.".merge_cell_edit_popup");
334                 break;
335             case ('bool') :
336                 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))
337                     $xtpl->assign("EDIT_FIELD_VALUE", " checked");
338                 else
339                     $xtpl->assign("EDIT_FIELD_VALUE", "");
340
341                 $xtpl->assign("CELL_WIDTH", $col_width);
342                 $xtpl->parse("main.".$section_name.".merge_cell_edit_checkbox");
343                 break;
344             case ('date') :
345             case ('datetime') :
346                 $xtpl->assign("CALENDAR_LANG", "en");
347                 $xtpl->assign("USER_DATEFORMAT", '('.$timedate->get_user_date_format().')');
348                 $xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
349                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
350                 $xtpl->assign("CELL_WIDTH", $col_width);
351                 $xtpl->assign("THEME", $theme);
352                 $xtpl->parse("main.".$section_name.".merge_cell_edit_date");
353                 break;
354                         case ('datetimecombo') :
355                                 $xtpl->assign("CALENDAR_LANG", "en");
356                 $xtpl->assign("USER_DATEFORMAT", $timedate->get_user_time_format());
357                 $xtpl->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
358                 $xtpl->assign("EDIT_FIELD_VALUE", $select_row_curr_field_value);
359                 $xtpl->assign("CELL_WIDTH", $col_width);
360                 $xtpl->assign("THEME", $theme);
361                 $xtpl->parse("main.".$section_name.".merge_cell_edit_datetime");
362                 break;
363             default :
364                 break;
365         }
366
367         //render a column for each selected record to merge
368         foreach ($merge_ids_array as $id) {
369             $xtpl->assign("CELL_WIDTH", $col_width);
370             $field_name=null;
371             switch ($field_check) {
372                 case ('bool') :
373                     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'])) {
374                         $xtpl->assign("FIELD_VALUE", " checked");
375                     } else {
376                         $xtpl->assign("FIELD_VALUE", "");
377                     }
378                     $field_name="main.".$section_name.".merge_cell_field_value_checkbox";
379                     break;
380                 case ('enum') :
381                     if(!empty($field_array['function']) && !empty($field_array['options']) && !empty($mergeBeanArray[$id]-> $field_array['name'])){
382                         //if fieldoptions were set from a function, get the value directly
383                         display_field_value($field_array['options'][$mergeBeanArray[$id]-> $field_array['name']]);
384                     
385                     }else if ($mergeBeanArray[$id]-> $field_array['name'] != '' and isset($field_array['options']) and isset($app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']])) {
386                         display_field_value( $app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']]);
387                     } else {
388                         display_field_value($mergeBeanArray[$id]-> $field_array['name']);
389                     }
390                     $field_name="main.".$section_name.".merge_cell_field_value";
391                     break;
392                 case ('multienum') :
393                      if(!empty($field_array['function']) && !empty($field_array['options']) && !empty($mergeBeanArray[$id]-> $field_array['name'])){
394                         //if fieldoptions were set from a function, get the value directly
395                         $displayME = str_replace("^","",$mergeBeanArray[$id]-> $field_array['name']);
396                         $meVals = explode(',', $displayME);
397                         //iterate through each entry and get the Options value
398                         foreach($meVals as $optionIndex){
399                             $displayME = str_replace($optionIndex,$field_array['options'][$optionIndex],$displayME);
400                         }
401                         display_field_value($displayME);
402
403                     }else if ($mergeBeanArray[$id]-> $field_array['name'] != '' and isset($field_array['options']) and isset($app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']])) {
404                         display_field_value(str_replace("^","",$app_list_strings[$field_array['options']][$mergeBeanArray[$id]-> $field_array['name']]));
405                     } else {
406                         display_field_value(str_replace("^","",$mergeBeanArray[$id]-> $field_array['name']));
407                     }
408                     $field_name="main.".$section_name.".merge_cell_field_value";
409                     break;
410                 case ('relate') :
411                 case ('link') :
412                     $related_name=false;
413                     if (empty($mergeBeanArray[$id]-> $field_array['name']) && !empty($mergeBeanArray[$id]-> $field_array['id_name'])) {
414                        $related_name=get_related_name($field_array,$mergeBeanArray[$id]-> $field_array['id_name']);
415                        if ($related_name !== false) {
416                             $mergeBeanArray[$id]-> $field_array['name']=$related_name;
417                        }
418                     }
419                     display_field_value($mergeBeanArray[$id]-> $field_array['name']);
420                     $field_name="main.".$section_name.".merge_cell_field_value";
421                     break;
422                 default :
423                     display_field_value($mergeBeanArray[$id]-> $field_array['name']);
424                     $field_name="main.".$section_name.".merge_cell_field_value";
425                     break;
426             }
427
428             $json_data = array ('field_name' => $field_array['name'], 'field_type' => $field_check,);
429             //add an array of fields/values to the json array
430             //for setting all the values for merge
431             if ($field_check == 'relate' or $field_check == 'link') {
432                 $temp_array = Array ();
433                 $json_data['popup_fields'] = Array ($field_array['name'] => $mergeBeanArray[$id]-> $field_array['name'], $field_array['id_name'] => $mergeBeanArray[$id]-> $field_array['id_name'],);
434             } else if($field_check == 'teamset') {
435                 $json_data['field_value'] = TeamSetManager::getCommaDelimitedTeams($mergeBeanArray[$id]->team_set_id, $mergeBeanArray[$id]->team_id, true);
436                 $json_data['field_value2'] = TeamSetManager::getTeamsFromSet($mergeBeanArray[$id]->team_set_id);
437                 $json_data['field_value3'] =  $mergeBeanArray[$id]->team_set_id;
438             } else if($field_check == 'multienum') {
439                 $json_data['field_value'] = unencodeMultienum($mergeBeanArray[$id]-> $field_array['name']);
440             } else {
441                 $json_data['field_value'] = $mergeBeanArray[$id]-> $field_array['name'];
442             }
443             $encoded_json_data = $json->encode($json_data);
444             $xtpl->assign('ENCODED_JSON_DATA', $encoded_json_data);
445             $xtpl->parse($field_name);
446         }
447
448         $xtpl->parse("main.".$section_name);
449         $field_count ++;
450     }
451 }
452
453 $header_cols= array();
454 foreach ($merge_ids_array as $id) {
455   $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']}";
456   if (count($merge_ids_array) > 1) {
457     $td.="&nbsp;|<a id='remove_$id' onclick=\"remove_me(this,'{$id}');\" href='#' >{$mod_strings['LBL_REMOVE_FROM_MERGE']}</a>";
458   }
459   $td.="</td>";
460   $header_cols[]=$td;
461 }
462
463 if ($diff_field_count>0) {
464     $xtpl->assign("DIFF_HEADER","<tr height='20'><td colspan=2><strong>{$mod_strings['LBL_DIFF_COL_VALUES']}</strong></td>".implode(' ',$header_cols)."</tr>");
465     $xtpl->assign("SIMILAR_HEADER","<tr height='20'><td colspan=20><strong>{$mod_strings['LBL_SAME_COL_VALUES']}</strong></td></tr>");
466     $xtpl->assign("GROUP_PARTITION","<tr height=3><td colspan=20' class='listViewHRS1'></td></tr>");
467 } else {
468     $xtpl->assign("SIMILAR_HEADER","<tr height='20'><td colspan=2><strong>{$mod_strings['LBL_SAME_COL_VALUES']}</strong></td>".implode(' ',$header_cols)."</tr>");
469 }
470 $merge_verify=$mod_strings['LBL_DELETE_MESSAGE'].'\\n';
471 foreach ($merge_records_names as $name) {
472         $merge_verify.= $name."\\n";
473 }
474 $merge_verify.='\\n'.$mod_strings['LBL_PROCEED'];
475 $xtpl->assign("MERGE_VERIFY",$merge_verify);
476
477 global $beanList;
478
479 //Jenny - Bug 8386 - The object_name couldn't be found because it was searching for
480 // 'Case' instead of 'aCase'.
481 if ($focus->merge_bean->object_name == 'Case') {
482     $focus->merge_bean->object_name = 'aCase';
483 }
484
485 $mod=array_search($focus->merge_bean->object_name,$beanList);
486 $mod_strings = return_module_language($current_language, $mod);
487
488 //add javascript for required fields enforcement.
489
490 $javascript = new javascript();
491 $javascript->setFormName('EditView');
492 $javascript->setSugarBean($focus->merge_bean);
493 $javascript->addAllFields('');
494 if (isset($focus->merge_bean->field_defs['team_name'])) {
495     $javascript->addFieldGeneric('team_name', 'varchar', $app_strings['LBL_TEAM'] ,'true');
496 }
497 $xtpl->assign("VALIDATION_JS", $javascript->getScript());
498
499 $xtpl->parse("main");
500 $xtpl->out("main");
501
502 /*
503  * function truncates values to max_data_legth and adds the complete value as hover text.
504  */
505 function display_field_value($value) {
506     global $xtpl, $max_data_length, $mod_strings;
507     if (strlen($value)-$max_data_length > 3) {
508         $xtpl->assign("FIELD_VALUE", substr($value,0,$max_data_length).'...');
509     } else {
510         $xtpl->assign("FIELD_VALUE", $value);
511     }
512     $xtpl->assign("HOVER_TEXT", $mod_strings['LBL_MERGE_VALUE_OVER'] .': ' . $value);
513 }
514 /*
515  * implements the rules that decide which fields will participate in a merge.
516  */
517 function show_field($field_def) {
518     global $filter_for_valid_editable_attributes,$invalid_attribute_by_name;
519     //field in invalid attributes list?
520     if (isset($invalid_attribute_by_name[$field_def['name']])) {
521         return false;
522     }
523     //field has 'duplicate_merge property set to disabled?'
524     if (isset($field_def['duplicate_merge']) ) {
525         if ($field_def['duplicate_merge']=='disabled' or $field_def['duplicate_merge']==false) {
526             return false;
527         }
528         if ($field_def['duplicate_merge']=='enabled' or $field_def['duplicate_merge']==true) {
529             return true;
530         }
531     }
532
533     //field has auto_increment set to true do not participate in merge.
534     //we have a unique index on that field.
535     if (isset($field_def['auto_increment']) and $field_def['auto_increment']==true) {
536         return false;
537     }
538
539     //set required attribute values in $field_def
540     if (!isset($field_def['source']) or empty($field_def['source'])) {
541         $field_def['source']='db';
542     }
543
544     if (!isset($field_def['dbType']) or empty($field_def['dbType']) and isset($field_def['type'])) {
545         $field_def['dbType']=$field_def['type'];
546     }
547
548     foreach ($filter_for_valid_editable_attributes as $attribute_set) {
549         $b_all=false;
550         foreach ($attribute_set as $attr=>$value) {
551             if (isset($field_def[$attr]) and $field_def[$attr]==$value) {
552                 $b_all=true;
553             } else {
554                 $b_all=false;
555                 break;
556             }
557         }
558         if ($b_all) {
559             return true;
560         }
561     }
562     return false;
563 }
564 /* if the attribute of type relate and name is empty fetch using the vardef entries.
565  *
566  */
567 function get_related_name($field_def,$id_value) {
568     if (!empty($field_def['rname']) && !empty($field_def['id_name']) && !empty($field_def['table'])) {
569         if (!empty($id_value)) {
570
571             //default the column name to rname in vardefs
572             $col_name = $field_def['rname'];
573             //if this module is non db and has a module set, then check to see if this field should be concatenated
574             if (!empty($field_def['module']) && $field_def['source'] == 'non-db'){
575                 global $beanList, $beanFiles;
576                   //get the bean field defs based on the module param
577                   $bean = $beanList[$field_def['module']];
578                   require_once ($beanFiles[$bean]);
579                   $focus = new $bean();
580                   if(!empty( $focus->field_defs[$field_def['rname']])){
581                         $related_def = $focus->field_defs[$field_def['rname']];
582                         //if field defs has concat field array set, then concatenate values
583                         if(isset($related_def['db_concat_fields']) && !empty($related_def['db_concat_fields'])){
584                         $col_name = $focus->db->concat($field_def['table'], $related_def['db_concat_fields']);
585                         }
586                   }
587             }
588
589             $query = "select ".$col_name." from " .$field_def['table'] ." where id='$id_value'";
590
591             $result=$GLOBALS['db']->query($query);
592             $row=$GLOBALS['db']->fetchByAssoc($result);
593             if (!empty($row[$field_def['rname']])) {
594                 return $row[$field_def['rname']];
595             }
596         }
597     }
598     return false;
599 }
600 ?>