<?php $this->load->view('admin/inc/header');?>
<body>

	<?php $this->load->view('admin/inc/nav_top');?>
		
	<div class="container-fluid">
		<div class="row-fluid">
			<?php $this->load->view('admin/inc/nav_main');?>
			<div id="content" class="span10">
			<!-- start: Content -->
			<div>
				<hr>
				<ul class="breadcrumb">
					<li>
						<a href="<?php echo site_url('/');?>">Home</a> <span class="divider">/</span>
					</li>
					<li>
						<a href="#">Users</a>
					</li>
				</ul>
				<hr>
			</div>
			
			<div class="row-fluid sortable">
            
            
				<div class="box span8">
					<div class="box-header">
						<h2><i class="icon-th"></i><span class="break"></span>All Users</h2>
						<div class="box-icon">
							<a href="#" class="btn-close"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content" id="curr_cats">
                  	  	<?php $this->admin_model->get_all_users();?>
                                        
                  </div>
				</div>
                <div class="box span4 noMargin" onTablet="span12" onDesktop="span4">
					<div class="box-header">
						<h2><i class="icon-list"></i><span class="break"></span>User Stats</h2>
						<div class="box-icon">
							<a href="#" class="btn-minimize"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn-close"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content">
					<?php //$this->google_model->load_overview();?>
					</div>
				</div><!--/span-->
                
  
                
                <div class="box span4 noMargin" onTablet="span12" onDesktop="span4">
					<div class="box-header">
						<h2><i class="icon-list"></i><span class="break"></span>Legend</h2>
						<div class="box-icon">
							<a href="#" class="btn-minimize"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn-close"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content">
                    
                   
                     <div class="well">

                      <p><a title="Delete the user" rel="tooltip" class="btn btn-mini btn-danger" style="cursor:pointer"><i class="icon-trash icon-white"></i></a> - Delete User</p>
                      
					</div>
                    <a onClick="add_sys_user()" class="btn btn-inverse"><i class="fa-icon-plus-sign"></i> Add New User</a> 
		    		</div>
				</div><!--/span-->
                
			</div>
			
			<hr>
			
			<div class="row-fluid">
				
				
				
			</div>
			
			<hr>
			

			<!-- end: Content -->
			</div><!--/#content.span10-->
		</div><!--/fluid-row-->
				
		<div class="modal hide fade" id="modal-add">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Add System user</h3>
          </div>
          <div class="modal-body">
            <form id="user-add" name="user-add" method="post" action="<?php echo site_url('/');?>admin/add_sys_user_do" class="form-horizontal">
            
            <div class="control-group">
                  <label class="control-label" for="name">User Name</label>
                <div class="controls">
                   <input type="text" id="name" name="name" placeholder="User Name" value="">                    
                </div>
             </div>
              <div class="control-group">
                  <label class="control-label" for="sname">Surname</label>
                <div class="controls">
                   <input type="text" id="sname" name="sname" placeholder="Surname" value="">                    
                </div>
             </div>
              <div class="control-group">
                  <label class="control-label" for="position">User Position</label>
                <div class="controls">
                    <select name="position" id="position">
                      <option value="editor">Editor</option>
                      <option value="admin">Admin</option>
                     
                    </select>                    
                </div>
             </div>
             <div class="control-group">
                  <label class="control-label" for="email">User Email</label>
                <div class="controls">
                   <input type="text" id="email" name="email" placeholder="User Email" value="">                    
                </div>
             </div>
             <div class="control-group">
                  <label class="control-label" for="userpass">User Password</label>
                <div class="controls">
                   <input type="password" id="userpass" name="userpass" placeholder="User Password" value="">                    
                </div>
             </div>  
               
                
            </form>
          </div>
          <div class="modal-footer">
            <a onClick="$('#modal-add').modal('hide');" class="btn">Close</a>
            <a href="#" class="btn btn-primary">Add user</a>
          </div>
        </div>
        
        <div class="modal hide fade" id="modal-user-delete">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Delete the User</h3>
          </div>
          <div class="modal-body">
            <div class="alert">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                 <strong>Please Note!</strong> Are you sure you want to delete the current user? All user details will be removed. This proces is not reversible.
            </div>
        
          </div>
          <div class="modal-footer">
            <a onClick="$('#modal-user-delete').modal('hide');" class="btn">Close</a>
            <a href="#" class="btn btn-primary">Delete User</a>
          </div>
        </div>
        
        
        
        <div class="modal hide fade" id="modal-update">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Update System user</h3>
          </div>
          <div class="modal-body" id="update_content">
            
          </div>
          <div class="modal-footer">
            <a onClick="$('#modal-update').modal('hide');" class="btn">Close</a>
            <a onClick="update_sys_user_do()" class="btn btn-primary">Update user</a>
          </div>
        </div>
        <div class="clearfix"></div>
				
       

            
	
	<?php $this->load->view('admin/inc/footer');?>
	</div><!--/.fluid-container-->
	<script type="text/javascript">
		function delete_user(id){
			  
			$('#modal-user-delete').bind('show', function() {
				//var id = $(this).data('id'),
					removeBtn = $(this).find('.btn-primary');
						
					removeBtn.unbind('click').click(function(e) { 
						e.preventDefault();	
						$.ajax({
						  url: "<?php echo site_url('/');?>admin/delete_user/"+id+"/",
						  success: function(data) {
							
							$('footer').html(data);
							$('#modal-user-delete').modal('hide');
							window.location = '<?php echo site_url('/');?>admin/users';
						  }
						});
						
					});
			}).modal({ backdrop: true });
		}

						
			
						
						
				function add_sys_user(){
						
						$('#modal-add').bind('show', function() {
								
								var removeBtn = $(this).find('.btn-primary');
								
								removeBtn.unbind('click').click(function(e) { 
									e.preventDefault();
									var frm = $('#user-add');
						
									$.ajax({
									  type: "post",
									  data: frm.serialize(),
									  url: "<?php echo site_url('/');?>admin/add_sys_user_do",
									  success: function(data) {
										
										$('#msg').html(data);
										$('#modal-add').modal('hide');
										window.location = '<?php echo site_url('/');?>admin/users';
									  }
									});
									
								});
						}).modal({ backdrop: true });
						
					}			
					
					function update_sys_user(id){
						
						$('#modal-update').bind('show', function() {
								
									$.ajax({
									  type: "get",
									  url: "<?php echo site_url('/');?>admin/get_sys_user/"+id,
									  success: function(data) {
										
										$('#update_content').html(data);
									  }
									});
									
							
						}).modal({ backdrop: true });
						
					}
					
					
					function update_sys_user_do(){
						
							  var frm = $('#user-update');
					
							  $.ajax({
								type: "post",
								data: frm.serialize(),
								url: "<?php echo site_url('/');?>admin/update_sys_user_do",
								success: function(data) {
								  
								  $('#msg').html(data);
								  $('#modal-update').modal('hide');
								  window.location = '<?php echo site_url('/');?>admin/users';
								}
							  });
							
						
					}
							
							
						

						

	</script>
</body>
</html>