<file_sep><?php

defined('BASEPATH') or exit('No direct script access allowed');

class Users extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function get_all_users()
	{
		$query = $this->db->query('SELECT * FROM users ORDER BY username');
		return [
			'status' => '200',
			'users' => $query->result_array()
		];
	}

	public function get_users_by_search_query(string $query = null, bool $strict = false)
	{
		if ($query === null) {
			return $this->get_all_users();
		}

		if ($strict) {
			$query = $this->db->query('SELECT * FROM users WHERE username = ? ORDER BY username', [$query]);
		} else {
			$query = $this->db->query('SELECT * FROM users WHERE username LIKE ? ORDER BY username', ['%' . $query . '%']);
		}

		return [
			'status' => '200',
			'users' => $query->result_array()
		];
	}

	public function validate_user_array(array $user_array = null)
	{



		if (strlen($user_array['username']) < 4) {
			$data['error']['username'] = 'Username harus lebih dari 4 karakter';
		}

		if (strlen($user_array['username']) > 80) {
			$data['error']['username'] = 'Username tidak boleh lebih dari 80 karakter';
		}

		if (strlen($user_array['nama_lengkap']) === 0) {
			$data['error']['nama_lengkap'] = 'Nama lengkap kosong';
		}

		if (strlen($user_array['nama_lengkap']) > 120) {
			$data['error']['nama_lengkap'] = 'Nama lengkap tidak boleh lebih dari 120 karakter';
		}

		if ((preg_match('/[0-9]+/', $user_array['password']) !== 1) || (preg_match('/[A-Za-z]+/', $user_array['password']) !== 1)) {
			$data['error']['password'] = 'Password harus minimal terdiri dari satu huruf dan satu angka';
		}

		if ($user_array['password'] === "<PASSWORD>,") {
			$data['error']['password'] = 'K<PASSWORD>';
		}


		if (!filter_var($user_array['email'], FILTER_VALIDATE_EMAIL)) {
			$data['error']['email'] = 'Email tidak valid';
		}


		if (!isset($data['error'])) {
			$data = [];
			array_push($data, $user_array['username']);
			array_push($data, $user_array['nama_lengkap']);
			array_push($data, $user_array['password']);
			array_push($data, $user_array['email']);
		}

		return $data;
	}

	public function add_user(array $user_array = null)
	{
		if ($user_array === null) {
			return [
				'status' => '400',
				'error' => 'Request array is empty'
			];
		}

		$user_array = $this->validate_user_array($user_array);

		if ($user_array['error'] !== null) {
			return [
				'status' => '400',
				'error' => $user_array['error']
			];
		}

		$pre_create = $this->get_users_by_search_query($user_array[0], true);
		if (count($pre_create['users']) > 0) {
			return [
				'status' => '409',
				'error' => 'Resource user is exists',
				'users' => $pre_create['users']
			];
		}

		$this->db->query('INSERT INTO users VALUES (? , ? , ? , ?)', $user_array);

		$response = $this->get_users_by_search_query($user_array[0], true);
		$response['status'] = 201;

		return $response;
	}

	public function put_user(array $user_array = null)
	{
		if ($user_array === null) {
			return [
				'status' => '400',
				'error' => 'Request array is empty'
			];
		}

		$user_array = $this->validate_user_array($user_array);

		if ($user_array['error'] !== null) {
			return [
				'status' => '400',
				'error' => $user_array['error']
			];
		}

		for ($i = 1; $i < 4; $i++) {
			$user_array[$i + 3] = $user_array[$i];
		}

		$this->db->query(
			'INSERT INTO users VALUES (? , ? , ? , ?) ON DUPLICATE KEY UPDATE nama_lengkap = ?, password = ?, email = ?',
			$user_array
		);


		$response = $this->get_users_by_search_query($user_array[0], true);
		$response['status'] = 200;

		return $response;
	}

	public function delete_user(string $username = null)
	{
		if ($username === null) {
			return [
				'status' => '400',
				'error' => 'Request array is empty'
			];
		}

		$this->db->query('DELETE FROM users WHERE username = ?', [$username]);
		$aff = $this->db->affected_rows();

		return [
			'status' => 200,
			'affected_rows' => $aff
		];

	}
}
<file_sep># nyabun-opo-ngaso
hmmmmmmmmmmmmmm
<file_sep><?php
defined('BASEPATH') or exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Student Entry</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="<KEY>"
    crossorigin="anonymous">

