EIOS/filesdel.php

301 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
error_reporting(0);
ini_set('memory_limit', '-1');
header('Content-Type: text/html; charset=utf-8');
date_default_timezone_set('Europe/Moscow');
$page=''; if(isset($_GET['page'])) $page=$_GET['page'];
if(isset($_SESSION['user'])&&($_SESSION['user']['id']==1||$_SESSION['user']['id']==9277)){}else{ exit(); }
if($page=='show_pm'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/pm/';
$p=0; if(isset($_GET['p'])) $p=(int)$_GET['p'];
$kol = 50;
$sql = 'SELECT p.data_c,p.message,p.file,u.fio FROM acs_pm as p, acs_users as u WHERE u.id=p.from_user AND (message NOT LIKE "%[ОПОВЕЩЕНИЕ]%" AND message NOT LIKE "%[ГРУППА]%" AND message NOT LIKE "%За вами в НБ%" AND message NOT LIKE "%На сайте eios.mkgtu.ru%" AND message NOT LIKE "%[ПРЕПОДАВАТЕЛЯМ]%") ORDER BY p.data_c DESC LIMIT '.($p*$kol).','.$kol;
$rez = $DB->QUR_SEL($sql);
$imgs = array('jpg','jpeg','png','bmp','JPG','JPEG','PNG','BMP');
echo '<table>';
if ($rez[0]) {
echo '<tr><td>Дата</td><td>Кто послал</td><td>Сообщение</td><td>Файл</td></tr>';
foreach($rez as $key => $val)if($key) {
echo '<tr>';
echo '<td>' . date('H:i d.m.Y',$val['data_c']) . '</td>';
echo '<td>' . $val['fio'] . '</td>';
if(mb_strlen($val['message'])>80) {
echo '<td><a href="#" title="' . stripslashes($val['message']) . '">' . mb_substr($val['message'], 0, 80) . '...</a></td>';
}else{
echo '<td>' . $val['message'] . '</td>';
}
if($val['file']!='') {
$fs = filesize_format(filesize($val['file']) );
$fna = pathinfo($val['file'],PATHINFO_FILENAME);
$ext = pathinfo($val['file'],PATHINFO_EXTENSION );
if(in_array($ext,$imgs)){
echo '<td><a href="/' . $val['file'] . '" target="_blank"><img src="/' . $val['file'] . '" width="100" height="100" /></a> ['.$fs.']</td>';
}else {
echo '<td><a href="/' . $val['file'] . '" target="_blank">' . $fna . '</a> ['.$fs.']</td>';
}
}else{
echo '<td>нет</td>';
}
echo '</tr>';
}
echo '<tr><td colspan="4" style="text-align: center;">';
for($i=1; $i<=100; $i++){
echo '<a href="/filesdel.php?page=show_pm&p='.$i.'">['.$i.']</a> ';
}
echo '</td></tr>';
}
echo '</table>';
echo '<style>table{border-collapse: collapse; border:1px solid gray;}td{ border:1px solid gray; padding:2px;}</style>';
//echo $sql . '<pre>' . print_r($rez, 1) . '</pre>';
}
if($page=='compressfiles'){//Сжатие файлов опасно!!! несколько раз сжимает файлы(((
$dir = 'upload/pm/';
$filesPM = scandir($dir);//echo '<pre>'.print_r($filesPM,1).'</pre>';
$i=0;
foreach($filesPM as $key => $pm)if($pm!='.'&&$pm!='..'){//обходим папки каждого пользователя
$files = scandir($dir.$pm);
foreach($files as $key1 => $file)if($file!='.'&&$file!='..'){//обходим файлы пользователя
$filename = $dir.$pm.'/'.$file;
//$id = explode('/',$pm);
//echo $id[0].':'.$filename.'<br>';
$ext = pathinfo($filename, PATHINFO_EXTENSION); //echo '[ext='.$ext.']'.$filename.'<br>';
if($ext=='jpg'||$ext=='jpeg'||$ext=='gif'||$ext=='png'||$ext=='bmp'){
$datafile = filemtime($filename);
$filesize = filesize($filename);
if($filesize > 1500000){
exec ('convert '.$_SERVER['DOCUMENT_ROOT'].'/'.$filename.' -auto-orient -strip -quality 50 '.$_SERVER['DOCUMENT_ROOT'].'/'.$filename.'');
touch($filename,$datafile,$datafile);//установим время исходного файла
$filesize1 = filesize($filename);
$i++;
echo $filesize.' - '.$filename;//.'-'.$filesize1.'<br>';
}
}
}
//echo '<pre>'.print_r($files,1).'</pre>';
if($i==10) break;
}
}
if($page=='showfiles'){//Просмотр файлов
$start=0; if(isset($_GET['start'])) $start=$_GET['start'];
$kol=400; if(isset($_GET['kol'])) $kol=$_GET['kol'];
$data=mktime(0,0,0,date('m'),date('d')-3,date('Y')); if(isset($_GET['data'])) { $data1=explode('.',$_GET['data']); $data=mktime(0,0,0,$data1[1],$data1[0],$data1[2]);}
$ext1='img'; if(isset($_GET['ext'])) $ext1=$_GET['ext'];
$dir = 'upload/pm/';
$filesPM = scandir($dir);//echo '<pre>'.print_r($filesPM,1).'</pre>';
$s=0; $i=0;
foreach($filesPM as $key => $pm)if($pm!='.'&&$pm!='..'){//обходим папки каждого пользователя
$files = scandir($dir.$pm);
foreach($files as $key1 => $file)if($file!='.'&&$file!='..'){//обходим файлы пользователя
$fileName = $dir.$pm.'/'.$file;
$datafile = filemtime($fileName);
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
if($ext1=='img'){
if($ext=='jpg'||$ext=='jpeg'||$ext=='gif'||$ext=='png'||$ext=='bmp'){
if($s>=$start){
if($data>=$datafile){
echo '<a href="/'.$fileName.'" target="_blank"><img src="/'.$fileName.'" style="width:80px;height:80px;margin:2px;" alt="'.$fileName.'"></a>';
//echo $i.'. [ext='.$ext.'] '.$fileName.'<br>';
$i++;
}
}
$s++;
}
}
if($ext1==$ext){
if($s>=$start){
if($data>=$datafile){
if($ext1=='mp4'){
echo '<video width="240" height="140" controls="controls"><source src="/'.$fileName.'" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\'></video>';
}else{
echo '<a href="/'.$fileName.'" target="_blank">'.$fileName.'</a><br>';
}
$i++;
}
}
$s++;
}
if($i>=$kol) break(2);
}
//echo '<pre>'.print_r($files,1).'</pre>';
}
if($start>0) echo '<a href="filesdel.php?page=showfiles&ext='.$ext1.'&start='.($start-$kol).'">Назад</a>';
echo '<a href="filesdel.php?page=showfiles&ext='.$ext1.'&start='.($start+$kol).'">Вперед</a>';
}
if($page=='delfiles'){//УДАЛЕНИЕ файлов из личной переписки
exit();
$data = mktime(0,0,0,date('m'),date('d')-30,date('Y'));//последние 30 дней храним!
$dir = 'upload/pm/';
$filesPM = scandir($dir);//echo '<pre>'.print_r($filesPM,1).'</pre>';
$i=0;
foreach($filesPM as $key => $pm)if($pm!='.'&&$pm!='..'){//обходим папки каждого пользователя
$files = scandir($dir.$pm);
foreach($files as $key1 => $file)if($file!='.'&&$file!='..'){//обходим файлы пользователя
$datafile = filemtime($dir.$pm.'/'.$file);
//echo date('H:i:s d.m.Y',$data).'='.date('H:i:s d.m.Y',$datafile).' - ';
if($datafile<=$data) {
//echo 'Удаляем<br>';
unlink($dir.$pm.'/'.$file);
}else {
//echo 'не удаляем<br>';
}
}
//echo '<pre>'.print_r($files,1).'</pre>';
//$i++;if($i==10) break;
}
}
//перемещение файлов в tmp выше корня которых нет в базе
if($page=='checkfile_lections'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/lections/';
scandir_upload($dir,'acs_lections','file');
/*$files = scandir($dir);
$out = '<table>';
foreach($files as $key => $file)if($file!='.'&&$file!='..'){
$status = ''; $tmp=array();
$sql = 'SELECT id,data_c FROM acs_lections WHERE file="'.$file.'" ORDER BY data_c DESC';
$rez = $DB->QUR_SEL($sql);
if($rez[0]) {
foreach($rez as $k => $v)if($k){
$tmp[] = date('H:i d.m.Y',$v['data_c']).'; ';
}
}
if(count($tmp)) {
$status = implode(';',$tmp);
$style='';
}else{
$style='color:red;';
movefile($dir.$file,'/home/admin/web/eios.mkgtu.ru/tmp/');
}
$out .= '<tr>';
$out .= '<td style="'.$style.'">'.$key.'</td>';
$out .= '<td style="'.$style.'">'.$status.'</td>';
$out .= '<td><a href="/'.$dir.$file.'" target="_blank" style="'.$style.'">'.$file.'</a></td>';
$out .= '</tr>';
}
$out .= '</table>';
if(isset($_GET['out'])) echo $out;
//echo '<pre>'.print_r($files,1).'</pre>';*/
}
if($page=='checkfile_controln'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/controln/';
scandir_upload($dir,'acs_controln','file');
}
if($page=='checkfile_practic'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/practic/';
scandir_upload($dir,'acs_practich','file');
}
if($page=='checkfile_praktika'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/praktika/';
scandir_upload($dir,'acs_praktika','file');
}
if($page=='checkfile_workprogram'){
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/workprogram/';
scandir_upload($dir,'acs_workprogram','file');
}
if($page=='sessions'){
echo '<pre>'.print_r($_SESSION,1).'</pre>';
}
if($page=='checkfile_pm'){//надо доделать!!!! перенос и удаление файлов
include 'inc/_db.php';
include_once 'config.php';
$dir = 'upload/pm/';
$files = scandir($dir);
foreach($files as $key => $file)if($file!='.'&&$file!='..'){
if(isset($_SESSION['filescheck']['acs_pm'])&&$key>$_SESSION['filescheck']['acs_pm']) {
$path = $dir . $file;
if (is_dir($path)) {
$files1 = scandir($path);
foreach ($files1 as $key1 => $file1) if ($file1 != '.' && $file1 != '..') {
$fdb = $dir . $file . '/' . $file1;
$sql = 'SELECT id FROM acs_pm WHERE file="' . $fdb . '"';
$rez = $DB->QUR_SEL($sql);
if (!$rez[0]) {
//movefile($dir.$file,'/home/admin/web/eios.mkgtu.ru/tmp/');
$pi = pathinfo($fdb);
echo $sql . '<pre>' . print_r($pi, 1) . '</pre>';
$path_kuda = '/home/admin/web/eios.mkgtu.ru/tmp/' . $pi['dirname'];
echo '$path_kuda: ' . $path_kuda . '<br>';
$file = $_SERVER['DOCUMENT_ROOT'] . '/' . $fdb;
echo '$file: ' . $file . '<br>';
exit();
}
//echo $sql.'<pre>'.print_r($rez,1).'</pre>';
}
//echo '<pre>'.print_r($files1,1).'</pre>';
}
}
$_SESSION['filescheck']['acs_pm'] = $key;
}
}
//сканируем директории и проверяем файлы в таблице
function scandir_upload($dir,$table,$pole){
GLOBAL $DB;
$files = scandir($dir);
$out = '<table>';
foreach($files as $key => $file)if($file!='.'&&$file!='..'){
if(isset($_SESSION['filescheck'][$table])&&$key>$_SESSION['filescheck'][$table]) {
$status = '';
$tmp = array();
$sql = 'SELECT id,data_c FROM ' . $table . ' WHERE ' . $pole . '="' . $file . '"';
$rez = $DB->QUR_SEL($sql);
if ($rez[0]) {
foreach ($rez as $k => $v) if ($k) {
$tmp[] = date('H:i d.m.Y', $v['data_c']) . '; ';
}
}
if (count($tmp)) {
$status = implode(';', $tmp);
$style = '';
} else {
$style = 'color:red;';
movefile($dir . $file, '/home/admin/web/eios.mkgtu.ru/tmp/');
}
$out .= '<tr>';
$out .= '<td style="' . $style . '">' . $key . '</td>';
$out .= '<td style="' . $style . '">' . $status . '</td>';
$out .= '<td><a href="/' . $dir . $file . '" target="_blank" style="' . $style . '">' . $file . '</a></td>';
$out .= '</tr>';
}
$_SESSION['filescheck'][$table] = $key;
}
$out .= '</table>';
if(isset($_GET['out'])) echo $out;
}
//перемещаем файлы в временную директорию
function movefile($path_ot,$path_kuda){
$out='';
$pi = pathinfo($path_ot); //Array( [dirname] => upload/lections [basename] => 10007_666_17354518032020_0.pdf [extension] => pdf [filename] => 10007_666_17354518032020_0 )
$out .= '$path_ot: '.$path_ot.'<br>'; // upload/lections/10007_666_17354518032020_0.pdf
$out .= '$path_kuda: '.$path_kuda.'<br>'; // /home/admin/web/eios.mkgtu.ru/tmp/
$dir_tmp = $path_kuda.$pi['dirname'];
$out .= '$dir_tmp: '.$dir_tmp.'<br>'; ///home/admin/web/eios.mkgtu.ru/tmp/upload/lections
$file = $_SERVER['DOCUMENT_ROOT'].'/'.$path_ot;
$out .= '$file: '.$file.'<bR>'; ///home/admin/web/eios.mkgtu.ru/public_html/upload/lections/10007_666_17354518032020_0.pdf
if(isset($_GET['out'])) echo $out;
exec ('mkdir -p '.$dir_tmp);
exec ('mv '.$file.' '.$dir_tmp);
}
function filesize_format($filesize){
$formats = array('Б','КБ','МБ','ГБ','ТБ');// варианты размера файла
$format = 0;
while ($filesize > 1024 && count($formats) != ++$format){
$filesize = round($filesize / 1024, 2);
}
$formats[] = 'ТБ';
return $filesize.$formats[$format];
}