Index: trunk/calendar/inc/class.uicalendar.inc.php
===================================================================
--- trunk/calendar/inc/class.uicalendar.inc.php	(revision 212)
+++ trunk/calendar/inc/class.uicalendar.inc.php	(revision 360)
@@ -118,4 +118,25 @@
 			$this->link_tpl->set_block('link_picture','link_close','link_close');
 			$this->link_tpl->set_block('link_picture','link_text','link_text');
+			
+			/*************** EVENTO **************************/
+/* Este bloco de codigo foi adicionado pois os eventos de agendamento (exibicao do mes) para impressao serao tratados em outro template
+(event_link.tpl) */
+
+			$this->event_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
+			$this->event_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
+			$this->event_tpl->set_unknowns('remove');
+			$this->event_tpl->set_file(
+				Array(
+					'link_event'	=> 'event_link.tpl'
+				)
+			);
+			$this->event_tpl->set_block('link_event','link_event_pict','link_event_pict');
+			$this->event_tpl->set_block('link_event','event_pict','event_pict');
+			$this->event_tpl->set_block('link_event','link_event_open','link_event_open');
+			$this->event_tpl->set_block('link_event','link_event_close','link_event_close');
+			$this->event_tpl->set_block('link_event','link_event_text','link_event_text');
+
+
+/*************************************************/
 
 			if($this->bo->use_session)
@@ -435,5 +456,7 @@
 				$print = "<a href='javascript:void(0)' onClick=\"javascript:window.open('".$this->page('month'.$param).
 						"','','width=600,height=600,toolbar=no,scrollbars=yes,resizable=no');\" onMouseOver=\"window.status = '".
-						lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';				
+						lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
+				//linha abaixo foi adicionada para exibir a pagina do mes em tela
+				$large_month = $this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner);				
 			}
 			else
@@ -444,4 +467,6 @@
 				$print =	'';
 				$GLOBALS['phpgw_info']['flags']['nofooter'] = True;
+				//linha abaixo foi adicionada para exibir a pagina do mes para impressao
+				$large_month = $this->display_month_print($this->bo->month,$this->bo->year,True,$this->bo->owner);
 			}
 
@@ -457,5 +482,6 @@
 				'next_month_link'		=>	$next_month_link,
 				'small_calendar_next'	=>	$minical_next,
-				'large_month'				=>	$this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner),
+				//'large_month'				=>	$this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner),
+				'large_month'		=>	$large_month,
 				'print'						=>	$print
 			);
@@ -463,9 +489,19 @@
 			$p = CreateObject('phpgwapi.Template',$this->template_dir);
 			$p->set_unknowns('remove');
-			$p->set_file(
-				Array(
-					'index_t'	=>	'index.tpl'
-				)
-			);
+			// Alteracao que desvincula o template para tela do template de impressao do mes (month_print teve que ser criado);
+			if($print != '')
+			{
+				$p->set_file(
+					Array(
+						'index_t'	=>	'index.tpl'
+					)
+				);
+			}else {
+				$p->set_file(
+					Array(
+						'index_t'	=>	'month_print.tpl'
+					)
+				);
+			}
 			$p->set_var($var);
 			return $p->fp('out','index_t');
@@ -2936,4 +2972,194 @@
 			return $str;
 		}
