diff --git a/core/lib/DataBase.class.php b/core/lib/DataBase.class.php index e37ecb0..0564054 100644 --- a/core/lib/DataBase.class.php +++ b/core/lib/DataBase.class.php @@ -159,9 +159,7 @@ class DataBase { return false; } } - - - + public function getRow($table, $sql = '', $params = []) { $result = $this->query('SELECT * FROM `'.$table.'` '.$sql.' LIMIT 1', $params); @@ -172,6 +170,4 @@ class DataBase { } } - - } \ No newline at end of file diff --git a/core/lib/User.class.php b/core/lib/User.class.php index d086b93..9e82a51 100644 --- a/core/lib/User.class.php +++ b/core/lib/User.class.php @@ -9,9 +9,11 @@ class User { public $id; public $users_table; + public $mail_table; - public function __construct($users_table = 'users') { + public function __construct($users_table = 'users', $mail_table = 'messages') { $this->users_table = $users_table; + $this->mail_table = $mail_table; } // Получение всех полей пользователя @@ -120,6 +122,61 @@ class User { session_unset(); session_destroy(); return true; - } + } + + // Получает количество входящих писем пользователя + public function getMailCount($user_id = '', $type = 'to', $new = ''){ + global $DataBase; + + if($user_id==''){ + $user_id = $this->id; + } + + if($type == 'to'){ + $message_type = 'message_to'; + } else { + $message_type = 'message_from'; + } + + if($new=='Y'){ + $arFilter = array($message_type => $user_id, 'new' => 'Y'); + } else{ + $arFilter = array($message_type => $user_id); + } + + $result = $DataBase->getItems($this->mail_table, $arFilter); + + if($result){ + return count($result); + } else { + return 0; + } + } + + public function getMail($user_id = '', $type = 'to'){ + global $DataBase; + + if($user_id==''){ + $user_id = $this->id; + } + + if($type == 'to'){ + $message_type = 'message_to'; + } else { + $message_type = 'message_from'; + } + + $result = $DataBase->getItems($this->mail_table, array($message_type => $user_id), array('id'=>'desc')); + + if($result){ + return $result; + } else { + return false; + } + } + + public function getNewMail(){ + + } } \ No newline at end of file diff --git a/example.php b/example.php index 5579495..d0c1aea 100644 --- a/example.php +++ b/example.php @@ -28,6 +28,36 @@ if($User->is_user()):

Добро пожаловать, ! Выход

getMailCount($User->id, 'to', 'Y').'/'.$User->getMailCount($User->id, 'to').')
'; +echo 'Исходящих писем: '.$User->getMailCount($User->id, 'from').'
'; +echo 'Мои сообщения:
'; +?> + + + + + + + + +getMail(); +foreach($mail as $item): +$user_fields = $User->getFields($item['message_from']); +?> + + + + + + + + + +
IDОт когоСообщениеНе прочитаноВремя
+
@@ -43,10 +73,11 @@ endif; echo '
'.session_id().'
'; + /* Регистрация */ - +/* $new_user['login'] = 'demo'; $new_user['pass'] = '12345'; $new_user['access_level'] = 'user'; @@ -57,4 +88,4 @@ if(!$User->user_exists($new_user['login'])) { echo 'Registration Success'; } else { echo 'User already exists'; -} \ No newline at end of file +}*/ \ No newline at end of file