PageRenderTime 72ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/include/export_utils.php

https://github.com/BarnetikKoop/SuiteCRM
PHP | 909 lines | 801 code | 34 blank | 74 comment | 40 complexity | e27553bfb841123f924822ec8bcfafbd MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  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. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  7. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it under
  10. * the terms of the GNU Affero General Public License version 3 as published by the
  11. * Free Software Foundation with the addition of the following permission added
  12. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  13. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  14. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License along with
  22. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  23. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. * 02110-1301 USA.
  25. *
  26. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  27. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  28. *
  29. * The interactive user interfaces in modified source and object code versions
  30. * of this program must display Appropriate Legal Notices, as required under
  31. * Section 5 of the GNU Affero General Public License version 3.
  32. *
  33. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  34. * these Appropriate Legal Notices must retain the display of the "Powered by
  35. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  36. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  37. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  38. ********************************************************************************/
  39. /*********************************************************************************
  40. * Description:
  41. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights
  42. * Reserved. Contributor(s): ______________________________________..
  43. * *******************************************************************************/
  44. /**
  45. * gets the system default delimiter or an user-preference based override
  46. * @return string the delimiter
  47. */
  48. function getDelimiter() {
  49. global $sugar_config;
  50. global $current_user;
  51. if (!empty($sugar_config['export_excel_compatible'])) {
  52. return "\t";
  53. }
  54. $delimiter = ','; // default to "comma"
  55. $userDelimiter = $current_user->getPreference('export_delimiter');
  56. $delimiter = empty($sugar_config['export_delimiter']) ? $delimiter : $sugar_config['export_delimiter'];
  57. $delimiter = empty($userDelimiter) ? $delimiter : $userDelimiter;
  58. return $delimiter;
  59. }
  60. /**
  61. * builds up a delimited string for export
  62. * @param string type the bean-type to export
  63. * @param array records an array of records if coming directly from a query
  64. * @return string delimited string for export
  65. */
  66. function export($type, $records = null, $members = false, $sample=false) {
  67. global $locale;
  68. global $beanList;
  69. global $beanFiles;
  70. global $current_user;
  71. global $app_strings;
  72. global $app_list_strings;
  73. global $timedate;
  74. global $mod_strings;
  75. global $current_language;
  76. $sampleRecordNum = 5;
  77. $contact_fields = array(
  78. "id"=>"Contact ID"
  79. ,"lead_source"=>"Lead Source"
  80. ,"date_entered"=>"Date Entered"
  81. ,"date_modified"=>"Date Modified"
  82. ,"first_name"=>"First Name"
  83. ,"last_name"=>"Last Name"
  84. ,"salutation"=>"Salutation"
  85. ,"birthdate"=>"Lead Source"
  86. ,"do_not_call"=>"Do Not Call"
  87. ,"email_opt_out"=>"Email Opt Out"
  88. ,"title"=>"Title"
  89. ,"department"=>"Department"
  90. ,"birthdate"=>"Birthdate"
  91. ,"do_not_call"=>"Do Not Call"
  92. ,"phone_home"=>"Phone (Home)"
  93. ,"phone_mobile"=>"Phone (Mobile)"
  94. ,"phone_work"=>"Phone (Work)"
  95. ,"phone_other"=>"Phone (Other)"
  96. ,"phone_fax"=>"Fax"
  97. ,"email1"=>"Email"
  98. ,"email2"=>"Email (Other)"
  99. ,"assistant"=>"Assistant"
  100. ,"assistant_phone"=>"Assistant Phone"
  101. ,"primary_address_street"=>"Primary Address Street"
  102. ,"primary_address_city"=>"Primary Address City"
  103. ,"primary_address_state"=>"Primary Address State"
  104. ,"primary_address_postalcode"=>"Primary Address Postalcode"
  105. ,"primary_address_country"=>"Primary Address Country"
  106. ,"alt_address_street"=>"Other Address Street"
  107. ,"alt_address_city"=>"Other Address City"
  108. ,"alt_address_state"=>"Other Address State"
  109. ,"alt_address_postalcode"=>"Other Address Postalcode"
  110. ,"alt_address_country"=>"Other Address Country"
  111. ,"description"=>"Description"
  112. );
  113. $account_fields = array(
  114. "id"=>"Account ID",
  115. "name"=>"Account Name",
  116. "website"=>"Website",
  117. "industry"=>"Industry",
  118. "account_type"=>"Type",
  119. "ticker_symbol"=>"Ticker Symbol",
  120. "employees"=>"Employees",
  121. "ownership"=>"Ownership",
  122. "phone_office"=>"Phone",
  123. "phone_fax"=>"Fax",
  124. "phone_alternate"=>"Other Phone",
  125. "email1"=>"Email",
  126. "email2"=>"Other Email",
  127. "rating"=>"Rating",
  128. "sic_code"=>"SIC Code",
  129. "annual_revenue"=>"Annual Revenue",
  130. "billing_address_street"=>"Billing Address Street",
  131. "billing_address_city"=>"Billing Address City",
  132. "billing_address_state"=>"Billing Address State",
  133. "billing_address_postalcode"=>"Billing Address Postalcode",
  134. "billing_address_country"=>"Billing Address Country",
  135. "shipping_address_street"=>"Shipping Address Street",
  136. "shipping_address_city"=>"Shipping Address City",
  137. "shipping_address_state"=>"Shipping Address State",
  138. "shipping_address_postalcode"=>"Shipping Address Postalcode",
  139. "shipping_address_country"=>"Shipping Address Country",
  140. "description"=>"Description"
  141. );
  142. //Array of fields that should not be exported, and are only used for logic
  143. $remove_from_members = array("ea_deleted", "ear_deleted", "primary_address");
  144. $focus = 0;
  145. $bean = $beanList[$type];
  146. require_once($beanFiles[$bean]);
  147. $focus = new $bean;
  148. $searchFields = array();
  149. $db = DBManagerFactory::getInstance();
  150. if($records) {
  151. $records = explode(',', $records);
  152. $records = "'" . implode("','", $records) . "'";
  153. $where = "{$focus->table_name}.id in ($records)";
  154. } elseif (isset($_REQUEST['all']) ) {
  155. $where = '';
  156. } else {
  157. if(!empty($_REQUEST['current_post'])) {
  158. $ret_array = generateSearchWhere($type, $_REQUEST['current_post']);
  159. $where = $ret_array['where'];
  160. $searchFields = $ret_array['searchFields'];
  161. } else {
  162. $where = '';
  163. }
  164. }
  165. $order_by = "";
  166. if($focus->bean_implements('ACL')){
  167. if(!ACLController::checkAccess($focus->module_dir, 'export', true)){
  168. ACLController::displayNoAccess();
  169. sugar_die('');
  170. }
  171. if(ACLController::requireOwner($focus->module_dir, 'export')){
  172. if(!empty($where)){
  173. $where .= ' AND ';
  174. }
  175. $where .= $focus->getOwnerWhere($current_user->id);
  176. }
  177. /* BEGIN - SECURITY GROUPS */
  178. if(ACLController::requireSecurityGroup($focus->module_dir, 'export') )
  179. {
  180. require_once('modules/SecurityGroups/SecurityGroup.php');
  181. global $current_user;
  182. $owner_where = $focus->getOwnerWhere($current_user->id);
  183. $group_where = SecurityGroup::getGroupWhere($focus->table_name,$focus->module_dir,$current_user->id);
  184. if(!empty($owner_where)) {
  185. if(empty($where))
  186. {
  187. $where = " (". $owner_where." or ".$group_where.")";
  188. } else {
  189. $where .= " AND (". $owner_where." or ".$group_where.")";
  190. }
  191. } else {
  192. if(!empty($where)){
  193. $where .= ' AND ';
  194. }
  195. $where .= $group_where;
  196. }
  197. }
  198. /* END - SECURITY GROUPS */
  199. }
  200. // Export entire list was broken because the where clause already has "where" in it
  201. // and when the query is built, it has a "where" as well, so the query was ill-formed.
  202. // Eliminating the "where" here so that the query can be constructed correctly.
  203. if($members == true){
  204. $query = $focus->create_export_members_query($records);
  205. }else{
  206. $beginWhere = substr(trim($where), 0, 5);
  207. if ($beginWhere == "where")
  208. $where = substr(trim($where), 5, strlen($where));
  209. $query = $focus->create_export_query($order_by,$where);
  210. }
  211. $result = '';
  212. $populate = false;
  213. if($sample) {
  214. $result = $db->limitQuery($query, 0, $sampleRecordNum, true, $app_strings['ERR_EXPORT_TYPE'].$type.": <BR>.".$query);
  215. if( $focus->_get_num_rows_in_query($query)<1 ){
  216. $populate = true;
  217. }
  218. }
  219. else {
  220. $result = $db->query($query, true, $app_strings['ERR_EXPORT_TYPE'].$type.": <BR>.".$query);
  221. }
  222. $fields_array = $db->getFieldsArray($result,true);
  223. //set up the order on the header row
  224. $fields_array = get_field_order_mapping($focus->module_dir, $fields_array);
  225. //set up labels to be used for the header row
  226. $field_labels = array();
  227. foreach($fields_array as $key=>$dbname){
  228. //Remove fields that are only used for logic
  229. if($members && (in_array($dbname, $remove_from_members)))
  230. continue;
  231. //default to the db name of label does not exist
  232. $field_labels[$key] = translateForExport($dbname,$focus);
  233. }
  234. $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
  235. if ($locale->getExportCharset() == 'UTF-8' &&
  236. ! preg_match('/macintosh|mac os x|mac_powerpc/i', $user_agent)) // Bug 60377 - Mac Excel doesn't support UTF-8
  237. {
  238. //Bug 55520 - add BOM to the exporting CSV so any symbols are displayed correctly in Excel
  239. $BOM = "\xEF\xBB\xBF";
  240. $content = $BOM;
  241. }
  242. else
  243. {
  244. $content = '';
  245. }
  246. // setup the "header" line with proper delimiters
  247. $content .= "\"".implode("\"".getDelimiter()."\"", array_values($field_labels))."\"\r\n";
  248. $pre_id = '';
  249. if($populate){
  250. //this is a sample request with no data, so create fake datarows
  251. $content .= returnFakeDataRow($focus,$fields_array,$sampleRecordNum);
  252. }else{
  253. $records = array();
  254. //process retrieved record
  255. while($val = $db->fetchByAssoc($result, false)) {
  256. //order the values in the record array
  257. $val = get_field_order_mapping($focus->module_dir,$val);
  258. $new_arr = array();
  259. if($members){
  260. if($pre_id == $val['id'])
  261. continue;
  262. if($val['ea_deleted']==1 || $val['ear_deleted']==1){
  263. $val['primary_email_address'] = '';
  264. }
  265. unset($val['ea_deleted']);
  266. unset($val['ear_deleted']);
  267. unset($val['primary_address']);
  268. }
  269. $pre_id = $val['id'];
  270. foreach ($val as $key => $value)
  271. {
  272. //getting content values depending on their types
  273. $fieldNameMapKey = $fields_array[$key];
  274. if (isset($focus->field_name_map[$fieldNameMapKey]) && $focus->field_name_map[$fieldNameMapKey]['type'])
  275. {
  276. $fieldType = $focus->field_name_map[$fieldNameMapKey]['type'];
  277. switch ($fieldType)
  278. {
  279. //if our value is a currency field, then apply the users locale
  280. case 'currency':
  281. require_once('modules/Currencies/Currency.php');
  282. $value = currency_format_number($value);
  283. break;
  284. //if our value is a datetime field, then apply the users locale
  285. case 'datetime':
  286. case 'datetimecombo':
  287. $value = $timedate->to_display_date_time($db->fromConvert($value, 'datetime'));
  288. $value = preg_replace('/([pm|PM|am|AM]+)/', ' \1', $value);
  289. break;
  290. //kbrill Bug #16296
  291. case 'date':
  292. $value = $timedate->to_display_date($db->fromConvert($value, 'date'), false);
  293. break;
  294. // Bug 32463 - Properly have multienum field translated into something useful for the client
  295. case 'multienum':
  296. $value = str_replace("^","",$value);
  297. if (isset($focus->field_name_map[$fields_array[$key]]['options']) && isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']]) )
  298. {
  299. $valueArray = explode(",",$value);
  300. foreach ($valueArray as $multikey => $multivalue )
  301. {
  302. if (isset($app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$multivalue]) )
  303. {
  304. $valueArray[$multikey] = $app_list_strings[$focus->field_name_map[$fields_array[$key]]['options']][$multivalue];
  305. }
  306. }
  307. $value = implode(",",$valueArray);
  308. }
  309. break;
  310. }
  311. }
  312. // Keep as $key => $value for post-processing
  313. $new_arr[$key] = preg_replace("/\"/","\"\"", $value);
  314. }
  315. // Use Bean ID as key for records
  316. $records[$pre_id] = $new_arr;
  317. }
  318. // Check if we're going to export non-primary emails
  319. if ($focus->hasEmails() && in_array('email_addresses_non_primary', $fields_array))
  320. {
  321. // $records keys are bean ids
  322. $keys = array_keys($records);
  323. // Split the ids array into chunks of size 100
  324. $chunks = array_chunk($keys, 100);
  325. foreach ($chunks as $chunk)
  326. {
  327. // Pick all the non-primary mails for the chunk
  328. $query =
  329. "
  330. SELECT eabr.bean_id, ea.email_address
  331. FROM email_addr_bean_rel eabr
  332. LEFT JOIN email_addresses ea ON ea.id = eabr.email_address_id
  333. WHERE eabr.bean_module = '{$focus->module_dir}'
  334. AND eabr.primary_address = '0'
  335. AND eabr.bean_id IN ('" . implode("', '", $chunk) . "')
  336. AND eabr.deleted != '1'
  337. ORDER BY eabr.bean_id, eabr.reply_to_address, eabr.primary_address DESC
  338. ";
  339. $result = $db->query($query, true, $app_strings['ERR_EXPORT_TYPE'] . $type . ": <BR>." . $query);
  340. while ($val = $db->fetchByAssoc($result, false)) {
  341. if (empty($records[$val['bean_id']]['email_addresses_non_primary'])) {
  342. $records[$val['bean_id']]['email_addresses_non_primary'] = $val['email_address'];
  343. } else {
  344. // No custom non-primary mail delimeter yet, use semi-colon
  345. $records[$val['bean_id']]['email_addresses_non_primary'] .= ';' . $val['email_address'];
  346. }
  347. }
  348. }
  349. }
  350. foreach($records as $record)
  351. {
  352. $line = implode("\"" . getDelimiter() . "\"", $record);
  353. $line = "\"" . $line;
  354. $line .= "\"\r\n";
  355. $content .= $line;
  356. }
  357. }
  358. return $content;
  359. }
  360. function generateSearchWhere($module, $query) {//this function is similar with function prepareSearchForm() in view.list.php
  361. $seed = loadBean($module);
  362. if(file_exists('modules/'.$module.'/SearchForm.html')){
  363. if(file_exists('modules/' . $module . '/metadata/SearchFields.php')) {
  364. require_once('include/SearchForm/SearchForm.php');
  365. $searchForm = new SearchForm($module, $seed);
  366. }
  367. 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.
  368. // 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.
  369. $where = $_SESSION['export_where'];
  370. $whereArr = explode (" ", trim($where));
  371. if ($whereArr[0] == trim('where')) {
  372. $whereClean = array_shift($whereArr);
  373. }
  374. $where = implode(" ", $whereArr);
  375. //rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function
  376. //expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for
  377. //the function to return the results in a standard format.
  378. $ret_array['where'] = $where;
  379. $ret_array['searchFields'] =array();
  380. return $ret_array;
  381. }
  382. else {
  383. return;
  384. }
  385. }
  386. else{
  387. require_once('include/SearchForm/SearchForm2.php');
  388. if(file_exists('custom/modules/'.$module.'/metadata/metafiles.php')){
  389. require('custom/modules/'.$module.'/metadata/metafiles.php');
  390. }elseif(file_exists('modules/'.$module.'/metadata/metafiles.php')){
  391. require('modules/'.$module.'/metadata/metafiles.php');
  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. //fixing bug #48483: Date Range search on custom date field then export ignores range filter
  406. // first of all custom folder should be checked
  407. if(file_exists('custom/modules/'.$module.'/metadata/SearchFields.php'))
  408. {
  409. require_once('custom/modules/'.$module.'/metadata/SearchFields.php');
  410. }
  411. elseif(!empty($metafiles[$module]['searchfields']))
  412. {
  413. require_once($metafiles[$module]['searchfields']);
  414. }
  415. elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php'))
  416. {
  417. require_once('modules/'.$module.'/metadata/SearchFields.php');
  418. }
  419. if(empty($searchdefs) || empty($searchFields)) {
  420. //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty.
  421. return;
  422. }
  423. $searchForm = new SearchForm($seed, $module);
  424. $searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl');
  425. }
  426. $searchForm->populateFromArray(unserialize(base64_decode($query)));
  427. $where_clauses = $searchForm->generateSearchWhere(true, $module);
  428. if (count($where_clauses) > 0 )$where = '('. implode(' ) AND ( ', $where_clauses) . ')';
  429. $GLOBALS['log']->info("Export Where Clause: {$where}");
  430. $ret_array['where'] = $where;
  431. $ret_array['searchFields'] = $searchForm->searchFields;
  432. return $ret_array;
  433. }
  434. /**
  435. * calls export method to build up a delimited string and some sample instructional text on how to use this file
  436. * @param string type the bean-type to export
  437. * @return string delimited string for export with some tutorial text
  438. */
  439. function exportSample($type) {
  440. global $app_strings;
  441. //first grab the
  442. $_REQUEST['all']=true;
  443. //retrieve the export content
  444. $content = export($type, null, false, true);
  445. // Add a new row and add details on removing the sample data
  446. // Our Importer will stop after he gets to the new row, ignoring the text below
  447. return $content . "\n" . $app_strings['LBL_IMPORT_SAMPLE_FILE_TEXT'];
  448. }
  449. //this function will take in the bean and field mapping and return a proper value
  450. function returnFakeDataRow($focus,$field_array,$rowsToReturn = 5){
  451. if(empty($focus) || empty($field_array))
  452. return ;
  453. //include the file that defines $sugar_demodata
  454. include('install/demoData.en_us.php');
  455. $person_bean = false;
  456. if( isset($focus->first_name)){
  457. $person_bean = true;
  458. }
  459. global $timedate;
  460. $returnContent = '';
  461. $counter = 0;
  462. $new_arr = array();
  463. //iterate through the record creation process as many times as defined. Each iteration will create a new row
  464. while($counter < $rowsToReturn){
  465. $counter++;
  466. //go through each field and populate with dummy data if possible
  467. foreach($field_array as $field_name){
  468. if(empty($focus->field_name_map[$field_name]) || empty($focus->field_name_map[$field_name]['type'])){
  469. //type is not set, fill in with empty string and continue;
  470. $returnContent .= '"",';
  471. continue;
  472. }
  473. $field = $focus->field_name_map[$field_name];
  474. //fill in value according to type
  475. $type = $field['type'];
  476. switch ($type) {
  477. case "id":
  478. case "assigned_user_name":
  479. //return new guid string
  480. $returnContent .= '"'.create_guid().'",';
  481. break;
  482. case "int":
  483. //return random number`
  484. $returnContent .= '"'.mt_rand(0,4).'",';
  485. break;
  486. case "name":
  487. //return first, last, user name, or random name string
  488. if($field['name'] == 'first_name'){
  489. $count = count($sugar_demodata['first_name_array']) - 1;
  490. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",';
  491. }elseif($field['name'] == 'last_name'){
  492. $count = count($sugar_demodata['last_name_array']) - 1;
  493. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",';
  494. }elseif($field['name'] == 'user_name'){
  495. $count = count($sugar_demodata['first_name_array']) - 1;
  496. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'_'.mt_rand(1,111).'",';
  497. }else{
  498. //return based on bean
  499. if($focus->module_dir =='Accounts'){
  500. $count = count($sugar_demodata['company_name_array']) - 1;
  501. $returnContent .= '"'.$sugar_demodata['company_name_array'][mt_rand(0,$count)].'",';
  502. }elseif($focus->module_dir =='Bugs'){
  503. $count = count($sugar_demodata['bug_seed_names']) - 1;
  504. $returnContent .= '"'.$sugar_demodata['bug_seed_names'][mt_rand(0,$count)].'",';
  505. }elseif($focus->module_dir =='Notes'){
  506. $count = count($sugar_demodata['note_seed_names_and_Descriptions']) - 1;
  507. $returnContent .= '"'.$sugar_demodata['note_seed_names_and_Descriptions'][mt_rand(0,$count)].'",';
  508. }elseif($focus->module_dir =='Calls'){
  509. $count = count($sugar_demodata['call_seed_data_names']) - 1;
  510. $returnContent .= '"'.$sugar_demodata['call_seed_data_names'][mt_rand(0,$count)].'",';
  511. }elseif($focus->module_dir =='Tasks'){
  512. $count = count($sugar_demodata['task_seed_data_names']) - 1;
  513. $returnContent .= '"'.$sugar_demodata['task_seed_data_names'][mt_rand(0,$count)].'",';
  514. }elseif($focus->module_dir =='Meetings'){
  515. $count = count($sugar_demodata['meeting_seed_data_names']) - 1;
  516. $returnContent .= '"'.$sugar_demodata['meeting_seed_data_names'][mt_rand(0,$count)].'",';
  517. }elseif($focus->module_dir =='ProductCategories'){
  518. $count = count($sugar_demodata['productcategory_seed_data_names']) - 1;
  519. $returnContent .= '"'.$sugar_demodata['productcategory_seed_data_names'][mt_rand(0,$count)].'",';
  520. }elseif($focus->module_dir =='ProductTypes'){
  521. $count = count($sugar_demodata['producttype_seed_data_names']) - 1;
  522. $returnContent .= '"'.$sugar_demodata['producttype_seed_data_names'][mt_rand(0,$count)].'",';
  523. }elseif($focus->module_dir =='ProductTemplates'){
  524. $count = count($sugar_demodata['producttemplate_seed_data']) - 1;
  525. $returnContent .= '"'.$sugar_demodata['producttemplate_seed_data'][mt_rand(0,$count)].'",';
  526. }else{
  527. $returnContent .= '"Default Name for '.$focus->module_dir.'",';
  528. }
  529. }
  530. break;
  531. case "relate":
  532. if($field['name'] == 'team_name'){
  533. //apply team names and user_name
  534. $teams_count = count($sugar_demodata['teams']) - 1;
  535. $users_count = count($sugar_demodata['users']) - 1;
  536. $returnContent .= '"'.$sugar_demodata['teams'][mt_rand(0,$teams_count)]['name'].','.$sugar_demodata['users'][mt_rand(0,$users_count)]['user_name'].'",';
  537. }else{
  538. //apply GUID
  539. $returnContent .= '"'.create_guid().'",';
  540. }
  541. break;
  542. case "bool":
  543. //return 0 or 1
  544. $returnContent .= '"'.mt_rand(0,1).'",';
  545. break;
  546. case "text":
  547. //return random text
  548. $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",';
  549. break;
  550. case "team_list":
  551. $teams_count = count($sugar_demodata['teams']) - 1;
  552. //give fake team names (East,West,North,South)
  553. $returnContent .= '"'.$sugar_demodata['teams'][mt_rand(0,$teams_count)]['name'].'",';
  554. break;
  555. case "date":
  556. //return formatted date
  557. $timeStamp = strtotime('now');
  558. $value = date($timedate->dbDayFormat, $timeStamp);
  559. $returnContent .= '"'.$timedate->to_display_date_time($value).'",';
  560. break;
  561. case "datetime":
  562. case "datetimecombo":
  563. //return formatted date time
  564. $timeStamp = strtotime('now');
  565. //Start with db date
  566. $value = date($timedate->dbDayFormat.' '.$timedate->dbTimeFormat, $timeStamp);
  567. //use timedate to convert to user display format
  568. $value = $timedate->to_display_date_time($value);
  569. //finally forma the am/pm to have a space so it can be recognized as a date field in excel
  570. $value = preg_replace('/([pm|PM|am|AM]+)/', ' \1', $value);
  571. $returnContent .= '"'.$value.'",';
  572. break;
  573. case "phone":
  574. $value = '('.mt_rand(300,999).') '.mt_rand(300,999).'-'.mt_rand(1000,9999);
  575. $returnContent .= '"'.$value.'",';
  576. break;
  577. case "varchar":
  578. //process varchar for possible values
  579. if($field['name'] == 'first_name'){
  580. $count = count($sugar_demodata['first_name_array']) - 1;
  581. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",';
  582. }elseif($field['name'] == 'last_name'){
  583. $count = count($sugar_demodata['last_name_array']) - 1;
  584. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'",';
  585. }elseif($field['name'] == 'user_name'){
  586. $count = count($sugar_demodata['first_name_array']) - 1;
  587. $returnContent .= '"'.$sugar_demodata['last_name_array'][mt_rand(0,$count)].'_'.mt_rand(1,111).'",';
  588. }elseif($field['name'] == 'title'){
  589. $count = count($sugar_demodata['titles']) - 1;
  590. $returnContent .= '"'.$sugar_demodata['titles'][mt_rand(0,$count)].'",';
  591. }elseif(strpos($field['name'],'address_street')>0){
  592. $count = count($sugar_demodata['street_address_array']) - 1;
  593. $returnContent .= '"'.$sugar_demodata['street_address_array'][mt_rand(0,$count)].'",';
  594. }elseif(strpos($field['name'],'address_city')>0){
  595. $count = count($sugar_demodata['city_array']) - 1;
  596. $returnContent .= '"'.$sugar_demodata['city_array'][mt_rand(0,$count)].'",';
  597. }elseif(strpos($field['name'],'address_state')>0){
  598. $state_arr = array('CA','NY','CO','TX','NV');
  599. $count = count($state_arr) - 1;
  600. $returnContent .= '"'.$state_arr[mt_rand(0,$count)].'",';
  601. }elseif(strpos($field['name'],'address_postalcode')>0){
  602. $returnContent .= '"'.mt_rand(12345,99999).'",';
  603. }else{
  604. $returnContent .= '"",';
  605. }
  606. break;
  607. case "url":
  608. $returnContent .= '"https://www.sugarcrm.com",';
  609. break;
  610. case "enum":
  611. //get the associated enum if available
  612. global $app_list_strings;
  613. if(isset($focus->field_name_map[$field_name]['type']) && !empty($focus->field_name_map[$field_name]['options'])){
  614. if ( !empty($app_list_strings[$focus->field_name_map[$field_name]['options']]) ) {
  615. //get the values into an array
  616. $dd_values = $app_list_strings[$focus->field_name_map[$field_name]['options']];
  617. $dd_values = array_values($dd_values);
  618. //grab the count
  619. $count = count($dd_values) - 1;
  620. //choose one at random
  621. $returnContent .= '"'.$dd_values[mt_rand(0,$count)].'",';
  622. } else{
  623. //name of enum options array was found but is empty, return blank
  624. $returnContent .= '"",';
  625. }
  626. }else{
  627. //name of enum options array was not found on field, return blank
  628. $returnContent .= '"",';
  629. }
  630. break;
  631. default:
  632. //type is not matched, fill in with empty string and continue;
  633. $returnContent .= '"",';
  634. }
  635. }
  636. $returnContent .= "\r\n";
  637. }
  638. return $returnContent;
  639. }
  640. //expects the field name to translate and a bean of the type being translated (to access field map and mod_strings)
  641. function translateForExport($field_db_name,$focus){
  642. global $mod_strings,$app_strings;
  643. if (empty($field_db_name) || empty($focus)){
  644. return false;
  645. }
  646. //grab the focus module strings
  647. $temp_mod_strings = $mod_strings;
  648. global $current_language;
  649. $mod_strings = return_module_language($current_language, $focus->module_dir);
  650. $fieldLabel = '';
  651. //!! first check to see if we are overriding the label for export.
  652. if (!empty($mod_strings['LBL_EXPORT_'.strtoupper($field_db_name)])){
  653. //entry exists which means we are overriding this value for exporting, use this label
  654. $fieldLabel = $mod_strings['LBL_EXPORT_'.strtoupper($field_db_name)];
  655. }
  656. //!! next check to see if we are overriding the label for export on app_strings.
  657. elseif (!empty($app_strings['LBL_EXPORT_'.strtoupper($field_db_name)])){
  658. //entry exists which means we are overriding this value for exporting, use this label
  659. $fieldLabel = $app_strings['LBL_EXPORT_'.strtoupper($field_db_name)];
  660. }//check to see if label exists in mapping and in mod strings
  661. elseif (!empty($focus->field_name_map[$field_db_name]['vname']) && !empty($mod_strings[$focus->field_name_map[$field_db_name]['vname']])){
  662. $fieldLabel = $mod_strings[$focus->field_name_map[$field_db_name]['vname']];
  663. }//check to see if label exists in mapping and in app strings
  664. elseif (!empty($focus->field_name_map[$field_db_name]['vname']) && !empty($app_strings[$focus->field_name_map[$field_db_name]['vname']])){
  665. $fieldLabel = $app_strings[$focus->field_name_map[$field_db_name]['vname']];
  666. }//field is not in mapping, so check to see if db can be uppercased and found in mod strings
  667. elseif (!empty($mod_strings['LBL_'.strtoupper($field_db_name)])){
  668. $fieldLabel = $mod_strings['LBL_'.strtoupper($field_db_name)];
  669. }//check to see if db can be uppercased and found in app strings
  670. elseif (!empty($app_strings['LBL_'.strtoupper($field_db_name)])){
  671. $fieldLabel = $app_strings['LBL_'.strtoupper($field_db_name)];
  672. }else{
  673. //we could not find the label in mod_strings or app_strings based on either a mapping entry
  674. //or on the db_name itself or being overwritten, so default to the db name as a last resort
  675. $fieldLabel = $field_db_name;
  676. }
  677. //strip the label of any columns
  678. $fieldLabel= preg_replace("/([:]|\xEF\xBC\x9A)[\\s]*$/", '', trim($fieldLabel));
  679. //reset the bean mod_strings back to original import strings
  680. $mod_strings = $temp_mod_strings;
  681. return $fieldLabel;
  682. }
  683. //call this function to return the desired order to display columns for export in.
  684. //if you pass in an array, it will reorder the array and send back to you. It expects the array
  685. //to have the db names as key values, or as labels
  686. function get_field_order_mapping($name='',$reorderArr = '', $exclude = true){
  687. //define the ordering of fields, note that the key value is what is important, and should be the db field name
  688. $field_order_array = array();
  689. $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');
  690. $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');
  691. $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');
  692. $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');
  693. $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' );
  694. $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');
  695. $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');
  696. $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');
  697. $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');
  698. $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');
  699. $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');
  700. $fields_to_exclude = array();
  701. $fields_to_exclude['accounts'] = array('account_name');
  702. $fields_to_exclude['bugs'] = array('system_id');
  703. $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');
  704. $fields_to_exclude['notes'] = array('first_name','last_name', 'file_mime_type','embed_flag');
  705. $fields_to_exclude['tasks'] = array('date_start_flag', 'date_due_flag');
  706. //of array is passed in for reordering, process array
  707. if(!empty($name) && !empty($reorderArr) && is_array($reorderArr)){
  708. //make sure reorderArr has values as keys, if not then iterate through and assign the value as the key
  709. $newReorder = array();
  710. foreach($reorderArr as $rk=> $rv){
  711. if(is_int($rk)){
  712. $newReorder[$rv]=$rv;
  713. }else{
  714. $newReorder[$rk]=$rv;
  715. }
  716. }
  717. //if module is not defined, lets default the order to another module of the same type
  718. //this would apply mostly to custom modules
  719. if(!isset($field_order_array[strtolower($name)]) && isset($_REQUEST['module'])){
  720. $exemptModuleList = array('ProspectLists');
  721. if(in_array($name, $exemptModuleList))
  722. return $newReorder;
  723. //get an instance of the bean
  724. global $beanList;
  725. global $beanFiles;
  726. $bean = $beanList[$_REQUEST['module']];

Large files files are truncated, but you can click here to view the full file