From 7a58576a1d9c8d705e2b461bf993cc91fab0ea48 Mon Sep 17 00:00:00 2001 From: torun23 Date: Mon, 22 Jul 2024 15:19:37 +0530 Subject: [PATCH] commit --- application/.htaccess | 6 - application/config/database.php | 4 +- application/config/routes.php | 2 +- application/controllers/Form_controller.php | 35 +- application/controllers/Forms.php | 95 +++--- .../controllers/New_form_controller.php | 5 +- .../controllers/Publish_controller.php | 3 +- application/controllers/Response_submit.php | 45 +-- application/models/Form_model.php | 2 +- application/models/Frontend_model.php | 14 +- application/models/New_form_model.php | 36 +- application/models/Preview_model.php | 27 +- application/models/Publish_model.php | 4 +- application/models/Response_model.php | 53 ++- application/models/Updation_model.php | 72 +++- application/views/Frontend/footer.php | 3 - application/views/Frontend/header.php | 66 ---- application/views/Tables/draft.php | 4 +- application/views/Tables/list_forms.php | 4 +- application/views/edit_form_view.php | 118 ++++--- application/views/form_preview.php | 77 ++++- application/views/form_preview_back.php | 15 +- application/views/response_details_view.php | 25 +- application/views/response_submit.php | 37 +- application/views/templates/footer.php | 8 +- application/views/templates/forms.txt | 320 ------------------ application/views/templates/forms2.txt | 320 ------------------ application/views/templates/header.php | 7 +- assets/css/form_preview_back.css | 51 +++ assets/css/header_styles.css | 2 + assets/css/response_details.view.css | 30 ++ assets/css/response_submit.css | 57 ++++ assets/css/styles.css | 9 +- assets/js/scripts.js | 35 +- 34 files changed, 635 insertions(+), 956 deletions(-) delete mode 100644 application/.htaccess delete mode 100644 application/views/Frontend/footer.php delete mode 100644 application/views/Frontend/header.php delete mode 100644 application/views/templates/forms.txt delete mode 100644 application/views/templates/forms2.txt create mode 100644 assets/css/form_preview_back.css create mode 100644 assets/css/response_details.view.css create mode 100644 assets/css/response_submit.css diff --git a/application/.htaccess b/application/.htaccess deleted file mode 100644 index 6c63ed4..0000000 --- a/application/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - - Require all denied - - - Deny from all - \ No newline at end of file diff --git a/application/config/database.php b/application/config/database.php index b0164e6..7da6d6e 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -76,8 +76,8 @@ $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', - 'username' => 'admin', - 'password' => 'Password', + 'username' => 'torun', + 'password' => 'thug@NIT20', 'database' => 'google_forms', 'dbdriver' => 'mysqli', 'dbprefix' => '', diff --git a/application/config/routes.php b/application/config/routes.php index 6c37616..c8b9593 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -9,7 +9,7 @@ $route['responses/view/(:num)'] = 'Response_submit/viewresponse/$1'; $route['default_controller'] = 'Form_controller/index_forms'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; -$route['start'] = 'home/index'; +$route['start'] = 'Form_controller/index_forms'; $route['new_form'] = 'home/create_form'; $route['title_desc'] = 'home/title'; $route['default_page'] = 'Form_controller/index_forms'; diff --git a/application/controllers/Form_controller.php b/application/controllers/Form_controller.php index 4b8149b..2f0c987 100644 --- a/application/controllers/Form_controller.php +++ b/application/controllers/Form_controller.php @@ -60,16 +60,33 @@ redirect('default_page'); // 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']); + $formData = $this->input->post('formData'); + + if (!$formData) { + echo json_encode(['status' => 'error', 'message' => 'Form data is missing']); + return; + } + + $form_id = $formData['form_id']; + $title = $formData['title']; + $description = $formData['description']; + $questions = $formData['questions']; + + $this->load->model('Updation_model'); + $updateStatus = $this->Updation_model->update_form_data($form_id, $title, $description, $questions); + + if ($updateStatus) { + echo json_encode(['status' => 'success', 'message' => 'Form updated successfully']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to update form data']); + } } + + + + + + public function index_forms_draft($form_id = null) { $this->load->model('Frontend_model'); diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index 8008669..d916740 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -34,65 +34,60 @@ class Forms extends CI_Controller } - 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 + $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('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 including 'is_required' + $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); + } - - // 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('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('templates/header'); $this->load->view('form_preview_back', $data); $this->load->view('templates/footer'); - } - - + } diff --git a/application/controllers/New_form_controller.php b/application/controllers/New_form_controller.php index 1364c51..e42fea1 100644 --- a/application/controllers/New_form_controller.php +++ b/application/controllers/New_form_controller.php @@ -6,8 +6,10 @@ class New_form_controller extends CI_Controller { public function submit_form() { if (!$this->session->userdata('logged_in')) { // If not logged in, redirect to login page - redirect('users/login'); + echo json_encode(['status' => 'error', 'message' => 'User not logged in']); + return; } + // Decode the formData from the POST request $formData = $this->input->post('formData'); @@ -20,7 +22,6 @@ class New_form_controller extends CI_Controller { if ($saveStatus) { echo json_encode(['status' => 'success', 'message' => 'Form data submitted successfully']); - } else { echo json_encode(['status' => 'error', 'message' => 'Failed to save form data']); } diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php index 3c58533..a04a305 100644 --- a/application/controllers/Publish_controller.php +++ b/application/controllers/Publish_controller.php @@ -31,11 +31,12 @@ class Publish_controller extends CI_Controller { $user_id = $this->session->userdata('user_id'); $this->load->model('Publish_model'); $data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id); - + $this->load->view('templates/header'); $this->load->view('publish_view', $data); $this->load->view('templates/footer'); } + // Method to unpublish a form public function unpublish_form($form_id) { diff --git a/application/controllers/Response_submit.php b/application/controllers/Response_submit.php index 54a32db..a23d016 100644 --- a/application/controllers/Response_submit.php +++ b/application/controllers/Response_submit.php @@ -19,24 +19,33 @@ class Response_submit extends CI_Controller { public function view_responses($form_id) { $this->load->model('Response_model'); - + $data['form'] = $this->Response_model->get_form($form_id); $data['responses'] = $this->Response_model->get_responses_by_form($form_id); - + $this->load->view('templates/header'); $this->load->view('responses_list', $data); $this->load->view('templates/footer'); - } + public function submit_form() { $this->load->model('Response_model'); $responses = $this->input->post('responses'); $user_id = $this->session->userdata('user_id'); // Assuming user_id is stored in session - + $form_id = $this->input->post('form_id'); // Assuming form_id is passed + + // Insert into responses table + $response_id = $this->Response_model->insert_response([ + 'form_id' => $form_id, + 'user_id' => $user_id, + 'submitted_at' => date('Y-m-d H:i:s') + ]); + + // Insert each answer into response_answers table foreach ($responses as $response) { $answered_text = ''; - + if (isset($response['options'])) { if (is_array($response['options'])) { $answered_text = implode(', ', $response['options']); @@ -46,28 +55,18 @@ class Response_submit extends CI_Controller { } else if (isset($response['answered_text'])) { $answered_text = $response['answered_text']; } - - // Find the max response_id for the given form_id - $this->db->select_max('response_id'); - $this->db->where('form_id', $response['form_id']); - $max_response_id = $this->db->get('responses')->row()->response_id; - - // Increment the response_id by 1 - $new_response_id = $max_response_id + 1; - + $data = [ - 'form_id' => $response['form_id'], - 'user_id' => $user_id, + 'response_id' => $response_id, 'question_id' => $response['question_id'], 'answered_text' => $answered_text, - 'response_id' => $new_response_id, 'submitted_at' => date('Y-m-d H:i:s') ]; - - $this->Response_model->insert_response($data); + + $this->Response_model->insert_response_answer($data); } - - redirect('Response_submit/view_responses/' . $response['form_id']); + + redirect('Response_submit/view_responses/' . $form_id); } @@ -87,10 +86,12 @@ class Response_submit extends CI_Controller { $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); + $data['questions_and_answers'] = $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'); } + + } diff --git a/application/models/Form_model.php b/application/models/Form_model.php index c3c4e5a..aad772a 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -21,7 +21,7 @@ class Form_model extends CI_Model { foreach ($section['options'] as $option_text) { $option_data = array( 'question_id' => $question_id, - 'text' => $option_text, + 'option_text' => $option_text, 'created_at' => date('Y-m-d H:i:s') ); diff --git a/application/models/Frontend_model.php b/application/models/Frontend_model.php index be11bb7..883a198 100644 --- a/application/models/Frontend_model.php +++ b/application/models/Frontend_model.php @@ -7,30 +7,32 @@ class Frontend_model extends CI_Model { { // 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 + + // Filter forms by user_id and order by created_at in descending order $this->db->where('user_id', $user_id); // Assuming 'user_id' is the column name in the 'forms' table + $this->db->order_by('created_at', 'DESC'); // Order by created_at column, most recent first $query = $this->db->get('forms'); return $query->result(); // Return the result as an array of objects } + public function deleteForm($id){ return $this->db->delete('forms', ['id' => $id]); } - public function getFormById($form_id) + public function getFormById($form_id) { $query = $this->db->get_where('forms', ['id' => $form_id]); return $query->row_array(); } - public function getforms_draft($user_id) { + public function getforms_draft($user_id) { $this->db->where('is_published', 0); // Filter by unpublished forms $this->db->where('user_id', $user_id); // Filter by user_id - $this->db->order_by('created_on', 'DESC'); // Sort by creation date, newest first + $this->db->order_by('created_at', 'DESC'); // Sort by creation date, newest first $query = $this->db->get('forms'); return $query->result(); } diff --git a/application/models/New_form_model.php b/application/models/New_form_model.php index c494f68..2bf6235 100644 --- a/application/models/New_form_model.php +++ b/application/models/New_form_model.php @@ -2,37 +2,41 @@ class New_form_model extends CI_Model { public function save_form_data($formId, $formData) { - if (!$formId) { - return false; // Handle error if formId is not valid + if (!$formId || !isset($formData['questions'])) { + return false; // Handle error if formId is not valid or questions are missing } - + $questions_array = $formData['questions']; - - foreach ($questions_array as $question) { + + foreach ($questions_array as $question) { $questionData = [ 'form_id' => $formId, 'text' => $question['text'], 'type' => $question['type'], - 'required' => ($question['required'] == 'true') ? 1 : 0 + 'is_required' => isset($question['is_required']) && $question['is_required'] == 'true' ? 1 : 0 ]; - + $this->db->insert('questions', $questionData); $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') { + if (in_array($question['type'], ['multiple-choice', 'checkboxes', 'dropdown'])) { foreach ($question['options'] as $option) { - $optionData = [ - 'question_id' => $questionId, - 'option_text' => $option - ]; - // Insert option into options table - $this->db->insert('options', $optionData); + if (!empty($option)) { // Avoid inserting empty options + $optionData = [ + 'question_id' => $questionId, + 'option_text' => $option // Ensure column name matches database schema + ]; + // Insert option into options table + $this->db->insert('options', $optionData); + } } } } - + return true; // Return true indicating success } + + } ?> diff --git a/application/models/Preview_model.php b/application/models/Preview_model.php index 3959b2e..4e2783d 100644 --- a/application/models/Preview_model.php +++ b/application/models/Preview_model.php @@ -1,19 +1,22 @@ db->where('id', $form_id); + $query = $this->db->get('forms'); + return $query->row(); + } - public function get_form($form_id) - { - return $this->db->get_where('forms', array('id' => $form_id))->row(); + public function get_questions($form_id) { + $this->db->where('form_id', $form_id); + $query = $this->db->get('questions'); + return $query->result(); // Ensure this returns objects with the 'is_required' field } - - public function get_questions($form_id) - { - return $this->db->get_where('questions', array('form_id' => $form_id))->result(); - } - - public function get_options($question_id) - { - return $this->db->get_where('options', array('question_id' => $question_id))->result(); + + public function get_options($question_id) { + $this->db->where('question_id', $question_id); + $query = $this->db->get('options'); + return $query->result(); // Ensure this returns the options related to the question } } \ No newline at end of file diff --git a/application/models/Publish_model.php b/application/models/Publish_model.php index b256d14..c3384c9 100644 --- a/application/models/Publish_model.php +++ b/application/models/Publish_model.php @@ -10,8 +10,10 @@ public function update_form($form_id, $data) { // Method to retrieve published forms by user public function get_published_forms_by_user($user_id) { $this->db->where('user_id', $user_id); - $this->db->where('is_published', 1); + $this->db->where('is_published', 1); + $this->db->order_by('id', 'DESC'); // Order by id column, most recent first $query = $this->db->get('forms'); return $query->result(); } + } diff --git a/application/models/Response_model.php b/application/models/Response_model.php index bb4c93f..46aa549 100644 --- a/application/models/Response_model.php +++ b/application/models/Response_model.php @@ -1,17 +1,25 @@ db->insert('responses', $data); return $this->db->insert_id(); } + public function insert_response_answer($data) { + $this->db->insert('response_answers', $data); + } + public function get_form($form_id) { $this->db->where('id', $form_id); $query = $this->db->get('forms'); return $query->row(); } +// 888888888888888888888 + + public function get_questions($form_id) { $this->db->where('form_id', $form_id); $query = $this->db->get('questions'); @@ -23,16 +31,33 @@ class Response_model extends CI_Model { $query = $this->db->get('options'); return $query->result(); } - +// 888888888888888888888 + public function get_responses_by_form($form_id) { - $this->db->select('responses.response_id, MAX(responses.submitted_at) as submitted_at, users.username'); + $this->db->select('responses.id as response_id, responses.submitted_at, users.username'); $this->db->from('responses'); $this->db->join('users', 'responses.user_id = users.id'); $this->db->where('responses.form_id', $form_id); - $this->db->group_by('responses.response_id, users.username'); + $query = $this->db->get(); + $responses = $query->result(); + + foreach ($responses as &$response) { + $response->answers = $this->get_answers_by_response_id($response->response_id); + } + + return $responses; + } + + public function get_answers_by_response_id($response_id) { + $this->db->select('response_answers.question_id, response_answers.answered_text'); + $this->db->from('response_answers'); + $this->db->where('response_answers.response_id', $response_id); $query = $this->db->get(); return $query->result(); - } public function get_responses($form_id) { + } +// 888888888888888888888 + + public function get_responses($form_id) { $this->db->where('form_id', $form_id); $query = $this->db->get('responses'); return $query->result(); @@ -41,25 +66,33 @@ class Response_model extends CI_Model { // Method to get response details public function get_response($response_id) { - $this->db->where('response_id', $response_id); - $query = $this->db->get('responses'); + $this->db->select('responses.*, users.email'); + $this->db->from('responses'); + $this->db->join('users', 'responses.user_id = users.id'); // Assuming 'user_id' is the foreign key in 'responses' + $this->db->where('responses.id', $response_id); + $query = $this->db->get(); 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->select('questions.id AS question_id, questions.text AS question_text, response_answers.answered_text, users.email'); $this->db->from('questions'); - $this->db->join('responses', 'questions.id = responses.question_id'); - $this->db->where('responses.response_id', $response_id); + $this->db->join('response_answers', 'questions.id = response_answers.question_id'); + $this->db->join('responses', 'response_answers.response_id = responses.id'); + $this->db->join('users', 'responses.user_id = users.id'); // Join to get the user's email + $this->db->where('response_answers.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); + $this->db->where('responses.id', $response_id); $query = $this->db->get(); return $query->row(); } diff --git a/application/models/Updation_model.php b/application/models/Updation_model.php index f004cb4..320d441 100644 --- a/application/models/Updation_model.php +++ b/application/models/Updation_model.php @@ -18,34 +18,74 @@ class Updation_model extends CI_Model { $query = $this->db->get('options'); return $query->result_array(); } - - public function update_form($form_id, $title, $description) { + public function update_form_data($form_id, $title, $description, $questions) { + $this->db->trans_start(); + + // Update form title and description $this->db->where('id', $form_id); $this->db->update('forms', ['title' => $title, 'description' => $description]); - } - - public function update_questions($form_id, $questions) { - // First, delete existing questions + + // Update questions $this->db->where('form_id', $form_id); $this->db->delete('questions'); - - // Insert new questions + foreach ($questions as $question) { - $this->db->insert('questions', [ + $question_data = [ 'form_id' => $form_id, - 'text' => $question['text'] - ]); + 'text' => $question['text'], + 'type' => $question['type'], + 'is_required' => $question['required'] // Correctly capture the required value + ]; + $this->db->insert('questions', $question_data); $question_id = $this->db->insert_id(); - + if (isset($question['options'])) { - foreach ($question['options'] as $option) { - $this->db->insert('options', [ + foreach ($question['options'] as $option_text) { + $option_data = [ 'question_id' => $question_id, - 'option_text' => $option - ]); + 'option_text' => $option_text + ]; + $this->db->insert('options', $option_data); } } } + + $this->db->trans_complete(); + + return $this->db->trans_status(); } + + + private function update_question_options($question_id, $options) { + // Fetch existing options for this question + $existing_options = $this->db->where('question_id', $question_id)->get('options')->result_array(); + $existing_option_texts = array_column($existing_options, 'option_text'); + + // Insert or update options + foreach ($options as $option_text) { + if (in_array($option_text, $existing_option_texts)) { + // Option already exists, no need to insert + continue; + } + + // Insert new option + $option_data = [ + 'question_id' => $question_id, + 'option_text' => $option_text + ]; + $this->db->insert('options', $option_data); + } + + // Delete options that are no longer present + $options_to_delete = array_diff($existing_option_texts, $options); + if (!empty($options_to_delete)) { + $this->db->where('question_id', $question_id); + $this->db->where_in('option_text', $options_to_delete); + $this->db->delete('options'); + } + } + + + } ?> diff --git a/application/views/Frontend/footer.php b/application/views/Frontend/footer.php deleted file mode 100644 index 12db258..0000000 --- a/application/views/Frontend/footer.php +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/application/views/Frontend/header.php b/application/views/Frontend/header.php deleted file mode 100644 index d8be42d..0000000 --- a/application/views/Frontend/header.php +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - Google Forms - - - - - - - - - -
- session->flashdata('user_registered')): ?> - ' . $this->session->flashdata('user_registered') . '

