init
This commit is contained in:
429
modules/vCals/HTTP_WebDAV_Server_vCal.php
Executable file
429
modules/vCals/HTTP_WebDAV_Server_vCal.php
Executable file
@@ -0,0 +1,429 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once 'modules/Calendar/Calendar.php';
|
||||
|
||||
require_once 'include/HTTP_WebDAV_Server/Server.php';
|
||||
|
||||
|
||||
/**
|
||||
* Filesystem access using WebDAV
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
class HTTP_WebDAV_Server_vCal extends HTTP_WebDAV_Server
|
||||
{
|
||||
/**
|
||||
* Root directory for WebDAV access
|
||||
*
|
||||
* Defaults to webserver document root (set by ServeRequest)
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $base = "";
|
||||
var $vcal_focus;
|
||||
var $vcal_type = "";
|
||||
var $source = "";
|
||||
var $publish_key = "";
|
||||
|
||||
function HTTP_WebDAV_Server_vCal()
|
||||
{
|
||||
$this->vcal_focus = new vCal();
|
||||
$this->user_focus = new User();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serve a webdav request
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
*/
|
||||
function ServeRequest($base = false)
|
||||
{
|
||||
|
||||
global $sugar_config,$current_language;
|
||||
|
||||
if (!empty($sugar_config['session_dir']))
|
||||
{
|
||||
session_save_path($sugar_config['session_dir']);
|
||||
}
|
||||
|
||||
session_start();
|
||||
|
||||
// clean_incoming_data();
|
||||
|
||||
|
||||
$current_language = $sugar_config['default_language'];
|
||||
|
||||
// special treatment for litmus compliance test
|
||||
// reply on its identifier header
|
||||
// not needed for the test itself but eases debugging
|
||||
/*
|
||||
foreach(apache_request_headers() as $key => $value) {
|
||||
if(stristr($key,"litmus")) {
|
||||
error_log("Litmus test $value");
|
||||
header("X-Litmus-reply: ".$value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// set root directory, defaults to webserver document root if not set
|
||||
if ($base) {
|
||||
$this->base = realpath($base); // TODO throw if not a directory
|
||||
} else if(!$this->base) {
|
||||
$this->base = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
|
||||
$query_arr = array();
|
||||
// set path
|
||||
if ( empty($_SERVER["PATH_INFO"]))
|
||||
{
|
||||
$this->path = "/";
|
||||
if(strtolower($_SERVER["REQUEST_METHOD"]) == 'get'){
|
||||
$query_arr = $_REQUEST;
|
||||
}else{
|
||||
parse_str($_REQUEST['parms'],$query_arr);
|
||||
}
|
||||
} else{
|
||||
$this->path = $this->_urldecode( $_SERVER["PATH_INFO"]);
|
||||
|
||||
if(ini_get("magic_quotes_gpc")) {
|
||||
$this->path = stripslashes($this->path);
|
||||
}
|
||||
|
||||
$query_str = preg_replace('/^\//','',$this->path);
|
||||
$query_arr = array();
|
||||
parse_str($query_str,$query_arr);
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty($query_arr['type']))
|
||||
{
|
||||
$this->vcal_type = $query_arr['type'];
|
||||
}
|
||||
else {
|
||||
$this->vcal_type = 'vfb';
|
||||
}
|
||||
|
||||
if ( ! empty($query_arr['source']))
|
||||
{
|
||||
$this->source = $query_arr['source'];
|
||||
}
|
||||
else {
|
||||
$this->source = 'outlook';
|
||||
}
|
||||
|
||||
if ( ! empty($query_arr['key']))
|
||||
{
|
||||
$this->publish_key = $query_arr['key'];
|
||||
}
|
||||
|
||||
// select user by email
|
||||
if ( ! empty($query_arr['email']))
|
||||
{
|
||||
|
||||
|
||||
// clean the string!
|
||||
$query_arr['email'] = clean_string($query_arr['email']);
|
||||
//get user info
|
||||
$this->user_focus->retrieve_by_email_address( $query_arr['email']);
|
||||
|
||||
}
|
||||
// else select user by user_name
|
||||
else if ( ! empty($query_arr['user_name']))
|
||||
{
|
||||
// clean the string!
|
||||
$query_arr['user_name'] = clean_string($query_arr['user_name']);
|
||||
|
||||
//get user info
|
||||
$arr = array('user_name'=>$query_arr['user_name']);
|
||||
$this->user_focus->retrieve_by_string_fields($arr);
|
||||
}
|
||||
// else select user by user id
|
||||
else if ( ! empty($query_arr['user_id']))
|
||||
{
|
||||
$this->user_focus->retrieve($query_arr['user_id']);
|
||||
}
|
||||
|
||||
// if we haven't found a user, then return 404
|
||||
if ( empty($this->user_focus->id) || $this->user_focus->id == -1)
|
||||
{
|
||||
$this->http_status("404 Not Found");
|
||||
return;
|
||||
}
|
||||
|
||||
// if(empty($this->user_focus->user_preferences))
|
||||
// {
|
||||
$this->user_focus->loadPreferences();
|
||||
// }
|
||||
|
||||
// let the base class do all the work
|
||||
parent::ServeRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* No authentication is needed here
|
||||
*
|
||||
* @access private
|
||||
* @param string HTTP Authentication type (Basic, Digest, ...)
|
||||
* @param string Username
|
||||
* @param string Password
|
||||
* @return bool true on successful authentication
|
||||
*/
|
||||
function check_auth($type, $user, $pass)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function GET()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// {{{ http_GET()
|
||||
|
||||
/**
|
||||
* GET method handler
|
||||
*
|
||||
* @param void
|
||||
* @returns void
|
||||
*/
|
||||
function http_GET()
|
||||
{
|
||||
|
||||
if ($this->vcal_type == 'vfb')
|
||||
{
|
||||
$this->http_status("200 OK");
|
||||
echo $this->vcal_focus->get_vcal_freebusy($this->user_focus);
|
||||
} else {
|
||||
$this->http_status("404 Not Found");
|
||||
}
|
||||
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ http_PUT()
|
||||
|
||||
/**
|
||||
* PUT method handler
|
||||
*
|
||||
* @param void
|
||||
* @return void
|
||||
*/
|
||||
function http_PUT()
|
||||
{
|
||||
$options = Array();
|
||||
$options["path"] = $this->path;
|
||||
$options["content_length"] = $_SERVER["CONTENT_LENGTH"];
|
||||
|
||||
// get the Content-type
|
||||
if (isset($_SERVER["CONTENT_TYPE"])) {
|
||||
// for now we do not support any sort of multipart requests
|
||||
if (!strncmp($_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
|
||||
$this->http_status("501 not implemented");
|
||||
echo "The service does not support mulipart PUT requests";
|
||||
return;
|
||||
}
|
||||
$options["content_type"] = $_SERVER["CONTENT_TYPE"];
|
||||
} else {
|
||||
// default content type if none given
|
||||
$options["content_type"] = "application/octet-stream";
|
||||
}
|
||||
|
||||
/* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
|
||||
ignore any Content-* (e.g. Content-Range) headers that it
|
||||
does not understand or implement and MUST return a 501
|
||||
(Not Implemented) response in such cases."
|
||||
*/
|
||||
foreach ($_SERVER as $key => $val) {
|
||||
if (strncmp($key, "HTTP_CONTENT", 11)) continue;
|
||||
switch ($key) {
|
||||
case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
|
||||
// TODO support this if ext/zlib filters are available
|
||||
$this->http_status("501 not implemented");
|
||||
echo "The service does not support '$val' content encoding";
|
||||
return;
|
||||
|
||||
case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12
|
||||
// we assume it is not critical if this one is ignored
|
||||
// in the actual PUT implementation ...
|
||||
$options["content_language"] = $val;
|
||||
break;
|
||||
|
||||
case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
|
||||
/* The meaning of the Content-Location header in PUT
|
||||
or POST requests is undefined; servers are free
|
||||
to ignore it in those cases. */
|
||||
break;
|
||||
|
||||
case 'HTTP_CONTENT_RANGE': // RFC 2616 14.16
|
||||
// single byte range requests are NOT supported
|
||||
// the header format is also specified in RFC 2616 14.16
|
||||
// TODO we have to ensure that implementations support this or send 501 instead
|
||||
$this->http_status("400 bad request");
|
||||
echo "The service does only support single byte ranges";
|
||||
return;
|
||||
|
||||
case 'HTTP_CONTENT_MD5': // RFC 2616 14.15
|
||||
// TODO: maybe we can just pretend here?
|
||||
$this->http_status("501 not implemented");
|
||||
echo "The service does not support content MD5 checksum verification";
|
||||
return;
|
||||
|
||||
case 'HTTP_CONTENT_LENGTH': // RFC 2616 14.14
|
||||
/* The meaning of the Content-Location header in PUT
|
||||
or POST requests is undefined; servers are free
|
||||
to ignore it in those cases. */
|
||||
break;
|
||||
|
||||
default:
|
||||
// any other unknown Content-* headers
|
||||
$this->http_status("501 not implemented");
|
||||
echo "The service does not support '$key'";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// DO AUTHORIZATION for publishing Free/busy to Sugar:
|
||||
if ( $this->user_focus->getPreference('calendar_publish_key') &&
|
||||
$this->publish_key != $this->user_focus->getPreference('calendar_publish_key' ))
|
||||
{
|
||||
$this->http_status("401 not authorized");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// retrieve
|
||||
$arr = array('user_id'=>$this->user_focus->id,'type'=>'vfb','source'=>$this->source);
|
||||
$this->vcal_focus->retrieve_by_string_fields($arr);
|
||||
|
||||
$isUpdate = false;
|
||||
|
||||
if ( ! empty($this->vcal_focus->user_id ) &&
|
||||
$this->vcal_focus->user_id != -1 )
|
||||
{
|
||||
$isUpdate = true;
|
||||
}
|
||||
|
||||
// open input stream
|
||||
$options["stream"] = fopen("php://input", "r");
|
||||
$content = '';
|
||||
|
||||
// read in input stream
|
||||
while (!feof($options["stream"]))
|
||||
{
|
||||
$content .= fread($options["stream"], 4096);
|
||||
}
|
||||
|
||||
// set freebusy members and save
|
||||
$this->vcal_focus->content = $content;
|
||||
$this->vcal_focus->type = 'vfb';
|
||||
$this->vcal_focus->source = $this->source;
|
||||
$focus->date_modified = null;
|
||||
$this->vcal_focus->user_id = $this->user_focus->id;
|
||||
$this->vcal_focus->save();
|
||||
|
||||
if ( $isUpdate )
|
||||
{
|
||||
$this->http_status("204 No Content");
|
||||
} else {
|
||||
$this->http_status("201 Created");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT method handler
|
||||
*
|
||||
* @param array parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function PUT(&$options)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* LOCK method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function lock(&$options)
|
||||
{
|
||||
|
||||
$options["timeout"] = time()+300; // 5min. hardcoded
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* UNLOCK method handler
|
||||
*
|
||||
* @param array general parameter passing array
|
||||
* @return bool true on success
|
||||
*/
|
||||
function unlock(&$options)
|
||||
{
|
||||
|
||||
return "200 OK";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* checkLock() helper
|
||||
*
|
||||
* @param string resource path to check for locks
|
||||
* @return bool true on success
|
||||
*/
|
||||
function checkLock($path)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
83
modules/vCals/Server.php
Executable file
83
modules/vCals/Server.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
// SugarCRM free/busy server
|
||||
// put and get free/busy information for sugarcrm users in vCalendar format.
|
||||
// Uses WebDAV for HTTP PUT and GET methods of access
|
||||
// REQUIRED PHP packages:
|
||||
// 1. PEAR
|
||||
//
|
||||
// Saves PUTs as Freebusy SugarBeans
|
||||
//
|
||||
// documentation on Free/Busy from Microsoft:
|
||||
// http://support.microsoft.com/kb/196484
|
||||
//
|
||||
// other docs:
|
||||
// http://www.windowsitpro.com/MicrosoftExchangeOutlook/Article/ArticleID/7697/7697.html
|
||||
//
|
||||
// excerpt:
|
||||
// You must install the Microsoft Internet Explorer (IE) Web Publishing Wizard to get
|
||||
// the functionality you need to publish Internet free/busy data to a server or the Web.
|
||||
// You can install this wizard from Control Panel, Add/Remove Programs, Microsoft Internet
|
||||
// Explorer, Web Publishing Wizard. For every user, you must configure the path and filename
|
||||
// where you want Outlook to store free/busy information. You configure this location on the
|
||||
// Free/Busy Options dialog box you see in Screen 2. You must initiate publishing manually by
|
||||
// using Tools, Send/Receive, Free/Busy Information in Outlook.
|
||||
//
|
||||
// To access a non-Exchange Server user's free/busy information, you must configure the
|
||||
// appropriate path on each contact's Details tab. For example, you enter
|
||||
// "http://servername/sugarcrm/index.php?entryPoint=vcal_server/type=vfb&source=outlook&email=myemail@servername.com".
|
||||
// If you don't configure this information correctly, the client software looks up the entry
|
||||
// in the Search at this URL window on the Free/Busy Options dialog box.
|
||||
//
|
||||
// Setup for: Microsoft Outlook XP
|
||||
// In Tools > Options > Calendar Options > Free/Busy
|
||||
//
|
||||
// Global search path:
|
||||
// %USERNAME% and %SERVER% are Outlook replacement variables to construct the email address:
|
||||
// http://servername/sugarcrm/index.php?entryPoint=vcal_server/type=vfb&source=outlook&email=%NAME%@%SERVER%
|
||||
// or contact by contact by editing the details and entering its Free/Busy URL:
|
||||
// http://servername/sugarcrm/index.php?entryPoint=vcal_server/type=vfb&source=outlook&email=user@email.com
|
||||
// or
|
||||
// http://servername/sugarcrm/index.php?entryPoint=vcal_server/type=vfb&source=outlook&user_name=user_name
|
||||
// or:
|
||||
// http://servername/sugarcrm/index.php?entryPoint=vcal_server/type=vfb&source=outlook&user_id=user_id
|
||||
require_once "modules/vCals/HTTP_WebDAV_Server_vCal.php";
|
||||
$server = new HTTP_WebDAV_Server_vCal();
|
||||
$server->ServeRequest();
|
||||
sugar_cleanup();
|
||||
?>
|
||||
54
modules/vCals/field_arrays.php
Executable file
54
modules/vCals/field_arrays.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Contains field arrays that are used for caching
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
$fields_array['vcal'] = array ('column_fields' =>Array(
|
||||
"id"
|
||||
,"user_id"
|
||||
,"date_modified"
|
||||
,"type"
|
||||
,"content"
|
||||
,"source"
|
||||
,"deleted"
|
||||
),
|
||||
);
|
||||
?>
|
||||
259
modules/vCals/vCal.php
Executable file
259
modules/vCals/vCal.php
Executable file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description:
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
require_once('modules/Calendar/Calendar.php');
|
||||
|
||||
class vCal extends SugarBean {
|
||||
// Stored fields
|
||||
var $id;
|
||||
var $date_modified;
|
||||
var $user_id;
|
||||
var $content;
|
||||
var $deleted;
|
||||
var $type;
|
||||
var $source;
|
||||
var $module_dir = "vCals";
|
||||
var $table_name = "vcals";
|
||||
|
||||
var $object_name = "vCal";
|
||||
|
||||
var $new_schema = true;
|
||||
|
||||
var $field_defs = array(
|
||||
);
|
||||
|
||||
// This is used to retrieve related fields from form posts.
|
||||
var $additional_column_fields = Array();
|
||||
|
||||
function vCal()
|
||||
{
|
||||
|
||||
parent::SugarBean();
|
||||
$this->disable_row_level_security = true;
|
||||
}
|
||||
|
||||
function get_summary_text()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
function fill_in_additional_list_fields()
|
||||
{
|
||||
}
|
||||
|
||||
function fill_in_additional_detail_fields()
|
||||
{
|
||||
}
|
||||
|
||||
function get_list_view_data()
|
||||
{
|
||||
}
|
||||
|
||||
// combines all freebusy vcals and returns just the FREEBUSY lines as a string
|
||||
function get_freebusy_lines_cache(&$user_bean)
|
||||
{
|
||||
$str = '';
|
||||
// First, get the list of IDs.
|
||||
$query = "SELECT id from vcals where user_id='{$user_bean->id}' AND type='vfb' AND deleted=0";
|
||||
$vcal_arr = $this->build_related_list($query, new vCal());
|
||||
|
||||
foreach ($vcal_arr as $focus)
|
||||
{
|
||||
if (empty($focus->content))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$lines = explode("\n",$focus->content);
|
||||
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
if ( preg_match('/^FREEBUSY[;:]/i',$line))
|
||||
{
|
||||
$str .= "$line\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// query and create the FREEBUSY lines for SugarCRM Meetings and Calls and
|
||||
// return the string
|
||||
function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
|
||||
{
|
||||
$str = '';
|
||||
global $DO_USER_TIME_OFFSET,$timedate;
|
||||
|
||||
$DO_USER_TIME_OFFSET = true;
|
||||
// get activities.. queries Meetings and Calls
|
||||
$acts_arr =
|
||||
CalendarActivity::get_activities($user_bean->id,
|
||||
false,
|
||||
$start_date_time,
|
||||
$end_date_time,
|
||||
'week');
|
||||
|
||||
// loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
|
||||
for ($i = 0;$i < count($acts_arr);$i++)
|
||||
{
|
||||
$act =$acts_arr[$i];
|
||||
$utcFormat = 'Ymd\THi';
|
||||
|
||||
$startTimeUTC = gmdate($utcFormat, $act->start_time->ts) . "00Z";
|
||||
$endTimeUTC = gmdate($utcFormat, $act->end_time->ts) . "00Z";
|
||||
|
||||
$str .= "FREEBUSY:". $startTimeUTC ."/". $endTimeUTC."\n";
|
||||
|
||||
}
|
||||
return $str;
|
||||
|
||||
}
|
||||
|
||||
// return a freebusy vcal string
|
||||
function get_vcal_freebusy($user_focus,$cached=true)
|
||||
{
|
||||
global $locale;
|
||||
$str = "BEGIN:VCALENDAR\n";
|
||||
$str .= "VERSION:2.0\n";
|
||||
$str .= "PRODID:-//SugarCRM//SugarCRM Calendar//EN\n";
|
||||
$str .= "BEGIN:VFREEBUSY\n";
|
||||
|
||||
$name = $locale->getLocaleFormattedName($user_focus->first_name, $user_focus->last_name);
|
||||
$email = $user_focus->email1;
|
||||
|
||||
// get current date for the user
|
||||
$now_date_time = new DateTimeUtil(array(), true);
|
||||
|
||||
// get start date GMT ( 1 day ago )
|
||||
$date_arr = array(
|
||||
'day'=>$now_date_time->day - 1,
|
||||
'month'=>($now_date_time->month),
|
||||
'hour'=>($now_date_time->hour),
|
||||
'min'=>($now_date_time->min),
|
||||
'year'=>$now_date_time->year);
|
||||
|
||||
$start_date_time = new DateTimeUtil($date_arr,true);
|
||||
|
||||
|
||||
// get date 2 months from start date
|
||||
global $sugar_config;
|
||||
$timeOffset = 0;
|
||||
if (isset($sugar_config['vcal_time']) && $sugar_config['vcal_time'] != 0 && $sugar_config['vcal_time'] < 13)
|
||||
{
|
||||
$timeOffset = $sugar_config['vcal_time'];
|
||||
}
|
||||
$date_arr = array(
|
||||
'day'=>$start_date_time->day,
|
||||
'month'=>($start_date_time->month + $timeOffset),
|
||||
'hour'=>($start_date_time->hour),
|
||||
'min'=>($start_date_time->min),
|
||||
'year'=>$start_date_time->year);
|
||||
|
||||
$end_date_time = new DateTimeUtil($date_arr,true);
|
||||
|
||||
// get UTC time format
|
||||
$utc_start_time = $start_date_time->get_utc_date_time();
|
||||
$utc_end_time = $end_date_time->get_utc_date_time();
|
||||
$utc_now_time = $now_date_time->get_utc_date_time();
|
||||
|
||||
$str .= "ORGANIZER;CN=$name:$email\n";
|
||||
$str .= "DTSTART:$utc_start_time\n";
|
||||
$str .= "DTEND:$utc_end_time\n";
|
||||
|
||||
// now insert the freebusy lines
|
||||
// retrieve cached freebusy lines from vcals
|
||||
if ($timeOffset != 0)
|
||||
{
|
||||
if ($cached == true)
|
||||
{
|
||||
$str .= $this->get_freebusy_lines_cache($user_focus);
|
||||
}
|
||||
// generate freebusy from Meetings and Calls
|
||||
else
|
||||
{
|
||||
$str .= $this->create_sugar_freebusy($user_focus,$start_date_time,$end_date_time);
|
||||
}
|
||||
}
|
||||
|
||||
// UID:20030724T213406Z-10358-1000-1-12@phoenix
|
||||
$str .= "DTSTAMP:$utc_now_time\n";
|
||||
$str .= "END:VFREEBUSY\n";
|
||||
$str .= "END:VCALENDAR\n";
|
||||
return $str;
|
||||
|
||||
}
|
||||
|
||||
// static function:
|
||||
// cache vcals
|
||||
function cache_sugar_vcal(&$user_focus)
|
||||
{
|
||||
vCal::cache_sugar_vcal_freebusy($user_focus);
|
||||
}
|
||||
|
||||
// static function:
|
||||
// caches vcal for Activities in Sugar database
|
||||
function cache_sugar_vcal_freebusy(&$user_focus)
|
||||
{
|
||||
$focus = new vCal();
|
||||
// set freebusy members and save
|
||||
$arr = array('user_id'=>$user_focus->id,'type'=>'vfb','source'=>'sugar');
|
||||
$focus->retrieve_by_string_fields($arr);
|
||||
|
||||
|
||||
$focus->content = $focus->get_vcal_freebusy($user_focus,false);
|
||||
$focus->type = 'vfb';
|
||||
$focus->date_modified = null;
|
||||
$focus->source = 'sugar';
|
||||
$focus->user_id = $user_focus->id;
|
||||
$focus->save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
102
modules/vCals/vardefs.php
Executable file
102
modules/vCals/vardefs.php
Executable file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
// Create the indexes
|
||||
$dictionary['vCal'] = array('table' => 'vcals'
|
||||
,'fields' => array (
|
||||
'id' =>
|
||||
array (
|
||||
'name' => 'id',
|
||||
'vname' => 'LBL_NAME',
|
||||
'type' => 'id',
|
||||
'required'=>true,
|
||||
'reportable'=>false,
|
||||
),
|
||||
'deleted' =>
|
||||
array (
|
||||
'name' => 'deleted',
|
||||
'vname' => 'LBL_DELETED',
|
||||
'type' => 'bool',
|
||||
'required' => false,
|
||||
'reportable'=>false,
|
||||
),
|
||||
'date_entered' =>
|
||||
array (
|
||||
'name' => 'date_entered',
|
||||
'vname' => 'LBL_DATE_ENTERED',
|
||||
'type' => 'datetime',
|
||||
),
|
||||
'date_modified' =>
|
||||
array (
|
||||
'name' => 'date_modified',
|
||||
'vname' => 'LBL_DATE_MODIFIED',
|
||||
'type' => 'datetime',
|
||||
),
|
||||
'user_id' =>
|
||||
array (
|
||||
'name' => 'user_id',
|
||||
'type' => 'id',
|
||||
'required'=>true,
|
||||
'reportable'=>false,
|
||||
),
|
||||
'type' =>
|
||||
array (
|
||||
'name' => 'type',
|
||||
'type' => 'varchar',
|
||||
'len' =>25,
|
||||
),
|
||||
'source' =>
|
||||
array (
|
||||
'name' => 'source',
|
||||
'type' => 'varchar',
|
||||
'len' =>25,
|
||||
),
|
||||
'content' =>
|
||||
array (
|
||||
'name' => 'content',
|
||||
'type' => 'text',
|
||||
),
|
||||
|
||||
|
||||
)
|
||||
, 'indices' => array (
|
||||
array('name' =>'vcalspk', 'type' =>'primary', 'fields'=>array('id')),
|
||||
array('name' =>'idx_vcal', 'type' =>'index', 'fields'=>array('type', 'user_id'))
|
||||
)
|
||||
|
||||
);
|
||||
?>
|
||||
Reference in New Issue
Block a user