/**
  * 
  * @param AccountInvitation $model
  * @return boolean
  */
 public function createAccountInvitation($model)
 {
     // foreach email create one separate invitation record
     $emails = explode(',', $model->account_invitation_to_email);
     foreach ($emails as $invite) {
         $inviteModel = new AccountInvitation();
         $inviteModel->account_invitation_to_email = trim($invite);
         $inviteModel->account_invitation_master_id = Yii::app()->user->id;
         $inviteModel->account_invitation_date = date('Y-m-d H:i');
         $inviteModel->account_invitation_status = 0;
         $inviteModel->account_invitation_rand_key = AccountInvitation::generateInvitationKey();
         $inviteModel->account_invitation_project = $model->account_invitation_project;
         $inviteModel->account_invitation_type = $model->account_invitation_type;
         $inviteModel->account_invitation_subscription_id = $model->account_invitation_subscription_id;
         $result_return = $inviteModel->save();
         if ($result_return) {
             // send email
             $message = new YiiMailMessage();
             $sender_name = AccountProfile::model()->getShortFullName(Yii::app()->user->id);
             // if this invitee already has an account with LinxCircle
             // use a different invitation template
             $tempAccount = Account::model()->getAccountByEmail(trim($invite));
             if ($tempAccount != null) {
                 $message->view = "invitationEmailExistingAccount";
                 $subject = $sender_name . ' invited you to join a team on ' . Yii::app()->name;
             } else {
                 $message->view = "invitationEmail";
                 $subject = $sender_name . ' invites you to join ' . Yii::app()->name;
             }
             //userModel is passed to the view
             $message->setBody(array('invitation_accept_url' => AccountInvitation::generateInvitationURL($inviteModel->account_invitation_id, $inviteModel->account_invitation_rand_key), 'invitation_message' => $model->account_invitation_message), 'text/html');
             $message->setSubject($subject);
             //$message->setBody($body, 'text/html');
             //$message->addTo($model->account_invitation_to_email);
             $message->addTo($invite);
             $message->setFrom('*****@*****.**');
             Yii::app()->mail->send($message);
         }
     }
     return true;
 }
 /**
  * Manages all models.
  */
 public function actionAdmin()
 {
     //$model = new AccountTeamMember('search');
     //$model->unsetAttributes();  // clear any default values
     // get team members I'm in charge
     //$model->master_account_id = Yii::app()->user->id;
     $subcription = LBApplication::getCurrentlySelectedSubscription();
     // CADP for getting list my team members of team that user is the master account of.
     $memberCADataProvider = AccountTeamMember::model()->getTeamMembers($subcription);
     // CADP for getting list of members from OTHER teams of which user is NOT the master account of.
     $otherMemberCADataProvider = AccountTeamMember::model()->getMyOtherTeams(Yii::app()->user->id, $subcription);
     // CADP for invites to this user
     $invitesToUserCADataProvider = AccountInvitation::model()->getInvitesToAccount(Yii::app()->user->id);
     // get master account of people whose teams I'm part of
     $model2 = new AccountTeamMember('search');
     $model2->unsetAttributes();
     $model2->member_account_id = Yii::app()->user->id;
     if (isset($_GET['AccountTeamMember'])) {
         $model->attributes = $_GET['AccountTeamMember'];
     }
     $this->render('admin', array('memberCADataProvider' => $memberCADataProvider, 'otherMemberCADataProvider' => $otherMemberCADataProvider, 'invitesToUserCADataProvider' => $invitesToUserCADataProvider));
 }