1 |
joko |
1.2 |
<?php |
2 |
|
|
// $Id: mcal.php,v 1.8 2002/12/02 05:23:00 jon Exp $ |
3 |
|
|
// $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $ |
4 |
|
|
|
5 |
|
|
/** |
6 |
|
|
* The Log_mcal class is a concrete implementation of the Log:: |
7 |
|
|
* abstract class which sends messages to a local or remote calendar |
8 |
|
|
* store accessed through MCAL. |
9 |
|
|
* |
10 |
|
|
* @author Chuck Hagenbuch <chuck@horde.org> |
11 |
|
|
* @version $Revision: 1.8 $ |
12 |
|
|
* @since Horde 1.3 |
13 |
|
|
* @package Log |
14 |
|
|
*/ |
15 |
|
|
class Log_mcal extends Log { |
16 |
|
|
|
17 |
|
|
/** |
18 |
|
|
* holding the calendar specification to connect to. |
19 |
|
|
* @var string |
20 |
|
|
*/ |
21 |
|
|
var $_calendar = '{localhost/mstore}'; |
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* holding the username to use. |
25 |
|
|
* @var string |
26 |
|
|
*/ |
27 |
|
|
var $_username = ''; |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* holding the password to use. |
31 |
|
|
* @var string |
32 |
|
|
*/ |
33 |
|
|
var $_password = ''; |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* holding the options to pass to the calendar stream. |
37 |
|
|
* @var integer |
38 |
|
|
*/ |
39 |
|
|
var $_options = 0; |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* ResourceID of the MCAL stream. |
43 |
|
|
* @var string |
44 |
|
|
*/ |
45 |
|
|
var $_stream = ''; |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* Integer holding the log facility to use. |
49 |
|
|
* @var string |
50 |
|
|
*/ |
51 |
|
|
var $_name = LOG_SYSLOG; |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/** |
55 |
|
|
* Constructs a new Log_mcal object. |
56 |
|
|
* |
57 |
|
|
* @param string $name The category to use for our events. |
58 |
|
|
* @param string $ident The identity string. |
59 |
|
|
* @param array $conf The configuration array. |
60 |
|
|
* @param int $maxLevel Maximum level at which to log. |
61 |
|
|
* @access public |
62 |
|
|
*/ |
63 |
|
|
function Log_mcal($name, $ident = '', $conf = array(), |
64 |
|
|
$maxLevel = PEAR_LOG_DEBUG) |
65 |
|
|
{ |
66 |
|
|
$this->_name = $name; |
67 |
|
|
$this->_ident = $ident; |
68 |
|
|
$this->_maxLevel = $maxLevel; |
69 |
|
|
$this->_calendar = $conf['calendar']; |
70 |
|
|
$this->_username = $conf['username']; |
71 |
|
|
$this->_password = $conf['password']; |
72 |
|
|
$this->_options = $conf['options']; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
/** |
76 |
|
|
* Opens a calendar stream, if it has not already been |
77 |
|
|
* opened. This is implicitly called by log(), if necessary. |
78 |
|
|
* @access public |
79 |
|
|
*/ |
80 |
|
|
function open() |
81 |
|
|
{ |
82 |
|
|
if (!$this->_opened) { |
83 |
|
|
$this->_stream = mcal_open($this->_calendar, $this->_username, |
84 |
|
|
$this->_password, $this->_options); |
85 |
|
|
$this->_opened = true; |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
/** |
90 |
|
|
* Closes the calendar stream, if it is open. |
91 |
|
|
* @access public |
92 |
|
|
*/ |
93 |
|
|
function close() |
94 |
|
|
{ |
95 |
|
|
if ($this->_opened) { |
96 |
|
|
mcal_close($this->_stream); |
97 |
|
|
$this->_opened = false; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
/** |
102 |
|
|
* Logs $message and associated information to the currently open |
103 |
|
|
* calendar stream. Calls open() if necessary. Also passes the |
104 |
|
|
* message along to any Log_observer instances that are observing |
105 |
|
|
* this Log. |
106 |
|
|
* |
107 |
|
|
* @param string $message The textual message to be logged. |
108 |
|
|
* @param string $priority The priority of the message. Valid |
109 |
|
|
* values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, |
110 |
|
|
* PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, |
111 |
|
|
* PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. |
112 |
|
|
* The default is PEAR_LOG_INFO. |
113 |
|
|
* @return boolean True on success or false on failure. |
114 |
|
|
* @access public |
115 |
|
|
*/ |
116 |
|
|
function log($message, $priority = PEAR_LOG_INFO) |
117 |
|
|
{ |
118 |
|
|
/* Abort early if the priority is above the maximum logging level. */ |
119 |
|
|
if ($priority > $this->_maxLevel) { |
120 |
|
|
return false; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
if (!$this->_opened) { |
124 |
|
|
$this->open(); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
$date_str = date('Y:n:j:G:i:s'); |
128 |
|
|
$dates = explode(':', $date_str); |
129 |
|
|
|
130 |
|
|
mcal_event_init($this->_stream); |
131 |
|
|
mcal_event_set_title($this->_stream, $this->_ident); |
132 |
|
|
mcal_event_set_category($this->_stream, $this->_name); |
133 |
|
|
mcal_event_set_description($this->_stream, $message); |
134 |
|
|
mcal_event_add_attribute($this->_stream, 'priority', $priority); |
135 |
|
|
mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2], |
136 |
|
|
$dates[3], $dates[4], $dates[5]); |
137 |
|
|
mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2], |
138 |
|
|
$dates[3], $dates[4], $dates[5]); |
139 |
|
|
mcal_append_event($this->_stream); |
140 |
|
|
|
141 |
|
|
$this->notifyAll(array('priority' => $priority, 'message' => $message)); |
142 |
|
|
|
143 |
|
|
return true; |
144 |
|
|
} |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
?> |