CPG group Anonymous = 3
define('CPG_ADMIN_GROUP', 1);
define('CPG_ANONYMOUS_GROUP', 3);
debug_log(T_('BEGIN'));
/* udb_authenticate(-)
Verify if a user is looged in, if yes authenticate it using cookies
*
* {@internal cpgGetUserData(-) }}
* {@internal User::verifylog(-) }}
* @author slamp
*/
function udb_authenticate()
{
debug_log('udb_authenticate');
global $CONFIG, $UDB_DB_LINK_ID, $USER_DATA, $current_User;
global $CONFIG, $UDB_DB_LINK_ID, $USER_DATA, $_COOKIE, $cookie_user, $cookie_pass;
debug_log("udb login: $current_User->login");
debug_log("udb pass: $current_User->pass");
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
// Permissions for a default group
// Default group data
$USER_DATA['group_quota'] = 1;
$USER_DATA['can_rate_pictures'] = 0;
$USER_DATA['can_send_ecards'] = 0;
$USER_DATA['can_post_comments'] = 0;
$USER_DATA['can_upload_pictures'] = 0;
$USER_DATA['can_create_albums'] = 0;
$USER_DATA['pub_upl_need_approval'] = 1;
$USER_DATA['priv_upl_need_approval'] = 1;
$USER_DATA['upload_form_config'] = 0;
$USER_DATA['num_file_upload'] = 0;
$USER_DATA['num_URI_upload'] = 0;
$USER_DATA['custom_user_upload'] = 0;
// Login procedure:
// @todo add isset current_User in first if
if ( isset($_COOKIE[$cookie_user]) && isset($_COOKIE[$cookie_pass]) )
{
debug_log('udb: cookie defini');
// get cookie
$udb_user_login = trim(strip_tags(get_magic_quotes_gpc() ? stripslashes($_COOKIE[$cookie_user]) : $_COOKIE[$cookie_user]));
$udb_user_pass = trim(strip_tags(get_magic_quotes_gpc() ? stripslashes($_COOKIE[$cookie_pass]) : $_COOKIE[$cookie_pass]));
}
elseif ( isset($current_User)) {
debug_log('udb: current_User defined');
$udb_user_login = $current_User->login;
$udb_user_pass = $current_User->pass;
}
else {
debug_log('udb: cookie et current_User non defini');
unset($udb_user_login);
unset($udb_user_pass);
}
if ( isset($udb_user_login) && isset($udb_user_pass) )
{
$udb_userdata = get_userdatabylogin($udb_user_login);
// @todo: a traiter cas du pass pas en md5 if( !$pass_is_md5 ) $user_pass = md5( $user_pass );
$udb_login_ok = ($udb_user_pass == $udb_userdata['user_pass']);
}
else {
$udb_login_ok = false;
}
if ( $udb_login_ok )
{ // login OK
debug_log("udb: login ok");
$udb_current_User = new User( $udb_userdata ); // COPY!
// $user_ID = $userdata_2['ID'];
// $user_nickname = $userdata['user_nickname'];
// $user_email = $userdata['user_email'];
// $user_url = $userdata['user_url'];
debug_log('udb login: ' . $udb_current_User->login);
debug_log('udb groupe: ' .$udb_current_User->Group->ID);
debug_log('udb level: ' . $udb_current_User->level);
// Even if in b2evolution, a user can be inside only one group at the same time, we use an array for groups to respects cpg functions
// Define the groups
$USER_DATA['groups'] = array();
switch ($udb_current_User->Group->ID) {
case B2EVO_ADMIN_GROUP: // 1
$USER_DATA['groups'][0] = CPG_ADMIN_GROUP; // 1
break;
case B2EVO_PRIV_BLOGGERS_GROUP: // 2
$USER_DATA['groups'][0] = 2; // a definir
break;
case B2EVO_BLOGGERS_GROUP: //3
$USER_DATA['groups'][0] = 3; // a definir
break;
case B2EVO_BASIC_USERS_GROUP: //4
$USER_DATA['groups'][0] = CPG_ANONYMOUS_GROUP; // 3
break;
default:
$USER_DATA['groups'][0] = CPG_ANONYMOUS_GROUP; // a verifier
break;
}
debug_log('udb groupe CPG: ' . $USER_DATA['groups'][0]);
$USER_DATA = cpgGetUserData($USER_DATA['groups'][0], $USER_DATA['groups'], CPG_ANONYMOUS_GROUP);
debug_log('udb groupe CPG: ' . $USER_DATA['groups'][0]);
define('USER_ID', $udb_current_User->ID);
define('USER_NAME', $udb_current_User->login); // a ameliorer
define('USER_GROUP_SET', '(' . $USER_DATA['groups'][0] . ')');
// define('USER_GROUP_SET', '(' . implode(',', $USER_DATA['groups']) . ')';
debug_log('udb groupe set: ' . USER_GROUP_SET);
define('USER_IS_ADMIN', ($udb_current_User->Group->ID == B2EVO_ADMIN_GROUP));
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
}
else
{ // login is NOT OK:
debug_log("udb: login failed");
// Login failed: user is a guest, initialize all the critial user settings
// verifier qd anonyme le groupe a mettre
$USER_DATA = cpgGetUserData(CPG_ANONYMOUS_GROUP, array(CPG_ANONYMOUS_GROUP), CPG_ANONYMOUS_GROUP);
define('USER_ID', 0);
define('USER_NAME', 'Anonymous');
define('USER_GROUP_SET', '(' . CPG_ANONYMOUS_GROUP . ')');
define('USER_IS_ADMIN', 0);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', 0);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
}
// @todo voir si il faut copier udb_current_User dans current_User
debug_log('udb: end');
debug_info();
}
/* udb_get_user_name(-)
Retrieve the name of a user
@return string
*/
function udb_get_user_name($uid)
{
global $current_User; // a tester
debug_log('udb_get_user_name');
if (isset($current_User)) { return $current_User->login; }
else { return ''; }
debug_info();
}
/* udb_get_user_name_id(-)
Retrieve the ID of a user (Added to fix banning w/ bb integration - Nibbler)
@return int
*/
function udb_get_user_id($username)
{
global $current_User;
debug_log("udb_get_user_id");
if (isset($current_User)) { return $current_User->ID; }
else { return ''; }
debug_info();
}
/* udb_redirect(-)
HTTP Redirect
*/
function udb_redirect($target)
{
#global $baseurl;
header('Location: http://' . $_SERVER['HTTP_HOST'] . B2EVO_WEB_PATH . $target);
#header('Location: ' . $baseurl . B2EVO_WEB_PATH . $target);
debug_log('redirected to : ' . $target);
debug_info();
exit;
}
/* udb_register_page(-)
Redirect to registration page in b2evolution
*/
function udb_register_page()
{
udb_redirect(REGISTRATION_REDIR);
}
/* udb_login_page(-)
Redirect to login page in b2evolution
*/
function udb_login_page()
{
udb_redirect(LOGIN_REDIR);
}
/* udb_logout_page(-)
Redirect to logout page in b2evolution
*/
function udb_logout_page()
{
#logout();
udb_redirect(LOGOUT_FLAG);
}
/* udb_edit_users(-)
Redirect to Edit users page in b2evolution admin section
*/
function udb_edit_users()
{
udb_redirect(EDIT_USERS_REDIR);
}
/* udb_get_user_infos(-)
Get user information
*/
function udb_get_user_infos($uid)
{
global $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
global $lang_register_php;
debug_log("udb_get_user_info");
debug_log('lang: ' . $lang_register_php);
$sql = "SELECT user_login as user_name, user_email, user_url as user_website " . "FROM " . $UDB_DB_NAME_PREFIX . B2EVOLUTION_TABLE_PREFIX . B2EVOLUTION_USER_TABLE . " " . "WHERE ID = '$uid'";
$result = db_query($sql, $UDB_DB_LINK_ID);
if (!mysql_num_rows($result)) cpg_die(ERROR, $lang_register_php['err_unk_user'], __FILE__, __LINE__);
$user_data = mysql_fetch_array($result);
$user_data['group_name'] = '';
mysql_free_result($result);
debug_info();
return $user_data;
}
/* udb_edit_profile(-)
Edit user profile
*/
function udb_edit_profile($uid)
{
debug_log('edit_profile: ' . $uid);
udb_redirect(EDIT_USER_PROFILE);
}
/* udb_list_users_query(-)
Query used to list users
*/
function udb_list_users_query(&$user_count)
{
global $CONFIG, $FORBIDDEN_SET;
debug_log("udb_list_user_query");
if ($FORBIDDEN_SET != "") {$forbidden = "AND $FORBIDDEN_SET";}
$sql = "SELECT (category - " . FIRST_USER_CAT . ") as user_id," . " '???' as user_name," . " COUNT(DISTINCT a.aid) as alb_count," . " COUNT(DISTINCT pid) as pic_count," . " MAX(pid) as thumb_pid " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN {$CONFIG['TABLE_PICTURES']} AS p ON p.aid = a.aid " . "WHERE approved = 'YES' AND category > " . FIRST_USER_CAT . " $forbidden GROUP BY category " . "ORDER BY category ";
$result = db_query($sql);
$user_count = mysql_num_rows($result);
debug_info();
return $result;
}
/* udb_list_users_retrieve_data(-)
*/
function udb_list_users_retrieve_data($result, $lower_limit, $count)
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
debug_log("udb_list_users_retrieve_data");
mysql_data_seek($result, $lower_limit);
$rowset = array();
$i = 0;
$user_id_set = '';
while (($row = mysql_fetch_array($result)) && ($i++ < $count)) {
$user_id_set .= $row['user_id'] . ',';
$rowset[] = $row;
}
mysql_free_result($result);
$user_id_set = '(' . substr($user_id_set, 0, -1) . ')';
$sql = "SELECT ID as user_id, username as user_name " . "FROM " . $UDB_DB_NAME_PREFIX . B2EVOLUTION_TABLE_PREFIX . B2EVOLUTION_USER_TABLE . " " . "WHERE user_id IN $user_id_set";
$result = db_query($sql, $UDB_DB_LINK_ID);
while ($row = mysql_fetch_array($result)) {
$name[$row['user_id']] = $row['user_name'];
}
for($i = 0; $i < count($rowset); $i++) {
$rowset[$i]['user_name'] = empty($name[$rowset[$i]['user_id']]) ? '???' : $name[$rowset[$i]['user_id']];
}
debug_info();
return $rowset;
}
/* udb_synchronize_groups(-)
Group table synchronisation
*/
function udb_synchronize_groups()
{
//nothing to do yet
debug_log("udb_synchronize_group");
debug_info();
}
/* udb_get_admin_album_list(-)
Retrieve the album list used in gallery admin mode
*/
function udb_get_admin_album_list()
{
global $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID, $FORBIDDEN_SET;
debug_log("udb_get_admin_album_list");
if (UDB_CAN_JOIN_TABLES) {
$sql = "SELECT aid, CONCAT('(', username, ') ', title) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "INNER JOIN " . $UDB_DB_NAME_PREFIX . B2EVOLUTION_TABLE_PREFIX . B2EVOLUTION_USER_TABLE . " AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY title";
return $sql;
} else {
$sql = "SELECT aid, IF(category > " . FIRST_USER_CAT . ", CONCAT('* ', title), CONCAT(' ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} " . "ORDER BY title";
return $sql;
}
debug_info();
}
/* udb_util_filloptions(-)
*/
function udb_util_filloptions()
{
global $albumtbl, $picturetbl, $categorytbl, $lang_util_php, $CONFIG, $UDB_DB_NAME_PREFIX, $UDB_DB_LINK_ID;
debug_log("udb_util_filloptions");
$usertbl = $UDB_DB_NAME_PREFIX.B2EVOLUTION_TABLE_PREFIX.B2EVOLUTION_USER_TABLE;
if (UDB_CAN_JOIN_TABLES) {
$query = "SELECT aid, category, IF(username IS NOT NULL, CONCAT('(', username, ') ', a.title), CONCAT(' - ', a.title)) AS title " . "FROM $albumtbl AS a " . "LEFT JOIN $usertbl AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY category, title";
$result = db_query($query, $UDB_DB_LINK_ID);
// $num=mysql_numrows($result);
echo ' (3)';
print ' (4)';
print '';
} else {
// Query for list of public albums
$public_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category < " . FIRST_USER_CAT . " ORDER BY title");
if (mysql_num_rows($public_albums)) {
$public_result = db_fetch_rowset($public_albums);
} else {
$public_result = array();
}
// Initialize $merged_array
$merged_array = array();
// Count the number of albums returned.
$end = count($public_result);
// Cylce through the User albums.
for($i=0;$i<$end;$i++) {
//Create a new array sow we may sort the final results.
$merged_array[$i]['id'] = $public_result[$i]['aid'];
$merged_array[$i]['album_name'] = $public_result[$i]['title'];
// Query the database to get the category name.
$vQuery = "SELECT name, parent FROM " . $CONFIG['TABLE_CATEGORIES'] . " WHERE cid='" . $public_result[$i]['category'] . "'";
$vRes = mysql_query($vQuery);
$vRes = mysql_fetch_array($vRes);
if (isset($merged_array[$i]['username_category'])) {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '').$merged_array[$i]['username_category'];
} else {
$merged_array[$i]['username_category'] = (($vRes['name']) ? '(' . $vRes['name'] . ') ' : '');
}
}
// We transpose and divide the matrix into columns to prepare it for use in array_multisort().
foreach ($merged_array as $key => $row) {
$aid[$key] = $row['id'];
$title[$key] = $row['album_name'];
$album_lineage[$key] = $row['username_category'];
}
// We sort all columns in descending order and plug in $album_menu at the end so it is sorted by the common key.
array_multisort($album_lineage, SORT_ASC, $title, SORT_ASC, $aid, SORT_ASC, $merged_array);
// Query for list of user albums
$user_albums = db_query("SELECT aid, title, category FROM {$CONFIG['TABLE_ALBUMS']} WHERE category >= " . FIRST_USER_CAT . " ORDER BY aid");
if (mysql_num_rows($user_albums)) {
$user_albums_list = db_fetch_rowset($user_albums);
} else {
$user_albums_list = array();
}
// Query for list of user IDs and names
$user_album_ids_and_names = db_query("SELECT (user_id + ".FIRST_USER_CAT.") as id, CONCAT('(', username, ') ') as name FROM $usertbl ORDER BY name ASC",$UDB_DB_LINK_ID);
if (mysql_num_rows($user_album_ids_and_names)) {
$user_album_ids_and_names_list = db_fetch_rowset($user_album_ids_and_names);
} else {
$user_album_ids_and_names_list = array();
}
// Glue what we've got together.
// Initialize $udb_i as a counter.
if (count($merged_array)) {
$udb_i = count($merged_array);
} else {
$udb_i = 0;
}
//Begin a set of nested loops to merge the various query results.
foreach ($user_albums_list as $aq) {
foreach ($user_album_ids_and_names_list as $uq) {
if ($aq['category'] == $uq['id']) {
$merged_array[$udb_i]['id']= $aq['category'];
$merged_array[$udb_i]['album_name']= $aq['title'];
$merged_array[$udb_i]['username_category']= $uq['name'];
$udb_i++;
}
}
}
// The user albums and public albums have been merged into one list. Print the dropdown.
echo ' (3)';
print ' (4)';
print '';
}
debug_info();
}
// ------------------------------------------------------------------------- //
// Define wheter we can join tables or not in SQL queries (same host & same db or user)
define('UDB_CAN_JOIN_TABLES', (B2EVO_DB_HOST == $CONFIG['dbserver'] && (B2EVO_DB_NAME == $CONFIG['dbname'] || B2EVO_DB_USERNAME == $CONFIG['dbuser'])));
// define('UDB_CAN_JOIN_TABLES', false);
// Connect to b2evolution database if necessary
$UDB_DB_LINK_ID = 0;
$UDB_DB_NAME_PREFIX = B2EVO_DB_NAME ? '`' . B2EVO_DB_NAME . '`.' : '';
if (!UDB_CAN_JOIN_TABLES) {
$UDB_DB_LINK_ID = @MYSQL_CONNECT(B2EVO_DB_HOST, B2EVO_DB_USERNAME, B2EVO_DB_PASSWORD);
IF (!$UDB_DB_LINK_ID) DIE("COPPERMINE CRITICAL ERROR:
UNABLE TO CONNECT TO B2EVOLUTION BOARD DATABASE !
MYSQL SAID: " . MYSQL_ERROR() . "");
}
?>