diff --git a/calendar/freebusy.php b/calendar/freebusy.php index a6ef400b4e..e738d55a0e 100644 --- a/calendar/freebusy.php +++ b/calendar/freebusy.php @@ -12,7 +12,7 @@ /* $Id$ */ - $GLOBALS['phpgw_info'] = array( + $GLOBALS['egw_info'] = array( 'flags' => array( 'currentapp' => 'calendar', 'noheader' => True, @@ -20,46 +20,51 @@ ), ); // check if we are loged in, by checking sessionid and kp3, as the sessionid get set automaticaly by php for php4-sessions - $sessionid = isset($_COOKIE['sessionid']) ? $_COOKIE['sessionid'] : @$_GET['sessionid']; - $kp3 = isset($_COOKIE['kp3']) ? $_COOKIE['kp3'] : @$_GET['kp3']; - - if (!($loged_in = $sessionid && $kp3)) + if (!($loged_in = @$_REQUEST['sessionid'] && @$_REQUEST['kp3'])) { - $GLOBALS['phpgw_info']['flags']['currentapp'] = 'login'; - $GLOBALS['phpgw_info']['flags']['noapi'] = True; + $GLOBALS['egw_info']['flags']['currentapp'] = 'login'; + $GLOBALS['egw_info']['flags']['noapi'] = True; } include ('../header.inc.php'); function fail_exit($msg) { echo "\n\n$msg\n\n\n

$msg

\n\n\n"; + $GLOBALS['egw']->translation->charset()."\" />\n\n

$msg

\n\n\n"; - $GLOBALS['phpgw']->common->phpgw_exit(); + $GLOBALS['egw']->common->egw_exit(); } if (!$loged_in) { include ('../phpgwapi/inc/functions.inc.php'); - $GLOBALS['phpgw_info']['flags']['currentapp'] = 'calendar'; + $GLOBALS['egw_info']['flags']['currentapp'] = 'calendar'; } - $user = is_numeric($_GET['user']) ? (int) $_GET['user'] : $GLOBALS['phpgw']->accounts->name2id($_GET['user']); + $user = is_numeric($_GET['user']) ? (int) $_GET['user'] : $GLOBALS['egw']->accounts->name2id($_GET['user'],'account_lid','u'); - if (!($username = $GLOBALS['phpgw']->accounts->id2name($user))) + if (!($username = $GLOBALS['egw']->accounts->id2name($user))) { - fail_exit(lang("freebusy: Unknow user '%1', wrong password or not availible to not loged in users !!!",$_GET['user'])); + fail_exit(lang("freebusy: Unknow user '%1', wrong password or not availible to not loged in users !!!"." $username($user)",$_GET['user'])); } if (!$loged_in) { - $GLOBALS['phpgw']->preferences->account_id = $user; - $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->read_repository(); - $GLOBALS['phpgw_info']['user']['account_id'] = $user; - $GLOBALS['phpgw_info']['user']['account_lid'] = $username; + $GLOBALS['egw']->preferences->account_id = $user; + $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(); + $GLOBALS['egw_info']['user']['account_id'] = $user; + $GLOBALS['egw_info']['user']['account_lid'] = $username; - $cal_prefs = &$GLOBALS['phpgw_info']['user']['preferences']['calendar']; + $cal_prefs = &$GLOBALS['egw_info']['user']['preferences']['calendar']; if (!$cal_prefs['freebusy'] || !empty($cal_prefs['freebusy_pw']) && $cal_prefs['freebusy_pw'] != $_GET['password']) { fail_exit(lang("freebusy: Unknow user '%1', wrong password or not availible to not loged in users !!!",$_GET['user'])); } } - ExecMethod('calendar.boicalendar.freebusy'); + if ($_GET['debug']) + { + echo "
";
+	}
+	else
+	{
+		ExecMethod2('phpgwapi.browser.content_header','freebusy.ifb','text/calendar');
+	}
+	echo ExecMethod2('calendar.boical.freebusy',$user,$_GET['end']);
diff --git a/calendar/inc/class.bocal.inc.php b/calendar/inc/class.bocal.inc.php
index 27ace1094e..99b5001418 100644
--- a/calendar/inc/class.bocal.inc.php
+++ b/calendar/inc/class.bocal.inc.php
@@ -1685,6 +1685,22 @@ class bocal
 			$GLOBALS['egw']->preferences->save_repository(False,'default');
 		}
 	}
