diff --git a/www/aptui/announcement.ajax b/www/aptui/announcement.ajax new file mode 100644 index 0000000000000000000000000000000000000000..ba7e02e44f4c5b8fbcb02ce68be4812262710937 --- /dev/null +++ b/www/aptui/announcement.ajax @@ -0,0 +1,53 @@ +. +# +# }}} +# +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); +} diff --git a/www/aptui/js/common.js b/www/aptui/js/common.js index af094d93e05c1eb06f3bc4f5c0cf7bcd3c5c5514..d00f33b3e6e20406420c0257552a02d665eebd7b 100644 --- a/www/aptui/js/common.js +++ b/www/aptui/js/common.js @@ -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(){}); +}; diff --git a/www/aptui/js/quickvm_sup.js b/www/aptui/js/quickvm_sup.js index e682f1635194a2eacbb4a240fec99c677a158527..9bf9e628ece0449c0205b2732fa66d4b8af6b181 100755 --- a/www/aptui/js/quickvm_sup.js +++ b/www/aptui/js/quickvm_sup.js @@ -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; diff --git a/www/aptui/quickvm_sup.php b/www/aptui/quickvm_sup.php index 39f8d98133f32e6527002cb48117b9b5ff440827..4ba290fea00e0bf4860d982c8c144650fd187b4d 100644 --- a/www/aptui/quickvm_sup.php +++ b/www/aptui/quickvm_sup.php @@ -103,6 +103,7 @@ $PAGEHEADER_FUNCTION = function($thinheader = 0, $ignore1 = NULL, if ($login_user && !($login_status & CHECKLOGIN_WEBONLY)) { $showmenus = 1; } + echo " $title @@ -296,6 +297,21 @@ $PAGEHEADER_FUNCTION = function($thinheader = 0, $ignore1 = NULL, \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 ""; + } + } 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; diff --git a/www/aptui/server-ajax.php b/www/aptui/server-ajax.php index 74085882ec8f484ab4fb5dcb1bf324f6e6417c7c..edaa881b6dc20d52e40b92fd77837076eeca47ff 100644 --- a/www/aptui/server-ajax.php +++ b/www/aptui/server-ajax.php @@ -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")) ); #