From c4e33fc943cf30721c56b0e4bbe0485b634fcd9f Mon Sep 17 00:00:00 2001 From: Nael Date: Mon, 8 Jul 2013 23:21:28 +0200 Subject: [PATCH] implemented database query for poll bars --- uVote/api/votes/votes.php | 21 ++- uVote/page/PageApi.php | 3 + uVote/page/default_page/closedvoteinfo.tpl | 10 +- uVote/page/default_page/js/loadtexts.js | 163 +-------------------- uVote/page/default_page/openvoteinfo.tpl | 12 +- uVote/page/default_page/vote.tpl | 2 +- 6 files changed, 44 insertions(+), 167 deletions(-) diff --git a/uVote/api/votes/votes.php b/uVote/api/votes/votes.php index da29f86..a1fd4f2 100644 --- a/uVote/api/votes/votes.php +++ b/uVote/api/votes/votes.php @@ -12,13 +12,30 @@ class votes { return $result; } + private static function getProgessbar($percentage){ + $vars = array('percentage' => $percentage); + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/closedvoteinfo.tpl'), $vars); + } public static function get_openinfo($poll_ID){ $con = new \SYSTEM\DB\Connection(new \DBD\uVote()); $res = $con->prepare( 'selVoteByID', 'SELECT * FROM `uvote_votes` WHERE `ID` = ?;', array($poll_ID)); - $result = $res->next(); - return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/openvoteinfo.tpl'),$result == NULL ? array() : $result); + $res = $res->next(); + $result = array(); + $parties = array('cdu', 'spd', 'fdp', 'b90', 'linke'); + $pb = ""; + $part = $con->prepare( 'selVoteByPoll_ID', + 'SELECT * FROM `uvote_votes_per_party` WHERE `poll_ID` =' .$poll_ID.';', + array($party, $votes_pro, $votes_contra, $nr_attending)); + foreach($parties as $party){ + $vars = array('votes_pro' => $party['votes_pro'], 'votes_contra' => $party['votes_contra'], 'nr_attending' => $party['nr_attending'],); + $pb .= self::getProgessbar($votes_pro); + } + $result['graph_right'] = $pb; + $result = array_merge($result,$res, $part); + + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/openvoteinfo.tpl'),$result); } public static function write_vote($poll_ID, $vote){ if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ diff --git a/uVote/page/PageApi.php b/uVote/page/PageApi.php index d6eb19c..7901c4a 100644 --- a/uVote/page/PageApi.php +++ b/uVote/page/PageApi.php @@ -38,6 +38,9 @@ class PageApi extends \SYSTEM\PAGE\PageClass { } public static function action_developer(){ + require_once '../system/sai/autoload.inc.php'; + //require_once 'dasense/sai/autoload.inc.php'; + //require_once 'dasense/sai/register_modules.php'; return new \SYSTEM\SAI\saigui();} } \ No newline at end of file diff --git a/uVote/page/default_page/closedvoteinfo.tpl b/uVote/page/default_page/closedvoteinfo.tpl index b5c6982..370b765 100644 --- a/uVote/page/default_page/closedvoteinfo.tpl +++ b/uVote/page/default_page/closedvoteinfo.tpl @@ -1,7 +1,3 @@ -
-
${text}

