Skip to content

Commit

Permalink
Merge pull request #994 from SmoKE585/alpha
Browse files Browse the repository at this point in the history
Оповещения для модулей
  • Loading branch information
sergejey authored Aug 9, 2021
2 parents 2fc5f2f + 55c0e83 commit dc35879
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 11 deletions.
18 changes: 12 additions & 6 deletions 3rdparty/bootstrap/css/bootstrap.min.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.notyBody::-webkit-scrollbar { width: 7px; height: 10px;}
.notyBody::-webkit-scrollbar-button { display:none; }
.notyBody::-webkit-scrollbar-track { background-color: #4792d1;}
.notyBody::-webkit-scrollbar-track-piece { background-color: #ffffff;}
.notyBody::-webkit-scrollbar-thumb { height: 30px; background-color: #4792d1; border-radius: 3px;}
.notyBody::-webkit-scrollbar-corner { background-color: #999;}
.notyBody::-webkit-resizer { background-color: #4792d1;}

/*! * Bootstrap v3.0.0 * * Copyright 2013 Twitter, Inc * Licensed under the Apache License v2.0 * http://www.apache.org/licenses/LICENSE-2.0 * * Designed and built with all the love in the world by @mdo and @fat. *//*! normalize.css v2.1.0 | MIT License | git.io/normalize */
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary
{
Expand Down Expand Up @@ -2959,7 +2967,7 @@
z-index:1000;
display:none;
float:left;
min-width:160px;
min-width:220px;
padding:5px 0;
margin:2px 0 0;
font-size:14px;
Expand Down Expand Up @@ -5490,8 +5498,7 @@
text-align:left;
white-space:normal;
background-color:#fff;
border:1px solid #ccc;
border:1px solid rgba(0,0,0,0.2);
border:1px solid rgb(71 146 209);
border-radius:6px;
-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);
box-shadow:0 5px 10px rgba(0,0,0,0.2);
Expand Down Expand Up @@ -5526,7 +5533,7 @@
}
.popover-content
{
padding:9px 14px
padding: 5px 10px;
}
.popover .arrow,.popover .arrow:after
{
Expand Down Expand Up @@ -5568,8 +5575,7 @@
top:50%;
left:-11px;
margin-top:-11px;
border-right-color:#999;
border-right-color:rgba(0,0,0,0.25);
border-right-color:rgb(71 146 209);
border-left-width:0
}
.popover.right .arrow:after
Expand Down
44 changes: 44 additions & 0 deletions lib/module.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,48 @@ public function codeParams($in)

return $res_str;
}

public function sendnotification($str, $type = 'default')
{
if($type != 'info' && $type != 'danger' && $type != 'warning' && $type != 'success' && $type != 'default') {
$type = 'default';
}

$rec["ADD"] = time();
$rec["TYPE"] = $type;
$rec["PLUGINS_ID"] = SQLSelectOne("SELECT `ID` FROM `plugins` WHERE `MODULE_NAME` = '".$this->name."'")['ID'];
$rec["MESSAGE"] = htmlspecialchars(strip_tags($str));
$rec["READ"] = 0;

if(!$rec["PLUGINS_ID"]) return json_encode(array('status' => false, 'error' => 'Only extension plugins allowed! Not system plugins!'));

if(SQLSelectOne("SELECT COUNT(*) AS TOTAL_UNREAD FROM `plugins_noty` WHERE `PLUGINS_ID` = '".$rec["PLUGINS_ID"]."' AND `READ` = '0'")['TOTAL_UNREAD'] > 10) {
return json_encode(array('status' => false, 'error' => 'More than 10 notifications in the unread status.'));
}

$ifExest = SQLSelectOne("SELECT ID FROM `plugins_noty` WHERE `MESSAGE` = '".$str."' AND `READ` = '0'")['ID'];
if($ifExest['ID']) {
return json_encode(array('status' => false, 'error' => 'Such a record already exists. ID - '.$ifExest['ID'], 'id' => $ifExest['ID']));
}

$rec["ID"] = SQLInsert("plugins_noty", $rec);

return json_encode(array('status' => true, 'id' => $rec["ID"]));

}

public function readnotification($noty_id)
{
$rec["ID"] = $noty_id;
$rec["READ"] = 1;

if(empty(SQLSelectOne("SELECT ID FROM `plugins_noty` WHERE `ID` = '".$rec["ID"]."' AND `READ` = '0'")['ID'])) {
return json_encode(array('status' => false, 'error' => 'No such noty found'));
}

SQLUpdate("plugins_noty", $rec);

return json_encode(array('status' => true));

}
}
5 changes: 5 additions & 0 deletions modules/market/market.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ function admin(&$out)
}
exit;
}

