Index: trunk/calendar/inc/class.bocalendar.inc.php
===================================================================
--- trunk/calendar/inc/class.bocalendar.inc.php	(revision 313)
+++ trunk/calendar/inc/class.bocalendar.inc.php	(revision 363)
@@ -709,4 +709,6 @@
 			{
 				$event = $this->so->read_entry($event_id);
+				if(!$this->ex_participants)
+					$this->ex_participants = html_entity_decode($event['ex_participants']);			
 				if($this->check_perms(PHPGW_ACL_DELETE,$event))
 				{
@@ -1087,4 +1089,6 @@
 				);
 			}
+			if(!$this->ex_participants)
+				$this->ex_participants = $event['ex_participants'];			
 			if($overlapping_events)
 			{
@@ -1111,6 +1115,4 @@
 				if(!$event['id'])
 				{
-					if(!$this->ex_participants)
-						$this->ex_participants = $event['ex_participants'];
 					$this->so->add_entry($event);
 					$this->send_update(MSG_ADDED,$event['participants'],'',$this->get_cached_event());
@@ -2526,4 +2528,6 @@
 	function create_vcard($event_array)
 	{
+	if(!$event_array)
+		return null;
 	$tmpattach="BEGIN:VCALENDAR\n"
 	."PRODID:-//Expresso Livre//Calendar//EN\n"
@@ -2532,5 +2536,5 @@
 		{
 			// It translates int to string
-			if (! array_key_exists  ('end', $event))
+			if (!is_object($event)  || !is_array($event) || !array_key_exists  ('end', $event))
 				$event = $event_array;
 			if ( $event['end']['month'] < 10 )
@@ -2721,10 +2725,4 @@
 					$details['link'];
 			}
-
-			/*if(!is_object($GLOBALS['phpgw']->send))
-			{
-				$GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
-			}*/
-		//	$send = &$GLOBALS['phpgw']->send;
 			
 			//Seta o email usando phpmailer
@@ -2734,18 +2732,12 @@
 			$mail = new PHPMailer();
 			$mail->IsSMTP();
-			/*
-			$mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer'];
-			$mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort'];
-			$mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email'];
-			$mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
-			$mail->IsHTML(true);
-			*/
 			$boemailadmin = CreateObject('emailadmin.bo');
 			$emailadmin_profile = $boemailadmin->getProfileList();
 			$emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
+		
 			$mail->Host = $emailadmin['smtpServer'];
 			$mail->Port = $emailadmin['smtpPort'];
 			$mail->From = $GLOBALS['phpgw']->preferences->values['email'];
-			$mail->FromName = $GLOBALS['phpgw_info']['user'];
+			$mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
 			$mail->IsHTML(true);
 
@@ -2753,5 +2745,4 @@
 			foreach($to_notify as $userid => $statusid) 
 			{
-			 	$mail->ClearAllRecipients();
 			 	$mail->ClearAttachments();
 			 	
@@ -3000,32 +2991,23 @@
 					$mail->SenderName = $mail->FromName;
 					$mail->Subject = $subject;
-					
-					
-					//It sends email for the participants ( Envia email para os participantes)
-					if(!$mail->Send())
-					{
-						
-   						$returncode=false;
-					}
-					else
-					{
-						$returncode=true;
-					}
-								
-					//$returncode = $send->msg('email',$to,$subject,$tmpbody,''/*$msgtype*/,'','','',$sender, $content_type/*,$boundary*/);
-
-				
 					unset($vardata5);
 					unset($vardata6);
-					if (!$returncode)	// not nice, but better than failing silently
-					{
-						echo '<p><b>bocalendar::send_update</b>: '.lang("Failed sending message to '%1' #%2 subject='%3', sender='%4'!!!",$to,$userid,htmlspecialchars($subject), $sender)."<br>\n";
-						echo '<i>'.$mail->ErrorInfo."</i><br>\n";
-						echo lang('This is mostly caused by a not or wrongly configured SMTP server. Notify your administrator.')."</p>\n";
-						echo '<p>'.lang('Click %1here%2 to return to the calendar.','<a href="'.$GLOBALS['phpgw']->link('/calendar/').'">','</a>')."</p>\n";
-					}
-				}
-			}
+				}
+			}
+
+			//Inicializa variável de retorno.
+			$returncode=true;			
+			if(count($mail->to)) {				
+				// Envia aviso a todos os participantes.
+				if(!$mail->Send()) {				
+					$returncode = false;
+					$errorInfo['participants'] = $mail->ErrorInfo;
+				}
+				else
+					$returncode =  true;
+			}
+			
 			if(count($to_notify) && $this->ex_participants){
+				$mail->ClearAllRecipients();
 				$var = explode(",",trim($this->ex_participants));
 				$to = array();
@@ -3035,4 +3017,5 @@
 					list($subject,$body1) = split("\n",$GLOBALS['phpgw']->preferences->parse_notify($notify_msg,$details),2);
 				}