+
+/*****************************************************************************************/
+/*Funcao foi duplicada e alterada para tratar os eventos de agendamento (exibicao do mes) para impressao;
+utiliza o template event_lik.tpl*/
+
+		function link_to_month_entry($event,$month,$day,$year)
+		{
+			$str = '';
+			$is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
+			$viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
+
+			$starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
+			$endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
+			$rawdate = mktime(0,0,0,$month,$day,$year);
+			$rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
+			$nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
+			if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
+			{
+				$time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
+			}
+			elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
+			{
+				$time = '[ '.lang('All Day').' ]';
+			}
+			elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
+			{
+				if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
+				{
+					$start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
+				}
+				else
+				{
+					$start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
+				}
+
+				if($endtime >= ($rawdate_offset + 86400))
+				{
+					$end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
+				}
+				else
+				{
+					$end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
+				}
+				$time = $start_time.' - '.$end_time;
+			}
+			else
+			{
+				$time = '';
+			}
+			
+			$texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
+
+			
+			
+			if(!$is_private)
+			{
+				//$text .= $this->bo->display_status($event['users_status']);
+				
+				// split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation	
+				$textstatus=$this->bo->display_status($event['users_status']); 
+				
+			}
+
+			$text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
+			
+			$texttime=$time;
+			$texttitle=$this->bo->get_short_field($event,$is_private,'title');
+			$textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
+			// added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
+			$textlocation=$this->bo->get_short_field($event,$is_private,'location');
+
+			if ($viewable)
+			{
+				$date = sprintf('%04d%02d%02d',$year,$month,$day);
+				$this->event_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
+				$this->event_tpl->set_var('lang_view',lang('View this entry'));
+				$this->event_tpl->set_var('desc', $textdesc);
+				$this->event_tpl->set_var('location', $textlocation);
+				$this->event_tpl->parse('picture','link_event_open',True);
+			}
+			if (!$is_private)
+			{
+				if($event['priority'] == 3)
+				{
+					$picture[] = Array(
+						'pict'	=> $GLOBALS['phpgw']->common->image('calendar','high'),
+						'width'	=> 16,
+						'height'=> 16,
+						'title' => lang('high priority')
+					);
+				}
+				if($event['recur_type'] == MCAL_RECUR_NONE)
+				{
+					$picture[] = Array(
+						'pict'	=> $GLOBALS['phpgw']->common->image('calendar','circle'),
+						'width'	=> 9,
+						'height'=> 9,
+						'title' => lang('single event')
+					);
+				}
+				else
+				{
+					$picture[] = Array(
+						'pict'	=> $GLOBALS['phpgw']->common->image('calendar','recur'),
+						'width'	=> 12,
+						'height'=> 12,
+						'title' => lang('recurring event')
+					);
+				}
+			}
+			$participants = $this->planner_participants($event['participants']);
+			if(count($event['participants']) > 1)
+			{
+				$picture[] = Array(
+					'pict'	=> $GLOBALS['phpgw']->common->image('calendar','multi_3'),
+					'width'	=> 14,
+					'height'=> 14,
+					'title' => $participants
+				);
+			}
+			else
+			{
+				$picture[] = Array(
+					'pict'	=>  $GLOBALS['phpgw']->common->image('calendar','single'),
+					'width'	=> 14,
+					'height'=> 14,
+					'title' => $participants
+				);
+			}
+			if($event['public'] == 0)
+			{
+				$picture[] = Array(
+					'pict'	=> $GLOBALS['phpgw']->common->image('calendar','private'),
+					'width'	=> 13,
+					'height'=> 13,
+					'title' => lang('private')
+				);
+			}
+			if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
+			{
+				// if the alarm is to go off the day before the event
+				// the icon does not show up because of 'alarm_today'
+				// - TOM
+				if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
+				{
+					$picture[] = Array(
+						'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
+						'width' => 13,
+						'height'=> 13,
+						'title' => lang('alarm')
+					);
+				}
+			}
+
+			$description = $this->bo->get_short_field($event,$is_private,'description');
+			for($i=0;$i<count($picture);$i++)
+			{
+				$var = Array(
+					'pic_image' => $picture[$i]['pict'],
+					'width'     => $picture[$i]['width'],
+					'height'    => $picture[$i]['height'],
+					'title'     => $picture[$i]['title']
+				);
+				$this->output_template_array($this->event_tpl,'picture','event_pict',$var);
+			}
+			if ($texttitle)
+			{
+				$var = Array(
+			//		'text' => $text,
+					'time'=> $texttime,
+					'title'=> $texttitle,
+					'users_status'=>$textstatus,
+					'desc'=> $textdesc,
+					'location'=> "<br><b>Local:</b> ".$textlocation
+				);
+				$this->output_template_array($this->event_tpl,'picture','link_event_text',$var);
+			}
+
+			if ($viewable)
+			{
+				$this->event_tpl->parse('picture','link_event_close',True);
+			}
+			$str = $this->event_tpl->fp('out','link_event_pict');
+			$this->event_tpl->set_var('picture','');
+			$this->event_tpl->set_var('out','');
+//			unset($p);
+			return $str;
+		}
+
+/*****************************************************************************************/
 
 		function overlap($params)
