Example #1
0
function createCode($length)
{
    $hash = md5(uniqid(rand(), true));
    $newCode = substr($hash, 0, $length);
    $checkCode = mysql_query("SELECT uid FROM {$mysqldb} WHERE uid = '{$newCode}'");
    if (mysql_num_rows($checkCode) != 0) {
        createCode($length);
    }
    return $newCode;
}
Example #2
0
<?php

session_start();
// This script checks 5 different social media advertisements (verticals) and its conversion rate.
// Contact: Andreas Rubin-Schwarz - andi@herokins.com
include 'config.inc.php';
// Set Server IP and Server Proxy IP (If existant)
$serverip = $_SERVER['REMOTE_ADDR'];
$proxyip = $_SERVER['HTTP_X_FORWARDED_FOR'];
// Set unique id to identify user
if (!isset($_SESSION['uniqueid'])) {
    $_SESSION['uniqueid'] = createCode(7);
}
?>
<!DOCTYPE html>

<html class="no-js" lang="en">
<head>
  <!-- title and meta -->
  <meta charset="utf-8">
  <meta content="width=device-width,initial-scale=1.0" name="viewport">
  <meta content="description" name="SEO Optimized message.">

  <title>Brand A - Headline</title>

  <!-- css -->
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto+Slab">
  <link rel="stylesheet" href="css/base.css">
  <link rel="stylesheet" href="css/style.css">

  <!-- js -->
