<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">Wiadomości</div>
					
						Typ:
						<select name="typ" style="width:100px" onchange="location.href=this.options[this.selectedIndex].value">
							<?php
								foreach($list_types as $k=>$v)
									echo '<option value="'.base_url().'tickets/list_items/'.$k.'" '.((isset($list_type) && ($list_type==$v)) ? 'selected = \'selected\'' : '').'>'.$v.'</option>';
							?>										
						</select>
					
					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 style="width:100px" onchange="location.href=this.options[this.selectedIndex].value">';
    							echo '<option value="'.base_url().'tickets/list_items/0">wszystkie</option>';
								
								$selected_month  = $this->uri->segment(5);
								
								foreach($miesiace as $key=>$value)
								{	
									
									foreach($value as $key2=>$value2)
									{
										$ltype = 0;
										if($list_type == 'wysłane')
											$ltype = 1;
											
											
										$val = base_url().'tickets/list_items/'.$ltype.'/0/'.$key2;	
										
										if($key2 == $selected_month)
											echo '<option value="'.$val.'" selected="selected">'.$value2.'</option>\r\n';
										else
											echo '<option value="'.$val.'">'.$value2.'</option>\r\n';
									}
								}
							echo '</select>';
						?>
					
					<table  id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1">
							<thead>
								<tr>
									<?php
										if($list_type == 'odebrane')
											echo '<th>Od</th>';
										else
											echo '<th>Do</th>';
									?>	
									<th>Temat</th>
									<th>Priorytet</th>
                                    <th>Status</th>
                                    <th>Data wysłania</th>
									<th>Kategoria</th>
									<?php
										if($list_type == 'wysłane')
											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 empty($ticket->data_odebrania) and $ticket->odbiorca_id == $user_account['id'])
													echo ' style="font-weight:bold;">';
												else		
													echo '>';


													if($list_type == 'odebrane')
														echo '<td>'.$ticket->nadawca.'</td>';	//odebrane
													else
														echo '<td>'.$ticket->odbiorca.'</td>';	//wyslane

													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>';
													echo '<td>'.$ticket->status.'</td>';
							

                                                    echo '<td>'.$ticket->data_wyslania.'</td>';


													echo '<td>'.$ticket->kategoria.'</td>';
													
													if($list_type == 'wysłane')
														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 class="formHr">&nbsp;</div>
                	<input type="button" name="nowa_wiadomosc" value="Nowa wiadomość" class="formButton" onClick="document.location.href='<?php echo base_url();?>tickets/add';"/>											
				</div>
			</td>
		</tr>
	</table>
</div>				