<?php require admin_view('static/header') ?>

<div class="container-fluid">

	<div class="row">

		<div class="col-lg-12">

			<div style="text-align: right;">

				<form class="form-inline" action="" method="get">

					<div class="input-group">

						<input type="text" name="search" class="form-control" value="" placeholder="Sipariş ara...">

						<span class="input-group-btn">

							<select class="form-control" style="border-radius:0;" name="search_type">

								<option value="id">İşlem 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>İşlem ID</th>

							<th>Sipariş ID</th>

							<th>Kullanıcı</th>

							<th>Servis</th>

							<th>Bağlantı</th>

							<th>Başlangıç</th>

							<th>Miktar</th>

							<th>Talep</th>

							<th>Durum</th>

							<th>Tarih</th>

							<th></th>

						</tr>

					</thead>

					<tbody>

						<?php foreach ($tasks as $task) :

							$order = $db->from('orders')->where('order_id', $task['order_id'])->first(); 
							$service = $db->from('services')->where('service_id', $order['service_id'])->first(); ?>
							
							<tr>

								<td><?= $task['task_id'] ?></td>

								<td><?= $task['order_id'] ?></td>

								<td><?= ($task["user_username"] != null) ? $task["user_username"] : "Silinmiş"; ?></td>

								<td style="max-width:30%"><span class="label-id"><?= $task['service_id'] ?></span><?= $task['service_name'] ?></td>

								<td style="max-width:10%"><?= $task["order_link"]; ?></td>

								<td><?= $task['order_start_count'] ?></td>

								<td><?= $task['order_quantity'] ?></td>

								<td><?= $task['task_type'] ?> <?php if ($task['task_type'] == "Telafi" && $service['refill_type'] == 2) : ?>(Otomatik)<?php else : ?>(Manuel)<?php endif; ?></td>

								<td><?= $task['task_status'] ?></td>

								<td><?= str_date($task["task_date"]) ?></td>

								<th>

									<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">

											<?php if ($service['refill_type'] == 1) : ?>

												<li><a href="#" onclick="task_deny('<?= $task['task_id'] ?>', '<?= $task['type'] ?>')">Reddet</a></li>

												<li><a href="#" onclick="task_confirm('<?= $task['task_id'] ?>', '<?= $task['type'] ?>')">Onayla</a></li>

											<?php endif; ?>

										</ul>

									</div>

								</th>

							</tr>

						<?php endforeach; ?>

					</tbody>

				</table>

			</div>

			<ul class="pagination">

				<?= $db->showPagination(admin_url(route(1) . '?' . $pageParam . '=[page]')); ?>

			</ul>

		</div>



	</div>



</div>

<?php require admin_view('static/footer') ?>