commit
This commit is contained in:
parent
fe5ee0596c
commit
2e5e30aa1e
|
@ -3,12 +3,16 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
$route['forms'] = 'home/index4';
|
$route['forms'] = 'home/index4';
|
||||||
|
|
||||||
|
$route['responses/list/(:num)'] = 'Response_submit/list_responses/$1';
|
||||||
|
$route['responses/view/(:num)'] = 'Response_submit/viewresponse/$1';
|
||||||
|
|
||||||
$route['default_controller'] = 'Form_controller/index_forms';
|
$route['default_controller'] = 'Form_controller/index_forms';
|
||||||
$route['404_override'] = '';
|
$route['404_override'] = '';
|
||||||
$route['translate_uri_dashes'] = FALSE;
|
$route['translate_uri_dashes'] = FALSE;
|
||||||
$route['start'] = 'home/index';
|
$route['start'] = 'home/index';
|
||||||
$route['new_form'] = 'home/create_form';
|
$route['new_form'] = 'home/create_form';
|
||||||
$route['title_desc'] = 'home/title';
|
$route['title_desc'] = 'home/title';
|
||||||
$route['forms_home'] = 'Form_controller/index_forms';
|
$route['default_page'] = 'Form_controller/index_forms';
|
||||||
$route['forms/delete/(:any)'] = 'Form_controller/delete/$1';
|
$route['forms/delete/(:any)'] = 'Form_controller/delete/$1';
|
||||||
|
// $route['froms_home'] = 'Form_controller/index_forms';
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ class Form extends CI_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function submit() {
|
public function submit() {
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
$form_data = json_decode($this->input->raw_input_stream, true);
|
$form_data = json_decode($this->input->raw_input_stream, true);
|
||||||
|
|
||||||
if ($this->Form_model->save_form($form_data)) {
|
if ($this->Form_model->save_form($form_data)) {
|
||||||
|
|
|
@ -3,26 +3,68 @@ 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()
|
public function index_forms($form_id = null)
|
||||||
{
|
{
|
||||||
$this->load->view('Frontend/header');
|
|
||||||
|
|
||||||
$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
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
|
|
||||||
$data= $this->Frontend_model->getforms();
|
// Retrieve form title from the forms table using form_id
|
||||||
$this->load->view('Tables/list_forms',['forms'=> $data]);
|
$form_title = 'Untitled Form'; // Default title
|
||||||
|
if ($form_id) {
|
||||||
|
$form = $this->Frontend_model->getFormById($form_id);
|
||||||
|
if ($form) {
|
||||||
|
$form_title = $form['title'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load views and data if user is logged in
|
||||||
|
$this->load->view('templates/header');
|
||||||
|
|
||||||
$this->load->view('Frontend/footer');
|
$data = $this->Frontend_model->getforms();
|
||||||
|
$this->load->view('Tables/list_forms', ['forms' => $data, 'form_title' => $form_title]);
|
||||||
|
|
||||||
|
$this->load->view('templates/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($id)
|
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->load->model('Frontend_model');
|
||||||
$this->Frontend_model->deleteForm($id);
|
$this->Frontend_model->deleteForm($id);
|
||||||
$this->session->set_flashdata('status','Form data deleted successfully');
|
$this->session->set_flashdata('status','Form data deleted successfully');
|
||||||
redirect('forms_home');
|
redirect('default_page');
|
||||||
|
}
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('Updation_model');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load the form for editing
|
||||||
|
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('edit_form_view', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the edited form
|
||||||
|
public function update_form() {
|
||||||
|
$form_id = $this->input->post('form_id');
|
||||||
|
$title = $this->input->post('title');
|
||||||
|
$description = $this->input->post('description');
|
||||||
|
$questions = $this->input->post('questions');
|
||||||
|
|
||||||
|
$this->Updation_model->update_form($form_id, $title, $description);
|
||||||
|
$this->Updation_model->update_questions($form_id, $questions);
|
||||||
|
|
||||||
|
echo json_encode(['status' => 'success']);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,10 @@ class Forms extends CI_Controller
|
||||||
{
|
{
|
||||||
public function preview($form_id)
|
public function preview($form_id)
|
||||||
{
|
{
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
// Load the model that handles the form data
|
// Load the model that handles the form data
|
||||||
$this->load->model('preview_model');
|
$this->load->model('preview_model');
|
||||||
|
|
||||||
|
@ -23,12 +27,21 @@ class Forms extends CI_Controller
|
||||||
$data['form'] = $form;
|
$data['form'] = $form;
|
||||||
$data['questions'] = $questions;
|
$data['questions'] = $questions;
|
||||||
|
|
||||||
|
$this->load->view('templates/header');
|
||||||
|
|
||||||
$this->load->view('form_preview', $data);
|
$this->load->view('form_preview', $data);
|
||||||
// redirect('home/preview_forms');
|
$this->load->view('templates/footer');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function response_preview($form_id)
|
public function response_preview($form_id)
|
||||||
{
|
{
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Load the model that handles the form data
|
// Load the model that handles the form data
|
||||||
$this->load->model('preview_model');
|
$this->load->model('preview_model');
|
||||||
|
|
||||||
|
@ -50,6 +63,36 @@ class Forms extends CI_Controller
|
||||||
$this->load->view('response_submit', $data);
|
$this->load->view('response_submit', $data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public function preview_back($form_id)
|
||||||
|
{
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
$this->load->view('templates/header');
|
||||||
|
|
||||||
|
$this->load->view('form_preview_back', $data);
|
||||||
|
$this->load->view('templates/footer');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,53 +4,32 @@ defined('BASEPATH') or exit('No direct script access allowed');
|
||||||
class Home extends CI_Controller
|
class Home extends CI_Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
public function index1()
|
// index2-default
|
||||||
|
public function default_page()
|
||||||
{
|
{
|
||||||
$this->load->view('templates/header');
|
|
||||||
$this->load->view('pages/about');
|
|
||||||
$this->load->view('templates/footer');
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
public function index2()
|
|
||||||
{
|
|
||||||
// $this->load->view('templates/header');
|
|
||||||
$this->load->view('Frontend/header');
|
$this->load->view('Frontend/header');
|
||||||
|
|
||||||
$this->load->view('Form_controller/index_forms');
|
$this->load->view('Form_controller/index_forms');
|
||||||
// $this->load->view('templates/footer');
|
|
||||||
$this->load->view('Frontend/footer');
|
$this->load->view('Frontend/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function design_form()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->load->view('templates/forms_ui');
|
||||||
|
|
||||||
}
|
}
|
||||||
public function index3()
|
public function title()
|
||||||
{
|
{
|
||||||
$this->load->view('templates/header');
|
|
||||||
$this->load->view('pages/homepage');
|
|
||||||
$this->load->view('templates/footer');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function design_form(){
|
|
||||||
$this->load->view('templates/forms_ui');
|
|
||||||
}
|
|
||||||
public function title(){
|
|
||||||
$this->load->view('templates/header');
|
$this->load->view('templates/header');
|
||||||
$this->load->view('templates/form_title');
|
$this->load->view('templates/form_title');
|
||||||
$this->load->view('templates/footer');
|
$this->load->view('templates/footer');
|
||||||
|
|
||||||
}
|
}
|
||||||
public function index4()
|
public function ui_forms()
|
||||||
{
|
{
|
||||||
$this->load->view('templates/forms_ui');
|
$this->load->view('templates/forms_ui');
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function preview_forms($data)
|
|
||||||
|
|
||||||
// { $this->load->view('templates/header');
|
|
||||||
|
|
||||||
// $this->load->view('form_preview',$data);
|
|
||||||
// $this->load->view('templates/footer');
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
|
@ -3,6 +3,10 @@ class New_form extends CI_Controller
|
||||||
{
|
{
|
||||||
public function create_form()
|
public function create_form()
|
||||||
{
|
{
|
||||||
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
$data['title'] = 'Form Details';
|
$data['title'] = 'Form Details';
|
||||||
$this->form_validation->set_rules('title', 'Title', 'required');
|
$this->form_validation->set_rules('title', 'Title', 'required');
|
||||||
$this->form_validation->set_rules('description', 'Description', 'required');
|
$this->form_validation->set_rules('description', 'Description', 'required');
|
||||||
|
|
|
@ -4,21 +4,28 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
class New_form_controller extends CI_Controller {
|
class New_form_controller extends CI_Controller {
|
||||||
|
|
||||||
public function submit_form() {
|
public function submit_form() {
|
||||||
// no need to decode the data
|
if (!$this->session->userdata('logged_in')) {
|
||||||
|
// If not logged in, redirect to login page
|
||||||
|
redirect('users/login');
|
||||||
|
}
|
||||||
|
// Decode the formData from the POST request
|
||||||
$formData = $this->input->post('formData');
|
$formData = $this->input->post('formData');
|
||||||
|
|
||||||
|
// Check if form_id is set in session
|
||||||
$formId = $this->session->userdata('form_id');
|
$formId = $this->session->userdata('form_id');
|
||||||
if ($formId) {
|
if ($formId) {
|
||||||
// Save questions and options associated with the form_id
|
// Load the model and save form data
|
||||||
$this->load->model('new_form_model');
|
$this->load->model('new_form_model');
|
||||||
$this->new_form_model->save_form_data($formId, $formData);
|
$saveStatus = $this->new_form_model->save_form_data($formId, $formData);
|
||||||
|
|
||||||
|
if ($saveStatus) {
|
||||||
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
|
echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']);
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'Failed to submit form data']);
|
echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Form ID not found in session']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -6,6 +6,10 @@ class Publish_controller extends CI_Controller {
|
||||||
// Method to publish a form
|
// Method to publish a form
|
||||||
public function publish_form($form_id) {
|
public function publish_form($form_id) {
|
||||||
// Generate a unique link
|
// 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);
|
$response_link = base_url("forms/response_preview/" . $form_id);
|
||||||
$this->load->model('Publish_model');
|
$this->load->model('Publish_model');
|
||||||
// Update is_published to 1 and set the response link
|
// Update is_published to 1 and set the response link
|
||||||
|
@ -20,12 +24,16 @@ $this->load->model('Publish_model');
|
||||||
|
|
||||||
// Method to list published forms of a user
|
// Method to list published forms of a user
|
||||||
public function list_user_published_forms() {
|
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');
|
$user_id = $this->session->userdata('user_id');
|
||||||
$this->load->model('Publish_model');
|
$this->load->model('Publish_model');
|
||||||
$data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id);
|
$data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id);
|
||||||
|
|
||||||
$this->load->view('Frontend/header');
|
$this->load->view('templates/header');
|
||||||
$this->load->view('publish_view', $data);
|
$this->load->view('publish_view', $data);
|
||||||
$this->load->view('Frontend/footer');
|
$this->load->view('templates/footer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,28 @@ class Response_submit extends CI_Controller {
|
||||||
|
|
||||||
redirect('Response_submit/view_responses/' . $response['form_id']);
|
redirect('Response_submit/view_responses/' . $response['form_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Method to list responses for a form
|
||||||
|
public function list_responses($form_id) {
|
||||||
|
$this->load->model('Response_model');
|
||||||
|
$data['form'] = $this->Response_model->get_form($form_id);
|
||||||
|
$data['responses'] = $this->Response_model->get_responses($form_id);
|
||||||
|
|
||||||
|
$this->load->view('Frontend/header');
|
||||||
|
$this->load->view('responses_list_view', $data);
|
||||||
|
$this->load->view('Frontend/footer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to view questions and answers for a specific response
|
||||||
|
public function viewresponse($response_id) {
|
||||||
|
$this->load->model('Response_model');
|
||||||
|
$data['response'] = $this->Response_model->get_response($response_id);
|
||||||
|
$data['form'] = $this->Response_model->get_form_by_response($response_id); // Get form details
|
||||||
|
$data['questions'] = $this->Response_model->get_questions_and_answers($response_id);
|
||||||
|
|
||||||
|
$this->load->view('templates/header');
|
||||||
|
$this->load->view('response_details_view', $data);
|
||||||
|
$this->load->view('templates/footer');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Users extends CI_Controller
|
||||||
// Set message
|
// Set message
|
||||||
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
|
$this->session->set_flashdata('user_loggedin', 'You are now logged in');
|
||||||
|
|
||||||
redirect('forms_home');
|
redirect('default_page');
|
||||||
} else {
|
} else {
|
||||||
// Set message
|
// Set message
|
||||||
$this->session->set_flashdata('login_failed', 'Login is invalid');
|
$this->session->set_flashdata('login_failed', 'Login is invalid');
|
||||||
|
|
|
@ -3,13 +3,28 @@
|
||||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
class Frontend_model extends CI_Model {
|
class Frontend_model extends CI_Model {
|
||||||
public function getforms(){
|
public function getforms()
|
||||||
$query = $this->db->get("forms");
|
{
|
||||||
return $query->result();
|
// Get the user_id from session
|
||||||
|
$user_id = $this->session->userdata('user_id');
|
||||||
|
|
||||||
|
// Ensure user_id is set
|
||||||
|
if (!$user_id) {
|
||||||
|
return []; // Return an empty array if user_id is not available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Filter forms by user_id
|
||||||
|
$this->db->where('user_id', $user_id); // Assuming 'user_id' is the column name in the 'forms' table
|
||||||
|
$query = $this->db->get('forms');
|
||||||
|
|
||||||
|
return $query->result(); // Return the result as an array of objects
|
||||||
|
}
|
||||||
public function deleteForm($id){
|
public function deleteForm($id){
|
||||||
return $this->db->delete('forms', ['id' => $id]);
|
return $this->db->delete('forms', ['id' => $id]);
|
||||||
}
|
}
|
||||||
|
public function getFormById($form_id)
|
||||||
|
{
|
||||||
|
$query = $this->db->get_where('forms', ['id' => $form_id]);
|
||||||
|
return $query->row_array();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,35 +1,38 @@
|
||||||
<?php
|
<?php
|
||||||
class New_form_model extends CI_Model {
|
class New_form_model extends CI_Model {
|
||||||
|
|
||||||
public function save_form_data($formId,$formData) {
|
public function save_form_data($formId, $formData) {
|
||||||
if (!$formId) {
|
if (!$formId) {
|
||||||
return false; // Handle error if formId is not valid
|
return false; // Handle error if formId is not valid
|
||||||
}
|
}
|
||||||
|
|
||||||
$questions_array = $formData['questions'];
|
$questions_array = $formData['questions'];
|
||||||
|
|
||||||
foreach ($questions_array as $question) {
|
foreach ($questions_array as $question) {
|
||||||
$questionData = [
|
$questionData = [
|
||||||
'form_id' => $formId,
|
'form_id' => $formId,
|
||||||
'text' => $question['text'],
|
'text' => $question['text'],
|
||||||
'type' => $question['type'],
|
'type' => $question['type'],
|
||||||
'required' => ($question['required'] == 'true') ? 0 : 1
|
'required' => ($question['required'] == 'true') ? 1 : 0
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->db->insert('questions', $questionData);
|
$this->db->insert('questions', $questionData);
|
||||||
$questionId = $this->db->insert_id(); // Get the inserted question_id
|
$questionId = $this->db->insert_id(); // Get the inserted question_id
|
||||||
|
|
||||||
|
// Handle options for multiple-choice, checkboxes, and dropdown questions
|
||||||
|
if ($question['type'] === 'multiple-choice' || $question['type'] === 'checkboxes' || $question['type'] === 'dropdown') {
|
||||||
foreach ($question['options'] as $option) {
|
foreach ($question['options'] as $option) {
|
||||||
$optionData = [ 'question_id' => $questionId,
|
$optionData = [
|
||||||
'option_text' => $option];
|
'question_id' => $questionId,
|
||||||
|
'option_text' => $option
|
||||||
|
];
|
||||||
// Insert option into options table
|
// Insert option into options table
|
||||||
$this->db->insert('options', $optionData);
|
$this->db->insert('options', $optionData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true; // Return true indicating success
|
return true; // Return true indicating success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -10,7 +10,7 @@ public function update_form($form_id, $data) {
|
||||||
// Method to retrieve published forms by user
|
// Method to retrieve published forms by user
|
||||||
public function get_published_forms_by_user($user_id) {
|
public function get_published_forms_by_user($user_id) {
|
||||||
$this->db->where('user_id', $user_id);
|
$this->db->where('user_id', $user_id);
|
||||||
$this->db->where('is_published', 1); // Ensure only published forms are retrieved
|
$this->db->where('is_published', 1);
|
||||||
$query = $this->db->get('forms');
|
$query = $this->db->get('forms');
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,35 @@ class Response_model extends CI_Model {
|
||||||
$this->db->group_by('responses.response_id, users.username');
|
$this->db->group_by('responses.response_id, users.username');
|
||||||
$query = $this->db->get();
|
$query = $this->db->get();
|
||||||
return $query->result();
|
return $query->result();
|
||||||
|
} public function get_responses($form_id) {
|
||||||
|
$this->db->where('form_id', $form_id);
|
||||||
|
$query = $this->db->get('responses');
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Method to get response details
|
||||||
|
public function get_response($response_id) {
|
||||||
|
$this->db->where('response_id', $response_id);
|
||||||
|
$query = $this->db->get('responses');
|
||||||
|
return $query->row();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to get questions and answers for a response
|
||||||
|
public function get_questions_and_answers($response_id) {
|
||||||
|
$this->db->select('questions.id AS question_id, questions.text AS question_text, responses.answered_text');
|
||||||
|
$this->db->from('questions');
|
||||||
|
$this->db->join('responses', 'questions.id = responses.question_id');
|
||||||
|
$this->db->where('responses.response_id', $response_id);
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
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');
|
||||||
|
$this->db->where('responses.response_id', $response_id);
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
class Updation_model extends CI_Model {
|
||||||
|
|
||||||
|
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) {
|
||||||
|
$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() {
|
||||||
|
$query = $this->db->get('options');
|
||||||
|
return $query->result_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update_form($form_id, $title, $description) {
|
||||||
|
$this->db->where('id', $form_id);
|
||||||
|
$this->db->update('forms', ['title' => $title, 'description' => $description]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update_questions($form_id, $questions) {
|
||||||
|
// First, delete existing questions
|
||||||
|
$this->db->where('form_id', $form_id);
|
||||||
|
$this->db->delete('questions');
|
||||||
|
|
||||||
|
// Insert new questions
|
||||||
|
foreach ($questions as $question) {
|
||||||
|
$this->db->insert('questions', [
|
||||||
|
'form_id' => $form_id,
|
||||||
|
'text' => $question['text']
|
||||||
|
]);
|
||||||
|
$question_id = $this->db->insert_id();
|
||||||
|
|
||||||
|
if (isset($question['options'])) {
|
||||||
|
foreach ($question['options'] as $option) {
|
||||||
|
$this->db->insert('options', [
|
||||||
|
'question_id' => $question_id,
|
||||||
|
'option_text' => $option
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -25,9 +25,8 @@
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
|
||||||
<!-- <li><a href="<?php echo base_url(); ?>home/index3">Home</a></li> -->
|
<!-- <li><a href="<?php echo base_url(); ?>home/index3">Home</a></li> -->
|
||||||
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
|
|
||||||
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
|
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
|
||||||
<li><a href="<?php echo base_url(); ?>Response_submit/submit_form">Responses</a></li>
|
<!-- <li><a href="<?php echo base_url(); ?>">Responses</a></li> -->
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
@ -55,9 +54,7 @@
|
||||||
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('user_loggedin')): ?>
|
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedin') . '</p>'; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<!-- here your table will occur -->
|
<!-- here your table will occur -->
|
||||||
<table id="basetable1" class="table table-bordered">
|
<table id = "basetable1" class="table table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Form_Id</th>
|
<th>Form_Id</th>
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Edit</th>
|
<th>Edit</th>
|
||||||
<th>Delete</th>
|
<th>Delete</th>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -41,7 +40,7 @@
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<a href="" class="btn btn-success btn-sm">Edit</a>
|
<a href="<?php echo base_url('Form_controller/edit_form/' . $row->id); ?>" class="btn btn-success btn-sm">Edit</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
|
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Edit Form</title>
|
||||||
|
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/bootstrap.min.css">
|
||||||
|
<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">
|
||||||
|
<div class="form-header">
|
||||||
|
<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']; ?>">
|
||||||
|
<div class="header-row">
|
||||||
|
<textarea class="form-control untitled-question" placeholder="Untitled Question" rows="1"><?php echo $question['text']; ?></textarea>
|
||||||
|
<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="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>
|
||||||
|
</select>
|
||||||
|
<label class="toggle-switch">
|
||||||
|
<input type="checkbox" class="required-toggle" <?php echo $question['required'] ? 'checked' : ''; ?>>
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
<span class="delete-section-icon"><i class="fas fa-trash-alt"></i></span>
|
||||||
|
</div>
|
||||||
|
<div class="options-container">
|
||||||
|
<?php
|
||||||
|
// Fetch options for this question only
|
||||||
|
$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']; ?>">
|
||||||
|
<span class="delete-option-icon">×</span>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-secondary add-option-btn">Add Option</button>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="submit-btn" class="btn btn-success" style="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>
|
||||||
|
<script src="<?php echo base_url('assets/js/jquery-ui.js'); ?>"></script>
|
||||||
|
<!-- <script src="<?php echo base_url('assets/js/edit.js'); ?>"></script> -->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(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">
|
||||||
|
<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">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">×</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();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Submit button functionality
|
||||||
|
$('#submit-btn').on('click', function() {
|
||||||
|
var formData = collectFormData();
|
||||||
|
formData['form_id'] = <?php echo $form['id']; ?>;
|
||||||
|
|
||||||
|
$.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!');
|
||||||
|
} 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'),
|
||||||
|
options: []
|
||||||
|
};
|
||||||
|
|
||||||
|
$(this).find('.option-label').each(function() {
|
||||||
|
questionData.options.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
formData.questions.push(questionData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return formData;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,116 +1,53 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Form Preview - Google Forms</title>
|
|
||||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
|
||||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
|
|
||||||
<style>
|
|
||||||
body { background-color: rgb(240, 235, 248); }
|
|
||||||
.container { margin-top: 30px; }
|
|
||||||
.form-section { background-color: white; width: 56%; margin-bottom: 30px; margin-left: 240px; padding: 20px; position: relative; align-items: center; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
|
|
||||||
.form-header { background-color: white; padding: 20px; margin-bottom: 10px; margin-left: 240px; border-radius: 10px 10px 0 0; display:flex ;flex-direction: column; justify-content: space-between; align-items: left; position: relative; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border-top: 10px solid rgb(103, 58, 183); width: 56%; }
|
|
||||||
.form-section h2 { text-align: center; margin-bottom: 30px; }
|
|
||||||
.form-section .question-section { margin-bottom: 20px; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);">
|
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<div id="navbar">
|
|
||||||
<ul class="nav navbar-nav">
|
|
||||||
<li><a href="<?php echo base_url(); ?>home/index3">Home</a></li>
|
|
||||||
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
|
|
||||||
<?php if ($this->session->userdata('logged_in')): ?>
|
|
||||||
<li><a href="#">Responses</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(); ?>home/title">Create Form</a></li>
|
|
||||||
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
|
|
||||||
<?php endif; ?>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<?php if ($this->session->flashdata('user_registered')): ?>
|
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('login_failed')): ?>
|
|
||||||
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('user_loggedin')): ?>
|
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedin') . '</p>'; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="form-header">
|
<div class="form-header">
|
||||||
<h2><?php echo $form->title; ?></h2>
|
<h2><?php echo $form->title; ?></h2>
|
||||||
|
|
||||||
<h4><?php echo $form->description; ?></h4>
|
<h4><?php echo $form->description; ?></h4>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-section">
|
|
||||||
<?php foreach ($questions as $question): ?>
|
<?php foreach ($questions as $question): ?>
|
||||||
|
<div class="form-section">
|
||||||
<div class="question-section">
|
<div class="question-section">
|
||||||
<input type="text" class="form-control question-label" value="<?php echo $question->text; ?>" disabled>
|
<input type="text" class="form-control question-label" value="<?php echo $question->text; ?>" disabled>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php if ($question->type == 'multiple-choice'): ?>
|
<?php if ($question->type == 'multiple-choice'): ?>
|
||||||
|
<div class="options-container">
|
||||||
<?php foreach ($question->options as $option): ?>
|
<?php foreach ($question->options as $option): ?>
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<input type="radio" name="option-<?php echo $question->id; ?>">
|
<input type="radio" name="option-<?php echo $question->id; ?>" disabled>
|
||||||
<label><?php echo $option->option_text; ?></label>
|
<label><?php echo $option->option_text; ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
<?php elseif ($question->type == 'checkbox'): ?>
|
<?php elseif ($question->type == 'checkbox'): ?>
|
||||||
|
<div class="options-container">
|
||||||
<?php foreach ($question->options as $option): ?>
|
<?php foreach ($question->options as $option): ?>
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<input type="checkbox" name="option-<?php echo $question->id; ?>">
|
<input type="checkbox" name="option-<?php echo $question->id; ?>" disabled>
|
||||||
<label><?php echo $option->option_text; ?></label>
|
<label><?php echo $option->option_text; ?></label>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
<?php elseif ($question->type == 'short-answer'): ?>
|
<?php elseif ($question->type == 'short-answer'): ?>
|
||||||
<input type="text" class="form-control" placeholder="Short answer text">
|
<div class="options-container">
|
||||||
|
<input type="text" class="form-control" placeholder="Short answer text" disabled>
|
||||||
|
</div>
|
||||||
<?php elseif ($question->type == 'paragraph'): ?>
|
<?php elseif ($question->type == 'paragraph'): ?>
|
||||||
<textarea class="form-control" placeholder="Paragraph text"></textarea>
|
<div class="options-container">
|
||||||
|
<textarea class="form-control" placeholder="Paragraph text" disabled></textarea>
|
||||||
|
</div>
|
||||||
<?php elseif ($question->type == 'dropdown'): ?>
|
<?php elseif ($question->type == 'dropdown'): ?>
|
||||||
<select class="form-control">
|
<div class="options-container">
|
||||||
|
<select class="form-control" disabled>
|
||||||
<?php foreach ($question->options as $option): ?>
|
<?php foreach ($question->options as $option): ?>
|
||||||
<option><?php echo $option->option_text; ?></option>
|
<option><?php echo $option->option_text; ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
|
||||||
<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;">Publish</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
|
|
||||||
<script>
|
|
||||||
CKEDITOR.replace('editor1');
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<div class="container">
|
||||||
|
<div class="form-header">
|
||||||
|
<h2><?php echo $form->title; ?></h2>
|
||||||
|
<h4><?php echo $form->description; ?></h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php foreach ($questions as $question): ?>
|
||||||
|
<div class="form-section">
|
||||||
|
<div class="question-section">
|
||||||
|
<input type="text" class="form-control question-label" value="<?php echo $question->text; ?>" disabled>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($question->type == 'multiple-choice'): ?>
|
||||||
|
<div class="options-container">
|
||||||
|
<?php foreach ($question->options as $option): ?>
|
||||||
|
<div class="option">
|
||||||
|
<input type="radio" name="option-<?php echo $question->id; ?>" disabled>
|
||||||
|
<label><?php echo $option->option_text; ?></label>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php elseif ($question->type == 'checkbox'): ?>
|
||||||
|
<div class="options-container">
|
||||||
|
<?php foreach ($question->options as $option): ?>
|
||||||
|
<div class="option">
|
||||||
|
<input type="checkbox" name="option-<?php echo $question->id; ?>" disabled>
|
||||||
|
<label><?php echo $option->option_text; ?></label>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php elseif ($question->type == 'short-answer'): ?>
|
||||||
|
<div class="options-container">
|
||||||
|
<input type="text" class="form-control" placeholder="Short answer text" disabled>
|
||||||
|
</div>
|
||||||
|
<?php elseif ($question->type == 'paragraph'): ?>
|
||||||
|
<div class="options-container">
|
||||||
|
<textarea class="form-control" placeholder="Paragraph text" disabled></textarea>
|
||||||
|
</div>
|
||||||
|
<?php elseif ($question->type == 'dropdown'): ?>
|
||||||
|
<div class="options-container">
|
||||||
|
<select class="form-control" disabled>
|
||||||
|
<?php foreach ($question->options as $option): ?>
|
||||||
|
<option><?php echo $option->option_text; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($forms as $row): ?>
|
<?php foreach ($forms as $row): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $row->id; ?></td>
|
<td><a href="<?php echo base_url('Response_submit/view/' . $row->id); ?>"><?php echo $row->id; ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
|
<a href="<?php echo base_url('forms/preview_back/' . $row->id); ?>"><?php echo $row->title; ?></a>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo $row->description; ?></td>
|
<td><?php echo $row->description; ?></td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="form-header">
|
||||||
|
<h2><?php echo $form->title; ?></h2>
|
||||||
|
<h4><?php echo $form->description; ?></h4>
|
||||||
|
</div>
|
||||||
|
<?php foreach ($questions as $question): ?>
|
||||||
|
<div class="form-section">
|
||||||
|
<div class="question-section">
|
||||||
|
<input type="text" class="form-control question-label" value="<?php echo $question->question_text; ?>" disabled>
|
||||||
|
<textarea class="form-control" disabled><?php echo $question->answered_text; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
|
@ -33,7 +33,11 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($responses as $response): ?>
|
<?php foreach ($responses as $response): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $response->response_id; ?></td>
|
<td>
|
||||||
|
<a href="<?php echo base_url('responses/view/' . $response->response_id); ?>">
|
||||||
|
<?php echo $response->response_id; ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
<td><?php echo $response->username; ?></td>
|
<td><?php echo $response->username; ?></td>
|
||||||
<td><?php echo $response->submitted_at; ?></td>
|
<td><?php echo $response->submitted_at; ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
</div>
|
<div></div>
|
||||||
<script>
|
<script>
|
||||||
CKEDITOR.replace( 'editor1' );
|
$(document).ready(function(){
|
||||||
|
$('#basetable1').DataTable();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
|
@ -31,6 +31,10 @@
|
||||||
float: left;
|
float: left;
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
.container{
|
||||||
|
margin-top: 10px;
|
||||||
|
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -42,8 +46,6 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="navbar-header">
|
<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(); ?>Form_controller/index_forms">Google Forms</a>
|
||||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a>
|
|
||||||
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar">
|
<div id="navbar">
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Google Forms</title>
|
<title>Form Preview - Google Forms</title>
|
||||||
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
|
||||||
|
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/styles.css">
|
||||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
|
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
|
||||||
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
|
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.8/css/dataTables.bootstrap.css">
|
||||||
</head>
|
<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">
|
||||||
|
|
||||||
<body class = "body_header_bg" >
|
</head>
|
||||||
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" >
|
<body>
|
||||||
|
|
||||||
|
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);">
|
||||||
<div class="container" style="background-color: rgb(103, 58, 183);">
|
<div class="container" style="background-color: rgb(103, 58, 183);">
|
||||||
<?php if ($this->session->userdata('logged_in')): ?>
|
<?php if ($this->session->userdata('logged_in')): ?>
|
||||||
<div class="navbar-header">
|
<div class="navbar-header">
|
||||||
|
@ -22,13 +24,9 @@
|
||||||
|
|
||||||
<div id="navbar">
|
<div id="navbar">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<!-- <li><a href="<?php echo base_url(); ?>home/index3">Home</a></li> -->
|
|
||||||
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
|
|
||||||
<?php if ($this->session->userdata('logged_in')): ?>
|
<?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(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
|
||||||
<li><a href="<?php echo base_url(); ?>Response_submit/submit_form">Responses</a></li>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<?php if (!$this->session->userdata('logged_in')): ?>
|
<?php if (!$this->session->userdata('logged_in')): ?>
|
||||||
|
@ -38,19 +36,17 @@
|
||||||
<?php if ($this->session->userdata('logged_in')): ?>
|
<?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(); ?>home/title">Create Form</a></li>
|
||||||
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
|
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container">
|
|
||||||
|
<div class="container">
|
||||||
<?php if ($this->session->flashdata('user_registered')): ?>
|
<?php if ($this->session->flashdata('user_registered')): ?>
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
|
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
<?php if ($this->session->flashdata('login_failed')): ?>
|
<?php if ($this->session->flashdata('login_failed')): ?>
|
||||||
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -62,8 +58,4 @@
|
||||||
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
<?php if ($this->session->flashdata('user_loggedout')): ?>
|
||||||
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div>
|
|
|
@ -1,4 +1,81 @@
|
||||||
|
body {
|
||||||
|
background-color: rgb(240, 235, 248);
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section {
|
||||||
|
background-color: white;
|
||||||
|
width: 56%;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
margin-left: 240px;
|
||||||
|
padding: 20px;
|
||||||
|
position: relative;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-header {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
margin-left: 240px;
|
||||||
|
border-radius: 10px 10px 0 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: left;
|
||||||
|
position: relative;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
border-top: 10px solid rgb(103, 58, 183);
|
||||||
|
width: 56%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section h2 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section .question-section {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
/* Navbar custom styles */
|
||||||
|
.navbar-custom {
|
||||||
|
background-color: rgb(103, 58, 183);
|
||||||
|
color: white;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-custom .navbar-brand,
|
||||||
|
.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 */
|
||||||
|
text-decoration: none; /* Remove underline if present */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.navbar-nav>li>a {
|
||||||
|
transition: color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-nav>li>a:hover {
|
||||||
|
color: white; /* Explicitly set text color on hover */
|
||||||
|
}
|
||||||
|
|
||||||
|
#submit-btn {
|
||||||
|
margin-top: 20px;
|
||||||
|
float: left;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
.post-date{
|
.post-date{
|
||||||
background: #f4f4f4;
|
background: #f4f4f4;
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
@ -28,3 +105,10 @@ a.pagination-link{
|
||||||
.cat-delete{
|
.cat-delete{
|
||||||
display:inline;
|
display:inline;
|
||||||
}
|
}
|
||||||
|
#basetable1 {
|
||||||
|
border: 1px solid #3333336c; /* Darker border color */
|
||||||
|
}
|
||||||
|
|
||||||
|
#basetable1 th, #basetable1 td {
|
||||||
|
border: 1px solid #3333336c; /* Darker border color for table cells */
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -0,0 +1,220 @@
|
||||||
|
body {
|
||||||
|
background-color: rgb(240, 235, 248);
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
position: relative;
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form_container_top {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-top: 10px;
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
border-bottom: 1px solid #f4f4f9;
|
||||||
|
color: black;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-header {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
margin-left: 240px;
|
||||||
|
border-radius: 10px 10px 0 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
border-top: 10px solid rgb(103, 58, 183);
|
||||||
|
width: 56%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-header h2 {
|
||||||
|
flex: 1;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#preview-btn {
|
||||||
|
margin-right: 10px;
|
||||||
|
background-color: rgb(103, 58, 183);
|
||||||
|
border-color: #007bff;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 33px;
|
||||||
|
height: 33px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#preview-btn i {
|
||||||
|
font-size: 1.5em;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#add-section-btn {
|
||||||
|
position: absolute;
|
||||||
|
left: -60px;
|
||||||
|
top: 24px;
|
||||||
|
z-index: 1000;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: rgb(103, 58, 183);
|
||||||
|
color: white;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 1.5em;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section {
|
||||||
|
background-color: white;
|
||||||
|
width: 56%;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
margin-left: 240px;
|
||||||
|
padding: 20px;
|
||||||
|
position: relative;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
transition: transform 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section.active {
|
||||||
|
border-left: 6px solid rgb(66, 133, 244);
|
||||||
|
transform: scale(1.02);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.untitled-question {
|
||||||
|
flex: 1;
|
||||||
|
margin-right: 10px;
|
||||||
|
width: calc(100% - 230px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-select {
|
||||||
|
width: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-section-icon {
|
||||||
|
cursor: pointer;
|
||||||
|
color: grey;
|
||||||
|
font-size: 1.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.options-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.options-container select {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section textarea {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option input[type="radio"],
|
||||||
|
.option input[type="checkbox"] {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option .delete-option-icon {
|
||||||
|
margin-left: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: grey;
|
||||||
|
font-size: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-label {
|
||||||
|
width: 42%;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-option-btn {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
color: #333;
|
||||||
|
margin-top: 11px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-state-highlight {
|
||||||
|
background-color: transparent !important;
|
||||||
|
border: none !important;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
width: 56%;
|
||||||
|
margin-left: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Toggle Switch CSS */
|
||||||
|
.toggle-switch {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: 34px;
|
||||||
|
height: 20px;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-switch input {
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider {
|
||||||
|
position: absolute;
|
||||||
|
cursor: pointer;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #ccc;
|
||||||
|
transition: .4s;
|
||||||
|
border-radius: 34px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider:before {
|
||||||
|
position: absolute;
|
||||||
|
content: "";
|
||||||
|
height: 14px;
|
||||||
|
width: 14px;
|
||||||
|
left: 3px;
|
||||||
|
bottom: 3px;
|
||||||
|
background-color: white;
|
||||||
|
transition: .4s;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider {
|
||||||
|
background-color: rgb(103, 58, 183);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider:before {
|
||||||
|
transform: translateX(14px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.body_header_bg {
|
||||||
|
background-color: rgb(240, 235, 248);
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
$(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">
|
||||||
|
<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">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">×</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();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Submit button functionality
|
||||||
|
$('#submit-btn').on('click', function() {
|
||||||
|
var formData = collectFormData();
|
||||||
|
formData['form_id'] = <?php echo $form['id']; ?>;
|
||||||
|
|
||||||
|
$.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!');
|
||||||
|
} 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'),
|
||||||
|
options: []
|
||||||
|
};
|
||||||
|
|
||||||
|
$(this).find('.option-label').each(function() {
|
||||||
|
questionData.options.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
formData.questions.push(questionData);
|
||||||
|
});
|
||||||
|
|
||||||
|
return formData;
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,29 +1,30 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
let index = 1;
|
let index = 1;
|
||||||
let activeSection = null;
|
let activeSection = null;
|
||||||
// Add option function
|
|
||||||
function addOption(type, container) {
|
function addOption(type, container) {
|
||||||
let optionIndex = container.children().length + 1;
|
// let optionIndex = container.children().length + 1;
|
||||||
let optionHtml;
|
let optionHtml;
|
||||||
if (type === 'multiple-choice' || type === 'checkboxes') {
|
if (type === 'multiple-choice' || type === 'checkboxes') {
|
||||||
optionHtml = `
|
optionHtml = `
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
|
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
|
||||||
<input type="text" class="form-control option-label" value="Option ${optionIndex}">
|
<input type="text" class="form-control option-label" >
|
||||||
<span class="delete-option-icon">×</span>
|
<span class="delete-option-icon">×</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
} else if (type === 'dropdown') {
|
}
|
||||||
|
else if (type === 'dropdown') {
|
||||||
optionHtml = `
|
optionHtml = `
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<input type="text" class="form-control option-label" value="Option ${optionIndex}">
|
<input type="text" class="form-control option-label">
|
||||||
<span class="delete-option-icon">×</span>
|
<span class="delete-option-icon">×</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
container.append(optionHtml);
|
container.append(optionHtml);
|
||||||
}
|
}
|
||||||
//Form section function
|
|
||||||
function createFormSection() {
|
function createFormSection() {
|
||||||
let newSection = `
|
let newSection = `
|
||||||
<div class="form-section" data-index="${index}">
|
<div class="form-section" data-index="${index}">
|
||||||
|
@ -48,7 +49,6 @@ $(document).ready(function() {
|
||||||
`;
|
`;
|
||||||
$('#form-container').append(newSection);
|
$('#form-container').append(newSection);
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
positionAddSectionButton();
|
positionAddSectionButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,10 +64,8 @@ $(document).ready(function() {
|
||||||
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
|
top: position.top + activeSection.height() / 2 - buttonHeight / 2 + 'px'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//Event handler is triggered
|
|
||||||
// creates a new form section;sets it as active;respositions the add section button
|
|
||||||
$('#add-section-btn').on('click', function() {
|
$('#add-section-btn').on('click', function() {
|
||||||
createFormSection();
|
createFormSection();
|
||||||
$('.form-section').removeClass('active');
|
$('.form-section').removeClass('active');
|
||||||
|
@ -75,12 +73,11 @@ $(document).ready(function() {
|
||||||
activeSection.addClass('active');
|
activeSection.addClass('active');
|
||||||
positionAddSectionButton();
|
positionAddSectionButton();
|
||||||
});
|
});
|
||||||
// It updates the options container based on the selected type, adding the necessary input fields or buttons.
|
|
||||||
$(document).on('change', '.custom-select', function() {
|
$(document).on('change', '.custom-select', function() {
|
||||||
let type = $(this).val();
|
let type = $(this).val();
|
||||||
let container = $(this).closest('.form-section').find('.options-container');
|
let container = $(this).closest('.form-section').find('.options-container');
|
||||||
container.empty();
|
container.empty();
|
||||||
|
|
||||||
$(this).closest('.form-section').find('.add-option-btn').remove();
|
$(this).closest('.form-section').find('.add-option-btn').remove();
|
||||||
|
|
||||||
if (type === 'short-answer') {
|
if (type === 'short-answer') {
|
||||||
|
@ -92,15 +89,13 @@ $(document).ready(function() {
|
||||||
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>');
|
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// add option event handler
|
|
||||||
// adds a new option to the options container and updates the option numbers
|
|
||||||
$(document).on('click', '.add-option-btn', function() {
|
$(document).on('click', '.add-option-btn', function() {
|
||||||
let type = $(this).closest('.form-section').find('.custom-select').val();
|
let type = $(this).closest('.form-section').find('.custom-select').val();
|
||||||
let container = $(this).closest('.form-section').find('.options-container');
|
let container = $(this).closest('.form-section').find('.options-container');
|
||||||
addOption(type, container);
|
addOption(type, container);
|
||||||
|
|
||||||
});
|
});
|
||||||
// removes the section;updates the active section;repositions add section button
|
|
||||||
$(document).on('click', '.delete-section-icon', function() {
|
$(document).on('click', '.delete-section-icon', function() {
|
||||||
let section = $(this).closest('.form-section');
|
let section = $(this).closest('.form-section');
|
||||||
let prevSection = section.prev('.form-section');
|
let prevSection = section.prev('.form-section');
|
||||||
|
@ -117,27 +112,20 @@ $(document).ready(function() {
|
||||||
nextSection.find('.delete-section-icon').appendTo(nextSection.find('.form-header'));
|
nextSection.find('.delete-section-icon').appendTo(nextSection.find('.form-header'));
|
||||||
activeSection = nextSection;
|
activeSection = nextSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
positionAddSectionButton();
|
positionAddSectionButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
// delele option
|
|
||||||
$(document).on('click', '.delete-option-icon', function() {
|
$(document).on('click', '.delete-option-icon', function() {
|
||||||
let option = $(this).closest('.option');
|
let option = $(this).closest('.option');
|
||||||
let container = option.closest('.options-container');
|
let container = option.closest('.options-container');
|
||||||
option.remove();
|
option.remove();
|
||||||
|
|
||||||
});
|
});
|
||||||
// Event handler for required toggle button
|
|
||||||
$(document).on('click', '.required-toggle', function() {
|
|
||||||
$(this).closest('.form-section').toggleClass('required');
|
|
||||||
});
|
|
||||||
$(document).on('click', '.required-toggle', function() {
|
$(document).on('click', '.required-toggle', function() {
|
||||||
$(this).closest('.form-section').toggleClass('required');
|
$(this).closest('.form-section').toggleClass('required');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Preview button functionality
|
|
||||||
$('#preview-btn').on('click', function() {
|
$('#preview-btn').on('click', function() {
|
||||||
let previewWindow = window.open('', '_blank');
|
let previewWindow = window.open('', '_blank');
|
||||||
let previewContent = `
|
let previewContent = `
|
||||||
|
@ -210,8 +198,6 @@ $(document).ready(function() {
|
||||||
previewWindow.document.close();
|
previewWindow.document.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Activate the section;repositions add section button
|
|
||||||
$(document).on('click', '.form-section', function() {
|
$(document).on('click', '.form-section', function() {
|
||||||
$('.form-section').removeClass('active');
|
$('.form-section').removeClass('active');
|
||||||
$(this).addClass('active');
|
$(this).addClass('active');
|
||||||
|
@ -228,6 +214,7 @@ $(document).ready(function() {
|
||||||
positionAddSectionButton();
|
positionAddSectionButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function collectFormData() {
|
function collectFormData() {
|
||||||
var formData = {
|
var formData = {
|
||||||
questions:[]
|
questions:[]
|
||||||
|
@ -235,35 +222,62 @@ $(document).ready(function() {
|
||||||
|
|
||||||
$('.form-section').each(function() {
|
$('.form-section').each(function() {
|
||||||
var questionData = {
|
var questionData = {
|
||||||
text : $(this).find('.untitled-question').val(),
|
text: $(this).find('.untitled-question').val(),
|
||||||
type : $(this).find('.custom-select').val(),
|
type: $(this).find('.custom-select').val(),
|
||||||
required :$(this).find('.required-toggle').is(':checked'),
|
required: $(this).find('.required-toggle').is(':checked'),
|
||||||
options:[]
|
options: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$(this).find('.option-label').each(function() {
|
$(this).find('.option-label').each(function() {
|
||||||
questionData.options.push($(this).val());
|
questionData.options.push($(this).val());
|
||||||
});
|
});
|
||||||
|
|
||||||
formData.questions.push(questionData);
|
formData.questions.push(questionData);
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log(formData);
|
console.log(formData);
|
||||||
return formData;
|
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 };
|
||||||
|
}
|
||||||
|
|
||||||
$('#submit-btn').on('click', function() {
|
$('#submit-btn').on('click', function() {
|
||||||
let formData = collectFormData();
|
let formData = collectFormData();
|
||||||
console.log(formData);
|
console.log(formData);
|
||||||
|
|
||||||
|
let validation = validateFormData(formData);
|
||||||
|
if (!validation.isValid) {
|
||||||
|
alert(validation.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: base_url + 'New_form_controller/submit_form',
|
url: base_url + 'New_form_controller/submit_form',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {formData:formData},
|
data: { formData: formData },
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
if (response.status === 'success') {
|
||||||
alert('Form submitted successfully!');
|
alert('Form submitted successfully!');
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
} else {
|
||||||
|
alert(response.message);
|
||||||
|
console.log(response);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
error: function(error) {
|
error: function(error) {
|
||||||
alert('Error submitting form!');
|
alert('Error submitting form!');
|
||||||
|
@ -272,6 +286,5 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#form-container').disableSelection();
|
$('#form-container').disableSelection();
|
||||||
});
|
});
|
|
@ -0,0 +1,93 @@
|
||||||
|
$(document).ready(function() {
|
||||||
|
let index = 1;
|
||||||
|
let activeSection = null;
|
||||||
|
|
||||||
|
function addOption(type, container) {
|
||||||
|
let optionHtml;
|
||||||
|
if (type === 'multiple-choice' || type === 'checkboxes') {
|
||||||
|
optionHtml = `
|
||||||
|
<div class="option">
|
||||||
|
<input type="${type === 'multiple-choice' ? 'radio' : 'checkbox'}" disabled>
|
||||||
|
<input type="text" class="form-control option-label">
|
||||||
|
<span class="delete-option-icon">×</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else if (type === 'dropdown') {
|
||||||
|
optionHtml = `
|
||||||
|
<div class="option">
|
||||||
|
<input type="text" class="form-control option-label">
|
||||||
|
<span class="delete-option-icon">×</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
container.append(optionHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createFormSection() {
|
||||||
|
let newSection = `
|
||||||
|
<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">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
$('#form-container').append(newSection);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
positionAddSectionButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function positionAddSectionButton() {
|
||||||
|
if (activeSection) {
|
||||||
|
let position = activeSection.position();
|
||||||
|
let buttonWidth = $('#add-section-btn').outerWidth();
|
||||||
|
let 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').on('click', function() {
|
||||||
|
createFormSection();
|
||||||
|
$('.form-section').removeClass('active');
|
||||||
|
activeSection = $('.form-section').last();
|
||||||
|
activeSection.addClass('active');
|
||||||
|
positionAddSectionButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('change', '.custom-select', function() {
|
||||||
|
let type = $(this).val();
|
||||||
|
let container = $(this).closest('.form-section').find('.options-container');
|
||||||
|
container.empty();
|
||||||
|
|
||||||
|
$(this).closest('.form-section').find('.add-option-btn').remove();
|
||||||
|
|
||||||
|
if (type === 'short-answer') {
|
||||||
|
container.append('<input type="text" class="form-control" disabled placeholder="Short answer text">');
|
||||||
|
} else if (type === 'paragraph') {
|
||||||
|
container.append('<textarea class="form-control" disabled placeholder="Paragraph text"></textarea>');
|
||||||
|
} else {
|
||||||
|
addOption(type, container);
|
||||||
|
$(this).closest('.form-section').append('<button class="btn btn-secondary add-option-btn">Add Option</button>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue