diff --git a/application/config/database.php b/application/config/database.php index de9475a..e8ab51e 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' => 'root', - 'password' => '', + 'username' => 'jostheta', + 'password' => 'Pa$$w0rd', 'database' => 'gforms', 'dbdriver' => 'mysqli', 'dbprefix' => '', diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index 47b1700..37dde2e 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -145,23 +145,17 @@ class Forms extends CI_Controller } public function publish_form($form_id) { - - // Update is_published to 1 - $this->Form_model->update_form($form_id, ['is_published' => 1]); - // Generate a unique link $response_link = base_url("forms/respond/" . $form_id); - - // Prepare data for the view - $data = []; - $data['response_link'] = $response_link; - $data['forms'] = $this->Form_model->get_all_forms(); - - $this->load->view('templates/header'); - $this->load->view('forms/myforms',$data); - $this->load->view('templates/footer'); - - + + // Update is_published to 1 and set the response link + $this->Form_model->update_form($form_id, [ + 'is_published' => 1, + 'response_link' => $response_link + ]); + + // Redirect to the list_user_forms function + redirect('forms/list_user_published_forms'); } public function respond($form_id){ @@ -214,14 +208,40 @@ class Forms extends CI_Controller // View a specific response public function view_response($response_id) { + // Get the response details $data['response'] = $this->Form_model->get_response($response_id); - $data['form'] = $this->Form_model->get_form($data['response']->form_id); - - $this->load->view('templates/header'); - $this->load->view('forms/view_response', $data); - $this->load->view('templates/footer'); + if (empty($data['response'])) { + show_404(); + } + + // Get the form details using the form ID from the response + $form_id = $data['response']->form_id; + $data['form'] = $this->Form_model->get_form($form_id); + + // Get the questions and their options for the form + $data['questions'] = $this->Form_model->get_questions_by_form_id($form_id); + foreach ($data['questions'] as &$question) { + $question->options = $this->Form_model->get_options_by_question_id($question->question_id); } + + // Load the views + $this->load->view('templates/header'); + $this->load->view('forms/view_response', $data); + $this->load->view('templates/footer'); +} + +public function list_user_published_forms() { + $user_id = $this->session->userdata('user_id'); + $data['forms'] = $this->Form_model->get_published_forms_by_user($user_id); + + $this->load->view('templates/header'); + $this->load->view('forms/user_forms', $data); + $this->load->view('templates/footer'); +} + + + } diff --git a/application/models/Form_model.php b/application/models/Form_model.php index ab8710e..cf9b812 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -177,6 +177,14 @@ class Form_model extends CI_Model { $query = $this->db->get('forms'); return $query->row(); } + + public function get_published_forms_by_user($user_id) { + $this->db->where('user_id', $user_id); + $this->db->where('is_published', 1); // Ensure only published forms are retrieved + $query = $this->db->get('forms'); + return $query->result(); + } + } diff --git a/application/views/forms/mydrafts.php b/application/views/forms/mydrafts.php index 17e7116..5e407fd 100644 --- a/application/views/forms/mydrafts.php +++ b/application/views/forms/mydrafts.php @@ -25,4 +25,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/application/views/forms/myforms.php b/application/views/forms/myforms.php index 12f059f..e2bbb52 100644 --- a/application/views/forms/myforms.php +++ b/application/views/forms/myforms.php @@ -7,7 +7,6 @@ Form Title Published Created At - Response Links @@ -17,13 +16,6 @@ title, ENT_QUOTES, 'UTF-8') ?> is_published == 0)?'No':'Yes'?> created_at)); ?> - - is_published == 1): ?> - Response link - - Not Published - - diff --git a/application/views/forms/user_forms.php b/application/views/forms/user_forms.php index e956634..4cd2c30 100644 --- a/application/views/forms/user_forms.php +++ b/application/views/forms/user_forms.php @@ -1,23 +1,26 @@ -
-

Your Forms

+
+

Published Forms

+ + - + + - + diff --git a/application/views/forms/view_response.php b/application/views/forms/view_response.php index e95281b..08f9833 100644 --- a/application/views/forms/view_response.php +++ b/application/views/forms/view_response.php @@ -17,17 +17,16 @@
answers as $answer) { if ($answer->question_id == $question->question_id) { - $answer_text = htmlspecialchars($answer->answer_text, ENT_QUOTES, 'UTF-8'); - break; + $answer_texts[] = htmlspecialchars($answer->answer_text, ENT_QUOTES, 'UTF-8'); } } ?> question_type == 'paragraph') : ?>
- +
@@ -35,10 +34,10 @@ options as $optionIndex => $option) : ?>
question_type == 'multiple-choice') : ?> - option_text, ENT_QUOTES, 'UTF-8')) ? 'checked' : '' ?> readonly> + option_text, ENT_QUOTES, 'UTF-8'), $answer_texts)) ? 'checked' : '' ?> readonly> question_type == 'checkbox') : ?> - option_text, ENT_QUOTES, 'UTF-8')) !== false) ? 'checked' : '' ?> readonly> + option_text, ENT_QUOTES, 'UTF-8'), $answer_texts)) ? 'checked' : '' ?> readonly>
Form Title Created AtResponse Links
title, ENT_QUOTES, 'UTF-8') ?>title, ENT_QUOTES, 'UTF-8') ?> created_at)) ?>response_link ?>
No forms found.No forms found.