[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc. 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * $Header$ 17 * Description: TODO: To be written. 18 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 19 * All Rights Reserved. 20 * Contributor(s): ______________________________________.. 21 ********************************************************************************/ 22 23 require_once ('Smarty_setup.php'); 24 require_once ('modules/Import/ImportLead.php'); 25 require_once ('modules/Import/ImportAccount.php'); 26 require_once ('modules/Import/ImportContact.php'); 27 require_once ('modules/Import/ImportOpportunity.php'); 28 require_once ('modules/Import/ImportProduct.php'); 29 require_once ('modules/Import/ImportMap.php'); 30 require_once ('modules/Import/UsersLastImport.php'); 31 require_once ('modules/Import/parse_utils.php'); 32 require_once ('include/ListView/ListView.php'); 33 require_once ('include/database/PearDatabase.php'); 34 require_once ('modules/Import/ImportSave.php'); 35 36 set_time_limit(0); 37 ini_set("display_errors",'0'); 38 39 40 function p($str) 41 { 42 global $adb; 43 $adb->println("IMP :".$str); 44 } 45 46 function implode_assoc($inner_delim, $outer_delim, $array) 47 { 48 $output = array(); 49 50 foreach( $array as $key => $item ) 51 { 52 $output[] = $key . $inner_delim . $item; 53 } 54 55 return implode($outer_delim, $output); 56 } 57 58 global $mod_strings; 59 global $app_list_strings; 60 global $app_strings; 61 global $current_user; 62 global $import_file_name; 63 global $theme; 64 global $upload_maxsize; 65 global $site_URL; 66 67 $theme_path="themes/".$theme."/"; 68 $image_path=$theme_path."images/"; 69 require_once ($theme_path.'layout_utils.php'); 70 71 $log->info("Upload Step 3"); 72 73 74 $delimiter = ','; 75 // file handle 76 $count = 0; 77 $error = ""; 78 $col_pos_to_field = array(); 79 $header_to_field = array(); 80 $field_to_pos = array(); 81 $focus = 0; 82 $current_bean_type = ""; 83 $id_exists_count = 0; 84 $broken_ids = 0; 85 86 $has_header = 0; 87 88 if ( isset( $_REQUEST['has_header']) && $_REQUEST['has_header'] == 'on') 89 { 90 $has_header = 1; 91 } 92 if($_REQUEST['modulename'] != '') 93 $_REQUEST['module'] = $_REQUEST['modulename']; 94 95 96 $import_object_array = Array( 97 "Leads"=>"ImportLead", 98 "Accounts"=>"ImportAccount", 99 "Contacts"=>"ImportContact", 100 "Potentials"=>"ImportOpportunity", 101 "Products"=>"ImportProduct" 102 ); 103 104 if(isset($_REQUEST['module']) && $_REQUEST['module'] != '') 105 { 106 $current_bean_type = $import_object_array[$_REQUEST['module']]; 107 } 108 else 109 { 110 $current_bean_type = "ImportContact"; 111 } 112 113 $focus = new $current_bean_type(); 114 115 //Constructing the custom vtiger_field Array 116 require_once ('include/CustomFieldUtil.php'); 117 $custFldArray = getCustomFieldArray($_REQUEST['module']); 118 p("IMP 3: custFldArray"); 119 p($custFldArray); 120 121 //Initializing an empty Array to store the custom vtiger_field Column Name and Value 122 $resCustFldArray = Array(); 123 124 p("Getting from request"); 125 // loop through all request variables 126 foreach ($_REQUEST as $name=>$value) 127 { 128 p("name=".$name." value=".$value); 129 // only look for var names that start with "colnum" 130 if ( strncasecmp( $name, "colnum", 6) != 0 ) 131 { 132 continue; 133 } 134 if ($value == "-1") 135 { 136 137 continue; 138 } 139 140 // this value is a user defined vtiger_field name 141 $user_field = $value; 142 143 // pull out the column position for this vtiger_field name 144 $pos = substr($name,6); 145 146 // make sure we haven't seen this vtiger_field defined yet 147 if ( isset( $field_to_pos[$user_field]) ) 148 { 149 show_error_import($mod_strings['LBL_ERROR_MULTIPLE']); 150 exit; 151 152 } 153 154 p("user_field=".$user_field." if=".$focus->importable_fields[$user_field]); 155 156 // match up the "official" vtiger_field to the user 157 // defined one, and map to columm position: 158 if ( isset( $focus->importable_fields[$user_field] ) || isset( $custFldArray[$user_field] )) 159 { 160 p("user_field SET=".$user_field); 161 // now mark that we've seen this vtiger_field 162 $field_to_pos[$user_field] = $pos; 163 $col_pos_to_field[$pos] = $user_field; 164 } 165 } 166 167 p("field_to_pos"); 168 $adb->println($field_to_pos); 169 p("col_pos_to_field"); 170 $adb->println($col_pos_to_field); 171 172 // Now parse the file and look for errors 173 $max_lines = -1; 174 175 $ret_value = 0; 176 177 if ($_REQUEST['source'] == 'act') 178 { 179 $ret_value = parse_import_act($_REQUEST['tmp_file'],$delimiter,$max_lines,$has_header); 180 } 181 else 182 { 183 $ret_value = parse_import($_REQUEST['tmp_file'],$delimiter,$max_lines,$has_header); 184 } 185 186 if (file_exists($_REQUEST['tmp_file'])) 187 { 188 unlink($_REQUEST['tmp_file']); 189 } 190 191 $datarows = $ret_value['rows']; 192 193 $ret_field_count = $ret_value['field_count']; 194 195 $saved_ids = array(); 196 197 $firstrow = 0; 198 199 if (! isset($datarows)) 200 { 201 $error = $mod_strings['LBL_FILE_ALREADY_BEEN_OR']; 202 $datarows = array(); 203 } 204 205 if ($has_header == 1) 206 { 207 $firstrow = array_shift($datarows); 208 } 209 210 //Mark the last imported records as deleted which are imported by the current user in vtiger_users_last_import vtiger_table 211 if(!isset($_REQUEST['startval'])) 212 { 213 $seedUsersLastImport = new UsersLastImport(); 214 $seedUsersLastImport->mark_deleted_by_user_id($current_user->id); 215 } 216 $skip_required_count = 0; 217 218 p("processing started ret_field_count=".$ret_field_count); 219 $adb->println($datarows); 220 221 $error = ''; 222 $focus = new $current_bean_type(); 223 224 225 // SAVE MAPPING IF REQUESTED 226 if(isset($_REQUEST['save_map']) && $_REQUEST['save_map'] == 'on' && isset($_REQUEST['save_map_as']) && $_REQUEST['save_map_as'] != '') 227 { 228 p("save map"); 229 $serialized_mapping = ''; 230 231 if( $has_header) 232 { 233 foreach($col_pos_to_field as $pos=>$field_name) 234 { 235 if ( isset($firstrow[$pos]) && isset( $field_name)) 236 { 237 $header_to_field[ $firstrow[$pos] ] = $field_name; 238 } 239 } 240 241 $serialized_mapping = implode_assoc("=","&",$header_to_field); 242 } 243 else 244 { 245 $serialized_mapping = implode_assoc("=","&",$col_pos_to_field); 246 } 247 248 $mapping_file_name = $_REQUEST['save_map_as']; 249 250 $mapping_file = new ImportMap(); 251 252 //$query_arr = array('assigned_user_id'=>$current_user->id,'name'=>$mapping_file_name); 253 //$mapping_file->retrieve_by_string_fields($query_arr, false); 254 255 $result = $mapping_file->save_map( $current_user->id, 256 $mapping_file_name, 257 $_REQUEST['module'], 258 $has_header, 259 $serialized_mapping ); 260 261 $adb->println("Save map done"); 262 $adb->println($result); 263 } 264 //save map - ends 265 266 267 268 269 if(isset($_SESSION['totalrows']) && $_SESSION['totalrows'] != '') 270 { 271 $xrows = $_SESSION['totalrows']; 272 } 273 else 274 { 275 $xrows = $datarows; 276 } 277 if(isset($_SESSION['return_field_count'])) 278 { 279 $ret_field_count = $_SESSION['return_field_count']; 280 } 281 if(isset($_SESSION['column_position_to_field'])) 282 { 283 $col_pos_to_field = $_SESSION['column_position_to_field']; 284 } 285 if($xrows != '') 286 { 287 $datarows = $xrows; 288 } 289 if($_REQUEST['skipped_record_count'] != '') 290 $skipped_record_count = $_REQUEST['skipped_record_count']; 291 else 292 $_REQUEST['skipped_record_count'] = 0; 293 294 if($_REQUEST['noofrows'] != '') 295 $totalnoofrows = $_REQUEST['noofrows']; 296 else 297 $totalnoofrows = count($datarows); 298 299 $loopcount = ($totalnoofrows/$RECORDCOUNT)+1; 300 301 if($_REQUEST['startval'] != '') 302 $START = $_REQUEST['startval']; 303 else 304 $START = $_SESSION['startval']; 305 if($_REQUEST['recordcount'] != '') 306 $RECORDCOUNT = $_REQUEST['recordcount']; 307 else 308 $RECORDCOUNT = $_SESSION['recordcount']; 309 310 if(($START+$RECORDCOUNT) > $totalnoofrows) 311 { 312 $RECORDCOUNT = $totalnoofrows - $START; 313 } 314 315 if($totalnoofrows > $RECORDCOUNT && $START < $totalnoofrows) 316 { 317 $rows1 = Array(); 318 for($j=$START;$j<$START+$RECORDCOUNT;$j++) 319 { 320 $rows1[] = $datarows[$j]; 321 } 322 323 $res = InsertImportRecords($datarows,$rows1,$focus,$ret_field_count,$col_pos_to_field,$START,$RECORDCOUNT,$_REQUEST['module'],$totalnoofrows,$skipped_record_count); 324 325 if($START != 0) 326 echo '<b>'.$res.'</b>'; 327 328 $count = $_REQUEST['count']; 329 } 330 else 331 { 332 if($START == 0) 333 { 334 $res = InsertImportRecords($datarows,$datarows,$focus,$ret_field_count,$col_pos_to_field,$START,$totalnoofrows,$_REQUEST['module'],$totalnoofrows,$skipped_record_count); 335 } 336 // exit; 337 } 338 339 //Display the imported records message 340 echo "<div align='center' width='100%'><font color='green'><b>".$_SESSION['import_display_message']."</b></font></div>"; 341 342 343 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |