<repo_name>PranjanPatel/JrDash<file_sep>/application/views/TODO/register.php
<!DOCTYPE html>
<html>

<head>
    <title>Registration Page</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    <style>
         .form-control{
            width: 43%;
            display: inline;
        }
        form{
            width: 70%;
            margin-left: 30%;
            margin-top: 1%;
        }
        .btn-success{
            margin-left: 7%;
        }
        .name{
            width: 20%;
            margin-left: 3%;
        }
    </style>
</head>

<body>
    
    <form method="post" action="<?php echo site_url('Login/register'); ?>">
    <div class="form-group">
            <label for="pass">Name</label>
            <input type="text" class="form-control name" id="fname" name="fname" placeholder="First Name">
            <input type="text" class="form-control name" id="lname" name="lname" placeholder="Last Name">
        </div>    
    <div class="form-group">
            <label for="user">Username</label>
            <input type="text" class="form-control" id="user" name="userName" placeholder="Username">
        </div>
        <div class="form-group">
            <label for="pass">Password</label>
            <input type="<PASSWORD>" class="form-control" id="pass" name="password" placeholder="<PASSWORD>">
        </div>
        
        <div class="form-group">
            <input type="submit" class="btn btn-success" value="Register">
        </div>
    </form>
</body>

</html><file_sep>/application/views/login_view.php
<!DOCTYPE html>
<html>

<head>
    <title>Login Page</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    <style>
        .form-control{
            width: 65%;
            display: inline;
        }
        form{
            width: 70%;
            margin-left: 20%;
            margin-top: 1%;
        }
        .btn-success{
            margin-left: 7%;
        }
    </style>
</head>

<body>
    
    <form method="post" action="<?php echo site_url('Login/process'); ?>">
        <div class="form-group">
            <label for="user">Username</label>
            <input type="text" class="form-control" id="user" name="user" placeholder="Username">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="<PASSWORD>" class="form-control" id="pass" name="pass" placeholder="<PASSWORD>">
        </div>
        <?php echo isset($error) ? $error : ''; ?>
        <div class="form-group">
            <input type="submit" class="btn btn-success" value="Login">
            <input type="button" class="btn btn-info"  onclick="window.location='<?php echo site_url("Login/openRegister");?>'" value="Register Here">
            
        </div>
    </form>
</body>

</html><file_sep>/application/models/Common_model.php
<?php
class Common_model extends CI_Model{

public function add_data($table,$data){
$this->db->insert($table, $data);
return true;
}

public function update_data($table,$data,$where){
$this->db->where($where);
$this->db->update($table,$data);
return true;
}

public function delete_data($table,$where){
$this->db->where($where);
$this->db->delete($table);
return true;
}

public function get_all_data($table){
$query = $this->db->get($table);
return $result = $query->result_array();
}

public function get_data_by_id($where,$table){
$query = $this->db->get_where($table, $where);
$result = $query->result_array();
return $result;
}

public function custom_fetch_data_with_where($table,$where,$ord_by){
          $this->db->where($where);
          $this->db->order_by($ord_by,'asc');
          $query = $this->db->get($table);
          $result  = $query->result_array();
          return $result;
}
}

