<?php $__env->startSection('header'); ?>
    <style>
        #header {
            background:#8d1c22;
        }

        .form-inline {
            margin:10px;
        }
        #content .table {
            font-size:12px;
        }

        .head-table {
            width:100%;
        }
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
   <div class="row-fluid">
    	<div class="span9">
    	</div>
        <div>
            <h4 class="nametag">使用者管理系統</h4>
		<br><br><br>

	<h5><?php echo Session::get('message'); ?></h5>

	<?php if(Session::get('info')): ?>
		<h5><?php echo Session::get('info'); ?></h5>
	<?php endif; ?>

	<?php if($errors->first() == "1"): ?>
        <div class="alert alert-success">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <strong>寄送成功!</strong>
        </div>
        <?php elseif($errors->any()): ?>
        <div class="alert alert-danger">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <strong>錯誤!</strong> <?php echo $errors->first(); ?>

        </div>
	<?php endif; ?>

		<div class = "row">
	    		<div class="input-group">
		        	<span class="input-group-addon">選擇分類：</span>
	        		<select class="form-control" name="id" id = 'select_id'>
				<option value = "0">全部</option>
				<option value = "1" <?php if(isset($id))echo($id==0)?"selected":""; ?>>種子帳戶</option>
				<option value = "2" <?php if(isset($id))echo($id==1)?"selected":""; ?>>一般帳戶</option>
				</select>			
	       	        </div>
			<!--a href=<?php echo URL::to('admin/user/memberlist/1'); ?> class="btn btn-info">
                    		<span class="glyphicon glyphicon-file"></span>
                    		種子帳戶
                	</a>
                	<a href=<?php echo URL::to('admin/user/memberlist/2'); ?>  class="btn btn-info">
                   		<span class="glyphicon glyphicon-file"></span>
                    		一般帳戶
                	</a-->
		</div>
		<hr>
		<div class="row">
		<!--div
  class="fb-like"
  data-share="true"
  data-width="450"
  data-show-faces="true">
</div-->
	            <div class = "col-xs-8 col-sm-8 col-md-8">    
			<a href=<?php echo URL::to('admin/user/create-user'); ?> class="btn btn-primary">
        	            <span class="glyphicon glyphicon-file"></span>
                	    新增使用者
	                </a>
		
			<!--button class="btn btn-success" id="fb-auth">Login</button-->
			<div class="fb-login-button" scope="email" id="fb-auth" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="true"></div>
	
			<!--a class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">
				<span class="glyphicon glyphicon-file"></span>
				新增種子帳戶
			</a-->
                            <!--a href=<?php echo URL::to('admin/user/login'); ?>>使用者登入API(測試)</a-->
		   </div>
		   <div class = "col-md-4 col-ms-4 col-xs-4 pull right" style="margin-top:10px">
			<div class="input-group">
				<input type="text" id="user_search" value="" class="form-control" placeholder="user's account"/>
				<input type="text" id="user_condition_search" value="" class="form-control" placeholder="搜尋條件"/>
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="button" name="search" onclick="searchByIE()">Seach</button>
                                </span>
			</div>
		   </div>
                </div>
		<br><hr>
                <table class="table table-bordered" id="user-table">
              <thead>
                    <!--tr><th>Account</th><th>身分字號</th><th>出生日期</th><th>手機號碼</th><th>信箱</th><th>住址</th><th>紅利</th><th>操作</th><th>狀態</th></tr-->
                    <tr><th>註冊時間</th><th>登入方式</th><th>會員編號</th><th>帳戶狀態</th><th>帳戶權限</th><th>會員名稱</th><th>聯絡電話</th><th>功能按鈕</th></tr>
              </thead>
              <tbody>
              <?php foreach($users as $user): ?>
                <tr>
		<td><?php echo $user->register_time; ?></td>
		<td><?php echo $user->login_type; ?></td>
                <td><a href="<?php echo URL::to('admin/user/detail/'.$user->id); ?>"><?php echo $user->id; ?></td>
                <td><?php echo($user->is_available == 0)?"停權":"權限正常"; ?></td>
		<td><?php echo $user->status; ?></td>
		<td id="td_user_account"><?php echo $user->name; ?></td>
                <td><?php echo $user->phone; ?></td>

                <td><!--a href="<?php echo URL::to('admin/user/update-user/'.$user->id); ?>" class='btn btn-success glyphicon glyphicon glyphicon-edit'></a>

                    <form action="<?php echo URL::to('admin/user/delete-user'); ?>" method="POST" style="display:inline">
                                        <input type="hidden" name="id" value="<?php echo $user->id; ?>" />
                                        <button name="del" type="submit" class='<?php if($user->is_available ==0)
											echo "btn btn-info glyphicon glyphicon-ok row-ok";
										      else
											echo "btn btn-danger glyphicon glyphicon-remove row-remove";?>'
 								onclick="if(!confirm('確定要改變此使用者帳戶權限?'))
								{return false;};">
					</button>
                                </form-->
                    	<a href="<?php echo URL::to('admin/user/detail/'.$user->id); ?>" class='btn btn-primary glyphicon glyphicon glyphicon-user'></a>
		    <?php if($user->level == '一般帳戶'): ?>
                    <form action="<?php echo URL::to('admin/user/delete-user'); ?>" method="POST" style="display:inline">
                                        <input type="hidden" name="id" value="<?php echo $user->id; ?>" />
                                        <button name="del" type="submit" class='<?php if($user->is_available ==0)
											echo "btn btn-info glyphicon glyphicon-ok row-ok";
										      else
											echo "btn btn-danger glyphicon glyphicon-remove row-remove";?>'
 								onclick="if(!confirm('確定要改變此使用者帳戶權限?'))
								{return false;};">
					</button>
                                </form>
		    <?php endif; ?>
		    <?php if($user->login_type == 'NINETEN'): ?>
                    	<a href="<?php echo URL::to('admin/user/send-passwd/'.$user->id); ?>" class='btn btn-warning glyphicon glyphicon glyphicon-envelope' 
				onclick="if(!confirm('是否寄送密碼')){return false;}"></a>
		    <?php else: ?>
                    	<a href=# class='btn btn-default glyphicon glyphicon glyphicon-envelope' 
				onclick="{alert('此為facebook 登入用戶 無法傳送更改密碼！'); return false;}"></a>
		    <?php endif; ?>
                </td>
                </tr>
                <?php endforeach; ?>
              </tbody>
            </table>
