This commit is contained in:
RameshT 2024-07-24 18:42:00 +05:30
parent a6c68f3598
commit 7156b3e8d2
21 changed files with 401 additions and 336 deletions

View File

@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://localhost/google_forms';
$config['base_url'] = 'http://192.168.2.110/google_forms';
/*
|--------------------------------------------------------------------------

View File

@ -10,7 +10,6 @@ $route['default_controller'] = 'Form_controller/index_forms';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['start'] = 'Form_controller/index_forms';
// $route['new_form'] = 'home/create_form';
$route['title_desc'] = 'homepage/title';
$route['forms/delete/(:any)'] = 'Form_controller/delete/$1';
$route['home'] = 'Form_controller/index_forms';
@ -26,4 +25,3 @@ $route['response_preview/(:num)'] = 'forms/response_preview/$1';
$route['title'] = 'homepage/title';
// $route['designform'] = 'homepage/design_form';

View File

@ -1,11 +1,12 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');
class Form_controller extends CI_Controller {
class Form_controller extends CI_Controller
{
public function index_forms($form_id = null)
public function index_forms($form_id = null)
{
$this->load->model('Frontend_model');
$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
@ -30,92 +31,91 @@ class Form_controller extends CI_Controller {
$this->load->view('templates/footer');
}
public function delete($id)
{
if (!$this->session->userdata('logged_in')) {
public function delete($id)
{
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
$this->load->model('Frontend_model');
$this->Frontend_model->deleteForm($id);
$this->session->set_flashdata('status','Form data deleted successfully');
redirect('home');
}
public function __construct() {
$this->load->model('Frontend_model');
$this->Frontend_model->deleteForm($id);
$this->session->set_flashdata('status', 'Form data deleted successfully');
redirect('home');
}
public function __construct()
{
parent::__construct();
$this->load->model('Updation_model');
}
// Load the form for editing
public function edit_form($form_id) {
public function edit_form($form_id)
{
$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();
// $this->load->view('templates/header');
// $this->load->view('templates/header');
$this->load->view('edit_form_view', $data);
// $this->load->view('templates/footer');
// $this->load->view('templates/footer');
}
// Save the edited form
public function update_form() {
public function update_form()
{
$formData = $this->input->post('formData');
if (!$formData) {
echo json_encode(['status' => 'error', 'message' => 'Form data is missing']);
return;
}
$form_id = $formData['form_id'];
$title = $formData['title'];
$description = $formData['description'];
$questions = $formData['questions'];
$this->load->model('Updation_model');
$updateStatus = $this->Updation_model->update_form_data($form_id, $title, $description, $questions);
if ($updateStatus) {
echo json_encode(['status' => 'success', 'message' => 'Form updated successfully']);
} else {
echo json_encode(['status' => 'error', 'message' => 'Failed to update form data']);
}
}
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');
}
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

@ -10,12 +10,12 @@ class Frontend_model extends CI_Model {
// Ensure user_id is set
if (!$user_id) {
return []; // Return an empty array if user_id is not available
return [];
}
// Filter forms by user_id and order by created_at in descending order
$this->db->where('user_id', $user_id); // Assuming 'user_id' is the column name in the 'forms' table
$this->db->order_by('created_at', 'DESC'); // Order by created_at column, most recent first
$this->db->where('user_id', $user_id);
$this->db->order_by('created_at', 'DESC');
$query = $this->db->get('forms');
return $query->result(); // Return the result as an array of objects
@ -30,9 +30,9 @@ class Frontend_model extends CI_Model {
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_at', 'DESC'); // Sort by creation date, newest first
$this->db->where('is_published', 0);
$this->db->where('user_id', $user_id);
$this->db->order_by('created_at', 'DESC');
$query = $this->db->get('forms');
return $query->result();
}

View File

@ -25,7 +25,7 @@ class New_form_model extends CI_Model {
if (!empty($option)) { // Avoid inserting empty options
$optionData = [
'question_id' => $questionId,
'option_text' => $option // Ensure column name matches database schema
'option_text' => $option
];
// Insert option into options table
$this->db->insert('options', $optionData);

View File

@ -1,39 +1,45 @@
<?php
class Response_model extends CI_Model {
// 888888888888888888888
class Response_model extends CI_Model
{
// 888888888888888888888
public function insert_response($data) {
public function insert_response($data)
{
$this->db->insert('responses', $data);
return $this->db->insert_id();
}
public function insert_response_answer($data) {
public function insert_response_answer($data)
{
$this->db->insert('response_answers', $data);
}
public function get_form($form_id) {
public function get_form($form_id)
{
$this->db->where('id', $form_id);
$query = $this->db->get('forms');
return $query->row();
}
// 888888888888888888888
public function get_questions($form_id) {
public function get_questions($form_id)
{
$this->db->where('form_id', $form_id);
$query = $this->db->get('questions');
return $query->result();
}
public function get_options($question_id) {
public function get_options($question_id)
{
$this->db->where('question_id', $question_id);
$query = $this->db->get('options');
return $query->result();
}
// 888888888888888888888
public function get_responses_by_form($form_id) {
public function get_responses_by_form($form_id)
{
$this->db->select('responses.id as response_id, responses.submitted_at, users.username');
$this->db->from('responses');
$this->db->join('users', 'responses.user_id = users.id');
@ -48,16 +54,17 @@ class Response_model extends CI_Model {
return $responses;
}
public function get_answers_by_response_id($response_id) {
public function get_answers_by_response_id($response_id)
{
$this->db->select('response_answers.question_id, response_answers.answered_text');
$this->db->from('response_answers');
$this->db->where('response_answers.response_id', $response_id);
$query = $this->db->get();
return $query->result();
}
// 888888888888888888888
public function get_responses($form_id) {
public function get_responses($form_id)
{
$this->db->where('form_id', $form_id);
$query = $this->db->get('responses');
return $query->result();
@ -65,7 +72,8 @@ class Response_model extends CI_Model {
// Method to get response details
public function get_response($response_id) {
public function get_response($response_id)
{
$this->db->select('responses.*, users.email');
$this->db->from('responses');
$this->db->join('users', 'responses.user_id = users.id'); // Assuming 'user_id' is the foreign key in 'responses'
@ -73,10 +81,11 @@ class Response_model extends CI_Model {
$query = $this->db->get();
return $query->row();
}
// Method to get questions and answers for a response
public function get_questions_and_answers($response_id) {
public function get_questions_and_answers($response_id)
{
$this->db->select('questions.id AS question_id, questions.text AS question_text, response_answers.answered_text, users.email');
$this->db->from('questions');
$this->db->join('response_answers', 'questions.id = response_answers.question_id');
@ -86,9 +95,10 @@ class Response_model extends CI_Model {
$query = $this->db->get();
return $query->result();
}
public function get_form_by_response($response_id) {
public function get_form_by_response($response_id)
{
$this->db->select('forms.title, forms.description');
$this->db->from('forms');
$this->db->join('responses', 'forms.id = responses.form_id');

View File

@ -1,34 +1,39 @@
<?php
class Updation_model extends CI_Model {
class Updation_model extends CI_Model
{
public function get_form($form_id) {
public function get_form($form_id)
{
$this->db->where('id', $form_id);
$query = $this->db->get('forms');
return $query->row_array();
}
public function get_questions($form_id) {
public function get_questions($form_id)
{
$this->db->where('form_id', $form_id);
$this->db->order_by('id', 'ASC');
$query = $this->db->get('questions');
return $query->result_array();
}
public function get_options() {
public function get_options()
{
$query = $this->db->get('options');
return $query->result_array();
}
public function update_form_data($form_id, $title, $description, $questions) {
public function update_form_data($form_id, $title, $description, $questions)
{
$this->db->trans_start();
// Update form title and description
$this->db->where('id', $form_id);
$this->db->update('forms', ['title' => $title, 'description' => $description]);
// Update questions
$this->db->where('form_id', $form_id);
$this->db->delete('questions');
foreach ($questions as $question) {
$question_data = [
'form_id' => $form_id,
@ -38,7 +43,7 @@ class Updation_model extends CI_Model {
];
$this->db->insert('questions', $question_data);
$question_id = $this->db->insert_id();
if (isset($question['options'])) {
foreach ($question['options'] as $option_text) {
$option_data = [
@ -49,25 +54,26 @@ class Updation_model extends CI_Model {
}
}
}
$this->db->trans_complete();
return $this->db->trans_status();
}
private function update_question_options($question_id, $options) {
private function update_question_options($question_id, $options)
{
// Fetch existing options for this question
$existing_options = $this->db->where('question_id', $question_id)->get('options')->result_array();
$existing_option_texts = array_column($existing_options, 'option_text');
// Insert or update options
foreach ($options as $option_text) {
if (in_array($option_text, $existing_option_texts)) {
// Option already exists, no need to insert
continue;
}
// Insert new option
$option_data = [
'question_id' => $question_id,
@ -75,7 +81,7 @@ class Updation_model extends CI_Model {
];
$this->db->insert('options', $option_data);
}
// Delete options that are no longer present
$options_to_delete = array_diff($existing_option_texts, $options);
if (!empty($options_to_delete)) {
@ -84,8 +90,8 @@ class Updation_model extends CI_Model {
$this->db->delete('options');
}
}
}
?>
?>

View File

@ -50,7 +50,7 @@ Drafts
class="btn btn-danger btn-sm" style=" background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Delete</a>
</td>
<td>
<a href="<?php echo base_url('form_preview/' . $row->id); ?>">
<a href="<?php echo base_url('publish/' . $row->id); ?>">
<i class="fas fa-eye"></i> <!-- Eye icon -->
</a>
</td>

View File

@ -42,7 +42,7 @@
<th>Description</th>
<th>Created On</th>
<th>Status</th>
<th>Preview</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
@ -52,13 +52,13 @@
<tr class="<?php echo ($row->is_published ? '' : 'draft-row'); ?>">
<td><?php echo $serialNumber++; ?></td>
<td class="title-column">
<?php echo $row->title; ?>
<a href="<?php echo base_url('publish/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->created_at; ?></td>
<td><?php echo ($row->is_published ? 'Published' : 'Draft'); ?></td>
<td>
<a href="<?php echo base_url('form_preview/' . $row->id); ?>">
<a href="<?php echo base_url('responses/' . $row->id); ?>">
<i class="fas fa-eye"></i> <!-- Eye icon -->
</a>
</td>

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -12,36 +13,38 @@
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-custom">
<div class="container">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>">Google Forms</a>
</div>
<?php endif; ?>
<div id="navbar">
<ul class="nav navbar-nav left">
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>published_forms">Published Forms</a></li>
<li><a href="<?php echo base_url(); ?>drafts">Drafts</a></li>
<?php endif; ?>
</ul>
<ul class="nav navbar-nav right">
<?php if (!$this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>homepage/title">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?>
</ul>
<div class="container">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>">Google Forms</a>
</div>
<?php endif; ?>
<div id="navbar" class="navbar-collapse">
<ul class="nav navbar-nav">
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>published_forms">Published Forms</a></li>
<li><a href="<?php echo base_url(); ?>drafts">Drafts</a></li>
<?php endif; ?>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if (!$this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>homepage/title">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?>
</ul>
</div>
</nav>
</div>
</nav>
<!-- Alert Messages -->
<div class="container">
@ -65,22 +68,28 @@
<!-- Form Editor -->
<div class="container">
<div class="form-header">
<button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button>
<!-- <button id="preview-btn" class="btn btn-info"><i class="fas fa-eye"></i></button> -->
<input type="text" id="form-title" class="form-control" value="<?php echo $form['title']; ?>">
<input type="text" id="form-description" class="form-control" value="<?php echo $form['description']; ?>">
<button id="add-section-btn" class="btn btn-primary">+</button>
</div>
<div id="form-container">
<?php foreach ($questions as $question): ?>
<div class="form-section" data-index="<?php echo $question['id']; ?>" data-type="<?php echo $question['type']; ?>">
<div class="form-section" data-index="<?php echo $question['id']; ?>"
data-type="<?php echo $question['type']; ?>">
<div class="header-row">
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"><?php echo $question['text']; ?></textarea>
<input type="text" class="form-control untitled-question" placeholder="Untitled Question" rows="1"
value="<?php echo $question['text']; ?>">
<select class="custom-select">
<option value="short-answer" <?php echo $question['type'] == 'short-answer' ? 'selected' : ''; ?>>Short Answer</option>
<option value="paragraph" <?php echo $question['type'] == 'paragraph' ? 'selected' : ''; ?>>Paragraph</option>
<option value="short-answer" <?php echo $question['type'] == 'short-answer' ? 'selected' : ''; ?>>
Short Answer</option>
<option value="paragraph" <?php echo $question['type'] == 'paragraph' ? 'selected' : ''; ?>>
Paragraph</option>
<option value="multiple-choice" <?php echo $question['type'] == 'multiple-choice' ? 'selected' : ''; ?>>Multiple Choice</option>
<option value="checkboxes" <?php echo $question['type'] == 'checkboxes' ? 'selected' : ''; ?>>Checkboxes</option>
<option value="dropdown" <?php echo $question['type'] == 'dropdown' ? 'selected' : ''; ?>>Dropdown</option>
<option value="checkboxes" <?php echo $question['type'] == 'checkboxes' ? 'selected' : ''; ?>>
Checkboxes</option>
<option value="dropdown" <?php echo $question['type'] == 'dropdown' ? 'selected' : ''; ?>>Dropdown
</option>
</select>
<label class="toggle-switch">
<input type="checkbox" class="required-toggle" <?php echo $question['is_required'] ? 'checked' : ''; ?>>
@ -94,16 +103,17 @@
$this->db->where('question_id', $question['id']);
$options = $this->db->get('options')->result_array();
foreach ($options as $option):
?>
?>
<div class="option">
<input type="text" class="form-control option-label" value="<?php echo $option['option_text']; ?>">
<input type="text" class="form-control option-label"
value="<?php echo $option['option_text']; ?>">
<span class="delete-option-icon">&times;</span>
</div>
<?php endforeach; ?>
</div>
<!-- Show or hide the "Add Option" button based on question type -->
<?php if ($question['type'] === 'multiple-choice' || $question['type'] === 'checkboxes' || $question['type'] === 'dropdown'): ?>
<button class="btn btn-secondary add-option-btn">Add Option</button>
<button class="btn btn-primary add-option-btn">Add Option</button>
<?php endif; ?>
</div>
<?php endforeach; ?>
@ -117,39 +127,39 @@
<!-- <script src="<?php echo base_url('assets/js/scripts.js'); ?>"></script> -->
<script>
$(document).ready(function() {
var base_url = '<?php echo base_url(); ?>';
var index = 1;
var activeSection = null;
$(document).ready(function () {
var base_url = '<?php echo base_url(); ?>';
var index = 1;
var activeSection = null;
function positionAddSectionButton() {
if (activeSection) {
var position = activeSection.position();
var buttonWidth = $('#add-section-btn').outerWidth();
var buttonHeight = $('#add-section-btn').outerHeight();
function positionAddSectionButton() {
if (activeSection) {
var position = activeSection.position();
var buttonWidth = $('#add-section-btn').outerWidth();
var buttonHeight = $('#add-section-btn').outerHeight();
$('#add-section-btn').css({
position: 'absolute',
left: position.left - buttonWidth - 47 + 'px',
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
$('#add-section-btn').css({
position: 'absolute',
left: position.left - buttonWidth - 47 + 'px',
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
});
}
}
// Add section button functionality
$('#add-section-btn').on('click', function () {
createFormSection();
$('.form-section').removeClass('active');
activeSection = $('.form-section').last();
activeSection.addClass('active');
positionAddSectionButton();
});
}
}
// Add section button functionality
$('#add-section-btn').on('click', function() {
createFormSection();
$('.form-section').removeClass('active');
activeSection = $('.form-section').last();
activeSection.addClass('active');
positionAddSectionButton();
});
function createFormSection() {
var sectionHtml = `
function createFormSection() {
var sectionHtml = `
<div class="form-section" data-type="">
<div class="header-row">
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
<input type = "text" class="form-control untitled-question" placeholder="Untitled Question" rows="1">
<select class="custom-select">
<option value="short-answer">Short Answer</option>
<option value="paragraph">Paragraph</option>
@ -164,128 +174,132 @@ $(document).ready(function() {
<span class="delete-section-icon"><i class="fas fa-trash-alt"></i></span>
</div>
<div class="options-container"></div>
<button class="btn btn-secondary add-option-btn">Add Option</button>
<button class="btn btn-primary add-option-btn">Add Option</button>
</div>
`;
$('#form-container').append(sectionHtml);
}
$('#form-container').append(sectionHtml);
positionAddSectionButton();
// Handle option button click
$(document).on('click', '.add-option-btn', function() {
var $section = $(this).closest('.form-section');
var optionHtml = `
}
// Handle option button click
$(document).on('click', '.add-option-btn', function () {
var $section = $(this).closest('.form-section');
var optionHtml = `
<div class="option">
<input type="text" class="form-control option-label" value="">
<span class="delete-option-icon">&times;</span>
</div>
`;
$section.find('.options-container').append(optionHtml);
});
// Handle delete section button click
$(document).on('click', '.delete-section-icon', function() {
$(this).closest('.form-section').remove();
});
// Handle delete option button click
$(document).on('click', '.delete-option-icon', function() {
$(this).closest('.option').remove();
});
// Handle preview button click
$('#preview-btn').on('click', function() {
alert('Preview functionality is not implemented.');
});
// Handle submit button click
$('#submit-btn').on('click', function() {
var formData = collectFormData();
formData['form_id'] = <?php echo $form['id']; ?>;
let validation = validateFormData(formData);
if (!validation.isValid) {
alert(validation.message);
return;
}
$.ajax({
url: base_url + 'Form_controller/update_form',
type: 'POST',
data: { formData: formData },
dataType: 'JSON',
success: function(response) {
if (response.status === 'success') {
alert('Form updated successfully!');
window.location.href = base_url + 'drafts';
} else {
alert(response.message);
}
},
error: function(error) {
alert('Error updating form!');
console.log(error);
}
});
});
// Collect form data function
function collectFormData() {
var formData = {
title: $('#form-title').val(),
description: $('#form-description').val(),
questions: []
};
$('.form-section').each(function() {
var questionData = {
id: $(this).data('index'),
text: $(this).find('.untitled-question').val(),
type: $(this).find('.custom-select').val(),
required: $(this).find('.required-toggle').is(':checked') ? 1 : 0, // Correctly capture the required value
options: []
};
$(this).find('.option-label').each(function() {
questionData.options.push($(this).val());
$section.find('.options-container').append(optionHtml);
});
formData.questions.push(questionData);
});
// Handle delete section button click
$(document).on('click', '.delete-section-icon', function () {
$(this).closest('.form-section').remove();
});
return formData;
}
function validateFormData(formData) {
for (let question of formData.questions) {
if (!question.text.trim()) {
return { isValid: false, message: 'All questions must have text.' };
}
if ((question.type === 'multiple-choice' || question.type === 'checkboxes' || question.type === 'dropdown') && question.options.length === 0) {
return { isValid: false, message: 'All options-based questions must have at least one option.' };
}
for (let option of question.options) {
if (!option.trim()) {
return { isValid: false, message: 'All options must have text.' };
// Handle delete option button click
$(document).on('click', '.delete-option-icon', function () {
$(this).closest('.option').remove();
});
// Handle preview button click
$('#preview-btn').on('click', function () {
alert('Preview functionality is not implemented.');
});
$('.form-section').each(function () {
$(this).on('click', function () {
$('.form-section').removeClass('active');
$(this).addClass('active');
activeSection = $(this);
positionAddSectionButton();
});
});
// Handle window resize to reposition button
$(window).on('resize', function () {
positionAddSectionButton();
});
// Handle submit button click
$('#submit-btn').on('click', function () {
var formData = collectFormData();
formData['form_id'] = <?php echo $form['id']; ?>;
let validation = validateFormData(formData);
if (!validation.isValid) {
alert(validation.message);
return;
}
$.ajax({
url: base_url + 'Form_controller/update_form',
type: 'POST',
data: { formData: formData },
dataType: 'JSON',
success: function (response) {
if (response.status === 'success') {
alert('Form updated successfully!');
window.location.href = base_url + 'drafts';
} else {
alert(response.message);
}
},
error: function (error) {
alert('Error updating form!');
console.log(error);
}
});
});
// Collect form data function
function collectFormData() {
var formData = {
title: $('#form-title').val(),
description: $('#form-description').val(),
questions: []
};
$('.form-section').each(function () {
var questionData = {
id: $(this).data('index'),
text: $(this).find('.untitled-question').val(),
type: $(this).find('.custom-select').val(),
required: $(this).find('.required-toggle').is(':checked') ? 1 : 0, // Correctly capture the required value
options: []
};
$(this).find('.option-label').each(function () {
questionData.options.push($(this).val());
});
formData.questions.push(questionData);
});
return formData;
}
function validateFormData(formData) {
for (let question of formData.questions) {
if (!question.text.trim()) {
return { isValid: false, message: 'All questions must have text.' };
}
if ((question.type === 'multiple-choice' || question.type === 'checkboxes' || question.type === 'dropdown') && question.options.length === 0) {
return { isValid: false, message: 'All options-based questions must have at least one option.' };
}
for (let option of question.options) {
if (!option.trim()) {
return { isValid: false, message: 'All options must have text.' };
}
}
}
return { isValid: true };
}
}
return { isValid: true };
}
// Initialize
$('.form-section').each(function() {
$(this).on('click', function() {
$('.form-section').removeClass('active');
$(this).addClass('active');
activeSection = $(this);
positionAddSectionButton();
// Initialize
});
});
// Handle window resize to reposition button
$(window).on('resize', function() {
positionAddSectionButton();
});
});
</script>
</body>
</html>
</html>

View File

@ -1 +0,0 @@
<h4>This is about page</h4>

View File

@ -1 +0,0 @@
<h4>Welcome to Google Forms !</h4>

View File

@ -1 +0,0 @@
<h4>This is the home page</h4>

View File

@ -28,8 +28,8 @@
<tr>
<th>Responses</th>
<th>Title</th>
<th>Status</th>
<th>Response Link</th>
<th>Status</th>
<th>Preview</th>
</tr>
</thead>
@ -40,14 +40,14 @@
<td class="title-column">
<?php echo $row->title; ?>
</td>
<td>
<a href="<?php echo base_url('Publish_controller/unpublish_form/' . $row->id); ?>" class="btn btn-danger btn-sm" style=" background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Unpublish</a>
</td>
<td>
<a href="<?php echo $row->response_link; ?>" target="_blank"><?php echo $row->response_link; ?></a>
</td>
<td>
<a href="<?php echo base_url('Publish_controller/unpublish_form/' . $row->id); ?>" class="btn btn-danger btn-sm" style=" background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Unpublish</a>
</td>
<td>
<a href="<?php echo base_url('form_preview/' . $row->id); ?>">
<i class="fas fa-eye"></i> <!-- Eye icon -->
</a>

View File

@ -7,6 +7,11 @@
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
</head>
<body>
<style>
.username-column {
color: darkblue; /* Dark blue color for title */
}
</style>
<div class="container">
<div class="row">
<div class="col-md-12 mt-4">
@ -25,21 +30,22 @@
<table id="basetable1" class="table table-bordered">
<thead>
<tr>
<th>Response ID</th>
<th>Username</th>
<th>Submitted At</th>
<th>View</th>
</tr>
</thead>
<tbody>
<?php foreach ($responses as $response): ?>
<tr>
<td class="username-column"><?php echo $response->username; ?></td>
<td><?php echo $response->submitted_at; ?></td>
<td>
<a href="<?php echo base_url('responses/view/' . $response->response_id); ?>">
<?php echo $response->response_id; ?>
<i class="fas fa-eye"></i> <!-- Eye icon -->
</a>
</td>
<td><?php echo $response->username; ?></td>
<td><?php echo $response->submitted_at; ?></td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -1,10 +1,3 @@
<!-- <script>
$(document).ready(function(){
$('#basetable1').DataTable({
// "pagingType": "full_numbers"
});
});
</script> -->
<script>
$('#basetable1').DataTable({

View File

@ -9,6 +9,8 @@
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/jquery-ui.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">

View File

@ -1,35 +1,61 @@
.navbar-container {
max-width: 100%;
margin: 0 auto;
padding: 0 15px;
}
/* Navbar styles */
.navbar-custom {
background-color: rgb(103, 58, 183); ; /* Customize this color */
}
/* Button positioning for section addition */
#add-section-btn {
position: absolute;
/* Ensure proper positioning */
}
.form-section {
margin-bottom: 15px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
.header-row {
background-color: rgb(103, 58, 183);
border-radius: 0;
height: 70px;
display: flex;
align-items: center;
align-items: center;
padding: 0;
}
.header-row textarea,
.header-row select {
margin-right: 10px;
}
/* Brand styling */
.navbar-custom .navbar-brand {
color: #fff; /* Customize brand color */
color: #fff;
font-size: 19px;
margin-right: 20px;
padding: 15px 10px;
}
.navbar-custom .navbar-nav {
display: flex;
align-items: center;
margin-left: -17px;
padding: 0;
flex: 1;
}
.navbar-custom .navbar-nav li {
margin: 0 10px;
}
.navbar-custom .navbar-nav li a {
color: #fff; /* Customize link color */
color: #fff;
background-color: transparent;
font-size: 15px;
height: 70px;
padding: 15px 10px;
transition: none;
}
.navbar-custom .navbar-nav.navbar-right {
margin-left: auto;
display: flex;
align-items: center;
}
.navbar-custom .navbar-nav.navbar-right li {
margin: 0 10px;
}
#add-section-btn {
position: absolute;
}

View File

@ -49,13 +49,16 @@ body {
border-radius: 0;
}
.navbar-custom .navbar-brand,
.navbar-custom .navbar-nav>li>a {
.navbar-custom .navbar-brand>li>a {
color: white;
font-size: 16px;
transition: color 0.3s ease;
}
.navbar-custom .navbar-nav>li>a{
color: white;
font-size: 16px;
transition: color 0.3s ease;
}
.navbar-custom .navbar-brand:hover,
.navbar-custom .navbar-nav>li>a:hover {
color: white; /* Keep text color white on hover */

View File

@ -114,8 +114,21 @@ body {
.custom-select {
width: 220px;
height: 45px;
display: block;
/* width: 100%; */
/* height: 45px; */
padding: 10px 15px;
font-size: 15px;
line-height: 1.42857143;
/* color: #2c3e50; */
background-color: #ffffff;
background-image: none;
border: 1px solid #dce4ec;
border-radius: 4px;
}
.delete-section-icon {
flex: 0.1;
cursor: pointer;
@ -164,7 +177,7 @@ body {
background-color: rgb(66, 133, 244);
/* color: rgb(66, 133, 244); */
margin-top: 11px;
font-size: 0.9em;
font-size: 0.8em;
}
@ -177,8 +190,7 @@ body {
width: 56%;
margin-left: 240px;
}
/* Toggle Switch CSS */
/* Toggle Switch CSS */
.toggle-switch {
position: relative;
display: inline-block;

View File

@ -30,8 +30,7 @@ function addOption(type, container) {
<div class="form-section" data-index="${index}">
<div class="header-row">
${index === 1 ? '<div class="violet-border"></div>' : ''}
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
<select class="custom-select">
<input type="text" class="form-control untitled-question" placeholder="Untitled Question" rows="1"> <select class="custom-select">
<option value="short-answer">Short Answer</option>
<option value="paragraph">Paragraph</option>
<option value="multiple-choice">Multiple Choice</option>
@ -145,13 +144,13 @@ function addOption(type, container) {
<body>
<div class="container">
<div class="form-header">
<h2>Untitled Form</h2>
<h3>Form Preview</h3>
</div>
`;
$('.form-section').each(function() {
previewContent += '<div class="form-section">';
previewContent += '<div class="question-section">';
previewContent += '<textarea class="form-control question-label" disabled>' + $(this).find('.untitled-question').val() + '</textarea>';
previewContent += '<div class="question-label">' + $(this).find('.untitled-question').val() + '</div>';
previewContent += '</div>';
let type = $(this).find('.custom-select').val();
let optionsContainer = $(this).find('.options-container');
@ -189,7 +188,6 @@ function addOption(type, container) {
previewContent += '</div>';
});
previewContent += `
<button class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
</div>
</body>
</html>