<?php

    if(isset($_POST['update'])) {
	$name_user = $_POST['name_user'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];
	$senha = md5($_POST['pass']);
	$passemail = $_POST['pass'];
	$salt = base64_encode($_POST['pass']);
	$address = $_POST['address'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zipcode = $_POST['zipcode'];
	$signature = $_POST['signature'];
	$suporte = $_POST['suporte'];
	$login = $_POST['login'];
	$registerID = $_POST['registerID'];
	
	$crud = new crud('users'); // Table
    $crud->atualizar("name_user='$name_user',email='$email',senha='$senha',salt='$salt',address='$address',city='$city',state='$state',zipcode='$zipcode',signature='$signature',login='$login',phone='$phone'", "id='$registerID'");
	
	header("Location: index.php?mod=Adm&y=2");
	}
	
?>

 <script>
     $().ready(function() {

		$("#CustomerForm").validate({
			rules: {
                login: {
					required: true,
					minlength: 6
				},
				name_user: {
					required: true,
					minlength: 4
				},
				pass: {
					required: true,
					minlength: 5
				},
				pass2: {
					required: true,
					minlength: 5,
					equalTo: "#pass"
				},
				email: {
					required: true,
					email: true
				}
			},
			messages: {
	            login: {
					required: "<?php echo $lang['VALIDATE_LOGIN']; ?>",
					minlength: "<?php echo $lang['VALIDATE_LOGIN_MIN']; ?>"
				},
				name_user: {
					required: "<?php echo $lang['VALIDATE_NAME']; ?>",
					minlength: "<?php echo $lang['VALIDATE_NAME_MIN']; ?>"
				},
				pass: {
					required: "<?php echo $lang['VALIDATE_PASS']; ?>",
					minlength: "<?php echo $lang['VALIDATE_PASS_MIN']; ?>"
				},
				pass2: {
					required: "<?php echo $lang['VALIDATE_PASS']; ?>",
					minlength: "<?php echo $lang['VALIDATE_PASS_MIN']; ?>",
					equalTo: "<?php echo $lang['VALIDATE_PASS_CONFIRM']; ?>"
				},
				email: "<?php echo $lang['VALIDATE_EMAIL']; ?>"
			}
		});

	});
	
	</script>

<!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Admin Profile
          </h1>
         
        </section>

        <!-- Main content -->
        <section class="content">

          <div class="row">
            <div class="col-md-3">

              <!-- Profile Image -->
              <div class="box box-primary">
                <div class="box-body box-profile">
                  <img class="profile-user-img img-responsive img-circle" src="<?php echo $gravatar_link; ?>" alt="User profile picture">
                  <h3 class="profile-username text-center"><?php echo $logado['name_user']; ?></h3>
                  <p class="text-muted text-center">
				  <?php if($logado['nivel'] == '1') { echo "Administrator"; } if($logado['nivel'] == '2') { echo "Support"; } if($logado['nivel'] == '3') { echo "Billing"; }  ?>
				  </p>

                  <ul class="list-group list-group-unbordered">
                    <li class="list-group-item">
                      <b>Followers</b> <a class="pull-right">1,322</a>
                    </li>
                    <li class="list-group-item">
                      <b>Following</b> <a class="pull-right">543</a>
                    </li>
                    <li class="list-group-item">
                      <b>Friends</b> <a class="pull-right">13,287</a>
                    </li>
                  </ul>

                  <a href="#" class="btn btn-primary btn-block"><b>Follow</b></a>
                </div><!-- /.box-body -->
              </div><!-- /.box -->

              
            </div><!-- /.col -->
            
            
            <div class="col-md-9">
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#activity" data-toggle="tab">Activity</a></li>
                  <li><a href="#settings" data-toggle="tab">Settings</a></li>
                </ul>
                <div class="tab-content">
                  <div class="active tab-pane" id="activity">
                   
                 <table class="table table-striped table-hover">
                    <thead>
                      <tr>
                        <th><?php echo $lang['IP']; ?></th>
                        <th><?php echo $lang['DATE']; ?></th>
                        <th><?php echo $lang['BROWSER']; ?></th>
                        <th><?php echo $lang['ACTION']; ?></th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
					$user = $logado['id'];
					$dt = date('Y-m-d');
 		  			$logs = mysql_query("SELECT * FROM log_tb WHERE user = '$user' AND data = '$dt' order by id DESC");
 		  			while($log = mysql_fetch_array($logs)){ 
					?>
		            <tr>
					
		            <td><?php echo $log['ip']; ?></td>
		            <td><?php if($lang['DATE_FORMAT'] == 'PT') { ?><?php echo data_br($log['data']); ?><?php } ?><?php if($lang['DATE_FORMAT'] == 'EN') { ?><?php echo data_en($log['data']); ?><?php } ?> <?php echo $log['hora']; ?></td>
		            <td><?php echo $log['navegador']; ?></td>
		            <td><?php if($log['msg'] == '') { ?>Dashboard<? } else { ?><?php echo $log['msg']; ?><?php } ?></td>
					
		            </tr>
					<?php } ?>
					
                    </tbody>
                    <tfoot>
                      <tr>
                        <th><?php echo $lang['IP']; ?></th>
                        <th><?php echo $lang['DATE']; ?></th>
                        <th><?php echo $lang['BROWSER']; ?></th>
                        <th><?php echo $lang['ACTION']; ?></th>
                      </tr>
                    </tfoot>
                  </table>
                   
                   
                   
                  </div><!-- /.tab-pane -->
                  
                  
                  

                  <div class="tab-pane" id="settings">
					  
                    <form method="POST" action="?mod=Adm" id="CustomerForm" name="CustomerForm" class="form-horizontal">
                    <input type="hidden" name="len" id="pass-len" value="8">
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['NAME']; ?></label>
                        <div class="col-sm-10">
						<input type="text" name="name_user" value="<?php echo @$logado['name_user']; ?>" id="name_user" class="form-control" placeholder="<?php echo $lang['NAME_PLACEHOLDER']; ?>">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['EMAIL']; ?></label>
                        <div class="col-sm-10">
                      <input type="email" class="form-control" name="email" value="<?php echo @$logado['email']; ?>" placeholder="<?php echo $lang['EMAIL_PLACEHOLDER']; ?>">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['LOGIN']; ?></label>
                        <div class="col-sm-10">
                        <input type="text" name="login" id="login" value="<?php echo @$logado['login']; ?>" class="form-control">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['PASS']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" class="form-control" name="pass" id="pass" value="<?php echo @base64_decode($logado['salt']); ?>" placeholder="<?php echo $lang['PASS_PLACEHOLDER']; ?>">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['PASS_CONFIRM']; ?></label>
                        <div class="col-sm-10">
                       <input type="text" class="form-control" name="pass2" id="pass2" placeholder="<?php echo $lang['PASS_CONFIRM_PLACEHOLDER']; ?>">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['PHONE']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" name="phone" id="phone" value="<?php echo @$logado['phone']; ?>" class="form-control">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['ADDRESS']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" name="address" value="<?php echo $logado['address']; ?>" class="form-control">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['CITY']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" name="city" value="<?php echo $logado['city']; ?>" class="form-control">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['STATE']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" name="state" value="<?php echo $logado['state']; ?>" class="form-control">
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['ZIPCODE']; ?></label>
                        <div class="col-sm-10">
                      <input type="text" name="zipcode" value="<?php echo $logado['zipcode']; ?>" class="form-control">
                        </div>
                      </div>
                      
                       <div class="form-group">
                        <label for="Input" class="col-sm-2 control-label"><?php echo $lang['SIGNATURE']; ?></label>
                        <div class="col-sm-10">
                      <textarea name="signature" class="form-control" id="msg"><?php echo @$logado['sigature']; ?></textarea>
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                        <input type="submit" value="<?php echo $lang['UPDATE']; ?>" name="update" style="text-transform:uppercase" class="btn btn-info btn-lg btn-block">
						<input type="hidden" name="registerID" value="<?php echo @$logado['id']; ?>"> 
                        </div>
                      </div>
                    </form>
                    
                    
                  </div><!-- /.tab-pane -->
                </div><!-- /.tab-content -->
              </div><!-- /.nav-tabs-custom -->
            </div><!-- /.col -->
          </div><!-- /.row -->

        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