'; ?> - - - - session->flashdata('login_failed')): ?> - ' . $this->session->flashdata('login_failed') . '

'; ?> - - - - - session->flashdata('user_loggedout')): ?> - ' . $this->session->flashdata('user_loggedout') . '

'; ?> - - - - -
-
\ No newline at end of file diff --git a/application/views/Tables/draft.php b/application/views/Tables/draft.php index f813272..0d7355b 100644 --- a/application/views/Tables/draft.php +++ b/application/views/Tables/draft.php @@ -9,7 +9,7 @@

- List of Forms +Drafts

@@ -33,7 +33,7 @@ href="id); ?>">title; ?> description; ?> - created_on; ?> + created_at; ?> Edit diff --git a/application/views/Tables/list_forms.php b/application/views/Tables/list_forms.php index 91c6d96..8fe06ea 100644 --- a/application/views/Tables/list_forms.php +++ b/application/views/Tables/list_forms.php @@ -32,7 +32,7 @@ href="id); ?>">title; ?> description; ?> - created_on; ?> + created_at; ?> is_published ? 'Published' : 'Draft'); ?> @@ -44,4 +44,4 @@
- \ No newline at end of file + diff --git a/application/views/edit_form_view.php b/application/views/edit_form_view.php index 5cb4d8c..214dd82 100644 --- a/application/views/edit_form_view.php +++ b/application/views/edit_form_view.php @@ -8,6 +8,7 @@ + @@ -18,62 +19,61 @@ -
- -
-
- - - - -
-
- db->where('question_id', $question['id']); - $options = $this->db->get('options')->result_array(); - foreach ($options as $option): - ?> -
- - × + +
+
+ + + + +
+
+ db->where('question_id', $question['id']); + $options = $this->db->get('options')->result_array(); + foreach ($options as $option): + ?> +
+ + × +
+ +
+ + + +
- -
- - -
-
- - + diff --git a/application/views/form_preview.php b/application/views/form_preview.php index 617fbe0..8b40637 100644 --- a/application/views/form_preview.php +++ b/application/views/form_preview.php @@ -1,3 +1,75 @@ + + + + + + Form Preview - Google Forms + + + + +

