google_forms/application/controllers/Forms.php

106 lines
3.2 KiB
PHP
Raw Normal View History

2024-07-16 12:29:59 +00:00
<?php
2024-08-02 12:21:50 +00:00
2024-07-16 12:29:59 +00:00
defined('BASEPATH') or exit('No direct script access allowed');
class Forms extends CI_Controller
{
public function preview($form_id)
{
2024-07-19 10:46:18 +00:00
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
2024-08-02 12:24:05 +00:00
2024-07-16 12:29:59 +00:00
// Load the model that handles the form data
$this->load->model('preview_model');
// Fetch the form details
$form = $this->preview_model->get_form($form_id);
// Fetch the questions for the form
$questions = $this->preview_model->get_questions($form_id);
// Fetch the options for each question
foreach ($questions as &$question) {
$question->options = $this->preview_model->get_options($question->id);
}
// Pass the data to the view
$data['form'] = $form;
$data['questions'] = $questions;
2024-08-02 12:21:50 +00:00
$this->load->view('templates/header');
2024-07-19 10:46:18 +00:00
2024-07-16 12:29:59 +00:00
$this->load->view('form_preview', $data);
2024-07-19 10:46:18 +00:00
$this->load->view('templates/footer');
2024-07-16 12:29:59 +00:00
}
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
public function response_preview($form_id)
{
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page with form_id as a parameter
redirect('users/login/' . $form_id);
}
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Load the model that handles the form data
$this->load->model('preview_model');
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Fetch the form details
$form = $this->preview_model->get_form($form_id);
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Check if the form is responsive
if ($form->is_responsive == 0) {
// Pass a message to the view
$data['message'] = "This form is not accepting responses.";
2024-07-22 09:49:37 +00:00
$this->load->view('response_submit', $data);
2024-07-26 12:41:46 +00:00
return;
2024-07-17 12:21:51 +00:00
}
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Fetch the questions for the form
$questions = $this->preview_model->get_questions($form_id);
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Fetch the options for each question
foreach ($questions as &$question) {
$question->options = $this->preview_model->get_options($question->id);
}
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
// Pass the data to the view
$data['form'] = $form;
$data['questions'] = $questions;
2024-08-02 12:21:50 +00:00
2024-07-26 12:41:46 +00:00
$this->load->view('response_submit', $data);
}
2024-08-02 12:21:50 +00:00
public function preview_back($form_id)
{
2024-07-19 10:46:18 +00:00
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
2024-08-02 12:21:50 +00:00
2024-07-19 10:46:18 +00:00
// Load the model that handles the form data
$this->load->model('preview_model');
2024-08-02 12:21:50 +00:00
2024-07-19 10:46:18 +00:00
// Fetch the form details
$form = $this->preview_model->get_form($form_id);
2024-08-02 12:21:50 +00:00
2024-07-22 09:49:37 +00:00
// Fetch the questions for the form including 'is_required'
2024-07-19 10:46:18 +00:00
$questions = $this->preview_model->get_questions($form_id);
2024-08-02 12:21:50 +00:00
2024-07-19 10:46:18 +00:00
// Fetch the options for each question
foreach ($questions as &$question) {
$question->options = $this->preview_model->get_options($question->id);
}
2024-08-02 12:21:50 +00:00
// / Pass the data to the view
2024-07-19 10:46:18 +00:00
$data['form'] = $form;
$data['questions'] = $questions;
2024-08-02 12:21:50 +00:00
2024-07-22 09:49:37 +00:00
$this->load->view('templates/header');
2024-07-19 10:46:18 +00:00
$this->load->view('form_preview_back', $data);
$this->load->view('templates/footer');
2024-08-02 12:21:50 +00:00
// $this->load->view('templates/footer');
2024-07-19 10:46:18 +00:00
}
2024-07-16 12:29:59 +00:00
}