@@ -3239,5 +3465,219 @@
 		}
 
-		function display_month($month,$year,$showyear,$owner=0)
+/***************************************************************************************/
+/*As funcoes abaixo
+	month_week_header()
+	month_display_week()
+	display_month_print()
+	month_day_of_week() - esta foi criada mas parte do codigo e de outra funcao da API (day_of_week());
+
+  foram duplicadas e modificadas para atender aas modificacoes do layout de impressao mensal da agenda de eventos;
+  TODO: otimizar o codigo
+
+  Rommel Cysne
+*/
+
+		function month_week_header($month,$year,$display_name = False)
+		{
+			$this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
+
+		//	$p = CreateObject('phpgwapi.Template',$this->template_dir);
+			$p->set_unknowns('remove');
+		//	$p->set_file(
+		//		Array (
+		//			'month_header' => 'month_header_print.tpl'
+		//		)
+		//	);
+	//		$p->set_block('month_header','monthly_header','monthly_header');
+	//		$p->set_block('month_header','column_title','column_title');
+
+/*			$var = Array(
+				'bgcolor'	=> $this->theme['th_bg'],
+				'font_color'	=> $this->theme['th_text']
+			);
+			/*if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
+			{
+				$var = Array(
+					'bgcolor'	=> '',
+					'font_color'	=> ''
+				);
+			}*/
+	/*		$p->set_var($var);
+
+			$p->set_var('col_width','14');
+		/*	if($display_name == True)
+			{
+				$p->set_var('col_title',lang('name'));
+				$p->parse('column_header','column_title',True);
+				$p->set_var('col_width','12');
+			}
+*/
+			//for($i=0;$i<7;$i++)
+			//{
+			//	$p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
+			//	$p->parse('column_header','column_title',True);
+			//}
+//			return $p->fp('out','monthly_header');
+		}
+
+
+		function month_day_of_week($year,$month,$day)
+		{
+			$dia = Array(
+				0 => 'Domingo',
+				1 => 'Segunda',
+				2 => 'Ter&ccedil;a',
+				3 => 'Quarta',
+				4 => 'Quinta',
+				5 => 'Sexta',
+				6 => 'S&aacute;bado'
+			);
+
+			if($month > 2)
+			{
+				$month -= 2;
+			}
+				else
+			{
+				$month += 10;
+				$year--;
+			}
+			$day = (floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * floor($year / 100) + 77);
+
+			$month_day = ($day - 7 * floor($day / 7)); //retorna o numero do dia da semana (Ex: domingo eh dia 0, terca eh 2);
+			$weekday = $dia[$month_day]; //retorna o nome do dia da semana de acordo com seu numero;
+
+			return ($weekday);
+
+		}
+
+		function month_display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
+		{
+			if($owner == 0)
+			{
+				$owner = $GLOBALS['phpgw_info']['user']['account_id'];
+			}
+
+			$temp_owner = $this->bo->owner;
+
+			$str = '';
+			$p = CreateObject('phpgwapi.Template',$this->template_dir);
+			$p->set_unknowns('keep');
+
+			$p->set_file(
+				Array(
+					'month_header'	=> 'month_header_print.tpl',
+					'month_day'	=> 'month_day_print.tpl'
+				)
+			);
+			$p->set_block('month_header','monthly_header','monthly_header');
+			$p->set_block('month_header','month_column','month_column');
+			$p->set_block('month_day','month_daily','month_daily');
+			$p->set_block('month_day','day_event','day_event');
+			$p->set_block('month_day','event','event');
+
+			$p->set_var('extra','');
+			$p->set_var('col_width','14');
+		/*	if($display_name)
+			{
+				$p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
+				$p->parse('column_header','month_column',True);
+				$p->set_var('col_width','12');
+			}*/
+			$today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
+			$daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
+			foreach($daily as $date => $day_params)
+			{
+				$year  = (int)substr($date,0,4);
+				$month = (int)substr($date,4,2);
+				$day   = (int)substr($date,6,2);
+				$var   = Array(
+					'column_data' => '',
+					'extra' => ''
+				);
+				$p->set_var($var);
+				if ($weekly || ($date >= $monthstart && $date <= $monthend))
+				{
+					//if ($day_params['new_event'])
+					//{
+					//	$new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
+					//		. '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
+					//		. '</a>';
+					//	$day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
+					//}
+					//else
+					//{
+						$new_event_link = '';
+						$day_num = $day;
+						$dia_semana = $this->month_day_of_week($year,$month,$day_num);
+						$day_number = $dia_semana . ",  " . $day_num;
+					//}
+
+					$var = Array(
+						'extra'		=> $day_params['extra'],
+						'new_event_link'=> $new_event_link,
+						'day_number'	=> $day_number
+					);
+	/*				if($day_params['week'])
+					{
+
+//NDEE: style! m_w_table in month_day.tpl
+// week-hilite
+						//$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
+	//					$var['new_event_link'] .= ' &nbsp; '.
+	//						(!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'"><span id="calendar_weekinfo" class="calendar_weekinfo">' .$day_params['week'].'</span></a>' : '<span id="calendar_weekinfo" class="calendar_weekinfo">'.$day_params['week'].'</span>');
+					}
+	*/
+			
+
+					$p->set_var($var);
+
+	/*				if(@$day_params['holidays'])
+					{
+						foreach($day_params['holidays'] as $key => $value)
+						{
+							$var = Array(
+								'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
+							);
+							$this->output_template_array($p,'daily_events','event',$var);
+						
+					}
+	*/
+
+					if($day_params['appts'])
+					{
+						$var = Array(
+							'week_day_font_size'	=> '2',
+							'events'		=> ''
+						);
+						$p->set_var($var);
+						$events = $this->bo->cached_events[$date];
+						//eventos
+						//print_r($events);
+						foreach($events as $event)
+						{
+							if ($this->bo->rejected_no_show($event))
+							{
+								continue;	// user does not want to see rejected events
+							}
+							$p->set_var('day_events',$this->link_to_month_entry($event,$month,$day,$year));
+							$p->parse('events','event',True);
+							$p->set_var('day_events','');
+						}
+					}
+					$p->parse('daily_events','day_event',True);
+					$p->parse('column_data','month_daily',True);
+					$p->set_var('daily_events','');
+					$p->set_var('events','');
+				}
+				$p->parse('column_header','month_column',True);
+				$p->set_var('column_data','');
+			}
+			$this->bo->owner = $temp_owner;
+			return $p->fp('out','monthly_header');
+
+		}
+
+		function display_month_print($month,$year,$showyear,$owner=0)
 		{
 			if($this->debug)
@@ -3259,4 +3699,57 @@
 			$start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
 
+			$p = CreateObject('phpgwapi.Template',$this->template_dir);
+			$p->set_unknowns('keep');
+
+			$p->set_file(
+				Array(
+					'week' => 'month_day_print.tpl'
+				)
+			);
+			$p->set_block('week','m_w_table','m_w_table');
+			$p->set_block('week','event','event');
+
+			$var = Array(
+				'cols'      => 1,
+				'day_events'=> '' //$this->month_week_header($month,$year,False)
+			);
+//			$this->output_template_array($p,'row','event',$var);
+
+			$cellcolor = $this->theme['row_on'];
+
+			for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
+			{
+				$cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
+				$var = Array(
+					'day_events' => $this->month_display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
+				);
+				$this->output_template_array($p,'row','event',$var);
+			}
+			return $p->fp('out','m_w_table');
+		}
+
+
+/***************************************************************************************/
+
+		function display_month($month,$year,$showyear,$owner=0)
+		{
+			if($this->debug)
+			{
+				echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
+			}
+
+			$this->bo->store_to_cache(
+				Array(
+					'syear'	=> $year,
+					'smonth'=> $month,
+					'sday'	=> 1
+				)
+			);
+
+			$monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
+			$monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
+
+			$start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
+
 			if($this->debug)
 			{
@@ -3277,5 +3770,5 @@
 
 			$var = Array(
-				'cols'      => 7,
+				'cols'      => 1,
 				'day_events'=> $this->week_header($month,$year,False)
 			);
@@ -4584,4 +5077,5 @@
 		function set_week_array($startdate,$cellcolor,$weekly)
 		{
+			$data = date("m");
 			for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
 			{
