From c0ab63541165e1528a780ea52f2a37b43906b184 Mon Sep 17 00:00:00 2001 From: torun23 Date: Tue, 16 Jul 2024 17:59:59 +0530 Subject: [PATCH] commit --- application/config/routes.php | 7 +- application/controllers/Form_controller.php | 22 +++- application/controllers/Forms.php | 31 +++++ application/controllers/Home.php | 23 +++- .../controllers/Publish_controller.php | 31 +++++ application/controllers/Users.php | 2 +- application/models/Frontend_model.php | 15 +++ application/models/New_form_model.php | 3 +- application/models/Preview_model.php | 19 +++ application/models/Publish_model.php | 17 +++ application/views/Frontend/footer.php | 3 + application/views/Frontend/header.php | 69 +++++++++++ application/views/Tables/list_forms.php | 58 +++++++++ application/views/form_preview.php | 112 ++++++++++++++++++ application/views/publish_view.php | 49 ++++++++ application/views/templates/forms_ui.php | 2 +- application/views/templates/header.php | 13 +- 17 files changed, 462 insertions(+), 14 deletions(-) create mode 100644 application/controllers/Forms.php create mode 100644 application/controllers/Publish_controller.php create mode 100644 application/models/Frontend_model.php create mode 100644 application/models/Preview_model.php create mode 100644 application/models/Publish_model.php create mode 100644 application/views/Frontend/footer.php create mode 100644 application/views/Frontend/header.php create mode 100644 application/views/Tables/list_forms.php create mode 100644 application/views/form_preview.php create mode 100644 application/views/publish_view.php diff --git a/application/config/routes.php b/application/config/routes.php index 1e47882..bb24084 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -1,13 +1,14 @@ load->view('templates/forms_ui'); + $this->load->view('Frontend/header'); + + $this->load->model('Frontend_model'); + + $data= $this->Frontend_model->getforms(); + $this->load->view('Tables/list_forms',['forms'=> $data]); + + + $this->load->view('Frontend/footer'); + } + + public function delete($id) + { +$this->load->model('Frontend_model'); +$this->Frontend_model->deleteForm($id); +$this->session->set_flashdata('status','Form data deleted successfully'); +redirect('forms_home'); + } + } \ No newline at end of file diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php new file mode 100644 index 0000000..05af47e --- /dev/null +++ b/application/controllers/Forms.php @@ -0,0 +1,31 @@ +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('form_preview', $data); + // redirect('home/preview_forms'); + + } + +} diff --git a/application/controllers/Home.php b/application/controllers/Home.php index d2d129a..8815208 100644 --- a/application/controllers/Home.php +++ b/application/controllers/Home.php @@ -21,9 +21,13 @@ class Home extends CI_Controller } public function index2() { - $this->load->view('templates/header'); - $this->load->view('pages/formspage'); - $this->load->view('templates/footer'); + // $this->load->view('templates/header'); + $this->load->view('Frontend/header'); + + $this->load->view('Form_controller/index_forms'); + // $this->load->view('templates/footer'); + $this->load->view('Frontend/footer'); + } @@ -43,4 +47,17 @@ public function title(){ $this->load->view('templates/footer'); } +public function index4() +{ + $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'); + +// } } \ No newline at end of file diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php new file mode 100644 index 0000000..e99a72b --- /dev/null +++ b/application/controllers/Publish_controller.php @@ -0,0 +1,31 @@ +load->model('Publish_model'); + // Update is_published to 1 and set the response link + $this->Publish_model->update_form($form_id, [ + 'is_published' => 1, + 'response_link' => $response_link + ]); + + // Redirect to the list_user_published_forms function + redirect('Publish_controller/list_user_published_forms'); +} + +// Method to list published forms of a user +public function list_user_published_forms() { + $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('Frontend/header'); + $this->load->view('publish_view', $data); + $this->load->view('Frontend/footer'); +} +} diff --git a/application/controllers/Users.php b/application/controllers/Users.php index fbb0e0d..9620894 100644 --- a/application/controllers/Users.php +++ b/application/controllers/Users.php @@ -71,7 +71,7 @@ class Users extends CI_Controller // Set message $this->session->set_flashdata('user_loggedin', 'You are now logged in'); - redirect('title_desc'); + redirect('forms_home'); } else { // Set message $this->session->set_flashdata('login_failed', 'Login is invalid'); diff --git a/application/models/Frontend_model.php b/application/models/Frontend_model.php new file mode 100644 index 0000000..00da6d1 --- /dev/null +++ b/application/models/Frontend_model.php @@ -0,0 +1,15 @@ + +db->get("forms"); + return $query->result(); + } + + public function deleteForm($id){ + return $this->db->delete('forms', ['id' => $id]); + } + +} \ No newline at end of file diff --git a/application/models/New_form_model.php b/application/models/New_form_model.php index 0b53b28..c6f0ef1 100644 --- a/application/models/New_form_model.php +++ b/application/models/New_form_model.php @@ -5,7 +5,8 @@ class New_form_model extends CI_Model { if (!$formId) { return false; // Handle error if formId is not valid } - foreach ($formData['questions'] as $question) { + $questions_array = $formData['questions']; + foreach ($questions_array as $question) { $questionData = [ 'form_id' => $formId, 'text' => $question['text'], diff --git a/application/models/Preview_model.php b/application/models/Preview_model.php new file mode 100644 index 0000000..3959b2e --- /dev/null +++ b/application/models/Preview_model.php @@ -0,0 +1,19 @@ +db->get_where('forms', array('id' => $form_id))->row(); + } + + 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(); + } + +} \ No newline at end of file diff --git a/application/models/Publish_model.php b/application/models/Publish_model.php new file mode 100644 index 0000000..8365fac --- /dev/null +++ b/application/models/Publish_model.php @@ -0,0 +1,17 @@ +db->where('id', $form_id); + return $this->db->update('forms', $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); // Ensure only published forms are retrieved + $query = $this->db->get('forms'); + return $query->result(); +} +} diff --git a/application/views/Frontend/footer.php b/application/views/Frontend/footer.php new file mode 100644 index 0000000..12db258 --- /dev/null +++ b/application/views/Frontend/footer.php @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/application/views/Frontend/header.php b/application/views/Frontend/header.php new file mode 100644 index 0000000..6320f37 --- /dev/null +++ b/application/views/Frontend/header.php @@ -0,0 +1,69 @@ + + + + + + + + Google Forms + + + + + + + + + +
+ session->flashdata('user_registered')): ?> + ' . $this->session->flashdata('user_registered') . '

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

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

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

