|
iTx Technologies offre gratuitement
|
||
[Vue sommaire] [Imprimer] [Vue textuelle]
1 <?php 2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 3 /********************************************************************************* 4 * SugarCRM is a customer relationship management program developed by 5 * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License version 3 as published by the 9 * Free Software Foundation with the addition of the following permission added 10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY 12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 * details. 18 * 19 * You should have received a copy of the GNU General Public License along with 20 * this program; if not, see http://www.gnu.org/licenses or write to the Free 21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 * 02110-1301 USA. 23 * 24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 26 * 27 * The interactive user interfaces in modified source and object code versions 28 * of this program must display Appropriate Legal Notices, as required under 29 * Section 5 of the GNU General Public License version 3. 30 * 31 * In accordance with Section 7(b) of the GNU General Public License version 3, 32 * these Appropriate Legal Notices must retain the display of the "Powered by 33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 34 * technical reasons, the Appropriate Legal Notices must display the words 35 * "Powered by SugarCRM". 36 ********************************************************************************/ 37 /********************************************************************************* 38 39 * Description: 40 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights 41 * Reserved. Contributor(s): ______________________________________.. 42 * *******************************************************************************/ 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 52 $delimiter = ','; // default to "comma" 53 $userDelimiter = $current_user->getPreference('export_delimiter'); 54 $delimiter = empty($sugar_config['export_delimiter']) ? $delimiter : $sugar_config['export_delimiter']; 55 $delimiter = empty($userDelimiter) ? $delimiter : $userDelimiter; 56 57 return $delimiter; 58 } 59 60 61 /** 62 * builds up a delimited string for export 63 * @param string type the bean-type to export 64 * @param array records an array of records if coming directly from a query 65 * @return string delimited string for export 66 */ 67 function export($type, $records = null, $members = false) { 68 global $beanList; 69 global $beanFiles; 70 global $current_user; 71 global $app_strings; 72 global $timedate; 73 $contact_fields = array( 74 "id"=>"Contact ID" 75 ,"lead_source"=>"Lead Source" 76 ,"date_entered"=>"Date Entered" 77 ,"date_modified"=>"Date Modified" 78 ,"first_name"=>"First Name" 79 ,"last_name"=>"Last Name" 80 ,"salutation"=>"Salutation" 81 ,"birthdate"=>"Lead Source" 82 ,"do_not_call"=>"Do Not Call" 83 ,"email_opt_out"=>"Email Opt Out" 84 ,"title"=>"Title" 85 ,"department"=>"Department" 86 ,"birthdate"=>"Birthdate" 87 ,"do_not_call"=>"Do Not Call" 88 ,"phone_home"=>"Phone (Home)" 89 ,"phone_mobile"=>"Phone (Mobile)" 90 ,"phone_work"=>"Phone (Work)" 91 ,"phone_other"=>"Phone (Other)" 92 ,"phone_fax"=>"Fax" 93 ,"email1"=>"Email" 94 ,"email2"=>"Email (Other)" 95 ,"assistant"=>"Assistant" 96 ,"assistant_phone"=>"Assistant Phone" 97 ,"primary_address_street"=>"Primary Address Street" 98 ,"primary_address_city"=>"Primary Address City" 99 ,"primary_address_state"=>"Primary Address State" 100 ,"primary_address_postalcode"=>"Primary Address Postalcode" 101 ,"primary_address_country"=>"Primary Address Country" 102 ,"alt_address_street"=>"Other Address Street" 103 ,"alt_address_city"=>"Other Address City" 104 ,"alt_address_state"=>"Other Address State" 105 ,"alt_address_postalcode"=>"Other Address Postalcode" 106 ,"alt_address_country"=>"Other Address Country" 107 ,"description"=>"Description" 108 ); 109 110 $account_fields = array( 111 "id"=>"Account ID", 112 "name"=>"Account Name", 113 "website"=>"Website", 114 "industry"=>"Industry", 115 "account_type"=>"Type", 116 "ticker_symbol"=>"Ticker Symbol", 117 "employees"=>"Employees", 118 "ownership"=>"Ownership", 119 "phone_office"=>"Phone", 120 "phone_fax"=>"Fax", 121 "phone_alternate"=>"Other Phone", 122 "email1"=>"Email", 123 "email2"=>"Other Email", 124 "rating"=>"Rating", 125 "sic_code"=>"SIC Code", 126 "annual_revenue"=>"Annual Revenue", 127 "billing_address_street"=>"Billing Address Street", 128 "billing_address_city"=>"Billing Address City", 129 "billing_address_state"=>"Billing Address State", 130 "billing_address_postalcode"=>"Billing Address Postalcode", 131 "billing_address_country"=>"Billing Address Country", 132 "shipping_address_street"=>"Shipping Address Street", 133 "shipping_address_city"=>"Shipping Address City", 134 "shipping_address_state"=>"Shipping Address State", 135 "shipping_address_postalcode"=>"Shipping Address Postalcode", 136 "shipping_address_country"=>"Shipping Address Country", 137 "description"=>"Description" 138 ); 139 $focus = 0; 140 $content = ''; 141 142 $bean = $beanList[$type]; 143 require_once($beanFiles[$bean]); 144 $focus = new $bean; 145 $searchFields = array(); 146 $db = DBManagerFactory::getInstance(); 147 148 if($records) { 149 $records = explode(',', $records); 150 $records = "'" . implode("','", $records) . "'"; 151 $where = "{$focus->table_name}.id in ($records)"; 152 } elseif (isset($_REQUEST['all']) ) { 153 $where = ''; 154 } else { 155 if(!empty($_REQUEST['current_post'])) { 156 $ret_array = generateSearchWhere($type, $_REQUEST['current_post']); 157 158 $where = $ret_array['where']; 159 $searchFields = $ret_array['searchFields']; 160 } else { 161 $where = ''; 162 } 163 } 164 $order_by = ""; 165 if($focus->bean_implements('ACL')){ 166 if(!ACLController::checkAccess($focus->module_dir, 'export', true)){ 167 ACLController::displayNoAccess(); 168 sugar_die(''); 169 } 170 if(ACLController::requireOwner($focus->module_dir, 'export')){ 171 if(!empty($where)){ 172 $where .= ' AND '; 173 } 174 $where .= $focus->getOwnerWhere($current_user->id); 175 } 176 177 } 178 // Export entire list was broken because the where clause already has "where" in it 179 // and when the query is built, it has a "where" as well, so the query was ill-formed. 180 // Eliminating the "where" here so that the query can be constructed correctly. 181 if($members == true){ 182 $query = $focus->create_export_members_query($records); 183 }else{ 184 $beginWhere = substr(trim($where), 0, 5); 185 if ($beginWhere == "where") 186 $where = substr(trim($where), 5, strlen($where)); 187 $ret_array = create_export_query_relate_link_patch($type, $searchFields, $where); 188 if(!empty($ret_array['join'])) { 189 $query = $focus->create_export_query($order_by,$ret_array['where'],$ret_array['join']); 190 } else { 191 $query = $focus->create_export_query($order_by,$ret_array['where']); 192 } 193 } 194 195 196 $result = $db->query($query, true, $app_strings['ERR_EXPORT_TYPE'].$type.": <BR>.".$query); 197 198 $fields_array = $db->getFieldsArray($result,true); 199 200 // setup the "header" line with quotation marks 201 $header = implode("\"".getDelimiter()."\"", array_values($fields_array)); 202 if($members){ 203 $header = str_replace('"ea_deleted","ear_deleted","primary_address",','',$header); 204 } 205 $header = "\"" .$header; 206 $header .= "\"\r\n"; 207 $content .= $header; 208 $pre_id = ''; 209 210 while($val = $db->fetchByAssoc($result, -1, false)) { 211 $new_arr = array(); 212 213 214 215 216 217 218 219 220 221 if($members){ 222 if($pre_id == $val['id']) 223 continue; 224 if($val['ea_deleted']==1 || $val['ear_deleted']==1){ 225 $val['primary_email_address'] = ''; 226 } 227 unset($val['ea_deleted']); 228 unset($val['ear_deleted']); 229 unset($val['primary_address']); 230 } 231 $pre_id = $val['id']; 232 $vals = array_values($val); 233 foreach ($vals as $key => $value) { 234 //if our value is a datetime field, then apply the users locale 235 if(isset($focus->field_name_map[$fields_array[$key]]['type']) && $focus->field_name_map[$fields_array[$key]]['type'] == 'datetime'){ 236 $value = $timedate->to_display_date_time($value); 237 $value = preg_replace('/([pm|PM|am|AM]+)/', ' \1', $value); 238 } 239 //kbrill Bug #16296 240 if(isset($focus->field_name_map[$fields_array[$key]]['type']) && $focus->field_name_map[$fields_array[$key]]['type'] == 'date'){ 241 $value = $timedate->to_display_date($value, false); 242 } 243 244 245 246 247 248 249 array_push($new_arr, preg_replace("/\"/","\"\"", $value)); 250 } 251 $line = implode("\"".getDelimiter()."\"", $new_arr); 252 $line = "\"" .$line; 253 $line .= "\"\r\n"; 254 255 $content .= $line; 256 } 257 return $content; 258 } 259 260 function generateSearchWhere($module, $query) {//this function is similar with function prepareSearchForm() in view.list.php 261 $seed = loadBean($module); 262 if(file_exists('modules/'.$module.'/SearchForm.html')){ 263 if(file_exists('modules/' . $module . '/metadata/SearchFields.php')) { 264 require_once ('include/SearchForm/SearchForm.php'); 265 $searchForm = new SearchForm($module, $seed); 266 } 267 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. 268 //So currently massupdate will not gernerate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now. 269 $where = $_SESSION['export_where']; 270 $whereArr = explode (" ", trim($where)); 271 if ($whereArr[0] == trim('where')) { 272 $whereClean = array_shift($whereArr); 273 } 274 $where = implode(" ", $whereArr); 275 //rrs bug: 31329 - previously this was just returning $where, but the problem is the caller of this function 276 //expects the results in an array, not just a string. So rather than fixing the caller, I felt it would be best for 277 //the function to return the results in a standard format. 278 $ret_array['where'] = $where; 279 $ret_array['searchFields'] =array(); 280 return $ret_array; 281 } 282 else { 283 return; 284 } 285 } 286 else{ 287 require_once ('include/SearchForm/SearchForm2.php'); 288 if (file_exists('custom/modules/'.$module.'/metadata/searchdefs.php')) 289 { 290 require_once('custom/modules/'.$module.'/metadata/searchdefs.php'); 291 } 292 elseif (!empty($metafiles[$module]['searchdefs'])) 293 { 294 require_once($metafiles[$module]['searchdefs']); 295 } 296 elseif (file_exists('modules/'.$module.'/metadata/searchdefs.php')) 297 { 298 require_once('modules/'.$module.'/metadata/searchdefs.php'); 299 } 300 301 if(!empty($metafiles[$module]['searchfields'])) 302 require_once($metafiles[$module]['searchfields']); 303 elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php')) 304 require_once('modules/'.$module.'/metadata/SearchFields.php'); 305 if(empty($searchdefs) || empty($searchFields)) { 306 //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty. 307 return; 308 } 309 $searchForm = new SearchForm($seed, $module); 310 $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); 311 } 312 $searchForm->populateFromArray(unserialize(base64_decode($query))); 313 $where_clauses = $searchForm->generateSearchWhere(true, $module); 314 if (count($where_clauses) > 0 )$where = '('. implode(' ) AND ( ', $where_clauses) . ')'; 315 $GLOBALS['log']->info("Export Where Clause: {$where}"); 316 $ret_array['where'] = $where; 317 $ret_array['searchFields'] = $searchForm->searchFields; 318 return $ret_array; 319 } 320 321 322 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
|
|
|