2024-07-16 12:29:59 +00:00
|
|
|
<?php
|
|
|
|
|
2024-08-09 12:04:48 +00:00
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-08-09 12:04:48 +00:00
|
|
|
class Publish_controller extends CI_Controller
|
|
|
|
{
|
2024-07-19 12:30:57 +00:00
|
|
|
// Method to publish a form
|
2024-08-09 12:04:48 +00:00
|
|
|
public function publish_form($form_id)
|
|
|
|
{
|
2024-07-19 12:30:57 +00:00
|
|
|
// Generate a unique link
|
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
|
|
// If not logged in, redirect to login page
|
|
|
|
redirect('users/login');
|
|
|
|
}
|
2024-07-23 12:54:27 +00:00
|
|
|
$response_link = base_url("response_preview/" . $form_id);
|
2024-07-19 12:30:57 +00:00
|
|
|
$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
|
2024-07-22 12:39:47 +00:00
|
|
|
redirect('published_forms');
|
2024-07-19 10:46:18 +00:00
|
|
|
}
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 12:30:57 +00:00
|
|
|
// Method to list published forms of a user
|
2024-08-09 12:04:48 +00:00
|
|
|
public function list_user_published_forms()
|
|
|
|
{
|
2024-07-19 12:30:57 +00:00
|
|
|
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);
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-19 12:30:57 +00:00
|
|
|
$this->load->view('templates/header');
|
|
|
|
$this->load->view('publish_view', $data);
|
2024-08-09 12:04:48 +00:00
|
|
|
// $this->load->view('templates/footer');
|
2024-07-19 10:46:18 +00:00
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-16 12:29:59 +00:00
|
|
|
|
2024-07-19 12:30:57 +00:00
|
|
|
// Method to unpublish a form
|
2024-08-09 12:04:48 +00:00
|
|
|
public function unpublish_form($form_id)
|
|
|
|
{
|
2024-07-19 12:30:57 +00:00
|
|
|
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
|
2024-07-26 12:41:46 +00:00
|
|
|
$this->Publish_model->update_form($form_id, ['is_responsive' => 1]);
|
2024-07-19 12:30:57 +00:00
|
|
|
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
// redirect('published_forms');
|
2024-07-19 12:30:57 +00:00
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
public function toggle_responsive($form_id)
|
|
|
|
{
|
2024-07-26 12:41:46 +00:00
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
|
|
redirect('users/login');
|
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
$is_responsive = $this->input->post('is_responsive', true);
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
if ($is_responsive === null) {
|
|
|
|
log_message('error', 'is_responsive is null');
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Invalid data received']);
|
|
|
|
return;
|
|
|
|
}
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
log_message('info', 'is_responsive received: ' . $is_responsive);
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
$this->load->model('Publish_model');
|
|
|
|
$update_result = $this->Publish_model->update_form($form_id, ['is_responsive' => $is_responsive]);
|
2024-08-09 12:04:48 +00:00
|
|
|
|
2024-07-26 12:41:46 +00:00
|
|
|
if ($update_result) {
|
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
} else {
|
|
|
|
log_message('error', 'Failed to update is_responsive');
|
|
|
|
echo json_encode(['success' => false, 'message' => 'Failed to update']);
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 12:29:59 +00:00
|
|
|
}
|