$relatedTableJoin="LEFT JOIN $relatedTable ON $relatedTable.id = {$currentTable}_cstm.$relatedField";
}
//-- $relatedTable.id AS related_id,
//-- {$currentTable}_cstm.id_c AS current_id_c,
//-- {$relatedTable}_cstm.id_c AS related_id_c,
$selects[]="(SELECT $currentTable.id AS current_id,'$currentModule' AS current_module,'$currentField' AS current_field,'$relatedModule' AS related_module,'$relatedField' AS related_field,$relatedFieldSelect,$relatedLabel FROM $currentTable JOIN {$currentTable}_cstm ON {$currentTable}_cstm.id_c=$currentTable.id $relatedTableCustomJoin$relatedTableJoin WHERE $currentTable.id='{$record['id']}')";
}
}
}
$selects=array_unique($selects);
// grab custom related fields information
// query max length optimization, measured by mssql FreeTDS connection too
$queryMaxLength=620000;
$query='';
$i=0;
$selectsCount=count($selects)-1;
foreach($selectsas$select){
$queryTemp=$query.($i==0?$select:" UNION $select");
}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.
// 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.
$where=$_SESSION['export_where'];
$whereArr=explode("",trim($where));
if($whereArr[0]==trim('where')){
$whereClean=array_shift($whereArr);
}
$where=implode("",$whereArr);
//rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function
//expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for
//the function to return the results in a standard format.
$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",';
//define the ordering of fields, note that the key value is what is important, and should be the db field name
$field_order_array=array();
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$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');
$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');