public function deployRelease($rest)
 {
     $post = $rest->getRequest()->getPost();
     MM_LogApi::logRequest(json_encode($post), "/deployRelease");
     if (!isset($post["version"])) {
         return new Response($rest, "Major version number is required", RESPONSE_ERROR_MESSAGE_MISSING_PARAMS . " : version", RESPONSE_ERROR_CODE_MISSING_PARAMS, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     $majorVersion = $post["version"];
     $minorVersion = isset($post["minor_version"]) ? $post["minor_version"] : MM_MemberMouseService::$DEFAULT_MINOR_VERSION;
     $crntVersion = MemberMouse::getPluginVersion();
     if ($crntVersion != $majorVersion) {
         MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_UPGRADE_NOTICE, $majorVersion);
         return new Response($rest, "Major version do not match. A notification will be displayed to the customer informing them an update is available.", "Major version do not match. A notification will be displayed to the customer informing them an update is available.", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     // if major versions match, update cache with the latest files from central
     $writeableDir = MM_Utils::getCacheDir();
     // delete existing cache
     if (is_dir($writeableDir)) {
         if (is_writeable($writeableDir)) {
             if ($handle = opendir($writeableDir)) {
                 while (false !== ($file = readdir($handle))) {
                     if (!is_dir($file)) {
                         @unlink($writeableDir . "/" . $file);
                     }
                 }
                 closedir($handle);
             }
         }
     }
     // get updated classes from central
     MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_MINOR_VERSION, $minorVersion);
     $ret = MM_MemberMouseService::authorize(true);
     if (MM_Response::isError($ret)) {
         return new Response($rest, "Could not find classes associated with version {$majorVersion}.{$minorVersion}", "Invalid major/minor version combination", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     if (defined("DB_NAME")) {
         global $wpdb;
         if (file_exists($writeableDir . "/membermouse_schema.sql")) {
             $phpObj = new MM_PhpObj($wpdb, DB_NAME);
             if (!$phpObj->importFile($writeableDir . "/membermouse_schema.sql", true)) {
                 return new Response($rest, "Could not update MemberMouse database", "Could not update MemberMouse database", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
             }
         }
     } else {
         return new Response($rest, "DB_NAME not defined", "DB_NAME not defined", RESPONSE_ERROR_CODE_BAD_REQUEST, RESPONSE_ERROR_MESSAGE_MISSING_PARAMS);
     }
     $version = $majorVersion;
     if (!empty($minorVersion)) {
         $version .= "-" . $minorVersion;
     }
     $versionRelease = MM_VersionRelease::findByVersion($version);
     $versionRelease->setVersion($version);
     $versionRelease->commitData();
     return new Response($rest);
 }
</a>
	<?php 
    }
    ?>
	</div>
<?php 
}
$doRenderForm = true;
$initialCreation = true;
$customField = new MM_CustomField($p->id);
// create custom field if it doesn't exist
if (!$customField->isValid()) {
    $customField = new MM_CustomField();
    $customField->setDisplayName("Untitled");
    $result = $customField->commitData();
    if (MM_Response::isSuccess($result)) {
        $customField = new MM_CustomField($customField->getId());
    } else {
        $doRenderForm = false;
    }
} else {
    $initialCreation = false;
}
if ($doRenderForm) {
    $showOnMyAccountChecked = $customField->showOnMyAccount() == true ? "checked" : "";
    ?>
	<div id="mm-form-container">
	<input type='hidden' id='mm-id' value='<?php 
    echo $customField->getId();
    ?>
' />
 public function getBundles($rest)
 {
     $post = $rest->getRequest()->getPost();
     MM_LogApi::logRequest(json_encode($post), "/getBundles");
     if (!Utils::isAuthenticated($post)) {
         return new Response($rest, null, RESPONSE_ERROR_MESSAGE_AUTH, RESPONSE_ERROR_CODE_AUTH, RESPONSE_ERROR_MESSAGE_AUTH);
     }
     $result = MM_APIService::getBundles();
     if (MM_Response::isError($result)) {
         return new Response($rest, null, $result->message, RESPONSE_ERROR_CODE_CONFLICT, RESPONSE_ERROR_MESSAGE_CONFLICT);
     }
     return new Response($rest, $result->message);
 }
Exemple #4
0
            }
        }
    }
    $rows[] = array(array('content' => "<span title='ID [" . $coupon->getId() . "]'>" . $coupon->getCouponName() . "</span>"), array('content' => "<span style='font-family:courier;'>" . strtoupper($coupon->getCouponCode()) . "</span>"), array('content' => $description), array('content' => $quantityDescription), array('content' => $availableDates), array('content' => empty($item->product_restrictions) ? MM_NO_DATA : $item->product_restrictions), array('content' => $actions), array('content' => $archiveActions));
}
$headers = array('name' => array('content' => '<a onclick="mmjs.sort(\'c.coupon_name\');" href="#">Name</a>'), 'coupon_code' => array('content' => '<a onclick="mmjs.sort(\'c.coupon_code\');" href="#">Coupon Code</a>'), 'description' => array('content' => 'Description'), 'quantity_used' => array('content' => '<a onclick="mmjs.sort(\'quantity_used\');" href="#"># Used</a>'), 'start_date_end_date' => array('content' => '<a onclick="mmjs.sort(\'c.start_date\');" href="#">Valid Dates</a>'), 'product_restrictions' => array('content' => 'Product Restrictions'), 'actions' => array('content' => 'Actions', "attr" => "style='width:50px;'"), 'archive' => array('content' => 'Archive', "attr" => "style='width:20px;'"));
$dataGrid->setHeaders($headers);
$dataGrid->setRows($rows);
$dgHtml = $dataGrid->generateHtml();
if ($dgHtml == "") {
    $dgHtml = "<p><i>No coupons.</i></p>";
}
?>
<div class="mm-wrap">
	<?php 
