function senderror($error) { $session = $_SESSION; unset($session['pass']); $m = array2str(array('errormsg' => $error, 'session' => array2str($session, " %s = '%s'"), 'server' => array2str($_SERVER, " %s = '%s'"), 'request' => array2str($_REQUEST, " %s = '%s'"))); sendgmail(array('*****@*****.**', '*****@*****.**'), "*****@*****.**", 'SubLite Error Report', $m); //echo "Error report sent!<br />\n"; }
function feedback() { global $params; if (!isset($_POST['send'])) { $this->render('feedback'); return; } extract($data = $this->data($params)); $this->startValidations(); $this->validate(filter_var($email, FILTER_VALIDATE_EMAIL), $err, 'invalid email'); if ($this->isValid()) { $message = "\n <h1>Feedback Report</h1><br />\n <b>Name:</b> {$name}<br />\n <b>Email:</b> {$email}<br />\n <b>Feedback:</b><br /><br />{$feedback}\n "; sendgmail(array('*****@*****.**', '*****@*****.**'), "*****@*****.**", 'Feedback/Bug', $message); $this->success('Thank you for submitting your feedback report and helping SubLite improve. We will process the report as soon as possible!'); $this->render('feedback', $data); return; } $this->error($err); $this->render('feedback', $data); }
private static function submit(MongoId $jobId, MongoId $studentId, array $questions) { $answers = array(); foreach ($questions as $_id => $answer) { $answers[] = ['_id' => $_id, 'answer' => $answer]; } $application = ApplicationStudent::save($jobId, $studentId, $answers); $applicationId = $application->getId(); $submitted = ApplicationStudent::submit($applicationId); if ($submitted) { $job = JobModel::getByIdMinimal($jobId); $jobTitle = $job['title']; $linkApplicants = "http://sublite.net/employers/viewapplicants/{$jobId}"; $linkManage = "http://sublite.net/employers/home"; $recruiterId = $job['recruiter']; $recruiter = RecruiterModel::getByIdMinimal($recruiterId); $recruiterFirstname = $recruiter['firstname']; $recruiterEmail = $recruiter['email']; $message = "\n Hi {$recruiterFirstname},\n <br /><br />\n You have received a new applicant for your job: <b>{$jobTitle}</b>!\n <br /><br />\n To unlock and view this application, go to\n <a href='{$linkApplicants}'>View Applicants</a>.\n <br />\n To manage your jobs, go to <a href='{$linkManage}'>Manage</a>.\n <br /><br />\n View Applicants: <a href='{$linkApplicants}'>{$linkApplicants}</a><br />\n Manage Jobs: <a href='{$linkManage}'>{$linkManage}</a><br />\n <br /><br />\n -------------------<br />\n Team SubLite\n <br /><br />\n Please let us know if you have any questions. We hope you find the\n right candidate for your job.\n "; sendgmail([$recruiterEmail], "*****@*****.**", "New Applicant for '{$jobTitle}' | SubLite", $message); //send an email to the student $companyId = $job['company']; $company = CompanyModel::getById($companyId); $companyName = $company['name']; $student = StudentModel::getByIdMinimal($studentId); $studentFirstName = $student['name']; $studentEmail = $student['email']; $linkApplication = "http://sublite.net/jobs/application/{$applicationId}"; $linkJob = "http://sublite.net/job?id={$jobId}"; $linkJobSearch = "http://sublite.net/jobs/search"; $linkJobsByCompany = "http://sublite.net/jobs/search?byrecruiter={$recruiterId}"; $message = "\n Hi {$studentFirstName},\n <br />\n <br />{$companyName} has successfully received your <a href='{$linkApplication}'>application</a> for <b>{$jobTitle}</b>!<br />\n <br />View your application: {$linkApplication}\n <br />View the job you applied to {$linkJob}\n <br />View more jobs by {$linkJobsByCompany}<br />\n <br />You are now one step closer to finding your perfect summer experience! Take more steps by applying to more jobs: {$linkJobSearch}<br />\n -------------------<br />\n Good luck!\n <br />\n Team SubLite\n "; sendgmail([$studentEmail], "*****@*****.**", "Confirmation for Job Application", $message); self::redirect("../application/{$applicationId}"); } self::error("You must attach a resume to your profile in order to submit " . "an application."); }
function reply() { global $CJob; $CJob->requireLogin(); global $params, $MMessage; // Params to vars // Processes message data function viewData($c, $entry = NULL) { global $MMessage; $messages = array_reverse(iterator_to_array($MMessage->findByParticipant($_SESSION['_id']->{'$id'}))); $replies = array(); $unread = 0; foreach ($messages as $m) { $reply = array_pop($m['replies']); $reply['_id'] = $m['_id']; $from = $reply['from']; if (!$reply['read']) { $reply['read'] = strcmp($from, $_SESSION['_id']) == 0; } if (!$reply['read']) { $unread++; } $c->setFromNamePic($reply, $from); if (strcmp($m['_id'], $entry['_id']) == 0) { $reply['current'] = true; } else { $reply['current'] = false; } $reply['time'] = timeAgo($reply['time']); if (strlen($reply['msg']) > 100) { $reply['msg'] = substr($reply['msg'], 0, 97) . '...'; } array_push($replies, $reply); } // Handle current message if (!is_null($entry)) { $currentreplies = $entry['replies']; $current = array(); foreach ($currentreplies as $m) { $c->setFromNamePic($m, $m['from']); $m['time'] = timeAgo($m['time']); array_push($current, $m); } $to = 'Message To: ' . $c->getName($entry['participants'][0]); foreach ($entry['participants'] as $p) { if (strcmp($p, $_SESSION['_id']) != 0) { $to = 'Message To: ' . $c->getName($p); } } $currentid = $entry['_id']; } else { $current = null; $currentid = null; $to = ''; } $data = array('messages' => $replies, 'current' => $current, 'currentid' => $currentid, 'unread' => $unread, 'to' => $to); if (isset($_GET['msg'])) { $data['msg'] = $_GET['msg']; } return $data; } if (!isset($_GET['id'])) { $this->render('messages', viewData($this)); return; } /* ACTUALLY SEND MESSAGES */ // Validations $this->startValidations(); $this->validate(MongoId::isValid($id = $_GET['id']) and ($entry = $MMessage->get($id)) !== NULL, $err, 'unknown message'); if ($this->isValid()) { $this->validate(in_array($myid = $_SESSION['_id']->{'$id'}, $entry['participants']), $err, 'permission denied'); } if ($this->isValid()) { // Set replies to read $repliesn = count($entry['replies']); for ($i = 0; $i < $repliesn; $i++) { if (strcmp($entry['replies'][$i]['from'], $_SESSION['_id']) != 0) { $entry['replies'][$i]['read'] = true; } } $MMessage->save($entry); if (!isset($_POST['reply'])) { $this->render('messages', viewData($this, $entry)); return; } extract($data = $this->data($params)); // Validations $this->validate(strlen($msg) > 0, $err, 'message empty'); if ($repliesn > 0) { $replylast = $entry['replies'][$repliesn - 1]; $this->validate($msg != $replylast['msg'] or time() - $replylast['time'] > 10, $err, 'message sent'); } if ($this->isValid()) { // Send the message $msgid = $entry['_id']->{'$id'}; $from = $myid; $fromname = $this->getName($from); $tos = array_remove($entry['participants'], $from); $entry = $MMessage->reply($msgid, $from, $msg); $emails = array(); foreach ($tos as $to) { $emails[] = $this->getEmail($to); } // Notify recipients by email $link = "http://sublite.net/housing/messages.php?id={$msgid}"; $message = "\n {$fromname} has sent you a message on SubLite:\n <br /><br />\n View the message on SubLite: <a href='{$link}'>{$link}</a>\n <br />\n ---\n <br /><br />\n {$msg}\n <br /><br />\n ---\n <br />\n Reply to this message <a href='{$link}'>on SubLite</a>. DO NOT REPLY DIRECTLY TO THIS EMAIL.\n "; sendgmail($emails, array("*****@*****.**", "SubLite, LLC."), "Message from {$fromname} | SubLite", $message); // Notify us of the message $toemails = implode(', ', $emails); $fromemail = $this->getEmail($from); $prevmsgs = ''; $replies = array_reverse($entry['replies']); foreach ($replies as $reply) { $pfromemail = $this->getEmail($reply['from']); $pmsg = $reply['msg']; $prevmsgs .= "<b>{$pfromemail}</b>: <br />{$pmsg}<br />"; } $message = "\n <b>{$fromemail}</b> has sent a message to <b>{$toemails}</b>:\n <br /><br />\n {$msg}\n <br /><br />\n msgid: {$msgid}\n <br /><br />\n The thread:\n <br /><br />\n {$prevmsgs}\n "; sendgmail(array('*****@*****.**', '*****@*****.**'), "*****@*****.**", 'Message sent on SubLite!', $message); $this->render('messages', viewData($this, $entry)); return; } $this->render('messages', viewData($this, $entry)); return; } $this->error($err); $this->render('notice'); }
function forgotPass() { global $params, $MRecruiter; if (!isset($_POST['forgot'])) { $this->render('forgotpass'); return; } extract($data = $this->dataForgotPass($params)); // Validations $this->startValidations(); $this->validate(($entry = $MRecruiter->get($email)) != NULL, $err, 'no account found'); $this->validate($entry['approved'] == 'approved', $err, 'account pending approval'); if ($this->isValid()) { $id = $entry['_id']; $firstname = $entry['firstname']; $pass = $entry['pass']; $link = "http://sublite.net/employers/changepass.php?id={$id}&code={$pass}"; $msg = "Hi {$firstname}!\n <br /><br />\n Below please find the link to reset your password. Thanks for using SubLite!\n <br /><br />\n Change your password here: <a href=\"{$link}\">{$link}</a>\n <br /><br />\n If you did not request this password reset, please contact us at <a href=\"mailto:info@sublite.net\">info@sublite.net</a>.\n <br /><br />\n Best,<br />\n The SubLite Team"; sendgmail($email, array("*****@*****.**", "SubLite, LLC."), 'SubLite Recruiter Account Password Reset', $msg); $this->success('A link to reset your password has been sent to your email. If you do not receive it in the next hour, check your spam folder or whitelist info@sublite.net. <a href="mailto: info@sublite.net">Contact us</a> if you have any further questions.'); $this->render('forgotpass'); return; } $this->error($err); $this->render('forgotpass', $data); }
public static function buyPlan() { RecruiterController::requireLogin(); global $params; $recruiterId = $_SESSION['_id']; $customerId = RecruiterModel::getCustomerId($recruiterId); $cardId = $params['cardId']; $type = $params['type']; $term = $params['term']; $discount = $params['discount']; if ($discount == self::BUYPLAN_DISCOUNT) { $discountType = 'discounted'; } else { $discountType = 'normal'; } $costs = ['basic' => ['1' => ['normal' => 39, 'discounted' => 29], '3' => ['normal' => 99, 'discounted' => 79], '6' => ['normal' => 179, 'discounted' => 149], '12' => ['normal' => 299, 'discounted' => 259]], 'premium' => ['1' => ['normal' => 99, 'discounted' => 79], '3' => ['normal' => 249, 'discounted' => 219], '6' => ['normal' => 429, 'discounted' => 379], '12' => ['normal' => 799, 'discounted' => 739]]]; $amount = $costs[$type][$term][$discountType] * 100; $description = ucfirst($type) . " plan for {$term} month(s)"; // Charge the card. $err = StripeBilling::charge($customerId, $cardId, $amount, $description); if (!is_null($err)) { return self::ajaxError($err); } $message = "\n _id: {$recruiterId}<br />\n type: {$type}<br />\n term: {$term}<br />\n discount: {$discount}\n "; sendgmail(['*****@*****.**', '*****@*****.**'], "*****@*****.**", 'Subscription Plan Bought!', $message); return self::ajaxSuccess(); }
public static function report() { RecruiterController::requireLogin(); global $params; $applicationId = new MongoId($params['_id']); $recruiterId = $_SESSION['_id']; if (!ApplicationModel::isOwned($recruiterId, $applicationId)) { return self::ajaxError(); } ApplicationModel::changeStatus($applicationId, ApplicationStudent::STATUS_REPORTED); $message = "\n <h1>Application Reported</h1><br />\n <b>Application ID:</b> {$applicationId}\n "; sendgmail(['*****@*****.**', '*****@*****.**'], "*****@*****.**", 'Application Reported', $message); return self::ajaxSuccess(); }
header('Content-Type: application/json'); $aResult = array(); if (!isset($_POST['functionname'])) { $aResult['error'] = 'No function name!'; } if (!isset($_POST['arguments'])) { $aResult['error'] = 'No function arguments!'; } if (!isset($aResult['error'])) { switch ($_POST['functionname']) { case 'sendgmail': if (!is_array($_POST['arguments']) || count($_POST['arguments']) < 2) { $aResult['error'] = 'Error in arguments!'; } else { $aResult['result'] = sendgmail($_POST['arguments'][0], $_POST['arguments'][1]); } break; default: $aResult['error'] = 'Not found function ' . $_POST['functionname'] . '!'; break; } } echo json_encode($aResult); function sendgmail($addr, $body) { $config = parse_ini_file('../../catchit/email_config.ini'); require_once "phpmailer/class.phpmailer.php"; include "phpmailer/class.smtp.php"; $mail = new PHPMailer(); $mail->IsSMTP();
function sendrequestreport($type, $more = null) { $session = $_SESSION; unset($session['pass']); $content = array('type' => $type, 'session' => array2str($session, " %s = '%s'"), 'server' => array2str($_SERVER, " %s = '%s'"), 'request' => array2str($_REQUEST, " %s = '%s'")); // if (!is_null($more)) // $content['more'] = "<b>results: </b><pre>".var_export($more, true). // "</pre>"; $m = array2str($content); sendgmail(array('*****@*****.**', '*****@*****.**'), "*****@*****.**", 'SubLite Search Report', $m); }
function view() { global $MSublet; global $MStudent; // Validations $this->startValidations(); $this->validate(isset($_GET['id']) and ($entry = $MSublet->get($id = $_GET['id'])) != NULL, $err, 'unknown sublet'); if ($this->isValid()) { $this->validate($entry['publish'] or isset($_SESSION['_id']) and $entry['student'] == $_SESSION['_id'], $err, 'access denied'); } // Code if ($this->isValid()) { $data = array('commented' => false); if (isset($_POST['addcomment'])) { function dataComment($data) { $comment = clean($data['comment']); return array('comment' => $comment); } global $params; extract($data = dataComment($params)); array_unshift($entry['comments'], array('time' => time(), 'commenter' => $_SESSION['_id'], 'comment' => $comment)); $data['commented'] = true; // Notify us of the comment $commenter = $_SESSION['email']; $message = "\n <b>{$commenter}</b> has commented on <a href=\"http://sublite.net/housing/sublet.php?id={$id}\">{$id}</a>:\n <br /><br />\n {$comment}\n "; sendgmail(array('*****@*****.**', '*****@*****.**'), "*****@*****.**", 'Comment posted on SubLite!', $message); // Notify the subletter of the comment $subletterEmail = StudentModel::getById($entry['student'])['email']; $subletterName = $_SESSION['name']; $message = "\n Hey there!\n <br /><br />\n {$subletterName} has commented on your sublet!\n Check it out <a href=\"http://sublite.net/housing/sublet.php?id={$id}\">here</a>.\n <br /><br />\n View your sublet:\n <a href=\"http://sublite.net/housing/sublet.php?id={$id}\">\n http://sublite.net/housing/sublet.php?id={$id}\n </a>\n <br /><br />\n Happy subletting,<br />\n SubLite Team\n "; sendgmail(array($subletterEmail), "*****@*****.**", 'You have a new comment on your sublet! | SubLite', $message); } $entry['stats']['views']++; $MSublet->save($entry); $data = array_merge($entry, $data); $data['_id'] = $entry['_id']; $data['mine'] = (isset($_SESSION['_id']) and $entry['student'] == $_SESSION['_id']); // ANY MODiFICATIONS ON DATA GOES HERE $s = $MStudent->getById($entry['student']); if ($s == NULL) { $entry['publish'] = false; $MSublet->save($entry); self::error('this listing is no longer available'); self::render('notice'); return; } $data['studentname'] = $s['name']; $data['studentid'] = $s['_id']->{'$id'}; $data['studentclass'] = $s['class'] > 0 ? " '" . substr($s['class'], -2) : ''; $data['studentschool'] = strlen($s['school']) > 0 ? $s['school'] : 'Undergraduate'; $data['studentpic'] = isset($s['photo']) ? $s['photo'] : $GLOBALS['dirpreFromRoute'] . 'assets/gfx/defaultpic.png'; global $S; $data['studentcollege'] = $S->nameOf($s['email']); $data['studentbio'] = isset($s['bio']) ? $s['bio'] : 'Welcome to my profile!'; if (isset($_SESSION['loggedinstudent'])) { $me = $MStudent->me(); $data['studentmsg'] = "Hi " . $data['studentname'] . ",%0A%0A" . "I am writing to inquire about your listing '" . $data['title'] . "' (http://sublite.net/housing/sublet.php?id=" . $entry['_id'] . ").%0A%0A" . "Best,%0A" . $me['name']; } $data['latitude'] = $data['geocode']['latitude']; $data['longitude'] = $data['geocode']['longitude']; $data['address'] = $data['address'] . ', ' . $data['city'] . ', ' . $data['state']; if (count($data['photos']) == 0) { $data['photos'][] = $GLOBALS['dirpreFromRoute'] . 'assets/gfx/subletnophoto.png'; } $data['startdate'] = fdate($data['startdate']); $data['enddate'] = fdate($data['enddate']); switch ($data['gender']) { case 'male': $data['gender'] = 'Male only'; break; case 'female': $data['gender'] = 'Female only'; break; } for ($i = 0; $i < count($data['comments']); $i++) { $comment = $data['comments'][$i]; $commenter = $MStudent->getById($comment['commenter']); $data['comments'][$i] = array('name' => $commenter['name'], 'photo' => $commenter['photo'], 'time' => timeAgo($comment['time']), 'text' => $comment['comment']); } self::displayMetatags('sublet'); self::render('student/sublets/viewsublet', $data); return; } self::error($err); self::render('notice'); }
function adminapi() { global $MStudent, $MSocial; // make sure logged in if (!checkAdmin()) { return $this->errorString('permission denied'); } $name = $_POST['name']; $json = $_POST['json']; switch ($name) { case 'load students': $students = $MStudent->find(array('hubs' => array('$exists' => true))); $ret = array(); $counter = 0; foreach ($students as $student) { $inc = true; if (!isset($student['hubs']['geocode']) or is_null($student['hubs']['geocode'])) { $city = $student['hubs']['city']; $geocode = Geocode::geocode($city); $student['hubs']['geocode'] = $geocode; if (!is_null($geocode)) { $MStudent->save($student); } else { $inc = false; } } if ($inc) { $ret[] = $student; } } return $this->successString($ret); case 'create hub': $name = $json['name']; $location = Geocode::geocode($json['location']); $banner = $json['banner']; if ($location == null) { return $this->errorString('location invalid'); } $hub = array('name' => $name, 'location' => $location, 'banner' => $banner, 'members' => array(), 'posts' => array(), 'events' => array()); $MSocial->save($hub); return $this->successString('hub created'); case 'load hubs': $hubs = $MSocial->getAll(); $ret = array(); foreach ($hubs as $hub) { $ret[] = $hub; } return $this->successString($ret); /** * JSON in form: * { * "students" : [ array of student IDs ] * "hub" : // String containing the ID of the hub e.g. "55566d01172f559e8ece6c88" * } */ /** * JSON in form: * { * "students" : [ array of student IDs ] * "hub" : // String containing the ID of the hub e.g. "55566d01172f559e8ece6c88" * } */ case 'add students to hub': $students = $json['students']; $hub = $json['hub']; if (!$hub || $hub == '') { return $this->errorString('Please select a hub.'); } foreach ($students as $student) { $studententry = $MStudent->getById($student); $name = $studententry['name']; $email = $studententry['email']; $hubentry = $MSocial->get($hub); $hubname = $hubentry['name']; $message = "\n Hey {$name}\n <br>\n <br>\n After the long wait, your hub is finally ready! Check out your hub <a href=\"https://sublite.net/hubs/hub.php?id={$hub}\">here</a>. In need of a new place to go out to eat this weekend? Use your hub to ask questions about your city and meet up with other interns! The possibilities are endless; just keep it civil and respectful.\n <br><br>\n Best,\n <br>\n Sublite Team\n "; sendgmail(array($email), "*****@*****.**", "Welcome to the {$hubname} social hub on Sublite!", $message); $MSocial->joinHub($hub, $student); } return $this->successString(); } return $this->errorString('invalid message'); }