   <?php
   // CRUD 
   @$getId = base64_decode(anti_injection($_GET['id']));  
    if(@$getId){ 
        $query = mysql_query("SELECT * FROM users WHERE id = + $getId");
        $result = mysql_fetch_array($query);
    }
    
    if(isset ($_POST['save'])){
	$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'];
	$nivel = $_POST['nivel'];
	$login = $_POST['login'];
	$status = $_POST['status'];
	
	$crud = new crud('users');  // table
    $crud->inserir("name_user,email,senha,salt,address,city,state,zipcode,signature,suporte,nivel,login,phone,status", "'$name_user','$email','$senha','$salt','$address','$city','$state','$zipcode','$signature','$suporte','$nivel','$login','$phone','$status'");
	
	header("Location: index.php?mod=Users&y=1"); 
    
	
	}
	
	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'];
	$nivel = $_POST['nivel'];
	$login = $_POST['login'];
	$status = $_POST['status'];
	$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',suporte='$suporte',nivel='$nivel',login='$login',phone='$phone',status='$status'", "id='$registerID'");
	
	header("Location: index.php?mod=Users&y=2");
	}
	
    if ((isset($_GET["action"])) && ($_GET["action"] == "delete")) {
    $id = base64_decode($_GET['id']); 
    $crud = new crud('users'); // Table
    $crud->excluir("id = $id"); // ID
    
    header("Location: index.php?mod=Users&y=3");
    }
    
    
    ?>
    <!-- JAVASCRIPT -->
     <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>
    <!-- END -->  
      
    <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <?php echo $lang['TITLE_NEW_USERS']; ?>
          </h1>
          
        </section>

       
       <!-- Main content -->
        <section class="content">
          <div class="row">
			  
			  
            <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['SLOGAN_REGISTER_CUSTOMER']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form role="form" method="POST" id="CustomerForm" name="CustomerForm">
				<input type="hidden" name="len" id="pass-len" value="8">
					
                  <div class="box-body">
					  
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['NAME']; ?></label>
                      <input type="text" name="name_user" value="<?php echo @$result['name_user']; ?>" id="name_user" class="form-control" placeholder="<?php echo $lang['NAME_PLACEHOLDER']; ?>">
                    </div>
              
                   
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['EMAIL']; ?></label>
                      <input type="email" class="form-control" name="email" value="<?php echo @$result['email']; ?>" placeholder="<?php echo $lang['EMAIL_PLACEHOLDER']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['LOGIN']; ?></label>
                      <input type="text" name="login" id="login" value="<?php echo @$result['login']; ?>" class="form-control">
                    </div>
                   
                   <div class="form-group">
                   <label for="Input"><?php echo $lang['PASS']; ?></label>
                   <div class="input-group ">
					
                    <input type="text" class="form-control" name="pass" id="pass" value="<?php echo @base64_decode($result['salt']); ?>" placeholder="<?php echo $lang['PASS_PLACEHOLDER']; ?>">
                    <span class="input-group-btn">
                      <button class="btn btn-info btn-flat" name="generate" id="generatePassword" type="button">Go!</button>
                    </span>
                  </div>
                   </div>
                   
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PASS_CONFIRM']; ?></label>
                      <input type="text" class="form-control" name="pass2" id="pass2" placeholder="<?php echo $lang['PASS_CONFIRM_PLACEHOLDER']; ?>">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['PHONE']; ?></label>
                      <input type="text" name="phone" id="phone" value="<?php echo @$result['phone']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['USER_NIVEL']; ?></label>
                      <select id="nivel" name="nivel" class="form-control" style="width: 100%;" required>
                      <option value="1"><?php echo $lang['SELECT_USER_NIVEL1']; ?></option>
                      <option value="2"><?php echo $lang['SELECT_USER_NIVEL2']; ?></option>
                      <option value="3"><?php echo $lang['SELECT_USER_NIVEL3']; ?></option>
				      </select>
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['DEPARTMENT']; ?></label>
                      <select id="server" name="suporte" id="suporte" class="form-control select2" style="width: 100%;">
						  <option value="">Select</option>
                    <?php
					$catsr = mysql_query("SELECT * FROM departments order by id DESC");
					while($srv = mysql_fetch_array($catsr)){ 
					?>
                    <option value="<?php echo $srv['id']; ?>" <?php if (@$result['suporte'] == $srv['id']) { echo "selected"; } ?>><?php echo $srv['name_department']; ?></option>
				    <?php } ?> 
				    </select>
                    </div>
                    
                   <div class="form-group">
                      <label for="Input"><?php echo $lang['STATUS']; ?></label><br>
                      <label for="S"><input id="S" type="radio" name="status" value="S" <?php if (@$result['status'] == 'S') { echo "checked"; } if (@$result['status'] == '') { echo "checked"; } ?>> <?php echo $lang['ACTIVE']; ?></label>
                      <label for="N"><input id="N" type="radio" name="status" value="N" <?php if (@$result['status'] == 'N') { echo "checked"; } ?>> <?php echo $lang['BLOCK']; ?></label>
                    </div>
                    
                    
                   
                  </div><!-- /.box-body -->

                 
                
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
           
           <!-- left column -->
            <div class="col-md-6">
              <!-- general form elements -->
              <div class="box box-info">
                <div class="box-header with-border">
                  <h3 class="box-title"><?php echo $lang['SLOGAN_REGISTER_ADDRESS']; ?></h3>
                </div><!-- /.box-header -->
                <!-- form start -->
   
                  <div class="box-body">
					 
					<div class="form-group">
                      <label for="Input"><?php echo $lang['ADDRESS']; ?></label>
                      <input type="text" name="address" value="<?php echo $result['address']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['CITY']; ?></label>
                      <input type="text" name="city" value="<?php echo $result['city']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['STATE']; ?></label>
                      <input type="text" name="state" value="<?php echo $result['state']; ?>" class="form-control">
                    </div>
                    
                     <div class="form-group">
                      <label for="Input"><?php echo $lang['ZIPCODE']; ?></label>
                      <input type="text" name="zipcode" value="<?php echo $result['zipcode']; ?>" class="form-control">
                    </div>
                    
                    <div class="form-group">
                      <label for="Input"><?php echo $lang['SIGNATURE']; ?></label>
                      <textarea name="signature" class="form-control" id="msg"><?php echo @$result['sigature']; ?></textarea>
                    </div>
                   
                  </div><!-- /.box-body -->

                  <div class="box-footer">
					  
		  <?php if (@$result['id'] <> '') { ?>

		  <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 @$result['id']; ?>"> 
		  <? } else { ?>
		  <input type="submit" value="<?php echo $lang['REGISTER']; ?>" name="save" style="text-transform:uppercase" class="btn btn-success btn-lg btn-block">
		  <?php } ?>
					  
                  </div>
                  
                 
                </form>
                
              </div><!-- /.box -->
           </div><!-- /.col -->
           
          </div><!-- /.row -->
        </section><!-- /.content -->
       
        
      </div><!-- /.content-wrapper -->
   
   
   
   
