From: Lo?c C. <lo...@us...> - 2001-04-04 11:11:42
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat In directory usw-pr-cvs1:/tmp/cvs-serv5662 Added Files: users_low.php3 Log Message: The first dev. version that works! Still many things to do, of course... --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This script defines the 'users' frame for browser that does not support | // | DHTML. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: users_low.php3,v 1.1 2001/04/04 11:11:38 loic1 Exp $ // // The 'users' frame for browsers that does not support DHTML. // /** * Gets the extension for the php scripts */ if (!isset($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF']; define('C_EXTENSION', (substr($PHP_SELF, -1) == 3) ? 'php3' : 'php'); /** * Gets some core libraries */ require('./config/config.lib.' . C_EXTENSION); require('./lib/common.lib.' . C_EXTENSION); require('./lib/database/' . C_DB_TYPE . '.lib.' . C_EXTENSION); require('./lib/clean.lib.' . C_EXTENSION); /** * Gets the values of variables sent or posted to this script * * Uses the 'pmcGrabGlobals()' and the 'pmcHandleMagicQuotes()' functions * defined in the 'chat/lib/common.lib.php3' library. */ pmcGrabGlobals('dbSessionId'); /** * Start the session handler */ require('./lib/db_sessions.lib.' . C_EXTENSION); dbSessionInitIt( C_DB_TYPE, C_DB_HOST, C_DB_NAME, C_DB_USER, C_DB_PASS, C_SESS_TBL, C_REG_DEL, C_SESS_DEL * 60 ); dbSessionstart(); /** * Defines the language to be used */ require('./localization/' . $dbSessionVars['lang'] . '/localized.chat.' . C_EXTENSION); $textDirection = (L_CHARSET == 'windows-1256') ? 'rtl' : 'ltr'; /** * Sends HTTP headers * * The 'pmcHttpHeaders()' fonction is defined in the 'chat/lib/common.lib.php3' * library */ pmcHttpHeaders(L_CHARSET, true); /** * Format an username according to the status of the user * * The 'pmcSpecialChars()' fonction is defined in the * 'chat/lib/common.lib.php3' library * * @param string the username * @param boolean whether this username uses 'iso-8859-1' character set or * not * @param string the status of the user * * @return string the formatted username * * @access public */ function pmcFormatUsername($theUsername, $isUnLatin1, $theSatus) { $tagOpen = ($theSatus == 'a' || $theSatus == 'm') ? '<i>' : ''; $tagClose = ($tagOpen != '') ? '</i>' : ''; $theUsername = $tagOpen . pmcSpecialChars($theUsername, $isUnLatin1) . $tagClose; return $theUsername; } // end of the 'pmcFormatUsername()' function /** * Defines some variables */ $slashedNick = pmcSlashSingleQuotes($dbSessionVars['nick']); $currentRoomType = $dbSessionVars['roomType']; $slashedCurrentRoomName = pmcSlashSingleQuotes($dbSessionVars['targetRoom']); $usersList = array(); /** * Build the users list for the current room * * The 'pmcSlashSingleQuotes()', the 'pmcHandleMagicQuotes()' and the * 'pmcSpecialChars()' fonctions are defined in the 'chat/lib/common.lib.php3' * library */ if (C_DB_TYPE == 'mysql') { $currentRoomQuery = 'SELECT usr.username, usr.latin1, usr.status, reg.gender ' . 'FROM ' . C_USR_TBL . ' usr LEFT JOIN ' . C_REG_TBL . ' reg ON usr.username = reg.username ' . 'WHERE usr.room = \'' . $slashedCurrentRoomName . '\' ' . 'ORDER BY usr.username'; } else if (C_DB_TYPE == 'pgsql') { $currentRoomQuery = 'SELECT usr.username, usr.latin1, usr.status, reg.gender ' . 'FROM ' . C_USR_TBL . ' usr, ' . C_REG_TBL . ' reg ' . 'WHERE usr.room = \'' . $slashedCurrentRoomName . '\' ' . 'UNION ' . 'SELECT usr.username, usr.latin1, usr.status, NULL ' . 'FROM ' . C_USR_TBL . ' usr ' . 'WHERE usr.username NOT IN (SELECT reg.username FROM ' . C_REG_TBL . ' reg) AND usr.room = \'' . $slashedCurrentRoomName . '\' ' . 'ORDER BY usr.username'; } else { $currentRoomQuery = 'SELECT usr.username, usr.latin1, usr.status, NULL ' . 'FROM ' . C_USR_TBL . ' usr ' . 'WHERE usr.room = \'' . $slashedCurrentRoomName . '\' ' . 'ORDER BY usr.username'; } $usersCnt = 0; $usersList[] = '<!-- The current room -->'; $usersList[] = '<p>'; $usersList[] = '<b>' . htmlspecialchars($dbSessionVars['targetRoom']) . '</b>' . '<span class="small">' . '<bdo dir="' . $textDirection . '"></bdo>' . ' (%NUMROWS%)' . '</span><br />'; $currentRoomDb = new pmcDB; $currentRoomDb->query($currentRoomQuery); while (list($username, $latin1, $status, $gender) = $currentRoomDb->nextRecord()) { $usersCnt++; $username = pmcHandleMagicQuotes($username, '', 1, 'del'); // Define the icon to put for this user if ($gender == 0) $gender = 'undefined'; else if ($gender == 1) $gender = 'boy'; else if ($gender == 2) $gender = 'girl'; else $gender = 'none'; if ($status != 'u' && $status != 'k' && $status != 'd' && $status != 'b') { $tmpStr = '<a href="#" onclick="window.parent.pmcRunCmd(' . (($username == $dbSessionVars['nick']) ? '\'PROFILE\', \'\'' : '\'WHOIS\', \'' . pmcSlashSingleQuotes(pmcSpecialChars($username, $latin1)) .'\'') . '); return false;" class="user">' . '<img src="images/gender_' . $gender . '.gif" width="14" height="14" border="0" alt="' . L_PROFILE . '" />' . '</a> '; } else { $tmpStr = '<img src="images/gender_none.gif" width="14" height="14" border="0" alt="' . L_NO_PROFILE . '" /> '; } // Define the format to be used for the username according to the status if ($username != $dbSessionVars['nick']) { $tmpStr .= '<a href="javascript:window.parent.pmcUserClick(\'' . pmcSlashSingleQuotes(pmcSpecialChars($username, $latin1)) . '\', false)" class="user">' . pmcFormatUsername($username, $latin1, $status) . '</a><br />'; } else { $tmpStr .= pmcFormatUsername($username, $latin1, $status) . '<br />'; } $usersList[] = "\t" . $tmpStr; } $currentRoomDb->cleanResults(); $currentRoomDb->close(); $usersList[] = '</p>'; $usersList[] = ''; $usersList[] = ''; $usersList[2] = str_replace('%NUMROWS%', $usersCnt, $usersList[2]); /** * Build the users list for the others populated rooms * * The 'pmcSlashSingleQuotes()', the 'pmcHandleMagicQuotes()' and the * 'pmcSpecialChars()' fonctions are defined in the 'chat/lib/common.lib.php3' * library */ // 1. Get the list of rooms and users if (C_DB_TYPE == 'mysql') { $otherRoomsQuery = 'SELECT usr.username, usr.latin1, usr.status, reg.gender ' . 'FROM ' . C_USR_TBL . ' usr LEFT JOIN ' . C_REG_TBL . ' reg ON usr.username = reg.username ' . 'WHERE usr.room = \'%OTHER%\' ' . 'ORDER BY usr.username'; } else if (C_DB_TYPE == 'pgsql') { $otherRoomsQuery = 'SELECT usr.username, usr.latin1, usr.status, reg.gender ' . 'FROM ' . C_USR_TBL . ' usr, ' . C_REG_TBL . ' reg ' . 'WHERE usr.room = \'%OTHER%\' ' . 'UNION ' . 'SELECT usr.username, usr.latin1, usr.status, 0 ' . 'FROM ' . C_USR_TBL . ' usr ' . 'WHERE usr.username NOT IN (SELECT reg.username FROM ' . C_REG_TBL . ' reg) AND usr.room = \'%OTHER%\' ' . 'ORDER BY usr.username'; } else { $otherRoomsQuery = 'SELECT usr.username, usr.latin1, usr.status, 0 ' . 'FROM ' . C_USR_TBL . ' usr ' . 'WHERE usr.room = \'%OTHER%\' ' . 'ORDER BY usr.username'; } $othersRooms = array(); $otherRoomDb = new pmcDB; $otherRoomDb->query("SELECT DISTINCT room FROM " . C_MSG_TBL . " WHERE room != '$slashedCurrentRoomName' AND type = 1 ORDER BY room"); while (list($otherRoom) = $otherRoomDb->nextRecord()) $othersRooms[pmcHandleMagicQuotes($otherRoom, '', 1, 'del')] = ''; $otherRoomDb->cleanResults(); $filteredOtherRooms = array(); reset($othersRooms); while (list($roomName, $usersIn) = each($othersRooms)) { $usersDetails = array(); $slashedOther = pmcSlashSingleQuotes($roomName); $otherRoomDb->query(str_replace('%OTHER%', $slashedOther, $otherRoomsQuery)); while (list($otherUser, $latin1, $status, $gender) = $otherRoomDb->nextRecord()) { $usersDetails[] = array( pmcHandleMagicQuotes($otherUser, '', 1, 'del'), $latin1, $status, $gender ); } $otherRoomDb->cleanResults(); if (count($usersDetails) > 0) $filteredOtherRooms[$roomName] = $usersDetails; unset($usersDetails); } $otherRoomDb->close(); $othersRooms = $filteredOtherRooms; unset($roomName); unset($usersIn); unset($filteredOtherRooms); // 2. Format this list if (count($othersRooms) > 0) { $i = 0; $childCnt = array(); $joinUrl = $dbSessionVars['from'] . '?' . dbSessionSID('GET') . $pmcQueryArgSeparator . 'exitMessage=1' . $pmcQueryArgSeparator . 'newTargetRoom=1%NEWROOM%'; reset($othersRooms); while (list($roomName, $usersIn) = each($othersRooms)) { $usersInCnt = count($usersIn); if ($usersInCnt > 0) { $id = md5($roomName); $childCnt[$id] = $usersInCnt; $usersList[] = '<!-- The others rooms currently in use -->'; $usersList[] = '<p>'; $usersList[] = '<a href="' . str_replace('%NEWROOM%', urlencode($roomName), $joinUrl) . '" target="_parent">' . htmlspecialchars($roomName) . '</a>' . '<span class="small"><bdo dir="' . $textDirection . '"></bdo> ' . '(' . $usersInCnt . ')</span><br />'; for (reset($usersIn); $userDetails = current($usersIn); next($usersIn)) { $otherUser = $userDetails[0]; $latin1 = $userDetails[1]; $status = $userDetails[2]; $gender = $userDetails[3]; // Put an icon when there is a profile for the user if ($gender == 0) $gender = 'undefined'; else if ($gender == 1) $gender = 'boy'; else if ($gender == 2) $gender = 'girl'; else $gender = 'none'; if ($status != 'u' && $status != 'k' && $status != 'd' && $status != 'b') $tmpStr = '<a href="#" onclick="window.parent.pmcRunCmd(\'WHOIS\', \''. pmcSlashSingleQuotes(pmcSpecialChars($otherUser, $latin1)) . '\'); return false" class="user">' . '<img src="images/gender_' . $gender . '.gif" width="14" height="14" border="0" alt="' . L_PROFILE . '" />' . '</a> '; else $tmpStr = '<img src="images/gender_none.gif" width="14" height="14" border="0" alt="' . L_NO_PROFILE . '" /> '; $tmpStr .= '<a href="javascript:window.parent.pmcUserClick(\'' . pmcSlashSingleQuotes(pmcSpecialChars($otherUser, $latin1)) . '\', false)" class="user">' . pmcFormatUsername($otherUser, $latin1, $status) . '</a><br />'; $usersList[] = "\t" . $tmpStr; } $usersList[] = '</p>'; $usersList[] = ''; } } unset($usersIn); $usersList[] = ''; } unset($othersRooms); /** * Build the list of empty default and public rooms * * The 'pmcSlashSingleQuotes()', the 'pmcHandleMagicQuotes()' and the * 'pmcSpecialChars()' fonctions are defined in the 'chat/lib/common.lib.php3' * library */ $joinUrl = $dbSessionVars['from'] . '?' . dbSessionSID('GET') . $pmcQueryArgSeparator . 'exitMessage=1' . $pmcQueryArgSeparator . 'newTargetRoom=1%NEWROOM%'; $usersList[] = '<!-- The others default and public rooms -->'; reset($defaultChatRooms); for ($k = 0; $k < count($defaultChatRooms); $k++) { $tmpRoom = stripslashes($defaultChatRooms[$k]); $id = md5($tmpRoom); // Display this room name when it hadn't been displayed yet if (strcasecmp($tmpRoom, $dbSessionVars['targetRoom']) != 0 && (!isset($childCnt) || !isset($childCnt[$id]))) { $usersList[] = '<p>'; $usersList[] = "\t" . '<a href="' . str_replace('%NEWROOM%', urlencode($tmpRoom), $joinUrl) . '" target="_parent">' . htmlspecialchars($tmpRoom) . '</a>' . '<span class="small"><bdo dir="' . $textDirection . '"></bdo>' . ' (0)</span>'; $usersList[] = ''; $usersList[] = '</p>'; } } /** * Displays the frame */ // The url for the style sheet $cssUrl = pmcUrlForStyleSheet('style', L_CHARSET, (defined('L_FONT_NAME')) ? L_FONT_NAME : '', L_FONT_SIZE); $refeshUrl = 'users_low.' . C_EXTENSION . '?' . dbSessionSID('GET'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html dir="<?php echo($textDirection); ?>"> <head> <title><?php echo(APP_NAME); ?></title> <meta http-equiv="Refresh" content="30; url=<?php echo($refeshUrl); ?>" /> <link rel="stylesheet" href="<?php echo($cssUrl); ?>" type="text/css" /> </head> <body class="frame"> <?php reset($usersList); for ($i = 0; $i < count($usersList); $i++) { echo($usersList[$i] . "\n"); } ?> </body> </html> <?php ?> |