Ignore:
Timestamp:
01/10/12 11:25:51 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2434 - Commit inicial do novo módulo de agenda do Expresso - expressoCalendar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/services/ImapServiceAdapter.php

    r5204 r5341  
    11<?php 
    22 
    3 include_once "../header.session.inc.php"; 
    4  
    5 include_once "../expressoMail1_2/inc/class.imap_functions.inc.php"; 
     3include_once ROOTPATH."/../header.session.inc.php"; 
     4 
     5include_once ROOTPATH."/../expressoMail1_2/inc/class.imap_functions.inc.php"; 
    66 
    77class ImapServiceAdapter extends imap_functions/* implements Service*/ 
     
    1212    } 
    1313 
    14     public function connect( $config ) 
    15     { 
    16         $this->init(); 
    17     } 
    18  
    19     public function find( $URI, $context, $justthese = false, $criteria = false ) 
    20     { 
     14//     public function connect( $config ) 
     15//     { 
     16//      $this->init(); 
     17//     } 
    2118         
    22         if( is_array($URI) ) 
     19    public function find( $URI, $justthese = false, $criteria = false ) 
    2320        {  
    24             $criteria = $justthese; 
    25             $justthese = $context; 
    26             $context = $URI['context']; 
     21        $context = $justthese['context']; 
    2722            $URI = $URI['concept']; 
    28         } 
    2923 
    3024        switch( $URI ) 
     
    5448                $sord  = $criteria['sord']; //{desc} get the direction 
    5549 
     50                $filter = $criteria['filter']; 
     51 
    5652                if( !$sidx ) $sidx = 1; 
    5753 
    5854                $folder_name = str_replace( '.', $this->imap_delimiter, $context['folder'] ); 
    5955                 
    60                 $folder = $this->get_range_msgs2(array('folder'=>$folder_name)); 
    61  
    62                 $count = $folder['num_msgs']; 
     56                $count = imap_num_msg( $this->open_mbox( $folder_name ) ); 
    6357 
    6458                $total_pages = $count > 0 ? ceil( $count/$limit ) : 0; 
     
    6761                    $page = $total_pages; 
    6862 
    69                 $start = $limit * $page - $limit; // do not put $limit*($page - 1) 
     63                $start = $limit * $page - $limit; 
     64 
     65                // do not put $limit*($page - 1) 
    7066                //end: for grid 
    7167 
    72                 $service_params = array( 'folder' => $folder_name, //INBOX 
     68                if( $filter ) 
     69                { 
     70                    if( $filter[0] !== 'msgNumber' ) 
     71                    { 
     72                        for( $i = 0; $i < count($filter); $i++ ) 
     73                        { 
     74                            if( count( $filter[$i] ) === 4 ) 
     75                                $criteria['isExact'] = ( array_shift( $filter[$i] ) === 'AND' ); 
     76 
     77                            $criteria[ $filter[$i][0] ] = array( 'criteria' => $filter[$i][2], 'filter' => $filter[$i][1] ); 
     78                        } 
     79 
     80                        return $this->searchSieveRule($criteria); 
     81                    } 
     82 
     83                    $msgNumber = array(); 
     84 
     85                    for( $i = $start; $i < $start + $limit && isset( $filter[2][$i] ); $i++ ) 
     86                          $msgNumber[] = $filter[2][$i]; 
     87 
     88                    if( empty( $msgNumber ) ) 
     89                        return( false ); 
     90 
     91                    $result = $this->get_info_msgs( array( 'folder' => $folder_name,  
     92                                                           'msgs_number' => implode( ',', $msgNumber ) ) ); 
     93 
     94                    foreach( $result as $i => $val ) 
     95                        $result[$i] = unserialize( $val ); 
     96 
     97                } 
     98                else 
     99                { 
     100                    $result = $this->get_range_msgs2( array( 'folder' => $folder_name, //INBOX 
    73101                                         'msg_range_begin' => $start + 1, //?? 
    74102                                         'msg_range_end' => $start + $limit, //$limit = $_GET['rows']; // get how many rows we want to have into the grid 
    75103                                         'sort_box_type' => 'SORTARRIVAL',  
    76104                                         'search_box_type' => 'ALL', 
    77                                          'sort_box_reverse' => 1 ); 
    78  
    79                 $result = $this->to_utf8($this->get_range_msgs2($service_params)); 
     105                                                             'sort_box_reverse' => 1 ) ); 
     106                } 
    80107                //return var_export($result); 
    81108 
    82                 $response = array( "page" => $page, "total" => $total_pages, "records" => $result['num_msgs'] ); 
     109                $response = array( "page" => $page, "total" => $total_pages, "records" => $count ); 
    83110                 
    84111                for ($i=0; $i<count($result); $i++) 
     
    96123                    { 
    97124                                $response["rows"][$i] = $result[$i]; 
    98                                 $response["rows"][$i]['body'] = $this->to_utf8($result[$i]['body']); 
    99                                 $response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate']) * 1000 ); 
    100                                 //USA OS TIME ZONES 
    101                                 //$response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()) * 1000 ); 
     125                        $response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate'] + $this->functions->CalculateDateOffset() ) * 1000 ); 
    102126                                $response["rows"][$i]['flags'] = implode(',', $flags_enum); 
    103127                                $response["rows"][$i]['size'] = $response["rows"][$i]['Size']; 
    104                                 $response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()  * 1000 ); 
     128//                      $response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()  * 1000 ); 
    105129                                unset($response["rows"][$i]['Size']); 
    106130                    } 
    107131                 } 
     132 
     133                $response = $this->to_utf8($response); 
    108134 
    109135                break; 
     
    113139    } 
    114140 
    115     public function retrieve( $concept, $id, $parents, $justthese = false, $criteria = false ) 
    116     { 
    117         return $this->read( array( 'id' => $id,  
    118                             'concept' => $concept,  
    119                             'context' => $parents ), $justthese ); 
    120     } 
     141//     public function retrieve( $concept, $id, $parents, $justthese = false, $criteria = false ) 
     142//     { 
     143//      return $this->read( array( 'id' => $id,  
     144//                          'concept' => $concept,  
     145//                          'context' => $parents ), $justthese ); 
     146//     } 
    121147 
    122148    public function read( $URI, $justthese = false ) 
    123149    { 
    124         $folder_name = str_replace( '.', $this->imap_delimiter, $URI['context']['folder'] ); 
    125  
    126         $response = $this->get_info_msg( array('msg_number'=>$URI['id'],'msg_folder'=>$folder_name) ); 
    127  
    128         return $this->to_utf8( $response ); 
     150 
     151        return $this->to_utf8( $this->get_info_msg( array('msg_number'=>$URI['id'], 
     152                                                                                                          'msg_folder'=>str_replace( '.', $this->imap_delimiter, $justthese['context']['folder'] )) ) ); 
    129153    } 
    130154 
     
    149173    public function setup() 
    150174    {} 
     175 
     176    public function commit( $uri ) 
     177    { return( true ); } 
     178 
     179    public function rollback( $uri ) 
     180    {} 
     181 
     182    public function begin( $uri ) 
     183    {} 
     184 
    151185 
    152186    public function teardown() 
     
    160194                }  
    161195        } elseif(is_string($in)) {  
    162                 //if(mb_detect_encoding($in) != "UTF-8")  
    163196                        return mb_convert_encoding( $in , 'UTF-8' , 'UTF-8 , ISO-8859-1' );  
    164                 //else  
    165                 //      return $in;  
    166197        } else {  
    167198                return $in;  
Note: See TracChangeset for help on using the changeset viewer.