Esempio n. 1
0
function pp_register($userName, $userPass, $userMail)
{
    if (empty($userName) || empty($userPass) || empty($userMail)) {
        return false;
    }
    $link = pp_connect();
    if ($link) {
        $sql = "SELECT userId FROM " . PP_TABLE_USER . " WHERE userName='******' OR userEmail='" . mysqli_real_escape_string($link, $userMail) . "'";
        $result = mysqli_query($link, $sql);
        if (mysqli_fetch_assoc($result)) {
            echo "<p>This username or email is already registered!</p>";
            return false;
        }
        $sql = "INSERT INTO " . PP_TABLE_USER . " VALUES(" . "NULL" . ", " . "'" . mysqli_real_escape_string($link, $userName) . "', " . "'" . mysqli_real_escape_string($link, password_hash($userPass, PASSWORD_DEFAULT)) . "', " . "'" . "user" . "', " . "'" . mysqli_real_escape_string($link, $userMail) . "', " . "'" . mysqli_real_escape_string($link, pp_generate_user_token()) . "', " . "0)";
        $result = mysqli_query($link, $sql);
        if ($result) {
            $newUserId = mysqli_insert_id($link);
            //Create menu and page;
            $newPageId = pp_create_page($newUserId, "My First Page", "<h2>Page by " . $userName . "</h2>");
            $newMenuId = pp_create_menu($newUserId, "My Menu");
            pp_create_menu_item($newMenuId, $newPageId);
            pp_set_active_menu($newUserId, $newMenuId);
            return true;
        } else {
            echo "<p>An error occured registering a new user</p>";
            echo "<p>" . mysqli_error($link) . "</p>";
        }
    }
    return false;
}
Esempio n. 2
0
<?php

if (isset($_SESSION['user']['userId'])) {
    echo '<p><a href="?page=admin">Back to admin panel</a></p>';
    echo '<h2>Select active menu</h2>';
    if (isset($_POST['submit'])) {
        $menuId = filter_input(INPUT_POST, 'menu', FILTER_VALIDATE_INT);
        if ($menuId) {
            //UPDATE MENU
            pp_set_active_menu($_SESSION['user']['userId'], $menuId);
        }
    }
    $menuData = pp_get_user_menus($_SESSION['user']['userId']);
    $activeMenu = pp_get_user_details($_SESSION['user']['userId'])['activeMenu'];
    ?>
<form action="<?php 
    echo $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
    ?>
" method="post">
    <table>
        <tr><th rel="col" class="align_left">Menu name</th><th rel="col">Menu id</th><th rel="col">Is active</th></tr>
        <?php 
    foreach ($menuData as $data) {
        echo "<tr>\n";
        echo '<td class="align_left"><a href="?page=editmenu&param=' . $data['menuId'] . '">' . $data['menuName'] . '</a></td>';
        echo '<td>' . $data['menuId'] . '</td>';
        if ($data['menuId'] === $activeMenu) {
            echo '<td><input type="radio" name="menu" checked value="' . $data['menuId'] . '"></td>';
        } else {
            echo '<td><input type="radio" name="menu" value="' . $data['menuId'] . '"></td>';
        }