commit
This commit is contained in:
parent
2e5e30aa1e
commit
b027df8f68
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
|
@ -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']);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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>
|
|
@ -22,8 +22,6 @@
|
|||
<th>Description</th>
|
||||
<th>Created On</th>
|
||||
<th>Status</th>
|
||||
<th>Edit</th>
|
||||
<th>Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -38,14 +36,6 @@
|
|||
<td>
|
||||
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?>
|
||||
</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>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12 mt-4 ">
|
||||
<div class="col-md-12 mt-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<?php if ($this->session->flashdata('status')): ?>
|
||||
|
@ -20,23 +20,23 @@
|
|||
<th>Form_Id</th>
|
||||
<th>Title</th>
|
||||
<th>Description</th>
|
||||
<th>Status</th>
|
||||
<th>Response Link</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($forms as $row): ?>
|
||||
<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>
|
||||
<a href="<?php echo base_url('forms/preview_back/' . $row->id); ?>"><?php echo $row->title; ?></a>
|
||||
</td>
|
||||
<td><?php echo $row->description; ?></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>
|
||||
<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>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<?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(); ?>Form_controller/index_forms_draft">Drafts</a></li>
|
||||
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
Loading…
Reference in New Issue