Skip to content

Commit

Permalink
fullcalendar, timeline, profile update, todo statics, regex password …
Browse files Browse the repository at this point in the history
…control
  • Loading branch information
kutluhanazafli committed Jul 11, 2024
1 parent faf8432 commit d1bb185
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 97 deletions.
144 changes: 144 additions & 0 deletions Controller/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,148 @@
exit();
}

}

elseif (route(1) == 'calendar'){

$start = get('start');
$end = get('end');
// TODO Dynamic url for edit
$sql = "
SELECT todo_id, todo_title as title, todo_color as color, todo_start_date as start, todo_end_date as end, CONCAT('/ToDo/todo/edit/',todos.todo_id) as url
FROM todos
WHERE todos.user_id = ?";

if ($start && $end){
$sql .= " && (todo_start_date BETWEEN '$start' AND '$end' OR todo_end_date BETWEEN '$start' AND '$end')";
}

$q = $db->prepare($sql);
$q->execute([get_session('user_id')]);
$array = $q->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($array);

}

if (route(1) == 'profile'){
$post = filter($_POST);

if (!$post['name']){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Please enter your name';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}
if (!$post['surname']){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Please enter your surname';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}
if (!$post['email']){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Please enter your email';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}
$name = $post['name'];
$surname = $post['surname'];
$email = $post['email'];
$id = get_session('user_id');
$q = $db->query("UPDATE users SET user_email = '$email', user_name = '$name', user_surname = '$surname' WHERE users.user_id = '$id' ");

if ($q){

add_session('user_name', $name);
add_session('user_surname', $surname);
add_session('user_fullname', $name.' '.$surname);
add_session('user_email', $email);


$status = 'success';
$title = 'Success!';
$msg = 'Your information has been updated';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();
}else{
$status = 'error';
$title = 'Ops! Error!';
$msg = 'An error occurred while updating your information';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();
}


}
if (route(1) == 'passwordchange'){
$post = filter($_POST);


if (!$post['old_password'] || (get_session('user_password') != hash('SHA512', $post['old_password']))){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Your old password is incorrect.';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}


$lowercase = preg_match('#[a-z]#', $post['password']);
$uppercase = preg_match('#[A-Z]#', $post['password']);
$number = preg_match('#[0-9]#', $post['password']);


if(!$post['password'] || !$lowercase || !$uppercase || !$number || strlen($post['password']) < 6){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Your password must be at least 6 characters long and contain at least one lowercase letter, one uppercase letter, and one number.';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}


if (!$post['password'] || !$post['password_again'] || ($post['password'] != $post['password_again'])){

$status = 'error';
$title = 'Ops! Error!';
$msg = 'Passwords do not match.';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();

}

$p = hash('SHA512', $post['password']);
$id = get_session('user_id');
$upd = $db->query("UPDATE users SET user_password= '$p' WHERE users.user_id = '$id' ");

if ($upd){
add_session('user_password', $p);

$status = 'success';
$title = 'Success!';
$msg = 'Your password has been updated';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();
}else{
$status = 'error';
$title = 'Ops! Error!';
$msg = 'An error occurred while updating your password';
echo json_encode(['status' => $status, 'title' => $title, 'msg' => $msg]);
exit();
}

}
14 changes: 9 additions & 5 deletions Controller/home.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

if (route(0) == 'home') {
if (route(0) == 'home' && !route(1)) {

view('home/home', [
'name' => 'Kutluhan',
'surname' => 'Azaflı',
]);
$return = model('home', [], 'list');

view('home/home', $return['data']);
}

elseif (route(0) == 'home' && route(1) == 'calendar') {

view('home/calendar');

}

3 changes: 3 additions & 0 deletions Controller/profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

view('profile/home');
1 change: 1 addition & 0 deletions Model/auth/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
add_session('user_name', $user['user_name']);
add_session('user_surname', $user['user_surname']);
add_session('user_fullname', $user['user_fullname']);
add_session('user_password', $user['user_password']);
add_session('user_email', $user['user_email']);
add_session('login', true);

Expand Down
35 changes: 35 additions & 0 deletions Model/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

if ($process == 'list') {

$q = $db->prepare('SELECT todos.*, category_title FROM todos
LEFT JOIN categories on categories.category_id = todos.category_id
WHERE todos.user_id = ? && todo_status =? ORDER BY todo_start_date ASC');
$q->execute([get_session('user_id'), 'c']);
$todos = $q->fetchAll(PDO::FETCH_ASSOC);

$q = $db -> prepare("SELECT todo_status, COUNT(todos.todo_id) as total,
(COUNT(todos.todo_id) * 100 / (SELECT COUNT(todo_id) FROM todos WHERE user_id = ?)) as percentage
FROM todos WHERE todos.user_id = ?
GROUP BY todos.todo_status");
$get = $q -> execute([get_session('user_id'), get_session('user_id')]);

if ($q -> rowCount()) {

return [
'success' => true,
'type' => 'success',
'data' => array_merge(['stats' => $q -> fetchAll(PDO::FETCH_ASSOC)], ['continue' => $todos])
];

} else {

return [
'success' => false,
'type' => 'success',
'data' => []
];

}

}
40 changes: 40 additions & 0 deletions View/home/calendar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php view('static/header'); ?>
<div class="wrapper">
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
<ul class="navbar-nav ml-auto">
<li class="nav-item d-none d-sm-inline-block">
<a href="<?= URL . 'logout'; ?>" class="nav-link">Logout</a>
</li>
</ul>
</nav>
<?php view('static/sidebar'); ?>
<div class="content-wrapper p-2">
<div class="content">
<div id="calendar">

</div>
</div>
</div>
<?php view('static/footer'); ?>
</div>

<script src="<?= assets('plugins/jquery/jquery.min.js'); ?>"></script>
<script src="<?= assets('plugins/bootstrap/js/bootstrap.bundle.min.js'); ?>"></script>
<script src="<?= assets('js/adminlte.min.js'); ?>"></script>
<script src="<?= assets('plugins/fullcalendar/locales-all.js'); ?>"></script>
<script src="<?= assets('plugins/fullcalendar/main.js'); ?>"></script>
<script>

document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
locale: '<?= default_lang(); ?>',
events : '<?= url('api/calendar/') ?>'
});
calendar.render();
});

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

0 comments on commit d1bb185

Please sign in to comment.