if ($this->ajax && $_GET['op'] == 'readNoty' && !empty($this->id)) {
echo $this->readnotification($this->id);
exit;
}

if ($this->ajax && $_GET['op'] == 'news') {
$result = $this->marketRequest('op=news', 15*60); //15*60
Expand Down
20 changes: 19 additions & 1 deletion modules/panel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,25 @@ function run()
} else {
$last_allow = $i;
}


if(preg_match('|<#(.*?)#>|si', $modules[$i]['TITLE'], $arr)) {
$titleSearchNoty = constant($arr[1]);
} else {
$titleSearchNoty = $modules[$i]['NAME'];
}

$getNOTY = SQLSelect("SELECT * FROM `plugins_noty` WHERE `PLUGINS_ID` = (SELECT ID FROM `plugins` WHERE `MODULE_NAME` = '".$titleSearchNoty."') AND `READ` = 0 ORDER BY `ADD` DESC LIMIT 10");

if(!empty($getNOTY)) {
$modules[$i]['PLUGINS_NOTY_COUNT'] = count($getNOTY);
$modules[$i]['PLUGINS_NOTY_COLOR'] = $getNOTY[0]['TYPE'];
$modules[$i]['PLUGINS_ID'] = $getNOTY[0]['PLUGINS_ID'];
$modules[$i]['PLUGINS_NOTY'] = $getNOTY;
} else {
$modules[$i]['PLUGINS_NOTY_COUNT'] = 0;
$modules[$i]['PLUGINS_ID'] = $getNOTY[0]['PLUGINS_ID'];
}

