getDisplayNames(); $accepted_count = 0; $declined_count = 0; $invited_count = 0; $failed_emails = array(); if($_POST['action'] == 'acceptUsers') { if(isSet($_POST['accept_decline'])) { foreach($_POST['accept_decline'] as $subscription_id => $data) { foreach($data as $cat_id => $response) { $course_meta = new CourseMeta($cat_id); if($course_meta instanceOf CourseMeta) { $action = $response['action']; $message = $this->safeStringInput($response['message'], true); switch($action) { case 2: //Decline student $declined_count++; $course_meta->setSubscriptionStatus($subscription_id, 0, $message); break; case 1: //Accept student $accepted_count++; $course_meta->setSubscriptionStatus($subscription_id, 1, $message); break; } } } } } } if($_POST['action'] == 'inviteStudents') { $emails = split("\n", $_POST['emails']); //Uploaded emails file handler if($_FILES["invite_emails_file"]["error"] == 0) { $emails_file = split("\n", file_get_contents($_FILES['invite_emails_file']['tmp_name'])); $emails = array_merge($emails_file, $emails); } /* Trim all the emails, otherwise array_unique failes */ $email_trimmed = array(); foreach($emails as $email) { $email_trimmed[] = trim($email); } //Use only unique emails $emails = array_unique($email_trimmed); $course_ids = $_POST['course_cat_id']; if(count($emails) > 0) { foreach($emails as $email) { //IF email is valid if(filter_var($email, FILTER_VALIDATE_EMAIL)) { $invited_count++; if(count($course_ids) > 0) { $message = ''; //Iterate through all the courses and generate message body foreach($course_ids as $cat_id) { $course_meta = new CourseMeta($cat_id); if($course_meta->getIsCourse() && !$course_meta->getIsClosed()) { $message .= $course_meta->inviteStudentMessage($email)."\n"; } else { $this->echoNoticeDiv(sprintf(__('Course "%s" is closed, cannot invite students', lepress_textdomain), $course_meta->getName())); if(count($course_ids) == 1) { $invited_count = 0; } } } if(!empty($message) && !$course_meta->getIsClosed()) { global $current_user; $headers = 'From: '.$current_user->user_firstname.' '.$current_user->user_lastname.' <'.$current_user->user_email.'>' . "\r\n"; $teacher_personal_message = $this->safeStringInput($_POST['invite_message'], true); $message = (!empty($teacher_personal_message) ? $teacher_personal_message."\n\n" : '').$message; $message .= 'Enter course URL on the "Addrss of Course" field on LePress -> Subscriptions page.'; $message .= "\n\n".'Invitation key(s) expire(s) in 7 days and is only valid for this email address.'."\n\n"; $message .= 'Be sure you have set the same email address in your Wordpress profile, otherwise subscribing to course fails.'; wp_mail($email, 'You have been invited to course(s)', $message, $headers); } } } else { $failed_emails[] = $email; } } } } //Unsubscribing a student if(isSet($_GET['rm'])) { $data = explode('-', base64_decode($_GET['rm'])); if(is_array($data) && count($data) == 2) { $got_cat_ID = intval($data[0]); $subscription_id = intval($data[1]); if(intval($got_cat_ID) > 0) { if($subscription_id > 0) { $course_meta = new CourseMeta($got_cat_ID); $student = $course_meta->getStudentBySubscription($subscription_id); if($student) { $course_meta->setSubscriptionStatus($subscription_id, 2, $message = false); $name = $display_name_order == 1 ? $student->first_name.' '.$student->last_name : $student->last_name.' '.$student->first_name; $this->echoNoticeDiv(__('You have unsubscribed student', lepress_textdomain).' - '.$name); } } } } } //Display accepted students count if($accepted_count > 0) { $this->echoNoticeDiv(sprintf(_n(__("You have accepted %d student.", lepress_textdomain), __("You have accepted %d students.", lepress_textdomain), $accepted_count, lepress_textdomain), $accepted_count)); } //Display declined students count if($declined_count > 0) { $this->echoNoticeDiv(sprintf(_n(__("You have declined %d student.", lepress_textdomain), __("You have declined %d students.", lepress_textdomain), $declined_count, lepress_textdomain), $declined_count)); } //Display invited students count if($invited_count > 0) { $this->echoNoticeDiv(sprintf(_n(__("You have invited %d student.", lepress_textdomain), __("You have invited %d students.", lepress_textdomain), $invited_count, lepress_textdomain), $invited_count)); } //Display failed invites count if(($f = count($failed_emails)) > 0) { $this->echoNoticeDiv(sprintf(_n(__("%d student email was not valid.", lepress_textdomain), __("%d students emails were not valid.", lepress_textdomain), $f, lepress_textdomain), $f)); } ?>