This commit is contained in:
torun23 2024-07-19 18:00:57 +05:30
parent 2e5e30aa1e
commit b027df8f68
9 changed files with 146 additions and 44 deletions

View File

@ -52,7 +52,10 @@ redirect('default_page');
$data['questions'] = $this->Updation_model->get_questions($form_id); $data['questions'] = $this->Updation_model->get_questions($form_id);
$data['options'] = $this->Updation_model->get_options(); $data['options'] = $this->Updation_model->get_options();
// $this->load->view('templates/header');
$this->load->view('edit_form_view', $data); $this->load->view('edit_form_view', $data);
// $this->load->view('templates/footer');
} }
// Save the edited form // Save the edited form
@ -67,4 +70,35 @@ redirect('default_page');
echo json_encode(['status' => 'success']); 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');
}
} }

View File

@ -20,6 +20,7 @@ class New_form_controller extends CI_Controller {
if ($saveStatus) { if ($saveStatus) {
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']); echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
} else { } else {
echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']); echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']);
} }

View File

@ -3,15 +3,15 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class Publish_controller extends CI_Controller { class Publish_controller extends CI_Controller {
// Method to publish a form // Method to publish a form
public function publish_form($form_id) { public function publish_form($form_id) {
// Generate a unique link // Generate a unique link
if (!$this->session->userdata('logged_in')) { if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page // If not logged in, redirect to login page
redirect('users/login'); redirect('users/login');
} }
$response_link = base_url("forms/response_preview/" . $form_id); $response_link = base_url("forms/response_preview/" . $form_id);
$this->load->model('Publish_model'); $this->load->model('Publish_model');
// Update is_published to 1 and set the response link // Update is_published to 1 and set the response link
$this->Publish_model->update_form($form_id, [ $this->Publish_model->update_form($form_id, [
'is_published' => 1, 'is_published' => 1,
@ -20,10 +20,10 @@ $this->load->model('Publish_model');
// Redirect to the list_user_published_forms function // Redirect to the list_user_published_forms function
redirect('Publish_controller/list_user_published_forms'); redirect('Publish_controller/list_user_published_forms');
} }
// Method to list published forms of a user // Method to list published forms of a user
public function list_user_published_forms() { public function list_user_published_forms() {
if (!$this->session->userdata('logged_in')) { if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page // If not logged in, redirect to login page
redirect('users/login'); redirect('users/login');
@ -35,5 +35,19 @@ public function list_user_published_forms() {
$this->load->view('templates/header'); $this->load->view('templates/header');
$this->load->view('publish_view', $data); $this->load->view('publish_view', $data);
$this->load->view('templates/footer'); $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');
}
} }

View File

@ -27,4 +27,13 @@ class Frontend_model extends CI_Model {
$query = $this->db->get_where('forms', ['id' => $form_id]); $query = $this->db->get_where('forms', ['id' => $form_id]);
return $query->row_array(); 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();
}
} }

View File

@ -0,0 +1,53 @@
<div class="container">
<div class="row">
<div class="col-md-12 mt-4">
<div class="card">
<div class="card-header">
<?php if ($this->session->flashdata('status')): ?>
<div class="alert alert-success">
<?= $this->session->flashdata('status'); ?>
</div>
<?php endif; ?>
<h3>
List of Forms
</h3>
</div>
<div class="card-body">
<!-- here your table will occur -->
<table id="basetable1" class="table table-bordered">
<thead>
<tr>
<th>Form_Id</th>
<th>Title</th>
<th>Description</th>
<th>Created On</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($forms as $row): ?>
<tr>
<td><?php echo $row->id; ?></td>
<td><a
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->created_on; ?></td>
<td>
<a href="<?php echo base_url('Form_controller/edit_form/' . $row->id); ?>"
class="btn btn-success btn-sm">Edit</a>
</td>
<td>
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -22,8 +22,6 @@
<th>Description</th> <th>Description</th>
<th>Created On</th> <th>Created On</th>
<th>Status</th> <th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -38,14 +36,6 @@
<td> <td>
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?> <?php echo ($row->is_published ? 'Published' : 'Draft'); ?>
</td> </td>
<td>
<a href="<?php echo base_url('Form_controller/edit_form/' . $row->id); ?>" class="btn btn-success btn-sm">Edit</a>
</td>
<td>
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
class="btn btn-danger btn-sm">Delete</a>
</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>

View File

@ -1,6 +1,6 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-12 mt-4 "> <div class="col-md-12 mt-4">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<?php if ($this->session->flashdata('status')): ?> <?php if ($this->session->flashdata('status')): ?>
@ -20,23 +20,23 @@
<th>Form_Id</th> <th>Form_Id</th>
<th>Title</th> <th>Title</th>
<th>Description</th> <th>Description</th>
<th>Status</th>
<th>Response Link</th> <th>Response Link</th>
<th>Status</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($forms as $row): ?> <?php foreach ($forms as $row): ?>
<tr> <tr>
<td><a href="<?php echo base_url('Response_submit/view/' . $row->id); ?>"><?php echo $row->id; ?></td> <td><a href="<?php echo base_url('Response_submit/view/' . $row->id); ?>"><?php echo $row->id; ?></a></td>
<td> <td>
<a href="<?php echo base_url('forms/preview_back/' . $row->id); ?>"><?php echo $row->title; ?></a> <a href="<?php echo base_url('forms/preview_back/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td> </td>
<td><?php echo $row->description; ?></td> <td><?php echo $row->description; ?></td>
<td> <td>
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?> <a href="<?php echo $row->response_link; ?>" target="_blank"><?php echo $row->response_link; ?></a>
</td> </td>
<td> <td>
<a href="<?php echo $row->response_link; ?>" target="_blank"><?php echo $row->response_link; ?></a> <a href="<?php echo base_url('Publish_controller/unpublish_form/' . $row->id); ?>" class="btn btn-danger btn-sm">Unpublish</a>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>

View File

@ -26,6 +26,8 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<?php if ($this->session->userdata('logged_in')): ?> <?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li> <li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
<li><a href="<?php echo base_url(); ?>Form_controller/index_forms_draft">Drafts</a></li>
<?php endif; ?> <?php endif; ?>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">

View File

@ -1 +0,0 @@