<?php require admin_view('static/header') ?>
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">
				<a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_sendsms" data-id="send" class="btn btn-default">SMS Gönder</a>
				<a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_sendemail" data-id="send" class="btn btn-default">Mail Gönder</a>
				<a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_sendsms" data-id="numbers" class="btn btn-default">İletişim Bilgileri</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="Üye ara...">
			        		<span class="input-group-btn">
			        			<select class="form-control" style="border-radius:0;" name="search_type">
			        				<option value="id">Üye ID</option>
			        				<option value="email">EMail</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="datatabletest" class="table order-table table-grey" style="margin-bottom:0;">

							<thead>

								<tr>

									<th>ID</th>

									<th>Kullanıcı adı</th>

									<th>EMail</th>

									<th>Telefon Numarası</th>

									<th>Bakiye</th>

									<th>Üyelik Durumu</th>

									<th>Statü</th>

									<th>Fiyatlandırma</th>

									<th>Üye Kayıt Tarihi</th>

									<th>Son Güncelleme</th>

									<th></th>

								</tr>

							</thead>

							<tbody>

								<?php foreach($users as $u): $userpromotion = $db->from('special_offers')->where('user_id', $u['user_id'])->select('count(offer_id) as total')->total(); ?>

									<tr>

										<td><?=$u["user_id"];?></td>

										<td><b><?=$u["user_username"];?></b></td>

										<td><?=$u["user_email"];?></td>

										<td><?=$u["user_skype"];?></td>

										<td><?=$u["user_balance"];?></td>

										<td>

											<?php if($u["user_status"] == 0): ?>

												<span class="label label-danger">Askıya Alınmış</span>

											<?php elseif($u["user_status"] == 1): ?>

												<span class="label label-success">Aktif</span>

											<?php endif; ?>

										</td>

										<td>

											<?php if($u["user_authority"] == 0): ?>

												<span class="label label-success">Üye</span>

											<?php elseif($u["user_authority"] == 2): ?>

												<span class="label label-primary">Yetkili</span>

											<?php endif; ?>

										</td>

										<td>

											<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#modalDefault" data-id="<?=$u["user_id"]?>" data-action="get_userpromotions">Özel fiyatlandırma <span class="badge badge-xs"><?=$userpromotion?></span></button>

										</td>

										<td><?php

										if ($u["reg_date"] != null) {
											echo str_date(date('Y-m-d H:i:s', $u["last_date"]));
										}else{
											echo "Belirsiz";
										}
										
										?></td>

										<td><?php

										if ($u["last_date"] != null) {
											echo str_date(date('Y-m-d H:i:s', $u["last_date"]));
										}else{
											echo "Belirsiz";
										}
										
										?></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 pull-right" aria-labelledby="dropdownMenu1">

													<li><a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_user" data-id="<?=$u["user_id"]?>">Üyeyi Düzenle</a></li>

													<li><a href="javascript:;" data-toggle="modal" data-toggle="modal" data-target="#modalDefault" data-action="get_usersms" data-id="<?=$u["user_id"]?>">SMS Gönder</a></li>

													<?php if($u["user_status"] == 0): ?>

														<li><a href="#" onclick="user_block(<?=$u["user_id"]?>)">Hesabı Aktifleştir</a></li>

													<?php elseif($u["user_status"] == 1): ?>

														<li><a href="#" onclick="user_block(<?=$u["user_id"]?>)">Hesabı Askıya Al</a></li>

													<?php endif; ?>

													<?php
														echo '<li><a href="/admin/logs?search='.$u["user_username"].'&search_type=username">Loglar</a></li>'
													?>
													
													<?php
														echo '<li><a href="/admin/orders?search='.$u["user_username"].'&search_type=username">Siparişler</a></li>'
													?>
													
													<li><a href="javascript:;" onclick="uye_toplu_indirim_sil(<?=$u["user_id"]?>)">İndirimleri Sil</a></li>
												</ul>

											</div>

										</td>

									</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') ?>