| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 * 10 ********************************************************************************/ 11 12 $count = 0; 13 $skip_required_count = 0; 14 15 /** function used to save the records into database 16 * @param array $rows - array of total rows of the csv file 17 * @param array $rows1 - rows to be saved 18 * @param object $focus - object of the corresponding import module 19 * @param int $ret_field_count - total number of fields(columns) available in the csv file 20 * @param int $col_pos_to_field - field position in the mapped array 21 * @param int $start - starting row count value to import 22 * @param int $recordcount - count of records to be import ie., number of records to import 23 * @param string $module - import module 24 * @param int $totalnoofrows - total number of rows available 25 * @param int $skip_required_count - number of records skipped 26 This function will redirect to the ImportStep3 if the available records is greater than the record count (ie., number of records import in a single loop) otherwise (total records less than 500) then it will be redirected to import step last 27 */ 28 function InsertImportRecords($rows,$rows1,$focus,$ret_field_count,$col_pos_to_field,$start,$recordcount,$module,$totalnoofrows,$skip_required_count) 29 { 30 global $current_user; 31 global $adb; 32 33 // MWC ** Getting vtiger_users 34 $temp = get_user_array(FALSE); 35 foreach ( $temp as $key=>$data) 36 $my_users[$data] = $key; 37 p(print_r(my_users,1)); 38 $adb->println("Users List : "); 39 $adb->println($my_users); 40 41 if($start == 0) 42 { 43 $_SESSION['totalrows'] = $rows; 44 $_SESSION['return_field_count'] = $ret_field_count; 45 $_SESSION['column_position_to_field'] = $col_pos_to_field; 46 } 47 $ii = $start; 48 // go thru each row, process and save() 49 foreach ($rows1 as $row) 50 { 51 $adb->println("Going to Save the row ".$ii." =====> "); 52 $adb->println($row); 53 global $mod_strings; 54 55 $do_save = 1; 56 //MWC 57 $my_userid = $current_user->id; 58 59 for($field_count = 0; $field_count < $ret_field_count; $field_count++) 60 { 61 p("col_pos[".$field_count."]=".$col_pos_to_field[$field_count]); 62 63 if ( isset( $col_pos_to_field[$field_count]) ) 64 { 65 p("set =".$field_count); 66 if (! isset( $row[$field_count]) ) 67 { 68 continue; 69 } 70 71 p("setting"); 72 73 // TODO: add check for user input 74 // addslashes, striptags, etc.. 75 $field = $col_pos_to_field[$field_count]; 76 if (substr(trim($field), 0, 3) == "CF_") 77 { 78 p("setting custfld".$field."=".$row[$field_count]); 79 $resCustFldArray[$field] = $row[$field_count]; 80 } 81 //MWC 82 elseif ( $field == "assignedto" || $field == "assigned_user_id" ) 83 { 84 //Here we are assigning the user id in column fields, so in function assign_user (ImportLead.php and ImportProduct.php files) we should use the id instead of user name when query the user 85 //or we can use $focus->column_fields['smownerid'] = $my_users[$row[$field_count]]; 86 $focus->column_fields[$field] = $my_users[$row[$field_count]]; 87 p("setting my_userid=$my_userid for user=".$row[$field_count]); 88 } 89 else 90 { 91 //$focus->$field = $row[$field_count]; 92 $focus->column_fields[$field] = $row[$field_count]; 93 p("Setting ".$field."=".$row[$field_count]); 94 } 95 96 } 97 98 } 99 100 p("setting done"); 101 102 p("do save before req vtiger_fields=".$do_save); 103 104 $adb->println($focus->required_fields); 105 106 foreach ($focus->required_fields as $field=>$notused) 107 { 108 $fv = $focus->column_fields[$field]; 109 if (! isset($fv) || $fv == '') 110 { 111 p("fv ".$field." not set"); 112 $do_save = 0; 113 $skip_required_count++; 114 break; 115 } 116 } 117 118 p("do save=".$do_save); 119 120 if ($do_save) 121 { 122 p("saving.."); 123 124 125 if ( ! isset($focus->column_fields["assigned_user_id"]) || $focus->column_fields["assigned_user_id"]=='') 126 { 127 //$focus->column_fields["assigned_user_id"] = $current_user->id; 128 //MWC 129 $focus->column_fields["assigned_user_id"] = $my_userid; 130 } 131 132 // now do any special processing for ex., map account with contact and potential 133 $focus->process_special_fields(); 134 135 $focus->save($module); 136 //$focus->saveentity($module); 137 $return_id = $focus->id; 138 139 if(count($resCustFldArray)>0) 140 { 141 142 if($_REQUEST['module'] == 'Contacts') 143 { 144 $_REQUEST['module']='contactdetails'; 145 } 146 $dbquery="select * from vtiger_field where vtiger_tablename='".$_REQUEST['module']."'"; 147 $custresult = $adb->query($dbquery); 148 if($adb->num_rows($custresult) != 0) 149 { 150 if (! isset( $_REQUEST['module'] ) || $_REQUEST['module'] == 'Contacts') 151 { 152 $columns = 'contactid'; 153 $custTabName = 'contactscf'; 154 } 155 else if ( $_REQUEST['module'] == 'Accounts') 156 { 157 $columns = 'accountid'; 158 $custTabName = 'accountscf'; 159 } 160 else if ( $_REQUEST['module'] == 'Potentials') 161 { 162 $columns = 'potentialid'; 163 $custTabName = 'potentialscf'; 164 } 165 166 else if ( $_REQUEST['module'] == 'Products') 167 { 168 $columns = 'productid'; 169 $custTabName = 'productscf'; 170 } 171 $noofrows = $adb->num_rows($custresult); 172 $values='"'.$focus->id.'"'; 173 for($j=0; $j<$noofrows; $j++) 174 { 175 $colName=$adb->query_result($custresult,$j,"columnname"); 176 if(array_key_exists($colName, $resCustFldArray)) 177 { 178 $value_colName = $resCustFldArray[$colName]; 179 180 $columns .= ', '.$colName; 181 $values .= ', "'.$value_colName.'"'; 182 } 183 } 184 185 $insert_custfld_query = 'insert into '.$custTabName.' ('.$columns.') values('.$values.')'; 186 $adb->query($insert_custfld_query); 187 188 } 189 } 190 191 $last_import = new UsersLastImport(); 192 $last_import->assigned_user_id = $current_user->id; 193 $last_import->bean_type = $_REQUEST['module']; 194 $last_import->bean_id = $focus->id; 195 $last_import->save(); 196 array_push($saved_ids,$focus->id); 197 $count++; 198 } 199 $ii++; 200 } 201 202 $_REQUEST['count'] = $ii; 203 if(isset($_REQUEST['module'])) 204 $modulename = $_REQUEST['module']; 205 206 $end = $start+$recordcount; 207 $START = $start + $recordcount; 208 $RECORDCOUNT = $recordcount; 209 210 if($end >= $totalnoofrows) 211 { 212 $module = 'Import';//$_REQUEST['module']; 213 $action = 'ImportSteplast'; 214 //exit; 215 $imported_records = $ii - $skip_required_count; 216 if($imported_records == $ii) 217 $skip_required_count = 0; 218 $message= urlencode("<b>".$mod_strings['LBL_SUCCESS']."</b>"."<br><br>" .$mod_strings['LBL_SUCCESS_1']." $imported_records" ."<br><br>" .$mod_strings['LBL_SKIPPED_1']." $skip_required_count " ); 219 } 220 else 221 { 222 $module = 'Import'; 223 $action = 'ImportStep3'; 224 } 225 ?> 226 227 <script> 228 setTimeout("b()",1000); 229 function b() 230 { 231 document.location.href="index.php?action=<?php echo $action?>&module=<?php echo $module?>&modulename=<?php echo $modulename?>&startval=<?php echo $end?>&recordcount=<?php echo $RECORDCOUNT?>&noofrows=<?php echo $totalnoofrows?>&message=<?php echo $message?>&skipped_record_count=<?php echo $skip_required_count?>&parenttab=<?php echo $_SESSION['import_parenttab']?>"; 232 } 233 </script> 234 235 <?php 236 $_SESSION['import_display_message'] = '<br>'.$start.' to '.$end.' of '.$totalnoofrows.' are imported successfully'; 237 //return $_SESSION['import_display_message']; 238 } 239 ?> 240
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 |