From b027df8f68dfe326aef6451212fe5b222d68feaf Mon Sep 17 00:00:00 2001 From: torun23 Date: Fri, 19 Jul 2024 18:00:57 +0530 Subject: [PATCH] commit --- application/controllers/Form_controller.php | 34 +++++++++ .../controllers/New_form_controller.php | 1 + .../controllers/Publish_controller.php | 70 +++++++++++-------- application/models/Frontend_model.php | 9 +++ application/views/Tables/draft.php | 53 ++++++++++++++ application/views/Tables/list_forms.php | 10 --- application/views/publish_view.php | 10 +-- application/views/templates/header.php | 2 + assets/css/specific_styles.css | 1 - 9 files changed, 146 insertions(+), 44 deletions(-) create mode 100644 application/views/Tables/draft.php delete mode 100644 assets/css/specific_styles.css diff --git a/application/controllers/Form_controller.php b/application/controllers/Form_controller.php index 05124c3..4b8149b 100644 --- a/application/controllers/Form_controller.php +++ b/application/controllers/Form_controller.php @@ -52,7 +52,10 @@ redirect('default_page'); $data['questions'] = $this->Updation_model->get_questions($form_id); $data['options'] = $this->Updation_model->get_options(); + // $this->load->view('templates/header'); $this->load->view('edit_form_view', $data); + // $this->load->view('templates/footer'); + } // Save the edited form @@ -67,4 +70,35 @@ redirect('default_page'); echo json_encode(['status' => 'success']); } + public function index_forms_draft($form_id = null) { + $this->load->model('Frontend_model'); + + // Check if the user is logged in + if (!$this->session->userdata('logged_in')) { + // If not logged in, redirect to login page + redirect('users/login'); + } + + // Retrieve form title from the forms table using form_id + $form_title = 'Untitled Form'; // Default title + if ($form_id) { + $form = $this->Frontend_model->getFormById($form_id); + if ($form) { + $form_title = $form['title']; + } + } + + // Get the user_id from session + $user_id = $this->session->userdata('user_id'); + + // Load views and data if user is logged in + $this->load->view('templates/header'); + + // Get the forms created by the user + $data = $this->Frontend_model->getforms_draft($user_id); + $this->load->view('Tables/draft', ['forms' => $data, 'form_title' => $form_title]); + + $this->load->view('templates/footer'); + } + } \ No newline at end of file diff --git a/application/controllers/New_form_controller.php b/application/controllers/New_form_controller.php index d8d7495..1364c51 100644 --- a/application/controllers/New_form_controller.php +++ b/application/controllers/New_form_controller.php @@ -20,6 +20,7 @@ class New_form_controller extends CI_Controller { if ($saveStatus) { echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']); + } else { echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']); } diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php index cc1a880..3c58533 100644 --- a/application/controllers/Publish_controller.php +++ b/application/controllers/Publish_controller.php @@ -3,37 +3,51 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class Publish_controller extends CI_Controller { -// Method to publish a form -public function publish_form($form_id) { - // Generate a unique link - if (!$this->session->userdata('logged_in')) { - // If not logged in, redirect to login page - redirect('users/login'); + // Method to publish a form + public function publish_form($form_id) { + // Generate a unique link + if (!$this->session->userdata('logged_in')) { + // If not logged in, redirect to login page + redirect('users/login'); + } + $response_link = base_url("forms/response_preview/" . $form_id); + $this->load->model('Publish_model'); + // Update is_published to 1 and set the response link + $this->Publish_model->update_form($form_id, [ + 'is_published' => 1, + 'response_link' => $response_link + ]); + + // Redirect to the list_user_published_forms function + redirect('Publish_controller/list_user_published_forms'); } - $response_link = base_url("forms/response_preview/" . $form_id); -$this->load->model('Publish_model'); - // Update is_published to 1 and set the response link - $this->Publish_model->update_form($form_id, [ - 'is_published' => 1, - 'response_link' => $response_link - ]); - // Redirect to the list_user_published_forms function - redirect('Publish_controller/list_user_published_forms'); -} + // Method to list published forms of a user + public function list_user_published_forms() { + if (!$this->session->userdata('logged_in')) { + // If not logged in, redirect to login page + redirect('users/login'); + } + $user_id = $this->session->userdata('user_id'); + $this->load->model('Publish_model'); + $data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id); -// Method to list published forms of a user -public function list_user_published_forms() { - if (!$this->session->userdata('logged_in')) { - // If not logged in, redirect to login page - redirect('users/login'); + $this->load->view('templates/header'); + $this->load->view('publish_view', $data); + $this->load->view('templates/footer'); } - $user_id = $this->session->userdata('user_id'); - $this->load->model('Publish_model'); - $data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id); - $this->load->view('templates/header'); - $this->load->view('publish_view', $data); - $this->load->view('templates/footer'); -} + // Method to unpublish a form + public function unpublish_form($form_id) { + if (!$this->session->userdata('logged_in')) { + // If not logged in, redirect to login page + redirect('users/login'); + } + $this->load->model('Publish_model'); + // Update is_published to 0 + $this->Publish_model->update_form($form_id, ['is_published' => 0]); + + // Redirect to the list_user_published_forms function + redirect('Publish_controller/list_user_published_forms'); + } } diff --git a/application/models/Frontend_model.php b/application/models/Frontend_model.php index c9edce3..be11bb7 100644 --- a/application/models/Frontend_model.php +++ b/application/models/Frontend_model.php @@ -27,4 +27,13 @@ class Frontend_model extends CI_Model { $query = $this->db->get_where('forms', ['id' => $form_id]); return $query->row_array(); } + public function getforms_draft($user_id) { + $this->db->where('is_published', 0); // Filter by unpublished forms + $this->db->where('user_id', $user_id); // Filter by user_id + $this->db->order_by('created_on', 'DESC'); // Sort by creation date, newest first + $query = $this->db->get('forms'); + return $query->result(); + } + + } \ No newline at end of file diff --git a/application/views/Tables/draft.php b/application/views/Tables/draft.php new file mode 100644 index 0000000..f813272 --- /dev/null +++ b/application/views/Tables/draft.php @@ -0,0 +1,53 @@ +
+
+
+
+
+ session->flashdata('status')): ?> +
+ session->flashdata('status'); ?> +
+ +

+ List of Forms +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Form_IdTitleDescriptionCreated OnEditDelete
id; ?>title; ?> + description; ?>created_on; ?> + Edit + + Delete +
+
+
+
+
+
\ No newline at end of file diff --git a/application/views/Tables/list_forms.php b/application/views/Tables/list_forms.php index 8692c99..91c6d96 100644 --- a/application/views/Tables/list_forms.php +++ b/application/views/Tables/list_forms.php @@ -22,8 +22,6 @@ Description Created On Status - Edit - Delete @@ -38,14 +36,6 @@ is_published ? 'Published' : 'Draft'); ?> - - - Edit - - - Delete - diff --git a/application/views/publish_view.php b/application/views/publish_view.php index bdd95e5..3be8acb 100644 --- a/application/views/publish_view.php +++ b/application/views/publish_view.php @@ -1,6 +1,6 @@
-
+
session->flashdata('status')): ?> @@ -20,23 +20,23 @@ Form_Id Title Description - Status Response Link + Status - id; ?> + id; ?> title; ?> description; ?> - is_published ? 'Published' : 'Draft'); ?> + response_link; ?> - response_link; ?> + Unpublish diff --git a/application/views/templates/header.php b/application/views/templates/header.php index 9e574b0..ce55d87 100644 --- a/application/views/templates/header.php +++ b/application/views/templates/header.php @@ -26,6 +26,8 @@