diff --git a/application/config/config.php b/application/config/config.php index f168a7d..8dfc488 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -23,7 +23,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | a PHP script and you can easily do that on your own. | */ -$config['base_url'] = 'http://192.168.2.110/google_forms'; +$config['base_url'] = 'http://localhost/google_forms'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Form_controller.php b/application/controllers/Form_controller.php index e5952cb..fc5c28f 100644 --- a/application/controllers/Form_controller.php +++ b/application/controllers/Form_controller.php @@ -3,26 +3,19 @@ defined('BASEPATH') or exit('No direct script access allowed'); class Form_controller extends CI_Controller { - - public function index() { - // Fetch the data - $this->load->model('Form_model'); - $this->load->model('Response_model'); - $data['total_forms'] = $this->Form_model->get_total_forms(); - $data['published_forms'] = $this->Form_model->get_published_forms(); - $data['total_responses'] = $this->Response_model->get_total_responses(); -// var_dump($data); - // Load the view and pass the data - $this->load->view('list_forms', $data); - } + public function index_forms($form_id = null) { $this->load->model('Frontend_model'); + $this->load->model('Form_model'); + $this->load->model('Response_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'); } + $user_id = $this->session->userdata('user_id'); // Retrieve form title from the forms table using form_id $form_title = 'Untitled Form'; // Default title @@ -32,15 +25,20 @@ class Form_controller extends CI_Controller $form_title = $form['title']; } } - + + // Fetch data from models + $data['total_forms'] = $this->Form_model->get_total_forms($user_id); + $data['published_forms'] = $this->Form_model->get_published_forms($user_id); + $data['total_responses'] = $this->Response_model->get_total_responses($user_id); + $data['forms'] = $this->Form_model->get_all_forms($user_id); + $data['form_title'] = $form_title; + // Load views and data if user is logged in $this->load->view('templates/header'); - - $data = $this->Frontend_model->getforms(); - $this->load->view('Tables/list_forms', ['forms' => $data, 'form_title' => $form_title]); - + $this->load->view('Tables/list_forms', $data); $this->load->view('templates/footer'); } + public function delete($id) { diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php index 3587573..31370b2 100644 --- a/application/controllers/Publish_controller.php +++ b/application/controllers/Publish_controller.php @@ -34,7 +34,7 @@ class Publish_controller extends CI_Controller { $this->load->view('templates/header'); $this->load->view('publish_view', $data); - $this->load->view('templates/footer'); + // $this->load->view('templates/footer'); } diff --git a/application/controllers/Response_submit.php b/application/controllers/Response_submit.php index 6032f5b..a98f813 100644 --- a/application/controllers/Response_submit.php +++ b/application/controllers/Response_submit.php @@ -25,7 +25,7 @@ class Response_submit extends CI_Controller { $this->load->view('templates/header'); $this->load->view('responses_list', $data); - $this->load->view('templates/footer'); + // $this->load->view('templates/footer'); } @@ -93,5 +93,37 @@ class Response_submit extends CI_Controller { $this->load->view('templates/footer'); } + public function summary($form_id) +{ + $this->load->model('Form_model'); + $this->load->model('Response_model'); + + // Check if the user is logged in + if (!$this->session->userdata('logged_in')) { + redirect('users/login'); + } + + // Fetch form details + $form = $this->Form_model->get_form_by_id($form_id); + if (!$form) { + show_404(); + } + + // Fetch summary data + $summary_data = $this->Response_model->get_summary_data($form_id); + + $data['form'] = $form; + $data['summary_data'] = $summary_data; + + $this->load->view('templates/header'); + $this->load->view('Forms/summary', $data); + $this->load->view('templates/footer'); +} + + + + + + } diff --git a/application/models/Form_model.php b/application/models/Form_model.php index 0dea148..df48707 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -4,22 +4,38 @@ defined('BASEPATH') or exit('No direct script access allowed'); class Form_model extends CI_Model { + // Function to get form details by ID + public function get_form_by_id($form_id) + { + $this->load->database(); + $this->db->where('id', $form_id); + $query = $this->db->get('forms'); + return $query->row(); + } // Get the total number of forms - public function get_total_forms() - { - $this->load->database(); - - return $this->db->count_all('forms'); + public function get_total_forms($user_id) { + // Ensure user_id is passed as a parameter and used in the query + $this->db->where('user_id', $user_id); + return $this->db->count_all_results('forms'); // Use count_all_results to ensure WHERE conditions are applied } - - // Get the number of published forms - public function get_published_forms() - { - $this->load->database(); - + + // Function to count published forms + public function get_published_forms($user_id) { + // Ensure user_id and is_published are passed as parameters and used in the query + $this->db->where('user_id', $user_id); $this->db->where('is_published', 1); - return $this->db->count_all_results('forms'); + return $this->db->count_all_results('forms'); // Use count_all_results to ensure WHERE conditions are applied } + + // Function to get all forms + public function get_all_forms($user_id) + { + $this->db->where('user_id', $user_id); + $this->db->order_by('created_at', 'DESC'); + $query = $this->db->get('forms'); + return $query->result(); + } + public function save_form($form_data) { $this->db->trans_start(); diff --git a/application/models/Response_model.php b/application/models/Response_model.php index 75d64d0..1a37424 100644 --- a/application/models/Response_model.php +++ b/application/models/Response_model.php @@ -6,10 +6,16 @@ class Response_model extends CI_Model } // Get the total number of responses - public function get_total_responses() { - return $this->db->count_all('responses'); + public function get_total_responses($user_id) { + // Join the responses table with the forms table + $this->db->select('responses.id'); + $this->db->from('responses'); + $this->db->join('forms', 'responses.form_id = forms.id'); + // Filter by user_id in the forms table + $this->db->where('forms.user_id', $user_id); + return $this->db->count_all_results(); } - + public function insert_response($data) { $this->db->insert('responses', $data); @@ -113,5 +119,54 @@ class Response_model extends CI_Model $query = $this->db->get(); return $query->row(); } + + + // Function to get summary data for a form + public function get_summary_data($form_id) + { + $this->load->database(); + + $summary_data = array(); + + // Get questions for the form + $this->db->select('id,text,type'); + $this->db->where('form_id', $form_id); + $questions = $this->db->get('questions')->result_array(); + + // Get responses count + $this->db->where('form_id', $form_id); + $responses = $this->db->get('responses')->result_array(); + + if (count($responses) > 0) { + $response_ids = array_column($responses, 'id'); + + // Get response answers + $this->db->where_in('response_id', $response_ids); + $response_answers = $this->db->get('response_answers')->result_array(); + + // Process response answers + foreach ($questions as $question) { + $question_id = $question['id']; + $summary_data[$question_id] = [ + 'text' => $question['text'], + 'type' => $question['type'], + 'answers' => [] + ]; + } + + foreach ($response_answers as $answer) { + $question_id = $answer['question_id']; + $answered_text = $answer['answered_text']; + + if (!isset($summary_data[$question_id]['answers'][$answered_text])) { + $summary_data[$question_id]['answers'][$answered_text] = 1; + } else { + $summary_data[$question_id]['answers'][$answered_text]++; + } + } + } + + return $summary_data; + } } diff --git a/application/views/Forms/summary.php b/application/views/Forms/summary.php new file mode 100644 index 0000000..75faa79 --- /dev/null +++ b/application/views/Forms/summary.php @@ -0,0 +1,100 @@ + + + + + + Form Summary + + + + + +
+
+
+
+
+

Summary for "title; ?>"

+ Back to Responses +
+
+
+ +
+ +
+ +
+ +
+
    + +
  • + +
+
+ + +
+
+
+
+
+
+ + + diff --git a/application/views/Tables/draft.php b/application/views/Tables/draft.php index 140b011..a6ddba5 100644 --- a/application/views/Tables/draft.php +++ b/application/views/Tables/draft.php @@ -6,7 +6,9 @@ Form List - + + + -
+
-
+
+
+
+
Total Forms Created
+

+
+
+
+
+
+
+
Published Forms
+

+
+
+
+
+
+
+
Responses Submitted
+

+
+
+
+
+ + +
+
session->flashdata('status')): ?> @@ -24,36 +106,37 @@ session->flashdata('status'); ?>
-

Drafts

+

List of Forms

+ - + + - - - + + - + - - - + + + - @@ -66,31 +149,3 @@ - - - diff --git a/application/views/edit_form_view.php b/application/views/edit_form_view.php index cca0cdb..a30a86e 100644 --- a/application/views/edit_form_view.php +++ b/application/views/edit_form_view.php @@ -22,7 +22,18 @@ @@ -140,7 +151,15 @@ $(document).ready(function () { var base_url = ''; var activeSection = null; - + $('#form-container').sortable({ + placeholder: 'ui-state-highlight', + start: function (event, ui) { + ui.placeholder.height(ui.item.height()); + }, + stop: function (event, ui) { + positionAddSectionButton(); + } + }); function positionAddSectionButton() { if (activeSection) { var position = activeSection.position(); @@ -294,7 +313,7 @@ positionAddSectionButton(); }); - positionAddSectionButton(); + // positionAddSectionButton(); $(document).ready(function () { var base_url = ''; diff --git a/application/views/form_preview.php b/application/views/form_preview.php index 1d3fda1..02b03e2 100644 --- a/application/views/form_preview.php +++ b/application/views/form_preview.php @@ -8,10 +8,7 @@ - +

title; ?>

diff --git a/application/views/publish_view.php b/application/views/publish_view.php index ab1ee55..27c51a7 100644 --- a/application/views/publish_view.php +++ b/application/views/publish_view.php @@ -1,95 +1,3 @@ -
@@ -100,9 +8,7 @@ session->flashdata('status'); ?>
-

- Published Forms -

+

Published Forms

@@ -121,24 +27,17 @@ foreach ($forms as $row): ?>
- + -
DraftsForms TitleDescription Created OnEditDeletePreviewStatusResponses
title; ?>created_at)); ?> - Edit + + title; ?> + description; ?>created_at; ?> + is_published ? 'Published' : 'Draft'); ?> - Delete - - +
- title; ?> - title; ?> - response_link; ?> + response_link; ?> @@ -149,4 +48,51 @@
-
\ No newline at end of file +
+
+
+
+ \ No newline at end of file diff --git a/application/views/response_submit.php b/application/views/response_submit.php index 52fa47a..557910d 100644 --- a/application/views/response_submit.php +++ b/application/views/response_submit.php @@ -59,17 +59,46 @@ .popup-message { display: none; position: fixed; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); + top: 10%; + left: 40%; + transform: translate(-20%, -40%); background-color: white; - padding: 20px; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + padding: 30px; + width: 80%; + max-width: 600px; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); z-index: 1000; + border-top: 10px solid rgb(103, 58, 183); + border-radius: 8px; + text-align: center; + } + + .popup-message h2 { + margin-top: 0; + color: rgb(103, 58, 183); + font-size: 24px; /* Increase font size */ + } + + .popup-message p { + font-size: 18px; /* Increase font size */ + } + + .popup-message button { + background-color: rgb(103, 58, 183); + color: white; + border: none; + padding: 10px 20px; + border-radius: 5px; + cursor: pointer; + } + + .popup-message button:hover { + background-color: darkviolet; } +
+ + + Responses for "<?php echo $form->title; ?>" + -
-
-
-
-
- session->flashdata('status')): ?> -
- session->flashdata('status'); ?> -
- -

