2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
40 require_once 'modules/Calendar/Calendar.php';
41 require_once 'modules/iCals/iCal.php';
42 require_once 'modules/vCals/HTTP_WebDAV_Server_vCal.php';
45 * Calendar access using WebDAV
49 class HTTP_WebDAV_Server_iCal extends HTTP_WebDAV_Server_vCal
52 var $cal_encoding = "";
53 var $cal_charset = "";
57 * Constructor for the WebDAV srver
59 public function __construct()
61 $this->vcal_focus = new iCal();
62 $this->user_focus = new User();
66 * Serve a webdav request
71 public function ServeICalRequest($base = false)
73 if (empty($_REQUEST['type'])) {
74 $_REQUEST['type'] = 'ics';
77 if (empty($_REQUEST['encoding'])) {
78 $this->cal_encoding = 'utf-8';
80 $this->cal_encoding = $_REQUEST['encoding'];
83 if (empty($_REQUEST['cal_charset'])) {
84 $this->cal_charset = 'utf-8';
86 $this->cal_charset = $_REQUEST['cal_charset'];
89 if (empty($_REQUEST['http_spec'])) {
90 $this->http_spec = '1.1';
92 $this->http_spec = $_REQUEST['http_spec'];
95 // check the HTTP auth headers for a user
96 if (empty($_REQUEST['user_name']) && !empty($_SERVER['PHP_AUTH_USER'])) {
97 $_REQUEST['user_name'] = $_SERVER['PHP_AUTH_USER'];
98 $_REQUEST['key'] = $_SERVER['PHP_AUTH_PW'];
101 // if username is still empty, then return 401
102 if (empty($_REQUEST['user_name']) && empty($_REQUEST['email'])) {
103 if ($_REQUEST['type'] == 'ics') {
104 $this->http_status("401 not authorized");
105 header('WWW-Authenticate: Basic realm="SugarCRM iCal"');
107 echo 'Authorization required';
109 $this->http_status("404 Not Found");
114 parent::ServeRequest();
124 public function http_GET()
126 if ($this->vcal_type == 'vfb') {
127 $this->http_status("200 OK");
129 echo $this->vcal_focus->get_vcal_freebusy($this->user_focus);
130 } else if ($this->vcal_type == 'ics') {
131 // DO HTTP AUTHORIZATION for iCal:
132 if ( $this->user_focus->getPreference('calendar_publish_key') &&
133 $this->publish_key != $this->user_focus->getPreference('calendar_publish_key' )) {
134 $this->http_status("401 not authorized");
135 header('WWW-Authenticate: Basic realm="SugarCRM iCal"');
136 echo 'Authorization required';
140 $this->http_status("200 OK");
141 header('Content-Type: text/calendar; charset="' . $this->cal_charset . '"');
142 $result = mb_convert_encoding(html_entity_decode($this->vcal_focus->getVcalIcal($this->user_focus, $_REQUEST['num_months']), ENT_QUOTES, $this->cal_charset), $this->cal_encoding);
146 $this->http_status("404 Not Found");
153 * set HTTP return status and mirror it in a private header
155 * @param string status code and message
158 public function http_status($status)
160 // simplified success case
161 if($status === true) {
166 $this->_http_status = $status;
168 // generate HTTP status response
169 header("HTTP/$this->http_spec $status");
170 header("X-WebDAV-Status: $status", true);