<div id='fb-root'></div><!-- required for SDK initialization -->
<script src="http://connect.facebook.net/en_US/all.js"></script>
        <script language="JavaScript">
  		window.fbAsyncInit = function() {
		    FB.init({
		    appId      : '558716530932928',
		    cookie     : true,
		    xfbml      : true,
		    version    : 'v2.4'
    		    });

//////////

function updateButton(response) {
  //Log.info('Updating Button', response);
  var button = document.getElementById('fb-auth'), r = [], check = 1;

  if (response.status === 'connected') {
   /* button.innerHTML = 'Logout';
    button.className = 'btn btn-danger';
    button.onclick = function() {
      FB.logout(function(response) {
        Log.info('FB.logout callback', response);
      });
    };*/
      FB.api('/me?fields=name,id,email,gender','get', function(response) {
        for (var key in response) {
                r.push(response[key]);
        }
       <?php if(Session::has('info')): ?>
                check = 0;
        <?php endif; ?>
        if(check)
        {
                //redirect
                var url = "<?php echo URL::to('admin/user/fblogin/'); ?>" + '/'+ r;
                window.location.href= url;
        }
      });
  } /*else {
    button.innerHTML = 'Login';
    button.className = 'btn btn-success';
    button.onclick = function() {
      FB.login(function(response) {
        Log.info('FB.login callback', response);
        if (response.status === 'connected') {
          Log.info('User is logged in');
	alert(response.status);
        } else {
          Log.info('User is logged out');
        }
      });
    };
  }*/
}


FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
//////////i

////////////
  		};

	  (function(d, s, id){
	     var js, fjs = d.getElementsByTagName(s)[0];
	     if (d.getElementById(id)) {return;}
	     js = d.createElement(s); js.id = id;
	     js.src = "//connect.facebook.net/en_US/sdk.js";
	     fjs.parentNode.insertBefore(js, fjs);
	   }(document, 'script', 'facebook-jssdk'));
	

            $(document).ready(function(){
		// Write on keyup event of keyword input element
                    $("#user_search").keyup(function(){
                        // When value of the input is not blank
                        search($(this).val());
                    });
		// select event
               $("select[name=id]").change(function(){
			var value =$("select[name=id]").val();
		 	var URL = 'http://106.187.42.25/new-jack/new-nineten/public/admin/user/memberlist/'+value;
			window.location = URL;
		return false;
              });
		
		setInterval(function(){$("[name=register-time]").val(getCurrentDate());},1000);
            });
            // jQuery expression for case-insensitive filter
            $.extend($.expr[":"], 
            {
             "contains-ci": function(elem, i, match, array) 
                    {
                          return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
                    }
            });
   		
            function searchByIE() {
                search(document.getElementById("user_search").value);
            }

            function search(key) {
                if( key != "") {
                        // Show only matching TR, hide rest of them
                        $("#user-table tbody>tr").hide();
                        $("#user-table #td_user_account:contains-ci('" + key + "')").parent("tr").show();
                } else {
                        // When there is no input or clean again, show everything back
                        $("#user-table tbody>tr").show();
                }
            }
        </script>
    </div> <!-- div -->
</div> <!-- .row-fluid -->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('dialog'); ?>
    <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
          <h4 class="modal-title" id="mySmallModalLabel">新增種子帳戶</h4>
    </div>
    
	<div class="modal-body">
    	<?php echo Form::open(array('url' => '/admin/user/add-seed-user', 'id' => 'add-user-form')); ?>

		<div class="form-group">
			<label class="control-label col-sm-4">註冊時間</label>
			<div class="col-sm-8">
				<?php echo Form::text('register-time','', array('class' => 'form-control')); ?>

			</div>
		</div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">登入方式</label>
                        <div class="col-sm-8">
				<?php echo Form::select('login-type', array('NINETEN' => 'NINETEN', 'Facebook' => 'Facebook'),'NINETEN',['class' => 'form-control']); ?>

		        </div>
                </div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">帳戶權限</label>
                        <div class="col-sm-8">
				<?php echo Form::select('authority', array('一般' => '一般', '特殊' => '特殊'),'特殊',['class' => 'form-control']); ?>

                        </div>
                </div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">帳戶狀態</label>
                        <div class="col-sm-8">
				<?php echo Form::select('status', array('正常' => '正常', '停權' => '停權'), '正常',['class' => 'form-control']); ?>

                        </div>
                </div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">登入信箱</label>
                        <div class="col-sm-8">
				<?php echo Form::text('email','', array('class' => 'form-control')); ?>

			</div>
                </div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">種子姓名</label>
                        <div class="col-sm-8">
				<?php echo Form::text('name','', array('class' => 'form-control')); ?>

                        </div>
                </div> <br><br>
                <div class="form-group">
                        <label class="control-label col-sm-4">手機號碼</label>
                        <div class="col-sm-8">
				<?php echo Form::text('phone','', array('class' => 'form-control')); ?>

                        </div>
                </div> <br><br>
                <div class="form-group">
				<?php echo Form::submit('送出', array('class' => 'btn btn-primary')); ?>

                </div>
    	<?php echo Form::close(); ?>

	</div>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('Myadmin::layout.basic', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>