This commit is contained in:
torun23 2024-07-16 17:59:59 +05:30
parent 21213a9f21
commit c0ab635411
17 changed files with 462 additions and 14 deletions

View File

@ -1,13 +1,14 @@
<?php <?php
defined('BASEPATH') OR exit('No direct script access allowed'); defined('BASEPATH') OR exit('No direct script access allowed');
$route['forms'] = 'Form_controller/index'; $route['forms'] = 'home/index4';
$route['default_controller'] = 'home/index2'; $route['default_controller'] = 'Form_controller/index_forms';
$route['404_override'] = ''; $route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE; $route['translate_uri_dashes'] = FALSE;
$route['start'] = 'home/index'; $route['start'] = 'home/index';
$route['new_form'] = 'home/create_form'; $route['new_form'] = 'home/create_form';
$route['title_desc'] = 'home/title'; $route['title_desc'] = 'home/title';
$route['forms_home'] = 'Form_controller/index_forms';
$route['forms/delete/(:any)'] = 'Form_controller/delete/$1';

View File

@ -3,8 +3,26 @@ defined('BASEPATH') OR exit('No direct script access allowed');
class Form_controller extends CI_Controller { class Form_controller extends CI_Controller {
public function index() public function index_forms()
{ {
$this->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');
}
} }

View File

@ -0,0 +1,31 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Forms extends CI_Controller
{
public function preview($form_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('form_preview', $data);
// redirect('home/preview_forms');
}
}

View File

@ -21,9 +21,13 @@ class Home extends CI_Controller
} }
public function index2() public function index2()
{ {
$this->load->view('templates/header'); // $this->load->view('templates/header');
$this->load->view('pages/formspage'); $this->load->view('Frontend/header');
$this->load->view('templates/footer');
$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'); $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');
// }
} }

View File

@ -0,0 +1,31 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Publish_controller extends CI_Controller {
// Method to publish a form
public function publish_form($form_id) {
// Generate a unique link
$response_link = base_url("forms/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, [
'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');
}
}

View File

