function sendEmail($send = true)
 {
     $emailer = new Emailer();
     $message = $this->getString();
     $emailer->setMessage($message);
     $emailer->setSubject($this->subject);
     $emailer->setSender("*****@*****.**");
     $emailer->addRecipients($this->recipient);
     $emailer->addRecipients($this->bccrecipients, 1, "bcc");
     $emailer->addRecipients($this->ccrecipients, 1, "cc");
     if ($send) {
         $emailer->send();
     } else {
         $emailString = $emailer->getString();
         print $emailString;
     }
 }
 function eventSetCoWorker(EventControler $evtcl)
 {
     $goto = $evtcl->goto;
     if ($evtcl->fields['email_address'] != "") {
         $email_user = $evtcl->fields['email_address'];
     } else {
         $email_user = $evtcl->email;
     }
     if ($email_user != '' && !empty($email_user)) {
         // $email_user = $evtcl->email;//echo $email_user;exit;
         $iduser = $this->isUserExists($email_user);
         // user already in the db so just add
         if ($iduser) {
             $q = new sqlQuery($this->getDbCon());
             $q->query("select * from " . $this->table . " where iduser = "******" AND idcoworker= " . $iduser);
             //echo "select * from ".$this->table." where iduser = "******" AND idcoworker= ".$iduser;exit;
             if ($q->getNumRows() > 0) {
                 while ($q->fetch()) {
                     $accepted = $q->getData("accepted");
                 }
                 if ($accepted == 'Yes') {
                     $_SESSION['in_page_message'] = "cw_user-is-already-cw";
                 } elseif ($accepted == 'No') {
                     $_SESSION['in_page_message'] = "cw_already-have-pending-invitation";
                 }
             } else {
                 $this->iduser = $_SESSION['do_User']->iduser;
                 $this->idcoworker = $iduser;
                 $this->accepted = 'No';
                 $this->add();
                 $_SESSION['in_page_message'] = "cw_user-is-already-in-db-notification-sent";
             }
         } else {
             // Not found send the email.
             $enc_email = $this->encrypt($email_user);
             $q = new sqlQuery($this->getDbCon());
             $q->query("select * from " . $this->table . " where iduser = "******" AND enc_email = '" . $enc_email . "' AND accepted ='No'");
             //echo "select * from ".$this->table." where enc_email = '".$enc_email."' AND accepted ='No'";exit;
             if ($q->getNumRows() > 0) {
                 // If the invitation is still pending
                 $_SESSION['in_page_message'] = "cw_already-have-pending-invitation-to";
                 $_SESSION['in_page_message_data']['enc_email'] = $this->decrypt($enc_email);
             } else {
                 $this->iduser = $_SESSION['do_User']->iduser;
                 $this->idcoworker = 0;
                 $this->accepted = 'No';
                 $this->enc_email = $enc_email;
                 $this->add();
                 $last_id = $this->getInsertId($this->table, $this->primary_key);
                 include_once "class/Emailer.class.php";
                 $q = new sqlQuery($this->getDbCon());
                 $q->query("select * from " . $this->table . " where " . $this->primary_key . " = " . $last_id);
                 if ($q->getNumRows() > 0) {
                     while ($dData = $q->fetchArray()) {
                         $dData["firstname"] = $_SESSION['do_User']->firstname;
                         $dData["referer"] = $this->encrypt($last_id);
                         $full_name = $_SESSION['do_User']->firstname . " " . $_SESSION['do_User']->lastname;
                         $email = new Emailer();
                         $email->loadEmailer($this->getDbCon(), "invitation");
                         $email->setSender($full_name, $_SESSION['do_User']->email);
                         $email->mergeArray($dData);
                         if ($email->hasHtml()) {
                             $email->sendMailHtml($email_user);
                         } else {
                             $email->sendMailStandard($email_user);
                         }
                         $_SESSION['in_page_message'] = "cw_user-not-in-db-register";
                     }
                 }
             }
         }
     } else {
         $_SESSION['in_page_message'] = "cw_enter-emailid";
     }
 }