title; ?>

@@ -19,7 +91,7 @@
- type == 'checkbox'): ?> + type == 'checkboxes'): ?>
options as $option): ?>
@@ -50,4 +122,5 @@ Publish
- \ No newline at end of file + + diff --git a/application/views/form_preview_back.php b/application/views/form_preview_back.php index c2e8505..a14f07b 100644 --- a/application/views/form_preview_back.php +++ b/application/views/form_preview_back.php @@ -1,3 +1,13 @@ + + + + + + Form Preview - Google Forms + + + +

title; ?>

@@ -19,7 +29,7 @@
- type == 'checkbox'): ?> + type == 'checkboxes'): ?>
options as $option): ?>
@@ -50,4 +60,5 @@ Back
- \ No newline at end of file + + diff --git a/application/views/response_details_view.php b/application/views/response_details_view.php index 4b65971..ef9aec3 100644 --- a/application/views/response_details_view.php +++ b/application/views/response_details_view.php @@ -1,15 +1,28 @@ - -
+ + + + + + Response Details + + + + +

title; ?>

-

description; ?>

+

description; ?>

+ +

User Email: email; ?>

- +
- - +

question_text; ?>

+
answered_text; ?>
+ + diff --git a/application/views/response_submit.php b/application/views/response_submit.php index 509ff47..31a7e7d 100644 --- a/application/views/response_submit.php +++ b/application/views/response_submit.php @@ -5,14 +5,24 @@ Form Preview - Google Forms - + + +
@@ -20,14 +30,14 @@

