Initial import
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets;
|
||||
|
||||
|
||||
use app\models\DocsCms;
|
||||
use yii\base\Widget;
|
||||
|
||||
class DocumentWidget extends Widget
|
||||
{
|
||||
|
||||
public $document_key;
|
||||
public $model_class;
|
||||
public $model;
|
||||
|
||||
public function run()
|
||||
{
|
||||
$documents = DocsCms::find()->where(['document_key' => $this->document_key])->orderBy(['id' => SORT_DESC])->all();
|
||||
return $this->render('files/docs', [
|
||||
'document_key' => $this->document_key,
|
||||
'model_class' => $this->model_class,
|
||||
'model_id' => $this->model->id,
|
||||
'documents' => $documents
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\widgets;
|
||||
|
||||
use yii\base\Widget;
|
||||
|
||||
class FileWidget extends Widget
|
||||
{
|
||||
|
||||
public $media_key;
|
||||
public $object_key;
|
||||
public $single_file = false;
|
||||
public $media_type;
|
||||
public $actions;
|
||||
public $max_file_size = 3;
|
||||
public $error_message = 'Too big file, (max 3mb)';
|
||||
public $files;
|
||||
public $resolutions = [];
|
||||
public $model_class;
|
||||
public $model_id;
|
||||
|
||||
public function run()
|
||||
{
|
||||
return $this->render("media/$this->media_type", [
|
||||
'media_key' => $this->media_key,
|
||||
'object_key' => $this->object_key,
|
||||
'single_file' => $this->single_file,
|
||||
'actions' => $this->actions,
|
||||
'max_file_size' => $this->max_file_size,
|
||||
'error_message' => $this->error_message,
|
||||
'files' => $this->files,
|
||||
'resolutions' => $this->resolutions,
|
||||
'model_class' => $this->model_class,
|
||||
'model_id' => $this->model_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets;
|
||||
|
||||
use yii\base\Widget;
|
||||
|
||||
class FormWidget extends Widget
|
||||
{
|
||||
public $top = null;
|
||||
public $tabs = [];
|
||||
public $writeView = null;
|
||||
public $postService = null;
|
||||
public $validation = null;
|
||||
public $model = null;
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (isset($_GET['o']))
|
||||
return $this->render('form', [
|
||||
'top' => $this->top,
|
||||
'tabs' => $this->tabs,
|
||||
'writeView' => $this->writeView,
|
||||
'postService' => $this->postService,
|
||||
'validation' => $this->validation,
|
||||
'model' => $this->model
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\widgets;
|
||||
|
||||
use yii\base\Widget;
|
||||
|
||||
class TableWidget extends Widget
|
||||
{
|
||||
|
||||
public $top = [];
|
||||
public $th = [];
|
||||
public $data = [];
|
||||
public $actions = [];
|
||||
public $filter = [];
|
||||
public $advanced_filter = '';
|
||||
public $exportData = [];
|
||||
public $ignoreIds = [];
|
||||
public $listTabs = [];
|
||||
public $model = null;
|
||||
|
||||
public function run()
|
||||
{
|
||||
if (!isset($_GET['o']))
|
||||
return $this->render('table', [
|
||||
'top' => $this->top,
|
||||
'th' => $this->th,
|
||||
'data' => $this->data,
|
||||
'actions' => $this->actions,
|
||||
'filter' => $this->filter,
|
||||
'advanced_filter' => $this->advanced_filter,
|
||||
'exportData' => $this->exportData,
|
||||
'ignoreIds' => $this->ignoreIds,
|
||||
'listTabs' => $this->listTabs,
|
||||
'model' => $this->model
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
class Image
|
||||
{
|
||||
public function crateThumb($media_key, $object_key, $file_name, $file_type, $temp)
|
||||
{
|
||||
$file_dest = $this->getFileDest($media_key, $object_key, $file_name, 'thumb');
|
||||
$this->scaleImage($temp, $file_type, $file_dest, 0.3, 50);
|
||||
}
|
||||
|
||||
public function createCrop($crop, $file, $media_key, $object_key)
|
||||
{
|
||||
$file_dest = $this->getFileDest($media_key, $object_key, $file['name'], $crop);
|
||||
$this->scaleImage($file['tmp_name'], $file['type'], $file_dest, 0.7, 55);
|
||||
}
|
||||
|
||||
private function getFileDest($media_key, $object_key, $file_name, $last_dir)
|
||||
{
|
||||
$dir_ready = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready';
|
||||
$dir_media = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $media_key;
|
||||
$dir_object = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $media_key . '/' . $object_key;
|
||||
$dir_last = "$dir_object/$last_dir";
|
||||
$file_dest = "$dir_last/$file_name";
|
||||
if (!file_exists($dir_ready))
|
||||
mkdir($dir_ready, 0777);
|
||||
if (!file_exists($dir_media))
|
||||
mkdir($dir_media, 0777);
|
||||
if (!file_exists($dir_object))
|
||||
mkdir($dir_object, 0777);
|
||||
if (!file_exists($dir_last))
|
||||
mkdir($dir_last, 0777);
|
||||
return $file_dest;
|
||||
}
|
||||
|
||||
|
||||
private function cropImage($file, $file_type, $destination, $thumb_width = 0, $thumb_height = 0, $quality = 100)
|
||||
{
|
||||
switch ($file_type) {
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file);
|
||||
$quality = 9;
|
||||
break;
|
||||
default:
|
||||
echo json_encode(['error', 'Unsupported file format: ' . $file_type]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
$original_aspect = $width / $height;
|
||||
$thumb_aspect = $thumb_width / $thumb_height;
|
||||
if ($original_aspect >= $thumb_aspect) {
|
||||
$new_height = $thumb_height;
|
||||
$new_width = $width / ($height / $thumb_height);
|
||||
} else {
|
||||
$new_width = $thumb_width;
|
||||
$new_height = $height / ($width / $thumb_width);
|
||||
}
|
||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||
imagecopyresampled($thumb,
|
||||
$image,
|
||||
0 - ($new_width - $thumb_width) / 2,
|
||||
0 - ($new_height - $thumb_height) / 2,
|
||||
0, 0,
|
||||
$new_width, $new_height,
|
||||
$width, $height);
|
||||
if ($file_type == 'image/png') {
|
||||
imagealphablending($thumb, false);
|
||||
imagesavealpha($thumb, true);
|
||||
imagepng($thumb, $destination, $quality);
|
||||
} else {
|
||||
imagejpeg($thumb, $destination, $quality);
|
||||
}
|
||||
}
|
||||
|
||||
private function scaleImage($file, $file_type, $destination, $scale, $quality)
|
||||
{
|
||||
switch ($file_type) {
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file);
|
||||
$quality = 9;
|
||||
break;
|
||||
default:
|
||||
echo json_encode(['error', 'Unsupported file format: ' . $file_type]);
|
||||
exit;
|
||||
}
|
||||
|
||||
list($width, $height) = getimagesize($file);
|
||||
$scaledImage = imagescale($image, ($width * $scale), ($height * $scale));
|
||||
if ($file_type == 'image/png') {
|
||||
imagealphablending($scaledImage, false);
|
||||
imagesavealpha($scaledImage, true);
|
||||
imagepng($scaledImage, $destination, $quality);
|
||||
} else {
|
||||
imagejpeg($scaledImage, $destination, $quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
class Includes
|
||||
{
|
||||
public static function top($title, $data = [], $title_edit = null)
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/top', [
|
||||
'title' => $title,
|
||||
'title_edit' => $title_edit,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public static function wl($tabs = [])
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/wl', ['tabs' => $tabs]);
|
||||
}
|
||||
|
||||
public static function setTabs($tabs = [])
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/tabs', ['tabs' => $tabs]);
|
||||
}
|
||||
|
||||
public static function setListTabs($listTabs = []) {
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/listtabs', ['tabs' => $listTabs]);
|
||||
}
|
||||
|
||||
public static function formButtons($list_url)
|
||||
{
|
||||
return \Yii::$app->view->render('/../widgets/views/includes/fbuttons', [
|
||||
'list_url' => $list_url
|
||||
]);
|
||||
}
|
||||
|
||||
public static function inLocales($tab)
|
||||
{
|
||||
$locales = ['ts_en'];
|
||||
return in_array($tab, $locales);
|
||||
}
|
||||
|
||||
public static function tab($tab)
|
||||
{
|
||||
if (self::inLocales($tab))
|
||||
return 'ts';
|
||||
return $tab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
use app\services\Auth;
|
||||
|
||||
class UserRight
|
||||
{
|
||||
/** @var \app\models\UserPartner */
|
||||
public static $partner;
|
||||
|
||||
public static function add()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(1)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function edit()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(2)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function del()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(4)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function pub()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(5)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
if (self::$partner)
|
||||
if (self::$partner->role_id != 1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getPartner()
|
||||
{
|
||||
if (self::$partner)
|
||||
return self::$partner->id;
|
||||
}
|
||||
|
||||
public static function setPartner($partner)
|
||||
{
|
||||
if ($partner) {
|
||||
self::$partner = $partner;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: W10
|
||||
* Date: 2/17/2021
|
||||
* Time: 3:24 PM
|
||||
*/
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
use app\extensions\simplex\SimpleXLSX;
|
||||
use app\extensions\XLSXWriter;
|
||||
use app\extensions\XLSXReader;
|
||||
|
||||
class XLSx
|
||||
{
|
||||
public static function toXlsWriter($data, $fileName, $sheet, $header)
|
||||
{
|
||||
$headerRow = [];
|
||||
foreach ($header as $headerTitle => $headerElement) $headerRow[] = $headerTitle;
|
||||
|
||||
$filename = $fileName . '.csv';
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
$dataAsString = implode(';', $headerRow) . "\r\n";
|
||||
foreach ($data as $row) {
|
||||
$dataAsString .= implode(';', $row) . "\r\n";
|
||||
}
|
||||
echo $dataAsString;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
public static function toArrayWriter($targetFile, $sheet)
|
||||
{
|
||||
try {
|
||||
$xlsx = new XLSXReader($targetFile);
|
||||
return $xlsx->getSheetData($sheet);
|
||||
} catch (\Exception $e) {
|
||||
return ['error' => 'The Sheet not exists in this file'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $document_key
|
||||
* @var $model_class
|
||||
* @var $model_id
|
||||
* @var \app\models\DocsCms $documents
|
||||
*/
|
||||
?>
|
||||
<div class="inner-content p10">
|
||||
<div class="row">
|
||||
<label>Документи в проекта</label>
|
||||
<div class="top-page-panel">
|
||||
<div class="row action-buttons">
|
||||
<button data-model-id="<?= $model_id ?>" data-model-class="<?= $model_class ?>"
|
||||
data-document-key="<?= $document_key ?>" onclick="addDocument(this)"
|
||||
class="btn-ib btn-default ct"><i class="la la-plus-circle"></i> Добави документ
|
||||
</button>
|
||||
</div>
|
||||
<table class="cms-table top15 docs-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="c1">Вид</th>
|
||||
<th>Име (български)</th>
|
||||
<th>Име (английски)</th>
|
||||
<th class="ct">Файл (български)</th>
|
||||
<th class="ct">Файл (английски)</th>
|
||||
<th class="c1 ct">Изтриване</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (sizeof($documents) > 0): ?>
|
||||
|
||||
<?php
|
||||
/** @var \app\models\DocsCms $document */
|
||||
foreach ($documents as $document): ?>
|
||||
<tr data-document-id="<?= $document->id ?>">
|
||||
<td>
|
||||
<select data-input="document_type">
|
||||
<option value=""></option>
|
||||
<option <?= $document->document_type == 'pptx' ? 'selected' : '' ?>
|
||||
value="pptx">Презентация (pptx)
|
||||
</option>
|
||||
<option <?= $document->document_type == 'pdf' ? 'selected' : '' ?> value="pdf">Документ (pdf)</option>
|
||||
<option <?= $document->document_type == 'docx' ? 'selected' : '' ?> value="docx">Документ (docx)</option>
|
||||
<option <?= $document->document_type == 'xlsx' ? 'selected' : '' ?> value="xlsx">Таблица (xlsx)</option>
|
||||
<option <?= $document->document_type == 'other' ? 'selected' : '' ?> value="other">Други</option>
|
||||
</select>
|
||||
</td>
|
||||
<td><input data-input="name" value="<?= $document->name ?>"></td>
|
||||
<td><input data-input="name_en" value="<?= $document->name_en ?>"></td>
|
||||
<td class="ct">
|
||||
<?php if ($document->file_name): ?>
|
||||
<a href="<?= $document->file_name ?>" class="download-link"><span class="extension"><i class="la la-download"></i> <?= $document->extension ?> сваляне</span></a>
|
||||
<span data-document-id="<?= $document->id ?>" data-delete-field="file_name" onclick="deleteUploadedFile(this)" class="delete-link"><span class="extension"><i class="la la-trash"></i> изтриване</span></span>
|
||||
<?php else: ?>
|
||||
<button class="btn-ib btn-default" data-upload-field="file_name" onclick="attachAndUploadFile(this)">
|
||||
<i class="la la-file-upload"></i> Качи файл
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="ct">
|
||||
<?php if ($document->file_name_en): ?>
|
||||
<a href="<?= $document->file_name_en ?>" class="download-link"><span class="extension"><i class="la la-download"></i> <?= $document->extension_en ?> сваляне</span></a>
|
||||
<span data-document-id="<?= $document->id ?>" data-delete-field="file_name_en" onclick="deleteUploadedFile(this)" class="delete-link"><span class="extension"><i class="la la-trash"></i> изтриване</span></span>
|
||||
<?php else: ?>
|
||||
<button class="btn-ib btn-default" data-upload-field="file_name_en" onclick="attachAndUploadFile(this)">
|
||||
<i class="la la-file-upload"></i> Качи файл
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<button onclick="deleteDocument(this)" class="btn btn-red btn-ico center"><i class="la la-trash font-20"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<tr class="empty">
|
||||
<td colspan="7" class="ct p20" style="">
|
||||
<strong>Няма добавени документи</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/_public/assets/js/docs.js"></script>
|
||||
@@ -0,0 +1,499 @@
|
||||
<?php
|
||||
|
||||
use app\models\FileCms;
|
||||
use app\widgets\services\Includes;
|
||||
use app\services\Validate;
|
||||
use app\widgets\services\UserRight;
|
||||
|
||||
|
||||
?>
|
||||
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET'): ?>
|
||||
<style>
|
||||
.help_key_link {
|
||||
cursor: pointer; position: absolute; font-size: 10px; color: grey; top: 15px; right:0
|
||||
}
|
||||
.help_key_link.has_link {
|
||||
color: darkmagenta !important;
|
||||
font-weight: bold;
|
||||
font-size: 11px;
|
||||
}
|
||||
.help_info_button {
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: -15px;
|
||||
border-radius: 100%;
|
||||
height: 17px;
|
||||
width: 17px;
|
||||
font-size: 17px;
|
||||
text-align: center;
|
||||
line-height: 17px;
|
||||
background: #FFFFFF;
|
||||
}
|
||||
|
||||
.help_info_button:hover {
|
||||
background: #f1f1f1;
|
||||
}
|
||||
|
||||
.help_info_button .la {
|
||||
color: var(--base-background-dark);
|
||||
}
|
||||
|
||||
.help_info_button .content-body {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: 1000;
|
||||
background: #FFFFFF;
|
||||
border: 1px solid var(--base-background-dark);
|
||||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
|
||||
padding: 10px;
|
||||
width: 150px;
|
||||
border-radius: 5px;
|
||||
cursor: default;
|
||||
|
||||
}
|
||||
|
||||
.help_info_button .content-body a { cursor: pointer }
|
||||
|
||||
.help_info_button .content-body .content-body-title {
|
||||
font-size: 13px !important;
|
||||
font-weight: bold;
|
||||
text-align: left;
|
||||
color: var(--base-background-dark);
|
||||
}
|
||||
|
||||
.help_info_button .content-body .content-body-text {
|
||||
font-size: 13px;
|
||||
line-height: 13px;
|
||||
text-align: left;
|
||||
max-height: 300px;
|
||||
overflow-y: scroll;
|
||||
padding-right: 10px
|
||||
}
|
||||
|
||||
.content-body-text::-webkit-scrollbar {
|
||||
width: 3px;
|
||||
}
|
||||
|
||||
.content-body-text::-webkit-scrollbar-track {
|
||||
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.content-body-text::-webkit-scrollbar-thumb {
|
||||
background-color: var(--base-background);
|
||||
outline: 1px solid slategrey;
|
||||
}
|
||||
|
||||
.help_info_button .content-body .content-body-text p {
|
||||
font-size: 13px;
|
||||
line-height: 13px;
|
||||
text-align: left
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php if (!UserRight::edit() && !empty($_GET['id']) || empty($_GET['id']) && !UserRight::add()): ?>
|
||||
<!-- prevent edit view -->
|
||||
<style>
|
||||
.all-files {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.top-page-panel .action-buttons {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.files-container [data-del] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.file-img.dragging {
|
||||
display: block !important;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.readonly {
|
||||
pointer-events: none !important;
|
||||
appearance: none !important;
|
||||
-webkit-appearance: none !important;
|
||||
-moz-appearance: none !important;
|
||||
padding: 0 !important;
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
input[type="radio"] {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
pointer-events: none !important;
|
||||
padding: 0 !important;
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.search-box::after {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.selected-box .close {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.selected-box {
|
||||
padding-right: 5px !important;
|
||||
}
|
||||
|
||||
.require::after {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
[data-exposition-id] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.cke_top {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.upload-info {
|
||||
display: none
|
||||
}
|
||||
|
||||
.air-datepicker-cell {
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
#partner_logo_image_0 {
|
||||
pointer-events: none
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (!UserRight::edit() || !UserRight::add()): ?>
|
||||
<style>
|
||||
[onclick="addTs(this)"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
#tslist input {
|
||||
pointer-events: none
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var $top array
|
||||
* @var $tabs array
|
||||
* @var $data array
|
||||
* @var $writeView string
|
||||
* @var $postService
|
||||
* @var $validation
|
||||
* @var \yii\db\ActiveRecord | string $model
|
||||
*/
|
||||
$dataModel = null;
|
||||
|
||||
if ($model) {
|
||||
$dataModel = new $model();
|
||||
if (isset($_GET['id'])) {
|
||||
$updateModel = $model::findOne($_GET['id']);
|
||||
if ($updateModel)
|
||||
$dataModel = $updateModel;
|
||||
if (!$dataModel->id)
|
||||
header('Location: ' . explode('?', $_SERVER['REQUEST_URI'])[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
switch ($_GET['o']) {
|
||||
case 'w':
|
||||
|
||||
if (empty($_GET['id']) && !UserRight::add()) die('You have no permission to operate');
|
||||
if (!empty($_GET['id']) && !UserRight::edit()) die('You have no permission to operate');
|
||||
|
||||
if ($validation)
|
||||
Validate::defaultValidation($validation((object)$_POST, (object)$_FILES));
|
||||
if ($dataModel) {
|
||||
$postService((object)$_POST, $dataModel);
|
||||
} else {
|
||||
$postService((object)$_POST);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
// UPDATE STATUS
|
||||
foreach (['model', 'id', 'key'] as $p) {
|
||||
if (empty($_POST[$p])) {
|
||||
echo json_encode(['error' => 'Missing parameter: ' . $p]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var $modelStr \yii\db\ActiveRecord;
|
||||
* @var $remoteUpdateModel \yii\db\ActiveRecord;
|
||||
*/
|
||||
$modelStr = $_POST['model'];
|
||||
$remoteUpdateModel = $modelStr::findOne($_POST['id']);
|
||||
$remoteUpdateModel->{$_POST['key']} = $_POST['value'] == 'null' ? NULL : 1;
|
||||
if ($remoteUpdateModel->hasProperty('publish_date') && $_POST['key'] == 'is_active' && $_POST['value'] == 1) {
|
||||
if ($remoteUpdateModel->{'publish_date'}) {
|
||||
$dateRecorded = strtotime($remoteUpdateModel->{'publish_date'});
|
||||
$dateNow = strtotime(date('Y-m-d'));
|
||||
if ($dateNow > $dateRecorded) {
|
||||
$remoteUpdateModel->{'publish_date'} = date('Y-m-d H:i:s');
|
||||
}
|
||||
} else {
|
||||
$remoteUpdateModel->{'publish_date'} = date('Y-m-d H:i:s');
|
||||
}
|
||||
}
|
||||
$remoteUpdateModel->save();
|
||||
if ($remoteUpdateModel->hasProperty('article_key'))
|
||||
\app\models\Articles::updateArticle($remoteUpdateModel);
|
||||
echo json_encode(['successMsg' => Yii::t('cms', 'The status has been successfully updated')]);
|
||||
exit;
|
||||
break;
|
||||
case 'd':
|
||||
if (isset($_POST['ids']) && isset($_POST['model'])) {
|
||||
$ids = json_decode($_POST['ids']);
|
||||
/** @var \yii\db\ActiveRecord $model */
|
||||
$model = $_POST['model'];
|
||||
$table = $model::getTableSchema()->name;
|
||||
$dataToDelete = $model::find()->where(['IN', 'id', $ids])->all();
|
||||
foreach ($dataToDelete as $dtd) {
|
||||
if ($dtd->hasProperty('media_key') && !empty($dtd->media_key)) {
|
||||
FileCms::deleteAll(['media_key' => $dtd->media_key]);
|
||||
$raw = $_SERVER['DOCUMENT_ROOT'] . '/_files/raw/' . $dtd->media_key;
|
||||
$public = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $dtd->media_key;
|
||||
if (file_exists($raw))
|
||||
system("rm -rf " . escapeshellarg($raw));
|
||||
if (file_exists($public))
|
||||
system("rm -rf " . escapeshellarg($public));
|
||||
}
|
||||
\app\models\History::deleteAll(['table_name' => $table, 'history_id' => $dtd->id]);
|
||||
if ($dtd->hasProperty('article_key')) {
|
||||
$articleForDelete = \app\models\Articles::find()->where(['key' => $dtd->{'article_key'}])->one();
|
||||
if ($articleForDelete)
|
||||
$articleForDelete->delete();
|
||||
}
|
||||
$dtd->delete();
|
||||
}
|
||||
$count = sizeof($ids);
|
||||
$msg = $count == 1 ? '{count} record has been successfully deleted' :
|
||||
'{count} records have been successfully deleted';
|
||||
if (empty($_POST['noFlash']))
|
||||
Yii::$app->flash('success', Yii::t('cms', $msg, ['count' => $count]));
|
||||
echo json_encode(['success' => true, 'message' => Yii::t('cms', $msg, ['count' => $count])]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$controller = Yii::$app->controller->id;
|
||||
|
||||
|
||||
Includes::top($top['title'], $top['data'], $top['title_edit'] ?? null);
|
||||
Includes::setTabs($tabs);
|
||||
|
||||
if ($model) {
|
||||
$modelInfoKey = strtolower(substr(strrchr($model, "\\"), 1));
|
||||
echo '<div data-info-key-value="' . $modelInfoKey . '"></div>';
|
||||
}
|
||||
|
||||
echo $this->render('/' . $controller . '/' . $writeView, ['model' => $dataModel]);
|
||||
?>
|
||||
|
||||
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET'): ?>
|
||||
<?php if (!UserRight::edit() && !empty($_GET['id']) || empty($_GET['id']) && !UserRight::add()): ?>
|
||||
<!-- prevent edit view -->
|
||||
<script>
|
||||
function editSingleFileImage(e) {
|
||||
event.preventDefault()
|
||||
if (e.id !== 'partner_logo_image_0') {
|
||||
let checkbox = e.parentNode.querySelector('input')
|
||||
modal.modalPreview('<?= Yii::$app->params['cms'] ?>' + checkbox.dataset.srcRaw)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
document.querySelectorAll('.file-img').forEach(e => {
|
||||
e.classList.remove('draggable')
|
||||
e.removeAttribute('draggable')
|
||||
e.removeAttribute('data-file-index')
|
||||
e.removeAttribute('data-file-id')
|
||||
e.addEventListener('dragstart', function () {
|
||||
event.preventDefault()
|
||||
})
|
||||
e.addEventListener('dragging', function () {
|
||||
event.preventDefault()
|
||||
})
|
||||
})
|
||||
}, 300)
|
||||
document.querySelectorAll('input:not([type="radio"]), textarea').forEach(e => {
|
||||
e.setAttribute('readonly', true);
|
||||
e.classList.add('readonly')
|
||||
e.setAttribute('placeholder', 'Нама въведени данни')
|
||||
})
|
||||
document.querySelectorAll('select').forEach(e => {
|
||||
e.classList.add('readonly')
|
||||
|
||||
})
|
||||
|
||||
</script>
|
||||
<?php endif ?>
|
||||
|
||||
<script>
|
||||
/* all('.ckEditor', t => {
|
||||
t.id = t.name;
|
||||
CKEDITOR.replace(t.id, {language: 'bg'});
|
||||
}) */
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
if (typeof ClassicEditor === 'undefined') {
|
||||
console.error('CKEditor 5 not loaded');
|
||||
return;
|
||||
}
|
||||
|
||||
document.querySelectorAll('.ckEditor').forEach(function (el) {
|
||||
ClassicEditor.create(el);
|
||||
});
|
||||
});
|
||||
let dataInfoKey = document.querySelector('[data-info-key-value]');
|
||||
|
||||
const infoKeys = [];
|
||||
document.querySelectorAll('[name]').forEach(e => {
|
||||
if (e.type !== 'hidden' || e.name === 'media_key') {
|
||||
let input = e.name.replace('[]', '')
|
||||
e.parentNode.style.position = 'relative'
|
||||
let dataInfoKeyValue = dataInfoKey ? '_' + dataInfoKey.getAttribute('data-info-key-value') : '';
|
||||
let keyText = input + dataInfoKeyValue
|
||||
e.parentNode.setAttribute('data-hk', keyText)
|
||||
infoKeys.push(keyText);
|
||||
}
|
||||
})
|
||||
|
||||
<?php if(!empty($_SESSION['help_keys'])): ?>
|
||||
alert(window.location.path);
|
||||
request({
|
||||
url: '/admin-global/help-keys-remote/get-list/?keys=' + infoKeys.join(','), done: r => {
|
||||
|
||||
let has_link_list = [];
|
||||
if(r.list) {
|
||||
r.list.forEach(l => {
|
||||
has_link_list.push(l.key)
|
||||
})
|
||||
}
|
||||
document.querySelectorAll('[name]').forEach(e => {
|
||||
if (e.type !== 'hidden' || e.name === 'media_key') {
|
||||
let input = e.name.replace('[]', '')
|
||||
console.log(input);
|
||||
e.parentNode.style.position = 'relative'
|
||||
let key = document.createElement('div')
|
||||
key.classList.add('help_key_link')
|
||||
let dataInfoKeyValue = dataInfoKey ? '_' + dataInfoKey.getAttribute('data-info-key-value') : '';
|
||||
key.innerHTML = input + dataInfoKeyValue
|
||||
|
||||
if(has_link_list.indexOf(key.innerHTML) > -1) {
|
||||
key.classList.add('has_link')
|
||||
}
|
||||
let label = e.parentNode.querySelector('label');
|
||||
let title = label ? label.innerHTML : '';
|
||||
key.addEventListener('click', function () {
|
||||
request({
|
||||
url: '/admin-global/help-keys-remote/set-help/', post: {
|
||||
key: key.innerHTML,
|
||||
title
|
||||
}, done: r => {
|
||||
if (r.url_to) {
|
||||
window.open(r.url_to, '_blank').focus();
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
e.parentNode.appendChild(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
<?php else: ?>
|
||||
if(window.location.pathname !== '/admin-global/web-portal/tslist/') {
|
||||
if (infoKeys.length > 0) {
|
||||
request({
|
||||
url: '/remote/help-keys-remote/get-list/?keys=' + infoKeys.join(','), done: r => {
|
||||
if (r.list) {
|
||||
r.list.forEach(le => {
|
||||
let helpBtnContainer = document.querySelector(`[data-hk="${le.key}"]`);
|
||||
let helpBtn = document.createElement('div')
|
||||
helpBtn.classList.add('help_info_button')
|
||||
let icon = document.createElement('i')
|
||||
icon.className = 'help-info-ico la la-info-circle'
|
||||
helpBtn.appendChild(icon);
|
||||
helpBtnContainer.appendChild(helpBtn)
|
||||
icon.addEventListener('click', () => {
|
||||
if (helpBtn.classList.contains('open')) {
|
||||
closeHelpInfoWindow(helpBtn)
|
||||
icon.classList.add('la-info-circle')
|
||||
icon.classList.remove('la-times-circle')
|
||||
helpBtn.classList.remove('open')
|
||||
|
||||
} else {
|
||||
openHelpInfoWindow(le.id, helpBtn)
|
||||
icon.classList.remove('la-info-circle')
|
||||
icon.classList.add('la-times-circle')
|
||||
helpBtn.classList.add('open')
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
document.addEventListener('click', () => {
|
||||
document.querySelectorAll('.help_info_button.open').forEach(b => {
|
||||
if (!b.contains(event.target)) {
|
||||
closeHelpInfoWindow(b)
|
||||
let cIcon = b.querySelector('.la');
|
||||
cIcon.classList.add('la-info-circle')
|
||||
cIcon.classList.remove('la-times-circle')
|
||||
b.classList.remove('open')
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function openHelpInfoWindow(id, container) {
|
||||
request({
|
||||
dataType: 'html',
|
||||
url: '/remote/help-keys-remote/get-content/?id=' + id,
|
||||
done: html => {
|
||||
console.log(html)
|
||||
let contentBody = document.createElement('div');
|
||||
contentBody.className = 'content-body'
|
||||
contentBody.innerHTML = html;
|
||||
container.appendChild(contentBody);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function closeHelpInfoWindow(container) {
|
||||
container.querySelector('.content-body').remove();
|
||||
}
|
||||
}
|
||||
<?php endif ?>
|
||||
</script>
|
||||
<?php endif ?>
|
||||
<style>
|
||||
/* Allow ckeditor vertical resize */
|
||||
.ck-editor__editable {
|
||||
resize: vertical;
|
||||
min-height: 150px;
|
||||
}
|
||||
|
||||
/* Prevent ckeditor horizontal resize */
|
||||
.ck-editor__editable[contenteditable="true"] {
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $data array
|
||||
* @var $actions array
|
||||
* @var $exportData array
|
||||
*/
|
||||
|
||||
use app\widgets\services\UserRight;
|
||||
|
||||
if (!empty($_GET['roletest'])) {
|
||||
$partner = \app\services\Auth::userPartner();
|
||||
if ($partner) {
|
||||
foreach ($partner->userRights as $right) {
|
||||
echo '<br> ' . $right->right_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($actions['new']) || isset($actions['edit']) || isset($actions['delete']) || !empty($exportData)): ?>
|
||||
<div style="margin-bottom: 10px;" class="action-buttons">
|
||||
<?php if (isset($actions['new']) && UserRight::add()): ?>
|
||||
<a id="bNew" href="?o=w<?= !empty($_GET['listtab']) ? '&listtab=' . $_GET['listtab'] : '' ?>"
|
||||
class="btn-ib btn-default ct">
|
||||
<i class="la la-plus-circle"></i> <?= $actions['new'] ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (sizeof($data['list'])): ?>
|
||||
<?php if (isset($actions['edit']) && UserRight::edit()): ?>
|
||||
<a id="bEdit" class="btn-ib btn-default ct disabled">
|
||||
<i class="la la-edit"></i> <?= $actions['edit'] ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($actions['delete']) && UserRight::del()): ?>
|
||||
<a id="bDelete" data-model="<?= $data['model'] ?? null ?>" onclick="checkDelete(this)"
|
||||
class="btn-ib btn-default ct disabled">
|
||||
<i class="la la-trash-o"></i> <?= $actions['delete'] ?> <span id="delCount">(0)</span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($exportData)): ?>
|
||||
<a id="exportDate" href="<?= !empty($_GET['q']) ? '?q=' . $_GET['q'] . '&export=1' : '?export=1' ?>"
|
||||
class="btn-ib btn-default ct">
|
||||
<i class="la la-file-export"></i> <?= !empty($actions['export']) ? $actions['export'] : 'Export' ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $list_url
|
||||
*/
|
||||
|
||||
use app\widgets\services\UserRight;
|
||||
|
||||
$save = empty($_GET['id']) ? 'Създаване' : 'Запис';
|
||||
?>
|
||||
<a href="<?= Yii::$app->goTo($list_url) ?><?= isset($_GET['p']) ? '?p=' . $_GET['p'] : '' ?>"
|
||||
class="btn btn-default right10"><i class="la la-undo"></i> Назад</a>
|
||||
|
||||
<?php if(UserRight::edit() && !empty($_GET['id']) || UserRight::add() && empty($_GET['id'])): ?>
|
||||
<button onclick="saveAndBackToList(this)" class="btn btn-default right10">
|
||||
<i class="la la-check-circle"></i> Запис
|
||||
</button>
|
||||
<button id="save" class="btn btn-default">
|
||||
<i class="la la-save"></i> <?= empty($_GET['id']) ? $save : 'Актуализация' ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,116 @@
|
||||
<style>
|
||||
.category_search_box select {
|
||||
display: none
|
||||
}
|
||||
|
||||
.category_search_box .search-box {
|
||||
height: 15px !important;
|
||||
border-radius: 0;
|
||||
font-size: 12px;
|
||||
line-height: 15px;
|
||||
}
|
||||
|
||||
.search-box:after {
|
||||
top: 7px;
|
||||
}
|
||||
</style>
|
||||
<?php if (!empty($filter)):
|
||||
$filterGetData = Yii::$app->getFilterData();
|
||||
?>
|
||||
|
||||
<form data-type="search" method="get" autocomplete="off" autofocus="autofocus">
|
||||
<?php foreach ($filter as $row): ?>
|
||||
<div class="top-page-panel">
|
||||
<div class="toggle-filter"><i class="la <?= empty($_GET['q']) ? 'la-chevron-circle-up' : 'la-chevron-circle-down' ?>"></i> Търсене по критерии</div>
|
||||
<div class="main-filter <?= empty($_GET['q']) ? 'main-filter-closed' : '' ?> flex filter">
|
||||
<?php if (!empty($advanced_filter)): ?>
|
||||
<div class="row c1 top10">
|
||||
<label></label>
|
||||
<div class="btn-ib btn-default open-filter"><i class="la la-arrow-left"></i> Филтри</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="flex-wrap c11">
|
||||
<?php foreach ($row as $key => $filterElem): ?>
|
||||
<div class="row <?= $filterElem[1] ?? null ?> right10 top10">
|
||||
<?php if (!isset($filterElem[2])): ?>
|
||||
<label><?= $filterElem[0] ?></label>
|
||||
<input onkeyup="symbolInputProtect(this)" name="<?= $key ?>"
|
||||
placeholder="<?= $filterElem[0] ?>"
|
||||
value="<?= $filterGetData[$key] ?? null ?>">
|
||||
<?php else: ?>
|
||||
<label><?= $filterElem[0] ?></label>
|
||||
<select name="<?= $key ?>">
|
||||
<option value=""> -- без филтър --</option>
|
||||
<?php foreach ($filterElem[2] as $value => $name): ?>
|
||||
<option <?= isset($filterGetData[$key]) && $filterGetData[$key] == $value ? 'selected' : '' ?>
|
||||
value="<?= $value ?>"><?= $name ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<div class="row c3 top10">
|
||||
<label></label>
|
||||
<button class="btn-ib btn-default">
|
||||
<i class="la la-filter"></i>
|
||||
<?= Yii::t('cms', 'Search') ?></button>
|
||||
<a href="<?= Yii::$app->clearQueryUrl() ?>" class="btn-ib btn-default">
|
||||
<i class="la la-times"></i> <?= Yii::t('cms', 'Clear') ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</form>
|
||||
<div class="row-divider"></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($advanced_filter)): ?>
|
||||
<?= $advanced_filter ?>
|
||||
<?php endif; ?>
|
||||
<script src="/_public/plugins/air-datepicker/locales.js"></script>
|
||||
<script src="/_public/plugins/air-datepicker/air-datepicker.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
new AirDatepicker('.fDatepicker input', {
|
||||
locale: locales.bg,
|
||||
autoClose: true
|
||||
});
|
||||
all('.fDatepicker input').forEach(e => {
|
||||
e.setAttribute('readonly', true);
|
||||
})
|
||||
|
||||
const
|
||||
openFilter = one('.open-filter'),
|
||||
closeFilter = one('.close-filter'),
|
||||
af = one('.advanced-filter'),
|
||||
toggleFilter = one('.toggle-filter')
|
||||
mainFilter = one('.main-filter ')
|
||||
|
||||
if (openFilter && closeFilter && af) {
|
||||
openFilter.addEventListener('click', e => {
|
||||
if (af.classList.contains('filter-open')) {
|
||||
af.classList.remove('filter-open')
|
||||
openFilter.querySelector('i').switchClasses('la-arrow-left', 'la-arrow-right')
|
||||
} else {
|
||||
af.classList.add('filter-open')
|
||||
openFilter.querySelector('i').switchClasses('la-arrow-right', 'la-arrow-left')
|
||||
}
|
||||
})
|
||||
closeFilter.addEventListener('click', e => {
|
||||
af.classList.remove('filter-open')
|
||||
openFilter.querySelector('i').switchClasses('la-arrow-left', 'la-arrow-right')
|
||||
})
|
||||
}
|
||||
if(toggleFilter) {
|
||||
toggleFilter.addEventListener('click', e => {
|
||||
if (mainFilter.classList.contains('main-filter-closed')) {
|
||||
mainFilter.classList.remove('main-filter-closed')
|
||||
toggleFilter.querySelector('i').switchClasses('la-chevron-circle-down', 'la-chevron-circle-up')
|
||||
} else {
|
||||
mainFilter.classList.add('main-filter-closed')
|
||||
toggleFilter.querySelector('i').switchClasses('la-chevron-circle-up', 'la-chevron-circle-down')
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$tab = $_GET['listtab'] ?? 'main';
|
||||
/**
|
||||
* @var $tabs array
|
||||
*/
|
||||
?>
|
||||
<div class="wl-switch">
|
||||
<?php foreach ($tabs as $q => $title): ?>
|
||||
<a class="<?= $q == $tab ? 'selected' : '' ?>" href="<?= Yii::$app->setQueryString(['listtab' => $q]) ?>"><?= $title ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $data array
|
||||
*/
|
||||
|
||||
if ($data['pages'] > 1) :
|
||||
|
||||
$q = '?' . ($_GET['q'] ?? '');
|
||||
$sgn = $q !== '?' ? $q . '&' : $q;
|
||||
if ($sgn != '' && !empty($_GET['expId'])) {
|
||||
$sgn = $sgn . 'expId=' . $_GET['expId'] . '&';
|
||||
}
|
||||
?>
|
||||
<div class="pagination">
|
||||
<?php $p = $_GET['p'] ?? 1; ?>
|
||||
<div style="margin-right: 20px; line-height: 20px; color: var(--base-background-dark)"><?= $data['info'] ?></div>
|
||||
<?php if ($data['pages'] > 15): ?>
|
||||
<?php if ($p > 1): ?>
|
||||
<a href="<?= $sgn ?>p=1"><i class="la la-angle-double-left"></i></a>
|
||||
<a href="<?= $sgn ?>p=<?= $p - 1 ?>"><i class="la la-angle-left"></i></a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
$start = $p - 5;
|
||||
$end = $p + 5;
|
||||
$start = $start > 1 ? $start : 1;
|
||||
$end = $end < $data['pages'] ? $end : $data['pages'];
|
||||
|
||||
for ($i = $start; $i <= $end; $i++):
|
||||
$selected = $p == $i ? 'class="selected"' : 'href="' . $sgn . 'p=' . $i . '"'; ?>
|
||||
<a <?= $selected ?>><?= $i ?></a>
|
||||
<?php endfor; ?>
|
||||
|
||||
<?php if ($p < $data['pages']): ?>
|
||||
<a href="<?= $sgn ?>p=<?= $p + 1 ?>"><i class="la la-angle-right"></i></a>
|
||||
<a href="<?= $sgn ?>p=<?= $data['pages'] ?>"><i class="la la-angle-double-right"></i></a>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<?php for ($i = 0; $i < $data['pages']; $i++): ?>
|
||||
<?php
|
||||
$pn = ($i + 1);
|
||||
$selected = $p == $pn ? 'class="selected"' : 'href="' . $sgn . 'p=' . $pn . '"';
|
||||
?>
|
||||
<a <?= $selected ?>><?= $pn ?></a>
|
||||
<?php endfor; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$tab = $_GET['tab'] ?? 'main';
|
||||
/**
|
||||
* @var $tabs array
|
||||
*/
|
||||
?>
|
||||
<div class="wl-switch">
|
||||
<?php foreach ($tabs as $q => $title): ?>
|
||||
<a id="tab_<?= $q ?>" class="<?= $q == $tab ? 'selected' : '' ?>" href="<?= Yii::$app->setQueryString(['tab' => $q]) ?>"><?= $title ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $title string
|
||||
* @var $title_edit
|
||||
* @var $data array
|
||||
*/
|
||||
$controller = Yii::$app->controller->id;
|
||||
$pageTitle = isset($_GET['id']) ? $title_edit : $title;
|
||||
Yii::$app->controller->pageTitle = $pageTitle;
|
||||
?>
|
||||
<div class="flex top">
|
||||
<div class="top-title"><?= $pageTitle ?></div>
|
||||
<div class="breadcrumb p10">
|
||||
<?php foreach ($data as $url => $b): ?>
|
||||
<a href="/<?= $controller ?>/<?= $url ?>"><?= $b ?></a>
|
||||
<?php endforeach; ?>
|
||||
<span><?= $pageTitle ?></span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
$wl = $_GET['wl'] ?? 'bg';
|
||||
/**
|
||||
* @var $tabs array
|
||||
*/
|
||||
?>
|
||||
<div class="wl-switch">
|
||||
<?php foreach ($tabs as $q => $title): ?>
|
||||
<a class="<?= $q == $wl ? 'selected' : '' ?>" href="<?= Yii::$app->setQueryString(['wl' => $q]) ?>"><?= $title ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @var string $media_key
|
||||
* @var string $object_key
|
||||
* @var boolean $single_file
|
||||
* @var array $actions
|
||||
* @var int $max_file_size
|
||||
* @var string $error_message
|
||||
* @var array $files
|
||||
* @var array $resolutions
|
||||
* @var string $model_class
|
||||
* @var int $model_id
|
||||
*/
|
||||
foreach ($resolutions as $i => $r) {
|
||||
$resolutions[$i] = explode(':', $r);
|
||||
}
|
||||
|
||||
if (!empty($files[$object_key])) {
|
||||
if(isset($files[$object_key][0]) && $files[$object_key][0] == null)
|
||||
$files[$object_key] = [];
|
||||
}
|
||||
?>
|
||||
|
||||
<input class="media-key" type="hidden" name="media_key" value="<?= $media_key ?>">
|
||||
<input class="model-class" type="hidden" name="model_class" value="<?= $model_class ?>">
|
||||
<input class="model-id" type="hidden" name="model_id" value="<?= $model_id ?>">
|
||||
<div id="<?= $object_key ?>" class="top-page-panel">
|
||||
<input class="allowed_resolutions" type="hidden" value='<?= json_encode($resolutions) ?>'>
|
||||
<input class="max_file_size" type="hidden" value="<?= $max_file_size ?>">
|
||||
<input class="error_message" type="hidden" value="<?= $error_message ?>">
|
||||
<div class="action-buttons">
|
||||
<?php if (!empty($actions['add'])): ?>
|
||||
<div data-object-key="<?= $object_key ?>"
|
||||
data-single-file="<?= $single_file ?>"
|
||||
onclick="addFileImage(this)"
|
||||
data-edit-mode="<?= !empty($_GET['id']) ?>"
|
||||
class="btn-ib btn-default ct <?= $single_file == 1 && !empty($files[$object_key]) ? 'disabled' : '' ?>">
|
||||
<i class="la la-cloud-upload"></i> <?= $actions['add'] ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($actions['edit'])): ?>
|
||||
<div data-object-key="<?= $object_key ?>" onclick="editFileImage(this)"
|
||||
class="btnEdit btn-ib btn-default ct disabled"><i class="la la-crop-alt"></i> <?= $actions['edit'] ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($actions['delete'])): ?>
|
||||
<div onclick="removeFileImage(this)" data-object-key="<?= $object_key ?>"
|
||||
class="btnDelete btn-ib btn-default ct disabled"><i
|
||||
class="la la-trash"></i> <?= $actions['delete'] ?>
|
||||
<span class="delCount">(0)</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="files-container" style="<?= !empty($files[$object_key]) ? 'display:flex' : 'display:none' ?>">
|
||||
<div class="all-files" style="<?= $single_file ? 'margin-top: -7px' : '' ?>">
|
||||
<label style="<?= $single_file ? 'opacity: 0; height: 0; overflow: hidden' : '' ?>">
|
||||
<input data-object-key="<?= $object_key ?>" onclick="checkAll(this)" type="checkbox">
|
||||
<span>Маркирай всички изображения</span>
|
||||
</label>
|
||||
</div>
|
||||
<?php if (!empty($files[$object_key])): ?>
|
||||
<?php foreach ($files[$object_key] as $i => $file): ?>
|
||||
<?php if (!empty($file['id'])): ?>
|
||||
<div data-file-index="<?= $i ?>" class="file-img visible"
|
||||
data-file-id="<?= $file['id'] ?>">
|
||||
<img onclick="editSingleFileImage(this)" id="<?= $object_key ?>_<?= $i ?>"
|
||||
src="<?= $file['src'] ?>"/>
|
||||
<input type="checkbox"
|
||||
data-del="<?= $file['id'] ?>"
|
||||
data-id="<?= $object_key ?>_<?= $i ?>"
|
||||
data-object-key="<?= $object_key ?>"
|
||||
data-media-key="<?= $media_key ?>"
|
||||
data-file-name="<?= $file['file_name'] ?>"
|
||||
data-file-type="<?= $file['type'] ?>"
|
||||
data-src-raw="<?= $file['src_raw'] ?>"
|
||||
data-crop-files='<?= json_encode($file['crop_files']) ?>'
|
||||
onclick="checkSingle(this)">
|
||||
<div class="crops">
|
||||
<?php foreach ($file['crops'] as $crop): ?>
|
||||
<span><?= $crop ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $model Projects
|
||||
*/
|
||||
|
||||
use app\models\Projects;
|
||||
use app\widgets\FileWidget;
|
||||
|
||||
$media_key = $model->getMediaKey();
|
||||
|
||||
|
||||
?>
|
||||
<form autocomplete="off">
|
||||
<div class="inner-content p10">
|
||||
<div class="row c9 top15">
|
||||
<label>Изображения в проекта</label>
|
||||
<?= FileWidget::widget([
|
||||
'media_type' => 'image',
|
||||
'object_key' => 'project_images',
|
||||
'media_key' => $media_key,
|
||||
'files' => $model->getFiles('thumb'),
|
||||
'actions' => [
|
||||
'add' => 'Добавяне на изображения',
|
||||
'edit' => 'Редакция на изображение',
|
||||
'delete' => 'Премахване на изображения'
|
||||
],
|
||||
'resolutions' => ['16:11', '16:9', '1:1'],
|
||||
'max_file_size' => 2,
|
||||
'error_message' => 'Файловете по-големи от 2МБ, не бяха добавени'
|
||||
]) ?>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/_public/assets/js/order.js"></script>
|
||||
<script src="/_public/assets/js/file-img.js"></script>
|
||||
<script src="/_public/plugins/cropperJs/cropper.min.js"></script>
|
||||
<?php if (!$model->media_key): ?>
|
||||
<script>
|
||||
const media_key = '<?= $media_key ?>';
|
||||
request({
|
||||
url: window.location.href + '&media_key_update=1',
|
||||
post: {media_key: media_key}
|
||||
})
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
|
||||
use app\widgets\services\Includes;
|
||||
use app\widgets\services\UserRight;
|
||||
use app\widgets\services\XLSx;
|
||||
|
||||
/**
|
||||
* @var $this \yii\web\View;
|
||||
* @var $top array
|
||||
* @var $actions array
|
||||
* @var $th array
|
||||
* @var $data array
|
||||
* @var $advanced_filter string
|
||||
* @var $filter array
|
||||
* @var $exportData array
|
||||
* @var $ignoreIds array
|
||||
* @var $listTabs array
|
||||
* @var $model \yii\db\ActiveRecord | null
|
||||
*/
|
||||
?>
|
||||
<?php if ($_SERVER['REQUEST_METHOD'] == 'GET'): ?>
|
||||
<?php if (!UserRight::pub()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="is_for_publish"]),
|
||||
label.switch:has([data-key="on_partner_page"]),
|
||||
label.switch:has([data-key="partner_page_selected"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!UserRight::isAdmin()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="private"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<?php if (!UserRight::edit()): ?>
|
||||
<style>
|
||||
label.switch:has([data-key="partner_page_selected"]) {
|
||||
pointer-events: none;
|
||||
opacity: 0.8
|
||||
}
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
|
||||
if ($model && isset($_GET['update-indexes']) && $_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['indexes'])) {
|
||||
|
||||
$indexes = [];
|
||||
$ids = [];
|
||||
foreach (json_decode($_POST['indexes']) as $index) {
|
||||
$indexes[$index->id] = $index->order_index;
|
||||
$ids[] = $index->id;
|
||||
}
|
||||
|
||||
$data = $model::find()->where(['IN', 'id', $ids])->all();
|
||||
foreach ($data as $m) {
|
||||
if ($m->hasProperty('order_index')) {
|
||||
$m->{'order_index'} = $indexes[$m->{'id'}];
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['export'])) {
|
||||
$ed = $exportData();
|
||||
//echo json_encode($ed);
|
||||
//exit;
|
||||
$error = 0;
|
||||
foreach (['data', 'file_name', 'header'] as $d) {
|
||||
if (empty($ed[$d]))
|
||||
$error++;
|
||||
}
|
||||
if ($error == 0)
|
||||
XLSx::toXlsWriter($ed['data'], $ed['file_name'], $ed['file_name'], $ed['header']);
|
||||
}
|
||||
|
||||
if (isset($_GET['p']) && sizeof($data['list']) == 0) {
|
||||
header('Location: ' . explode('?', $_SERVER['REQUEST_URI'])[0]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Includes::top($top['title'] ?? null, $top['data'] ?? null);
|
||||
Includes::setListTabs($listTabs);
|
||||
?>
|
||||
|
||||
<div class="inner-content p10">
|
||||
<?= $this->render('includes/actions', ['actions' => $actions, 'data' => $data, 'exportData' => $exportData]) ?>
|
||||
<?= $this->render('includes/filter', ['filter' => $filter, 'advanced_filter' => $advanced_filter]); ?>
|
||||
<table class="cms-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
$j = 0;
|
||||
foreach ($th as $title => $class): ?>
|
||||
<th class="<?= $class ?>">
|
||||
<?php if (sizeof($data['list'])): ?>
|
||||
<?php if (isset($actions['delete']) && UserRight::del()): ?>
|
||||
<?= $j == 0 ? '<input id="checkAll" onclick="checkAll(this)" title="Избери всички" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?= $title ?>
|
||||
</th>
|
||||
<?php
|
||||
$j++;
|
||||
endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="<?= sizeof($th) ?>" style="padding: 0"></td>
|
||||
</tr>
|
||||
<?php if (!empty($data['list'])): ?>
|
||||
<?php foreach ($data['list'] as $index => $td): ?>
|
||||
<tr <?= isset($td['order_index']) ? 'data-index="' . $td['order_index'] . '"' : '' ?>>
|
||||
<?php $i = 0;
|
||||
foreach ($th as $title => $class): ?>
|
||||
<td class="<?= $class ?>">
|
||||
<?php if (isset($actions['edit']) || isset($actions['delete'])): ?>
|
||||
<?php if (UserRight::edit() || UserRight::del()): ?>
|
||||
<?php if (!empty($ignoreIds)): ?>
|
||||
<?php if (!in_array($td[$i], $ignoreIds)): ?>
|
||||
<?= $i == 0 ? '<input onclick="checkSingle(this)" data-del="' . $td['id'] . '" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php else: ?>
|
||||
<?= $i == 0 ? '<input disabled class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<?= $i == 0 ? '<input onclick="checkSingle(this)" data-del="' . $td['id'] . '" class="delete-checkbox" type="checkbox">' : '' ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?= $td[$i] ?>
|
||||
</td>
|
||||
<?php $i++;endforeach; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
|
||||
<tr>
|
||||
<td colspan="<?= sizeof($th) ?>" style="background: #fff"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ct" style="font-size: 16px; padding: 20px"
|
||||
colspan="<?= sizeof($th) ?>"><?= isset($_GET['q']) ? Yii::t('cms', 'No data found') : Yii::t('cms', 'No data has been added') ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (!empty($data['list'])): ?>
|
||||
<?= $this->render('includes/pagination', ['data' => $data]) ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
<script src="/_public/assets/js/order.js"></script>
|
||||
|
||||
<script>
|
||||
let sl = [];
|
||||
|
||||
function checkAll(el) {
|
||||
sl = [];
|
||||
all('td [data-del]').forEach(e => {
|
||||
e.checked = el.checked === true;
|
||||
if (el.checked) {
|
||||
sl.push(e.dataset.del);
|
||||
e.parentNode.parentNode.addClass('checked');
|
||||
} else {
|
||||
e.parentNode.parentNode.removeClass('checked');
|
||||
}
|
||||
|
||||
})
|
||||
updateActionButtons();
|
||||
}
|
||||
|
||||
function checkSingle(e) {
|
||||
if (e) {
|
||||
if (e.checked) {
|
||||
sl.push(e.dataset.del);
|
||||
e.parentNode.parentNode.addClass('checked');
|
||||
} else {
|
||||
let checkedAll = one('#checkAll')
|
||||
if (checkedAll) {
|
||||
checkedAll.checked = false;
|
||||
}
|
||||
e.parentNode.parentNode.removeClass('checked');
|
||||
const f = sl.indexOf(e.dataset.del);
|
||||
sl.splice(f, 1);
|
||||
}
|
||||
updateActionButtons(e.dataset.del);
|
||||
}
|
||||
}
|
||||
|
||||
function updateActionButtons() {
|
||||
const bEdit = one('#bEdit');
|
||||
const bDelete = one('#bDelete');
|
||||
const delCount = one('#delCount');
|
||||
const c = sl.length;
|
||||
if (delCount)
|
||||
delCount.innerText = '(' + c + ')';
|
||||
if (c > 0) {
|
||||
if (bDelete)
|
||||
bDelete.removeClass('disabled');
|
||||
if (bEdit) {
|
||||
if (c < 2) {
|
||||
bEdit.href = window.getUri('o=w&id=' + sl[0])
|
||||
bEdit.removeClass('disabled');
|
||||
} else {
|
||||
bEdit.addClass('disabled');
|
||||
bEdit.href = '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (bEdit)
|
||||
bEdit.addClass('disabled');
|
||||
if (bDelete)
|
||||
bDelete.addClass('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function checkDelete(e) {
|
||||
const msg = 'Сигурни ли сте, че искате да изтриете ' + (sl.length > 1 ? 'тези ' + sl.length + ' записа?' : 'този запис?');
|
||||
modal.confirm(msg, () => {
|
||||
request({
|
||||
url: window.getUri('o=d'),
|
||||
post: {
|
||||
ids: JSON.stringify(sl),
|
||||
model: e.dataset.model
|
||||
},
|
||||
done: e => {
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
window.onscroll = function () {
|
||||
const ab = one('.action-buttons');
|
||||
if (ab) {
|
||||
if (window.pageYOffset > ab.offsetTop) {
|
||||
ab.addClass('buttons-top')
|
||||
} else {
|
||||
ab.removeClass('buttons-top')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
all('.delete-checkbox', input => {
|
||||
input.checked = false;
|
||||
})
|
||||
})
|
||||
|
||||
orderItems('[data-index]', '?update-indexes=1', function () {
|
||||
});
|
||||
</script>
|
||||
<?php if (!UserRight::pub()): ?>
|
||||
<script>
|
||||
document.querySelectorAll('[data-key="on_partner_page"], [data-key="is_for_publish"], [data-key="partner_page_selected"]').forEach(e => {
|
||||
e.removeAttribute('onchange')
|
||||
})
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user