?><file_sep>/application/controllers/Home.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

    public function __construct()
        {
        parent::__construct();
        $this->load->model('Common_model');
        // $id = $this->session->userdata('id');
        // $this->load->library('image_lib');
        //     $this->load->library('upload');
        }
	public function index()
	{
        $this->load->view('login_view');
    }
    public function users()
	{
        $this->load->view('login_view');
    }
     public function todo_add()
    {
        $data = array(
                'name' => $this->input->post('name'),
                'is_complete' => '0',
                'status' => 'active',
                'created_by' => $this->session->userdata('id')
            );
            $result = $this->Common_model->add_data('tb_todo',$data);
                    $msg = '';
        if ($result) {
        $msg .= 'Added in Todo list.';
        } else {
        $msg .= 'ERROR! Try Again';
        }
        return $msg;
        exit();
    }
    
    public function todo_delete($id = 0)
    {
            $this->Common_model->delete_data('tb_todo',array('id'=>$id));
            exit();
    }
    public function todo_update($id = 0,$isComplete = 0)
    {
        if($isComplete == 1){
            $this->Common_model->update_data('tb_todo',array('is_complete'=>0),array('id'=>$id));
        } else {
            $this->Common_model->update_data('tb_todo',array('is_complete'=>1),array('id'=>$id));
        }
            exit();
    }
    public function get_all_todoes()
    {
        $todoes = $this->Common_model->get_data_by_id(array('created_by' => $this->session->userdata('id')),'tb_todo');
        $html = '';
      
        foreach($todoes as $todo){
        $html .= '<tr>';
        $html .= "<td>".$todo['name']."</td>";
        $html .= "<td>";
        if($todo['is_complete'] == 1){
            $html .= "<a href='javascript:void(0)' onClick='updateTodo(".$todo['id'].",".$todo['is_complete'].")' id='deleteTodo'><i class='fa fa-times' aria-hidden='true'></i></a>";
        } else {
            $html .= "<a href='javascript:void(0)' onClick='updateTodo(".$todo['id'].",".$todo['is_complete'].")' id='deleteTodo'><i class='fa fa-check' aria-hidden='true'></i></a>";
        }
        $html .= "</td>";
        $html .= "<td>";
        $html .= "<a href='javascript:void(0)' onClick='deleteTodo(".$todo['id'].")' id='deleteTodo'><i class='fa fa-minus-circle' aria-hidden='true'></i></a>";
        $html .= "</td>";
        
        $html .= '</tr>';
        }

        echo $html;
    }
    public function get_all_notes(){
        $notes = $this->Common_model->get_data_by_id(array('created_by' => $this->session->userdata('id')),'tb_notes');
        $html = '';
        foreach($notes as $note){
            $html .= '<tr>';
            // $html .= "<td>".$note['title']."</td>";
            $html .= "<td>";
            $html .= "<a href='javascript:void(0)' onClick='viewDescription(".$note['id'].")' id='editNote'>".$note['title']."</a>";
            $html .= "</td>";
            $html .= "<td>";
            $html .= "<a href='javascript:void(0)' onClick='updateNote(".$note['id'].")' id='editNote'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></a>";
            $html .= "</td>";
            $html .= "<td>";
            $html .= "<a href='javascript:void(0)' onClick='deleteNote(".$note['id'].")' id='deleteNote'><i class='fa fa-minus-circle' aria-hidden='true'></i></a>";
            $html .= "</td>";
            $html .= "</tr>";
            $html .= "<tr id='".$note['id']."DescHide' style='display:none'>";
            $html .= "<td colspan='3' style='display:block;'>";
            $html .= "<input type='text' class='form-control' disabled id='".$note['id']."Note' value='".$note['description']."'/>";
            $html .= "</td>";
            $html .= '</tr>';
            $html .= "<tr id='".$note['id']."Descedit' style='display:none'>";
            $html .= "<td colspan='3' style='display:block;'>";
            $html .= "<form method='post' id='notes_form_edit'>";
            $html .= "<input type='text' class='form-control' name='".$note['id']."titleEdit' id='".$note['id']."titleEdit' value='".$note['title']."'/>";
            $html .= "<textarea rows='3' name='".$note['id']."descriptionEdit' id='".$note['id']."descriptionEdit' style='width: 100%;'>".$note['description']."</textarea>";
            $html .= "<input type='button' onClick='saveUpdateNote(".$note['id'].")' class='btn btn-success' value='Save'>";
            $html .= "<input type='button' onClick='hideNoteEdit(".$note['id'].")' class='btn btn-default' value='Cancel'>";
            $html .= "</form>";
            $html .= "</td>";
            $html .= '</tr>';
            }
    
            echo $html;
    }
    public function note_delete($id = 0){
        $this->Common_model->delete_data('tb_notes',array('id'=>$id));
            exit();
    }
    public function note_add()
    {
        $data = array(
                'title' => $this->input->post('title'),
                'description' => $this->input->post('description'),
                'status' => 'active',
                'created_by' => $this->session->userdata('id')
            );
            $result = $this->Common_model->add_data('tb_notes',$data);
                    $msg = '';
        if ($result) {
        $msg .= 'Added in Todo list.';
        } else {
        $msg .= 'ERROR! Try Again';
        }
        return $msg;
        exit();
    }
    public function updateNote($id = 0){
        $data = array(
            'title' => $this->input->post($id.'titleEdit'),
            'description' => $this->input->post($id.'descriptionEdit'),
            'status' => 'active'
        );
        $result = $this->Common_model->update_data('tb_notes',$data,array('id'=>$id));
                $msg = '';
    if ($result) {
    $msg .= 'Added in Todo list.';
    } else {
    $msg .= 'ERROR! Try Again';
    }
    return $msg;
    exit();
    }
}
<file_sep>/application/views/TODO/home.php
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Home</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <style>
    .row {
    margin-right: 0px;
    margin-left: 0px;
    }
    
    .table>tbody>tr>td{
      border-top: none;
      border-bottom: 1px solid black;
    }
    .todoHeader{
      height: 35px;
      margin-left: -2px;
      margin-bottom: 10px;
      background: #3F7CB1;
      line-height: 2.428571;
    }
    .todoBox{
      background: lightblue;
      height: 100%;
      border-radius: 7px;
    }
    .notesHeader{
      height: 35px;
      margin-left: -2px;
      margin-bottom: 10px;
      background: #F7F5F9;
      line-height: 2.428571;
    }
    .notesBox{
      background: lightblue;
      height: 100%;
      border-radius: 7px;
    }
    .hide{
      -moz-animation: cssAnimation 0s ease-in 5s forwards;
    /* Firefox */
    -webkit-animation: cssAnimation 0s ease-in 5s forwards;
    /* Safari and Chrome */
    -o-animation: cssAnimation 0s ease-in 5s forwards;
    /* Opera */
    animation: cssAnimation 0s ease-in 5s forwards;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
    }
  </style>