</head>

<body>
  <div class="container mt-5">
    <h1>Student Entry</h1>

    <div class="modal fade" id="error-modal" tabindex="-1" role="dialog" aria-labelledby="error-modal-label" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="error-modal-label">Error</h5>
          </div>
          <div class="modal-body">
						<p id="error-msg">
						</p>
					</div>
					<div class="modal-footer">
					<div class="container-fluid">
            <button type="button" class="btn btn-secondary mb-2" data-dismiss="modal">Close</button>
          </div>
					</div>
				</div>
			</div>
		</div>


    <div class="modal fade" id="alter-modal" tabindex="-1" role="dialog" aria-labelledby="alter-modal-label" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="alter-modal-label">Student Form</h5>
          </div>
          <div class="modal-body">
					<div class="container-fluid">
            <form>
              <div class="form-group">
                <label for="id-input">ID</label>
                <input type="text" class="form-control" id="id-input" aria-describedby="id-help" placeholder="Enter ID" autocomplete="off">

              </div>
              <div class="form-group">
                <label for="name-input">Name</label>
                <input type="text" class="form-control" id="name-input" aria-describedby="name-help" placeholder="Enter name" autocomplete="off">

              </div>
              <div class="form-group">
                <label for="email-input">Email</label>
                <input type="email" class="form-control" id="email-input" aria-describedby="email-help" placeholder="Enter email" autocomplete="off">

              </div>
              <div class="form-group">
                <label for="dob-input">Date of Birth</label>
                <input type="date" class="form-control" id="dob-input" aria-describedby="dob-help" placeholder="Enter your birth date" autocomplete="off">

              </div>
              <div class="form-group">
                <label for="address-input">Address</label>
                <textarea class="form-control" id="address-input" aria-describedby="address-help" placeholder="Enter your address" autocomplete="off"></textarea>

              </div>
              <div class="form-group">
                <label for="phone-input">Phone</label>
                <input type="text" class="form-control" id="phone-input" aria-describedby="phone-help" placeholder="Enter your phone" autocomplete="off">

              </div>
              <div class="father-group">
                <label for="father-input">Father Name</label>
                <input type="text" class="form-control" id="father-input" aria-describedby="father-help" placeholder="Enter your father name "
                  autocomplete="off">

              </div>
              <div class="mother-group">
                <label for="mother-input">Mother Name</label>
                <input type="text" class="form-control" id="mother-input" aria-describedby="mother-help" placeholder="Enter your mother name "
                  autocomplete="off">

              </div>
            </form>
						</div>
          </div>
          <div class="modal-footer">
					<div class="container-fluid">
            <button type="button" id="cancel-button" class="btn btn-secondary mb-2" data-dismiss="modal">Discard and close</button>
            <button type="button" id="save-button" class="btn btn-primary mb-2">Save changes</button>
            <button type="button" id="delete-button" class="btn btn-danger mb-2">Delete record</button>
          </div>
					</div>
        </div>
      </div>
    </div>
    <div class="modal fade" id="create-modal" tabindex="-1" role="dialog" aria-labelledby="create-modal-label" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title" id="create-modal-label">Entry Student Form</h5>
            </div>
            <div class="modal-body">
						<div class="container-fluid">
              <form id="create-form">
                <div class="form-group">
                  <label for="id-input-c">ID</label>
                  <input type="text" class="form-control" id="id-input-c" aria-describedby="id-help" placeholder="Enter ID" autocomplete="off">
  
                </div>
                <div class="form-group">
                  <label for="name-input-c">Name</label>
                  <input type="text" class="form-control" id="name-input-c" aria-describedby="name-help" placeholder="Enter name" autocomplete="off">
  
                </div>
                <div class="form-group">
                  <label for="email-input-c">Email</label>
                  <input type="email" class="form-control" id="email-input-c" aria-describedby="email-help" placeholder="Enter email" autocomplete="off">
  
                </div>
                <div class="form-group">
                  <label for="dob-input-c">Date of Birth</label>
                  <input type="date" class="form-control" id="dob-input-c" aria-describedby="dob-help" placeholder="Enter your birth date" autocomplete="off">
  
                </div>
                <div class="form-group">
                  <label for="address-input-c">Address</label>
                  <textarea class="form-control" id="address-input-c" aria-describedby="address-help" placeholder="Enter your address" autocomplete="off"></textarea>
  
                </div>
                <div class="form-group">
                  <label for="phone-input-c">Phone</label>
                  <input type="text" class="form-control" id="phone-input-c" aria-describedby="phone-help" placeholder="Enter your phone" autocomplete="off">
  
                </div>
                <div class="father-group">
                  <label for="father-input-c">Father Name</label>
                  <input type="text" class="form-control" id="father-input-c" aria-describedby="father-help" placeholder="Enter your father name "
                    autocomplete="off">
  
                </div>
                <div class="mother-group">
                  <label for="mother-input-c">Mother Name</label>
                  <input type="text" class="form-control" id="mother-input-c" aria-describedby="mother-help" placeholder="Enter your mother name "
                    autocomplete="off">
  
                </div>
              </form>
							</div>
            </div>
            <div class="modal-footer">
						<div class="container-fluid">
              <button type="button" id="cancel-button-c" class="btn mb-2 btn-secondary" data-dismiss="modal">Discard and close</button>
              <button type="button" id="save-button-c" class="btn mb-2 btn-primary">Create Entry</button>
						</div>
            </div>
          </div>
        </div>
      </div>
    <div>
      <button type="button" id="create-button" class="btn btn-primary mb-4 mt-3">Entry Student</button>
      <br>
      <table class="table table-hover table-responsive-md">
        <thead>
          <tr>
            <th>No</th>
            <th>Nama</th>
            <th>Email</th>
          </tr>
        </thead>
        <tbody id="table-body"></tbody>
      </table>
    </div>
  </div>
  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="<KEY>
    crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="<KEY>"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="<KEY>"
    crossorigin="anonymous"></script>
  <script src="<?php echo base_url(); ?>static/js/main.js"></script>
