source: trunk/jabberit_messenger/inc/class.bologmessage.inc.php @ 1616

Revision 1616, 3.0 KB checked in by alexandrecorreia, 14 years ago (diff)

Ticket #740 - Logs utilizando o bandersnatch ( script perl - banco mysql )

  • Property svn:mime-type set to text/plain
Line 
1<?php
2
3  /***************************************************************************\
4  *  Expresso - Expresso Messenger                                            *
5  *     - Alexandre Correia / Rodrigo Souza                                                               *
6  * ------------------------------------------------------------------------- *
7  *  This program is free software; you can redistribute it and/or modify it  *
8  *  under the terms of the GNU General Public License as published by the    *
9  *  Free Software Foundation; either version 2 of the License, or (at your   *
10  *  option) any later version.                                               *
11  \***************************************************************************/
12
13define('PHPGW_INCLUDE_ROOT','../');     
14define('PHPGW_API_INC','../phpgwapi/inc');
15require_once(PHPGW_API_INC . '/class.db.inc.php');
16
17class bologmessage
18{
19        private $db;
20        private $db_name;
21        private $db_host;
22        private $db_port;
23        private $db_user;
24        private $db_pass;
25        private $db_type;
26       
27        function __construct()
28        {
29                $this->db = new db();
30                $this->db_name = "bandersnatch";
31                $this->db_host = "localhost";
32                $this->db_port = "3306";
33                $this->db_user = "";
34                $this->db_pass = "";
35                $this->db_type = "mysql";
36                $this->connectDB();
37        }
38
39        function __destruct()
40        {
41                $this->db->disconnect();               
42        }
43
44        private function connectDB()
45        {
46                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);
47        }       
48
49        public function getMessageUser( $pUser, $pLim1, $pLim2 )
50        {
51                $query = "SELECT message_from, COUNT(*) AS total_messages, MIN(message_timestamp) AS first_message, MAX(message_timestamp) AS last_message FROM message WHERE message_from like '%".$pUser."%' GROUP BY message_from LIMIT ".$pLim1.",".$pLim2.";";
52
53                $data = array();
54
55                if($this->db->query($query))
56                {
57                        while($this->db->next_record())
58                                $data[] = $this->db->row();
59                }
60               
61                return $data;
62        }
63       
64        public function getMessageUserDate( $pUser, $pDtFirst, $pDtLast, $pLim1, $pLim2 )
65        {
66                $data           = array();
67                $field_1        = "message_from";
68                $field_2        = "message_to";
69
70                $query = "SELECT ".$field_1.", ".$field_2.", COUNT(*) AS total_messages, MIN(message_timestamp) AS first_message, MAX(message_timestamp) AS last_message FROM message WHERE ".$field_1." = '".$pUser."' AND message_timestamp BETWEEN '".$pDtFirst."' AND '".$pDtLast."' GROUP BY ".$field_2." LIMIT ".$pLim1.",".$pLim2.";";
71       
72                if($this->db->query($query))
73                {
74                        while($this->db->next_record())
75                                $data[] = $this->db->row();
76                }
77               
78                return $data;
79        }
80       
81        public function getMessageUserComplete( $pUser1, $pUser2, $pDtFirst, $pDtLast, $pLim1, $pLim2 )
82        {
83                $query = "SELECT message_from, message_to, message_body, message_timestamp FROM message WHERE message_from = '".$pUser1."' AND message_to = '".$pUser2."' AND message_timestamp BETWEEN '".$pDtFirst."' AND '".$pDtLast."' ORDER BY message_timestamp DESC LIMIT ".$pLim1.",".$pLim2.";";
84               
85                if($this->db->query($query))
86                {
87                        while($this->db->next_record())
88                                $data[] = $this->db->row();
89                }
90               
91                return $data;
92        }
93}
94
95?>
Note: See TracBrowser for help on using the repository browser.