<div id="rightBox">
	<table border="0" cellpadding="0" cellspacing="0" class="rightBox_table">
		<tr>
			<td><img src="/files/contentBoxTop.jpg" alt="" width="690" height="16"/></td>
		</tr>
		<tr>
			<td valign="top" style="background-image: url(/files/contentBoxMiddle.jpg); width: 690px; height: 547px; background-position: center top; background-repeat: no-repeat;">
				<div id="rightBox_content">
					<div class="content_title">Lista wiadomości</div>
					<div style="margin-top:5px;">Miesiąc:
						<?php
							$currentMonthNumber =  (int)date("m");
							 
							$months =  array("Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień");
							
							$miesiace[][$currentMonthNumber] 	= 'obecny';
							if(($currentMonthNumber-1) > 0)
								$miesiace[][$currentMonthNumber-1] 	= 'poprzedni';
							else
								$miesiace[][12] 	= 'poprzedni';	
							
							for($i=($currentMonthNumber-3);$i>=0;$i--)
							{
								$miesiace[][$i+1] = $months[$i];
							}
							
							if($currentMonthNumber < 12)
							{
								for($i=11;$i>($currentMonthNumber-1);$i--)
								{
									$miesiace[][$i+1] = $months[$i];																		
								}
								
							}
							echo '<select onchange="location.href=this.options[this.selectedIndex].value">';
							
								echo '<option value="'.base_url().'tickets/list_items/'.$ltype.'">wszystkie</option>';
								
								$selected_month  = $this->uri->segment(5);
								
								foreach($miesiace as $key=>$value)
								{	
									
									foreach($value as $key2=>$value2)
									{
										$ltype = 0;
										if($list_type == 'wyslane')
											$ltype = 1;
											
											
										$val = base_url().'tickets/list_items/'.$ltype.'/0/'.$key2;	
										
										if($key2 == $selected_month)
											echo '<option value="'.$val.'" selected="selected">'.$value2.'</option>';
										else
											echo '<option value="'.$val.'">'.$value2.'</option>'; 							
									}
								}
							echo '</select>';							
						?>
					</div>
					<table  id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1">
							<thead>
								<tr>
									<th>ID</th>
									<th>Temat</th>
									<th>Priorytet</th>
									<?php
										if($list_type == 'odebrane')
											echo '<th>Od</th>';
										else
											echo '<th>Do</th>';	
									?>	
									<th>Data wysłania</th>
									<th>Kategoria</th>
									<?php
										if($list_type == 'wyslane')
											echo '<th>Odebrano</th>'; 
									?>
								</tr>
							</thead>
							<tbody>
									<?php
										if(isset($tickets) and count($tickets)>0)
										{
											foreach($tickets as $key=>$ticket)
											{
												echo '<tr';
													if($key%2 ==0)
														echo ' class="even" ';
													else
														echo ' class="odd" ';
												if($list_type == 'odebrane' and $ticket->data_odebrania == '')
													echo ' style="font-weight:bold;">';
												else		
													echo '>';
												
															echo '<td>'.$ticket->id.'</td>';
															echo '<td><a href="/tickets/show/'.$ticket->id.'">'.$ticket->temat;	

														
														if(isset($ticket->liczba_odpowiedzi))
														{
															$liczba_odpowiedzi = (int)$ticket->liczba_odpowiedzi;
															if($liczba_odpowiedzi > 0)
																echo ' ('.$ticket->liczba_odpowiedzi.') ';
														}
													echo '</a></td>';
															
													echo '<td>'.$ticket->priorytet.'</td>';
													
													if($list_type == 'odebrane')
														echo '<td>'.$ticket->nadawca.'</td>';	//odebrane
													else
														echo '<td>'.$ticket->odbiorca.'</td>';	//wyslane
													
													
													echo '<td>'.$ticket->data_wyslania.'</td>';
													echo '<td>'.$ticket->kategoria.'</td>';
													
													if($list_type == 'wyslane')
														echo '<td>'.$ticket->odebrano.'</td>'; 													
												echo '</tr>';													
											}
										}
									 ?>
								</tr>
							</tbody>
					</table>
					<?php
						echo '<br class="spacer"/><div class="pagination_links" style="margin-top:10px;margin-bottom:10px;">'.$paginacja.'</div>';
					?>	
					<br/>
					<div class="ticket_menu">
						<div class="ticket_menu_item"><a href="/tickets/add">Nowa wiadomość</a></div>
					</div>						
				</div>
			</td>
		</tr>
	</table>
</div>				