</head>

<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">jrDash</a>
    </div>
    <ul class="nav navbar-nav">
      <li class="active"><a href="#">Dashboard</a></li>
      <li><a href="#">User</a></li>
      <li><a href="<?php echo site_url('Login/logout'); ?>">Logout</a></li>
    </ul>
  </div>
</nav>
  <div class="container" >
    <div id="divHide" style="background: #E7F5E5;padding: 4px;display: none;">
      <ul id="popupUl">
        <li id="addTodo" style="display: none;">Added in To-do list.</li>
        <li id="markTodo" style="display: none;">Todo List Marked Completed.</li>
        <li id="addNote" style="display: none;">Added in Note list</li>
        <li id="updateNote" style="display: none;">Success</li>
      </ul>
    </div>
    <div class="col-md-6 todoBox" style="background:#4C9ED1;height: 100%;margin-top: 10px;  ">
      <div class="todoHeader">
        <strong style="color: white;margin-left: 10px;">TODO</strong>
      </div>
      <div class="row">
        <form method="post" id="todo_form">

          <div class="form-group">
            <div class="row" style="display: flex;">
              <input type="text" class="form-control" id="name" placeholder="Create New Todo Item" name="name">
              <button type="button" id="createTodo" name='createTodo' class="btn btn-success">Create</button>
            </div>
          </div>
        </form>
      </div>
      <div class="row">
        <table class="table">
          <tbody id="tbdoyTodo">
          </tbody>
        </table>
      </div>
    </div>

      <!-- ------------------------------------- Notes ------------------------- -->

      <div class="col-md-6 notesBox" style="background:#F4F2F5;height: 100%;margin-top: 10px;  ">
      <div class="notesHeader">
        <strong style="color: black;margin-left: 10px;">Notes</strong>
      </div>
      <div class="row">
        <form method="post" id="notes_form">

          <div class="form-group">
            <div class="row" style="display: flex;">
              <input type="text" class="form-control" id="title" placeholder="Note Title" name="title">
              <button type="button" id="createNotes" name='createNotes' class="btn btn-success">Create</button>
            </div>
            <div>
              <textarea rows="3" id="description" name="description" style="width: 100%;"></textarea>
            </div>
          </div>
        </form>
      </div>
      <div class="row">
        <table class="table" id="notesTable">
          <tbody id="tbdoyNotes">
          </tbody>
        </table>
      </div>
    </div>
  </div>
