All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit e0f61f7d authored by Jonathon Duerig's avatar Jonathon Duerig

Add announcement feature to portal interface

parent d480e1f5
<?php
#
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
chdir("..");
include_once("webtask.php");
include_once("geni_defs.php");
chdir("apt");
include_once("profile_defs.php");
include_once("instance_defs.php");
#
# User clicked the dismiss button on an announcement
#
function Do_Dismiss()
{
global $this_user, $ajax_args;
$uid_idx = $this_user->uid_idx();
$aid = $ajax_args['aid'];
$dblink = DBConnect("tbdb");
DBQueryWarn('update apt_announcement_info set dismissed=1 where aid="'.$aid.'" and uid_idx="'.$uid_idx.'"', $dblink);
}
#
# User clicked the action button on an announcement
#
function Do_Click()
{
global $this_user, $ajax_args;
$uid_idx = $this_user->uid_idx();
$aid = $ajax_args['aid'];
$dblink = DBConnect("tbdb");
DBQueryWarn('update apt_announcement_info set clicked=1 where aid="'.$aid.'" and uid_idx="'.$uid_idx.'"', $dblink);
}
......@@ -106,4 +106,41 @@ window.APT_OPTIONS.initialize = function (sup)
});
}
$('body').show();
}
};
APT_OPTIONS.CallServerMethod = function (url, route, method, args, callback)
{
// ignore url now.
url = 'https://' + window.location.host + '/apt/server-ajax.php';
url = 'server-ajax.php';
if (args == null) {
args = {"noargs" : "noargs"};
}
return $.ajax({
// the URL for the request
url: url,
success: callback,
// the data to send (will be converted to a query string)
data: {
ajax_route: route,
ajax_method: method,
ajax_args: args,
},
// whether this is a POST or GET request
type: "POST",
// the type of data we expect back
dataType : "json",
});
};
window.APT_OPTIONS.announceDismiss = function (aid) {
APT_OPTIONS.CallServerMethod('', 'announcement', 'Dismiss', {'aid': aid}, function(){});
};
window.APT_OPTIONS.announceClick = function (aid) {
APT_OPTIONS.CallServerMethod('', 'announcement', 'Click', {'aid': aid}, function(){});
};
......@@ -29,31 +29,8 @@ function HideWaitWait()
function CallServerMethod(url, route, method, args, callback)
{
// ignore url now.
url = 'https://' + window.location.host + '/apt/server-ajax.php';
url = 'server-ajax.php';
if (args == null) {
args = {"noargs" : "noargs"};
}
return $.ajax({
// the URL for the request
url: url,
success: callback,
// the data to send (will be converted to a query string)
data: {
ajax_route: route,
ajax_method: method,
ajax_args: args,
},
// whether this is a POST or GET request
type: "POST",
// the type of data we expect back
dataType : "json",
});
// Main body of function moved to common.js
return APT_OPTIONS.CallServerMethod(url, route, method, args, callback);
}
var jacksInstance;
......
......@@ -103,6 +103,7 @@ $PAGEHEADER_FUNCTION = function($thinheader = 0, $ignore1 = NULL,
if ($login_user && !($login_status & CHECKLOGIN_WEBONLY)) {
$showmenus = 1;
}
echo "<html>
<head>
<title>$title</title>
......@@ -296,6 +297,21 @@ $PAGEHEADER_FUNCTION = function($thinheader = 0, $ignore1 = NULL,
</div>
</div>\n";
# Put announcements, if any, right below the header.
if ($login_user && !($login_status & CHECKLOGIN_WEBONLY)) {
$announcements = GET_ANNOUNCEMENTS($login_user->uid_idx());
for ($i = 0; $i < count($announcements); $i++) {
$current = $announcements[$i];
echo "<div class='alert ".$current['style']." alert-dismissible'
role='alert' style='margin-top: -10px; margin-left: 40px; margin-right: 40px;'>";
echo " <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true' onclick='APT_OPTIONS.announceDismiss(" . $current['aid'] . ")'>&times;</span></button>";
echo " <span>" . $current["text"] . "</span>";
if ($current["url"]) {
echo " <a href='" . $current["url"] . "' class='btn btn-default' onclick='APT_OPTIONS.announceClick(" . $current["aid"] . ")' target='_blank'>" . $current["label"] . "</a>";
}
echo " </div>";
}
}
if (NOLOGINS()) {
$message = TBGetSiteVar("web/message");
}
......@@ -368,6 +384,40 @@ function SPITHEADER($thinheader = 0,
$PAGEHEADER_FUNCTION($thinheader, $ignore1, $ignore2, $ignore3);
}
function GET_ANNOUNCEMENTS($uid_idx)
{
global $PORTAL_GENESIS;
$dblink = DBConnect("tbdb");
# Add an apt_announcement_info entry for any announcements which don't have one
$query_result = DBQueryWarn('select a.idx from apt_announcements as a left join apt_announcement_info as i on a.idx=i.aid and ((a.uid_idx is NULL and i.uid_idx="'.$uid_idx.'") or (a.uid_idx is not NULL and a.uid_idx=i.uid_idx)) where a.genesis="'.$PORTAL_GENESIS.'" and a.retired=0 and i.uid_idx is NULL and (a.uid_idx is NULL or a.uid_idx="'.$uid_idx.'")');
while ($row = mysql_fetch_array($query_result, MYSQL_NUM)) {
DBQueryWarn('insert into apt_announcement_info set aid="'.$row[0].'", uid_idx="'.$uid_idx.'",seen_count=0');
}
$query_result = DBQueryWarn('select a.idx, a.text, a.link_label, a.link_url, i.seen_count, a.style '.
'from apt_announcements as a '.
'left join apt_announcement_info as i on a.idx=i.aid '.
'where (a.uid_idx is NULL or a.uid_idx="'.$uid_idx.'") and '.
'a.retired = 0 and a.genesis="'.$PORTAL_GENESIS.'" and '.
'i.uid_idx="'.$uid_idx.'" and '.
'i.dismissed = 0 and i.clicked = 0 and '.
'i.seen_count < 5', $dblink);
$result = array();
while ($row = mysql_fetch_array($query_result, MYSQL_NUM)) {
$item = array('text' => $row[1],
'style' => $row[5],
'label' => $row[2],
'aid' => $row[0],
'url' => $row[3]);
if ($row[3]) {
$item['url'] = preg_replace('/\{uid_idx\}/', $uid_idx, $row[3]);
}
array_push($result, $item);
DBQueryWarn('update apt_announcement_info set seen_count='.($row[4]+1).' where aid="'.$row[0].'" and uid_idx="'.$uid_idx.'"');
}
return $result;
}
$PAGEFOOTER_FUNCTION = function($ignored = NULL) {
global $PORTAL_HELPFORUM, $PORTAL_NSFNUMBER, $embedded;
......
......@@ -212,6 +212,13 @@ $routing = array("myprofiles" =>
"guest" => false,
"methods" => array("RankList" =>
"Do_RankList")),
"announcement" =>
array("file" => "announcement.ajax",
"guest" => false,
"methods" => array("Dismiss" =>
"Do_Dismiss",
"Click" =>
"Do_Click"))
);
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment