inital commit
This commit is contained in:
191
src/Controller/CertificateController.php
Normal file
191
src/Controller/CertificateController.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use App\Utility\Certificate;
|
||||
use Cake\View\View;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*Certificate Controller
|
||||
* *
|
||||
* @method \App\Model\Entity\Certificate[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) */
|
||||
class CertificateController extends AppController
|
||||
{
|
||||
|
||||
/**
|
||||
* Links
|
||||
*
|
||||
* @certificate/CHC/ehcplmmdgujaoerzhhhfglwkqakdeqzx --- Credit Hacker Challenge
|
||||
* @certificate/CRS01/yihjpcxejusqlrwtfkxhvjydmjoiiclh --- Credit Repair Software/Business Essentials
|
||||
* @certificate/M2CM01/jikhyrpbxljiyncvecixilkluvjbkalq --- Metro 2 Compliance Method
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->Auth->allow(['CHC', 'CRS', 'M2CM']);
|
||||
if ($this->Auth->user()) {
|
||||
$this->Auth->allow(['getcertificatelistbymemberId']);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Index method
|
||||
*
|
||||
* @return \Cake\Http\Response|void
|
||||
*/
|
||||
public function CHC($unique_string)
|
||||
{
|
||||
|
||||
$this->loadModel('Certificates');
|
||||
$certificate = $this->Certificates->getCertificateByUniqueString('CHC', $unique_string);
|
||||
|
||||
if (!empty($certificate)) {
|
||||
|
||||
$_SESSION['member_certificate'] = [
|
||||
'certificate_id' => $certificate->id,
|
||||
'name' => $certificate->name
|
||||
];
|
||||
return $this->redirect(['controller' => 'Cmsusers', 'action' => 'login']);
|
||||
}
|
||||
|
||||
die('Invalid Request');
|
||||
}
|
||||
|
||||
public function CRS($unique_string)
|
||||
{
|
||||
|
||||
$this->loadModel('Certificates');
|
||||
$certificate = $this->Certificates->getCertificateByUniqueString('CRS', $unique_string);
|
||||
|
||||
if (!empty($certificate)) {
|
||||
|
||||
$_SESSION['member_certificate'] = [
|
||||
'certificate_id' => $certificate->id,
|
||||
'name' => $certificate->name
|
||||
];
|
||||
return $this->redirect(['controller' => 'Cmsusers', 'action' => 'login']);
|
||||
}
|
||||
|
||||
die('Invalid Request');
|
||||
}
|
||||
|
||||
public function M2CM($unique_string)
|
||||
{
|
||||
|
||||
$this->loadModel('Certificates');
|
||||
$certificate = $this->Certificates->getCertificateByUniqueString('M2CM', $unique_string);
|
||||
|
||||
if (!empty($certificate)) {
|
||||
|
||||
$_SESSION['member_certificate'] = [
|
||||
'certificate_id' => $certificate->id,
|
||||
'name' => $certificate->name
|
||||
];
|
||||
return $this->redirect(['controller' => 'Cmsusers', 'action' => 'login']);
|
||||
}
|
||||
|
||||
die('Invalid Request');
|
||||
}
|
||||
|
||||
/**
|
||||
* View method
|
||||
*
|
||||
* @param string|null $idCertificate id.
|
||||
* @return \Cake\Http\Response|void
|
||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||
*/
|
||||
public function generatecertificate()
|
||||
{
|
||||
$request = $this->request->getData();
|
||||
if($this->request->is('ajax')){
|
||||
if($request['action'] == "session_unset"){
|
||||
if($request['session_unset'] == "1"){
|
||||
unset($_SESSION['member_certificate']);
|
||||
$response['status'] = true;
|
||||
$response['message'] = "Certificate session unset successfully";
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
die();
|
||||
}
|
||||
$inputData['member_id'] = $this->Auth->user('id');
|
||||
$inputData['certificate_id'] = 0;
|
||||
if($_SESSION['member_certificate']['certificate_id'] > 0){
|
||||
$inputData['certificate_id'] = $_SESSION['member_certificate']['certificate_id'];
|
||||
}
|
||||
$certificate_name = $_SESSION['member_certificate']['name'];
|
||||
$inputData['member_name'] = trim($request['fname'] . " " . $request['lname']);
|
||||
$this->loadModel('MemberCertificates');
|
||||
|
||||
if($inputData['certificate_id'] > 0 && $this->MemberCertificates->updateOrInsertMemberCertificate($inputData['member_id'], $inputData['certificate_id'], $inputData)) {
|
||||
|
||||
$pdf_file_path = Certificate::certificate_generate_for_pdf($inputData);
|
||||
$pdf_file_path = WWW_ROOT.$pdf_file_path;
|
||||
|
||||
$templateContent['certificate_name'] = $_SESSION['member_certificate']['name'];
|
||||
$templateContent['content'] = $inputData['member_name'];
|
||||
$templateContent['company_name'] = "Admin";
|
||||
$templateContent['company_email'] = NO_REPLY_EMAIL;
|
||||
|
||||
$subject = Certificate::CERTIFICATE_EMAIL_SUBJECTS[$inputData['certificate_id']];
|
||||
$this->sendEmail('certificate_email', $templateContent, $request['email'], $subject, $pdf_file_path);
|
||||
$download_name = str_replace(' ', '_', $certificate_name);
|
||||
$this->downloadFile($pdf_file_path,"pdf", $download_name);
|
||||
unset($_SESSION['member_certificate']);
|
||||
}
|
||||
|
||||
return $this->redirect(['controller' => 'Cmsusers', 'action' => 'login']);
|
||||
}
|
||||
|
||||
|
||||
private function downloadFile($file_path,$extension,$download_name){
|
||||
header('Content-Type: application/octet-stream');
|
||||
header("Content-Transfer-Encoding: Binary");
|
||||
header("Content-disposition: attachment; filename=\"" . "{$download_name}.{$extension}" . "\"");
|
||||
readfile($file_path);
|
||||
unlink($file_path);
|
||||
}
|
||||
|
||||
public function getcertificatelistbymemberId()
|
||||
{
|
||||
|
||||
if ($this->request->is('ajax')) {
|
||||
$response = [];
|
||||
$request = $this->request->getData();
|
||||
$this->loadModel('MemberCertificates');
|
||||
if ($request['action'] == "GET_CERTIFICATE_LIST") {
|
||||
$member_id = $request['member_id'];
|
||||
|
||||
$certificates = $this->MemberCertificates->getCertificateListByMemberId($member_id);
|
||||
$view = new View($this->request, $this->response);
|
||||
$response['html'] = $view->element('certificate/certificate_list', ['memberCertificates' => $certificates]);
|
||||
} else if ($request['action'] == "UPDATE_DOWNLOAD_STATUS") {
|
||||
$member_certificate_id = $request['member_certificate_id'];
|
||||
$status = $request['status'];
|
||||
$response['status'] = $this->MemberCertificates->updateById($member_certificate_id, ['downloaded' => $status]);
|
||||
$member_id = $request['member_id'];
|
||||
|
||||
$certificates = $this->MemberCertificates->getCertificateListByMemberId($member_id);
|
||||
|
||||
$view = new View($this->request, $this->response);
|
||||
$response['html'] = $view->element('certificate/certificate_list', ['memberCertificates' => $certificates]);
|
||||
$response['message'] = "Certificate download revoked successfully";
|
||||
|
||||
if ($response['status']) {
|
||||
$response['message'] = "Certificate download permitted successfully";
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user