Add new methods and bugfix. Add private messages.
This commit is contained in:
1 parent
073defb76d
commit
fc8c5b677c
3 files changed
+93
-9
No files matched your search
@@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+59
-2
@@ -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(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+33
-2
@@ -28,6 +28,36 @@ if($User->is_user()):
|
||||
<p>Добро пожаловать, <?=$user_fields['name'];?>! <a href="example.php?act=logout">Выход</a></p>
|
||||
<pre><?=print_r($user_fields, true);?></pre>
|
||||
<?php
|
||||
echo 'Входящих писем: ('.$User->getMailCount($User->id, 'to', 'Y').'/'.$User->getMailCount($User->id, 'to').')<br>';
|
||||
echo 'Исходящих писем: '.$User->getMailCount($User->id, 'from').'<br>';
|
||||
echo 'Мои сообщения:<br>';
|
||||
?>
|
||||
<table border="1px" style="border-collapse: collapse;">
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td>От кого</td>
|
||||
<td>Сообщение</td>
|
||||
<td>Не прочитано</td>
|
||||
<td>Время</td>
|
||||
</tr>
|
||||
<?php
|
||||
$mail = $User->getMail();
|
||||
foreach($mail as $item):
|
||||
$user_fields = $User->getFields($item['message_from']);
|
||||
?>
|
||||
<tr>
|
||||
<td><?=$item['id'];?></td>
|
||||
<td><?=$user_fields['name'];?></td>
|
||||
<td><?=$item['message'];?></td>
|
||||
<td><?=$item['new'];?></td>
|
||||
<td><?=date("d.m.Y H:i:s", $item['time']);?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
else:
|
||||
?>
|
||||
<form action="example.php" method="POST">
|
||||
@@ -43,10 +73,11 @@ endif;
|
||||
echo '<pre>'.session_id().'</pre>';
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Регистрация
|
||||
*/
|
||||
|
||||
/*
|
||||
$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';
|
||||
}
|
||||
}*/
|
||||
Reference in new issue
Block a user