Changeset 276


Ignore:
Timestamp:
04/30/08 17:16:01 (16 years ago)
Author:
niltonneto
Message:

Correções na importação e exportação dos contatos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/contactcenter/inc/class.ui_data.inc.php

    r258 r276  
    182182                        $GLOBALS['phpgw']->template->set_var('cc_msg_expresso_default', lang('Expresso (default)')); 
    183183                        $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')); 
    185185                        $GLOBALS['phpgw']->template->set_var('cc_msg_ie_personal', lang('Import / Export personal Contacts')); 
    186186                        $GLOBALS['phpgw']->template->set_var('cc_msg_import_fail', lang('The importation has failed. Verify the file format.')); 
    187187                        $GLOBALS['phpgw']->template->set_var('cc_msg_importing_contacts', lang('Importing Contacts...')); 
    188188                        $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')); 
    190195                        $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')); 
    191197                        $GLOBALS['phpgw']->template->set_var('cc_msg_export_error', lang('An error has occurred while the exportation.')); 
    192198                        $GLOBALS['phpgw']->template->set_var('cc_msg_new_email', lang('New Email')); 
     
    24662472                        echo serialize($return); 
    24672473                }        
    2468  
     2474                 
    24692475                function export_contacts($typeExport){ 
    24702476 
     
    25582564                                break; 
    25592565                                 
    2560                                 default: 
     2566                                case 'expresso': 
    25612567                                        $streamBuffer = "Nome,Email,Telefone\r\n"; 
    25622568                                        foreach($all_contacts as $index => $object){ 
     
    25792585                } 
    25802586 
     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                } 
    25812617 
    25822618                function import_contacts($typeImport){ 
    2583                                                  
    2584                         $delim          = ($typeImport == 'outlook' ? ';' : ','); 
    2585                          
     2619 
    25862620                        if($file = $_SESSION['contactcenter']['importCSV']) {                            
    25872621                                unset($_SESSION['contactcenter']['importCSV']);                          
     
    25892623                                $count = 0; 
    25902624                                $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 
    25922639                                $header = @fgetcsv($handle, $len, $delim) or die(serialize($return['error'] = true)); 
    25932640                                if(count($header)  < 2 || count($header) > 100) { 
     
    25972644                                        return; 
    25982645                                } 
    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'); 
    26032652                                switch($typeImport){ 
    26042653                                        case 'outlook2000': 
     
    26172666                                                $phone_pos=7; 
    26182667                                                break; 
    2619                                         default: 
     2668                                        case 'expresso': 
    26202669                                                $name_pos=0; 
    26212670                                                $email_pos=1; 
    26222671                                                $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 
    26252702                                while (($data = fgetcsv($handle, $len, $delim))) { 
    2626  
    26272703                                foreach ($header as $key=>$heading) 
    26282704                                $row[$heading]=(isset($data[$key])) ? $data[$key] : ''; 
     
    26452721                                        $contact = $boGroup->verify_contact($email); 
    26462722 
     2723                                        $line_iteration = $return['_failure'] + $return['_existing'] + $return['_new'];  
    26472724                                        if($contact){ 
    26482725                                                $return['_existing']++; 
     
    26502727                                        else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { 
    26512728                                                $return['_failure']++; 
     2729                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid E-Mail address: " . $email ."<br>"; 
    26522730                                        } 
    26532731                                        else if (!$sdata['given_names'] || !$email || !$boPeople ->quick_add($sdata)){                                           
    26542732                                                $return['_failure']++;                                                   
     2733                                                $return['_failure_status'] .= "Line: " . ($line_iteration + 2) . ", Invalid Name: " . $sdata['given_names'] ."<br>"; 
    26552734                                        } 
    26562735                                        else 
Note: See TracChangeset for help on using the changeset viewer.