+	
+	/**
+	 * Get the freebusy URL of a user
+	 *
+	 * @param int/string $user account_id or account_lid
+	 * @param string $pw=null password
+	 */
+	function freebusy_url($user,$pw=null)
+	{
+		if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user);
+
+		return (!$GLOBALS['egw_info']['server']['webserver_url'] || $GLOBALS['egw_info']['server']['webserver_url']{0} == '/' ?
+			($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] : '').
+			$GLOBALS['egw_info']['server']['webserver_url'].'/calendar/freebusy.php?user='.urlencode($user).
+			($pw ? '&password='.urlencode($pw) : '');
+	}
 }
 
 if (!function_exists('array_intersect_key'))	// php5.1 function
diff --git a/calendar/inc/class.boical.inc.php b/calendar/inc/class.boical.inc.php
index 266e276cc6..c0f2fd8e96 100644
--- a/calendar/inc/class.boical.inc.php
+++ b/calendar/inc/class.boical.inc.php
@@ -74,7 +74,7 @@
 			0 => 0,		// undefined
 			9 => 1,	8 => 1, 7 => 1, 6 => 1,	// low
 			5 => 2,		// normal
-			4 => 3, 3 => 3, 2 => 3, 1 => 3,	// high
+			4 => 3, 2 => 3, 3 => 3, 1 => 3,	// high
 		);
 		
 		/**
@@ -98,6 +98,14 @@
 			MCAL_RECUR_MONTHLY_WDAY => 'MP',	// BYDAY={1..5}{MO..SO}
 			MCAL_RECUR_YEARLY       => 'YM',
 		);
+		
+		/**
+		 * manufacturer and name of the sync-client
+		 *
+		 * @var string
+		 */
+		var $productManufacturer = 'file';
+		var $productName = '';
 
 		/**
 		 * Exports one calendar event to an iCalendar item
@@ -318,7 +326,7 @@
 				}
 				
 				$attributes['UID'] = $eventGUID;
-	
+
 				foreach($attributes as $key => $value)
 				{
 					foreach(is_array($value) ? $value : array($value) as $valueID => $valueData)
@@ -673,6 +681,10 @@
 
 		function setSupportedFields($_productManufacturer='file', $_productName='')
 		{
+			// save them vor later use
+			$this->productManufacturere = $_productManufacturer;
+			$this->productName = $_productName;
+
 			$defaultFields = array('public' => 'public', 'description' => 'description', 'end' => 'end',
 				'start' => 'start', 'location' => 'location', 'recur_type' => 'recur_type',
 				'recur_interval' => 'recur_interval', 'recur_data' => 'recur_data', 'recur_enddate' => 'recur_enddate',
@@ -904,7 +916,14 @@
 								$vcardData['non_blocking'] = $attributes['value'] == 'TRANSPARENT';
 								break;
 							case 'PRIORITY':
-	 							$vcardData['priority'] = (int) $this->priority_ical2egw[$attributes['value']];
+								if ($this->productManufacturer == 'nexthaus corporation')
+								{
+									$vcardData['priority'] = $attributes['value'] == 1 ? 3 : 2; // 1=high, 2=normal
+								}
+								else
+								{
+	 								$vcardData['priority'] = (int) $this->priority_ical2egw[$attributes['value']];
+								}
 	 							break;
 	 						case 'CATEGORIES':
 	 							$vcardData['category'] = array();
@@ -1036,5 +1055,57 @@
 			}
 			return false;
 		}
+		
+		/**
+		 * Create a freebusy vCal for the given user(s)
+		 *
+		 * @param int $user account_id
+		 * @param mixed $end=null end-date, default now+1 month
+		 * @return string
+		 */
+		function freebusy($user,$end=null)
+		{
+			if (!$end) $end = $this->now_su + 100*DAY_s;	// default next 100 days
+			
+			$vcal = &new Horde_iCalendar;
+			$vcal->setAttribute('PRODID','-//eGroupWare//NONSGML eGroupWare Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
+				strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
+			$vcal->setAttribute('VERSION','2.0');
+
+			$vfreebusy = Horde_iCalendar::newComponent('VFREEBUSY',$vcal);
+			$parameters = array(
+				'ORGANIZER' => $GLOBALS['egw']->translation->convert(
+					$GLOBALS['egw']->accounts->id2name($user,'account_firstname').' '.
+					$GLOBALS['egw']->accounts->id2name($user,'account_lastname'),
+					$GLOBALS['egw']->translation->charset(),'utf-8'),
+			);
+			foreach(array(
+				'URL' => $this->freebusy_url($user),
+				'DTSTART' => $this->date2ts($this->now_su,true),	// true = server-time
+				'DTEND' => $this->date2ts($end,true),	// true = server-time
+			  	'ORGANIZER' => $GLOBALS['egw']->accounts->id2name($user,'account_email'),
+				'DTSTAMP' => time(),
+			) as $attr => $value)
+			{
+				$vfreebusy->setAttribute($attr, $value, $parameters[$name]);
+			}
+			foreach(parent::search(array(
+				'start' => $this->now_su,
+				'end'   => $end,
+				'users' => $user,
+				'date_format' => 'server',
+				'show_rejected' => false,
+			)) as $event)
+			{
+				if ($event['non_blocking']) continue;
+
+				$vfreebusy->setAttribute('FREEBUSY',array(array(
+					'start' => $event['start'],
+					'end' => $event['end'],
+				)));
+			}
+			$vcal->addComponent($vfreebusy);
+
+			return $vcal->exportvCalendar();
+		}
 	}
