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-2013 SugarCRM Inc. |
6
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
20
|
|
|
* details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25
|
|
|
* 02110-1301 USA. |
26
|
|
|
* |
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
29
|
|
|
* |
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
33
|
|
|
* |
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
39
|
|
|
********************************************************************************/ |
40
|
|
|
|
41
|
|
|
/********************************************************************************* |
42
|
|
|
|
43
|
|
|
* Description: |
44
|
|
|
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights |
45
|
|
|
* Reserved. Contributor(s): ______________________________________.. |
46
|
|
|
* *******************************************************************************/ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* gets the system default delimiter or an user-preference based override |
50
|
|
|
* @return string the delimiter |
51
|
|
|
*/ |
52
|
|
|
function getDelimiter() { |
53
|
|
|
global $sugar_config; |
54
|
|
|
global $current_user; |
55
|
|
|
|
56
|
|
|
if (!empty($sugar_config['export_excel_compatible'])) { |
57
|
|
|
return "\t"; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$delimiter = ','; // default to "comma" |
61
|
|
|
$userDelimiter = $current_user->getPreference('export_delimiter'); |
62
|
|
|
$delimiter = empty($sugar_config['export_delimiter']) ? $delimiter : $sugar_config['export_delimiter']; |
63
|
|
|
$delimiter = empty($userDelimiter) ? $delimiter : $userDelimiter; |
64
|
|
|
|
65
|
|
|
return $delimiter; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* builds up a delimited string for export |
71
|
|
|
* @param string type the bean-type to export |
72
|
|
|
* @param array records an array of records if coming directly from a query |
73
|
|
|
* @return string delimited string for export |
74
|
|
|
*/ |
75
|
|
|
function export($type, $records = null, $members = false, $sample=false) { |
76
|
|
|
global $locale; |
77
|
|
|
global $beanList; |
78
|
|
|
global $beanFiles; |
79
|
|
|
global $current_user; |
80
|
|
|
global $app_strings; |
81
|
|
|
global $app_list_strings; |
82
|
|
|
global $timedate; |
83
|
|
|
global $mod_strings; |
84
|
|
|
global $current_language; |
85
|
|
|
$sampleRecordNum = 5; |
86
|
|
|
|
87
|
|
|
//Array of fields that should not be exported, and are only used for logic |
88
|
|
|
$remove_from_members = array("ea_deleted", "ear_deleted", "primary_address"); |
89
|
|
|
$focus = 0; |
90
|
|
|
|
91
|
|
|
$bean = $beanList[$type]; |
92
|
|
|
require_once($beanFiles[$bean]); |
93
|
|
|
$focus = new $bean; |
94
|
|
|
$searchFields = array(); |
95
|
|
|
$db = DBManagerFactory::getInstance(); |
96
|
|
|
|
97
|
|
|
if($records) { |
98
|
|
|
$records = explode(',', $records); |
99
|
|
|
$records = "'" . implode("','", $records) . "'"; |
100
|
|
|
$where = "{$focus->table_name}.id in ($records)"; |
101
|
|
|
} elseif (isset($_REQUEST['all']) ) { |
102
|
|
|
$where = ''; |
103
|
|
|
} else { |
104
|
|
|
if(!empty($_REQUEST['current_post'])) { |
105
|
|
|
$ret_array = generateSearchWhere($type, $_REQUEST['current_post']); |
106
|
|
|
|
107
|
|
|
$where = $ret_array['where']; |
108
|
|
|
$searchFields = $ret_array['searchFields']; |
109
|
|
|
} else { |
110
|
|
|
$where = ''; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
$order_by = ""; |
114
|
|
|
if($focus->bean_implements('ACL')){ |
115
|
|
|
if(!ACLController::checkAccess($focus->module_dir, 'export', true)){ |
116
|
|
|
ACLController::displayNoAccess(); |
117
|
|
|
sugar_die(''); |
118
|
|
|
} |
119
|
|
|
if(ACLController::requireOwner($focus->module_dir, 'export')){ |
120
|
|
|
if(!empty($where)){ |
121
|
|
|
$where .= ' AND '; |
122
|
|
|
} |
123
|
|
|
$where .= $focus->getOwnerWhere($current_user->id); |
124
|
|
|
} |
125
|
|
|
/* BEGIN - SECURITY GROUPS */ |
126
|
|
|
if(ACLController::requireSecurityGroup($focus->module_dir, 'export') ) |
127
|
|
|
{ |
128
|
|
|
require_once('modules/SecurityGroups/SecurityGroup.php'); |
129
|
|
|
global $current_user; |
130
|
|
|
$owner_where = $focus->getOwnerWhere($current_user->id); |
131
|
|
|
$group_where = SecurityGroup::getGroupWhere($focus->table_name,$focus->module_dir,$current_user->id); |
132
|
|
|
if(!empty($owner_where)) { |
133
|
|
|
if(empty($where)) |
134
|
|
|
{ |
135
|
|
|
$where = " (". $owner_where." or ".$group_where.")"; |
136
|
|
|
} else { |
137
|
|
|
$where .= " AND (". $owner_where." or ".$group_where.")"; |
138
|
|
|
} |
139
|
|
|
} else { |
140
|
|
|
if(!empty($where)){ |
141
|
|
|
$where .= ' AND '; |
142
|
|
|
} |
143
|
|
|
$where .= $group_where; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
/* END - SECURITY GROUPS */ |
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
// Export entire list was broken because the where clause already has "where" in it |
150
|
|
|
// and when the query is built, it has a "where" as well, so the query was ill-formed. |
151
|
|
|
// Eliminating the "where" here so that the query can be constructed correctly. |
152
|
|
|
if($members == true){ |
|
|
|
|
153
|
|
|
$query = $focus->create_export_members_query($records); |
154
|
|
|
}else{ |
155
|
|
|
$beginWhere = substr(trim($where), 0, 5); |
156
|
|
|
if ($beginWhere == "where") |
157
|
|
|
$where = substr(trim($where), 5, strlen($where)); |
158
|
|
|
|
159
|
|
|
$query = $focus->create_export_query($order_by,$where); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$result = ''; |
163
|
|
|
$populate = false; |
164
|
|
|
if($sample) { |
165
|
|
|
$result = $db->limitQuery($query, 0, $sampleRecordNum, true, $app_strings['ERR_EXPORT_TYPE'].$type.": <BR>.".$query); |
166
|
|
|
if( $focus->_get_num_rows_in_query($query)<1 ){ |
167
|
|
|
$populate = true; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
else { |
171
|
|
|
$result = $db->query($query, true, $app_strings['ERR_EXPORT_TYPE'].$type.": <BR>.".$query); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
$fields_array = $db->getFieldsArray($result,true); |
176
|
|
|
|
177
|
|
|
//set up the order on the header row |
178
|
|
|
$fields_array = get_field_order_mapping($focus->module_dir, $fields_array); |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
|
182
|
|
|
//set up labels to be used for the header row |
183
|
|
|
$field_labels = array(); |
184
|
|
|
foreach($fields_array as $key=>$dbname){ |
185
|
|
|
//Remove fields that are only used for logic |
186
|
|
|
if($members && (in_array($dbname, $remove_from_members))) |
187
|
|
|
continue; |
188
|
|
|
|
189
|
|
|
//default to the db name of label does not exist |
190
|
|
|
$field_labels[$key] = translateForExport($dbname,$focus); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
194
|
|
|
if ($locale->getExportCharset() == 'UTF-8' && |
195
|
|
|
! preg_match('/macintosh|mac os x|mac_powerpc/i', $user_agent)) // Bug 60377 - Mac Excel doesn't support UTF-8 |
196
|
|
|
{ |
197
|
|
|
//Bug 55520 - add BOM to the exporting CSV so any symbols are displayed correctly in Excel |
198
|
|
|
$BOM = "\xEF\xBB\xBF"; |
199
|
|
|
$content = $BOM; |
200
|
|
|
} |
201
|
|
|
else |
202
|
|
|
{ |
203
|
|
|
$content = ''; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
// setup the "header" line with proper delimiters |
207
|
|
|
$content .= "\"".implode("\"".getDelimiter()."\"", array_values($field_labels))."\"\r\n"; |
208
|
|
|
$pre_id = ''; |
209
|
|
|
|
210
|
|
|
if($populate){ |
211
|
|
|
//this is a sample request with no data, so create fake datarows |
212
|
|
|
$content .= returnFakeDataRow($focus,$fields_array,$sampleRecordNum); |
213
|
|
|
}else{ |
214
|
|
|
$records = array(); |
215
|
|
|
|
216
|
|
|
//process retrieved record |
217
|
|
|
while($val = $db->fetchByAssoc($result, false)) { |
218
|
|
|
|
219
|
|
|
if ($members) |
220
|
|
|
$focus = BeanFactory::getBean($val['related_type']); |
221
|
|
|
else |
222
|
|
|
{ // field order mapping is not applied for member-exports, as they include multiple modules |
223
|
|
|
//order the values in the record array |
224
|
|
|
$val = get_field_order_mapping($focus->module_dir,$val); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
$new_arr = array(); |
228
|
|
|
if($members){ |
229
|
|
|
if($pre_id == $val['id']) |
230
|
|
|
continue; |
231
|
|
|
if($val['ea_deleted']==1 || $val['ear_deleted']==1){ |
232
|
|
|
$val['primary_email_address'] = ''; |
233
|
|
|
} |
234
|
|
|
unset($val['ea_deleted']); |
235
|
|
|
unset($val['ear_deleted']); |
236
|
|
|
unset($val['primary_address']); |
237
|
|
|
} |
238
|
|
|
$pre_id = $val['id']; |
239
|
|
|
|
240
|
|
|
foreach ($val as $key => $value) |
241
|
|
|
{ |
242
|
|
|
//getting content values depending on their types |
243
|
|
|
$fieldNameMapKey = $fields_array[$key]; |
244
|
|
|
|
245
|
|
|
if (isset($focus->field_name_map[$fieldNameMapKey]) && $focus->field_name_map[$fieldNameMapKey]['type']) |
246
|
|
|
{ |
247
|
|
|
$fieldType = $focus->field_name_map[$fieldNameMapKey]['type']; |
248
|
|
|
switch ($fieldType) |
249
|
|
|
{ |
250
|
|
|
//if our value is a currency field, then apply the users locale |
251
|
|
|
case 'currency': |
252
|
|
|
require_once('modules/Currencies/Currency.php'); |
253
|
|
|
$value = currency_format_number($value); |
254
|
|
|
break; |
255
|
|
|
|
256
|
|
|
//if our value is a datetime field, then apply the users locale |
257
|
|
|
case 'datetime': |
258
|
|
|
case 'datetimecombo': |
259
|
|
|
$value = $timedate->to_display_date_time($db->fromConvert($value, 'datetime')); |
260
|
|
|
$value = preg_replace('/([pm|PM|am|AM]+)/', ' \1', $value); |
261
|
|
|
break; |
262
|
|
|
|
263
|
|
|
//kbrill Bug #16296 |
264
|
|
|
case 'date': |
265
|
|
|
$value = $timedate->to_display_date($db->fromConvert($value, 'date'), false); |
266
|
|
|
break; |
267
|
|
|
|
268
|
|
|
// Bug 32463 - Properly have multienum field translated into something useful for the client |
269
|
|
|
case 'multienum': |
270
|
|
|
$valueArray = unencodeMultiEnum($value); |
271
|
|
|
|
272
|
|
|
if (isset($focus->field_name_map[$fields_array[$key]]['options']) && isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']]) ) |
273
|
|
|
{ |
274
|
|
|
foreach ($valueArray as $multikey => $multivalue ) |
275
|
|
|
{ |
276
|
|
|
if (isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$multivalue]) ) |
277
|
|
|
{ |
278
|
|
|
$valueArray[$multikey] = $app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$multivalue]; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
$value = implode(",",$valueArray); |
283
|
|
|
|
284
|
|
|
break; |
285
|
|
|
|
286
|
|
|
case 'enum': |
287
|
|
|
if ( isset($focus->field_name_map[$fields_array[$key]]['options']) && |
288
|
|
|
isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']]) && |
289
|
|
|
isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$value]) |
290
|
|
|
) |
291
|
|
|
$value = $app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$value]; |
292
|
|
|
|
293
|
|
|
break; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
// Keep as $key => $value for post-processing |
299
|
|
|
$new_arr[$key] = preg_replace("/\"/","\"\"", $value); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
// Use Bean ID as key for records |
303
|
|
|
$records[$pre_id] = $new_arr; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
// Check if we're going to export non-primary emails |
307
|
|
|
if ($focus->hasEmails() && in_array('email_addresses_non_primary', $fields_array)) |
308
|
|
|
{ |
309
|
|
|
// $records keys are bean ids |
310
|
|
|
$keys = array_keys($records); |
311
|
|
|
|
312
|
|
|
// Split the ids array into chunks of size 100 |
313
|
|
|
$chunks = array_chunk($keys, 100); |
314
|
|
|
|
315
|
|
|
foreach ($chunks as $chunk) |
316
|
|
|
{ |
317
|
|
|
// Pick all the non-primary mails for the chunk |
318
|
|
|
$query = |
319
|
|
|
" |
320
|
|
|
SELECT eabr.bean_id, ea.email_address |
321
|
|
|
FROM email_addr_bean_rel eabr |
322
|
|
|
LEFT JOIN email_addresses ea ON ea.id = eabr.email_address_id |
323
|
|
|
WHERE eabr.bean_module = '{$focus->module_dir}' |
324
|
|
|
AND eabr.primary_address = '0' |
325
|
|
|
AND eabr.bean_id IN ('" . implode("', '", $chunk) . "') |
326
|
|
|
AND eabr.deleted != '1' |
327
|
|
|
ORDER BY eabr.bean_id, eabr.reply_to_address, eabr.primary_address DESC |
328
|
|
|
"; |
329
|
|
|
|
330
|
|
|
$result = $db->query($query, true, $app_strings['ERR_EXPORT_TYPE'] . $type . ": <BR>." . $query); |
331
|
|
|
|
332
|
|
|
while ($val = $db->fetchByAssoc($result, false)) { |
333
|
|
|
if (empty($records[$val['bean_id']]['email_addresses_non_primary'])) { |
334
|
|
|
$records[$val['bean_id']]['email_addresses_non_primary'] = $val['email_address']; |
335
|
|
|
} else { |
336
|
|
|
// No custom non-primary mail delimeter yet, use semi-colon |
337
|
|
|
$records[$val['bean_id']]['email_addresses_non_primary'] .= ';' . $val['email_address']; |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
foreach($records as $record) |
344
|
|
|
{ |
345
|
|
|
$line = implode("\"" . getDelimiter() . "\"", $record); |
346
|
|
|
$line = "\"" . $line; |
347
|
|
|
$line .= "\"\r\n"; |
348
|
|
|
$content .= $line; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return $content; |
354
|
|
|
|
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
function generateSearchWhere($module, $query) {//this function is similar with function prepareSearchForm() in view.list.php |
359
|
|
|
$seed = loadBean($module); |
|
|
|
|
360
|
|
|
if(file_exists('modules/'.$module.'/SearchForm.html')){ |
361
|
|
|
if(file_exists('modules/' . $module . '/metadata/SearchFields.php')) { |
362
|
|
|
require_once('include/SearchForm/SearchForm.php'); |
363
|
|
|
$searchForm = new SearchForm($module, $seed); |
364
|
|
|
} |
365
|
|
|
elseif(!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php. |
366
|
|
|
// Currently, massupdate will not generate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. |
367
|
|
|
$where = $_SESSION['export_where']; |
368
|
|
|
$whereArr = explode (" ", trim($where)); |
369
|
|
|
if ($whereArr[0] == trim('where')) { |
370
|
|
|
$whereClean = array_shift($whereArr); |
371
|
|
|
} |
372
|
|
|
$where = implode(" ", $whereArr); |
373
|
|
|
//rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function |
374
|
|
|
//expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for |
375
|
|
|
//the function to return the results in a standard format. |
376
|
|
|
$ret_array['where'] = $where; |
377
|
|
|
$ret_array['searchFields'] =array(); |
378
|
|
|
return $ret_array; |
379
|
|
|
} |
380
|
|
|
else { |
381
|
|
|
return; |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
else{ |
385
|
|
|
require_once('include/SearchForm/SearchForm2.php'); |
386
|
|
|
|
387
|
|
|
if(file_exists('custom/modules/'.$module.'/metadata/metafiles.php')){ |
388
|
|
|
require('custom/modules/'.$module.'/metadata/metafiles.php'); |
389
|
|
|
}elseif(file_exists('modules/'.$module.'/metadata/metafiles.php')){ |
390
|
|
|
require('modules/'.$module.'/metadata/metafiles.php'); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
if (file_exists('custom/modules/'.$module.'/metadata/searchdefs.php')) |
394
|
|
|
{ |
395
|
|
|
require_once('custom/modules/'.$module.'/metadata/searchdefs.php'); |
396
|
|
|
} |
397
|
|
|
elseif (!empty($metafiles[$module]['searchdefs'])) |
|
|
|
|
398
|
|
|
{ |
399
|
|
|
require_once($metafiles[$module]['searchdefs']); |
400
|
|
|
} |
401
|
|
|
elseif (file_exists('modules/'.$module.'/metadata/searchdefs.php')) |
402
|
|
|
{ |
403
|
|
|
require_once('modules/'.$module.'/metadata/searchdefs.php'); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
//fixing bug #48483: Date Range search on custom date field then export ignores range filter |
407
|
|
|
// first of all custom folder should be checked |
408
|
|
|
if(file_exists('custom/modules/'.$module.'/metadata/SearchFields.php')) |
409
|
|
|
{ |
410
|
|
|
require_once('custom/modules/'.$module.'/metadata/SearchFields.php'); |
411
|
|
|
} |
412
|
|
|
elseif(!empty($metafiles[$module]['searchfields'])) |
413
|
|
|
{ |
414
|
|
|
require_once($metafiles[$module]['searchfields']); |
415
|
|
|
} |
416
|
|
|
elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php')) |
417
|
|
|
{ |
418
|
|
|
require_once('modules/'.$module.'/metadata/SearchFields.php'); |
419
|
|
|
} |
420
|
|
|
if(empty($searchdefs) || empty($searchFields)) { |
|
|
|
|
421
|
|
|
//for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. |
422
|
|
|
return; |
423
|
|
|
} |
424
|
|
|
$searchForm = new SearchForm($seed, $module); |
425
|
|
|
$searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl'); |
|
|
|
|
426
|
|
|
} |
427
|
|
|
$searchForm->populateFromArray(sugar_unserialize(base64_decode($query))); |
|
|
|
|
428
|
|
|
$where_clauses = $searchForm->generateSearchWhere(true, $module); |
429
|
|
|
if (count($where_clauses) > 0 )$where = '('. implode(' ) AND ( ', $where_clauses) . ')'; |
430
|
|
|
$GLOBALS['log']->info("Export Where Clause: {$where}"); |
431
|
|
|
$ret_array['where'] = $where; |
432
|
|
|
$ret_array['searchFields'] = $searchForm->searchFields; |
433
|
|
|
return $ret_array; |
434
|
|
|
} |
435
|
|
|
/** |
436
|
|
|
* calls export method to build up a delimited string and some sample instructional text on how to use this file |
437
|
|
|
* @param string type the bean-type to export |
438
|
|
|
* @return string delimited string for export with some tutorial text |
439
|
|
|
*/ |
440
|
|
|
function exportSample($type) { |
441
|
|
|
global $app_strings; |
442
|
|
|
|
443
|
|
|
//first grab the |
444
|
|
|
$_REQUEST['all']=true; |
445
|
|
|
|
446
|
|
|
//retrieve the export content |
447
|
|
|
$content = export($type, null, false, true); |
448
|
|
|
|
449
|
|
|
// Add a new row and add details on removing the sample data |
450
|
|
|
// Our Importer will stop after he gets to the new row, ignoring the text below |
451
|
|
|
return $content . "\n" . $app_strings['LBL_IMPORT_SAMPLE_FILE_TEXT']; |
452
|
|
|
|
453
|
|
|
} |
454
|
|
|
//this function will take in the bean and field mapping and return a proper value |
455
|
|
|
function returnFakeDataRow($focus,$field_array,$rowsToReturn = 5){ |
456
|
|
|
|
457
|
|
|
if(empty($focus) || empty($field_array)) |
458
|
|
|
return ; |
459
|
|
|
|
460
|
|
|
//include the file that defines $sugar_demodata |
461
|
|
|
include('install/demoData.en_us.php'); |
462
|
|
|
|
463
|
|
|
$person_bean = false; |
464
|
|
|
if( isset($focus->first_name)){ |
465
|
|
|
$person_bean = true; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
global $timedate; |
469
|
|
|
$returnContent = ''; |
470
|
|
|
$counter = 0; |
471
|
|
|
$new_arr = array(); |
472
|
|
|
|
473
|
|
|
//iterate through the record creation process as many times as defined. Each iteration will create a new row |
474
|
|
|
while($counter < $rowsToReturn){ |
475
|
|
|
$counter++; |
476
|
|
|
//go through each field and populate with dummy data if possible |
477
|
|
|
foreach($field_array as $field_name){ |
478
|
|
|
|
479
|
|
|
if(empty($focus->field_name_map[$field_name]) || empty($focus->field_name_map[$field_name]['type'])){ |
480
|
|
|
//type is not set, fill in with empty string and continue; |
481
|
|
|
$returnContent .= '"",'; |
482
|
|
|
continue; |
483
|
|
|
} |
484
|
|
|
$field = $focus->field_name_map[$field_name]; |
485
|
|
|
//fill in value according to type |
486
|
|
|
$type = $field['type']; |
487
|
|
|
|
488
|
|
|
switch ($type) { |
489
|
|
|
|
490
|
|
|
case "id": |
491
|
|
|
case "assigned_user_name": |
492
|
|
|
//return new guid string |
493
|
|
|
$returnContent .= '"'.create_guid().'",'; |
494
|
|
|
break; |
495
|
|
|
case "int": |
496
|
|
|
//return random number` |
497
|
|
|
$returnContent .= '"'.mt_rand(0,4).'",'; |
498
|
|
|
break; |
499
|
|
|
case "name": |
500
|
|
|
//return first, last, user name, or random name string |
501
|
|
|
if($field['name'] == 'first_name'){ |
502
|
|
|
$count = count($sugar_demodata['first_name_array']) - 1; |
503
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",'; |
504
|
|
|
}elseif($field['name'] == 'last_name'){ |
505
|
|
|
$count = count($sugar_demodata['last_name_array']) - 1; |
506
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",'; |
507
|
|
|
}elseif($field['name'] == 'user_name'){ |
508
|
|
|
$count = count($sugar_demodata['first_name_array']) - 1; |
509
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'_'.mt_rand(1,111).'",'; |
510
|
|
|
}else{ |
511
|
|
|
//return based on bean |
512
|
|
|
if($focus->module_dir =='Accounts'){ |
513
|
|
|
$count = count($sugar_demodata['company_name_array']) - 1; |
514
|
|
|
$returnContent .= '"'.$sugar_demodata['company_name_array'][mt_rand(0,$count)].'",'; |
515
|
|
|
|
516
|
|
|
}elseif($focus->module_dir =='Bugs'){ |
517
|
|
|
$count = count($sugar_demodata['bug_seed_names']) - 1; |
518
|
|
|
$returnContent .= '"'.$sugar_demodata['bug_seed_names'][mt_rand(0,$count)].'",'; |
519
|
|
|
}elseif($focus->module_dir =='Notes'){ |
520
|
|
|
$count = count($sugar_demodata['note_seed_names_and_Descriptions']) - 1; |
521
|
|
|
$returnContent .= '"'.$sugar_demodata['note_seed_names_and_Descriptions'][mt_rand(0,$count)].'",'; |
522
|
|
|
|
523
|
|
|
}elseif($focus->module_dir =='Calls'){ |
524
|
|
|
$count = count($sugar_demodata['call_seed_data_names']) - 1; |
525
|
|
|
$returnContent .= '"'.$sugar_demodata['call_seed_data_names'][mt_rand(0,$count)].'",'; |
526
|
|
|
|
527
|
|
|
}elseif($focus->module_dir =='Tasks'){ |
528
|
|
|
$count = count($sugar_demodata['task_seed_data_names']) - 1; |
529
|
|
|
$returnContent .= '"'.$sugar_demodata['task_seed_data_names'][mt_rand(0,$count)].'",'; |
530
|
|
|
|
531
|
|
|
}elseif($focus->module_dir =='Meetings'){ |
532
|
|
|
$count = count($sugar_demodata['meeting_seed_data_names']) - 1; |
533
|
|
|
$returnContent .= '"'.$sugar_demodata['meeting_seed_data_names'][mt_rand(0,$count)].'",'; |
534
|
|
|
|
535
|
|
|
}elseif($focus->module_dir =='ProductCategories'){ |
536
|
|
|
$count = count($sugar_demodata['productcategory_seed_data_names']) - 1; |
537
|
|
|
$returnContent .= '"'.$sugar_demodata['productcategory_seed_data_names'][mt_rand(0,$count)].'",'; |
538
|
|
|
|
539
|
|
|
|
540
|
|
|
}elseif($focus->module_dir =='ProductTypes'){ |
541
|
|
|
$count = count($sugar_demodata['producttype_seed_data_names']) - 1; |
542
|
|
|
$returnContent .= '"'.$sugar_demodata['producttype_seed_data_names'][mt_rand(0,$count)].'",'; |
543
|
|
|
|
544
|
|
|
|
545
|
|
|
}elseif($focus->module_dir =='ProductTemplates'){ |
546
|
|
|
$count = count($sugar_demodata['producttemplate_seed_data']) - 1; |
547
|
|
|
$returnContent .= '"'.$sugar_demodata['producttemplate_seed_data'][mt_rand(0,$count)].'",'; |
548
|
|
|
|
549
|
|
|
}else{ |
550
|
|
|
$returnContent .= '"Default Name for '.$focus->module_dir.'",'; |
551
|
|
|
|
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
} |
555
|
|
|
break; |
556
|
|
|
case "relate": |
557
|
|
|
if($field['name'] == 'team_name'){ |
558
|
|
|
//apply team names and user_name |
559
|
|
|
$teams_count = count($sugar_demodata['teams']) - 1; |
560
|
|
|
$users_count = count($sugar_demodata['users']) - 1; |
561
|
|
|
|
562
|
|
|
$returnContent .= '"'.$sugar_demodata['teams'][mt_rand(0,$teams_count)]['name'].','.$sugar_demodata['users'][mt_rand(0,$users_count)]['user_name'].'",'; |
563
|
|
|
|
564
|
|
|
}else{ |
565
|
|
|
//apply GUID |
566
|
|
|
$returnContent .= '"'.create_guid().'",'; |
567
|
|
|
} |
568
|
|
|
break; |
569
|
|
|
case "bool": |
570
|
|
|
//return 0 or 1 |
571
|
|
|
$returnContent .= '"'.mt_rand(0,1).'",'; |
572
|
|
|
break; |
573
|
|
|
|
574
|
|
|
case "text": |
575
|
|
|
//return random text |
576
|
|
|
$returnContent .= '"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna",'; |
577
|
|
|
break; |
578
|
|
|
|
579
|
|
|
case "team_list": |
580
|
|
|
$teams_count = count($sugar_demodata['teams']) - 1; |
581
|
|
|
//give fake team names (East,West,North,South) |
582
|
|
|
$returnContent .= '"'.$sugar_demodata['teams'][mt_rand(0,$teams_count)]['name'].'",'; |
583
|
|
|
break; |
584
|
|
|
|
585
|
|
|
case "date": |
586
|
|
|
//return formatted date |
587
|
|
|
$timeStamp = strtotime('now'); |
588
|
|
|
$value = date($timedate->dbDayFormat, $timeStamp); |
589
|
|
|
$returnContent .= '"'.$timedate->to_display_date_time($value).'",'; |
590
|
|
|
break; |
591
|
|
|
|
592
|
|
|
case "datetime": |
593
|
|
|
case "datetimecombo": |
594
|
|
|
//return formatted date time |
595
|
|
|
$timeStamp = strtotime('now'); |
596
|
|
|
//Start with db date |
597
|
|
|
$value = date($timedate->dbDayFormat.' '.$timedate->dbTimeFormat, $timeStamp); |
598
|
|
|
//use timedate to convert to user display format |
599
|
|
|
$value = $timedate->to_display_date_time($value); |
600
|
|
|
//finally forma the am/pm to have a space so it can be recognized as a date field in excel |
601
|
|
|
$value = preg_replace('/([pm|PM|am|AM]+)/', ' \1', $value); |
602
|
|
|
$returnContent .= '"'.$value.'",'; |
603
|
|
|
|
604
|
|
|
break; |
605
|
|
|
case "phone": |
606
|
|
|
$value = '('.mt_rand(300,999).') '.mt_rand(300,999).'-'.mt_rand(1000,9999); |
607
|
|
|
$returnContent .= '"'.$value.'",'; |
608
|
|
|
break; |
609
|
|
|
case "varchar": |
610
|
|
|
//process varchar for possible values |
611
|
|
|
if($field['name'] == 'first_name'){ |
612
|
|
|
$count = count($sugar_demodata['first_name_array']) - 1; |
613
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",'; |
614
|
|
|
}elseif($field['name'] == 'last_name'){ |
615
|
|
|
$count = count($sugar_demodata['last_name_array']) - 1; |
616
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",'; |
617
|
|
|
}elseif($field['name'] == 'user_name'){ |
618
|
|
|
$count = count($sugar_demodata['first_name_array']) - 1; |
619
|
|
|
$returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'_'.mt_rand(1,111).'",'; |
620
|
|
|
}elseif($field['name'] == 'title'){ |
621
|
|
|
$count = count($sugar_demodata['titles']) - 1; |
622
|
|
|
$returnContent .= '"'.$sugar_demodata['titles'][mt_rand(0,$count)].'",'; |
623
|
|
|
}elseif(strpos($field['name'],'address_street')>0){ |
624
|
|
|
$count = count($sugar_demodata['street_address_array']) - 1; |
625
|
|
|
$returnContent .= '"'.$sugar_demodata['street_address_array'][mt_rand(0,$count)].'",'; |
626
|
|
|
}elseif(strpos($field['name'],'address_city')>0){ |
627
|
|
|
$count = count($sugar_demodata['city_array']) - 1; |
628
|
|
|
$returnContent .= '"'.$sugar_demodata['city_array'][mt_rand(0,$count)].'",'; |
629
|
|
|
}elseif(strpos($field['name'],'address_state')>0){ |
630
|
|
|
$state_arr = array('CA','NY','CO','TX','NV'); |
631
|
|
|
$count = count($state_arr) - 1; |
632
|
|
|
$returnContent .= '"'.$state_arr[mt_rand(0,$count)].'",'; |
633
|
|
|
}elseif(strpos($field['name'],'address_postalcode')>0){ |
634
|
|
|
$returnContent .= '"'.mt_rand(12345,99999).'",'; |
635
|
|
|
}else{ |
636
|
|
|
$returnContent .= '"",'; |
637
|
|
|
|
638
|
|
|
} |
639
|
|
|
break; |
640
|
|
|
case "url": |
641
|
|
|
$returnContent .= '"https://www.sugarcrm.com",'; |
642
|
|
|
break; |
643
|
|
|
|
644
|
|
|
case "enum": |
645
|
|
|
//get the associated enum if available |
646
|
|
|
global $app_list_strings; |
647
|
|
|
|
648
|
|
|
if(isset($focus->field_name_map[$field_name]['type']) && !empty($focus->field_name_map[$field_name]['options'])){ |
649
|
|
|
if ( !empty($app_list_strings[$focus->field_name_map[$field_name]['options']]) ) { |
650
|
|
|
|
651
|
|
|
//get the values into an array |
652
|
|
|
$dd_values = $app_list_strings[$focus->field_name_map[$field_name]['options']]; |
653
|
|
|
$dd_values = array_values($dd_values); |
654
|
|
|
|
655
|
|
|
//grab the count |
656
|
|
|
$count = count($dd_values) - 1; |
657
|
|
|
|
658
|
|
|
//choose one at random |
659
|
|
|
$returnContent .= '"'.$dd_values[mt_rand(0,$count)].'",'; |
660
|
|
|
} else{ |
661
|
|
|
//name of enum options array was found but is empty, return blank |
662
|
|
|
$returnContent .= '"",'; |
663
|
|
|
} |
664
|
|
|
}else{ |
665
|
|
|
//name of enum options array was not found on field, return blank |
666
|
|
|
$returnContent .= '"",'; |
667
|
|
|
} |
668
|
|
|
break; |
669
|
|
|
default: |
670
|
|
|
//type is not matched, fill in with empty string and continue; |
671
|
|
|
$returnContent .= '"",'; |
672
|
|
|
|
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
$returnContent .= "\r\n"; |
676
|
|
|
} |
677
|
|
|
return $returnContent; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
|
681
|
|
|
|
682
|
|
|
|
683
|
|
|
//expects the field name to translate and a bean of the type being translated (to access field map and mod_strings) |
684
|
|
|
function translateForExport($field_db_name,$focus){ |
685
|
|
|
global $mod_strings,$app_strings; |
686
|
|
|
|
687
|
|
|
if (empty($field_db_name) || empty($focus)){ |
688
|
|
|
return false; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
//grab the focus module strings |
692
|
|
|
$temp_mod_strings = $mod_strings; |
693
|
|
|
global $current_language; |
694
|
|
|
$mod_strings = return_module_language($current_language, $focus->module_dir); |
695
|
|
|
$fieldLabel = ''; |
696
|
|
|
|
697
|
|
|
//!! first check to see if we are overriding the label for export. |
698
|
|
|
if (!empty($mod_strings['LBL_EXPORT_'.strtoupper($field_db_name)])){ |
699
|
|
|
//entry exists which means we are overriding this value for exporting, use this label |
700
|
|
|
$fieldLabel = $mod_strings['LBL_EXPORT_'.strtoupper($field_db_name)]; |
701
|
|
|
|
702
|
|
|
} |
703
|
|
|
//!! next check to see if we are overriding the label for export on app_strings. |
704
|
|
|
elseif (!empty($app_strings['LBL_EXPORT_'.strtoupper($field_db_name)])){ |
705
|
|
|
//entry exists which means we are overriding this value for exporting, use this label |
706
|
|
|
$fieldLabel = $app_strings['LBL_EXPORT_'.strtoupper($field_db_name)]; |
707
|
|
|
|
708
|
|
|
}//check to see if label exists in mapping and in mod strings |
709
|
|
|
elseif (!empty($focus->field_name_map[$field_db_name]['vname']) && !empty($mod_strings[$focus->field_name_map[$field_db_name]['vname']])){ |
710
|
|
|
$fieldLabel = $mod_strings[$focus->field_name_map[$field_db_name]['vname']]; |
711
|
|
|
|
712
|
|
|
}//check to see if label exists in mapping and in app strings |
713
|
|
|
elseif (!empty($focus->field_name_map[$field_db_name]['vname']) && !empty($app_strings[$focus->field_name_map[$field_db_name]['vname']])){ |
714
|
|
|
$fieldLabel = $app_strings[$focus->field_name_map[$field_db_name]['vname']]; |
715
|
|
|
|
716
|
|
|
}//field is not in mapping, so check to see if db can be uppercased and found in mod strings |
717
|
|
|
elseif (!empty($mod_strings['LBL_'.strtoupper($field_db_name)])){ |
718
|
|
|
$fieldLabel = $mod_strings['LBL_'.strtoupper($field_db_name)]; |
719
|
|
|
|
720
|
|
|
}//check to see if db can be uppercased and found in app strings |
721
|
|
|
elseif (!empty($app_strings['LBL_'.strtoupper($field_db_name)])){ |
722
|
|
|
$fieldLabel = $app_strings['LBL_'.strtoupper($field_db_name)]; |
723
|
|
|
|
724
|
|
|
}else{ |
725
|
|
|
//we could not find the label in mod_strings or app_strings based on either a mapping entry |
726
|
|
|
//or on the db_name itself or being overwritten, so default to the db name as a last resort |
727
|
|
|
$fieldLabel = $field_db_name; |
728
|
|
|
|
729
|
|
|
} |
730
|
|
|
//strip the label of any columns |
731
|
|
|
$fieldLabel= preg_replace("/([:]|\xEF\xBC\x9A)[\\s]*$/", '', trim($fieldLabel)); |
732
|
|
|
|
733
|
|
|
//reset the bean mod_strings back to original import strings |
734
|
|
|
$mod_strings = $temp_mod_strings; |
735
|
|
|
return $fieldLabel; |
736
|
|
|
|
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
//call this function to return the desired order to display columns for export in. |
740
|
|
|
//if you pass in an array, it will reorder the array and send back to you. It expects the array |
741
|
|
|
//to have the db names as key values, or as labels |
742
|
|
|
function get_field_order_mapping($name='',$reorderArr = '', $exclude = true){ |
743
|
|
|
|
744
|
|
|
//define the ordering of fields, note that the key value is what is important, and should be the db field name |
745
|
|
|
$field_order_array = array(); |
746
|
|
|
$field_order_array['accounts'] = array( 'name'=>'Name', 'id'=>'ID', 'website'=>'Website', 'email_address' =>'Email Address', 'email_addresses_non_primary' => 'Non Primary E-mails', 'phone_office' =>'Office Phone', 'phone_alternate' => 'Alternate Phone', 'phone_fax' => 'Fax', 'billing_address_street' => 'Billing Street', 'billing_address_city' => 'Billing City', 'billing_address_state' => 'Billing State', 'billing_address_postalcode' => 'Billing Postal Code', 'billing_address_country' => 'Billing Country', 'shipping_address_street' => 'Shipping Street', 'shipping_address_city' => 'Shipping City', 'shipping_address_state' => 'Shipping State', 'shipping_address_postalcode' => 'Shipping Postal Code', 'shipping_address_country' => 'Shipping Country', 'description' => 'Description', 'account_type' => 'Type', 'industry' =>'Industry', 'annual_revenue' => 'Annual Revenue', 'employees' => 'Employees', 'sic_code' => 'SIC Code', 'ticker_symbol' => 'Ticker Symbol', 'parent_id' => 'Parent Account ID', 'ownership' =>'Ownership', 'campaign_id' =>'Campaign ID', 'rating' =>'Rating', 'assigned_user_name' =>'Assigned to', 'assigned_user_id' =>'Assigned User ID', 'team_id' =>'Team Id', 'team_name' =>'Teams', 'team_set_id' =>'Team Set ID', 'date_entered' =>'Date Created', 'date_modified' =>'Date Modified', 'modified_user_id' =>'Modified By', 'created_by' =>'Created By', 'deleted' =>'Deleted'); |
747
|
|
|
$field_order_array['contacts'] = array( 'first_name' => 'First Name', 'last_name' => 'Last Name', 'id'=>'ID', 'salutation' => 'Salutation', 'title' => 'Title', 'department' => 'Department', 'account_name' => 'Account Name', 'email_address' => 'Email Address', 'email_addresses_non_primary' => 'Non Primary E-mails for Import', 'phone_mobile' => 'Phone Mobile','phone_work' => 'Phone Work', 'phone_home' => 'Phone Home', 'phone_other' => 'Phone Other','phone_fax' => 'Phone Fax', 'primary_address_street' => 'Primary Address Street', 'primary_address_city' => 'Primary Address City', 'primary_address_state' => 'Primary Address State', 'primary_address_postalcode' => 'Primary Address Postal Code', 'primary_address_country' => 'Primary Address Country', 'alt_address_street' => 'Alternate Address Street', 'alt_address_city' => 'Alternate Address City', 'alt_address_state' => 'Alternate Address State', 'alt_address_postalcode' => 'Alternate Address Postal Code', 'alt_address_country' => 'Alternate Address Country', 'description' => 'Description', 'birthdate' => 'Birthdate', 'lead_source' => 'Lead Source', 'campaign_id' => 'campaign_id', 'do_not_call' => 'Do Not Call', 'portal_name' => 'Portal Name', 'portal_active' => 'Portal Active', 'portal_password' => 'Portal Password', 'portal_app' => 'Portal Application', 'reports_to_id' => 'Reports to ID', 'assistant' => 'Assistant', 'assistant_phone' => 'Assistant Phone', 'picture' => 'Picture', 'assigned_user_name' => 'Assigned User Name', 'assigned_user_id' => 'Assigned User ID', 'team_name' => 'Teams', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' =>'Date Created', 'date_modified' =>'Date Modified', 'modified_user_id' =>'Modified By', 'created_by' =>'Created By', 'deleted' =>'Deleted'); |
748
|
|
|
$field_order_array['leads'] = array( 'first_name' => 'First Name', 'last_name' => 'Last Name', 'id'=>'ID', 'salutation' => 'Salutation', 'title' => 'Title', 'department' => 'Department', 'account_name' => 'Account Name', 'account_description' => 'Account Description', 'website' => 'Website', 'email_address' => 'Email Address', 'email_addresses_non_primary' => 'Non Primary E-mails for Import', 'phone_mobile' => 'Phone Mobile', 'phone_work' => 'Phone Work', 'phone_home' => 'Phone Home', 'phone_other' => 'Phone Other', 'phone_fax' => 'Phone Fax', 'primary_address_street' => 'Primary Address Street', 'primary_address_city' => 'Primary Address City', 'primary_address_state' => 'Primary Address State', 'primary_address_postalcode' => 'Primary Address Postal Code', 'primary_address_country' => 'Primary Address Country', 'alt_address_street' => 'Alt Address Street', 'alt_address_city' => 'Alt Address City', 'alt_address_state' => 'Alt Address State', 'alt_address_postalcode' => 'Alt Address Postalcode', 'alt_address_country' => 'Alt Address Country', 'status' => 'Status', 'status_description' => 'Status Description', 'lead_source' => 'Lead Source', 'lead_source_description' => 'Lead Source Description', 'description'=>'Description', 'converted' => 'Converted', 'opportunity_name' => 'Opportunity Name', 'opportunity_amount' => 'Opportunity Amount', 'refered_by' => 'Referred By', 'campaign_id' => 'campaign_id', 'do_not_call' => 'Do Not Call', 'portal_name' => 'Portal Name', 'portal_app' => 'Portal Application', 'reports_to_id' => 'Reports To ID', 'assistant' => 'Assistant', 'assistant_phone' => 'Assistant Phone', 'birthdate'=>'Birthdate', 'contact_id' => 'Contact ID', 'account_id' => 'Account ID', 'opportunity_id' => 'Opportunity ID', 'assigned_user_name' => 'Assigned User Name', 'assigned_user_id' => 'Assigned User ID', 'team_name' => 'Teams', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' => 'Date Created', 'date_modified' => 'Date Modified', 'created_by' => 'Created By ID', 'modified_user_id' => 'Modified By ID', 'deleted' => 'Deleted'); |
749
|
|
|
$field_order_array['opportunities'] = array( 'name' => 'Opportunity Name', 'id'=>'ID', 'amount' => 'Opportunity Amount', 'currency_id' => 'Currency', 'date_closed' => 'Expected Close Date', 'sales_stage' => 'Sales Stage', 'probability' => 'Probability (%)', 'next_step' => 'Next Step', 'opportunity_type' => 'Opportunity Type', 'account_name' => 'Account Name', 'description' => 'Description', 'amount_usdollar' => 'Amount', 'lead_source' => 'Lead Source', 'campaign_id' => 'campaign_id', 'assigned_user_name' => 'Assigned User Name', 'assigned_user_id' => 'Assigned User ID', 'team_name' => 'Teams', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' => 'Date Created', 'date_modified' => 'Date Modified', 'created_by' => 'Created By ID', 'modified_user_id' => 'Modified By ID', 'deleted' => 'Deleted'); |
750
|
|
|
$field_order_array['notes'] = array( 'name' => 'Name', 'id'=>'ID', 'description' => 'Description', 'filename' => 'Attachment', 'parent_type' => 'Parent Type', 'parent_id' => 'Parent ID', 'contact_id' => 'Contact ID', 'portal_flag' => 'Display in Portal?', 'assigned_user_name' =>'Assigned to', 'assigned_user_id' => 'assigned_user_id', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' => 'Date Created', 'date_modified' => 'Date Modified', 'created_by' => 'Created By ID', 'modified_user_id' => 'Modified By ID', 'deleted' => 'Deleted' ); |
751
|
|
|
$field_order_array['bugs'] = array('bug_number' => 'Bug Number', 'id'=>'ID', 'name' => 'Subject', 'description' => 'Description', 'status' => 'Status', 'type' => 'Type', 'priority' => 'Priority', 'resolution' => 'Resolution', 'work_log' => 'Work Log', 'found_in_release' => 'Found In Release', 'fixed_in_release' => 'Fixed In Release', 'found_in_release_name' => 'Found In Release Name', 'fixed_in_release_name' => 'Fixed In Release', 'product_category' => 'Category', 'source' => 'Source', 'portal_viewable' => 'Portal Viewable', 'system_id' => 'System ID', 'assigned_user_id' => 'Assigned User ID', 'assigned_user_name' => 'Assigned User Name', 'team_name'=>'Teams', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' =>'Date Created', 'date_modified' =>'Date Modified', 'modified_user_id' =>'Modified By', 'created_by' =>'Created By', 'deleted' =>'Deleted'); |
752
|
|
|
$field_order_array['tasks'] = array( 'name'=>'Subject', 'id'=>'ID', 'description'=>'Description', 'status'=>'Status', 'date_start'=>'Date Start', 'date_due'=>'Date Due','priority'=>'Priority', 'parent_type'=>'Parent Type', 'parent_id'=>'Parent ID', 'contact_id'=>'Contact ID', 'assigned_user_name' =>'Assigned to', 'assigned_user_id'=>'Assigned User ID', 'team_name'=>'Teams', 'team_id'=>'Team id', 'team_set_id'=>'Team Set ID', 'date_entered'=>'Date Created', 'date_modified'=>'Date Modified', 'created_by'=>'Created By ID', 'modified_user_id'=>'Modified By ID', 'deleted'=>'Deleted'); |
753
|
|
|
$field_order_array['calls'] = array( 'name'=>'Subject', 'id'=>'ID', 'description'=>'Description', 'status'=>'Status', 'direction'=>'Direction', 'date_start'=>'Date', 'date_end'=>'Date End', 'duration_hours'=>'Duration Hours', 'duration_minutes'=>'Duration Minutes', 'reminder_time'=>'Reminder Time', 'parent_type'=>'Parent Type', 'parent_id'=>'Parent ID', 'outlook_id'=>'Outlook ID', 'assigned_user_name' =>'Assigned to', 'assigned_user_id'=>'Assigned User ID', 'team_name'=>'Teams', 'team_id'=>'Team id', 'team_set_id'=>'Team Set ID', 'date_entered'=>'Date Created', 'date_modified'=>'Date Modified', 'created_by'=>'Created By ID', 'modified_user_id'=>'Modified By ID', 'deleted'=>'Deleted'); |
754
|
|
|
$field_order_array['meetings'] =array( 'name'=>'Subject', 'id'=>'ID', 'description'=>'Description', 'status'=>'Status', 'location'=>'Location', 'date_start'=>'Date', 'date_end'=>'Date End', 'duration_hours'=>'Duration Hours', 'duration_minutes'=>'Duration Minutes', 'reminder_time'=>'Reminder Time', 'type'=>'Meeting Type', 'external_id'=>'External ID', 'password'=>'Meeting Password', 'join_url'=>'Join Url', 'host_url'=>'Host Url', 'displayed_url'=>'Displayed Url', 'creator'=>'Meeting Creator', 'parent_type'=>'Related to', 'parent_id'=>'Related to', 'outlook_id'=>'Outlook ID','assigned_user_name' =>'Assigned to','assigned_user_id' => 'Assigned User ID', 'team_name' => 'Teams', 'team_id' => 'Team id', 'team_set_id' => 'Team Set ID', 'date_entered' => 'Date Created', 'date_modified' => 'Date Modified', 'created_by' => 'Created By ID', 'modified_user_id' => 'Modified By ID', 'deleted' => 'Deleted'); |
755
|
|
|
$field_order_array['cases'] =array( 'case_number'=>'Case Number', 'id'=>'ID', 'name'=>'Subject', 'description'=>'Description', 'status'=>'Status', 'type'=>'Type', 'priority'=>'Priority', 'resolution'=>'Resolution', 'work_log'=>'Work Log', 'portal_viewable'=>'Portal Viewable', 'account_name'=>'Account Name', 'account_id'=>'Account ID', 'assigned_user_id'=>'Assigned User ID', 'team_name'=>'Teams', 'team_id'=>'Team id', 'team_set_id'=>'Team Set ID', 'date_entered'=>'Date Created', 'date_modified'=>'Date Modified', 'created_by'=>'Created By ID', 'modified_user_id'=>'Modified By ID', 'deleted'=>'Deleted'); |
756
|
|
|
$field_order_array['prospects'] =array( 'first_name'=>'First Name', 'last_name'=>'Last Name', 'id'=>'ID', 'salutation'=>'Salutation', 'title'=>'Title', 'department'=>'Department', 'account_name'=>'Account Name', 'email_address'=>'Email Address', 'email_addresses_non_primary' => 'Non Primary E-mails for Import', 'phone_mobile' => 'Phone Mobile', 'phone_work' => 'Phone Work', 'phone_home' => 'Phone Home', 'phone_other' => 'Phone Other', 'phone_fax' => 'Phone Fax', 'primary_address_street' => 'Primary Address Street', 'primary_address_city' => 'Primary Address City', 'primary_address_state' => 'Primary Address State', 'primary_address_postalcode' => 'Primary Address Postal Code', 'primary_address_country' => 'Primary Address Country', 'alt_address_street' => 'Alternate Address Street', 'alt_address_city' => 'Alternate Address City', 'alt_address_state' => 'Alternate Address State', 'alt_address_postalcode' => 'Alternate Address Postal Code', 'alt_address_country' => 'Alternate Address Country', 'description' => 'Description', 'birthdate' => 'Birthdate', 'assistant'=>'Assistant', 'assistant_phone'=>'Assistant Phone', 'campaign_id'=>'campaign_id', 'tracker_key'=>'Tracker Key', 'do_not_call'=>'Do Not Call', 'lead_id'=>'Lead Id', 'assigned_user_name'=>'Assigned User Name', 'assigned_user_id'=>'Assigned User ID', 'team_id' =>'Team Id', 'team_name' =>'Teams', 'team_set_id' =>'Team Set ID', 'date_entered' =>'Date Created', 'date_modified' =>'Date Modified', 'modified_user_id' =>'Modified By', 'created_by' =>'Created By', 'deleted' =>'Deleted'); |
757
|
|
|
|
758
|
|
|
$fields_to_exclude = array(); |
759
|
|
|
$fields_to_exclude['accounts'] = array('account_name'); |
760
|
|
|
$fields_to_exclude['bugs'] = array('system_id'); |
761
|
|
|
$fields_to_exclude['cases'] = array('system_id', 'modified_by_name', 'modified_by_name_owner', 'modified_by_name_mod', 'created_by_name', 'created_by_name_owner', 'created_by_name_mod', 'assigned_user_name', 'assigned_user_name_owner', 'assigned_user_name_mod', 'team_count', 'team_count_owner', 'team_count_mod', 'team_name_owner', 'team_name_mod', 'account_name_owner', 'account_name_mod', 'modified_user_name', 'modified_user_name_owner', 'modified_user_name_mod'); |
762
|
|
|
$fields_to_exclude['notes'] = array('first_name','last_name', 'file_mime_type','embed_flag'); |
763
|
|
|
$fields_to_exclude['tasks'] = array('date_start_flag', 'date_due_flag'); |
764
|
|
|
|
765
|
|
|
//of array is passed in for reordering, process array |
766
|
|
|
if(!empty($name) && !empty($reorderArr) && is_array($reorderArr)){ |
767
|
|
|
|
768
|
|
|
//make sure reorderArr has values as keys, if not then iterate through and assign the value as the key |
769
|
|
|
$newReorder = array(); |
770
|
|
|
foreach($reorderArr as $rk=> $rv){ |
771
|
|
|
if(is_int($rk)){ |
772
|
|
|
$newReorder[$rv]=$rv; |
773
|
|
|
}else{ |
774
|
|
|
$newReorder[$rk]=$rv; |
775
|
|
|
} |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
//if module is not defined, lets default the order to another module of the same type |
779
|
|
|
//this would apply mostly to custom modules |
780
|
|
|
if(!isset($field_order_array[strtolower($name)]) && isset($_REQUEST['module'])){ |
781
|
|
|
|
782
|
|
|
$exemptModuleList = array('ProspectLists'); |
783
|
|
|
if(in_array($name, $exemptModuleList)) |
784
|
|
|
return $newReorder; |
785
|
|
|
|
786
|
|
|
//get an instance of the bean |
787
|
|
|
global $beanList; |
788
|
|
|
global $beanFiles; |
789
|
|
|
|
790
|
|
|
$bean = $beanList[$_REQUEST['module']]; |
791
|
|
|
require_once($beanFiles[$bean]); |
792
|
|
|
$focus = new $bean; |
793
|
|
|
|
794
|
|
|
|
795
|
|
|
//if module is of type person |
796
|
|
|
if($focus instanceof Person){ |
797
|
|
|
$name = 'contacts'; |
798
|
|
|
} |
799
|
|
|
//if module is of type company |
800
|
|
|
else if ($focus instanceof Company){ |
801
|
|
|
$name = 'accounts'; |
802
|
|
|
} |
803
|
|
|
//if module is of type Sale |
804
|
|
|
else if ($focus instanceof Sale){ |
805
|
|
|
$name = 'opportunities'; |
806
|
|
|
}//if module is of type File |
807
|
|
|
else if ($focus instanceof Issue){ |
808
|
|
|
$name = 'bugs'; |
809
|
|
|
}//all others including type File can use basic |
810
|
|
|
else{ |
811
|
|
|
$name = 'Notes'; |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
//lets iterate through and create a reordered temporary array using |
817
|
|
|
//the newly formatted copy of passed in array |
818
|
|
|
$temp_result_arr = array(); |
819
|
|
|
$lname = strtolower($name); |
820
|
|
|
if(!empty($field_order_array[$lname])) { |
821
|
|
|
foreach($field_order_array[$lname] as $fk=> $fv){ |
822
|
|
|
|
823
|
|
|
//if the value exists as a key in the passed in array, add to temp array and remove from reorder array. |
824
|
|
|
//Do not force into the temp array as we don't want to violate acl's |
825
|
|
|
if(array_key_exists($fk,$newReorder)){ |
826
|
|
|
$temp_result_arr[$fk] = $newReorder[$fk]; |
827
|
|
|
unset($newReorder[$fk]); |
828
|
|
|
} |
829
|
|
|
} |
830
|
|
|
} |
831
|
|
|
//add in all the left over values that were not in our ordered list |
832
|
|
|
//array_splice($temp_result_arr, count($temp_result_arr), 0, $newReorder); |
833
|
|
|
foreach($newReorder as $nrk=>$nrv){ |
834
|
|
|
$temp_result_arr[$nrk] = $nrv; |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
|
838
|
|
|
if($exclude){ |
839
|
|
|
//Some arrays have values we wish to exclude |
840
|
|
|
if (isset($fields_to_exclude[$lname])){ |
841
|
|
|
foreach($fields_to_exclude[$lname] as $exclude_field){ |
842
|
|
|
unset($temp_result_arr[$exclude_field]); |
843
|
|
|
} |
844
|
|
|
} |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
//return temp ordered list |
848
|
|
|
return $temp_result_arr; |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
//if no array was passed in, pass back either the list of ordered columns by module, or the entireorder array |
852
|
|
|
if(empty($name)){ |
853
|
|
|
return $field_order_array; |
854
|
|
|
}else{ |
855
|
|
|
return $field_order_array[strtolower($name)]; |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
} |
859
|
|
|
?> |
860
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.