This commit is contained in:
torun23 2024-07-22 18:09:47 +05:30
parent 7a58576a1d
commit b5da349861
18 changed files with 182 additions and 38 deletions

View File

@ -5,14 +5,20 @@ $route['forms'] = 'home/index4';
$route['responses/list/(:num)'] = 'Response_submit/list_responses/$1';
$route['responses/view/(:num)'] = 'Response_submit/viewresponse/$1';
$route['publish/(:num)'] = 'forms/preview/$1';
$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'] = 'home/title';
$route['default_page'] = 'Form_controller/index_forms';
// $route['new_form'] = 'home/create_form';
$route['title_desc'] = 'homepage/title';
$route['forms/delete/(:any)'] = 'Form_controller/delete/$1';
// $route['froms_home'] = 'Form_controller/index_forms';
$route['home'] = 'Form_controller/index_forms';
$route['published_forms'] = 'Publish_controller/list_user_published_forms';
$route['drafts'] = 'Form_controller/index_forms_draft';
$route['edit/(:num)'] = 'Form_controller/edit_form/$1';
$route['form_preview/(:num)'] = 'forms/preview_back/$1';
$route['responses/(:num)'] = 'Response_submit/view_responses/$1';
$route['designform'] = 'homepage/design_form';

View File

@ -39,7 +39,7 @@ class Form_controller extends CI_Controller {
$this->load->model('Frontend_model');
$this->Frontend_model->deleteForm($id);
$this->session->set_flashdata('status','Form data deleted successfully');
redirect('default_page');
redirect('home');
}
public function __construct() {
parent::__construct();

View File

@ -1,11 +1,11 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home extends CI_Controller
class Homepage extends CI_Controller
{
// index2-default
public function default_page()
public function home()
{
$this->load->view('Frontend/header');

View File

@ -27,7 +27,7 @@ class New_form extends CI_Controller
// $this->session->set_flashdata('user_registered', 'You are now registered and can log in');
redirect('home/design_form');
redirect('designform');
}
}

View File

@ -19,7 +19,7 @@ class Publish_controller extends CI_Controller {
]);
// Redirect to the list_user_published_forms function
redirect('Publish_controller/list_user_published_forms');
redirect('published_forms');
}
// Method to list published forms of a user
@ -49,6 +49,6 @@ class Publish_controller extends CI_Controller {
$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');
redirect('published_forms');
}
}

View File

@ -14,7 +14,7 @@ class Response_submit extends CI_Controller {
$data['questions'] = $questions;
// Redirect to the view_responses function in the Response_submit controller
redirect('Response_submit/view_responses/' . $form_id);
redirect('responses/' . $form_id);
}
public function view_responses($form_id) {
@ -66,7 +66,7 @@ class Response_submit extends CI_Controller {
$this->Response_model->insert_response_answer($data);
}
redirect('Response_submit/view_responses/' . $form_id);
redirect('responses/' . $form_id);
}

View File

