Changeset 276
- Timestamp:
- 04/30/08 17:16:01 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/contactcenter/inc/class.ui_data.inc.php
r258 r276 182 182 $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)')); 183 183 $GLOBALS['phpgw']->template->set_var('cc_msg_choose_contacts_file', lang('Select the file that contains the contacts to be imported:')); 184 $GLOBALS['phpgw']->template->set_var('cc_msg_close ', lang('Close'));184 $GLOBALS['phpgw']->template->set_var('cc_msg_close_win', lang('Close')); 185 185 $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts')); 186 186 $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.')); 187 187 $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...')); 188 188 $GLOBALS['phpgw']->template->set_var('cc_msg_import_finished', lang('The importation has finished.')); 189 $GLOBALS['phpgw']->template->set_var('cc_msg_choose_valid_csv', lang('Select a valid CSV file to import your contacts')); 189 $GLOBALS['phpgw']->template->set_var('cc_msg_new', lang(' new')); 190 $GLOBALS['phpgw']->template->set_var('cc_msg_failure', lang(' failed')); 191 $GLOBALS['phpgw']->template->set_var('cc_msg_exists', lang(' were existent')); 192 $GLOBALS['phpgw']->template->set_var('cc_msg_show_more_info', lang('show more info')); 193 $GLOBALS['phpgw']->template->set_var('cc_msg_clean', lang('Clean')); 194 $GLOBALS['phpgw']->template->set_var('cc_msg_invalid_csv', lang('Select a valid CSV file to import your contacts')); 190 195 $GLOBALS['phpgw']->template->set_var('cc_msg_export_csv', lang('Select the format type that you want to export your contacts')); 196 $GLOBALS['phpgw']->template->set_var('cc_msg_automatic', lang('Automatic')); 191 197 $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.')); 192 198 $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email')); … … 2466 2472 echo serialize($return); 2467 2473 } 2468 2474 2469 2475 function export_contacts($typeExport){ 2470 2476 … … 2558 2564 break; 2559 2565 2560 default:2566 case 'expresso': 2561 2567 $streamBuffer = "Nome,Email,Telefone\r\n"; 2562 2568 foreach($all_contacts as $index => $object){ … … 2579 2585 } 2580 2586 2587 // Get the csv field and put into array, from php.net 2588 function parse_line($input_text, $delimiter = ',', $text_qualifier = '"') { 2589 $text = trim($input_text); 2590 if(is_string($delimiter) && is_string($text_qualifier)) { 2591 $re_d = '\x' . dechex(ord($delimiter)); //format for regexp 2592 $re_tq = '\x' . dechex(ord($text_qualifier)); //format for regexp 2593 2594 $fields = array(); 2595 $field_num = 0; 2596 while(strlen($text) > 0) { 2597 if($text{0} == $text_qualifier) { 2598 preg_match('/^' . $re_tq . '((?:[^' . $re_tq . ']|(?<=\x5c)' . $re_tq . ')*)' . $re_tq . $re_d . '?(.*)$/', $text, $matches); 2599 2600 $value = str_replace('\\' . $text_qualifier, $text_qualifier, $matches[1]); 2601 $text = trim($matches[2]); 2602 2603 $fields[$field_num++] = $value; 2604 } else { 2605 preg_match('/^([^' . $re_d . ']*)' . $re_d . '?(.*)$/', $text, $matches); 2606 2607 $value = $matches[1]; 2608 $text = trim($matches[2]); 2609 2610 $fields[$field_num++] = $value; 2611 } 2612 } 2613 return $fields; 2614 } else 2615 return false; 2616 } 2581 2617 2582 2618 function import_contacts($typeImport){ 2583 2584 $delim = ($typeImport == 'outlook' ? ';' : ','); 2585 2619 2586 2620 if($file = $_SESSION['contactcenter']['importCSV']) { 2587 2621 unset($_SESSION['contactcenter']['importCSV']); … … 2589 2623 $count = 0; 2590 2624 $return = array('error' => false, '_new' => 0, '_existing' => 0, '_failure' => 0); 2591 $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); 2625 $handle = @fopen($file, "r") or die(serialize($return['error'] = true)); 2626 2627 $input_header = fgets($handle); 2628 if ($typeImport == 'outlook') 2629 $delim = ';'; 2630 else if ($typeImport == 'auto') 2631 $delim = strstr($input_header,',') ? ',' : ';'; 2632 else 2633 $delim = ','; 2634 $csv_header = $this->parse_line($input_header,$delim); 2635 $firstContact = fgets($handle); 2636 preg_match("/\"(.+)\"[,;]/sU",$firstContact,$matches); // yahoo csv 2637 rewind($handle); 2638 2592 2639 $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); 2593 2640 if(count($header) < 2 || count($header) > 100) { … … 2597 2644 return; 2598 2645 } 2599 2600 $boGroup = CreateObject('contactcenter.bo_group'); 2601 $boPeople = CreateObject('contactcenter.bo_people_catalog'); 2602 2646 2647 if ($matches[0][strlen($matches[0])-1] == ';') 2648 $delim = ';'; 2649 2650 $boGroup = CreateObject('contactcenter.bo_group'); 2651 $boPeople = CreateObject('contactcenter.bo_people_catalog'); 2603 2652 switch($typeImport){ 2604 2653 case 'outlook2000': … … 2617 2666 $phone_pos=7; 2618 2667 break; 2619 default:2668 case 'expresso': 2620 2669 $name_pos=0; 2621 2670 $email_pos=1; 2622 2671 $phone_pos=2; 2623 } 2624 2672 break; 2673 default: 2674 foreach($csv_header as $index => $fieldName) 2675 { 2676 switch($fieldName){ 2677 case 'Name': 2678 case 'Nome': 2679 case 'First Name': 2680 $name_pos = $index; 2681 break; 2682 case 'E-mail': 2683 case 'Email': 2684 case 'E-mail Address': 2685 case 'Endereço de correio eletrônico': 2686 case 'End. de email': 2687 $email_pos = $index; 2688 break; 2689 case 'Home Phone': 2690 case 'Phone': 2691 case 'Telefone': 2692 case 'Telefone principal': 2693 case 'Telefone comercial': 2694 $phone_pos = $index; 2695 break; 2696 } 2697 } 2698 break; 2699 } 2700 2701 2625 2702 while (($data = fgetcsv($handle, $len, $delim))) { 2626 2627 2703 foreach ($header as $key=>$heading) 2628 2704 $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; … … 2645 2721 $contact = $boGroup->verify_contact($email); 2646 2722 2723 $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new']; 2647 2724 if($contact){ 2648 2725 $return['_existing']++; … … 2650 2727 else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { 2651 2728 $return['_failure']++; 2729 $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; 2652 2730 } 2653 2731 else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){ 2654 2732 $return['_failure']++; 2733 $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; 2655 2734 } 2656 2735 else
Note: See TracChangeset
for help on using the changeset viewer.