-?>
diff --git a/calendar/inc/hook_settings.inc.php b/calendar/inc/hook_settings.inc.php
index 50015b322d..dbfc11d242 100644
--- a/calendar/inc/hook_settings.inc.php
+++ b/calendar/inc/hook_settings.inc.php
@@ -15,7 +15,8 @@
 
 	/* $Id$ */
 
-	ExecMethod('calendar.bocal.check_set_default_prefs');
+	$bocal =& CreateObject('calendar.bocal');
+	$bocal->check_set_default_prefs();
 
 	$default = array(
 		'day'          => lang('Dayview'),
@@ -121,11 +122,7 @@
 //		'private+group'  => lang('private and group public'),
 //		'public+group'   => lang('global public and group public')
 	);
-	$freebusy_url = $GLOBALS['egw_info']['server']['webserver_url'].'/calendar/freebusy.php?user='.$GLOBALS['egw_info']['user']['account_lid'].'&password='.$GLOBALS['egw_info']['user']['preferences']['calendar']['freebusy_pw'];
-	if ($freebusy_url[0] == '/')
-	{
-		$freebusy_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$freebusy_url;
-	}
+	$freebusy_url = $bocal->freebusy_url($GLOBALS['egw_info']['user']['account_lid'],$GLOBALS['egw_info']['user']['preferences']['calendar']['freebusy_pw']);
 	$freebusy_help = lang('Should not loged in persons be able to see your freebusy information? You can set an extra password, different from your normal password, to protect this informations. The freebusy information is in iCal format and only include the times when you are busy. It does not include the event-name, description or locations. The URL to your freebusy information is %1.',''.$freebusy_url.'');
 
 	$GLOBALS['settings'] = array(
@@ -329,7 +326,7 @@
 			'xmlrpc' => True,
 			'admin'  => False
 		),
-/* disabled free/busy stuff til it gets rewritten with new Horde iCal classes -- RalfBecker 2006/03/03
+// disabled free/busy stuff til it gets rewritten with new Horde iCal classes -- RalfBecker 2006/03/03
 		'freebusy' => array(
 			'type'  => 'check',
 			'label' => 'Make freebusy information available to not loged in persons?',
@@ -349,5 +346,4 @@
 			'xmlrpc' => True,
 			'admin'  => False
 		)
-*/
 	);