</body>

</html>
<file_sep><?php

use Restserver\Libraries\REST_Controller;

defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';

class Api extends REST_Controller
{
	public function __construct($config = 'rest')
	{
		parent::__construct($config);
		$this->load->model('users');
	}

	public function index_get()
	{
		$this->response(['w' => 'w']);
	}

	public function users_get()
	{
		$query = $this->query('query');

		if ($query === null) {
			$response = $this->users->get_all_users();
		} else {
			$response = $this->users->get_users_by_search_query($query);
		}

		$this->response($response);
	}

	public function users_post()
	{
		$data = $this->post();
		$response = $this->users->add_user($data);

		$this->response($response);
	}

	public function users_put(string $username = null)
	{
		if ($username === null) {
			$response = ['status' => 400, 'error' => 'URL needs a username i.e (users/{username})'];
		} else {
			$data = $this->put();
			$data['username'] = $username;
			$response = $this->users->put_user($data);
		}

		$this->response($response);
	}

	public function users_delete(string $username = null)
	{
		if ($username === null) {
			$response = ['status' => 400, 'error' => 'URL needs a username i.e (users/{username})'];
		} else {
			$response = $this->users->delete_user($username);
		}

		$this->response($response);
	}
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utsppk2018_15_8518;

/**
 *
 * @author 15.8518
 */
public class MainFrame extends javax.swing.JFrame {