Example #3
0
$rows = NULL;
## If no session exists init game
if (!isset($_SESSION['counter']) || isset($_GET['restart'])) {
    ## Destroy old session
    session_destroy();
    session_start();
    $_SESSION = array();
    ## Initialise new session
    $_SESSION['counter'] = 0;
    // Init session counter
    $_SESSION['gameOver'] = false;
    // Init game finished property
    $_SESSION['guessedArray'] = array();
    // Init guesses
    ## Create pseudo random code and store in session
    $_SESSION['code'] = $searchedCodeArr = createCode($possibleCharsArr);
    ## Output start message
    $errorMsgOutput = "<div id='errorMsg' class='gameStart'>Welcome to 'codeBreaker', to start with the game,\n                        please enter four single characters (A-G) into the input fields.</div>";
} else {
    ## Prepare variables
    $searchedCodeArr = $_SESSION['code'];
    $code = implode(" ", $searchedCodeArr);
    // As string
    $counter = $_SESSION['counter'];
    $guessesArray = $_SESSION['guessedArray'];
    ## Proces input (on post request)...
    if (isset($_POST['letter'])) {
        // Read $_POST SUPERGLOBAL
        $lettersArray = $_POST['letter'];
        ## ... and if game not finished (seperated to output meaningful error messages)
        if (!$_SESSION['gameOver']) {
Example #4
0
function processUsers($users, $eventId)
{
    global $connection;
    //Store ALL the userIds that are new and leftover after the updating
    //So we can save the user_choice later on!
    $newUserIds = array();
    //collect the ids that we're receiving at this point
    //New dates dont have an ID so its easy to check which of the ids are there(And which arent in case they are deleted)
    $receivingIds = array();
    foreach ($users as $user) {
        if (isset($user['id'])) {
            $receivingIds[] = $user['id'];
        }
    }
    $toBeDeleted = array();
    //fetch the existing users and crossmatch them with the ones received. If an ID is absent in the receivingIDs
    //Add it to the toBeDeleted arr
    $existingUsers = array();
    $query = "SELECT * FROM event_user WHERE event_id = '" . mysqli_real_escape_string($connection, $eventId) . "'";
    if ($result = mysqli_query($connection, $query)) {
        while ($row = mysqli_fetch_array($result)) {
            //Skip the creator of the event
            if ($row['is_creator'] != 1) {
                $existingUsers[$row['id']]['name'] = $row['name'];
                $existingUsers[$row['id']]['email'] = $row['email'];
                if (!in_array($row['id'], $receivingIds)) {
                    $toBeDeleted[] = $row['id'];
                }
            }
        }
    }
    $usersToUpdate = array();
    //Loop through the existing users, check if they can be found in the receiving users
    //And see if they need updating
    foreach ($existingUsers as $existingId => $existingUser) {
        foreach ($users as $user) {
            if (isset($user['id']) && $existingId == $user['id']) {
                //This ID is known and is received again. See if it needs updating
                if ($existingUser['name'] != $user['name'] || $existingUser['email'] != $user['email']) {
                    $usersToUpdate[$existingId]['name'] = $user['name'];
                    $usersToUpdate[$existingId]['email'] = $user['email'];
                }
            }
        }
    }
    if (count($toBeDeleted) > 0) {
        foreach ($toBeDeleted as $id) {
            //delete the IDs that were not retrieved in the receivingIds
            $qry = "DELETE FROM event_user WHERE id = '" . mysqli_real_escape_string($connection, $id) . "' LIMIT 1";
            mysqli_query($connection, $qry);
            $qry = "DELETE FROM date_userchoice WHERE user_id = '" . mysqli_real_escape_string($connection, $id) . "'";
            mysqli_query($connection, $qry);
        }
    }
    if (count($usersToUpdate) > 0) {
        foreach ($usersToUpdate as $id => $user) {
            $qry = "UPDATE \n\t\t\t\t\t\tevent_user \n\t\t\t\t\tSET \n\t\t\t\t\t\tname = '" . mysqli_real_escape_string($connection, $user['name']) . "',\n\t\t\t\t\t\temail = '" . mysqli_real_escape_string($connection, $user['email']) . "' \n\t\t\t\t\tWHERE \n\t\t\t\t\t\tid = '" . mysqli_real_escape_string($connection, $id) . "'";
            mysqli_query($connection, $qry);
            $newUserIds[] = $id;
        }
    }
    //Save new users last
    foreach ($users as $user) {
        if (!isset($user['id'])) {
            //add new user
            if (isset($user['name']) && $user['name'] && !empty($user['name']) && isset($user['email']) && $user['email'] && !empty($user['email'])) {
                $code = createCode();
                $qry = "INSERT INTO \n\t\t\t\t\t\t\t\tevent_user (event_id, name, email, code) \n\t\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $eventId) . "', \n\t\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $user['name']) . "',\n\t\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $user['email']) . "',\n\t\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $code) . "'\n\t\t\t\t\t\t\t)";
                $result = mysqli_query($connection, $qry);
                if ($result) {
                    $newUserIds[] = mysqli_insert_id($connection);
                }
            }
        }
    }
    return $newUserIds;
}
Example #5
0
function statusShare($statusText, $imgType, $imgData)
{
    global $db;
    session_start();
    $errorList = '';
    $firstError = true;
    date_default_timezone_set("America/New_York");
    $p_date = date("Y-m-d H:i:s");
    if (strlen($imgData) > 0) {
        $data = explode(',', $imgData);
        $img = str_replace(' ', '+', $data[1]);
        $img2 = base64_decode($img);
        $tmp_code = createCode(10);
        $im = imagecreatefromstring($img2);
        imagejpeg($im, 'photos/tmp/' . $tmp_code . '.jpg');
        imagedestroy($im);
        if (file_exists('photos/tmp/' . $tmp_code . '.jpg')) {
            $code = createCode(40);
        }
        $sql = "INSERT INTO photo (u_id, p_code, p_type, p_date, p_status) VALUES(:u_id, :p_code, '1', :p_date, '1')";
        $stmt = $db->prepare($sql);
        $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT);
        $stmt->bindParam(':p_code', $code, PDO::PARAM_STR);
        $stmt->bindParam(':p_date', $p_date, PDO::PARAM_STR);
        try {
            $stmt->execute();
            $id = $db->lastInsertId();
        } catch (Exception $e) {
            if ($firstError) {
                $errorList .= 'Photo could not insert to table!';
                $firstError = false;
            } else {
                $errorList .= '<br />Photo could not insert to table!';
            }
        }
        if ($firstError == false) {
            $result['status'] = 'error';
            $result['msg'] = $errorList;
            echo json_encode($result);
            exit;
        }
        copy('photos/tmp/' . $tmp_code . '.jpg', 'photos/status/' . $id . '.jpg');
        unlink('photos/tmp/' . $tmp_code . '.jpg');
        $sql = "INSERT INTO user_status (u_id, p_id, us_text, us_date) VALUES (:u_id, :p_id, :us_text, :us_date)";
        $stmt = $db->prepare($sql);
        $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT);
        $stmt->bindParam(':p_id', $id, PDO::PARAM_INT);
        $stmt->bindParam(':us_text', $statusText, PDO::PARAM_STR);
        $stmt->bindParam(':us_date', $p_date, PDO::PARAM_STR);
        try {
            $stmt->execute();
            $id = $db->lastInsertId();
        } catch (Exception $e) {
            if ($firstError) {
                $errorList .= 'Status text could not updated with photo!';
                $firstError = false;
            } else {
                $errorList .= '<br />Status text could not updated with photo!';
            }
        }
        if ($firstError == false) {
            $result['status'] = 'error';
            $result['msg'] = $errorList;
            echo json_encode($result);
            exit;
        }
        if (strlen($statusText) > 0) {
            $type = 'u_shared_photo_and_text';
            $action = addUserAction($_SESSION['user']->u_id, $id, $type);
        } else {
            $type = 'u_shared_photo';
            $action = addUserAction($_SESSION['user']->u_id, $id, $type);
        }
    } else {
        if (strlen($statusText) > 0) {
            $sql = "INSERT INTO user_status (u_id, us_text, us_date) VALUES (:u_id, :us_text, :us_date)";
            $stmt = $db->prepare($sql);
            $stmt->bindParam(':u_id', $_SESSION['user']->u_id, PDO::PARAM_INT);
            $stmt->bindParam(':us_text', $statusText, PDO::PARAM_STR);
            $stmt->bindParam(':us_date', $p_date, PDO::PARAM_STR);
            try {
                $stmt->execute();
                $id = $db->lastInsertId();
            } catch (Exception $e) {
                if ($firstError) {
                    $errorList .= 'Status text could not updated!';
                    $firstError = false;
                } else {
                    $errorList .= '<br />Status text could not updated!';
                }
            }
            if ($firstError == false) {
                $result['status'] = 'error';
                $result['msg'] = $errorList;
                echo json_encode($result);
                exit;
            }
            $type = 'u_shared_text';
            $action = addUserAction($_SESSION['user']->u_id, $id, $type);
        }
    }
    if ($firstError == false) {
        $result['status'] = 'error';
        $result['msg'] = $errorList;
        echo json_encode($result);
        exit;
    }
    $result['status'] = 'success';
    $result['msg'] = 'Status updated';
    echo json_encode($result);
}
Example #6
0
                    $data['result'] = false;
                } else {
                    $userId = mysqli_insert_id($connection);
                    $userIds[] = $userId;
                    $html = '
Hoi ' . $user['name'] . ',<br>
' . $postData['creator_name'] . ' heeft je uitgenodigd om je beschikbare dagen te selecteren voor het evenement "' . $postData['name'] . '".
<a href="http://www.tengwerda.nl/prikkr/#/event/' . $code . '/' . $userCode . '">Geef nu je keuze door</a> 
';
                    mailIt($user['email'], 'Je bent uitgenodigd voor evenement "' . $postData['name'] . '" op Prikkr', $html);
                }
            }
        }
        //Save the creator of the event aswell as a user.
        if (isset($postData['creator_name']) && !empty($postData['creator_name']) && isset($postData['creator_email']) && !empty($postData['creator_email'])) {
            $creatorCode = createCode();
            $qry = "INSERT INTO \n\t\t\t\t\t\t\tevent_user (event_id, name, email, code, is_creator) \n\t\t\t\t\t\tVALUES (\n\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $addedId) . "',\n\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $postData['creator_name']) . "', \n\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $postData['creator_email']) . "', \n\t\t\t\t\t\t\t'" . mysqli_real_escape_string($connection, $creatorCode) . "',\n\t\t\t\t\t\t\t1\n\t\t\t\t\t\t)";
            $result = mysqli_query($connection, $qry);
            if (!$result) {
                $data['result'] = false;
            } else {
                $userIds[] = mysqli_insert_id($connection);
                $html = '
Hoi ' . $postData['creator_name'] . ',<br>
Je evenement "' . $postData['name'] . '" is aangemaakt en een mail is verstuurd naar alle opgegeven vrienden.<br>
<a href="http://www.tengwerda.nl/prikkr/#/event/' . $code . '/' . $creatorCode . '">Geef je eigen keuze door</a> of <a href="http://www.tengwerda.nl/prikkr/#/event/overview/' . $code . '/' . $creatorCode . '">Bekijk wat je vrienden tot nu ingevuld hebben</a>.<br>
';
                mailIt($postData['creator_email'], 'Je bent uitgenodigd voor evenement "' . $postData['name'] . '" op Prikkr', $html);
            }
        }
        if (count($dateIds) > 0 && count($userIds) > 0) {