2024-07-10 12:37:36 +00:00
|
|
|
<?php
|
2024-07-24 13:12:00 +00:00
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
2024-07-10 12:37:36 +00:00
|
|
|
|
2024-07-24 13:12:00 +00:00
|
|
|
class Form_controller extends CI_Controller
|
|
|
|
{
|
2024-07-10 12:37:36 +00:00
|
|
|
|
2024-07-24 13:12:00 +00:00
|
|
|
public function index_forms($form_id = null)
|
2024-07-19 10:46:18 +00:00
|
|
|
{
|
2024-07-24 13:12:00 +00:00
|
|
|
$this->load->model('Frontend_model');
|
2024-07-19 10:46:18 +00:00
|
|
|
// Check if the user is logged in
|
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
|
|
// If not logged in, redirect to login page
|
|
|
|
redirect('users/login');
|
|
|
|
}
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
// 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'];
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
// Load views and data if user is logged in
|
|
|
|
$this->load->view('templates/header');
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
$data = $this->Frontend_model->getforms();
|
|
|
|
$this->load->view('Tables/list_forms', ['forms' => $data, 'form_title' => $form_title]);
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
$this->load->view('templates/footer');
|
|
|
|
}
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-24 13:12:00 +00:00
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
if (!$this->session->userdata('logged_in')) {
|
2024-07-19 10:46:18 +00:00
|
|
|
// If not logged in, redirect to login page
|
|
|
|
redirect('users/login');
|
|
|
|
}
|
2024-07-24 13:12:00 +00:00
|
|
|
$this->load->model('Frontend_model');
|
|
|
|
$this->Frontend_model->deleteForm($id);
|
|
|
|
$this->session->set_flashdata('status', 'Form data deleted successfully');
|
2024-07-25 12:54:05 +00:00
|
|
|
redirect('drafts');
|
2024-07-24 13:12:00 +00:00
|
|
|
}
|
|
|
|
public function __construct()
|
|
|
|
{
|
2024-07-19 10:46:18 +00:00
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('Updation_model');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the form for editing
|
2024-07-24 13:12:00 +00:00
|
|
|
public function edit_form($form_id)
|
|
|
|
{
|
2024-07-19 10:46:18 +00:00
|
|
|
$data['form'] = $this->Updation_model->get_form($form_id);
|
|
|
|
$data['questions'] = $this->Updation_model->get_questions($form_id);
|
|
|
|
$data['options'] = $this->Updation_model->get_options();
|
|
|
|
|
2024-07-24 13:12:00 +00:00
|
|
|
// $this->load->view('templates/header');
|
2024-07-19 10:46:18 +00:00
|
|
|
$this->load->view('edit_form_view', $data);
|
2024-07-24 13:12:00 +00:00
|
|
|
// $this->load->view('templates/footer');
|
2024-07-19 12:30:57 +00:00
|
|
|
|
2024-07-19 10:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save the edited form
|
2024-07-24 13:12:00 +00:00
|
|
|
public function update_form()
|
|
|
|
{
|
2024-07-22 09:49:37 +00:00
|
|
|
$formData = $this->input->post('formData');
|
2024-07-24 13:12:00 +00:00
|
|
|
|
2024-07-22 09:49:37 +00:00
|
|
|
if (!$formData) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Form data is missing']);
|
|
|
|
return;
|
|
|
|
}
|
2024-07-24 13:12:00 +00:00
|
|
|
|
2024-07-22 09:49:37 +00:00
|
|
|
$form_id = $formData['form_id'];
|
|
|
|
$title = $formData['title'];
|
|
|
|
$description = $formData['description'];
|
|
|
|
$questions = $formData['questions'];
|
2024-07-24 13:12:00 +00:00
|
|
|
|
2024-07-22 09:49:37 +00:00
|
|
|
$this->load->model('Updation_model');
|
|
|
|
$updateStatus = $this->Updation_model->update_form_data($form_id, $title, $description, $questions);
|
2024-07-24 13:12:00 +00:00
|
|
|
|
2024-07-22 09:49:37 +00:00
|
|
|
if ($updateStatus) {
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Form updated successfully']);
|
|
|
|
} else {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Failed to update form data']);
|
|
|
|
}
|
2024-07-19 10:46:18 +00:00
|
|
|
}
|
2024-07-24 13:12:00 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2024-07-10 12:37:36 +00:00
|
|
|
}
|