@ -71,7 +71,7 @@ class Users extends CI_Controller
// Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
redirect('default_page');
redirect('home');
} else {
// Set message
$this->session->set_flashdata('login_failed', 'Login is invalid');

View File

@ -30,17 +30,17 @@ Drafts
<tr>
<td><?php echo $row->id; ?></td>
<td><a
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?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>
<a href="<?php echo base_url('Form_controller/edit_form/' . $row->id); ?>"
class="btn btn-success btn-sm">Edit</a>
<a href="<?php echo base_url('edit/' . $row->id); ?>"
class="btn btn-success btn-sm " style=" background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Edit</a>
</td>
<td>
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
class="btn btn-danger btn-sm">Delete</a>
class="btn btn-danger btn-sm" style=" background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Delete</a>
</td>
</tr>
<?php endforeach; ?>

View File

@ -29,7 +29,7 @@
<tr>
<td><?php echo $row->id; ?></td>
<td><a
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?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>

View File

@ -8,10 +8,6 @@
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/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">
<style>
/* Include your styles here */
</style>
</head>
<body>
<div class="container">
@ -59,7 +55,7 @@
</div>
<?php endforeach; ?>
</div>
<button id="submit-btn" class="btn btn-success" style="margin-left: 240px; margin-top: 20px">Submit</button>
<button id="submit-btn" class="btn btn-success" style="background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white; margin-left: 240px; margin-top: 20px">Submit</button>
</div>
<script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
@ -146,7 +142,7 @@ $(document).ready(function() {
success: function(response) {
if (response.status === 'success') {
alert('Form updated successfully!');
window.location.href = base_url + 'Form_controller/index_forms_draft';
window.location.href = base_url + 'drafts';
} else {
alert(response.message);
}
@ -204,3 +200,4 @@ $(document).ready(function() {
</script>
</body>
</html>
</div>

View File

@ -120,7 +120,7 @@
</div>
<?php endforeach; ?>
<a href="<?php echo base_url('Publish_controller/publish_form/'.$form->id); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px;">Publish</a>
<a href="<?php echo base_url('Publish_controller/publish_form/'.$form->id); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px; background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Publish</a>
</div>
</body>
</html>

View File

@ -58,7 +58,7 @@
</div>
<?php endforeach; ?>
<a href="<?php echo base_url('Publish_controller/list_user_published_forms'); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px;">Back</a>
<a href="<?php echo base_url('published_forms'); ?>" class="btn btn-success" style="margin-top: 20px; position: relative; left: 240px; background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white; position: relative; left: 240px;">Back</a>
</div>
</body>
</html>

View File

@ -29,14 +29,14 @@
<tr>
<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>
<a href="<?php echo base_url('form_preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td>
<td><?php echo $row->description; ?></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">Unpublish</a>
<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>
</tr>
<?php endforeach; ?>
@ -46,4 +46,3 @@
</div>
</div>
</div>
</div>

View File

@ -66,7 +66,7 @@
</div>
<?php endforeach; ?>
</div>
<button type="submit" class="btn btn-success" style="display: block; margin: 20px auto 20px 240px;">Submit</button>
<button type="submit" class="btn btn-success" style="display: block; margin: 20px auto 20px 240px; background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;">Submit</button>
</form>
</div>
</body>

View File

@ -28,6 +28,7 @@
#submit-btn {
margin-top: 20px;
background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); color: white;"
float: left;
clear: both;
}
@ -45,7 +46,7 @@
<nav class="navbar navbar-inverse navbar-custom">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>">Google Forms</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav navbar-right">

View File

@ -23,15 +23,15 @@
<div class="container" style="background-color: rgb(103, 58, 183);">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>">Google Forms</a>
</div>
<?php endif; ?>
<div id="navbar">
<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>
<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>
@ -41,7 +41,7 @@
<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(); ?>home/title">Create Form</a></li>
<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>

View File

@ -223,3 +223,9 @@ table a:not(.btn) {
table a:not(.btn):hover {
color: darkblue !important;
}
/* .btn-success {
color: #ffffff;
background-color: rgb(103, 58, 183);
border-color: rgb(103, 58, 183);
} */

View File

@ -0,0 +1,135 @@
$(document).ready(function() {
var base_url = '<?php echo base_url(); ?>';
// Add section button functionality
$('#add-section-btn').on('click', function() {
var sectionHtml = `
<div class="form-section" data-type="">
<div class="header-row">
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"></textarea>
<select class="custom-select">
<option value="short-answer">Short Answer</option>
<option value="paragraph">Paragraph</option>
<option value="multiple-choice">Multiple Choice</option>
<option value="checkboxes">Checkboxes</option>
<option value="dropdown">Dropdown</option>
</select>
<label class="toggle-switch">
<input type="checkbox" class="required-toggle">
<span class="slider"></span>
</label>
<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" style="display: none;">Add Option</button>
</div>
`;
$('#form-container').append(sectionHtml);
});
// Add option button functionality
$(document).on('click', '.add-option-btn', function() {
var optionHtml = `
<div class="option">
<input type="text" class="form-control option-label" placeholder="Option">
<span class="delete-option-icon">&times;</span>
</div>
`;
$(this).siblings('.options-container').append(optionHtml);
});
// Delete option functionality
$(document).on('click', '.delete-option-icon', function() {
$(this).parent().remove();
});
// Delete section functionality
$(document).on('click', '.delete-section-icon', function() {
$(this).closest('.form-section').remove();
});
// Show/Hide "Add Option" button based on question type
$(document).on('change', '.custom-select', function() {
var type = $(this).val();
var $section = $(this).closest('.form-section');
if (type === 'multiple-choice' || type === 'checkboxes' || type === 'dropdown') {
$section.find('.add-option-btn').show();
} else {
$section.find('.add-option-btn').hide();
}
}).trigger('change'); // Trigger change to apply to existing sections
// Submit button functionality
$('#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 + 'Form_controller/index_forms_draft';
} 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 };
}
});