@ -71,7 +71,7 @@ class Users extends CI_Controller
// Set message // Set message
$this->session->set_flashdata('user_loggedin', 'You are now logged in'); $this->session->set_flashdata('user_loggedin', 'You are now logged in');
redirect('title_desc'); redirect('forms_home');
} else { } else {
// Set message // Set message
$this->session->set_flashdata('login_failed', 'Login is invalid'); $this->session->set_flashdata('login_failed', 'Login is invalid');

View File

@ -0,0 +1,15 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Frontend_model extends CI_Model {
public function getforms(){
$query = $this->db->get("forms");
return $query->result();
}
public function deleteForm($id){
return $this->db->delete('forms', ['id' => $id]);
}
}

View File

@ -5,7 +5,8 @@ class New_form_model extends CI_Model {
if (!$formId) { if (!$formId) {
return false; // Handle error if formId is not valid return false; // Handle error if formId is not valid
} }
foreach ($formData['questions'] as $question) { $questions_array = $formData['questions'];
foreach ($questions_array as $question) {
$questionData = [ $questionData = [
'form_id' => $formId, 'form_id' => $formId,
'text' => $question['text'], 'text' => $question['text'],

View File

@ -0,0 +1,19 @@
<?php
class preview_model extends CI_Model {
public function get_form($form_id)
{
return $this->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();
}
}

View File

@ -0,0 +1,17 @@
<?php
class Publish_model extends CI_Model {
// Method to update form details including is_published status
public function update_form($form_id, $data) {
$this->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();
}
}

View File

@ -0,0 +1,3 @@
</div>
</body>
</html>

View File

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Forms</title>
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body style = "background-color: rgb(240,235,248);" >
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" >
<div class="container" style="background-color: rgb(103, 58, 183);">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
</div>
<?php endif; ?>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="<?php echo base_url(); ?>home/index3">Home</a></li>
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
<li><a href="">Responses</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if (!$this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>home/title">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<div class="container">
<?php if ($this->session->flashdata('user_registered')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('login_failed')): ?>
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedin')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedin') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedout')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
<?php endif; ?>
</div>
<div></div>

View File

@ -0,0 +1,58 @@
<div class="container">
<div class="row">
<div class="col-md-12 mt-4 ">
<div class="card">
<div class="card-header">
<?php if ($this->session->flashdata('status')): ?>
<div class="alert alert-success">
<?= $this->session->flashdata('status'); ?>
</div>
<?php endif; ?>
<h3>
List of Forms
</h3>
</div>
<div class="card-body">
<!-- here your table will occur -->
<table id="basetable1" class="table table-bordered">
<thead>
<tr>
<th>Form_Id</th>
<th>Title</th>
<th>Description</th>
<th>Created On</th>
<th>Status</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($forms as $row): ?>
<tr>
<td><?php echo $row->id; ?></td>
<td><a
href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td>
<td><?php echo $row->description; ?></td>
<td><?php echo $row->created_on; ?></td>
<td>
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?>
</td>
<td>
<a href="" class="btn btn-success btn-sm">Edit</a>
</td>
<td>
<a href="<?php echo base_url('forms/delete/' . $row->id); ?>"
class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Preview - Google Forms</title>
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
<style>
body { background-color: rgb(240, 235, 248); }
.container { margin-top: 30px; }
.form-section { background-color: white; width: 56%; margin-bottom: 30px; margin-left: 240px; padding: 20px; position: relative; align-items: center; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
.form-header { background-color: white; padding: 20px; margin-bottom: 10px; margin-left: 240px; border-radius: 10px 10px 0 0; display: flex; justify-content: space-between; align-items: center; position: relative; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border-top: 10px solid rgb(103, 58, 183); width: 56%; }
.form-section h2 { text-align: center; margin-bottom: 30px; }
.form-section .question-section { margin-bottom: 20px; }
</style>
</head>
<body>
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);">
<div class="container" style="background-color: rgb(103, 58, 183);">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
</div>
<?php endif; ?>
<div id="navbar">
<ul class="nav navbar-nav">
<li><a href="<?php echo base_url(); ?>home/index3">Home</a></li>
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="#">Responses</a></li>
<?php endif; ?>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if (!$this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>users/login">Login</a></li>
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>home/title">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>
<div class="container">
<?php if ($this->session->flashdata('user_registered')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_registered') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('login_failed')): ?>
<?php echo '<p class="alert alert-danger">' . $this->session->flashdata('login_failed') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedin')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedin') . '</p>'; ?>
<?php endif; ?>
<?php if ($this->session->flashdata('user_loggedout')): ?>
<?php echo '<p class="alert alert-success">' . $this->session->flashdata('user_loggedout') . '</p>'; ?>
<?php endif; ?>
</div>
<div class="container">
<div class="form-header">
<h2>Form Preview: <?php echo $form->title; ?></h2>
</div>
<div class="form-section">
<?php foreach ($questions as $question): ?>
<div class="question-section">
<input type="text" class="form-control question-label" value="<?php echo $question->text; ?>" disabled>
<?php if ($question->type == 'multiple-choice'): ?>
<?php foreach ($question->options as $option): ?>
<div class="option">
<input type="radio" name="option-<?php echo $question->id; ?>">
<label><?php echo $option->option_text; ?></label>
</div>
<?php endforeach; ?>
<?php elseif ($question->type == 'checkbox'): ?>
<?php foreach ($question->options as $option): ?>
<div class="option">
<input type="checkbox" name="option-<?php echo $question->id; ?>">
<label><?php echo $option->option_text; ?></label>
</div>
<?php endforeach; ?>
<?php elseif ($question->type == 'short-answer'): ?>
<input type="text" class="form-control" placeholder="Short answer text">
<?php elseif ($question->type == 'paragraph'): ?>
<textarea class="form-control" placeholder="Paragraph text"></textarea>
<?php elseif ($question->type == 'dropdown'): ?>
<select class="form-control">
<?php foreach ($question->options as $option): ?>
<option><?php echo $option->option_text; ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
<?php endforeach; ?>
<a href="<?php echo base_url('Publish_controller/publish_form/' . $form->id); ?>" class="btn btn-success" style="margin-top: 20px">Publish</a>
</div>
</div>
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('editor1');
</script>
</body>
</html>

View File

@ -0,0 +1,49 @@
<div class="container">
<div class="row">
<div class="col-md-12 mt-4 ">
<div class="card">
<div class="card-header">
<?php if ($this->session->flashdata('status')): ?>
<div class="alert alert-success">
<?= $this->session->flashdata('status'); ?>
</div>
<?php endif; ?>
<h3>
Published Forms
</h3>
</div>
<div class="card-body">
<!-- here your table will occur -->
<table id="basetable1" class="table table-bordered">
<thead>
<tr>
<th>Form_Id</th>
<th>Title</th>
<th>Description</th>
<th>Status</th>
<th>Response Link</th>
</tr>
</thead>
<tbody>
<?php foreach ($forms as $row): ?>
<tr>
<td><?php echo $row->id; ?></td>
<td>
<a href="<?php echo base_url('forms/preview/' . $row->id); ?>"><?php echo $row->title; ?></a>
</td>
<td><?php echo $row->description; ?></td>
<td>
<?php echo ($row->is_published ? 'Published' : 'Draft'); ?>
</td>
<td>
<a href="<?php echo $row->response_link; ?>" target="_blank"><?php echo $row->response_link; ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -41,7 +41,7 @@
<nav class="navbar navbar-inverse navbar-custom"> <nav class="navbar navbar-inverse navbar-custom">
<div class="container"> <div class="container">
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a> <a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a> <a class="navbar-brand" href="<?php echo base_url(); ?>home/index3">Home</a>
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a> <a class="navbar-brand" href="<?php echo base_url(); ?>home/index1">About</a>
</div> </div>

View File

@ -5,7 +5,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog App</title> <title>Google Forms</title>
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css"> <link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css"> <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/header_styles.css">
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script> <script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
@ -14,13 +14,20 @@
<body style = "background-color: rgb(240,235,248);" > <body style = "background-color: rgb(240,235,248);" >
<nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" > <nav class="navbar navbar-inverse" style="background-color: rgb(103, 58, 183);" >
<div class="container" style="background-color: rgb(103, 58, 183);"> <div class="container" style="background-color: rgb(103, 58, 183);">
<?php if ($this->session->userdata('logged_in')): ?>
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href="<?php echo base_url(); ?>home/index2">Google Forms</a> <a class="navbar-brand" href="<?php echo base_url(); ?>Form_controller/index_forms">Google Forms</a>
</div> </div>
<?php endif; ?>
<div id="navbar"> <div id="navbar">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="<?php echo base_url(); ?>home/index3">Home</a></li> <li><a href="<?php echo base_url(); ?>home/index3">Home</a></li>
<li><a href="<?php echo base_url(); ?>home/index1">About</a></li> <li><a href="<?php echo base_url(); ?>home/index1">About</a></li>
<?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>Publish_controller/list_user_published_forms">Published Forms</a></li>
<li><a href="">Responses</a></li>
<?php endif; ?>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
@ -29,7 +36,7 @@
<li><a href="<?php echo base_url(); ?>users/register">Register</a></li> <li><a href="<?php echo base_url(); ?>users/register">Register</a></li>
<?php endif; ?> <?php endif; ?>
<?php if ($this->session->userdata('logged_in')): ?> <?php if ($this->session->userdata('logged_in')): ?>
<li><a href="<?php echo base_url(); ?>home/design_form">Create Form</a></li> <li><a href="<?php echo base_url(); ?>home/title">Create Form</a></li>
<li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li> <li><a href="<?php echo base_url(); ?>users/logout">Logout</a></li>
<?php endif; ?> <?php endif; ?>