diff --git a/application/config/routes.php b/application/config/routes.php index 92e526a..fc85526 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -21,4 +21,9 @@ $route['edit/(:num)'] = 'Form_controller/edit_form/$1'; $route['form_preview/(:num)'] = 'forms/preview_back/$1'; $route['responses/(:num)'] = 'Response_submit/view_responses/$1'; -$route['designform'] = 'homepage/design_form'; +$route['designform/(:num)'] = 'homepage/design_form/$1'; +$route['response_preview/(:num)'] = 'forms/response_preview/$1'; + +$route['title'] = 'homepage/title'; + +// $route['designform'] = 'homepage/design_form'; diff --git a/application/controllers/Form.php b/application/controllers/Form.php index 5077544..67d5edd 100644 --- a/application/controllers/Form.php +++ b/application/controllers/Form.php @@ -23,4 +23,14 @@ class Form extends CI_Controller { echo json_encode($response); } + + public function view($form_id) { + $data['title'] = $this->Form_model->get_form_title($form_id); + + if ($data['title'] === null) { + show_404(); // Show 404 if form_id is invalid + } + + $this->load->view('templates/forms_ui',$data); + } } \ No newline at end of file diff --git a/application/controllers/Forms.php b/application/controllers/Forms.php index d916740..4624c24 100644 --- a/application/controllers/Forms.php +++ b/application/controllers/Forms.php @@ -38,7 +38,7 @@ class Forms extends CI_Controller { if (!$this->session->userdata('logged_in')) { // If not logged in, redirect to login page - redirect('users/login'); + redirect('users/login/'.$form_id); } // Load the model that handles the form data diff --git a/application/controllers/Home.php b/application/controllers/Homepage.php similarity index 100% rename from application/controllers/Home.php rename to application/controllers/Homepage.php diff --git a/application/controllers/New_form.php b/application/controllers/New_form.php index 0d12807..4099bcc 100644 --- a/application/controllers/New_form.php +++ b/application/controllers/New_form.php @@ -1,36 +1,29 @@ session->userdata('logged_in')) { // If not logged in, redirect to login page redirect('users/login'); } + $data['title'] = 'Form Details'; $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('description', 'Description', 'required'); - - + if ($this->form_validation->run() === FALSE) { $this->load->view('templates/header'); - $this->load->view('templates/form_title',$data); + $this->load->view('templates/form_title', $data); $this->load->view('templates/footer'); } else { - // $enc_password = md5($this->input->post('password')); $this->load->model('create_model'); - // $user_id = $this->session->userdata('user_id'); - - - $this->create_model->details(); - // $this->user_model->register(); - - - // $this->session->set_flashdata('user_registered', 'You are now registered and can log in'); - redirect('designform'); + $form_id = $this->create_model->details(); // Get the new form_id + + // Redirect to the form view with the form_id + redirect('form/view/' . $form_id); } - } + } ?> \ No newline at end of file diff --git a/application/controllers/New_form_controller.php b/application/controllers/New_form_controller.php index e42fea1..c49e72c 100644 --- a/application/controllers/New_form_controller.php +++ b/application/controllers/New_form_controller.php @@ -12,7 +12,6 @@ class New_form_controller extends CI_Controller { // Decode the formData from the POST request $formData = $this->input->post('formData'); - // Check if form_id is set in session $formId = $this->session->userdata('form_id'); if ($formId) { diff --git a/application/controllers/Publish_controller.php b/application/controllers/Publish_controller.php index c159a7c..43ab23d 100644 --- a/application/controllers/Publish_controller.php +++ b/application/controllers/Publish_controller.php @@ -10,7 +10,7 @@ class Publish_controller extends CI_Controller { // If not logged in, redirect to login page redirect('users/login'); } - $response_link = base_url("forms/response_preview/" . $form_id); + $response_link = base_url("response_preview/" . $form_id); $this->load->model('Publish_model'); // Update is_published to 1 and set the response link $this->Publish_model->update_form($form_id, [ diff --git a/application/controllers/Users.php b/application/controllers/Users.php index 9d42e47..f1f0e51 100644 --- a/application/controllers/Users.php +++ b/application/controllers/Users.php @@ -35,9 +35,10 @@ class Users extends CI_Controller * @return mixed(data return type) * @author torun */ - public function login() + public function login($form_id = null) { $data['title'] = 'Sign In'; + $data['form_id'] = $form_id; $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required'); @@ -71,7 +72,11 @@ class Users extends CI_Controller // Set message $this->session->set_flashdata('user_loggedin', 'You are now logged in'); - redirect('home'); + if ($form_id) { + redirect('forms/response_preview/'.$form_id); + } else { + redirect('home'); } + } else { // Set message $this->session->set_flashdata('login_failed', 'Login is invalid'); diff --git a/application/models/Create_model.php b/application/models/Create_model.php index 1d4fd94..69b8bab 100644 --- a/application/models/Create_model.php +++ b/application/models/Create_model.php @@ -20,7 +20,7 @@ class Create_model extends CI_Model { $formId = $this->db->insert_id(); $this->session->set_userdata('form_id', $formId); - +return $formId; } } diff --git a/application/models/Form_model.php b/application/models/Form_model.php index aad772a..b3969ac 100644 --- a/application/models/Form_model.php +++ b/application/models/Form_model.php @@ -37,4 +37,20 @@ class Form_model extends CI_Model { return true; } } + public function __construct() { + $this->load->database(); + } + + public function get_form_title($form_id) { + $this->db->select('title'); // Assuming the title column in the forms table is called 'title' + $this->db->from('forms'); + $this->db->where('id', $form_id); + $query = $this->db->get(); + + if ($query->num_rows() > 0) { + return $query->row()->title; + } else { + return null; + } + } } \ No newline at end of file diff --git a/application/views/Tables/draft.php b/application/views/Tables/draft.php index f6f9d1c..19daee0 100644 --- a/application/views/Tables/draft.php +++ b/application/views/Tables/draft.php @@ -1,3 +1,8 @@ +
@@ -17,22 +22,24 @@ Drafts - + - + - - - - + + - + + diff --git a/application/views/Tables/list_forms.php b/application/views/Tables/list_forms.php index d7e00e9..ee98e4b 100644 --- a/application/views/Tables/list_forms.php +++ b/application/views/Tables/list_forms.php @@ -1,3 +1,23 @@ + + + + + + + Form List + + + + +
@@ -14,27 +34,33 @@
-
Form_IdDrafts TitleDescription Created On Edit DeletePreview
id; ?>title; ?> + +
+ title; ?> description; ?>created_at; ?> Delete + + + +
+
- + + - - - - + + + @@ -45,3 +71,18 @@ + + + + diff --git a/application/views/edit_form_view.php b/application/views/edit_form_view.php index fd53d9f..9407a22 100644 --- a/application/views/edit_form_view.php +++ b/application/views/edit_form_view.php @@ -4,12 +4,65 @@ Edit Form - + - + + + + + + + + +
+ session->flashdata('user_registered')): ?> +

