336 lines
14 KiB
PHP
336 lines
14 KiB
PHP
<?php
|
|
if (!class_exists('Student')) require_once("../common_cadline_libraries/crm_hardlock.class.php");
|
|
|
|
if ($_SERVER['HTTP_HOST'] == 'www.archline.hu')
|
|
require_once('language/hu-HU.lang.php');
|
|
else
|
|
require_once('language/en-GB.lang.php');
|
|
|
|
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
|
if (isset($action) && $action != '') {
|
|
$student = new Student();
|
|
|
|
switch ($action) {
|
|
case 'readrecord': { // Get the students
|
|
$course_id = isset($_POST['course_id']) ? $_POST['course_id'] : '';
|
|
if (!isset($course_id) || $course_id == '') {
|
|
echo json_encode($process['wrong_course']);
|
|
die();
|
|
}
|
|
|
|
$courses = json_decode($_POST['courseArray']);
|
|
|
|
$search = isset($_POST['search_name']) ? $_POST['search_name'] : '';
|
|
$student->setCourseID($course_id);
|
|
$studentsArray = $student->getAllStudents($search, $courses);
|
|
|
|
echo json_encode($studentsArray);
|
|
break;
|
|
}
|
|
|
|
case 'readEmailRecord': {
|
|
$course_id = isset($_POST['course_id']) ? $_POST['course_id'] : '';
|
|
if (!isset($course_id) || $course_id == '') {
|
|
echo json_encode($process['wrong_course']);
|
|
die();
|
|
}
|
|
|
|
$student->setCourseID($course_id);
|
|
$studentsArray = $student->getAllStudents($search, []);
|
|
|
|
echo json_encode($studentsArray);
|
|
break;
|
|
}
|
|
|
|
case 'create': { // Insert a new student
|
|
$course_id = isset($_POST['course_id']) ? $_POST['course_id'] : '';
|
|
if (!isset($course_id) || $course_id == '') {
|
|
echo json_encode($process['wrong_course']);
|
|
die();
|
|
}
|
|
|
|
$name = $_POST["name"];
|
|
$email = $_POST["email"];
|
|
$phone = $_POST["phone"];
|
|
$school_id = $_POST["schoolid"];
|
|
|
|
$student->setCourseID($course_id);
|
|
$course = $student->getCourseByID();
|
|
|
|
$sql = "SELECT * FROM `" . CRMADATBAZIS . "`.`students` WHERE email = ?";
|
|
$student->query($sql, array('s', $email));
|
|
$students = $student->fetchNext();
|
|
|
|
if (!empty($students)) {
|
|
if ($student->studentInOtherSchool($school_id, $students['school_id']))
|
|
echo json_encode($process['other_school']);
|
|
else
|
|
echo json_encode($process['user_already']);
|
|
die();
|
|
}
|
|
|
|
$student->setName($name);
|
|
$student->setEmail($email);
|
|
$student->setPhone($phone);
|
|
$student->setSchoolID($school_id);
|
|
$student->setCourseID($course_id);
|
|
$student->setEndDate($course["vegzes_ideje"]);
|
|
$student->setSchool();
|
|
$student->setCourse();
|
|
$student->addStudent();
|
|
|
|
if ($student->getnUserID() == null) {
|
|
echo json_encode($process['user_failed']);
|
|
die();
|
|
}
|
|
|
|
$student->generateStudentPassword();
|
|
break;
|
|
}
|
|
|
|
case 'delete': { // Delete the selected student
|
|
if (isset($_POST['deletedid'])) $student->deleteStudent($_POST['deletedid']);
|
|
break;
|
|
}
|
|
|
|
case 'details': { // Get the selected student's details
|
|
if (isset($_POST["editid"])) {
|
|
$userid = $_POST["editid"];
|
|
$response = array();
|
|
$student->getStudent($_POST["editid"], $response);
|
|
|
|
echo json_encode($response);
|
|
} else {
|
|
$response["status"] = 200;
|
|
$response["message"] = "Invalid Request!";
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 'update': { // Edit the selected student
|
|
if (isset($_POST["hidden_user_id"])) {
|
|
$userid = $_POST["hidden_user_id"];
|
|
$name = $_POST["name"];
|
|
$email = $_POST["email"];
|
|
$phone = $_POST["phone"];
|
|
$course_id = $_POST["course_id"];
|
|
$status = $_POST["status"];
|
|
$isDelete = $_POST["isDelete"] == "Y";
|
|
|
|
$student->setCourseID($course_id);
|
|
$course = $student->getCourseByID();
|
|
|
|
$student->setSchoolID($course['school_id']);
|
|
$school = $student->getSchoolByID();
|
|
|
|
$begin = str_replace('-', '.', $course["begin"]);
|
|
$end = str_replace('-', '.', $course["vegzes_ideje"]);
|
|
$strEducation = $school['username'] . " " . $course['course_code'] . " " . $begin . " - " . $end;
|
|
|
|
$student->setName($name);
|
|
$student->setEmail($email);
|
|
$student->setPhone($phone);
|
|
$student->setSchoolID($course['school_id']);
|
|
$student->setnSchoolID($school['nSchoolID']);
|
|
$student->setCourseID($course_id);
|
|
$student->setEndDate($course["vegzes_ideje"]);
|
|
$student->setEducation($strEducation);
|
|
$student->setSchool();
|
|
$student->setCourse();
|
|
$student->setStatus($status);
|
|
$student->updateStudent($userid, $isDelete);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 'sendEmail': { // Send email to the selected students
|
|
if (isset($_POST['selected'])) {
|
|
$selected = json_decode(stripslashes($_POST['selected']));
|
|
$school_id = $_POST['school_id'];
|
|
$course_id = $_POST['course_id'];
|
|
$isSend = array();
|
|
$error = false;
|
|
|
|
$student->setSchoolID($school_id);
|
|
$student->setCourseID($course_id);
|
|
$student->setSchool();
|
|
$student->setCourse();
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . '/maintenance/libraries/phpmailer/PHPMailerAutoload.php');
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . '/maintenance/config.mail.php');
|
|
|
|
$mail = new PHPMailer();
|
|
|
|
$mail->isSMTP();
|
|
|
|
$mail->CharSet = 'UTF-8';
|
|
$mail->Host = $mailconfig['Host'];
|
|
$mail->Port = $mailconfig['Port'];
|
|
$mail->SMTPAuth = true;
|
|
$mail->SMTPKeepAlive = true;
|
|
|
|
$mail->Username = $mailconfig['Username'];
|
|
$mail->Password = $mailconfig['Password'];
|
|
|
|
if ($student->schoolEmail != '') {
|
|
foreach ($selected as $student_id) {
|
|
$student->sendDistributorEmail($student_id, $error, $isSend, $student->schoolEmail, $mail);
|
|
}
|
|
|
|
echo json_encode($isSend);
|
|
die();
|
|
}
|
|
|
|
foreach ($selected as $student_id) {
|
|
if ($_SERVER['HTTP_HOST'] == 'www.archline.hu')
|
|
$student->sendEmail($student_id, $error, $isSend, $mail);
|
|
else
|
|
$student->sendEngEmail($student_id, $error, $isSend, $mail);
|
|
}
|
|
|
|
$msg = "";
|
|
if ($error) {
|
|
$to = "marketing@cadline.hu";
|
|
$subject = 'Email küldés hiba';
|
|
$headers = 'MIME-Version: 1.0' . "\r\n";
|
|
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
|
|
$headers .= "From: mate.nagy@cadline.hu" . "\r\n";
|
|
|
|
$counter = 0;
|
|
$msg .= "A következő email címekre nem ment ki a levél: ";
|
|
|
|
foreach ($isSend as $email) {
|
|
if ($counter == 0)
|
|
$msg .= $email;
|
|
else
|
|
$msg .= ', ' . $email;
|
|
|
|
$counter++;
|
|
}
|
|
mail($to, $subject, $msg, $headers);
|
|
}
|
|
echo json_encode($isSend);
|
|
} else {
|
|
echo json_encode($process['email_failed']);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 'excel_export': {
|
|
require_once 'library/SimpleXLSXGen.php';
|
|
|
|
$courses = array();
|
|
$course_id = $_POST['excel_c_id'];
|
|
$search = '';
|
|
|
|
$student->setCourseID($course_id);
|
|
|
|
$studentsArray = $student->getAllStudents($search, $courses);
|
|
$school = $student->getSchoolByCourse();
|
|
|
|
$header = array();
|
|
|
|
if ($_SERVER['HTTP_HOST'] == 'www.archline.hu')
|
|
$header = array('<b>Név</b>', '<b>Email</b>', '<b>Telefonszám</b>', '<b>Státusz</b>', '<b>ARCHLine.XP Sorozatszám</b>', '<b>Program indítások</b>');
|
|
else
|
|
$header = array('<b>Name</b>', '<b>Email</b>', '<b>Telephone Number</b>', '<b>Status</b>', '<b>ARCHLine.XP Serial Number</b>', '<b>Program Starts</b>');
|
|
|
|
$students = array($header);
|
|
$pwd = '';
|
|
|
|
foreach ($studentsArray as $stud) {
|
|
if (preg_match('/>(.*?)</', $stud['prPass'], $pwd) == 1)
|
|
$pwd = $pwd[1];
|
|
|
|
$starts = $student->getProgramStarts($pwd);
|
|
$status = $student->getStudentStatus($stud['status']);
|
|
$studentDatas = array($stud['name'], $stud['email'], $stud['phone'], $status, $pwd, $starts);
|
|
array_push($students, $studentDatas);
|
|
}
|
|
|
|
$xlsx = Shuchkin\SimpleXLSXGen::fromArray($students);
|
|
$xlsx->setDefaultFontSize(14);
|
|
$xlsx->downloadAs($school['school_name'] . '_' . $school['course_name'] . '.xlsx');
|
|
break;
|
|
}
|
|
|
|
case 'excel_import': { // Import students from XLSX file
|
|
if (isset($_POST['schoolid'])) {
|
|
require_once 'library/SimpleXLSX.php';
|
|
|
|
$school_id = $_POST["schoolid"];
|
|
$course_id = $_POST["course_id"];
|
|
$values = array();
|
|
$error = array();
|
|
$xlsx = SimpleXLSX::parse($_FILES['file']['tmp_name']);
|
|
|
|
foreach ($xlsx->rows() as $k => $v) {
|
|
if ($k == 0) continue;
|
|
|
|
$values[] = array(
|
|
'name' => $v[0],
|
|
'email' => $v[1],
|
|
'phone' => $v[2]
|
|
);
|
|
}
|
|
|
|
$student->setSchoolID($school_id);
|
|
$student->setCourseID($course_id);
|
|
$student->setSchool();
|
|
$student->setCourse();
|
|
$course = $student->getCourseByID();
|
|
|
|
foreach ($values as $stud) {
|
|
$name = $stud['name'];
|
|
$email = str_replace(' ', '', $stud["email"]);
|
|
$phone = $stud["phone"];
|
|
|
|
if ($name == '') continue;
|
|
|
|
if (is_numeric($name)) {
|
|
array_push($error, $process['number_name'] . ": " . $name);
|
|
continue;
|
|
}
|
|
|
|
if ($email == '') {
|
|
array_push($error, $process['missing_email'] . ": " . $name);
|
|
continue;
|
|
}
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
array_push($error, $process['invalid_email'] . ": " . $email);
|
|
continue;
|
|
}
|
|
|
|
$sql = "SELECT * FROM `" . CRMADATBAZIS . "`.`students` WHERE email = ?";
|
|
$student->query($sql, array('s', $email));
|
|
$students = $student->fetchNext();
|
|
|
|
if (!empty($students)) {
|
|
if ($student->studentInOtherSchool($school_id, $students['school_id']))
|
|
array_push($error, $process['other_school'] . ": " . $email);
|
|
else
|
|
array_push($error, $process['email_already'] . ": " . $email);
|
|
continue;
|
|
}
|
|
|
|
$student->setName($name);
|
|
$student->setEmail($email);
|
|
$student->setPhone($phone);
|
|
$student->setEndDate($course["vegzes_ideje"]);
|
|
$student->addStudent();
|
|
|
|
if ($student->getnUserID() == null) {
|
|
array_push($error, $process['user_failed'] . ": " . $email);
|
|
continue;
|
|
}
|
|
$student->generateStudentPassword();
|
|
}
|
|
|
|
echo json_encode($error);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|