-
  • -

    ${text}

    -
    -
    \ No newline at end of file +
    +
    +
    \ No newline at end of file diff --git a/uVote/page/default_page/js/loadtexts.js b/uVote/page/default_page/js/loadtexts.js index 69b417c..780ebc8 100644 --- a/uVote/page/default_page/js/loadtexts.js +++ b/uVote/page/default_page/js/loadtexts.js @@ -16,9 +16,9 @@ $(document).ready(function() { vote_click($(this).attr('poll_ID'),3); }); - $('.btn_openvoteinfo').click(function () { + $('.btn_openvoteinfo').click(function () { if($("#openvoteinfo"+$(this).attr('poll_ID')).is(':visible')){ - $('#openvoteinfo'+$(this).attr('poll_ID')).slideUp('slow'); + $('#openvoteinfo'+$(this).attr('poll_ID')).slideUp('slow'); }else{ load_openvoteinfo($(this).attr('poll_ID')); } @@ -99,160 +99,13 @@ function load_openvoteinfo (poll_ID){ } function vote_click (poll_ID, vote) { - $.get('./api.php?call=vote&action=vote&poll_ID=' + poll_ID + '&vote=' + vote, function (data) { - dataTmp = data; - }).complete(function() { - alert (poll_ID); - }); -} - -function loadAjaxContent(url) { - var dataTmp; - $.get(url, function (data) { - dataTmp = data; - bodyelem = $("html,body"); - bodyelem.animate(); - }).complete(function() { - $('#site-content-wrapper').slideUp({duration: 'slow', - complete: function(){ - $('#site-content').html(dataTmp); - $('#site-content-wrapper').slideDown('slow'); - site_content_is_visible = true; - }}); - }); -} -function loadUrlPic(url_pic) { - var dataTmp; - $.get(url_pic, function (data) { - dataTmp = data; - bodyelem = $("html,body"); - bodyelem.animate(); - }).complete(function() { - $('.carousel-inner').slideUp({duration: 'slow', - complete: function(){ - $('#pic').html(dataTmp); - $('.carousel-inner').slideDown('slow'); - site_content_is_visible = true; - }}); - }); -} - -function loadApiPic(id) { - var dataTmp; - $.get('./api.php?call=img&id='+id, function (data) { - dataTmp = data; - bodyelem = $("html,body"); - bodyelem.animate(); - }).complete(function() { - - }); -}/* jQuery on document ready */ -$(document).ready(function() { - // handle navigation link click - $('.navbar ul li a').not('#menu_uvote').click(function () { - loadAjaxContent($(this).attr('url')); - - //loadUrlPic($(this).attr('url')); - }); - $('.btnvote_yes').click(function () { - vote_click($(this).attr('poll_ID'),1); - }); - $('.btnvote_no').click(function () { - vote_click($(this).attr('poll_ID'),2); - }); - $('.btnvote_off').click(function () { - vote_click($(this).attr('poll_ID'),3); - }); - - $('.btn_openvoteinfo').click(function () { - alert ("#openvoteinfo"+$(this).attr('poll_ID')('time_end')); - if($("#openvoteinfo"+$(this).attr('poll_ID')).not(":visible")){ - load_openvoteinfo($(this).attr('poll_ID')); - } - else{ - exit; + $.getJSON('./api.php?call=vote&action=vote&poll_ID=' + poll_ID + '&vote=' + vote, function(data) { + var items = []; + if(data.status == true){ + alert("sucess"); + } else { + alert(data.result.message); } - }); -// $('#register_btn').click(function () { -// account_create ($(this).attr ('#inputEmail')) -// }); - //jqBootstrapValidation - $("#form_register input").not("[type=submit]").jqBootstrapValidation( - { - preventSubmit: true, - submitError: function($form, event, errors) {}, - submitSuccess: function($form, event){ -// alert ('.api.php?call=account&action=create&username=' + $('#bt_login_user').val() + '&password_sha=' + $.sha1($('#bt_login_password').val()) + '&email=' + $('#bt_login_user').val() + '&locale=deDE'); - $.get('./api.php?call=account&action=create&username=' + $('#bt_login_user').val() + '&password_sha=' + $.sha1($('#bt_login_password').val()) + '&email=' + $('#bt_login_user').val() + '&locale=deDE', function (data) { - if(data == 1){ - window.location.reload(); - } else { - $('#help-block-user-password-combi-wrong').attr('style', 'display: block;'); - } - }); - event.preventDefault(); - } - }); - - $("#form_login input").not("[type=submit]").jqBootstrapValidation( - { - preventSubmit: true, - submitError: function($form, event, errors) {}, - submitSuccess: function($form, event){ -// alert ('.api.php?call=account&action=create&username=' + $('#bt_login_user').val() + '&password_sha=' + $.sha1($('#bt_login_password').val()) + '&email=' + $('#bt_login_user').val() + '&locale=deDE'); - $.get('./api.php?call=account&action=login&username=' + $('#login_email').val() + '&password_sha=' + $.sha1($('#login_password').val()) + '&password_md5=' + $.md5($('#login_password').val()), function (data) { - if(data == 1){ - window.location.reload(); - } else { - $('#help-block-user-password-combi-wrong').attr('style', 'display: block;'); - } - }); - event.preventDefault(); - } - }); - $("#form_logout input").not("[type=submit]").jqBootstrapValidation( - { - preventSubmit: true, - submitError: function($form, event, errors) {}, - submitSuccess: function($form, event){ - $.get('./api.php?call=account&action=logout', function (data) { - window.location.reload(); - }); - event.preventDefault(); - } - }); - -}); -function account_create(inputEmail, inputPassword){ - $.get('./api.php?call=account&action=create&username=' + NULL + '&password_sha=' + password + '&email=' + email + '&locale=deDE', function (data) { - dataTmp = data; - }).complete(function() { - - }); -} - -function load_openvoteinfo (poll_ID){ - var openvoteinfo; - $.get('./api.php?call=vote&action=openinfo&poll_ID=' + poll_ID, function (data) { - openvoteinfo = data; - bodyelem = $(""); - bodyelem.animate(); - }).complete(function() { - $('#openvoteinfo'+poll_ID).slideUp({duration: 'slow', - complete: function(){ - $('#openvoteinfo'+poll_ID).html(openvoteinfo); - $('#openvoteinfo'+poll_ID).slideDown('slow'); - site_content_is_visible = true; - }}); - }); - -} - -function vote_click (poll_ID, vote) { - $.get('./api.php?call=vote&action=vote&poll_ID=' + poll_ID + '&vote=' + vote, function (data) { - dataTmp = data; - }).complete(function() { - alert (poll_ID); }); } diff --git a/uVote/page/default_page/openvoteinfo.tpl b/uVote/page/default_page/openvoteinfo.tpl index bab18a4..63feff1 100644 --- a/uVote/page/default_page/openvoteinfo.tpl +++ b/uVote/page/default_page/openvoteinfo.tpl @@ -1,7 +1,15 @@ +${graph_right}
    -

    ${text}

    -
  • ${text}

    + + +
    +
    + +
    + +
    \ No newline at end of file diff --git a/uVote/page/default_page/vote.tpl b/uVote/page/default_page/vote.tpl index 7a6aec1..034891d 100644 --- a/uVote/page/default_page/vote.tpl +++ b/uVote/page/default_page/vote.tpl @@ -8,7 +8,7 @@ box-shadow: 1px 1px 4px 1px rgba(0, 0, 0, 0.5);">

    ${vote_title}

    -