init(); } public function connect( $config ) { $this->init(); } public function find( $URI, $context, $justthese = false, $criteria = false ) { if( is_array($URI) ) { $criteria = $justthese; $justthese = $context; $context = $URI['context']; $URI = $URI['concept']; } switch( $URI ) { case 'folder': { $result = $this->get_folders_list(); foreach ($result as $res) { $response[] = array( 'id' => $res['folder_id'], 'commonName' => $res['folder_name'], 'parentFolder' => $res['folder_parent'], 'messageCount' => array('unseen' => isset($res['folder_unseen']) ? $res['folder_unseen'] : null, 'total' => null) ); } break; } case 'message': { //begin: for grid $page = $criteria['page']; //{1} get the requested page $limit = $criteria['rows']; //{10} get how many rows we want to have into the grid $sidx = $criteria['sidx']; //{id} get index row - i.e. user click to sort $sord = $criteria['sord']; //{desc} get the direction if( !$sidx ) $sidx = 1; $folder_name = str_replace( '.', $this->imap_delimiter, $context['folder'] ); $folder = $this->get_range_msgs2(array('folder'=>$folder_name)); $count = $folder['num_msgs']; $total_pages = $count > 0 ? ceil( $count/$limit ) : 0; if( $page > $total_pages ) $page = $total_pages; $start = $limit * $page - $limit; // do not put $limit*($page - 1) //end: for grid $service_params = array( 'folder' => $folder_name, //INBOX 'msg_range_begin' => $start + 1, //?? 'msg_range_end' => $start + $limit, //$limit = $_GET['rows']; // get how many rows we want to have into the grid 'sort_box_type' => 'SORTARRIVAL', 'search_box_type' => 'ALL', 'sort_box_reverse' => 1 ); $result = $this->to_utf8($this->get_range_msgs2($service_params)); //return var_export($result); $response = array( "page" => $page, "total" => $total_pages, "records" => $result['num_msgs'] ); for ($i=0; $i $flag) { if ( !isset($result[$i][$flag]) || !trim($result[$i][$flag]) || trim($result[$i][$flag]) == '') unset($flags_enum[$key]); unset($result[$i][$flag]); } if (array_key_exists($i, $result)) { $response["rows"][$i] = $result[$i]; $response["rows"][$i]['body'] = $this->to_utf8($result[$i]['body']); $response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate']) * 1000 ); //USA OS TIME ZONES //$response["rows"][$i]['timestamp'] = ( ( $result[$i]['udate'] + $this->functions->CalculateDateOffset()) * 1000 ); $response["rows"][$i]['flags'] = implode(',', $flags_enum); $response["rows"][$i]['size'] = $response["rows"][$i]['Size']; $response["rows"][$i]['udate'] = ( $result[$i]['udate'] + $this->functions->CalculateDateOffset() * 1000 ); unset($response["rows"][$i]['Size']); } } break; } } return $response; } public function retrieve( $concept, $id, $parents, $justthese = false, $criteria = false ) { return $this->read( array( 'id' => $id, 'concept' => $concept, 'context' => $parents ), $justthese ); } public function read( $URI, $justthese = false ) { $folder_name = str_replace( '.', $this->imap_delimiter, $URI['context']['folder'] ); $response = $this->get_info_msg( array('msg_number'=>$URI['id'],'msg_folder'=>$folder_name) ); return $this->to_utf8( $response ); } public function create( $URI, $data ) {} public function delete( $URI, $justthese = false, $criteria = false ) {} public function deleteAll( $URI, $justthese = false, $criteria = false ) // avaliar {} public function update( $URI, $data, $criteria = false ) {} public function replace( $URI, $data, $criteria = false ) {} public function close() {} public function setup() {} public function teardown() {} function to_utf8($in) { if (is_array($in)) { foreach ($in as $key => $value) { $out[$this->to_utf8($key)] = $this->to_utf8($value); } } elseif(is_string($in)) { //if(mb_detect_encoding($in) != "UTF-8") return utf8_encode($in); //else // return $in; } else { return $in; } return $out; } }