<?php

App::uses('CakeEmail', 'Network/Email');
App::uses('Component', 'Controller');

Class MailcontentComponent extends Component {

    public $components = array('Session', 'Email', 'Mailer');

    public function orderconfirm($order_id) {
        $this->Order = ClassRegistry::init('Order');
        $data = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id)));

        $message = "";
        $message.="<p>Dear " . $data['Order']['name'] . ",</p>";
        $message.="<br />";
        $message.="<p>Following are the details received for the order uploaded by you.</p>";
        $message.="<p><strong>Order No: </strong> " . $data['Order']['orderid'] . ",</p>";
        $message.="<p><strong>Subject: </strong> " . $data['Order']['subject'] . ",</p>";
        $message.="<p><strong>Details: </strong> " . $data['Order']['desc'] . ",</p>";
        $message.="<p><strong>Deadline: </strong> " . $data['Order']['due_date'] . ",</p>";
        $message.="<p><strong>No of pages: </strong> " . $data['Order']['page'] . "</p>";
        $message.="<br />";
        $message.="<p>We will contact you soon.</p>";

        $to = $data['Order']['email'];
        $subject = "Details for your Maths assignment - " . Configure::read('SITE_TITLE');
        $from = Configure::read('FROM_EMAIL_ADDRESS');
        $emailtemplate = "newtemplete";

        $this->Mailer->sendMail($to, $subject, $from, $message, $attachments = null, $emailCofig = 'default', $emailtemplate);
    }

    public function orderquote($order_id) {
        $this->Order = ClassRegistry::init('Order');
        $data = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id)));
        $link = Router::url('/', true) . "payments?o_id=" . $data['Order']['orderid'];

        $message = "";
        $message.="<p>Dear " . $data['Order']['name'] . ",</p>";
        $message.="<br />";
        $message.="<p>We have gone through your assignment details and confirm the order will be done as per the requirements mentioned by you.</p>";
        $message.="<p>To make the payment, kindly log into your account & click the payment button on the order page OR pay directly using the below mentioned link.</p>";
        $message.="<p><strong>Order No: </strong> " . $data['Order']['orderid'] . ",</p>";
        $message.="<p><strong>Subject: </strong> " . $data['Order']['subject'] . ",</p>";
        $message.="<p><strong>Total Charges: </strong> USD " . $data['Order']['order_quote'] . ",</p>";
        $message.="<p><strong>Pay to start: </strong> USD " . $data['Order']['order_quote'] . ",</p>";
        $message.="<p><strong>Payment Link: </strong> <a href='$link'> " . $link . "</a></p>";
        $message.="<p><strong>Message : </strong> Our experts are ready to work on your assignment right away!</p>";
        $message.="<br />";
        $message.="<p>Regards,</p>";
        $message.="<p>" . Configure::read('SITE_TEAM') . "</p>";

        $to = $data['Order']['email'];
        $subject = "Best Price - USD " . $data['Order']['order_quote'] . " for your assignment - " . Configure::read('SITE_TITLE');
        $from = Configure::read('FROM_EMAIL_ADDRESS');
        $emailtemplate = "newtemplete";

        $this->Mailer->sendMail($to, $subject, $from, $message, $attachments = null, $emailCofig = 'default', $emailtemplate);
    }

    public function recievepayment($order_id) {
        $this->Order = ClassRegistry::init('Order');
        $data = $this->Order->find('first', array('conditions' => array('Order.id' => $order_id)));

        $message = "";
        $message.="<p>Dear " . $data['Order']['name'] . ",</p>";
        $message.="<br />";
        $message.="<p>We earnestly acknowledge your payment of $ " . $data['Order']['order_quote'] . ", which we received from you through PayPal..</p>";
        $message.="<p>We are looking forward and get back to you soon.</p>";
        $message.="<br />";
        $message.="<p>Regards,</p>";
        $message.="<p>" . Configure::read('SITE_TEAM') . "</p>";

        $to = $data['Order']['email'];
        $subject = "Payment Success - USD " . $data['Order']['order_quote'] . " for your assignment - " . Configure::read('SITE_TITLE');
        $from = Configure::read('FROM_EMAIL_ADDRESS');
        $emailtemplate = "newtemplete";

        $this->Mailer->sendMail($to, $subject, $from, $message, $attachments = null, $emailCofig = 'default', $emailtemplate);
    }

    public function contactus($data) {
        $message = "";
        $message.="<p>Hello " . $data['Contact']['name'] . ",</p>";
        $message.="<br />";
        $message.="<p><strong>Phone: </strong> " . $data['Contact']['phone'] . "</p>";
        $message.="<p><strong>Message: </strong> " . $data['Contact']['note'] . "</p>";
        $message.="<br />";
        $message.="<p>We will contact you soon.</p>";

        $to = Configure::read('FROM_EMAIL_ADDRESS');
        $subject = "Contact Form for Maths assignment - " . Configure::read('SITE_TITLE');
        $from = $data['Contact']['email'];
        $emailtemplate = "newtemplete";
        $this->Mailer->sendMail($to, $subject, $from, $message, $attachments = null, $emailCofig = 'default', $emailtemplate);
    }

    public function admin_add_institute_mail($data) {

        //Mail To institute : Start
        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');
        $mailer_subject = "$SiteTitle : Registration";

        $body = "<p>Hello " . $data['Institute']['institute_name'] . ",</p>";
        $body .= "<p>Welcome to $SiteTitle.</p>";
        $body .= "<p>You have successfully register in our website.</p>";
        $body .= "<p>Your account has been in under process. We will contact you in 24 hours.</p>";
        $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function admin_add_personal_mail($data) {

        //Mail To institute : Start
        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');
        $mailer_subject = "$SiteTitle : Registration";

        $body = "<p>Hello " . $data['Personal']['firstname'] . " " . $data['Personal']['lastname'] . ",</p>";
        $body .= "<p>Welcome to $SiteTitle.</p>";
        $body .= "<p>You have successfully register in our website.</p>";
        $body .= "<p>Your account has been in under process. We will contact you in 24 hours.</p>";
        $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To Admin : End
    }

    public function signup_institute_mail($data) {
        if ($data['User']['account_type'] == 'p') {
            //Mail To Admin : Start
            $mailer_to = Configure::read('ADMIN_EMAIL_ADDRESS');
            $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
            $SiteTeam = Configure::read('SITE_TEAM');
            $SiteTitle = Configure::read('SITE_TITLE');
            $mailer_subject = "$SiteTitle : New User registration";

            $body = "<p>Hello Admin,</p>";
            $body .= "<p>New Personal user registered on your website.</p>";
            $body .= "<p>Name : " . $data['Institute']['firstname'] . " " . $data['Institute']['lastname'] . "</p>";
            $body .= "<p>Email : " . $data['User']['email'] . "</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
            $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
            //Mail To Admin : End
            //Mail To institute : Start
            $mailer_to = $data['User']['email'];
            $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
            $SiteTeam = Configure::read('SITE_TEAM');
            $SiteTitle = Configure::read('SITE_TITLE');
            $mailer_subject = "$SiteTitle : Registration";

            $body = "<p>Hello " . $data['Institute']['firstname'] . " " . $data['Institute']['lastname'] . ",</p>";
            $body .= "<p>Welcome to $SiteTitle.</p>";
            $body .= "<p>You have successfully register in our website.</p>";
            $body .= "<p>Your account has been in under process. We will contact you in 24 hours.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
            $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
            //Mail To Admin : End
        } else {
            //Mail To Admin : Start
            $mailer_to = Configure::read('ADMIN_EMAIL_ADDRESS');
            $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
            $SiteTeam = Configure::read('SITE_TEAM');
            $SiteTitle = Configure::read('SITE_TITLE');
            $mailer_subject = "$SiteTitle : New institute registration";

            $body = "<p>Hello Admin,</p>";
            $body .= "<p>New institute registered on your website.</p>";
            $body .= "<p>Name : " . $data['Institute']['institute_name'] . "</p>";
            $body .= "<p>Email : " . $data['User']['email'] . "</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
            $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
            //Mail To Admin : End
            //Mail To institute : Start
            $mailer_to = $data['User']['email'];
            $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
            $SiteTeam = Configure::read('SITE_TEAM');
            $SiteTitle = Configure::read('SITE_TITLE');
            $mailer_subject = "$SiteTitle : Registration";

            $body = "<p>Hello " . $data['Institute']['institute_name'] . ",</p>";
            $body .= "<p>Welcome to $SiteTitle.</p>";
            $body .= "<p>You have successfully register in our website.</p>";
            $body .= "<p>Your account has been in under process. We will contact you in 24 hours.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
            $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
            //Mail To institute : End
        }
    }

    public function institute_emailverify($institute_id) {
        $this->Institute = ClassRegistry::init('Institute');
        $data = $this->Institute->read(null, $institute_id);

        //Mail To institute : Start
        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');
        $mailer_subject = "$SiteTitle : Account verification";

        $body = "<p>Hello " . $data['Institute']['institute_name'] . ",</p>";
        $body .= "<p>Your account request has been approved.</p>";
        $body .= "<p>You will shortly receive an activation email to your email address. After that you can access your account.</p>";
        $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function institute_activedeactive($institute_id) {
        $this->Institute = ClassRegistry::init('Institute');
        $this->Institute->recursive = 0;
        $data = $this->Institute->read(null, $institute_id);
        $mailer_to = $data['User']['email'];
        $admin_email_address = Configure::read('ADMIN_EMAIL_ADDRESS');
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $SubDomainUrl = Configure::read('SUB_DOMAIN_URL');

        if ($data['Institute']['active'] == 1) {
            $mailer_subject = "$SiteTitle : Account activation";
            $subdomainurl = "http://" . $data['Institute']['domain_name'] . $SubDomainUrl;
            $body = "<p>Hello " . $data['Institute']['institute_name'] . ",</p>";
            $body .= "<p>Your account has been activated now.</p>";
            $body .= "<p>You can access your account at <a href='$subdomainurl'>$subdomainurl<a/>.</p>";
            $body .= "<p>If you have any issue then please contact us <a href='mailto:$admin_email_address'>$admin_email_address</a>.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        } else {
            $mailer_subject = "$SiteTitle : Account Deactivation";
            $body = "<p>Hello " . $data['Institute']['institute_name'] . ",</p>";
            $body .= "<p>Your account has been deactivate.</p>";
            $body .= "<p>If you have any issue then please contact us <a href='mailto:$admin_email_address'>$admin_email_address</a>.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        }
        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function personal_emailverify($personal_id) {
        $this->Personal = ClassRegistry::init('Personal');
        $this->Personal->recursive = 2;
        $data = $this->Personal->read(null, $personal_id);
        //Mail To institute : Start
        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');
        $mailer_subject = "$SiteTitle : Account verification";

        $body = "<p>Hello " . $data['Personal']['firstname'] . " " . $data['Personal']['lastname'] . ",</p>";
        $body .= "<p>Your account request has been approved.</p>";
        $body .= "<p>You will shortly receive an activation email to your email address. After that you can access your account.</p>";
        $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function personal_activedeactive($personal_id) {
        $this->Personal = ClassRegistry::init('Personal');
        $this->Personal->recursive = 0;
        $data = $this->Personal->read(null, $personal_id);
        $mailer_to = $data['User']['email'];
        $admin_email_address = Configure::read('ADMIN_EMAIL_ADDRESS');
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $SubDomainUrl = Configure::read('SITE_URL');

        if ($data['Personal']['active'] == 1) {
            $mailer_subject = "$SiteTitle : Account activation";

            $body = "<p>Hello " . $data['Personal']['firstname'] . " " . $data['Personal']['lastname'] . ",</p>";
            $body .= "<p>Your account has been activated now.</p>";
            $body .= "<p>You can access your account at <a href='$SubDomainUrl'>$SubDomainUrl<a/>.</p>";
            $body .= "<p>If you have any issue then please contact us <a href='mailto:$admin_email_address'>$admin_email_address</a>.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        } else {
            $mailer_subject = "$SiteTitle : Account Deactivation";

            $body = "<p>Hello " . $data['Personal']['firstname'] . " " . $data['Personal']['lastname'] . ",</p>";
            $body .= "<p>Your account has been deactivate.</p>";
            $body .= "<p>If you have any issue then please contact us <a href='mailto:$admin_email_address'>$admin_email_address</a>.</p>";
            $body .= "<p>Thank you <br/> " . $SiteTeam . "</p>";
        }

        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function add_customer_mail($data) {

        $institute_id = $data['Customer']['institute_id'];

        $this->Institute = ClassRegistry::init('Institute');
        $this->Institute->recursive = -1;
        $institute_data = $this->Institute->read(null, $institute_id);

        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $SubDomainUrl = Configure::read('SUB_DOMAIN_URL');

        $mailer_subject = "$SiteTitle : Customer registration";
        $subdomainurl = "http://" . $institute_data['Institute']['domain_name'] . $SubDomainUrl;
        $body = "<p>Hello " . $data['Customer']['firstname'] . " " . $data['Customer']['lastname'] . ",</p>";
        $body .= "<p>Welcome and thank you for registering at $subdomainurl.</p>";
        $body .= "<p>Your account has now been created and you can log in by using below email address and password</p>";
        $body.="<p>Email : " . $data['User']['email'] . "</p>";
        $body.="<p>Password : " . $data['User']['password'] . "</p>";
        $body .= "<p>By visiting our website or at the following URL:</p>";
        $body .= "<p><a href='$subdomainurl'>$subdomainurl<a/></p>";
        $body .= "<p>If you have ANY question about the operation, please contact to store owner.</p>";
        $body .= "<p>Thank you <br/>" . $SiteTeam . "</p>";

        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function add_personaluser_mail($data) {

        $mailer_to = $data['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $SubDomainUrl = Configure::read('SITE_URL');

        $mailer_subject = "$SiteTitle : User registration";
        $body = "<p>Hello " . $data['Personaluser']['firstname'] . " " . $data['Personaluser']['lastname'] . ",</p>";
        $body .= "<p>Welcome and thank you for registering at $SubDomainUrl.</p>";
        $body .= "<p>Your account has now been created and you can log in by using below email address and password</p>";
        $body.="<p>Email : " . $data['User']['email'] . "</p>";
        $body.="<p>Password : " . $data['User']['password'] . "</p>";
        $body .= "<p>By visiting our website or at the following URL:</p>";
        $body .= "<p><a href='$SubDomainUrl'>$SubDomainUrl<a/></p>";
        $body .= "<p>If you have ANY question about the operation, please contact to store owner.</p>";
        $body .= "<p>Thank you <br/>" . $SiteTeam . "</p>";

        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function reedem_mail($id, $cid, $type = 'customer') {
        if ($type == 'customer') {
            $this->Customer = ClassRegistry::init('Customer');
            $customer = $this->Customer->read(null, $id);
        } else {
            $this->Personaluser = ClassRegistry::init('Personaluser');
            $customer = $this->Personaluser->read(null, $id);
        }

        $this->Category = ClassRegistry::init('Category');
        $category = $this->Category->read(null, $cid);

        $mailer_to = $customer['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $mailer_subject = "$SiteTitle : Redeemed";
        $body = "<p>Dear Customer,</p>";
        $body .= "<p>Your account is debited with " . $category['Category']['point_required'] . " points on " . date('d M Y') . ",</p>";
        $body .= "<p>Redeemed Category : " . $category['Category']['category_name'] . "</p>";
        $body .= "<p>To know your available balance please login with your credentials.</p>";
        $body .= "<p>If you have ANY question about the operation, please contact to store owner.</p>";
        $body .= "<p>Thank you <br/>" . $SiteTeam . "</p>";

        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

    public function rewards_mail($id, $cid, $type = 'customer') {
        if ($type == 'customer') {
            $this->Customer = ClassRegistry::init('Customer');
            $customer = $this->Customer->read(null, $id);
        } else {
            $this->Personaluser = ClassRegistry::init('Personaluser');
            $customer = $this->Personaluser->read(null, $id);
        }
        $this->Pointcategory = ClassRegistry::init('Pointcategory');
        $category = $this->Pointcategory->read(null, $cid);

        $mailer_to = $customer['User']['email'];
        $mailer_from = Configure::read('FROM_EMAIL_ADDRESS');
        $SiteTeam = Configure::read('SITE_TEAM');
        $SiteTitle = Configure::read('SITE_TITLE');

        $mailer_subject = "$SiteTitle : Rewarded";
        $body = "<p>Dear Customer,</p>";
        $body .= "<p>Your account is credited with " . $category['Pointcategory']['points'] . " points on " . date('d M Y') . ",</p>";
        $body .= "<p>Rewarded Category : " . $category['Pointcategory']['name'] . "</p>";
        $body .= "<p>To know your available balance please login with your credentials.</p>";
        $body .= "<p>If you have ANY question about the operation, please contact to store owner.</p>";
        $body .= "<p>Thank you <br/>" . $SiteTeam . "</p>";

        //Mail To institute : Start
        $this->Mailer->sendMail($mailer_to, $mailer_subject, $mailer_from, $body);
        //Mail To institute : End
    }

}