</body>
<script>
    $(document).ready(function() {
    getData();
    getNotes();
    
  });

  $("#createTodo").click(function() {
    var form = $("#todo_form").serialize();
    $.ajax({
      url: '<?php echo base_url('home/todo_add') ?>',
      data: form,
      method: 'POST',
      success: function(data) {
        $('#success_msg').alert();
        $('#name').val('');
        $("#divHide").show().delay(2500).fadeOut();
        $("#addTodo").show().delay(2000).fadeOut();
        getData();
      },
      error: function() {
        console.log("ERROR");
      }
    });
  });

  function getData() {
    $.ajax({
      url: '<?php echo base_url('home/get_all_todoes') ?>',
      method: 'GET',
      success: function(data) {
        $('#tbdoyTodo').html(data);
      },
      error: function() {
        console.log("ERROR");
      }
    });
  }

  function deleteTodo(id) {
    $.ajax({
      url: '<?php echo base_url('home/todo_delete/') ?>' + id,
      method: 'POST',
      success: function(data) {
        getData();
      },
      error: function() {
        console.log("ERROR");
      }
    });
  }

  function updateTodo(id, isComplete) {

    $.ajax({
      url: '<?php echo base_url('home/todo_update/') ?>' + id + '/' + isComplete,
      method: 'POST',
      success: function(data) {
        getData();
        $("#divHide").show().delay(2500).fadeOut();
       $("#markTodo").show().delay(2000).fadeOut();
        
      },
      error: function() {
        console.log("ERROR");
      }
    });
  }
  function getNotes() {
    $.ajax({
      url: '<?php echo base_url('home/get_all_notes') ?>',
      method: 'GET',
      success: function(data) {
        $('#tbdoyNotes').html(data);
      },
      error: function() {
        console.log("ERROR");
      }
    });
  }
  function deleteNote(id){
    $.ajax({
      url: '<?php echo base_url('home/note_delete/') ?>' + id,
      method: 'POST',
      success: function(data) {
        getNotes();
      },
      error: function() {
        console.log("ERROR");
      }
    });
  }
  $("#createNotes").click(function() {
    var form = $("#notes_form").serialize();
    $.ajax({
      url: '<?php echo base_url('home/note_add') ?>',
      data: form,
      method: 'POST',
      success: function(data) {
        $('#success_msg').alert();
        getNotes();
        $("#divHide").show().delay(2500).fadeOut();
       $("#addNote").show().delay(2000).fadeOut();
      },
      error: function() {
        console.log("ERROR");
      }
    });
  });
  function viewDescription(id){
    $('#'+id+'DescHide').toggle();
  }
  function updateNote(id){
    $('#'+id+'Descedit').show();
  }
  function hideNoteEdit(id){
    $('#'+id+'Descedit').hide();
  }
  function saveUpdateNote(id){
    var form = $("#notes_form_edit").serialize();
    $.ajax({
      url: '<?php echo base_url('home/updateNote/') ?>'+ id,
      data: form,
      method: 'POST',
      success: function(data) {
        $('#success_msg').alert();
        $("#divHide").show().delay(2500).fadeOut();
       $("#updateNote").show().delay(2000).fadeOut();
        getNotes();

      },
      error: function() {
        console.log("ERROR");
      }
    });
  }
</script>

</html><file_sep>/application/controllers/Login.php

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

class Login extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Common_model');
        $this->load->library('session');

        // $id = $this->session->userdata('id');
        // $this->load->library('image_lib');
        //     $this->load->library('upload');
    }
    public function index()
    {
        $this->load->view('login_view');
    }
    public function process()
    {
        $user = $this->input->post('user');
        $pass = $this->input->post('pass');
        $result =  $this->Common_model->get_data_by_id(array('user_name' => $user), "tb_user");
        if (!empty($result)) {
            if (($user == $result[0]['user_name'] && md5($pass) == $result[0]['password'])) {
                //declaring session  
                $this->session->set_userdata(array('user' => $user,'id'=>$result[0]['user_id']));
                $this->load->view('TODO/home');
            } else {
                $data['error'] = 'Your Account is Invalid';
                $this->load->view('login_view', $data);
            }
        } else {
            $data['error'] = 'Your Account is Invalid';
            $this->load->view('login_view', $data);
        }
    }
    public function logout()
    {
        //removing session  
        $this->session->unset_userdata('user','id');
        redirect("Login");
    }

    public function openRegister()
    {
        $this->load->view('TODO/register');
    }

    public function register()
    {
        $pass = md5($this->input->post('password'));
        $data = array(
            'first_name' => $this->input->post('fname'),
            'last_name' => $this->input->post('fname'),
            'user_name' => $this->input->post('userName'),
            'password' => $<PASSWORD>
        );
        $result = $this->Common_model->add_data('tb_user', $data);
        $msg = '';
        if ($result) {
            $this->load->view('login_view');
        } else {
            $msg .= 'ERROR! Try Again';
        }
        return $msg;
        exit();
    }
}
?> 