google_forms/application/controllers/Publish_controller.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2024-07-16 12:29:59 +00:00
<?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
2024-07-19 10:46:18 +00:00
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
2024-07-17 12:21:51 +00:00
$response_link = base_url("forms/response_preview/" . $form_id);
2024-07-16 12:29:59 +00:00
$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() {
2024-07-19 10:46:18 +00:00
if (!$this->session->userdata('logged_in')) {
// If not logged in, redirect to login page
redirect('users/login');
}
2024-07-16 12:29:59 +00:00
$user_id = $this->session->userdata('user_id');
$this->load->model('Publish_model');
$data['forms'] = $this->Publish_model->get_published_forms_by_user($user_id);
2024-07-19 10:46:18 +00:00
$this->load->view('templates/header');
2024-07-16 12:29:59 +00:00
$this->load->view('publish_view', $data);
2024-07-19 10:46:18 +00:00
$this->load->view('templates/footer');
2024-07-16 12:29:59 +00:00
}
}