FuelPHP Bin
Sign in
Public
PHP
Save
public function action_edit($id = 0) { //sending email if(Input::post('action') == 'confirm'){ foreach($this->fields as $field){ Session::set_flash($field, Input::post($field)); } $data = array(); foreach ($this->fields as $field) { $data[$field] = Session::get_flash($field); Session::keep_flash($field); } $this->template->content = View::forge('admin/mail/confirm',$data); }else{ $data["mail"] = Model_Mail::find($id); if($data["mail"] == null){ $data["mail"] = Model_mail::forge(); } // add if(Session::get_flash('title') != null and Security::check_token()){ // save $mail = $data["mail"]; $mail->for_all = Session::get_flash("for_all", 0); $mail->for_teachers = Session::get_flash("for_teachers", 0); $mail->for_students = Session::get_flash("for_students", 0); $mail->title = Session::get_flash("title"); $mail->body = Session::get_flash("body"); if($mail->for_all == null){ $mail->for_all = 0; } if($mail->for_students == null){ $mail->for_students = 0; } if($mail->for_teachers == null){ $mail->for_teachers = 0; } $mail->save(); $body = View::forge("email/mail"); $body->set("title", $mail->title); $body->set("body", $mail->body); //sending all start if($mail->for_all == 1){ $teachers = Model_User::find("all", [ "where" => [ ["group_id", 10], ["deleted_at", 0], ], "order_by" => [ ["id", "desc"] ] ]); foreach($teachers as $teacher){ $sendmail = Email::forge("JIS"); $sendmail->from(Config::get("statics.info_email"),Config::get("statics.info_name")); $sendmail->to($teacher->email); $sendmail->subject("{$mail->title} / OliveCode"); $sendmail->html_body("Dear {$teacher->firstname},\n\n". htmlspecialchars_decode($body) . "<a href='olivecode.localhost/teachers/unsubscribe'>Unsubscribe.</a>"); $sendmail->send(); } $students = Model_User::find("all", [ "where" => [ ["group_id", 1], ["deleted_at", 0], ], "order_by" => [ ["id", "desc"] ] ]); foreach($students as $student){ $sendmail = Email::forge("JIS"); $sendmail->from(Config::get("statics.info_email"),Config::get("statics.info_name")); $sendmail->to($student->email); $sendmail->subject("{$mail->title} / OliveCode"); $sendmail->html_body("Dear {$student->firstname},\n\n". htmlspecialchars_decode($body) . "<a href='olivecode.localhost/students/unsubscribe'>Unsubscribe.</a>"); $sendmail->send(); } Response::redirect("/admin/mail/sent"); }//sending all end //seding to enabled teachers start if($mail->for_teachers == 1){ $teachers = Model_User::find("all", [ "where" => [ ["group_id", 10], ["deleted_at", 0], ["need_news_email", 1] ], "order_by" => [ ["id", "desc"] ] ]); foreach($teachers as $teacher){ $sendmail = Email::forge("JIS"); $sendmail->from(Config::get("statics.info_email"),Config::get("statics.info_name")); $sendmail->to($teacher->email); $sendmail->subject("{$mail->title} / OliveCode"); $sendmail->html_body("Dear {$teacher->firstname},\n\n". htmlspecialchars_decode($body) . "<a href='olivecode.localhost/teachers/unsubscribe'>Unsubscribe.</a>"); $sendmail->send(); } }//seding to enabled teachers end //seding to enabled students start if($mail->for_students == 1){ $students = Model_User::find("all", [ "where" => [ ["group_id", 1], ["deleted_at", 0], ["need_news_email", 1] ], "order_by" => [ ["id", "desc"] ] ]); foreach($students as $student){ $sendmail = Email::forge("JIS"); $sendmail->from(Config::get("statics.info_email"),Config::get("statics.info_name")); $sendmail->to($student->email); $sendmail->subject("{$mail->title} / OliveCode"); $sendmail->html_body("Dear {$student->firstname},\n\n". htmlspecialchars_decode($body) . "<a href='olivecode.localhost/students/unsubscribe'>Unsubscribe.</a>"); $sendmail->send(); } }//seding to enabled students end Response::redirect("/admin/mail/sent"); } $view = View::forge("admin/mail/edit", $data); $this->template->content = $view; } }