]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/MergeRecords/Step1.php
Release 6.4.0
[Github/sugarcrm.git] / modules / MergeRecords / Step1.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48
49 require_once('include/JSON.php');
50
51 global $app_strings;
52 global $mod_strings;
53 global $app_list_strings;
54 global $current_language;
55 global $currentModule;
56 global $theme;
57
58 $json=new JSON(JSON_LOOSE_TYPE);
59
60 $current_module_strings = return_module_language($current_language, 'MergeRecords');
61
62 if (!isset($where)) $where = "";
63
64 $focus = new MergeRecord();
65
66 ////////////////////////////////////////////////////////////
67 //get instance of master record and retrieve related record
68 //and items
69 ////////////////////////////////////////////////////////////
70 $focus->merge_module = $_REQUEST['return_module'];
71 $focus->load_merge_bean($focus->merge_module, true, $_REQUEST['record']);
72
73
74 //get all available column fields
75 //TO DO: add custom field handling
76 $avail_fields=array();
77 $sel_fields=array();
78 $temp_field_array = $focus->merge_bean->field_defs;
79 $bean_data=array();
80 foreach($temp_field_array as $field_array)
81 {
82         if (isset($field_array['merge_filter']) 
83         ) {
84                 if (strtolower($field_array['merge_filter'])=='enabled' or strtolower($field_array['merge_filter'])=='selected') {
85                         $col_name = $field_array['name'];
86
87                             
88                         if(!isset($focus->merge_bean_strings[$field_array['vname']])) {
89                                 $col_label = $col_name;
90                         }
91                         else {
92                                 $col_label = str_replace(':', '', $focus->merge_bean_strings[$field_array['vname']]);
93                         }
94                         
95                         if (strtolower($field_array['merge_filter'])=='selected') {
96                                 $sel_fields[$col_name]=$col_label;
97                         } else {
98                 $avail_fields[$col_name] = $col_label;
99             }
100                         
101                         $bean_data[$col_name]=$focus->merge_bean->$col_name;
102                 }
103         }
104 }
105
106 /////////////////////////////////////////////////////////
107
108 //Print the master record header to the page
109 $params = array();
110 $params[] = "<a href='index.php?module={$focus->merge_bean->module_dir}&action=index'>{$GLOBALS['app_list_strings']['moduleList'][$focus->merge_bean->module_dir]}</a>";
111 $params[] = "<a href='index.php?module={$focus->merge_bean->module_dir}&action=DetailView&record={$focus->merge_bean->id}'>{$focus->merge_bean->name}</a>";
112 $params[] = $mod_strings['LBL_LBL_MERGE_RECORDS_STEP_1'];
113 echo getClassicModuleTitle($focus->merge_bean->module_dir, $params, true);
114
115 $xtpl = new XTemplate ('modules/MergeRecords/Step1.html');
116 $xtpl->assign("MOD", $mod_strings);
117 $xtpl->assign("APP", $app_strings);
118 $xtpl->assign("BEANDATA",$json->encode($bean_data));
119 //This is for the implemetation of finding all dupes for a module, not just
120 //dupes for a particular record
121 //commenting this out for now
122 //$choose_master_by_options = array('First Record Found', 'Most Recent Record', 'Oldest Record', 'Record Containing Most Data');
123 //$xtpl->assign("CHOOSE_MASTER_BY_OPTIONS", get_select_options_with_id($choose_master_by_options, 'First Record Found'));
124
125 $xtpl->assign("MERGE_MODULE", $focus->merge_module);
126 $xtpl->assign("ID", $focus->merge_bean->id);
127
128 $xtpl->assign("FIELD_AVAIL_OPTIONS", get_select_options_with_id($avail_fields,''));
129 $xtpl->assign("LBL_ADD_BUTTON", translate('LBL_ADD_BUTTON'));
130
131 if(isset($_REQUEST['return_id'])) $xtpl->assign("RETURN_ID", $_REQUEST['return_id']);
132 $xtpl->assign("RETURN_ACTION", $_REQUEST['return_action']);
133 $xtpl->assign("RETURN_MODULE", $_REQUEST['return_module']);
134
135 //set the url
136 $port=null;
137 if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
138     $port = $_SERVER['SERVER_PORT'];
139 }
140 $xtpl->assign("URL", appendPortToHost($sugar_config['site_url'], $port));
141 //set images
142 $xtpl->assign("RIGHTARROW_BIG_IMAGE", SugarThemeRegistry::current()->getImageURL('rightarrow_big.gif'));
143 $xtpl->assign("DELETE_INLINE_IMAGE", SugarThemeRegistry::current()->getImageURL('delete_inline.gif'));
144
145 //process preloaded filter.
146 $pre_loaded=null;
147 foreach ($sel_fields as $colName=>$colLabel) {
148     $pre_loaded.=addFieldRow($colName,$colLabel,$bean_data[$colName]);
149 }
150 $xtpl->assign("PRE_LOADED_FIELDS",$pre_loaded);
151 $xtpl->assign("OPERATOR_OPTIONS",$json->encode($app_list_strings['merge_operators_dom']));
152
153
154 $xtpl->parse("main.field_select_block");
155
156 $xtpl->parse("main");
157 $xtpl->out("main");
158
159
160 /**
161  * This function is equivalent of AddFieldRow in merge.js. is being used to
162  * preload the filter criteria based on the vardef.
163  * <span><table><tr><td></td><td></td><td></td></tr></table></span>
164  */
165 function addFieldRow($colName,$colLabel,$colValue) {
166     global $theme, $app_list_strings;
167     
168     static $operator_options;
169     if (empty($operator_options)) {
170         $operator_options= get_select_options_with_id($app_list_strings['merge_operators_dom'],'');
171     }
172
173     $LBL_REMOVE = translate('LBL_REMOVE');
174     $deleteInlineImage = SugarThemeRegistry::current()->getImageURL('delete_inline.gif');
175     $snippet=<<<EOQ
176     <span id=filter_{$colName} style='visibility:visible' value="{$colLabel}" valueId="{$colName}">
177         <table width='100%' border='0' cellpadding='0'>
178             <tr>
179                 <td width='2%'><a class="listViewTdToolsS1" href="javascript:remove_filter('filter_{$colName}')"><!--not_in_theme!--><img src='{$deleteInlineImage}' align='absmiddle' alt='{$LBL_REMOVE}' border='0' height='12' width='12'>&nbsp;</a></td>
180                 <td width='20%'>{$colLabel}:&nbsp;</td>
181                 <td width='10%'><select name='{$colName}SearchType'>{$operator_options}</select></td>
182                 <td width='68%'><input value="{$colValue}" id="{$colName}SearchField" name="{$colName}SearchField" type="text"></td>                  
183             </tr> 
184         </table>
185     </span>
186 EOQ;
187
188     return $snippet;
189 }