ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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 }