session->flashdata('user_registered'); ?>

+ + + session->flashdata('login_failed')): ?> +

session->flashdata('login_failed'); ?>

+ + + session->flashdata('user_loggedin')): ?> +

session->flashdata('user_loggedin'); ?>

+ + + session->flashdata('user_loggedout')): ?> +

session->flashdata('user_loggedout'); ?>

+ +
+ +
@@ -55,8 +108,9 @@
- + + @@ -65,9 +119,33 @@ - diff --git a/application/views/form_preview.php b/application/views/form_preview.php index fd32754..640ed41 100644 --- a/application/views/form_preview.php +++ b/application/views/form_preview.php @@ -5,81 +5,20 @@ Form Preview - Google Forms - - +

title; ?>

+

description; ?>

- +

text; ?>

type == 'multiple-choice'): ?> @@ -119,8 +58,8 @@
- - Publish -
+Publish +
+ diff --git a/application/views/form_preview_back.php b/application/views/form_preview_back.php index 045418d..f1772d6 100644 --- a/application/views/form_preview_back.php +++ b/application/views/form_preview_back.php @@ -5,19 +5,21 @@ Form Preview - Google Forms - + +

title; ?>

+

description; ?>

- +

text; ?>

type == 'multiple-choice'): ?> @@ -57,8 +59,8 @@
- - Back +Back +
diff --git a/application/views/publish_view.php b/application/views/publish_view.php index e939504..3753352 100644 --- a/application/views/publish_view.php +++ b/application/views/publish_view.php @@ -1,3 +1,12 @@ +
@@ -17,27 +26,32 @@
Form_IdForms Title Description Created On StatusPreview
id; ?>title; ?> + +
+ title; ?> description; ?> created_at; ?>is_published ? 'Published' : 'Draft'); ?> - is_published ? 'Published' : 'Draft'); ?> + + +
- + - - + + - + - - + + + - + + + + diff --git a/application/views/response_submit.php b/application/views/response_submit.php index c054d8c..d708c7a 100644 --- a/application/views/response_submit.php +++ b/application/views/response_submit.php @@ -8,21 +8,42 @@ + function validateForm() { + let isValid = true; + document.querySelectorAll('.question-container').forEach(function(container) { + let isRequired = container.dataset.required === '1'; + let questionType = container.dataset.type; + let isAnswered = false; + + // Select inputs relevant to the question type + let inputs = container.querySelectorAll('input[type="text"], textarea, select, input[type="radio"]:checked, input[type="checkbox"]:checked'); + if (inputs.length > 0) { + inputs.forEach(function(input) { + if (input.type === 'text' || input.tagName.toLowerCase() === 'textarea') { + if (input.value.trim() !== '') { + isAnswered = true; + } + } else if (input.type === 'radio' || input.type === 'checkbox') { + isAnswered = true; + } else if (input.tagName.toLowerCase() === 'select') { + if (input.value.trim() !== '') { + isAnswered = true; + } + } + }); + } + + if (isRequired && !isAnswered) { + container.style.border = '2px solid purple'; + isValid = false; + } else { + container.style.border = 'none'; + } + }); + return isValid; + } + +
diff --git a/application/views/templates/footer.php b/application/views/templates/footer.php index 35490a2..31fdb4f 100644 --- a/application/views/templates/footer.php +++ b/application/views/templates/footer.php @@ -1,7 +1,22 @@ - diff --git a/application/views/templates/form_title.php b/application/views/templates/form_title.php index af75e00..c7a5d51 100644 --- a/application/views/templates/form_title.php +++ b/application/views/templates/form_title.php @@ -12,8 +12,7 @@
- + - - + \ No newline at end of file diff --git a/application/views/templates/forms_ui.php b/application/views/templates/forms_ui.php index 60b90b7..dea9bc7 100644 --- a/application/views/templates/forms_ui.php +++ b/application/views/templates/forms_ui.php @@ -57,16 +57,18 @@
-
- -

Untitled Form

- -
-
- - +
+ +

+ +
+
+ + +
+ diff --git a/application/views/templates/header.php b/application/views/templates/header.php index 17cefbd..de0cf5c 100644 --- a/application/views/templates/header.php +++ b/application/views/templates/header.php @@ -9,12 +9,10 @@ - - - - - + + + @@ -41,7 +39,7 @@
  • Register
  • session->userdata('logged_in')): ?> -
  • Create Form
  • +
  • Create Form
  • Logout
  • diff --git a/application/views/users/login.php b/application/views/users/login.php index d3b1807..42ba6d7 100644 --- a/application/views/users/login.php +++ b/application/views/users/login.php @@ -1,4 +1,4 @@ - +

    diff --git a/assets/css/form_preview.css b/assets/css/form_preview.css new file mode 100644 index 0000000..858b6e9 --- /dev/null +++ b/assets/css/form_preview.css @@ -0,0 +1,68 @@ +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, .form-header h4 { + margin: 0; + text-align: left; +} +.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; +} +.btn-success { + margin-top: 20px; + position: relative; + left: 240px; + background-color: rgb(103, 58, 183); + border-color: rgb(103, 58, 183); + color: white; +} diff --git a/assets/css/form_preview_back.css b/assets/css/form_preview_back.css deleted file mode 100644 index 4e2c3ff..0000000 --- a/assets/css/form_preview_back.css +++ /dev/null @@ -1,51 +0,0 @@ -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_new.css b/assets/css/header_new.css new file mode 100644 index 0000000..4e1acc1 --- /dev/null +++ b/assets/css/header_new.css @@ -0,0 +1,35 @@ +/* Navbar styles */ +.navbar-custom { + background-color: rgb(103, 58, 183); ; /* Customize this color */ +} + +/* Button positioning for section addition */ +#add-section-btn { + position: absolute; + /* Ensure proper positioning */ +} + +.form-section { + margin-bottom: 15px; + padding: 15px; + border: 1px solid #ddd; + border-radius: 5px; +} + +.header-row { + display: flex; + align-items: center; +} + +.header-row textarea, +.header-row select { + margin-right: 10px; +} +.navbar-custom .navbar-brand { + color: #fff; /* Customize brand color */ +} + +.navbar-custom .navbar-nav li a { + color: #fff; /* Customize link color */ +} + diff --git a/assets/css/styles.css b/assets/css/styles.css index c1eebd1..d7f13e8 100644 --- a/assets/css/styles.css +++ b/assets/css/styles.css @@ -3,6 +3,17 @@ body { background-color: rgb(240, 235, 248); font-family: Arial, sans-serif; } +.form-section h2 { + text-align: center; + margin-bottom: 30px; +} + +.form-section .question-section { + margin-bottom: 20px; +} +/* Navbar custom styles */ + + .container { position: relative; margin-top: 30px; @@ -150,8 +161,8 @@ body { .add-option-btn { - background-color: #f0f0f0; - color: #333; + background-color: rgb(66, 133, 244); + /* color: rgb(66, 133, 244); */ margin-top: 11px; font-size: 0.9em; @@ -228,4 +239,20 @@ table a:not(.btn):hover { background-color: rgb(103, 58, 183); border-color: rgb(103, 58, 183); } */ +.btn-custom { + margin-top: 20px; + position: relative; + left: 240px; + background-color: rgb(103, 58, 183); + border-color: rgb(103, 58, 183); + color: white; +} +/* Assuming you have a stylesheet named styles.css */ +.btn.btn-primary.btn-block { +margin-top: 20px; +position: relative; +background-color: rgb(103, 58, 183); +border-color: rgb(103, 58, 183); +color: white; +} diff --git a/assets/js/scripts.js b/assets/js/scripts.js index f30d96e..a7cb623 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -225,7 +225,7 @@ function addOption(type, container) { var questionData = { text: $(this).find('.untitled-question').val(), type: questionType, - required: $(this).find('.required-toggle').is(':checked'), + is_required: $(this).find('.required-toggle').is(':checked'), options: [] }; @@ -239,7 +239,7 @@ function addOption(type, container) { formData.questions.push(questionData); }); - // console.log(formData); + console.log(formData); return formData; } @@ -282,7 +282,7 @@ function addOption(type, container) { window.location.href = base_url + 'Form_controller/index_forms'; } else { alert(response.message); - console.log(response); + // console.log(response); } }, error: function(error) {

    Form_IdResponses TitleDescriptionResponse Link StatusResponse LinkPreview
    id; ?> - title; ?> + + title; ?> + + Unpublish description; ?> response_link; ?> - Unpublish -