- Responses for "title; ?>" -

-
-
- - - - - - - - - - + color: darkblue; /* Dark blue color for title */ + } + + + +
+
+
+
+
+ session->flashdata('status')): ?> +
+ session->flashdata('status'); ?> +
+ +

Responses for "title; ?>"

+ +
+
+
UsernameSubmitted AtView
+ - - - - + + + - - -
username; ?>submitted_at; ?> - - - - UsernameSubmitted AtView
+ + + + + username; ?> + submitted_at; ?> + + + + + + + + + +
-
+ + diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php index ec5129f..ddd7348 100644 --- a/application/views/templates/footer.php +++ b/application/views/templates/footer.php @@ -1,17 +1,78 @@ + + \ No newline at end of file diff --git a/application/views/templates/header.php b/application/views/templates/header.php index 11116dd..8da2f79 100644 --- a/application/views/templates/header.php +++ b/application/views/templates/header.php @@ -30,6 +30,86 @@ text-decoration: none !important; /* Ensures no underline on hover */ background: none !important; /* Ensures no background color on hover */ } +.title-column { + color: darkblue; + } + + .draft-row { + background-color: #f0f0f0; + } + +.switch { + position: relative; + display: inline-block; + width: 34px; + height: 20px; + } + + .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; + } + + .slider:before { + position: absolute; + content: ""; + height: 14px; + width: 14px; + left: 3px; + bottom: 3px; + background-color: white; + transition: .4s; + } + + input:checked + .slider { + background-color: #673AB7; + } + + input:checked + .slider:before { + transform: translateX(14px); + } + + .slider.round { + border-radius: 20px; + } + + .slider.round:before { + border-radius: 50%; + } + + .switch .tooltip { + visibility: hidden; + width: 70px; + background-color: #555; + color: #fff; + text-align: center; + border-radius: 5px; + padding: 5px; + position: absolute; + z-index: 1; + bottom: 125%; + left: 290%; + margin-left: -60px; + opacity: 0; + transition: opacity 0.3s; + } + + .switch:hover .tooltip { + visibility: visible; + opacity: 1; + }