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 @@ +