<?php require_once "DB_CUD.php"; require_once "config.php"; $dbCUD = new DB_CUD($config); if (isset($_SESSION["user_email"])) { $userId = $_SESSION["user_id"]; $projects = $dbCUD->getUserProjects($userId); echo "<div class=\"projects\">\n <div class=\"center\">"; echo "<button class=\"add_project\" id=\"add_project_btn\">Add project</button>"; foreach ($projects as $project) { echo "\n <div class=\"project\">\n <div class=\"project_info clearfix\">\n <div class=\"project_name\">\n <h3>" . $project["name"] . "</h3>\n </div>\n <div class=\"project_actions\">\n <input type='hidden' name='project_id' value='" . $project["id"] . "'>\n <a href=\"#\" class=\"update_btn\">Update</a>\n <a href=\"http://{$_SERVER['SERVER_NAME']}/projectmanager/api.php?action=delete_proj&project_id=" . $project["id"] . "\" class=\"delete_btn\">Delete</a>\n </div>\n </div>\n <div class=\"add_tesk clearfix\">\n <form action=\"http://{$_SERVER['SERVER_NAME']}/projectmanager/api.php\">\n <input type=\"hidden\" name=\"action\" value=\"add_task\">\n <input type=\"hidden\" name=\"project_id\" value=\"" . $project["id"] . "\">\n <input type=\"text\" name=\"task_name\" required>\n <button type=\"submit\">Add task</button>\n </form>\n </div>\n <div class=\"tasks\">"; $projectId = $project["id"]; $tasks = $dbCUD->getTask($projectId); foreach ($tasks as $task) { echo "<div class=\"task clearfix\">\n <div class=\"task_name\">" . $task["name"] . "</div>\n <div class=\"task_actions\">\n <input type='hidden' name='task_id' value='" . $task["id"] . "'>\n <a href=\"#\" class=\"update_btn\">Update</a>\n <a href=\"http://{$_SERVER['SERVER_NAME']}/projectmanager/api.php?action=delete_task&task_id=" . $task["id"] . "\" class=\"delete_btn\">Delete</a>\n </div>\n </div>"; } echo "</div>\n </div>"; } echo "</div></div>"; } else { echo "<div class=\"projects\">\n <div class=\"center\">\n </div>\n </div>"; } ?> <div class="modal" id="add_project_modal"> <form class="modal_form" action="http://<?php echo $_SERVER['SERVER_NAME']; ?> /projectmanager/api.php" id="add_project_form"> <h5>Add project</h5> <input type="hidden" name="action" value="add_proj">
$projectName = $_REQUEST["project_name"]; $userId = $_SESSION["user_id"]; $result = $dbCUD->addProject($projectName, $userId); break; case "update_proj": $projectName = $_REQUEST["project_name"]; $projectId = $_REQUEST["project_id"]; $result = $dbCUD->updateProject($projectId, $projectName); break; case "delete_proj": $projectId = $_REQUEST["project_id"]; $result = $dbCUD->deleteProject($projectId); break; case "get_tasks": $projectId = $_REQUEST["project_id"]; $result = $dbCUD->getTask($projectId); break; case "add_task": $projectId = $_REQUEST["project_id"]; $taskName = $_REQUEST["task_name"]; $result = $dbCUD->addTask($projectId, $taskName); break; case "update_task": $taskName = $_REQUEST["task_name"]; $taskId = $_REQUEST["task_id"]; $result = $dbCUD->updateTask($taskId, $taskName); break; case "delete_task": $taskId = $_REQUEST["task_id"]; $result = $dbCUD->deleteTask($taskId); break;