+				
 				foreach($var as $index => $ex_participant){
 					$ex_participant = trim($ex_participant);
@@ -3041,9 +3024,11 @@
 							$to[] = $ex_participant;
 				}		
+				
 				foreach($to as $i => $to_array)
 					$mail->AddAddress($to_array);
+				
 				$_body = explode("<hr size='1' width='100%'>",$tmpbody);
-				$tmpbody = $_body[0];
-				$tmpbody.= "<b>".lang("external participants").":: </b> ".htmlentities($this->ex_participants);
+				$tmpbody = $_body[0] ? $_body[0] : $subject ;
+				$tmpbody.= "<br><b>".lang("external participants").":: </b> ".htmlentities($this->ex_participants);
 				$tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[title]."<br>";
 				$tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>";
@@ -3056,27 +3041,28 @@
 				else
 					$event_month="0".$GLOBALS['bocalendar']->so->cal->event[start][month];
-				$tmpbody .="<a href='../index.php?menuaction=calendar.uicalendar.add&date="
-				.$GLOBALS['bocalendar']->so->cal->event[start][year]
-				.$event_month
-				.$GLOBALS['bocalendar']->so->cal->event[start][mday]
-				."&hour=".$GLOBALS['bocalendar']->so->cal->event[start][hour]
-				."&minute=".$GLOBALS['bocalendar']->so->cal->event[start][min]
-				."&title=".$GLOBALS['bocalendar']->so->cal->event['title']
-				."&description=".$GLOBALS['bocalendar']->so->cal->event['description']
-				."&location=".$GLOBALS['bocalendar']->so->cal->event['location']."'>"
-				."<h2>".lang("Add to my expresso")."</h2>";
-				
 				//attach extern vcard			
 				// define('context','$GLOBALS.bocalendar.so.cal.event');
 				$tmpattach = $this->create_vcard($GLOBALS['bocalendar']->so->cal->event);
-				$tempdir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
-				srand((double)microtime()*1000000);
-				$random_number = rand(100000000,999999999);
-				$newfilename = md5(time() . getenv("REMOTE_ADDR") . $random_number );
-				$filename = $tempdir . $newfilename;
-				$attach_fd = fopen($filename,"w+");
-				fwrite($attach_fd,$tmpattach);
-				$mail->AddAttachment($filename, "extern.vcard", "base64", "text/plain"); // "application/octet-stream"
-				fclose($attach_fd);
+				if($tmpattach){					
+					$tmpbody .="<a href='../index.php?menuaction=calendar.uicalendar.add&date="
+					.$GLOBALS['bocalendar']->so->cal->event[start][year]
+				.$event_month
+				.$GLOBALS['bocalendar']->so->cal->event[start][mday]
+					."&hour=".$GLOBALS['bocalendar']->so->cal->event[start][hour]
+					."&minute=".$GLOBALS['bocalendar']->so->cal->event[start][min]
+					."&title=".$GLOBALS['bocalendar']->so->cal->event['title']
+					."&description=".$GLOBALS['bocalendar']->so->cal->event['description']
+					."&location=".$GLOBALS['bocalendar']->so->cal->event['location']."'>"
+					."<h2>".lang("Add to my expresso")."</h2>";
+					$tempdir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
+					srand((double)microtime()*1000000);
+					$random_number = rand(100000000,999999999);
+					$newfilename = md5(time() . getenv("REMOTE_ADDR") . $random_number );
+					$filename = $tempdir . $newfilename;
+					$attach_fd = fopen($filename,"w+");
+					fwrite($attach_fd,$tmpattach);
+					$mail->AddAttachment($filename, "extern.vcard", "base64", "text/plain"); // "application/octet-stream"
+					fclose($attach_fd);
+				}
 				$mail->From = $sender;
 				$mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
