HEX
Server: LiteSpeed
System: Linux server137.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
User: bibuzptr (1123)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/bibuzptr/elearning.bibu-edu.us/old 20th oct/admin/app/enrollstudent.php
<?php
include_once('../../includes/db_connect.php'); 
include_once "../../includes/swiftmailer/swift_required.php";
header("Content-Type:application/json");
$date = date("Y-m-d H:i:s");
$year = date("Y");
$today=date("D, d M Y");


if(isset($_POST["courseid"])){
  extract($_POST);
  if(mysqli_num_rows(mysqli_query($con,"SELECT * FROM mycourses WHERE courseid='$courseid' AND studentid='$studentid'"))<1){
      mysqli_query($con,"INSERT INTO mycourses(courseid,studentid) VALUES('$courseid','$studentid')");
      
      $cd=mysqli_fetch_assoc(mysqli_query($con,"SELECT title,hours FROM courses WHERE id='$courseid'"));
      $coursename=$cd["title"];
      $courseperiod=$cd["hours"];
      $std=mysqli_fetch_assoc(mysqli_query($con,"SELECT name,email,admno FROM students WHERE id='$studentid'"));
      $fname=$std["name"];
      $email=$std["email"];
      $admno=$std["admno"];
      $link="https://www.elearning.breakthroughuni.ac.ke/dashboard/";
      
      $notif = mysqli_fetch_assoc(mysqli_query($con,"SELECT * FROM notification_templates WHERE id='12'"));
      $transport = Swift_SmtpTransport::newInstance('breakthroughuni.ac.ke', 465, "ssl")
        ->setUsername('notification@breakthroughuni.ac.ke')
        ->setPassword('notif2019!');
        
        $mailer = Swift_Mailer::newInstance($transport);
        $message = Swift_Message::newInstance($notif["subject"])
        ->setFrom(array('notification@breakthroughuni.ac.ke' => 'Breakthrough Open University'))
        ->setTo(array($email => $fname))
        ->setContentType('text/html; charset=utf-8')
        ->setBody(str_replace(array("{fullname}","{course}","{link}","{today}","{admno}","{period}"),array($fname,$coursename,$link,$today,$admno,$courseperiod),$notif["body"]));
        $numSent = $mailer->send($message);
      
    echo json_encode(array('status' => '200','message' => 'SUCCESS'));
  }
  else{
    echo json_encode(array('status' => '300','message' => 'ERROR'));
   }
  }
  
?>
<?php mysqli_close($con) ?>