<?php
/*
Plugin Name: Email On Approved
Description: Email the user their password once they are approved
Version: 1.00
Requires at least: 2.04
*/


// UPDATE THESE VALUES

// DON'T UPDATE ANYTHING BELOW THIS LINE

addAction('record_postsave',  'emailOnApproved_sendPassword', null, 4);


//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
  global $CURRENT_USER, $SETTINGS;
  $fieldname = 'approved';

  // error checking
    if ($tableName != 'accounts') { return; } 
  if (!array_key_exists($fieldname, $CURRENT_USER)) {
    die(__FUNCTION__ .": You must create an accounts fields called '$fieldname'!");
  }

  // send email
  $wasChecked   = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
  $wasUnchecked = intval($oldRecord[$fieldname]  && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__   
	Congratulations!  
  
Your Artists of Palm Beach County membership has been approved and you now have access to the \"Members Only\" area of our web site. \n  
Your user name is: {$_REQUEST['username']} \n  
and your temporary password is: {$_REQUEST['password']}.\n \n  
Once you have successfully logged in, you can change your password and update your profile information. \n \n  
  
  
<a href=\"http://www.artistsofpalmbeachcounty.org{$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']}\">Click here to login</a>  
  
Best, \n  
    
The Membership Committee  
__TEXT__


  if ($wasChecked) {
    $errors = sendMessage(array(
      'from'    => $SETTINGS['adminEmail'],
      'to'      => $_REQUEST['email'],
      'subject' => "Your membership has been approved!",
      'text'    => $message, 
	

    ));
    if ($errors) { die($errors); }
  }

}



?>