    public javax.swing.JCheckBox getEditCheckBox() {
        return editCheckBox;
    }
   
    private OutputPane outputPane1;
    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        outputPane1 = new OutputPane();
        jScrollPane1.setViewportView(outputPane1);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        usernameTextField = new javax.swing.JTextField();
        namaTextField = new javax.swing.JTextField();
        emailTextField = new javax.swing.JTextField();
        usernameAlert = new javax.swing.JLabel();
        namaAlert = new javax.swing.JLabel();
        passwordAlert = new javax.swing.JLabel();
        konfirmasiPasswordAlert = new javax.swing.JLabel();
        emailAlert = new javax.swing.JLabel();
        simpanButton = new javax.swing.JButton();
        passwordField = new javax.swing.JPasswordField();
        konfirmasiPasswordField = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jLabel6 = new javax.swing.JLabel();
        editCheckBox = new javax.swing.JCheckBox();
        searchTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        findButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(600, 500));

        jLabel1.setText("Username");

        jLabel2.setText("Nama Lengkap");

        jLabel3.setText("Password");

        jLabel4.setText("Konfirmasi Password");

        jLabel5.setText("Email");

        usernameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usernameTextFieldActionPerformed(evt);
            }
        });

        emailTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailTextFieldActionPerformed(evt);
            }
        });

        usernameAlert.setForeground(new java.awt.Color(255, 51, 102));
        usernameAlert.setText("username minimal 4 huruf");

        namaAlert.setForeground(new java.awt.Color(255, 51, 102));
        namaAlert.setText("nama harus diisi");

        passwordAlert.setForeground(new java.awt.Color(255, 51, 102));
        passwordAlert.setText("password <PASSWORD> <PASSWORD>");

        konfirmasiPasswordAlert.setForeground(new java.awt.Color(255, 51, 102));
        konfirmasiPasswordAlert.setText("konfirmasi password tidak cocok");

        emailAlert.setForeground(new java.awt.Color(255, 51, 102));
        emailAlert.setText("format email salah");

        simpanButton.setText("Simpan");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel6.setText("USER CLIENT");

        editCheckBox.setText("Edit jika ada");

        searchTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchTextFieldActionPerformed(evt);
            }
        });

        jLabel7.setText("Cari :");

        findButton.setText("Cari");

        refreshButton.setText("Tampilkan Semua User (Refresh)");
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(editCheckBox))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(simpanButton)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(konfirmasiPasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                                            .addComponent(usernameTextField)
                                            .addComponent(namaTextField)
                                            .addComponent(passwordField)
                                            .addComponent(emailTextField))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(usernameAlert)
                                                .addGap(134, 134, 134))
                                            .addComponent(namaAlert, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(passwordAlert, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(konfirmasiPasswordAlert, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(emailAlert, javax.swing.GroupLayout.Alignment.LEADING)))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(findButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(refreshButton))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 722, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(usernameAlert))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(namaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(namaAlert))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(passwordAlert)
                    .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(konfirmasiPasswordAlert)
                    .addComponent(konfirmasiPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(emailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailAlert))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simpanButton)
                    .addComponent(editCheckBox))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(findButton)
                    .addComponent(refreshButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void usernameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_usernameTextFieldActionPerformed

    private void emailTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailTextFieldActionPerformed

    private void searchTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchTextFieldActionPerformed

    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_refreshButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox editCheckBox;
    private javax.swing.JLabel emailAlert;
    private javax.swing.JTextField emailTextField;
    private javax.swing.JButton findButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel konfirmasiPasswordAlert;
    private javax.swing.JPasswordField konfirmasiPasswordField;
    private javax.swing.JLabel namaAlert;
    private javax.swing.JTextField namaTextField;
    private javax.swing.JLabel passwordAlert;
    private javax.swing.JPasswordField passwordField;
    private javax.swing.JButton refreshButton;
    private javax.swing.JTextField searchTextField;
    private javax.swing.JButton simpanButton;
    private javax.swing.JLabel usernameAlert;
    private javax.swing.JTextField usernameTextField;
    // End of variables declaration//GEN-END:variables

    public javax.swing.JLabel getEmailAlert() {
        return emailAlert;
    }

    public javax.swing.JTextField getEmailTextField() {
        return emailTextField;
    }

    public javax.swing.JLabel getKonfirmasiPasswordAlert() {
        return konfirmasiPasswordAlert;
    }

    public javax.swing.JPasswordField getKonfirmasiPasswordField() {
        return konfirmasiPasswordField;
    }

    public javax.swing.JLabel getNamaAlert() {
        return namaAlert;
    }

    public javax.swing.JTextField getNamaTextField() {
        return namaTextField;
    }

    public javax.swing.JLabel getPasswordAlert() {
        return passwordAlert;
    }

    public javax.swing.JPasswordField getPasswordField() {
        return passwordField;
    }

    public javax.swing.JButton getSimpanButton() {
        return simpanButton;
    }

    public javax.swing.JLabel getUsernameAlert() {
        return usernameAlert;
    }

    public javax.swing.JTextField getUsernameTextField() {
        return usernameTextField;
    }

    public void setUsernameTextField(javax.swing.JTextField usernameTextField) {
        this.usernameTextField = usernameTextField;
    }

    public OutputPane getOutputPane1() {
        return outputPane1;
    }

    public javax.swing.JButton getFindButton() {
        return findButton;
    }

    public javax.swing.JTextField getSearchTextField() {
        return searchTextField;
    }

    public javax.swing.JButton getRefreshButton() {
        return refreshButton;
    }
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utsppk2018_15_8518;


/**
 *
 * @author 15.8518
 */
public class Main {

    public static void main(String args[]) {
        MainFrame mf = new MainFrame();
        RestProxy proxy = RestProxy.getInstance();
        
        GUIController gc = new GUIController(mf, proxy);
        

        
        java.awt.EventQueue.invokeLater(() -> {
            mf.setVisible(true);
        });
    }
}
<file_sep><?php

defined('BASEPATH') or exit('No direct script access allowed');

class Student extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function get_all_students()
	{
		$query = $this->db->query('SELECT * FROM students ORDER BY id');
		if ($this->db->error()['code'] !== 0) {
			return ['error' => 'db_error', 'code' => $this->db->error()['code']];
		}

		return ['students' => $query->result_array()];
	}

	public function get_students_by_id(string $id = null, bool $strict = false)
	{
		if ($id === null || strlen($id) === 0) {
			return ['students' => []];
		}

		if ($strict) {
			$query = $this->db->query('SELECT * FROM students WHERE id = ? ORDER BY id', [$id]);
		} else {
			$query = $this->db->query('SELECT * FROM students WHERE id LIKE ? ORDER BY id', ['%' . $id . '%']);
		}

		if ($this->db->error()['code'] !== 0) {
			return ['error' => 'db_error', 'code' => $this->db->error()['code']];
		}

		return ['students' =>$query->result_array()];

	}

	public function get_students_by_name(string $name = null, bool $strict = false)
	{
		if ($name === null || strlen($name) === 0) {
			return ['students' => []];
		}

		if ($strict) {
			$query = $this->db->query('SELECT * FROM students WHERE name = ? ORDER BY name', [$name]);
		} else {
			$query = $this->db->query('SELECT * FROM students WHERE name LIKE ? ORDER BY name', ['%' . $name . '%']);
		}

		if ($this->db->error()['code'] !== 0) {
			return ['error' => 'db_error', 'code' => $this->db->error()['code']];
		}

		return ['students' =>$query->result_array()];
	}

	public function validate_student(array $student_array = null)
	{
		if ($student_array === null) {
			return [
				'error' => 'student array is null'
			];
		}

		if (preg_match('/(^[\d]{9}$|^[\d]{2}[.][\d]{4}$)/', $student_array['id']) !== 1) {
			$data['error']['id'] = 'Student id is not match (i.e. 16.1111 or 211231233)';
		}

		if (strlen($student_array['name']) === 0) {
			$data['error']['name'] = 'Student name is empty';
		}

		if (strlen($student_array['name']) > 120) {
			$data['error']['name'] = 'Student name should be less than 120 characters';
		}

		if (!filter_var($student_array['email'], FILTER_VALIDATE_EMAIL)) {
			$data['error']['email'] = 'Email is not valid';
		}

		if (preg_match('/^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/', $student_array['dob']) === 1) {
			$re = explode('-', $student_array['dob']);
			if (!checkdate((int)$re[1], (int)$re[2], (int)$re[0])) {
				$data['error']['dob'] = 'Date is not valid or out of range (should be yyyy-mm-dd)';
			}
		} else {
			$data['error']['dob'] = 'Date is not well formed (i.e. yyyy-mm-dd)';
		}

		if (strlen($student_array['address']) < 5) {
			$data['error']['address'] = 'Please provide more detailed address';
		}

		if (preg_match('/^[\d]{3,15}$/', $student_array['phone']) !== 1) {
			$data['error']['phone'] = 'Phone number is not valid (should be 3 - 15 digit)';
		}

		if (strlen($student_array['father_name']) === 0) {
			$data['error']['father_name'] = 'Father name is empty';
		}

		if (strlen($student_array['father_name']) > 120) {
			$data['error']['father_name'] = 'Father name should be less than 120 characters';
		}

		if (strlen($student_array['mother_name']) === 0) {
			$data['error']['mother_name'] = 'Mother name is empty';
		}

		if (strlen($student_array['mother_name']) > 120) {
			$data['error']['mother_name'] = 'Mother name should be less than 120 characters';
		}

		if (!isset($data['error'])) {
			$data = [];
			array_push($data, $student_array['id']);
			array_push($data, $student_array['name']);
			array_push($data, $student_array['email']);
			array_push($data, $student_array['dob']);
			array_push($data, $student_array['address']);
			array_push($data, $student_array['phone']);
			array_push($data, $student_array['father_name']);
			array_push($data, $student_array['mother_name']);

		}

		return $data;
	}

	public function add_student(array $student_array = null)
	{
		$data = $this->validate_student($student_array);
		if (isset($data['error'])) {
			return ['error' => $data['error']];
		}

		$this->db->query('INSERT INTO students VALUES (? , ? , ? , ? , ? , ? , ? , ?)', $data);

		if ($this->db->error()['code'] !== 0) {
			return ['error' => 'db_error', 'code' => $this->db->error()['code']];
		}

		return $this->get_students_by_id($data[0], true);
	}

	public function put_student(array $student_array = null)
	{
		$data = $this->validate_student($student_array);
		if (isset($data['error'])) {
			return ['error' => $data['error']];
		}
		
		for ($i=1; $i < 8; $i++) { 
			$data[$i+7] = $data[$i];
		}

		$this->db->query(
			'INSERT INTO students VALUES (? , ? , ? , ? , ? , ? , ? , ?) ON DUPLICATE KEY '.
			'UPDATE name = ?, email = ?, dob = ?, address = ?, phone = ?, father_name = ?, mother_name = ?', 
		$data);

		if ($this->db->error()['code'] !== 0) {
			return ['error' => 'db_error', 'code' => $this->db->error()['code']];
		}

		return $this->get_students_by_id($data[0], true);
	}

	public function delete_student(string $id = null)
	{
		if ($id === null){
			$aff = 0;			
		}
		else {
			$this->db->query('DELETE FROM students WHERE id = ?', [$id]);
			$aff = $this->db->affected_rows();
		}

		return ['affected_rows' => $aff];

	}
}
