<?php require admin_view('static/header') ?>
<div class="container-fluid">
	<div class="row">
		<div class="col-lg-12">
			<a href="<?=admin_url('autos')?>" class="btn btn-default">Tüm Otomatik Siparişler</a>
			<a href="<?=admin_url('autos/1')?>" class="btn btn-default">Devam Ediyor</a>
			<a href="<?=admin_url('autos/0')?>" class="btn btn-default">Tamamlandı</a>
			<a href="<?=admin_url('autos/2')?>" class="btn btn-default">Durduruldu</a>
			<div class="pull-right">
				<form class="form-inline" action="" method="get">
					<div class="input-group">
						<input type="text" name="search" class="form-control" value="" placeholder="Abonelik ara...">
						<span class="input-group-btn">
							<select class="form-control" style="border-radius:0;" name="search_type">
								<option value="id">Sipariş ID</option>
								<option value="link">Bağlantı</option>
								<option value="username">Kullanıcı Adı</option>
							</select>
							<button type="submit" class="btn btn-default"><span class="fa fa-search" aria-hidden="true"></span></button>
						</span>
					</div>
				</form>
			</div>
			<div class="panel panel-default" style="margin-top:20px;">
				<table id="table" class="table order-table table-grey" style="margin-bottom:0;">
					<thead>
						<tr>
							<th>#</th>
							<th>Kullanıcı</th>
							<th style="width:30%;">Servis</th>
							<th>Tarih</th>
							<th style="width:10%;">Bağlantı</th>
							<th>Miktar</th>
							<th>Sınır</th>
							<th>Zaman Sınırı</th>
							<th>Durum</th>
							<th></th>
						</tr>
					</thead>
					<tbody>
						<?php foreach($autos as $auto): ?>
							<tr>
								<td><?=$auto["auto_id"];?></td>
								<td><b><?=($auto["user_username"] != null) ? $auto["user_username"] : "Silinmiş";?></b></td>
								<td style="width:30%;"> <span class="label-id"><?=($auto["service_id"] != null) ? $auto["service_id"] : "0";?></span><b><?=($auto["service_name"] != null) ? $auto["service_name"] : "Silinmiş";?></b></td>
								<td><?=str_date(date("Y-m-d H:i:s", $auto["auto_date"]));?></td>
								<td style="width:10%;"><?=$auto["auto_link"];?></td>
								<td><?=$auto["auto_quantity"];?></td>
								<td><?=$auto["auto_completed"];?>/<?=($auto["auto_limit"] != null) ? $auto["auto_limit"] : "∞";?></td>
								<td><?=($auto["auto_expiration"] != null) ? date("d.m.y H:i:s", $auto["auto_expiration"]) : "∞";?></td>
								<td>
									<?php if($auto["auto_status"] == 0): ?>
										Tamamlandı
									<?php elseif($auto["auto_status"] == 1): ?>
										Devam Ediyor
									<?php elseif($auto["auto_status"] == 2): ?>
										Durduruldu
									<?php endif; ?>
								</td>
								<td>
									<div class="dropdown pull-right">
										<button class="btn btn-xs btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">İşlemler<span class="caret"></span></button>
										<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
											<li class="dropdown-header">Sipariş Durumunu Güncelle</li>
											<?php if($auto["auto_status"] == 0): ?>
											<?php endif; ?>
											<?php if($auto["auto_status"] == 1): ?>
												<li><a href="#" onclick="update_auto_status('<?=$auto["auto_id"];?>', '2')">Durdur</a></li>
											<?php endif; ?>
											<?php if($auto["auto_status"] == 2): ?>
												<li><a href="#" onclick="update_auto_status('<?=$auto["auto_id"];?>', '1')" data-id="1">Devam Et</a></li>
											<?php endif; ?>
										</ul>
									</div>
								</td>
							</tr>
						<?php endforeach; ?>
					</tbody>
				</table>
			</div>
		</div>
	</div>		
</div>
<?php require admin_view('static/footer') ?>