title; ?>

description; ?>

-
+
-
+
- + type == 'multiple-choice'): ?> options as $option): ?>
@@ -35,7 +45,7 @@
- type == 'checkbox'): ?> + type == 'checkboxes'): ?> options as $option): ?>
@@ -56,9 +66,8 @@
- +
- \ No newline at end of file diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php index 353de2a..35490a2 100644 --- a/application/views/templates/footer.php +++ b/application/views/templates/footer.php @@ -1,7 +1,7 @@ -
- + diff --git a/application/views/templates/forms.txt b/application/views/templates/forms.txt deleted file mode 100644 index 6584653..0000000 --- a/application/views/templates/forms.txt +++ /dev/null @@ -1,320 +0,0 @@ - - - - - - - Google Form Clone - - - - - - - - - - -
-
- -

Untitled Form

- -
-
- - - -
- - - - - - - - -$(document).ready(function() { - let index = 1; - let activeSection = null; - - // Add option function - function addOption(type, container) { - let optionIndex = container.children().length + 1; - let optionHtml; - if (type === 'multiple-choice' || type === 'checkboxes') { - optionHtml = ` -
- - - × -
- `; - } else if (type === 'dropdown') { - optionHtml = ` -
- - × -
- `; - } - container.append(optionHtml); - } - - // Form section function - function createFormSection() { - let newSection = ` -
-
- ${index === 1 ? '
' : ''} - - - - -
-
-
- `; - $('#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' - }); - } - } - - // Event handler is triggered - // creates a new form section;sets it as active;repositions the add section button - $('#add-section-btn').on('click', function() { - createFormSection(); - $('.form-section').removeClass('active'); - activeSection = $('.form-section').last(); - activeSection.addClass('active'); - positionAddSectionButton(); - }); - - // It updates the options container based on the selected type, adding the necessary input fields or buttons. - $(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(''); - } else if (type === 'paragraph') { - container.append(''); - } else { - addOption(type, container); - $(this).closest('.form-section').append(''); - } - }); - - // add option event handler - // adds a new option to the options container and updates the option numbers - $(document).on('click', '.add-option-btn', function() { - let type = $(this).closest('.form-section').find('.custom-select').val(); - let container = $(this).closest('.form-section').find('.options-container'); - addOption(type, container); - // refreshOptionNumbers(container); - }); - - // removes the section;updates the active section;repositions add section button - $(document).on('click', '.delete-section-icon', function() { - let section = $(this).closest('.form-section'); - let prevSection = section.prev('.form-section'); - let nextSection = section.next('.form-section'); - section.remove(); - if (section.hasClass('active')) { - activeSection = null; - } - if (prevSection.length > 0) { - prevSection.find('.delete-section-icon').appendTo(prevSection.find('.form-section')); - activeSection = prevSection; - } else if (nextSection.length > 0) { - nextSection.find('.delete-section-icon').appendTo(nextSection.find('.form-header')); - activeSection = nextSection; - } - - positionAddSectionButton(); - }); - - // delete option - $(document).on('click', '.delete-option-icon', function() { - let option = $(this).closest('.option'); - let container = option.closest('.options-container'); - option.remove(); -K }); - - // Event handler for required toggle button - $(document).on('click', '.required-toggle', function() { - $(this).closest('.form-section').toggleClass('required'); - }); - - // Preview button functionality - $('#preview-btn').on('click', function() { - let previewWindow = window.open('', '_blank'); - let previewContent = ` - - - Form Preview - - - - -
-
-

Untitled Form

-
- `; - $('.form-section').each(function() { - previewContent += '
'; - previewContent += '
'; - previewContent += ''; - previewContent += '
'; - let type = $(this).find('.custom-select').val(); - let optionsContainer = $(this).find('.options-container'); - - if (type === 'multiple-choice') { - optionsContainer.find('.option').each(function() { - previewContent += ` -
- - -
- `; - }); - } else if (type === 'checkboxes') { - optionsContainer.find('.option').each(function() { - previewContent += ` -
- - -
- `; - }); - } else if (type === 'short-answer') { - previewContent += ''; - } else if (type === 'paragraph') { - previewContent += ''; - } else if (type === 'dropdown') { - let dropdownHtml = ''; - previewContent += dropdownHtml; - } - previewContent += '
'; - }); - previewContent += ` - -
- - - `; - previewWindow.document.write(previewContent); - previewWindow.document.close(); - }); - - // Activate the section;repositions add section button - $(document).on('click', '.form-section', function() { - $('.form-section').removeClass('active'); - $(this).addClass('active'); - activeSection = $(this); - positionAddSectionButton(); - }); - - $('#form-container').sortable({ - placeholder: 'ui-state-highlight', - start: function (event, ui) { - ui.placeholder.height(ui.item.height()); - }, - stop: function (event, ui) { - positionAddSectionButton(); - } - }); - - $('#form-container').disableSelection(); -}); -i have shared with you my html file as well as the js file, -i want you to update the js file in such a way that once i click the submit button in the forms ui section i want them to get updated in the database through post data. -each of the question text or the options i create and the type of question such as dropdown or checkbox,try to enclose every data under an active form ,in a similar way as you fetched all the information to show in the preview window. - - for each of the question text in each div created , i want to save in the text colomn in the questions table and for the type of question that is dropdown or multiple choice or checkbox etc i want to save them as 1,2,3,4 or 5 in the type colomn in the questions table and if the required button is selected it should reflect in the required colomn in the table as 0 or 1, for the options created in each of the div tag or the question tag should be saved in the text colomn in the options table. -so that i can retreive the data when required. -i want you also to create all the controllers and the models and the view required to perform the above task,i have created a login page after authorization the user is able to create the form -so with respect to that particular users id , all the above contents should be updated in the database -i will explain you the structure of my database - have also created a database in the phpmyadmin as google_forms wherein i currently have 4 tables as users,forms,questions,options -in the users table id,username,email,password,created_at where id isthe primary key . -The forms table has id,user_id as the foreign key which is refernced to the id from users table,created_at and description colomn. -questions table has id as the primary key,form_id as the foreign key which is referenced to the id from the forms table ,text,type,required ,created_at. -and the options table has id as the primary key ,question_id as the foreign key which is referenced to the id from the questions table. -finally i want a updation in my js file and html file as suggested -and i want all the controller and models to perform this task in the codeigniter \ No newline at end of file diff --git a/application/views/templates/forms2.txt b/application/views/templates/forms2.txt deleted file mode 100644 index f6c5c0c..0000000 --- a/application/views/templates/forms2.txt +++ /dev/null @@ -1,320 +0,0 @@ -**********MODEL**************** - -db->trans_start(); - - foreach ($form_data as $section) { - $question_data = array( - 'form_id' => $section['form_id'], - 'text' => $section['text'], - 'type' => $section['type'], - 'required' => $section['required'], - 'created_at' => date('Y-m-d H:i:s') - ); - - $this->db->insert('questions', $question_data); - $question_id = $this->db->insert_id(); - - foreach ($section['options'] as $option_text) { - $option_data = array( - 'question_id' => $question_id, - 'text' => $option_text, - 'created_at' => date('Y-m-d H:i:s') - ); - - $this->db->insert('options', $option_data); - } - } - - $this->db->trans_complete(); - - if ($this->db->trans_status() === FALSE) { - return false; - } else { - return true; - } - } -} -********************Controller********************** -load->model('Form_model'); - } - - public function submit() { - $form_data = json_decode($this->input->raw_input_stream, true); - - if ($this->Form_model->save_form($form_data)) { - $response = array('status' => 'success', 'message' => 'Form submitted successfully.'); - } else { - $response = array('status' => 'error', 'message' => 'Error submitting form.'); - } - - echo json_encode($response); - } -} -***********UPDATED HTML************************* -### Updated HTML -```html - - - - - - - Google Form Clone - - - - - - - - - - -
-
- -

Untitled Form

- -
-
- - - -
- - - - - - - - - - - - -*************************************88************************* -new Controller -load->model('Form_model'); // Load your Form_model - } - - public function save() { - // Handle AJAX post data - $form_data = $this->input->post('form_data'); // Assuming your AJAX post sends 'form_data' - - if (!empty($form_data)) { - foreach ($form_data as $section) { - $question_data = array( - 'form_id' => $section['form_id'], - 'text' => $section['text'], - 'type' => $section['type'], - 'required' => $section['required'], - 'created_at' => date('Y-m-d H:i:s') - ); - - $question_id = $this->Form_model->save_question($question_data); - - // Save options for this question - foreach ($section['options'] as $option_text) { - $option_data = array( - 'question_id' => $question_id, - 'text' => $option_text, - 'created_at' => date('Y-m-d H:i:s') - ); - - $this->Form_model->save_option($option_data); - } - } - - echo json_encode(array('success' => true)); - } else { - echo json_encode(array('success' => false)); - } - } - -} -******************************newMODEL********** -db->insert('questions', $question_data); - return $this->db->insert_id(); - } - - public function save_option($option_data) { - $this->db->insert('options', $option_data); - } - -} -******************JAVASCRIPT************updatead -function collectFormData() { - let formData = []; - let formId = $('#form-id').val(); - - $('.form-section').each(function() { - let questionText = $(this).find('.untitled-question').val(); - let type = $(this).find('.custom-select').val(); - let required = $(this).find('.required-toggle').is(':checked'); - let options = []; - - $(this).find('.option-label').each(function() { - options.push($(this).val()); - }); - - formData.push({ - form_id: formId, - text: questionText, - type: type, - required: required, - options: options - }); - }); - - $.ajax({ - url: 'Questions/save', // Endpoint to handle saving questions - type: 'POST', - dataType: 'json', - data: { form_data: formData }, - success: function(response) { - if (response.success) { - alert('Form data saved successfully!'); - // Handle success actions - } else { - alert('Failed to save form data.'); - // Handle failure actions - } - }, - error: function(xhr, status, error) { - alert('Error: ' + error); - // Handle error actions - } - }); -} diff --git a/application/views/templates/header.php b/application/views/templates/header.php index ce55d87..98ef812 100644 --- a/application/views/templates/header.php +++ b/application/views/templates/header.php @@ -7,9 +7,14 @@ - + + + + + + diff --git a/assets/css/form_preview_back.css b/assets/css/form_preview_back.css new file mode 100644 index 0000000..4e2c3ff --- /dev/null +++ b/assets/css/form_preview_back.css @@ -0,0 +1,51 @@ +body { background-color: rgb(240, 235, 248); } +.container { margin-top: 30px; } +.form-header { + background-color: white; + padding: 20px; + margin-left: 240px; + border-radius: 10px 10px 0 0; + display: flex; + flex-direction: column; + align-items: flex-start; + border-top: 10px solid rgb(103, 58, 183); + width: 56%; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + margin-bottom: 20px; +} +.form-header h2 { margin: 0; } +.form-header h4 { color: rgba(0, 0, 0, 0.5); } +.form-section { + background-color: white; + margin-bottom: 30px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + padding: 20px; +} +.question-section { + margin-bottom: 10px; +} +.question-label { + font-weight: bold; +} +.options-container { + margin-top: 10px; +} +.option { + margin-bottom: 10px; + display: flex; + align-items: center; +} +.option input[type="checkbox"] { + margin-right: 10px; + width: 16px; /* Adjust size of checkbox */ + height: 16px; /* Adjust size of checkbox */ +} +.option input[type="radio"] { + margin-right: 10px; + width: 16px; /* Adjust size of radio button */ + height: 16px; /* Adjust size of radio button */ +} +.option label { + margin: 0; +} \ No newline at end of file diff --git a/assets/css/header_styles.css b/assets/css/header_styles.css index d60bca3..fda9ce0 100644 --- a/assets/css/header_styles.css +++ b/assets/css/header_styles.css @@ -112,3 +112,5 @@ a.pagination-link{ #basetable1 th, #basetable1 td { border: 1px solid #3333336c; /* Darker border color for table cells */ } +/* Custom DataTables pagination styles */ + diff --git a/assets/css/response_details.view.css b/assets/css/response_details.view.css new file mode 100644 index 0000000..0ab97b4 --- /dev/null +++ b/assets/css/response_details.view.css @@ -0,0 +1,30 @@ + +.form-header { + margin-bottom: 20px; + text-align: left; +} +.form-description, .submitted-at, .user-email { +color: rgba(0, 0, 0, 0.5); /* Transparent text */ +margin-bottom: 10px; +text-align: left; /* Align text left */ +display: block; /* Ensure each element is a block element */ +width: 100%; /* Ensure each element takes the full width of the container */ +padding-left: 0; /* Ensure no padding is affecting alignment */ +} + +.form-section { + margin-bottom: 20px; +} +.question-section { + border: 1px solid #ddd; + padding: 15px; + border-radius: 5px; + background-color: #f9f9f9; + text-align: left; +} +.container { +width: 65%; /* Or any specific width */ +/* text-align: left; Ensure the container itself is aligned left */ +padding: 0; /* Ensure no padding is affecting alignment */ +margin: 0 auto; /* Center the container if needed */ +} diff --git a/assets/css/response_submit.css b/assets/css/response_submit.css new file mode 100644 index 0000000..59d45b2 --- /dev/null +++ b/assets/css/response_submit.css @@ -0,0 +1,57 @@ +body { background-color: rgb(240, 235, 248); } +.container { margin-top: 30px; } +.form-header { + background-color: white; + padding: 20px; + margin-left: 240px; + border-radius: 10px 10px 0 0; + display: flex; + flex-direction: column; + align-items: flex-start; + border-top: 10px solid rgb(103, 58, 183); + width: 56%; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + margin-bottom: 20px; +} +.form-header h2 { margin: 0; } +.form-header h4 { color: rgba(0, 0, 0, 0.5); } +.form-section { + background-color: white; + width: 56%; + margin-left: 240px; + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + margin-bottom: 30px; +} +.question-container { + border: 1px solid #ddd; + padding: 15px; + border-radius: 5px; + background-color: #f9f9f9; + margin-bottom: 20px; +} +.option { + margin-bottom: 10px; + display: flex; + align-items: center; +} +.option input[type="radio"], +.option input[type="checkbox"] { + margin-right: 10px; +} +.required-field::after { + content: '*'; + color: red; + margin-left: 5px; +} +.form-section { + background-color: white; + margin-bottom: 30px; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + padding: 20px; +} +.question-container { + margin-bottom: 20px; +} \ No newline at end of file diff --git a/assets/css/styles.css b/assets/css/styles.css index 9adafaf..086faf8 100644 --- a/assets/css/styles.css +++ b/assets/css/styles.css @@ -215,4 +215,11 @@ input:checked + .slider:before { } .body_header_bg{ background-color: rgb(240,235,248); -} \ No newline at end of file +} +table a:not(.btn) { + color: blue !important; +} + +table a:not(.btn):hover { + color: darkblue !important; +} diff --git a/assets/js/scripts.js b/assets/js/scripts.js index 780aed2..f30d96e 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -217,26 +217,32 @@ function addOption(type, container) { function collectFormData() { var formData = { - questions:[] + questions: [] }; - + $('.form-section').each(function() { + var questionType = $(this).find('.custom-select').val(); var questionData = { text: $(this).find('.untitled-question').val(), - type: $(this).find('.custom-select').val(), + type: questionType, required: $(this).find('.required-toggle').is(':checked'), options: [] }; - - $(this).find('.option-label').each(function() { - questionData.options.push($(this).val()); - }); - + + // Only add options if the question type supports them + if (questionType === 'multiple-choice' || questionType === 'checkboxes' || questionType === 'dropdown') { + $(this).find('.option-label').each(function() { + questionData.options.push($(this).val()); + }); + } + formData.questions.push(questionData); }); - console.log(formData); + + // console.log(formData); return formData; } + function validateFormData(formData) { for (let question of formData.questions) { @@ -254,17 +260,16 @@ function addOption(type, container) { } return { isValid: true }; } - $('#submit-btn').on('click', function() { let formData = collectFormData(); console.log(formData); - + let validation = validateFormData(formData); if (!validation.isValid) { alert(validation.message); return; } - + $.ajax({ url: base_url + 'New_form_controller/submit_form', type: 'POST', @@ -273,7 +278,8 @@ function addOption(type, container) { success: function(response) { if (response.status === 'success') { alert('Form submitted successfully!'); - console.log(response); + // Redirect to Form_controller/index_forms + window.location.href = base_url + 'Form_controller/index_forms'; } else { alert(response.message); console.log(response); @@ -281,10 +287,11 @@ function addOption(type, container) { }, error: function(error) { alert('Error submitting form!'); + window.location.href = base_url + 'Form_controller/index_forms'; console.log(error); } }); }); - + $('#form-container').disableSelection(); });