diff options
Diffstat (limited to 'public/app/controllers')
| -rw-r--r-- | public/app/controllers/Office.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/public/app/controllers/Office.php b/public/app/controllers/Office.php index be8919f..79f76d8 100644 --- a/public/app/controllers/Office.php +++ b/public/app/controllers/Office.php @@ -7,6 +7,7 @@ use Render; use app\controllers\Auth; use app\extends\App_manager; use app\models\Content_model; +use app\extends\SendMail_service; use app\extends\Cache_service; /** Office class @@ -333,6 +334,82 @@ class Office { } + ## SEND INVITATION + ## ------------------------------------------------------------------------- + + public static function send_invitation() + { + if (Auth::in_admin_group()) { + + $now = time(); // keep `now` and `expiration` timestamps + $expiration = $now + ( 3600 * 72 ); + + // prepare the prepare statement + $handler = []; + $binds = [ ':now' => $now ]; // sure value to bind + + foreach(Registry::get('REQUEST')->POST['ids'] as $key => $id) { + $handler[] = ':id'. $key; + $binds[':id'. $key] = $id; + } + + $all_handlers = implode(', ', $handler); + + $recipients = Registry::use('database')->runQuery( + "SELECT * FROM user + WHERE id IN ( $all_handlers ) AND ( + otp_expiration < :now OR otp_expiration IS NULL + )", + $binds + ); + + $sent = []; + + foreach($recipients as $key => $rec) { + $invitation = md5( + $rec['first_name'] + . $rec['last_name'] + . $rec['email'] + . rand(0, 999999) + ); + + /* + $gone = SendMail_service::send_invitation([ + 'email' => $rec['email'], + 'name' => $rec['last_name'] .' '. $rec['fisrt_name'], + 'code' => $invitation + ]) + + if ($gone) { + // update user record with invitation + Registry::use('database')->runQuery( + "UPDATE user SET invitatopm = :inv WHERE id = :id", + [ ':inv' => $invitation, ':id' => $rec['id'] ] + ); + + $sent[] = $rec['first_name'] + ." ". $rec['last_name'] + ." (". $rec['id'] .")" + .": ". $invitation; + } + */ + + $sent[] = $rec['first_name'] + ." ". $rec['last_name'] + ." (". $rec['id'] .")" + .": ". $invitation; + } + + return Render::json([ + 'success' => true, + 'sent' => implode(",\n\n", $sent), + ]); + + } + } + + + public static function petition_copy($sign) { if (Auth::in_admin_group()) { |
