Файл: moduls/groups/index.php
Строк: 173
<?php
/**
* @package Prime Social
* @link http://primesocial.ru
* @copyright Copyright (C) 2016 Prime Social
* @author BoB | http://primesocial.ru/about
*/
require_once('../../core/start.php');
require_once('func.php');
check_auth();
switch ($select) {
default:
head('Guruhlar');
if (empty($_GET['id'])) {
$page = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array(num($_SESSION['user_id'])));
} else {
$page = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array(num($_GET['id'])));
}
echo '<div class="lines">';
if (check() == FALSE) {
echo '[+] <a style="font-size:13px;" href="'.HOME.'/groups/new/">Guruh yaratish</a>';
} else {
echo '<a style="font-size:13px;" href="'.HOME.'/groups/'.my().'/">Mening guruhim</a>';
}
echo ' / <a href="/comm/'.$page['user_id'].'/" style="font-size:13px;"> A`zo guruhlarim</a>';
echo '</div>';
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS."");
if ($all == 0) {
echo DIV_AUT . 'Guruhlar yo`q' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT * FROM ".GROUPS." ORDER BY `id` DESC ");
while($group = $sql -> fetch()) {
$peoples = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? ", array($group['id']));
echo '<table cellspacing="0" cellpadding="0" width="100%" ><tr>
<td class="lines" width="5%">';
echo '' . (empty($group['logo']) ? '<img src="' . HOME . '/style/img/img.png" style="width:45px;height:45px;"/>' : '<img src="' . HOME . '/files/groups/'.$group['logo'] . '" style="width:45px;height:45px;"/>') . '';
echo '</td>';
echo '<td class="lines" style="vertical-align:top;" width="95%" >';
echo '<a href="'.HOME.'/groups/'.$group['id'].'/"><b>' . $group['name'] . '</b></a>
<span style="float:right;font-size:12px;color:#757575;">'.$peoples.' '.icon('group.png',12,11).' </span></br>';
echo '<span style="font-size:13px;color:#757575;">';
echo SubstrMaus(text($group['info']), 100);
echo '</span><br /> ';
echo '</td></tr></table>';
}
}
$array = array('Guruhlar');
nav($array);
break;
case 'view':
$id = abs(num($_GET['id']));
$group = DB::$dbs->queryFetch("SELECT * FROM ".GROUPS." WHERE `id` = ? ",array($id));
if (empty($group)) {
head('Guruh topilmadi');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <b>Guruh topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
head('Guruh: ' . $group['name']);
echo DIV_BLOCK . (empty($group['logo']) ? '<img src="' . HOME . '/style/img/img.png" />' :
'<img style="height:200px;" src="' . HOME . '/files/groups/'.$group['logo'] . '" />') . CLOSE_DIV;
echo DIV_BLOCK;
echo '<b>' . $group['name'] . '</b><br />';
echo '' . text($group['info']) . '<br />';
if ($group['user_id'] != $user['user_id']) {
$sql = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `user_id` = ? ", array($group['id'], $user['user_id']));
if ($sql == FALSE) {
echo '<form action="'.HOME.'/groups/'.$group['id'].'/join/" method="POST"><input type="submit" value="A`zo bo`lish" /></form>';
} else {
echo '<form action="'.HOME.'/groups/'.$group['id'].'/leave/" method="POST"><input type="submit" value="Tark etish" /></form>';
}
}
echo CLOSE_DIV;
echo ($group['user_id'] == $user['user_id'] ? DIV_LI . '<a href="'.HOME.'/groups/'.$group['id'].'/panel/"><b>Guruhni boshqarish</b></a>' . CLOSE_DIV : NULL);
if ($group['private_forum'] == 1) {
if (check_private($group['id']) == TRUE) {
$topics = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_TOPIC." WHERE `group_id` = ? ", array($group['id']));
$posts = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_POST." WHERE `group_id` = ? ", array($group['id']));
echo DIV_LI . ''.icon('forumlar.png').' <a href="'.HOME.'/groups/topics/'.$group['id'].'/">Muhokamalar</a> ['.$topics.'/'.$posts.']' . CLOSE_DIV;
}
} else {
$topics = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_TOPIC." WHERE `group_id` = ? ", array($group['id']));
$posts = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_POST." WHERE `group_id` = ? ", array($group['id']));
echo DIV_LI . ''.icon('forumlar.png').' <a href="'.HOME.'/groups/topics/'.$group['id'].'/">Muhokamalar</a> ['.$topics.'/'.$posts.']' . CLOSE_DIV;
}
$peoples = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? ", array($group['id']));
echo DIV_LI . ''.icon('users.png').' <a href="'.HOME.'/groups/'.$group['id'].'/peoples/">Ishtrokchilar</a> ['.$peoples.']' . CLOSE_DIV;
$admins = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `level` > ? ", array($group['id'], 0));
echo DIV_LI . ''.icon('adm.png').' <a href="'.HOME.'/groups/'.$group['id'].'/admin/">Ma`muriyat</a> ['.$admins.']' . CLOSE_DIV;
$array = array('Guruh');
nav($array);
require_once('../../core/stop.php');
break;
case 'admin':
$id = abs(num($_GET['id']));
$group = DB::$dbs->queryFetch("SELECT * FROM ".GROUPS." WHERE `id` = ? ",array($id));
if (empty($group)) {
head('Guruh topilmadi');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <b>Guruh topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
head('Ma`muriyat');
$n = new Navigator($all,10,'id='.$group['id']);
$sql = DB::$dbs->query("SELECT * FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `level` > ? ORDER BY `id` DESC LIMIT {$n->start()}, 10", array($group['id'], 0));
while($ank = $sql -> fetch()) {
echo DIV_LI . userLink($ank['user_id']) . ' [<b>' . group_level($ank['level']) . '</b>]' . CLOSE_DIV;
}
echo $n->navi();
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <a href="'.HOME.'/groups/'.$group['id'].'/">'.$group['name'].'</a> / <b>Ma`muriyat</b>' . CLOSE_DIV;
break;
case 'peoples':
$id = abs(num($_GET['id']));
$group = DB::$dbs->queryFetch("SELECT * FROM ".GROUPS." WHERE `id` = ? ",array($id));
if (empty($group)) {
head('Guruh topilmadi');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <b>Guruh topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
head('Guruh ishtrokchilari');
$n = new Navigator($all,10,'id='.$group['id']);
$sql = DB::$dbs->query("SELECT * FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, 10", array($group['id']));
while($ank = $sql -> fetch()) {
echo DIV_LI . userLink($ank['user_id']) . ' [<b>' . group_level($ank['level']) . '</b>]' . CLOSE_DIV;
}
echo $n->navi();
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <a href="'.HOME.'/groups/'.$group['id'].'/">'.$group['name'].'</a> / <b>Guruh ishtrokchilari</b>' . CLOSE_DIV;
break;
case 'join':
$id = abs(num($_GET['id']));
$group = DB::$dbs->queryFetch("SELECT * FROM ".GROUPS." WHERE `id` = ? ",array($id));
if (empty($group)) {
head('Guruh topilmadi');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <b>Guruh topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
$sql = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `user_id` = ? ", array($group['id'], $user['user_id']));
if ($sql == FALSE) {
DB::$dbs->query("INSERT INTO ".GROUPS_PEOPLES." (`group_id`, `user_id`, `level`) VALUES (?, ?, ?)", array($group['id'], $user['user_id'], 0));
header("Location: ".HOME."/groups/".$group['id']."/");
} else {
head('Siz ushbu guruhga a`zo bo`lgansiz');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <a href="'.HOME.'/groups/'.$group['id'].'/">'.$group['name'].'</a> / <b>Siz ushbu guruhga a`zo bo`lgansiz</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
break;
case 'leave':
$id = abs(num($_GET['id']));
$group = DB::$dbs->queryFetch("SELECT * FROM ".GROUPS." WHERE `id` = ? ",array($id));
if (empty($group)) {
head('Guruh topilmadi');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <b>Guruh topilmadi</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
if ($group['user_id'] == $user['user_id']) {
head('Diqqat!');
echo '<div class="white">Siz guruhni tark etolmaysiz, chunki siz ushbu guruhni yaratuvchisiz</div>';
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <a href="'.HOME.'/groups/'.$group['id'].'/">'.$group['name'].'</a> / <b>Siz guruhni tark etolmaysiz, chunki siz ushbu guruhni yaratuvchisiz</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
$sql = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `user_id` = ? ", array($group['id'], $user['user_id']));
if ($sql == TRUE) {
DB::$dbs->query("DELETE FROM ".GROUPS_PEOPLES." WHERE `group_id` = ? && `user_id` = ? ", array($group['id'], $user['user_id']));
header("Location: ".HOME."/groups/".$group['id']."/");
} else {
head('Siz ushbu guruh ishtrokchisi emassiz');
echo DIV_ERROR . 'Xatolik!' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups/">Guruh</a> / <a href="'.HOME.'/groups/'.$group['id'].'/">'.$group['name'].'</a> / <b>Siz ushbu guruh ishtrokchisi emassiz</b>' . CLOSE_DIV;
require_once('../../core/stop.php');
exit();
}
break;
case 'new':
head('Guruh yaratish');
if (!empty($_POST['add'])) {
$name2 = html($_POST['name']);
$info = html($_POST['info']);
if (!empty($_FILES['file']['name'])) {
$name = $_FILES['file']['name']; # Fayl nomi
$ext = strtolower(strrchr($name, '.')); # Fayl formati
$par = getimagesize($_FILES['file']['tmp_name']); # Rasm shakli
$size = $_FILES['file']['size']; # Fayl hajmi
$time = time();
$file = $time.$ext;
$pictures = array('.jpg', '.jpeg', '.gif', '.png'); # Mumkun bo`lgan formatlar
if ($size > (1048576 * $config['max_upload_group'])) {
$err .= 'Foto hajmi belgilangan miqdordan oshmoqda. [Max. '.$config['max_upload_group'].'Mb.]<br />';
}
if (preg_match('/.php/i', $name) || preg_match('/.pl/i', $name) || $name == '.htaccess' || !in_array($ext, $pictures)) {
$err .= 'Fayl shaklida xatolik.<br />';
}
}
if (empty($name2)) {
$err .= 'Guruh nomini to`ldiring<br />';
}
if (empty($info)) {
$err .= 'Guruh ta`rifini to`ldiring<br />';
}
if (empty($err)) {
if (empty($ext)) {
$file = 0;
}
copy($_FILES['file']['tmp_name'], '../../files/groups/'.$file); # Original tarzda yuklaymiz
img_resize('../../files/groups/'.$file, '../../files/groups/mini_'.$file, $config['mini_logo_par'][0], $config['mini_logo_par'][1]); # Mini
DB::$dbs->query("INSERT INTO ".GROUPS." (`name`, `info`, `logo`, `user_id`, `time`, `peoples`) VALUES (?, ?, ?, ?, ?, ?)", array($name2, $info, $file, $user['user_id'], time(), 1));
$lastid = DB::$dbs->lastInsertId();
DB::$dbs->query("INSERT INTO ".GROUPS_PEOPLES." (`group_id`, `user_id`, `level`) VALUES (?, ?, ?)", array($lastid, $user['user_id'], 2));
header("Location: ".HOME."/groups/".$lastid);
} else {
echo DIV_ERROR . $err . CLOSE_DIV;
}
}
echo DIV_AUT;
echo '<form action="#" method="POST" enctype="multipart/form-data">';
echo '<b>Guruh nomi:</b> [max. 100]<br /><input type="text" name="name" /><br /><br />';
echo '<b>Ta`rif:</b> [max. 250]<br /><textarea name="info"></textarea><br /><br />';
echo '<b>Logotip:</b> [max. '.$config['max_upload_group'].'mb., jpg, gif, png]<br /><input type="file" name="file"/><br /><br />';
echo '<input type="submit" name="add" value="Yaratish" /></form>';
echo CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/groups">Guruh</a> / <b>Guruh yaratish</b>' . CLOSE_DIV;
break;
}
require_once('../../core/stop.php');
?>