Файл: comm/class/func.class.php
Строк: 163
<?php
/** Модуль Сообщества
* @author Kratos
* @email wssy@mail.ua
* ICQ: 845348
* @version 1.0.0
*/
//Основной функционал
class func{
//Вывод категорий сообществ
static function showCommCat(){
$sql = "SELECT `id`,`name`,`cat`,`desc` FROM `comm` WHERE `type`= 1 ORDER by `id`";
$res = db::query($sql) or die(mysqli_error());
return $res;
}
//вывод инфы которую редактируют
static function showCommEditCat($id){
$sql = "SELECT `id`,`name`,`cat`,`desc` FROM `comm` WHERE `type`= 1 AND `id`=$id";
$res = db::query($sql) or die(mysqli_error());
return $res;
}
//Редактирования категорий
static function editCommCat($id,$name,$desc){
$sql = "UPDATE `comm` SET `name`='$name',`desc`='$desc' WHERE `id`=$id";
$res = db::query($sql) or die(mysqli_error());
return true;
}
// Новая категория
static function newCommCat($name,$desc){
$sql = "INSERT INTO `comm` SET
`name` = '$name',
`type` = '1',
`desc` = '$desc'";
$res = db::query($sql) or die(mysqli_error());
return true;
}
// Тип запроса ид
static function showCommType($id){
$sql = "SELECT `id`,`name`,`cat`,`desc`,`type` FROM `comm` WHERE `id`= $id";
$res = db::query($sql) or die(mysqli_error());
$row = mysqli_fetch_assoc($res);
return $row['type'];
}
static function deleteComm($id){
$sql = db::query("SELECT `id` FROM `comm` WHERE `cat`= $id");
while($res = mysqli_fetch_assoc($sql)):
//Удаления логотипов
if(file_exists('../files/comm/logo/' . $res['id'] . '_logo.png')){
unlink('../files/comm/logo/' . $res['id'] . '_logo.png');
unlink('../files/comm/logo/' . $res['id'] . '.png');
}
//Удаления юзеров
db::query("DELETE FROM `comm_users` WHERE `sid`= ".$res['id']."");
//Удаления новостей
db::query("DELETE FROM `comm_news` WHERE `id_soo`= ".$res['id']."");
//Удаления тем
db::query("DELETE FROM `comm_forum` WHERE `sid`= ".$res['id']." AND `type` = 't'");
//Удаления сообщенй в темах
db::query("DELETE FROM `comm_forum` WHERE `cat` = ".$res['id']."");
//Удаления сообществ
db::query("DELETE FROM `comm` WHERE `id`= $id LIMIT 1");
endwhile;
// Удаления категорий
db::query("DELETE FROM `comm` WHERE `cat`= $id");
return true;
}
static function deleteUserComm($id){
//Удаления логотипов
if(file_exists('../files/comm/logo/' . $id . '_logo.png')){
unlink('../files/comm/logo/' . $id . '_logo.png');
unlink('../files/comm/logo/' . $id . '.png');
}
//Удаления юзеров
db::query("DELETE FROM `comm_users` WHERE `sid`= ".$id."");
//Удаления новостей
db::query("DELETE FROM `comm_news` WHERE `id_soo`= ".$id."");
//Удаления тем
db::query("DELETE FROM `comm_forum` WHERE `sid`= ".$id."");
//Удаления сообщенй в темах
db::query("DELETE FROM `comm_forum` WHERE `cat` = ".$id."");
db::query("DELETE FROM `comm` WHERE `id`= $id");
return true;
}
// Создания сообщества
static function newCommSoo($id_group,$name,$desc,$access,$user_id){
$sql= array();
$sql = db::query("INSERT INTO `comm` SET
`cat` = '$id_group',
`type` = '2',
`name` = '$name',
`desc` = '$desc',
`user_id` = '$user_id',
`time` = '".time()."',
`access` = '$access'");
$soo_id = mysqli_insert_id();
$sql = db::query("INSERT INTO `comm_users` SET
`sid`='$soo_id',
`user_id`='$user_id',
`rights`='9'
");
if($sql){
return $soo_id;
}
else {
return false;
}
}
// счетчик сообществ в раздели
static function countComm($id){
$req = db::query("SELECT COUNT(*) FROM `comm` WHERE `type`= 2 AND `cat` = $id");
$total = db::result($req, 0);
return $total;
}
// Проверяем админа сообщества
static function rightsUserComm($id,$user){
$sql = "SELECT `rights` FROM `comm_users` WHERE `sid` = $id AND `user_id` = $user";
$res = db::query($sql) or die(mysqli_error());
$row = mysqli_fetch_assoc($res);
if($res){
return $row['rights'];
}else{
return false;
}
}
// Вывод инфу сообщества юзера (Доделать!!!!!!!!!!!!!!!!)
static function showUserComm($id){
$sql = "SELECT `id`,`name`,`cat`,`type`,`desc`,`user_id`,`access`
FROM `comm` WHERE `type` = 2 AND `id` = $id";
$res = db::query($sql) or die(mysqli_error());
$row = mysqli_fetch_assoc($res);
return $row;
}
// Редактируем настройки сообщества юзера
static function editUserComm($id_soo,$name,$desc,$access){
$sql = "UPDATE `comm` SET `name`='$name',`desc`='$desc',`access` = '$access' WHERE `id`=$id_soo";
$res = db::query($sql) or die(mysqli_error());
return true;
}
// Проверка состоит ли юзер в сообществи
static function UserComm($id_soo,$user){
$sql = db::query("SELECT COUNT(*) FROM `comm_users` WHERE `sid` = $id_soo AND `user_id` = $user");
$res = db::result($sql, 0);
return $res;
}
// вступаем а сообщество
static function usersInComm($id,$user_id){
$sql = db::query("INSERT INTO `comm_users` SET
`sid`='$id',
`user_id`='$user_id',
`rights`='0'"
) or die(mysqli_error());
if($sql)
return true;
}
// Сколько юзеров соостоит в сообществе
static function totalUsersComm($id,$type=null){
switch($type){
case'ban':
$sql = db::query("SELECT COUNT(*) FROM `comm_users` WHERE `sid` = $id AND `ban_time` >= ".time()."");
$total_usersban = db::result($sql, 0);
return $total_usersban;
break;
default:
$sql = db::query("SELECT COUNT(*) FROM `comm_users` WHERE `sid` = $id AND `ban_time` < ".time()."");
$total_users = db::result($sql, 0);
return $total_users;
break;
}
}
// выборка пользователей
static function showUsers($id_soo,$start,$kmess,$type = null){
switch($type){
case'ban':
$res = db::query("SELECT * FROM `comm_users` WHERE `sid` = $id_soo
AND `ban_time` >= ".time()." ORDER BY `id` DESC LIMIT $start, $kmess ");
return $res;
break;
default:
$res = db::query("SELECT * FROM `comm_users` WHERE `sid` = $id_soo AND `ban_time` < ".time()."
ORDER BY `id` DESC LIMIT $start, $kmess ");
return $res;
break;
}
}
// вывод информации пользователей которые участвуют в сообществе
static function showUsersInfo($users){
$sql = "SELECT * FROM `users` WHERE `id` = " . $users . "";
$res = db::query($sql) or die(mysqli_error());
$row = mysqli_fetch_assoc($res);
return $row;
}
//Удаления участника
static function delUsers($id_soo,$users){
$sql = "DELETE FROM `comm_users` WHERE `user_id` = $users AND `sid` = $id_soo LIMIT 1";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
}
// редактирования участника
static function editUsers($id_soo,$id_user,$rights = null,$type = null,$time_v = null){
switch($type){
case'delban':
$sql = "UPDATE `comm_users` SET `ban_time`='0' WHERE `user_id` = $id_user AND `sid` = $id_soo";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
break;
case'ban':
$sql = "UPDATE `comm_users` SET `ban_time`= $time_v WHERE `user_id` = $id_user AND `sid` = $id_soo";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
break;
case'up':
$sql = "UPDATE `comm_users` SET `rights`='$rights' WHERE `user_id`=$id_user AND `sid` = $id_soo";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
break;
default:
$sql = "SELECT `rights`,`ban` FROM `comm_users` WHERE `sid` = $id_soo AND user_id =$id_user";
$res = db::query($sql) or die(mysqli_error());
if ($res)
return $row = mysqli_fetch_assoc($res);
break;
}
}
//Вывод новостей
static function showNews($id_soo, $start, $kmess){
$sql = "SELECT `id`,`title`,`text`,`author`,`time` FROM `comm_news` WHERE `id_soo` = $id_soo ORDER by `time` DESC LIMIT $start,$kmess ";
$res = db::query($sql) or die(mysqli_error());
if ($res)
return $res;
break;
}
//Счетчик новостей!
static function countNews($id_soo){
$total = db::result(db::query("SELECT count(*) FROM `comm_news` WHERE `id_soo` = $id_soo"),0);
return $total;
}
//Добавляем новости сообщества
static function newsInComm($id_soo,$text,$name,$author){
$sql = db::query("INSERT INTO `comm_news` SET
`id_soo`='$id_soo',
`author`='$author',
`text`='$text',
`title`='$name',
`time`=".time().""
) or die(mysqli_error());
if($sql)
return true;
}
//Удаления новостей
static function deleteNews($idn){
$sql = "DELETE FROM `comm_news` WHERE `id` = $idn LIMIT 1";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
}
//
static function newsUpComm($text, $name,$idn){
$sql = "UPDATE `comm_news` SET `title`='$name',`text`='$text' WHERE `id`=$idn";
$res = db::query($sql) or die(mysqli_error());
if($res)
return true;
}
//
static function banstat($id_soo,$user_id){
$row = mysqli_fetch_assoc(db::query("SELECT * FROM `comm_users` WHERE `user_id` = $user_id AND `sid` = $id_soo AND `ban_time` >= ".time().""));
return $row['ban_time'];
}
}
?>