'; ?> + + + + +
+
\ No newline at end of file diff --git a/application/views/Tables/list_forms.php b/application/views/Tables/list_forms.php new file mode 100644 index 0000000..18c892e --- /dev/null +++ b/application/views/Tables/list_forms.php @@ -0,0 +1,58 @@ +
+
+
+
+
+ session->flashdata('status')): ?> +
+ session->flashdata('status'); ?> +
+ +

+ List of Forms +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Form_IdTitleDescriptionCreated OnStatusEditDelete
id; ?>title; ?> + description; ?>created_on; ?> + is_published ? 'Published' : 'Draft'); ?> + + Edit + + Delete +
+
+
+
+
+
\ No newline at end of file diff --git a/application/views/form_preview.php b/application/views/form_preview.php new file mode 100644 index 0000000..0020d39 --- /dev/null +++ b/application/views/form_preview.php @@ -0,0 +1,112 @@ + + + + + + Form Preview - Google Forms + + + + + + + +
+ session->flashdata('user_registered')): ?> + ' . $this->session->flashdata('user_registered') . '

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

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

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

'; ?> + +
+ +
+
+

Form Preview: title; ?>

+
+
+ +
+ + type == 'multiple-choice'): ?> + options as $option): ?> +
+ + +
+ + type == 'checkbox'): ?> + options as $option): ?> +
+ + +
+ + type == 'short-answer'): ?> + + type == 'paragraph'): ?> + + type == 'dropdown'): ?> + + +
+ + Publish +
+
+ + + + + + diff --git a/application/views/publish_view.php b/application/views/publish_view.php new file mode 100644 index 0000000..c8a7019 --- /dev/null +++ b/application/views/publish_view.php @@ -0,0 +1,49 @@ +
+
+
+
+
+ session->flashdata('status')): ?> +
+ session->flashdata('status'); ?> +
+ +

+ Published Forms +

+
+
+ + + + + + + + + + + + + + + + + + + + + + +
Form_IdTitleDescriptionStatusResponse Link
id; ?> + title; ?> + description; ?> + is_published ? 'Published' : 'Draft'); ?> + + response_link; ?> +
+
+
+
+
+
diff --git a/application/views/templates/forms_ui.php b/application/views/templates/forms_ui.php index deb01c2..c0d1466 100644 --- a/application/views/templates/forms_ui.php +++ b/application/views/templates/forms_ui.php @@ -41,7 +41,7 @@