if (file_exists(ROOT . 'img/modules/' . $modules[$i]['NAME'] . '.png')) {
$modules[$i]['ICON_SM'] = ROOTHTML . 'img/modules/' . $modules[$i]['NAME'] . '.png';
} else {
Expand Down
7 changes: 7 additions & 0 deletions modules/scripts/scripts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ function dbInstall($data)
safe_execs: EXCLUSIVE int(3) NOT NULL DEFAULT 0
safe_execs: PRIORITY int(10) NOT NULL DEFAULT 0
safe_execs: ADDED datetime
plugins_noty: ID int(15) unsigned NOT NULL auto_increment
plugins_noty: PLUGINS_ID int(15) NOT NULL DEFAULT 0
plugins_noty: MESSAGE varchar(80) NOT NULL DEFAULT ''
plugins_noty: TYPE varchar(50) NOT NULL DEFAULT 'info'
plugins_noty: READ int(2) NOT NULL DEFAULT 0
plugins_noty: ADD int(15) NOT NULL DEFAULT 0
EOD;
parent::dbInstall($data);
Expand Down
93 changes: 90 additions & 3 deletions templates/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,30 @@
</ul>
</li>
[#else LINKS#]
<li class="[#if SELECTED#]active[#endif#] category[#CATEGORY_ID#]" id="module_[#NAME#]_link"><a href='<#ROOTHTML#>admin.php?action=[#NAME#]' class="top-menu"><img src="[#ICON_SM#]" width="24" height="24">&nbsp;[#TITLE#]</a></li>
<li class="[#if SELECTED#]active[#endif#] category[#CATEGORY_ID#]" id="module_[#NAME#]_link">
<a href='<#ROOTHTML#>admin.php?action=[#NAME#]' class="top-menu"><img src="[#ICON_SM#]" width="24" height="24">&nbsp;[#TITLE#]
[#if PLUGINS_NOTY_COUNT != 0#]
<div id="plugNotyBtn_[#PLUGINS_ID#]" class="plugNotyBtn badge pull-right alert-[#PLUGINS_NOTY_COLOR#]" style="border: 1px solid;cursor: pointer;" data-container="body" data-toggle="popover" data-trigger="manual" data-placement="bottom" data-html="true" data-content="
<div style='min-width: 25rem;'>
<div style='font-size: 1rem;float:left'>Уведомление от модуля <b>[#TITLE#]</b></div>
<div style='font-size: 1rem;float:right;cursor: pointer;color: red;' onclick='closePopover([#PLUGINS_ID#]);'><i class='glyphicon glyphicon-remove-circle'></i></div>
<div class='clearfix'></div>
<hr style='margin: 0px 0px 5px 0px;'>
</div>
<div class='notyBody' id='notyBody_[#PLUGINS_ID#]' style='max-height: 200px;overflow-y: auto;overflow-x: hidden;'>
[#begin PLUGINS_NOTY#]
<div id='notyAlert_[#ID#]' class='plugNotyAlert alert alert-[#TYPE#]' onclick='readNoty([#ID#], [#PLUGINS_ID#])' style='padding: 5px 7px;margin: 0px 10px 5px 0px;font-size: 1.2rem;cursor:pointer;'>
<i class='glyphicon glyphicon-bullhorn'></i> [#MESSAGE#]
</div>
[#end PLUGINS_NOTY#]
<div style='text-align: center;font-size: 1.2rem;margin-top: 10px;'><a href='https://mjdm.ru/forum/viewtopic.php?f=7&p=128996#p128996' target= '_blank'>Что это?</a></div>
</div>
" data-original-title="">[#PLUGINS_NOTY_COUNT#]</div>
[#endif PLUGINS_NOTY#]
</a>
</li>
[#if NAME="xray"#]<li class="menu-item"><a href="#" onClick='return consoleToggle();'><i class="glyphicon glyphicon-flash"></i> <#LANG_CONSOLE#></a></li>[#endif#]
[#endif LINKS#]
[#endif DENIED#]
Expand Down Expand Up @@ -987,7 +1010,30 @@ <h4 class="panel-title">
<ul class="nav nav-list">
[#endif NEW_CATEGORY#]
[#if !DENIED#]
<li class="[#if SELECTED#]active[#endif#] category[#CATEGORY_ID#]" id="module_[#NAME#]_link"><a class="leftmenutab" href="?action=[#NAME#]"><img src="[#ICON_SM#]" style="width: 20px;height: 20px;">&nbsp;[#TITLE#]</a></li>
<li class="[#if SELECTED#]active[#endif#] category[#CATEGORY_ID#]" id="module_[#NAME#]_link">
<a class="leftmenutab" href="?action=[#NAME#]"><img src="[#ICON_SM#]" style="width: 20px;height: 20px;">&nbsp;[#TITLE#]
[#if PLUGINS_NOTY_COUNT != 0#]
<div id="plugNotyBtn_[#PLUGINS_ID#]" class="plugNotyBtn badge pull-right alert-[#PLUGINS_NOTY_COLOR#]" style="border: 1px solid;cursor: pointer;" data-container="body" data-toggle="popover" data-trigger="manual" data-placement="right" data-html="true" data-content="
<div style='min-width: 25rem;'>
<div style='font-size: 1rem;float:left'>Уведомление от модуля <b>[#TITLE#]</b></div>
<div style='font-size: 1rem;float:right;cursor: pointer;color: red;' onclick='closePopover([#PLUGINS_ID#]);'><i class='glyphicon glyphicon-remove-circle'></i></div>
<div class='clearfix'></div>
<hr style='margin: 0px 0px 5px 0px;'>
</div>
<div class='notyBody' id='notyBody_[#PLUGINS_ID#]' style='max-height: 200px;overflow-y: auto;overflow-x: hidden;'>
[#begin PLUGINS_NOTY#]
<div id='notyAlert_[#ID#]' class='plugNotyAlert alert alert-[#TYPE#]' onclick='readNoty([#ID#], [#PLUGINS_ID#])' style='padding: 5px 7px;margin: 0px 10px 5px 0px;font-size: 1.2rem;cursor:pointer;'>
<i class='glyphicon glyphicon-bullhorn'></i> [#MESSAGE#]
</div>
[#end PLUGINS_NOTY#]
<div style='text-align: center;font-size: 1.2rem;margin-top: 10px;'><a href='https://mjdm.ru/forum/viewtopic.php?f=7&p=128996#p128996' target= '_blank'>Что это?</a></div>
</div>
" data-original-title="">[#PLUGINS_NOTY_COUNT#]</div>
[#endif PLUGINS_NOTY#]
</a>
</li>
[#endif DENIED#]
[#if LAST_IN_CATEGORY#]
</ul>
Expand Down Expand Up @@ -1105,7 +1151,48 @@ <h4 class="panel-title">
});
}

$(document).ready(function() {
function readNoty(id, plugins_id) {
//Отправляем AJAX на прочтение
$.ajax({
url: '/ajax/market.html?op=readNoty&id='+id
}).done(function(data) {
data = JSON.parse(data);
if(data.status == true) {
countToEnd = Number($('#plugNotyBtn_'+plugins_id).text())-1;

$('#plugNotyBtn_'+plugins_id).text(countToEnd);
$('#notyAlert_'+id).hide('slow');

if(countToEnd == 0) {
$('#plugNotyBtn_'+plugins_id).popover('hide');
$('#plugNotyBtn_'+plugins_id).remove();
}
} else {
alert('Error processing messages from modules.');
}
});
}
function closePopover(id) {
$('#plugNotyBtn_'+id).popover('hide');
}

$(document).ready(function() {
//Прячем поповер при клике за пределами
$('body').on('click', function (e) {
$('[data-toggle=popover]').each(function () {
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
//Ноти
$("div.plugNotyBtn").hover(function() {
$(this).popover('show');
}, function() {
//$(this).popover('hide');
});


if ($(window).scrollTop() > 200 && (document.documentElement.scrollHeight - window.innerHeight) >= 200) {
$("nav").addClass("navbar-fixed-top");
$("nav").attr('style', 'box-shadow: 0px 1px 10px rgb(0 0 0 / 25%);z-index: 99999;border-radius: 4px;border-bottom: 2px solid #4792d1;');
Expand Down
2 changes: 1 addition & 1 deletion templates/panel_default.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ <h4 class="modal-title" id="myModalLabel"><#LANG_NEWDASH_DMB_TITLE_MODAL#></h4>
<div class="hidden-xs" onclick="hideHintCookie('howmaxdbsizehint');" style="margin-bottom: 20px;cursor:pointer;text-align: center;font-size: 7pt;margin-top: 5px;color: gray;font-style: italic;"><#LANG_NEWDASH_DONTSHOW_THIS_BLOCK#> <i class="glyphicon glyphicon-arrow-up"></i></div>
</div>

<div id="structureDB_chart" style="width: 100%;height: 300px;margin-bottom:10px"><center><img src="<#ROOTHTML#>img/ajax-loader.gif"/> <#LANG_NEWDASH_LOADING#></center></div>
<div id="structureDB_chart" style="border: 1px solid #e9e9e9;border-radius: 6px;width: 100%;height: 300px;margin-bottom:10px"><center><img src="<#ROOTHTML#>img/ajax-loader.gif"/> <#LANG_NEWDASH_LOADING#></center></div>

<!---
<div class="jumbotron" style="margin-bottom: 10px;border-radius: 5px;background-image: url(/img/main_img/scenario.png),radial-gradient(circle farthest-corner at 100px 50px, #ebfbf0, #69d147);background-size: contain;background-repeat: no-repeat;background-position: right center;">
Expand Down

0 comments on commit dc35879

Please sign in to comment.