Example #1
0
/**
 * Generate layout color form.
 *
 * @author Laurent Declercq <*****@*****.**>
 * @param $tpl iMSCP_pTemplate Template engine instance
 * @return void
 */
function client_generateLayoutColorForm($tpl)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $colors = layout_getAvailableColorSet();
    if (!empty($POST) && isset($_POST['layoutColor']) && in_array($_POST['layoutColor'], $colors)) {
        $selectedColor = $_POST['layoutColor'];
    } else {
        $selectedColor = layout_getUserLayoutColor($_SESSION['user_id']);
    }
    if (!empty($colors)) {
        foreach ($colors as $color) {
            $tpl->assign(array('COLOR' => $color, 'SELECTED_COLOR' => $color == $selectedColor ? $cfg->HTML_SELECTED : ''));
            $tpl->parse('LAYOUT_COLOR_BLOCK', '.layout_color_block');
        }
    } else {
        $tpl->assign('LAYOUT_COLORS_BLOCK', '');
    }
}
Example #2
0
/**
 * Sets given layout color for given user
 *
 * @author Laurent Declercq <*****@*****.**>
 * @param int $userId User unique identifier
 * @param string $color Layout color
 * @return bool TRUE on success false otherwise
 */
function layout_setUserLayoutColor($userId, $color)
{
    if (in_array($color, layout_getAvailableColorSet())) {
        $query = 'UPDATE `user_gui_props` SET `layout_color` = ? WHERE `user_id` = ?';
        exec_query($query, array($color, (int) $userId));
        // Dealing with sessions across multiple browsers for same user identifier - Begin
        $sessionId = session_id();
        $query = "SELECT `session_id` FROM `login` WHERE `user_name` = ?  AND `session_id` <> ?";
        $stmt = exec_query($query, array($_SESSION['user_logged'], $sessionId));
        if ($stmt->rowCount()) {
            foreach ($stmt->fetchAll(PDO::FETCH_COLUMN) as $otherSessionId) {
                session_write_close();
                session_id($otherSessionId);
                session_start();
                $_SESSION['user_theme_color'] = $color;
                // Update user layout color
            }
            // Return back to the previous session
            session_write_close();
            session_id($sessionId);
            session_start();
        }
        // Dealing with data across multiple sessions - End
        return true;
    }
    return false;
}