function activation($activation)
{
    global $user;
    global $db;
    global $noerrors;
    include 'functions/functions.php';
    if ($noerrors != 0) {
        echo json_encode(array("result" => "failed", "message" => "Database Connection"));
        return;
    }
    // JSON Message array
    $jsonArray = array();
    $findActivation = $db->prepare("SELECT * FROM `hash_codes` WHERE `type` = 'activation' AND `code` = :activationCode");
    $findActivation->bindParam(':activationCode', $activation);
    $findActivation->execute();
    if ($findActivation->rowCount() == 1) {
        $codeData = $findActivation->fetch();
        $userID = $codeData['userID'];
        $code = $codeData['code'];
        // Start transaction
        $db->beginTransaction();
        $sqlErrors = 0;
        // Make User Active
        $userActive = $db->prepare("UPDATE `users` SET `active` = '1' WHERE `userID` = :userID");
        $userActive->bindParam(':userID', $userID);
        if (!$userActive->execute()) {
            $sqlErrors++;
        }
        // Remove Hash Code
        $removeCode = $db->prepare("DELETE FROM `hash_codes` WHERE `code` = :hashCode");
        $removeCode->bindParam(':hashCode', $code);
        if (!$removeCode->execute()) {
            $sqlErrors++;
        }
        if ($sqlErrors == 0) {
            $db->commit();
            startHTML('Account Activated', false);
            echo '<div style="text-align:center;"><h2>Account Activated</h2></div>';
            footerHTML();
            return;
        } else {
            $db->rollBack();
            startHTML('Account Activated', false);
            echo '<div style="text-align:center;"><h2>Sorry an error occurred</h2></div>';
            footerHTML();
            return;
        }
    } else {
        startHTML('Account Activated', false);
        echo '<div style="text-align:center;"><h2>Sorry this activation code doesn\'t exist or has expired</h2></div>';
        footerHTML();
        return;
    }
}
Example #2
0
   $("#delete").click(function(e){
	e.preventDefault();
	bootbox.confirm("Are you sure you want to delete your account?<br><br>This action is permanent and cannot be undone", function(result){
		if(result)
		{
			$.get( "/scripts/notConfirmed/delete",function( data ) {
				var jData = jQuery.parseJSON(data);
				var result = jData.result;
				if(result == 'successful')
				{
					bootbox.alert("Your account has been deleted",function(){
						location.reload();
					});
				}
				else
				{
					var message = jData.message;
					bootbox.alert("Account Delete Failed.<br>Reason: "+message);
				}
			})
					
		}
	});
   })
	
});

</script>
<?php 
footerHTML();