@@ -3085,8 +3071,9 @@
 				$mail->Subject = lang("External event from Expresso");
 				$mail->Body = $tmpbody;
-				
-				if(!$mail->Send())
-				{
-   					$returncode=false;
+																		
+				if(!$mail->Send()) 
+				{
+					$returncode=false;
+					$errorInfo['ex_participants'] = $mail->ErrorInfo;
 				}
 				else
@@ -3101,5 +3088,5 @@
 			{
 				$GLOBALS['phpgw_info']['user'] = $temp_user;
-			}
+			}	
 
 			$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'] = $temp_tz_offset;
@@ -3107,8 +3094,48 @@
 			$GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] = $temp_timeformat;
 			$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] = $temp_dateformat;
-
+			
+			// Notifica por email o criador do compromisso, com as possíveis falhas.						
+			if($errorInfo) {
+				$tmpbody = "<font color='red'>".lang("The following commitment had problems for DELIVERING the NOTIFICATION messages.").".</font><br>";
+				$tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[title]."<br>";
+				$tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>";				
+				$tmpbody.= "<br><u>".lang("Failed to delivery")."</u><br>";
+				$failed = false;				
+				if(strstr($errorInfo['participants'],"recipients_failed")){
+					$failed	= explode("recipients_failed",$errorInfo['participants']);
+					$tmpbody.= lang("to").": ".$failed[1];
+				}
+				if(strstr($errorInfo['ex_participants'],"recipients_failed")){
+					$failed = explode("recipients_failed",$errorInfo['ex_participants']);
+					$tmpbody.= lang("to").": ".$failed[1];
+				}			
+				if(!$failed) {
+					$tmpbody.= lang("Description").":<br>";
+					$tmpbody.= $errorInfo['participants'];
+					$tmpbody.= "<br>".$errorInfo['ex_participants'];
+				}
+				$tmpbody.= "<br>".lang("Subject").": ".$subject;
+				// Reinicializa o objeto, devido ao erro anterior na entrega.
+				
+				$mail = new PHPMailer();
+				$mail->IsSMTP();
+				$mail->Host = $emailadmin['smtpServer'];
+				$mail->Port = $emailadmin['smtpPort'];
+				$mail->From = $sender;
+				$mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
+				$mail->Sender = $mail->From;
+				$mail->SenderName = $mail->FromName;
+				$mail->IsHTML(True);
+				$mail->Subject = lang("calendar event")." - ".lang("email notification");							
+				$mail->Body = $tmpbody;					
+				$mail->AddAddress($sender);
+				if(!$mail->Send())			
+					$returncode = false;
+				else
+					$returncode =  true;
+			}
 			return $returncode;
 		}
-
+		
 		function send_alarm($alarm)
 		{
@@ -3182,4 +3209,5 @@
 		function prepare_recipients(&$new_event,$old_event)
 		{
+						
 			// Find modified and deleted users.....
 			while(list($old_userid,$old_status) = each($old_event['participants']))
@@ -3206,9 +3234,10 @@
 				}
 			}
-
+			
 			if(count($this->added) > 0 || count($this->modified) > 0 || count($this->deleted) > 0)
 			{
 				if(count($this->added) > 0)
 				{
+					$this->ex_participants = '';
 					$this->send_update(MSG_ADDED,$this->added,'',$new_event);
 				}
@@ -3219,4 +3248,5 @@
 				if(count($this->deleted) > 0)
 				{
+					$this->ex_participants = '';
 					$this->send_update(MSG_DELETED,$this->deleted,$old_event);
 				}
@@ -3370,4 +3400,6 @@
 		function event2array($event)
 		{
+			
+			
 		  $var['title'] = Array(
 				'field'		=> $this->translate('Title'),
@@ -3386,5 +3418,5 @@
 				'data'	=> $event['ex_participants']
 			);
-
+			
 			$cats = Array();
 			$this->cat->categories($this->bo->owner,'calendar');
