protected function addUser($email, $password, $params = [], &$use_email_activation)
    {
        $return['error'] = true;

        $query = "INSERT INTO {$this->config->table_users} (isactive) VALUES (0)";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute()) {
            $return['message'] = $this->__lang("system_error") . " #03";
            return $return;
        }

        $uid = $this->dbh->lastInsertId("{$this->config->table_users}_id_seq");
        $email = htmlentities(strtolower($email));

        if ($use_email_activation) {
            $addRequest = $this->addRequest($uid, $email, "activation", $use_email_activation);

            if ($addRequest['error'] == 1) {
                $query = "DELETE FROM {$this->config->table_users} WHERE id = :id";
                $query_prepared = $this->dbh->prepare($query);
                $query_params = [
                    'id' => $uid
                ];
                $query_prepared->execute($query_params);

                $return['message'] = $addRequest['message'];
                return $return;
            }

            $isactive = 0;
        } else {
            $isactive = 1;
        }

        $password = $this->getHash($password);

        if (is_array($params)&& count($params) > 0) {
            $customParamsQueryArray = [];

            foreach($params as $paramKey => $paramValue) {
                $customParamsQueryArray[] = ['value' => $paramKey . ' = ?'];
            }

            $setParams = ', ' . implode(', ', array_map(function ($entry) {
                return $entry['value'];
            }, $customParamsQueryArray));
        } else { $setParams = ''; }

        $query = "UPDATE {$this->config->table_users} SET email = ?, password = ?, isactive = ? {$setParams} WHERE id = ?";
        $query_prepared = $this->dbh->prepare($query);

        $bindParams = array_values(array_merge([$email, $password, $isactive], $params, [$uid]));

        if (!$query_prepared->execute($bindParams)) {
            $query = "DELETE FROM {$this->config->table_users} WHERE id = ?";
            $query_prepared = $this->dbh->prepare($query);

            $query_prepared->execute([$uid]);
            $return['message'] = $this->__lang("system_error") . " #04";

            return $return;
        }

        $return['error'] = false;
        return $return;
    }
protected function addUser($email, $password, $params = [], &$use_email_activation)
    {
        $return['error'] = true;

        $query = "INSERT INTO {$this->config->table_users} (isactive) VALUES (0)";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute()) {
            $return['message'] = $this->__lang("system_error") . " #03";
            return $return;
        }

        $uid = $this->dbh->lastInsertId("{$this->config->table_users}_id_seq");
        $email = htmlentities(strtolower($email));

        if ($use_email_activation) {
            $addRequest = $this->addRequest($uid, $email, "activation", $use_email_activation);

            if ($addRequest['error'] == 1) {
                $query = "DELETE FROM {$this->config->table_users} WHERE id = :id";
                $query_prepared = $this->dbh->prepare($query);
                $query_params = [
                    'id' => $uid
                ];
                $query_prepared->execute($query_params);

                $return['message'] = $addRequest['message'];
                return $return;
            }

            $isactive = 0;
        } else {
            $isactive = 1;
        }

        $password = $this->getHash($password);

        if (is_array($params)&& count($params) > 0) {
            $customParamsQueryArray = [];

            foreach($params as $paramKey => $paramValue) {
                $customParamsQueryArray[] = ['value' => $paramKey . ' = ?'];
            }

            $setParams = ', ' . implode(', ', array_map(function ($entry) {
                return $entry['value'];
            }, $customParamsQueryArray));
        } else { $setParams = ''; }

        $query = "UPDATE {$this->config->table_users} SET email = ?, password = ?, isactive = ? {$setParams} WHERE id = ?";
        $query_prepared = $this->dbh->prepare($query);

        $bindParams = array_values(array_merge([$email, $password, $isactive], $params, [$uid]));

        if (!$query_prepared->execute($bindParams)) {
            $query = "DELETE FROM {$this->config->table_users} WHERE id = ?";
            $query_prepared = $this->dbh->prepare($query);

            $query_prepared->execute([$uid]);
            $return['message'] = $this->__lang("system_error") . " #04";

            return $return;
        }

        $return['error'] = false;
        return $return;
    }
protected function addUser ( $ email , $ password , $ params = [ ] , & $ use_email_activation ) { $ return [ 'error' ] = true ; $ query = "INSERT INTO {$this->config->table_users} (isactive) VALUES (0)" ; $ query_prepared = $ this -> dbh -> prepare ( $ query ) ; if ( ! $ query_prepared -> execute ( ) ) { $ return [ 'message' ] = $ this -> __lang ( "system_error" ) . " #03" ; return $ return ; } $ uid = $ this -> dbh -> lastInsertId ( "{$this->config->table_users}_id_seq" ) ; $ email = htmlentities ( strtolower ( $ email ) ) ; if ( $ use_email_activation ) { $ addRequest = $ this -> addRequest ( $ uid , $ email , "activation" , $ use_email_activation ) ; if ( $ addRequest [ 'error' ] == 1 ) { $ query = "DELETE FROM {$this->config->table_users} WHERE id = :id" ; $ query_prepared = $ this -> dbh -> prepare ( $ query ) ; $ query_params = [ 'id' => $ uid ] ; $ query_prepared -> execute ( $ query_params ) ; $ return [ 'message' ] = $ addRequest [ 'message' ] ; return $ return ; } $ isactive = 0 ; } else { $ isactive = 1 ; } $ password = $ this -> getHash ( $ password ) ; if ( is_array ( $ params ) && count ( $ params ) > 0 ) { $ customParamsQueryArray = [ ] ; foreach ( $ params as $ paramKey => $ paramValue ) { $ customParamsQueryArray [ ] = [ 'value' => $ paramKey . ' = ?' ] ; } $ setParams = ', ' . implode ( ', ' , array_map ( function ( $ entry ) { return $ entry [ 'value' ] ; } , $ customParamsQueryArray ) ) ; } else { $ setParams = '' ; } $ query = "UPDATE {$this->config->table_users} SET email = ?, password = ?, isactive = ? {$setParams} WHERE id = ?" ; $ query_prepared = $ this -> dbh -> prepare ( $ query ) ; $ bindParams = array_values ( array_merge ( [ $ email , $ password , $ isactive ] , $ params , [ $ uid ] ) ) ; if ( ! $ query_prepared -> execute ( $ bindParams ) ) { $ query = "DELETE FROM {$this->config->table_users} WHERE id = ?" ; $ query_prepared = $ this -> dbh -> prepare ( $ query ) ; $ query_prepared -> execute ( [ $ uid ] ) ; $ return [ 'message' ] = $ this -> __lang ( "system_error" ) . " #04" ; return $ return ; } $ return [ 'error' ] = false ; return $ return ; }
Adds a new user to database
@param string $email      -- email
@param string $password   -- password
@param array $params      -- additional params
@param boolean $use_email_activation  -- activate email confirm or not
@return int $uid
Adds a new user to database