<?php function _db_member_basic_query_prefix() { global $Config; $sql="SELECT " ."`m`.`mb_id`, `l`.`mb_login`, `m`.`mb_nickname`, `m`.`mb_timezone_minutes` " ."FROM `{$Config->TableMap['login']}` `l` " ."NATURAL LEFT JOIN `{$Config->TableMap['member']}` `m` " ."WHERE 1 "; return $sql; } function db_member_basic_by_auth($dbconn,$login,$pswdhash) { $sql=_db_member_basic_query_prefix() ."AND " ."`mb_login`='".$dbconn->escape($login)."' AND " ."`mb_pswdhash`='".$pswdhash."' AND " ."`mb_status`='VALID' " ."LIMIT 1 "; return $dbconn->query_row_assoc($sql); } function db_member_basic_by_id($dbconn,$mb_id) { $sql=_db_member_basic_query_prefix() ."AND " ."`mb_id`='".$dbconn->escape($mb_id)."' " ."LIMIT 1 "; return $dbconn->query_row_assoc($sql); } function db_load_member($dbconn,$mb_id) { if (!$mb_id) return array(); global $Config; $sql="SELECT * FROM `{$Config->TableMap['member']}` " ."WHERE `mb_id`=".$dbconn->escape($mb_id); return $dbconn->query_row_assoc($sql); } function db_load_member_info($dbconn,$mb_id) { global $Config; $sql="SELECT * " ."FROM `{$Config->TableMap['member_info']}` " ."WHERE `mb_id`=".$dbconn->escape($mb_id); return $dbconn->query_row_assoc($sql); } function db_load_member_emails($dbconn,$mb_ids,$validatedonly=true) { global $Config; $sql="SELECT * " ."FROM `{$Config->TableMap['member_email']}` " ."WHERE `mb_id` IN (".$dbconn->escape($mb_ids).") " .($validatedonly?"AND `me_status`='VALIDATED' ":""); return $dbconn->query_allrows_assoc($sql); } function db_load_member_phones($dbconn,$mb_ids) { global $Config; $sql="SELECT * " ."FROM `{$Config->TableMap['member_phone']}` " ."WHERE `mb_id` IN (".$dbconn->escape($mb_ids).")"; return $dbconn->query_allrows_assoc($sql); } function db_load_member_notifiable($dbconn,$mb_id) { global $Config; $sql="SELECT * " ."FROM `{$Config->TableMap['member_notifiable']}` " ."WHERE " ."`mb_id`=".$dbconn->escape($mb_id); return $dbconn->query_row_assoc($sql); } function db_insert_validation_code($dbconn,$vc_code) { global $Config; $sql="DELETE FROM `{$Config->TableMap['validation_code']}` " ."WHERE " ."`vc_timestamp`<DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$Config->VALIDATION_LIFE_DAYS." DAY) "; $dbconn->real_query($sql,"error.db.deletefail"); $sql="INSERT INTO `{$Config->TableMap['validation_code']}` (" ."`vc_code`, `vc_timestamp`" .") VALUES (" .$vc_code.", " ."UTC_TIMESTAMP()" .") "; $dbconn->real_query($sql,"error.db.insertfail"); return $dbconn->insert_id(); } function db_delete_validation_code($dbconn,$vc_id,$vc_code) { global $Config; $sql="DELETE FROM `{$Config->TableMap['validation_code']}` " ."WHERE " ."`vc_timestamp`<DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$Config->VALIDATION_LIFE_DAYS." DAY) "; $dbconn->real_query($sql,"error.db.deletefail"); $sql="DELETE FROM `{$Config->TableMap['validation_code']}` " ."WHERE " ."`vc_id`=".$dbconn->escape($vc_id)." AND " ."`vc_code`=".$dbconn->escape($vc_code); $dbconn->real_query($sql,"error.db.deletefail"); return $dbconn->affected_rows(); } function db_count_member_email($dbconn,$mb_id,$email=false,$validatedonly=false) { global $Config; $sql="SELECT COUNT(*) " ."FROM `{$Config->TableMap['member_email']}` " ."WHERE " ."`mb_id`=".$dbconn->escape($mb_id)." " .($email?"AND `mb_email`=".$dbconn->escape($email,true):'')." " .($validatedonly?"AND `me_status`='VALIDATED' ":''); return $dbconn->query_value($sql); } ?>