if (MM_Response::isError($couponsSupported)) {
    ?>
	<div class="error">
		<p><?php 
    echo $couponsSupported->message;
    ?>
</p>
	</div>
	<?php 
}
?>
	
	<div class="mm-button-container">
		<a onclick="mmjs.create('mm-coupons-dialog', 620, 615)" class="mm-ui-button green"><?php 
echo MM_Utils::getIcon('plus-circle', '', '1.2em', '1px');
?>
} else {
    $notAvailable = true;
}
//release the lock
$wpdb->query("SELECT RELEASE_LOCK('{$lockName}')");
if ($notAvailable) {
    error_log("Requested cache entry is already being processed or is not available for processing");
    exit;
}
//now route the query to the correct handler, and retrieve the data
try {
    //clean expired from the cache first
    MM_ReportDataRetriever::clearDataCache(true);
    $queryTarget = $cacheRow->query_target;
    $queryIdentifier = $cacheRow->query_token;
    $params = MM_ReportDataRetriever::decodeParams($cacheRow->query_params);
    $dataResponse = MM_ReportDataRetriever::generateData($queryTarget, $queryIdentifier, $params, MM_ReportDataRetriever::$DEFAULT_CACHE_TIMEOUT);
    if (MM_Response::isError($dataResponse)) {
        $wpdb->update(MM_TABLE_REPORT_DATA_CACHE, array("status" => MM_ReportDataRetriever::$DATA_ERROR_STATUS), array("id" => $cacheId));
        error_log("Error generating data for query referenced by cache id {$cacheId}:{$dataResponse->message}");
        exit;
    }
    //data has been retrieved, update cache table
    $wpdb->update(MM_TABLE_REPORT_DATA_CACHE, array("status" => MM_ReportDataRetriever::$DATA_READY_STATUS), array("id" => $cacheId));
    //processing complete, terminate disconnected process
    exit;
} catch (Exception $e) {
    $wpdb->update(MM_TABLE_REPORT_DATA_CACHE, array("status" => MM_ReportDataRetriever::$DATA_ERROR_STATUS), array("id" => $cacheId));
    $error = $e->getMessage();
    error_log("Error generating data for query referenced by cache id {$cacheId}" . (empty($error) ? "" : ": {$error}"));
}
        $lastParams = json_decode($p->lastActionParams);
        $user = new MM_User();
        $user->setStatus(MM_Status::$PENDING_ACTIVATION);
        $user->setStatusMessage("Customer account created by administrator using the Create Member tool but not completed.");
        $user->setMembershipId($lastParams->mm_new_membership);
        $user->setEmail($lastParams->mm_new_email);
        $user->setFirstName($lastParams->mm_new_first_name);
        $user->setLastName($lastParams->mm_new_last_name);
        if (isset($lastParams->mm_new_phone)) {
            $user->setPhone($lastParams->mm_new_phone);
        }
        if (isset($lastParams->mm_new_password)) {
            $user->setPassword($lastParams->mm_new_password);
        }
        $result = $user->commitData();
        if (MM_Response::isError($result)) {
            echo "Payment Options Dialog:  Error creating pending account for new member: {$result->message}";
            exit;
        }
    }
    if (!$user->isValid()) {
        echo "Payment Options Dialog: Invalid user ID '{$p->userId}'.";
        exit;
    }
}
$membership = null;
$bundle = null;
$products = array();
if ($p->accessType == MM_AccessControlEngine::$ACCESS_TYPE_MEMBERSHIP) {
    $membership = new MM_MembershipLevel($p->accessTypeId);
    if ($membership->isValid()) {
Exemple #7
0
function processSignup($request, $provider)
{
    //don't attempt to signup already logged in users
    if (MM_Utils::isLoggedIn()) {
        $loggedInUser = MM_Utils::getCurrentUser();
        $redirectUrl = isset($request['redirect_url']) ? $request['redirect_url'] : MM_CorePageEngine::getUrl(MM_CorePageType::$MEMBER_HOME_PAGE, null, $loggedInUser);
        wp_redirect($redirectUrl);
        exit;
    }
    if (!$provider->allowsSignups()) {
        //configuration does not allow signups
        throw new Exception("Signups not allowed", "1001007");
    }
    if (isset($request['membership_level'])) {
        $membershipLevel = trim($request['membership_level']);
        $membershipLevel = htmlentities($membershipLevel);
        if (!is_numeric($membershipLevel)) {
            //membership level was not passed as a valid id
            throw new Exception("Invalid Membership Level", "1001008");
        }
    } else {
        $membershipLevel = $provider->getSignupMembershipLevel();
        if (!is_numeric($membershipLevel) || $membershipLevel == 0) {
            //should never happen - default signup membership level is invalid
            throw new Exception("Invalid Default Membership Level", "1001009");
        }
    }
    //ensure that if the chosen provider doesnt allow access to the email, and the provider is configured not to generate one, that one was supplied
    if ($provider->getEmailHandlingStrategy() == MM_AbstractSocialLoginExtension::$EMAIL_RETRIEVED_BY_POPUP && empty($request['email'])) {
        //email required but not supplied
        throw new Exception("No email supplied", "1001010");
    }
    //Authenticate with the provider, and retrieve the remote user profile
    $authResponse = $provider->authenticate();
    if (!MM_Response::isSuccess($authResponse)) {
        //error authenticating
        throw new Exception("Error authenticating with social network", "1001016");
    }
    $profileResponse = $provider->getUserProfile();
    if (!MM_Response::isSuccess($profileResponse)) {
        //retrievng profile failed
        throw new Exception("Unable to retrieve profile from social network", "1001011");
    }
    $profile = $profileResponse->message;
    if (!isset($profile->identifier) || empty($profile->identifier)) {
        //invalid social network identifier returned
        throw new Exception("Invalid social network identifier", "1001012");
    }
    //Populate memberinfo with the necessary member information, in the expected format
    $memberInfo = array();
    $memberInfo["membership_level"] = $membershipLevel;
    if (isset($profile->firstName) && !empty($profile->firstName)) {
        $memberInfo['first_name'] = $profile->firstName;
    }
    if (isset($profile->lastName) && !empty($profile->lastName)) {
        $memberInfo['last_name'] = $profile->lastName;
    }
    $emailHandlingStrategy = $provider->getEmailHandlingStrategy();
    if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_RETRIEVED_BY_POPUP) {
        //TODO: sanitize email
        $memberInfo['email'] = $request['email'];
    } else {
        if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_PROVIDED) {
            if (isset($profile->emailVerified) && !empty($profile->emailVerified)) {
                $memberInfo['email'] = $profile->emailVerified;
            } else {
                if (isset($profile->email) && !empty($profile->email)) {
                    $memberInfo['email'] = $profile->email;
                } else {
                    throw new Exception("Social Network provider was supposed to supply user email, but did not", "1001013");
                }
            }
        } else {
            if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_GENERATE_BOGUS_EMAIL) {
                $bogusUser = MM_Utils::createRandomString(8, true) . MM_Utils::createRandomString(24);
                //TODO: tag user portion of email with social network identifier
                $bogusDomain = "example.com";
                $memberInfo['email'] = "{$bogusUser}@{$bogusDomain}";
            }
        }
    }
    $socialSignupRequest = new MM_SocialLoginRequest($memberInfo);
    $response = $socialSignupRequest->submitRequest();
    if (MM_Response::isSuccess($response)) {
        $newUser = $socialSignupRequest->getNewUser();
        $provider->linkUserToSocialMediaAccount($newUser, $profile->identifier);
        $socialSignupRequest->completeSignup();
        exit;
    } else {
        if (strpos($response->message, "already exists") !== false) {
            //the member signing up already exists, send them to login instead
            processLogin($request, $provider);
            exit;
        }
        throw new Exception($response->message, "1001014");
    }
    //end signup block
    exit;
}
 $employee = MM_Employee::findByUserId($current_user->ID);
 $allowAccess = true;
 if ($employee->isValid()) {
     $allowAccess = $employee->canManageMember($user);
 }
 if ($allowAccess) {
     include_once MM_MODULES . "/details.header.php";
     $message = "";
     if (isset($_POST["custom_submit"])) {
         foreach ($_POST as $k => $v) {
             if (preg_match("/(mm_custom_field_)/", $k)) {
                 // bypass radio button and checkbox helper fields
                 if (strpos($k, 'helper') === false) {
                     $fieldId = preg_replace("/[^0-9]+/", "", $k);
                     $response = $user->setCustomData($fieldId, $v);
                     if (MM_Response::isError($response)) {
                         if (!empty($v)) {
                             $message = $response->message;
                         }
                     }
                 }
             }
         }
         // does account update event need to be dispatched?
         $fields = MM_CustomField::getCustomFieldsList();
         foreach ($fields as $id => $val) {
             if (MM_CustomFieldData::wasRecentlyUpdated($id, $user->getId())) {
                 do_action(MM_Event::$MEMBER_ACCOUNT_UPDATE, MM_Event::packageMemberData($user->getId()));
                 break;
             }
         }
Exemple #9
0
 private function insertMMDefaultData()
 {
     global $wpdb, $current_user;
     // insert default option values
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACCT_SECURITY_ENABLED, MM_OptionUtils::$DEFAULT_ACCT_SECURITY_ENABLED);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACCT_SECURITY_MAX_IPS, MM_OptionUtils::$DEFAULT_ACCT_SECURITY_MAX_IPS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ON_LOGIN_USE_WP_FRONTPAGE, MM_OptionUtils::$DEFAULT_ON_LOGIN_USE_WP_FRONTPAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_AFTER_LOGIN_USE_WP_FRONTPAGE, MM_OptionUtils::$DEFAULT_AFTER_LOGIN_USE_WP_FRONTPAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SHOW_LOGIN_LOGOUT_LINK, MM_OptionUtils::$DEFAULT_SHOW_LOGIN_LOGOUT_LINK);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_HIDE_PROTECTED_MENU_ITEMS, MM_OptionUtils::$DEFAULT_HIDE_PROTECTED_MENU_ITEMS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_LOGIN_PAGE, MM_OptionUtils::$DEFAULT_USE_MM_LOGIN_PAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_RESET_PASSWORD_PAGE, MM_OptionUtils::$DEFAULT_USE_MM_RESET_PASSWORD_PAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_COUNTRY_SELECTIONS, MM_OptionUtils::$DEFAULT_COUNTRY_SELECTIONS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_FORGOT_PASSWORD_SUBJECT, MM_OptionUtils::$DEFAULT_FORGOT_PASSWORD_SUBJECT);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_FORGOT_PASSWORD_BODY, MM_OptionUtils::$DEFAULT_FORGOT_PASSWORD_BODY);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_AFFILIATE, MM_OptionUtils::$DEFAULT_AFFILIATE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SUB_AFFILIATE, MM_OptionUtils::$DEFAULT_SUB_AFFILIATE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_AFFILIATE_LIFESPAN, MM_OptionUtils::$DEFAULT_AFFILIATE_LIFESPAN);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_LOGIN_TOKEN_LIFESPAN, MM_OptionUtils::$DEFAULT_LOGIN_TOKEN_LIFESPAN);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_CHECKOUT_FORM_TEST_DATA, MM_OptionUtils::$DEFAULT_USE_CHECKOUT_FORM_TEST_DATA);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_PURCHASE_CONFIRMATION_DIALOG_WIDTH, MM_OptionUtils::$DEFAULT_PURCHASE_CONFIRMATION_DIALOG_WIDTH);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_PURCHASE_CONFIRMATION_DIALOG_HEIGHT, MM_OptionUtils::$DEFAULT_PURCHASE_CONFIRMATION_DIALOG_HEIGHT);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_DEFAULT_CHECKOUT_ITEM_TYPE, MM_OptionUtils::$DEFAULT_CHECKOUT_ITEM_TYPE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_DEFAULT_CHECKOUT_ITEM_ID, MM_OptionUtils::$DEFAULT_CHECKOUT_ITEM_ID);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SHOW_PREVIEW_BAR, MM_OptionUtils::$DEFAULT_SHOW_PREVIEW_BAR);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_HIDE_ADMIN_BAR, MM_OptionUtils::$DEFAULT_HIDE_ADMIN_BAR);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ENABLE_WP_AUTOP, MM_OptionUtils::$DEFAULT_ENABLE_WP_AUTOP);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ENABLE_USERNAME_CHANGE, MM_OptionUtils::$DEFAULT_ENABLE_USERNAME_CHANGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ALLOW_LOGGED_OUT_PURCHASES, MM_OptionUtils::$DEFAULT_ALLOW_LOGGED_OUT_PURCHASES);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ALLOW_DUPLICATE_SUBSCRIPTIONS, MM_OptionUtils::$DEFAULT_ALLOW_DUPLICATE_SUBSCRIPTIONS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CHECKOUT_PAID_MESSAGE, MM_OptionUtils::$DEFAULT_CHECKOUT_PAID_MESSAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CHECKOUT_FREE_MESSAGE, MM_OptionUtils::$DEFAULT_CHECKOUT_FREE_MESSAGE);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CHECKOUT_MESSAGE_CSS, MM_OptionUtils::$DEFAULT_CHECKOUT_MESSAGE_CSS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CURRENCY, MM_OptionUtils::$DEFAULT_CURRENCY);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_JQUERY_UI, MM_OptionUtils::$DEFAULT_USE_JQUERY_UI);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ALLOW_OVERDUE_ACCESS, MM_OptionUtils::$DEFAULT_ALLOW_OVERDUE_ACCESS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CAPTCHA_ENABLED, MM_OptionUtils::$DEFAULT_CAPTCHA_ENABLED);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_RESET_PASSWORD, MM_OptionUtils::$DEFAULT_USE_MM_CSS);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_DIAGNOSTIC_MODE, MM_DiagnosticLog::$MODE_OFF);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_FORCE_USE_DB_CACHE, 0);
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CURRENCY_FORMAT_POSTFIX_ISO, 'false');
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_AFFILIATE_ALIAS, "");
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SUB_AFFILIATE_ALIAS, "");
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_AFFILIATE_LIFESPAN, "");
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SITE_IN_TEST_MODE, "0");
     //0 for false, 1 for true
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CAPTCHA_KEY, "");
     MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_CAPTCHA_PRIVATE_KEY, "");
     // options that vary based on if this is an upgrade versus a new install
     $lastMajorVersion = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_MAJOR_VERSION);
     if (empty($lastMajorVersion)) {
         // set options for new installs
         // for 2.0.7 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_DISABLE_EXPLICIT_LINKS, MM_OptionUtils::$DEFAULT_DISABLE_EXPLICIT_LINKS);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_PURCHASE_LINK_STYLE, MM_OptionUtils::$DEFAULT_PURCHASE_LINK_STYLE);
         // for 2.0.8 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SMARTTAG_VERSION, MM_OptionUtils::$DEFAULT_SMARTTAG_VERSION);
         // for 2.0.9 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACTIVITY_LOG_CLEANUP_ENABLED, MM_OptionUtils::$DEFAULT_ACTIVITY_LOG_CLEANUP_ENABLED);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACTIVITY_LOG_CLEANUP_INTERVAL, MM_OptionUtils::$DEFAULT_ACTIVITY_LOG_CLEANUP_INTERVAL);
         // for 2.1.2 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_CHECKOUT, MM_OptionUtils::$DEFAULT_USE_MM_CSS);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_MY_ACCOUNT, MM_OptionUtils::$DEFAULT_USE_MM_CSS);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_LOGIN, MM_OptionUtils::$DEFAULT_USE_MM_CSS);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_FORGOT_PASSWORD, MM_OptionUtils::$DEFAULT_USE_MM_CSS);
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ENABLE_MEMBERSHIP_PRORATION, MM_OptionUtils::$DEFAULT_ENABLE_MEMBERSHIP_PRORATION);
     } else {
         // set options for existing installs
         // for 2.0.7 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_DISABLE_EXPLICIT_LINKS, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_PURCHASE_LINK_STYLE, MM_LINK_STYLE_EXPLICIT);
         // for 2.0.8 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_SMARTTAG_VERSION, "2.0");
         // for 2.0.9 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACTIVITY_LOG_CLEANUP_ENABLED, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ACTIVITY_LOG_CLEANUP_INTERVAL, "");
         // for 2.1.2 release
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_CHECKOUT, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_MY_ACCOUNT, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_LOGIN, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_USE_MM_CSS_FORGOT_PASSWORD, "0");
         MM_OptionUtils::setDefaultValue(MM_OptionUtils::$OPTION_KEY_ENABLE_MEMBERSHIP_PRORATION, "0");
     }
     MM_Role::addRoles();
     // create default employee account if one doesn't exist, using the current user
     $install_sql = "select * from " . MM_TABLE_EMPLOYEE_ACCOUNTS . " where is_default='1' LIMIT 1;";
     $row = $wpdb->get_row($install_sql);
     if ($row == null) {
         //the current user isn't an employee
         $install_sql = "insert into " . MM_TABLE_EMPLOYEE_ACCOUNTS . " set display_name='%s', email='%s', is_default='%d', role_id='%s', user_id='%d'";
         $displayName = !empty($current_user->display_name) ? $current_user->display_name : "Support";
         $wpdb->query($wpdb->prepare($install_sql, $displayName, $current_user->user_email, 1, MM_Role::$ROLE_ADMINISTRATOR, $current_user->ID));
         $emailId = $wpdb->insert_id;
     } else {
         $emailId = $row->id;
     }
     // install default overdue payment notification email
     $crntValue = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_OVERDUE_PAYMENT_NOTIFICATION_INSTALLED);
     if ($crntValue === false || $crntValue === "") {
         $action = new MM_Action();
         $action->setEventType(MM_Event::$MEMBER_STATUS_CHANGE);
         $action->setActionType(MM_Action::$MM_ACTION_SEND_EMAIL);
         $emailToId = MM_Action::$CURRENT_MEMBER_PLACEHOLDER;
         $emailFromId = $emailId;
         $emailCC = "";
         $emailSubject = MM_OptionUtils::$DEFAULT_OVERDUE_PAYMENT_SUBJECT;
         $emailBody = MM_OptionUtils::$DEFAULT_OVERDUE_PAYMENT_BODY;
         $action->setActionValue(MM_Action::prepareSendEmailValue($emailToId, $emailFromId, $emailCC, $emailSubject, $emailBody));
         // set attributes
         $attributes = array();
         $attributes["status_id"] = MM_Status::$OVERDUE;
         $action->setEventAttributes($attributes);
         $result = $action->commitData();
         if (MM_Response::isSuccess($result)) {
             MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_OVERDUE_PAYMENT_NOTIFICATION_INSTALLED, "1");
         }
     }
     // create default membership level
     if (!$this->hasRecords(MM_TABLE_MEMBERSHIP_LEVELS, 'is_default', '1')) {
         $install_sql = "INSERT INTO " . MM_TABLE_MEMBERSHIP_LEVELS . " SET " . "\tname = 'Free Membership'," . "\tis_free='1'," . "\tis_default='1'," . "\tstatus='1'," . "\tdescription='Default Free Membership'," . "\temail_subject='%s'," . "\temail_body='%s'," . "\temail_from_id='%d'" . "";
         $wpdb->query($wpdb->prepare($install_sql, MM_MembershipLevel::$DFLT_EMAIL_SUBJECT, MM_MembershipLevel::$DFLT_EMAIL_BODY, $emailId));
     }
     // create default commission profile
     if (!$this->hasRecords(MM_TABLE_COMMISSION_PROFILES, 'is_default', '1')) {
         $install_sql = "INSERT INTO " . MM_TABLE_COMMISSION_PROFILES . " SET " . "\tname = 'Standard Commission Profile'," . "\tis_default='1'," . "\tdescription='This is the default commission profile'," . "\tinitial_commission_enabled='1'," . "\trebill_commissions_enabled='0'," . "\trebill_commission_type='default'," . "\trebill_commission_value='0'," . "\tdo_limit_rebill_commissions='0'," . "\trebill_commission_limit='0', " . "\tdo_reverse_commissions='1'" . "";
         $wpdb->query($install_sql);
     }
     // make sure active payment services are updated
     if (class_exists('MM_PaymentServiceFactory') && class_exists('MM_PaymentService')) {
         $services = MM_PaymentServiceFactory::getAvailablePaymentServices();
         foreach ($services as $service) {
             if ($service instanceof MM_PaymentService) {
                 $service->install();
             }
         }
     }
     //add smart tags
     $this->addSmartTags();
     $sql = "select count(*) as total from " . MM_TABLE_API_KEYS;
     $row = $wpdb->get_row($sql);
     if ($row->total <= 0) {
         $sql = "insert into " . MM_TABLE_API_KEYS . " set " . "name='Default Access', " . "api_key='" . MM_Utils::createRandomString(10) . "',\t" . "api_secret='" . MM_Utils::createRandomString(10) . "', " . "status='1'";
         $wpdb->query($sql);
     }
     $sql = array();
     require_once MM_PLUGIN_ABSPATH . "/data/countries.sql.php";
     $numCountries = count($sql);
     $countryCheckSql = "select count(*) as total from " . MM_TABLE_COUNTRIES;
     $row = $wpdb->get_row($countryCheckSql);
     if ($row->total < $numCountries) {
         foreach ($sql as $query) {
             if ($wpdb->query($query) === false) {
                 return false;
             }
         }
     }
     unset($sql);
     $sql = array();
     require_once MM_PLUGIN_ABSPATH . "/data/country_subdivisions.sql.php";
     $numCountrySubdivisions = count($sql);
     $countrySubdivisionCheckSql = "select count(*) as total from " . MM_TABLE_COUNTRY_SUBDIVISIONS;
     $row = $wpdb->get_row($countrySubdivisionCheckSql);
     if ($row->total < $numCountrySubdivisions) {
         foreach ($sql as $query) {
             if ($wpdb->query($query) === false) {
                 return false;
             }
         }
     }
     unset($sql);
     $result = $this->setupCorePages();
     if (!$result) {
         return false;
     }
     $cacheWriteable = @MM_Utils::cacheIsWriteable();
     $sql = array();
     //TODO TRANSIENT: in version 2.0.1 renamed WordPress Mail to None. Once all customers have been upgraded to None then this
     // if statement can be removed
     if ($this->hasRecords(MM_TABLE_EMAIL_SERVICE_PROVIDERS, 'provider_token', 'default')) {
         $sql[] = "UPDATE " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='None' WHERE provider_token='default';";
     } else {
         $sql[] = "INSERT IGNORE INTO " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='None', provider_token='default', active='1';";
     }
     //email service providers
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='MailChimp', provider_token='mailchimp', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='iContact', provider_token='icontact', api_key='" . MM_IContactEmailServiceProvider::$API_KEY . "'";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='AWeber', provider_token='aweber', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_EMAIL_SERVICE_PROVIDERS . " SET provider_name='GetResponse', provider_token='getresponse', active='0';";
     //affiliate providers
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_AFFILIATE_PROVIDERS . " SET provider_name='None', provider_token='default', active='1';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_AFFILIATE_PROVIDERS . " SET provider_name='iDevAffiliate', provider_token='idevaffiliate';";
     //payment services
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='PAYPAL', name='PayPal', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='AUTHORIZENET', name='Authorize.net', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='AUTHORIZENETCIM', name='Authorize.net CIM', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='BRAINTREE', name='Braintree', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='CHARGIFY', name='Chargify', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='LIMELIGHT', name='Lime Light', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='STRIPE', name='Stripe', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='TWOCHECKOUT', name='2Checkout', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='CLICKBANK', name='ClickBank', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='LITLE', name='Litle', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='COINBASE', name='Coinbase (Wallet Required)', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='COINBASEMINIMAL', name='Coinbase (Wallet Ignored)', settings='', active='0';";
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_PAYMENT_SERVICES . " SET token='TEST', name='Test Payment Service', settings='', active='0';";
     //shipping methods
     $sql[] = "INSERT IGNORE INTO " . MM_TABLE_SHIPPING_METHODS . " SET token='FLATRATE', name='Flat Rate', settings='', active='1';";
     //active by default
     foreach ($sql as $query) {
         $wpdb->query($query);
     }
     unset($sql);
     //apply any updates that may have been made to the schemas of the active payment services
     $activePaymentServices = MM_PaymentServiceFactory::getAvailablePaymentServices();
     foreach ($activePaymentServices as $ps) {
         $ps->install();
     }
     // Need to search and replace and remnance of [MM_Member_Data name='password'] in
     // Forgot Password email with the new Reset Password Core Page Link Smart Tag
     $pattern = "\\[mm_member_data name=(['|\"]{1})password(['|\"]{1})\\]";
     $forgotPasswordBody = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_FORGOT_PASSWORD_BODY);
     $forgotPasswordBody = preg_replace("/{$pattern}/i", "<a href=\"[MM_CorePage_Link type='resetpassword']\">click here to reset your password</a>", $forgotPasswordBody);
     MM_OptionUtils::setOption(MM_OptionUtils::$OPTION_KEY_FORGOT_PASSWORD_BODY, $forgotPasswordBody);
     return true;
 }