91 lines
3.5 KiB
PHP
91 lines
3.5 KiB
PHP
<?php
|
||
|
||
class WebAppRaiserDocs {
|
||
|
||
public static function filesDir(){
|
||
return $_SERVER['DOCUMENT_ROOT'].'/files/DocsFiles/';
|
||
//return '/server/php/files/docs'.'/DocsFiles/';
|
||
}
|
||
|
||
public static function errorCodes()
|
||
{
|
||
return array(
|
||
UPLOAD_ERR_OK => 'Файл загружен',
|
||
UPLOAD_ERR_INI_SIZE => 'File is too big to upload',
|
||
UPLOAD_ERR_FORM_SIZE => 'File is too big to upload',
|
||
UPLOAD_ERR_PARTIAL => 'Файл загружен частично',
|
||
UPLOAD_ERR_NO_FILE => 'Не загружено ни одного файла',
|
||
UPLOAD_ERR_NO_TMP_DIR => 'На сервере отсутсвует временная директорая для загрузки файла',
|
||
UPLOAD_ERR_CANT_WRITE => 'Не получилось записать файл на диск',
|
||
UPLOAD_ERR_EXTENSION => 'Этот файл нельзя загрузить на этот сервер',
|
||
);
|
||
}
|
||
|
||
public static function getDocs($order_id)
|
||
{
|
||
$res = WebAppRaiserDB::select('war_files', 'order_id', $order_id);
|
||
return $res;
|
||
}
|
||
|
||
public static function renderDocsTable($docsList)
|
||
{
|
||
$docData = array();
|
||
if(empty($docsList)){
|
||
return '<p>Нет отправленных документов.</p>';
|
||
}
|
||
if(!isset($docsList[0]['category'])){
|
||
return '<p>Неверный формат списка документов.</p>';
|
||
}
|
||
foreach($docsList as $docItem) {
|
||
$docData[$docItem['category']][] = $docItem;
|
||
}
|
||
$output = '<div class="row">';
|
||
foreach($docData as $category => $category_list){
|
||
$output .= '<div class="col col-12 col-md-4"><h3>'.$category.'</h3>';
|
||
foreach($category_list as $category_item){
|
||
$output .= '<p><a href="/engine/classes/WebAppRaiser/getfile.php?id='.$category_item['object_id'].'&order_id='.$category_item['order_id'].'&fid='.$category_item['fid'].'">'.$category_item['file_name'].'</a></p>';
|
||
}
|
||
$output .= '<hr/></div>';
|
||
}
|
||
$output .= '</div>';
|
||
return $output;
|
||
}
|
||
|
||
public static function getDocument($fid){
|
||
global $user;
|
||
$agency = User::getUserAgencyID();
|
||
$files_dir = self::filesDir();
|
||
$res = WebAppRaiserDB::select('war_files', 'fid', $fid);
|
||
if(!empty($res)){
|
||
$filename = $res[0]['file_name'];
|
||
$filepath = $res[0]['file_path'];
|
||
$file = $files_dir.$filepath.$filename;
|
||
if(file_exists($file)){
|
||
if($res[0]['agency'] == $agency){
|
||
header("Cache-Control: public");
|
||
header("Content-Description: File Transfer");
|
||
header("Content-Disposition: attachment; filename=$filename");
|
||
header("Content-Type: ".mime_content_type($file));
|
||
header("Content-Transfer-Encoding: binary");
|
||
readfile($file);
|
||
exit;
|
||
}
|
||
else {
|
||
die('access denied');
|
||
}
|
||
}
|
||
}
|
||
die('file not found');
|
||
}
|
||
|
||
public static function getCategories()
|
||
{
|
||
$return = array();
|
||
$sql = 'SELECT category FROM `war_files` GROUP BY `category`';
|
||
$res = mysql_query($sql);
|
||
while ($row = mysql_fetch_assoc($res)) {
|
||
$return[$row['category']] = $row['category'];
|
||
}
|
||
return $return;
|
||
}
|
||
} |