ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
mcal.php
Go to the documentation of this file.
1 <?php
20 class Log_mcal extends Log
21 {
27  var $_calendar = '{localhost/mstore}';
28 
34  var $_username = '';
35 
41  var $_password = '';
42 
48  var $_options = 0;
49 
55  var $_stream = '';
56 
62  var $_name = LOG_SYSLOG;
63 
64 
74  function Log_mcal($name, $ident = '', $conf = array(),
75  $level = PEAR_LOG_DEBUG)
76  {
77  $this->_id = md5(microtime());
78  $this->_name = $name;
79  $this->_ident = $ident;
80  $this->_mask = Log::UPTO($level);
81  $this->_calendar = $conf['calendar'];
82  $this->_username = $conf['username'];
83  $this->_password = $conf['password'];
84  $this->_options = $conf['options'];
85  }
86 
92  function open()
93  {
94  if (!$this->_opened) {
95  $this->_stream = mcal_open($this->_calendar, $this->_username,
96  $this->_password, $this->_options);
97  $this->_opened = true;
98  }
99 
100  return $this->_opened;
101  }
102 
107  function close()
108  {
109  if ($this->_opened) {
110  mcal_close($this->_stream);
111  $this->_opened = false;
112  }
113 
114  return ($this->_opened === false);
115  }
116 
131  function log($message, $priority = null)
132  {
133  /* If a priority hasn't been specified, use the default value. */
134  if ($priority === null) {
135  $priority = $this->_priority;
136  }
137 
138  /* Abort early if the priority is above the maximum logging level. */
139  if (!$this->_isMasked($priority)) {
140  return false;
141  }
142 
143  /* If the connection isn't open and can't be opened, return failure. */
144  if (!$this->_opened && !$this->open()) {
145  return false;
146  }
147 
148  /* Extract the string representation of the message. */
149  $message = $this->_extractMessage($message);
150 
151  $date_str = date('Y:n:j:G:i:s');
152  $dates = explode(':', $date_str);
153 
154  mcal_event_init($this->_stream);
155  mcal_event_set_title($this->_stream, $this->_ident);
156  mcal_event_set_category($this->_stream, $this->_name);
157  mcal_event_set_description($this->_stream, $message);
158  mcal_event_add_attribute($this->_stream, 'priority', $priority);
159  mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2],
160  $dates[3], $dates[4], $dates[5]);
161  mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2],
162  $dates[3], $dates[4], $dates[5]);
163  mcal_append_event($this->_stream);
164 
165  $this->_announce(array('priority' => $priority, 'message' => $message));
166 
167  return true;
168  }
169 
170 }
$_password
Definition: mcal.php:41
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
$_name
Definition: mcal.php:62
$Header$
$_stream
Definition: mcal.php:55
$_username
Definition: mcal.php:34
log($message, $priority=null)
Logs $message and associated information to the currently open calendar stream.
Definition: mcal.php:131
open()
Opens a calendar stream, if it has not already been opened.
Definition: mcal.php:92
close()
Closes the calendar stream, if it is open.
Definition: mcal.php:107
$_priority
Definition: Log.php:69
$_calendar
Definition: mcal.php:27
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
$_opened
Definition: Log.php:45
const PEAR_LOG_DEBUG
Definition: Log.php:17
$_options
Definition: mcal.php:48
Log_mcal($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new Log_mcal object.
Definition: mcal.php:74