diff options
author | Vinzenz Rosenkranz <v1r0x@users.noreply.github.com> | 2017-11-27 12:05:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-27 12:05:20 +0300 |
commit | 27b7ce87aaa57156c41db9e01300319a8cd63e22 (patch) | |
tree | 14ae7842f9d5903eefe03e0a442b15c9859b1e5e /templates | |
parent | d06d5a38250637116552502c64157e84019ff954 (diff) | |
parent | ffb151c2f7cc8368809e73b96025a4e097c84d85 (diff) |
Merge branch 'develop' into fix-line-break
Diffstat (limited to 'templates')
-rw-r--r-- | templates/create.tmpl.php | 45 | ||||
-rw-r--r-- | templates/goto.tmpl.php | 769 | ||||
-rw-r--r-- | templates/main.tmpl.php | 121 | ||||
-rw-r--r-- | templates/no.acc.tmpl.php | 22 | ||||
-rw-r--r-- | templates/no.create.tmpl.php | 40 | ||||
-rw-r--r-- | templates/no.delete.tmpl.php | 40 |
6 files changed, 616 insertions, 421 deletions
diff --git a/templates/create.tmpl.php b/templates/create.tmpl.php index 1b7c178e..fa022046 100644 --- a/templates/create.tmpl.php +++ b/templates/create.tmpl.php @@ -23,25 +23,29 @@ \OCP\Util::addStyle('polls', 'main'); \OCP\Util::addStyle('polls', 'createpoll'); - \OCP\Util::addStyle('polls', 'jquery.datetimepicker'); + \OCP\Util::addStyle('polls', 'vendor/jquery.datetimepicker'); \OCP\Util::addScript('polls', 'create_edit'); \OCP\Util::addScript('polls', 'vendor/jquery.datetimepicker.full.min'); $userId = $_['userId']; + /** @var \OCP\IUserManager $userMgr */ $userMgr = $_['userMgr']; + /** @var \OCP\IURLGenerator $urlGenerator */ $urlGenerator = $_['urlGenerator']; - $isUpdate = isset($_['poll']) && $_['poll'] != null; + $isUpdate = isset($_['poll']) && $_['poll'] !== null; $isAnonymous = false; $hideNames = false; if ($isUpdate) { + /** @var OCA\Polls\Db\Event $poll */ $poll = $_['poll']; $isAnonymous = $poll->getIsAnonymous(); $hideNames = $isAnonymous && $poll->getFullAnonymous(); + /** @var OCA\Polls\Db\Date[]|OCA\Polls\Db\Text[] $dates */ $dates = $_['dates']; $chosen = '['; foreach ($dates as $d) { - if ($poll->getType() == '0') { + if ($poll->getType() === 0) { $chosen .= strtotime($d->getDt()); } else { $chosen .= '"' . $d->getText() . '"'; @@ -52,14 +56,15 @@ $chosen .= ']'; $title = $poll->getTitle(); $desc = $poll->getDescription(); - if ($poll->getExpire() != null) { + if ($poll->getExpire() !== null) { $expireTs = strtotime($poll->getExpire()) - 60*60*24; //remove one day, which has been added to expire at the end of a day $expireStr = date('d.m.Y', $expireTs); } $access = $poll->getAccess(); $accessTypes = $access; - if ( $access != 'registered' - && $access != 'hidden' && $access != 'public' + if ( + $access !== 'registered' + && $access !== 'hidden' && $access !== 'public' ) { $access = 'select'; } @@ -73,7 +78,7 @@ <div id="breadcrump"> <div class="crumb svg" data-dir="/"> <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>"> - <img class="svg" src="<?php print_unescaped(OCP\image_path("core", "places/home.svg")); ?>" alt="Home"> + <img class="svg" src="<?php print_unescaped(\OCP\Template::image_path('core', 'places/home.svg')); ?>" alt="Home"> </a> </div> <div class="crumb svg last"> @@ -87,7 +92,7 @@ </div> </div> </div> - + <?php if ($isUpdate): ?> <form name="finish_poll" action="<?php p($urlGenerator->linkToRoute('polls.page.update_poll')); ?>" method="POST"> <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" /> @@ -100,7 +105,7 @@ <header class="row"> </header> - + <div class="new_poll row"> <div class="col-50"> <label for="pollTitle" class="input_title"><?php p($l->t('Title')); ?></label> @@ -110,16 +115,16 @@ <label class="input_title"><?php p($l->t('Access')); ?></label> - <input type="radio" name="accessType" id="private" value="registered" class="radio" <?php if (!$isUpdate || $access == 'registered') print_unescaped('checked'); ?> /> + <input type="radio" name="accessType" id="private" value="registered" class="radio" <?php if (!$isUpdate || $access === 'registered') print_unescaped('checked'); ?> /> <label for="private"><?php p($l->t('Registered users only')); ?></label> - <input type="radio" name="accessType" id="hidden" value="hidden" class="radio" <?php if ($isUpdate && $access == 'hidden') print_unescaped('checked'); ?> /> + <input type="radio" name="accessType" id="hidden" value="hidden" class="radio" <?php if ($isUpdate && $access === 'hidden') print_unescaped('checked'); ?> /> <label for="hidden"><?php p($l->t('hidden')); ?></label> - <input type="radio" name="accessType" id="public" value="public" class="radio" <?php if ($isUpdate && $access == 'public') print_unescaped('checked'); ?> /> + <input type="radio" name="accessType" id="public" value="public" class="radio" <?php if ($isUpdate && $access === 'public') print_unescaped('checked'); ?> /> <label for="public"><?php p($l->t('Public access')); ?></label> - <input type="radio" name="accessType" id="select" value="select" class="radio" <?php if ($isUpdate && $access == 'select') print_unescaped('checked'); ?>> + <input type="radio" name="accessType" id="select" value="select" class="radio" <?php if ($isUpdate && $access === 'select') print_unescaped('checked'); ?>> <label for="select"><?php p($l->t('Select')); ?></label> <span id="id_label_select">...</span> @@ -135,7 +140,7 @@ </div> </div> - <input type="hidden" name="accessValues" id="accessValues" value="<?php if ($isUpdate && $access == 'select') p($accessTypes) ?>" /> + <input type="hidden" name="accessValues" id="accessValues" value="<?php if ($isUpdate && $access === 'select') p($accessTypes) ?>" /> <input id="isAnonymous" name="isAnonymous" type="checkbox" class="checkbox" <?php $isAnonymous ? print_unescaped('value="true" checked') : print_unescaped('value="false"'); ?> /> <label for="isAnonymous" class="input_title"><?php p($l->t('Anonymous')) ?></label> @@ -145,28 +150,28 @@ <label for="hideNames" class="input_title"><?php p($l->t('Hide user names for admin')) ?></label> </div> - <input id="id_expire_set" name="check_expire" type="checkbox" class="checkbox" <?php ($isUpdate && $poll->getExpire() != null) ? print_unescaped('value="true" checked') : print_unescaped('value="false"'); ?> /> + <input id="id_expire_set" name="check_expire" type="checkbox" class="checkbox" <?php ($isUpdate && $poll->getExpire() !== null) ? print_unescaped('value="true" checked') : print_unescaped('value="false"'); ?> /> <label for="id_expire_set" class="input_title"><?php p($l->t('Expires')); ?></label> <div class="input-group" id="expiration"> - <input id="id_expire_date" type="text" required="" <?php (!$isUpdate || $poll->getExpire() == null) ? print_unescaped('disabled="true"') : print_unescaped('value="' . $expireStr . '"'); ?> name="expire_date_input" /> + <input id="id_expire_date" type="text" required="" <?php (!$isUpdate || $poll->getExpire() === null) ? print_unescaped('disabled="true"') : print_unescaped('value="' . $expireStr . '"'); ?> name="expire_date_input" /> </div> </div> <div class="col-50"> - <input type="radio" name="pollType" id="event" value="event" class="radio" <?php if (!$isUpdate || $poll->getType() == '0') print_unescaped('checked'); ?> /> + <input type="radio" name="pollType" id="event" value="event" class="radio" <?php if (!$isUpdate || $poll->getType() === 0) print_unescaped('checked'); ?> /> <label for="event"><?php p($l->t('Event schedule')); ?></label> <!-- TODO texts to db --> - <input type="radio" name="pollType" id="text" value="text" class="radio" <?php if ($isUpdate && $poll->getType() == '1') print_unescaped('checked'); ?>> + <input type="radio" name="pollType" id="text" value="text" class="radio" <?php if ($isUpdate && $poll->getType() === 1) print_unescaped('checked'); ?>> <label for="text"><?php p($l->t('Text based')); ?></label> - <div id="date-select-container" <?php if ($isUpdate && $poll->getType() == '1') print_unescaped('style="display:none;"'); ?> > + <div id="date-select-container" <?php if ($isUpdate && $poll->getType() === 1) print_unescaped('style="display:none;"'); ?> > <label for="datetimepicker" class="input_title"><?php p($l->t('Dates')); ?></label> <input id="datetimepicker" type="text" /> <table id="selected-dates-table" class="choices"> </table> </div> - <div id="text-select-container" <?php if(!$isUpdate || $poll->getType() == '0') print_unescaped('style="display:none;"'); ?> > + <div id="text-select-container" <?php if(!$isUpdate || $poll->getType() === 0) print_unescaped('style="display:none;"'); ?> > <label for="text-title" class="input_title"><?php p($l->t('Text item')); ?></label> <div class="input-group"> <input type="text" id="text-title" placeholder="<?php print_unescaped('Insert text...'); ?>" /> diff --git a/templates/goto.tmpl.php b/templates/goto.tmpl.php index f04de991..d70028f3 100644 --- a/templates/goto.tmpl.php +++ b/templates/goto.tmpl.php @@ -1,4 +1,4 @@ -<?php +<?php /** * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> * @@ -25,375 +25,480 @@ \OCP\Util::addStyle('polls', 'main'); \OCP\Util::addStyle('polls', 'vote'); + if (!User::isLoggedIn()) { + \OCP\Util::addStyle('polls', 'public'); + } + + \OCP\Util::addScript('polls', 'app'); \OCP\Util::addScript('polls', 'vote'); - + $userId = $_['userId']; + /** @var \OCP\IUserManager $userMgr */ $userMgr = $_['userMgr']; + /** @var \OCP\IURLGenerator $urlGenerator */ $urlGenerator = $_['urlGenerator']; + /** @var \OCP\IAvatarManager $avaMgr */ $avaMgr = $_['avatarManager']; - + /** @var \OCA\Polls\Db\Event $poll */ $poll = $_['poll']; + /** @var OCA\Polls\Db\Date[]|OCA\Polls\Db\Text[] $dates */ $dates = $_['dates']; + /** @var OCA\Polls\Db\Participation[]|OCA\Polls\Db\ParticipationText[] $votes */ $votes = $_['votes']; + /** @var \OCA\Polls\Db\Comment[] $comments */ $comments = $_['comments']; - $isAnonymous = $poll->getIsAnonymous() && $userId != $poll->getOwner(); - $hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous(); + /** @var \OCA\Polls\Db\Notification $notification */ $notification = $_['notification']; - if ($poll->getExpire() == null) { + $isAnonymous = $poll->getIsAnonymous() && $userId !== $poll->getOwner(); + $hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous(); + $access = $poll->getAccess(); + if ($poll->getExpire() === null) { $expired = false; } else { $expired = time() > strtotime($poll->getExpire()); } -?> -<?php if($poll->getType() == '0') : ?> - <?php foreach($dates as $d) : ?> - <input class="hidden-dates" type="hidden" value="<?php print_unescaped($d->getDt()); ?>" /> - <?php endforeach ?> -<?php endif ?> - -<?php -if ( $poll->getDescription() != null - && $poll->getDescription() != '' -) { - $description = $poll->getDescription(); -} else { - $description = $l->t('No description provided.'); -} - -// init array for counting 'yes'-votes for each date -$total_y = array(); -$total_n = array(); -for ($i = 0 ; $i < count($dates) ; $i++) { - $total_y[$i] = 0; - $total_n[$i] = 0; -} -$user_voted = array(); - -$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]); + if ($expired) { + $statusClass = 'expired-vote'; + } else { + $statusClass = 'open-vote'; + if (time() < strtotime($poll->getExpire())) { + $statusClass .= ' endless'; + } + } + + if ($poll->getType() === 0) { + $pollType = 'date-poll'; + $pollTypeClass = 'date-poll'; + } else if ($poll->getType() === 1) { + $pollType = 'option-poll'; + $pollTypeClass = 'option-poll'; + } + + + if ( + $poll->getDescription() !== null && + $poll->getDescription() !== '' + ) { + $description = $poll->getDescription(); + } else { + $description = $l->t('No description provided.'); + } + + // init array for counting 'yes'-votes for each date + $total = array(); + for ($i = 0; $i < count($dates); $i++) { + $total['yes'][$i] = 0; + $total['no'][$i] = 0; + } + $userVoted = array(); + $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]); ?> <div id="app"> - <div id="app-content"> - <div id="app-content-wrapper"> - <div id="controls"> - <div id="breadcrump"> - <?php if (User::isLoggedIn()) : ?> - <div class="crumb svg" data-dir="/"> - <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>"> - <img class="svg" src="<?php print_unescaped(OCP\image_path("core", "places/home.svg")); ?>"" alt="Home"> - </a> - </div> - <div class="crumb svg last"> - <span><?php p($poll->getTitle()); ?></span> - </div> - <?php endif; ?> + <div id="app-content" class="<?php p($statusClass . ' ' . $pollTypeClass); ?>"> + <div id="controls" class="controls"> + <div id="breadcrump" class="breadcrump"> + <?php if (User::isLoggedIn()) : ?> + <div class="crumb svg" data-dir="/"> + <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>"> + <img class="svg" src="<?php print_unescaped(\OCP\Template::image_path('core', 'places/home.svg')); ?>" alt="Home"> + </a> + </div> + <?php endif; ?> + <div class="crumb svg last"> + <span><?php p($poll->getTitle()); ?></span> + </div> - <?php if (!User::isLoggedIn()) : ?> - <div class="col-100"> - <h2><?php p($poll->getTitle()); ?></h2> - </div> - <?php endif; ?> </div> + + + <a id="switchDetails" class="button details" title="Details" href="#"> + <span class="symbol icon-settings"></span> + <?php if (count($comments)) : ?> + <div id="comment-counter" class="badge"><?php p(count($comments)) ?></div> + <?php else: ?> + <div id="comment-counter" class="badge no-comments"><?php p(count($comments)) ?></div> + <?php endif; ?> + </a> + </div> + + <div id="votings" class="main-container"> + <div class="wordwrap description"><span><?php p($description); ?></span> + <?php + if ($expired) { + print_unescaped('<span class="' . $statusClass . '">' . $l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire())))) . '</span>'); + }?> </div> - <header class="row"> - </header> - <div class="row"> - <div class="col-70"> - <div class="wordwrap desc"><?php p($description); ?></div> - <div class="scroll_div"> - <table class="vote_table"> - <thead> - <?php - if ($poll->getType() == '0') { - print_unescaped('<tr id="time-slots-header"><th class="first_header_cell" colspan="3"></th>'); + <div class="table"> + <ul class="row header" > + <?php + foreach ($dates as $dateElement) { + if ($poll->getType() === 0) { + $timestamp = strtotime($dateElement->getDt()); + print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . $dateElement->getDt() . ' ' . date_default_timezone_get() . '" class="column vote time has-tooltip" data-timestamp="' . $timestamp . '"data-value-utc="' . $dateElement->getDt() . '">'); + + print_unescaped(' <div class="date-box column">'); + print_unescaped(' <div class="month">' . $l->t(date('M', $timestamp)) . '</div>'); + print_unescaped(' <div class="day">' . date('j', $timestamp) . '</div>'); + print_unescaped(' <div class="dayow">' . $l->t(date('D', $timestamp)) . '</div>'); + print_unescaped(' <div class="time">' . date('G:i', $timestamp) . ' UTC</div>'); + print_unescaped(' </div>'); + } else { + print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . preg_replace('/_\d+$/', '', $dateElement->getText()) . '" class="column vote option">'); + print_unescaped(' <div class="date-box column">' . preg_replace('/_\d+$/', '', $dateElement->getText()).'</div>'); + } + print_unescaped('<div class="counter row">'); + print_unescaped(' <div class="yes row">'); + print_unescaped(' <div class="svg"></div>'); + print_unescaped(' <div id="counter_yes_voteid_' . $dateElement->getId() . '" class ="result-cell yes" data-voteId="' . $dateElement->getId() . '">0</div>'); + print_unescaped(' </div>'); + print_unescaped(' <div class="no row">'); + print_unescaped(' <div class="svg"></div>'); + print_unescaped(' <div id="counter_no_voteid_' . $dateElement->getId() . '" class ="result-cell no" data-voteId="' . $dateElement->getId() . '">0</div>'); + print_unescaped(' </div>'); + print_unescaped('</div>'); + } + ?> + </li> + </ul> + <ul class="column table-body"> + <?php + if ($votes !== null) { + //group by user + $others = array(); + $displayName = ''; + $avatarName = ''; + $activeClass = ''; + foreach ($votes as $vote) { + if (!isset($others[$vote->getUserId()])) { + $others[$vote->getUserId()] = array(); + } + $others[$vote->getUserId()][]= $vote; + } + $userCnt = 0; + foreach (array_keys($others) as $usr) { + $userCnt++; + if ($usr === $userId) { + // if poll expired, just put current user among the others; + // otherwise skip here to add current user as last row (to vote) + if (!$expired) { + $userVoted = $others[$usr]; + continue; + } + } + if ( + $userMgr->get($usr) !== null && + !$isAnonymous && + !$hideNames + ) { + $displayName = $userMgr->get($usr)->getDisplayName(); + $avatarName = $usr; + } else { + if ($isAnonymous || $hideNames) { + $displayName = 'Anonymous'; + $avatarName = $userCnt; + } else { + $displayName = $usr; + $avatarName = $usr; + } + } + ?> + <li class="row user"> + <div class="first"> + <div class="user-cell row"> + <div class="avatar has-tooltip" title="<?php p($avatarName)?>"></div> + <div class="name"><?php p($displayName) ?></div> + </div> + </div> + <ul class="row"> + <?php + // loop over dts + $i_tot = 0; + + foreach ($dates as $dateElement) { + if ($poll->getType() === 0) { + $dateId = strtotime($dateElement->getDt()); + $pollId = 'voteid_' . $dateElement->getId(); + } else { + $dateId = $dateElement->getText(); + $pollId = 'voteid_' . $dateElement->getId(); + } + // look what user voted for this dts + $class = 'column poll-cell no'; + foreach ($others[$usr] as $vote) { + $voteVal = null; + if ($poll->getType() === 0) { + $voteVal = strtotime($vote->getDt()); } else { - print_unescaped('<tr id="vote-options-header"><th class="first_header_cell" colspan="3"></th>'); - foreach ($dates as $el) { - print_unescaped('<th title="' . preg_replace('/_\d+$/', '', $el->getText()) . '" class="vote-option">' . preg_replace('/_\d+$/', '', $el->getText()) . '</th>'); - } - } - print_unescaped('</tr>'); - ?> - </thead> - <tbody class="votes"> - <?php - if ($votes != null) { - //group by user - $others = array(); - foreach ($votes as $vote) { - if (!isset($others[$vote->getUserId()])) { - $others[$vote->getUserId()] = array(); - } - array_push($others[$vote->getUserId()], $vote); + $voteVal = $vote->getText(); } - $userCnt = 0; - foreach (array_keys($others) as $usr) { - $userCnt++; - if ($usr == $userId) { - // if poll expired, just put current user among the others; - // otherwise skip here to add current user as last row (to vote) - if (!$expired) { - $user_voted = $others[$usr]; - continue; - } - } - print_unescaped('<tr>'); - print_unescaped('<td class="avatar-cell">'); - if ( $userMgr->get($usr) != null - && !$isAnonymous && !$hideNames - ) { - print_unescaped('<div class="poll avatardiv" title="'.($usr).'"></div>'); - print_unescaped('</td>'); - print_unescaped('<td colspan="2" class="name">'); - p($userMgr->get($usr)->getDisplayName()); - } else { - if ($isAnonymous || $hideNames) { - print_unescaped('<div class="poll avatardiv" title="'.($userCnt).'"></div>'); - print_unescaped('</td>'); - print_unescaped('<td colspan="2" class="name">'); - } else { - print_unescaped('<div class="poll avatardiv" title="'.($usr).'"></div>'); - print_unescaped('</td>'); - print_unescaped('<td colspan="2" class="name">'); - p($usr); - } - } - print_unescaped('</td>'); - - // loop over dts - $i_tot = 0; - foreach ($dates as $dt) { - if ($poll->getType() == '0') { - $date_id = strtotime($dt->getDt()); - $poll_id = "pollid_" . $dt->getId(); - } else { - $date_id = $dt->getText(); - $poll_id = "pollid_" . $dt->getId(); - } - // look what user voted for this dts - $found = false; - foreach ($others[$usr] as $vote) { - $voteVal = null; - if ($poll->getType() == '0') { - $voteVal = strtotime($vote->getDt()); - } else { - $voteVal = $vote->getText(); - } - if ($date_id == $voteVal) { - if ($vote->getType() == '1') { - $cl = 'poll-cell yes'; - $total_y[$i_tot]++; - } else if ($vote->getType() == '0') { - $cl = 'poll-cell no'; - $total_n[$i_tot]++; - } else if ($vote->getType() == '2') { - $cl = 'poll-cell maybe'; - } else { - $cl = 'poll-cell unvoted'; - } - $found = true; - break; - } - } - if (!$found) { - $cl = 'poll-cell unvoted'; - } - // Make the td clickable - print_unescaped('<td class="' . $cl . '"><div></div></td>'); - // Make the div clickable - // print_unescaped('<td><div class="' . $cl . '"></div></td>'); - $i_tot++; + if ($dateId === $voteVal) { + if ($vote->getType() === 1) { + $class = 'column poll-cell yes'; + $total['yes'][$i_tot]++; + } else if ($vote->getType() === 0) { + $class = 'column poll-cell no'; + $total['no'][$i_tot]++; + } else if ($vote->getType() === 2) { + $class = 'column poll-cell maybe'; } - print_unescaped('</tr>'); + break; } } - $total_y_others = array_merge(array(), $total_y); - $total_n_others = array_merge(array(), $total_n); - if (!$expired) { - print_unescaped('<tr class="current-user">'); - print_unescaped('<td class="avatar-cell">'); - if (User::isLoggedIn()) { - print_unescaped('<div class="poll avatardiv" title="'.($userId).'"></div>'); - print_unescaped('</td>'); - print_unescaped('<td class="name">'); - p($userMgr->get($userId)->getDisplayName()); + print_unescaped('<li id="'. $pollId . '" class="' . $class . '"></li>'); + $i_tot++; + } + + print_unescaped('</ul>'); + print_unescaped('</li>'); + } + } + $totalYesOthers = array_merge(array(), $total['yes']); + $totalNoOthers = array_merge(array(), $total['no']); + $toggleTooltip = $l->t('Switch all options at once'); + if (!$expired) { + print_unescaped('<li class="row user current-user">'); + print_unescaped(' <div class="row first">'); + print_unescaped(' <div class="user-cell row">'); + if (User::isLoggedIn()) { + print_unescaped(' <div class="avatar has-tooltip" title="'.($userId).'"></div>'); + print_unescaped(' <div class="name">'); + p($userMgr->get($userId)->getDisplayName()); + } else { + print_unescaped(' <div class="avatar has-tooltip" title="?"></div>'); + print_unescaped(' <div id="id_ac_detected" class="name external current-user"><input type="text" name="user_name" id="user_name" placeholder="' . $l->t('Your name here') . '" />'); + } + print_unescaped(' </div>'); + print_unescaped(' </div>'); + print_unescaped(' <div id="toggle-cell" class="toggle-cell has-tooltip maybe" title="'. $toggleTooltip .'">'); + print_unescaped(' <div class="toggle"></div>'); + print_unescaped(' </div>'); + print_unescaped('</div>'); + print_unescaped('<ul class="row">'); + + $i_tot = 0; + foreach ($dates as $dateElement) { + if ($poll->getType() === 0) { + $dateId = strtotime($dateElement->getDt()); + $pollId = 'voteid_' . $dateElement->getId(); + } else { + $dateId = $dateElement->getText(); + $pollId = 'voteid_' . $dateElement->getId(); + } + // see if user already has data for this event + $class = 'no'; + $activeClass = 'column active poll-cell'; + if (isset($userVoted)) { + foreach ($userVoted as $obj) { + $voteVal = null; + if($poll->getType() === 0) { + $voteVal = strtotime($obj->getDt()); } else { - print_unescaped('<div class="poll avatardiv" title="?"></div>'); - print_unescaped('</td>'); - print_unescaped('<td id="id_ac_detected" class="external current-user"><input type="text" name="user_name" id="user_name" placeholder="' . $l->t('Your name here') . '" />'); + $voteVal = $obj->getText(); } - print_unescaped('</td><td class="toggle-all toggle maybe"><div id="toggle" class=""></div><img class="svg" src="../../../../core/img/actions/play-next.svg" "="" alt=""></td>'); - // print_unescaped('</td><td class="toggle-cell"><div id="toggle" class="toggle-all toggle maybe"></div><img class="svg" src="../../../../core/img/actions/play-next.svg" "="" alt=""></td>'); - $i_tot = 0; - foreach ($dates as $dt) { - if ($poll->getType() == '0') { - $date_id = strtotime($dt->getDt()); - $poll_id = "pollid_" . $dt->getId(); - } else { - $date_id = $dt->getText(); - $poll_id = "pollid_" . $dt->getId(); + if ($voteVal === $dateId) { + if ($obj->getType() === 1) { + $class = 'yes'; + $total['yes'][$i_tot]++; + } else if($obj->getType() === 2) { + $class = 'maybe'; } - // see if user already has data for this event - $cl = 'poll-cell active unvoted '; - if (isset($user_voted)) { - foreach ($user_voted as $obj) { - $voteVal = null; - if($poll->getType() == '0') { - $voteVal = strtotime($obj->getDt()); - } else { - $voteVal = $obj->getText(); - } - if ($voteVal == $date_id) { - if ($obj->getType() == '1') { - $cl = 'poll-cell active yes'; - $total_y[$i_tot]++; - } else if ($obj->getType() == '0') { - $cl = 'poll-cell active no'; - $total_n[$i_tot]++; - } else if($obj->getType() == '2') { - $cl = 'poll-cell active maybe'; - } - break; - } - } - } - // Make the td clickable - print_unescaped('<td id="' . $poll_id . '" class="cl_click ' . $cl . '" data-value="' . $date_id . '"><div></div></td>'); - // Make the div clickable - // print_unescaped('<td><div id="' . $date_id . '" class="cl_click ' . $cl . '"></div></td>'); - - $i_tot++; + break; } } - ?> - </tbody> - <tbody class="summary"> - <?php - $diff_array = $total_y; - for($i = 0 ; $i < count($diff_array) ; $i++) { - $diff_array[$i] = ($total_y[$i] - $total_n[$i]); - } - $max_votes = max($diff_array); - ?> - <tr class="total"> - <th colspan="3"><?php p($l->t('Total')); ?></th> - <?php for ($i = 0 ; $i < count($dates) ; $i++) : ?> - <td class="total"> - <?php - $classSuffix = "pollid_" . $dates[$i]->getId(); - if (isset($total_y[$i])) { - $val = $total_y[$i]; - } else { - $val = 0; - } - ?> - <div id="id_y_<?php p($classSuffix); ?>" class="result-cell yes" data-value=<?php p(isset($total_y_others[$i]) ? $total_y_others[$i] : '0'); ?>> - <?php p($val); ?> - </div> - <div id="id_n_<?php p($classSuffix); ?>" class="result-cell no" data-value=<?php p(isset($total_n_others[$i]) ? $total_n_others[$i] : '0'); ?>> - <?php p(isset($total_n[$i]) ? $total_n[$i] : '0'); ?> - </div> - </td> - <?php endfor; ?> - </tr> - <tr class="best"> - <th colspan="3"><?php p($l->t('Best option')); ?></th> - <?php - for ($i = 0; $i < count($dates); $i++) { - $check = ''; - if ($total_y[$i] - $total_n[$i] == $max_votes) { - $check = 'icon-checkmark'; - } - print_unescaped('<td class="win_row ' . $check . '" id="id_total_' . $i . '"></td>'); - } - ?> - </tr> - </tbody> - </table> - <form class="finish_vote" name="finish_vote" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_vote')); ?>" method="POST"> - <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" /> - <input type="hidden" name="userId" value="<?php p($userId); ?>" /> - <input type="hidden" name="dates" value="<?php p($poll->getId()); ?>" /> - <input type="hidden" name="types" value="<?php p($poll->getId()); ?>" /> - <input type="hidden" name="receiveNotifications" /> - <input type="hidden" name="changed" /> - <input type="button" id="submit_finish_vote" class="button btn" value="<?php p($l->t('Vote!')); ?>" /> - </form> - <?php if (User::isLoggedIn()) : ?> - <span class="notification"> - <input type="checkbox" id="check_notif" class="checkbox" <?php if ($notification != null) print_unescaped(' checked'); ?> /> - <label for="check_notif"><?php p($l->t('Receive notification email on activity')); ?></label> - </span> - <?php endif; ?> + } + print_unescaped('<li id="' . $pollId . '" class="' . $activeClass . ' ' . $class . '" data-value="' . $dateId . '"></li>'); + + $i_tot++; + } + print_unescaped('</ul>'); + print_unescaped('</li>'); + } + ?> + </ul> + </div> + <div class="submitPoll row"> + <div> + <form class="finish_vote" name="finish_vote" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_vote')); ?>" method="POST"> + <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" /> + <input type="hidden" name="userId" value="<?php p($userId); ?>" /> + <input type="hidden" name="dates" value="<?php p($poll->getId()); ?>" /> + <input type="hidden" name="types" value="<?php p($poll->getId()); ?>" /> + <input type="hidden" name="receiveNotifications" /> + <input type="hidden" name="changed" /> + <input type="button" id="submit_finish_vote" class="button btn" value="<?php p($l->t('Vote!')); ?>" /> + </form> + </div> + <?php if (User::isLoggedIn()) : ?> + <div class="notification"> + <input type="checkbox" id="check_notif" class="checkbox" <?php if ($notification !== null) print_unescaped(' checked'); ?> /> + <label for="check_notif"><?php p($l->t('Receive notification email on activity')); ?></label> + </div> + <?php endif; ?> + </div> + </div> + + <div id="app-sidebar" class="detailsView scroll-container disappear"> + <div class="close row"> + <a id="closeDetails" class="close icon-close" href="#" alt="<?php $l->t('Close');?>"></a> + </div> + + <div class="header row"> + <div class="pollInformation column"> + <div class="authorRow user-cell row"> + <div class="description leftLabel"><?php p($l->t('Owner')); ?></div> + <div class="avatar has-tooltip" title="<?php p($poll->getOwner())?>"></div> + <div class="author"><?php p($userMgr->get($poll->getOwner())->getDisplayName()); ?></div> + </div> + + <div class="cloud"> + <?php + if ($expired) { + print_unescaped('<span class="expired">' . $l->t('Expired'). '</span>'); + } else { + if ($poll->getExpire() !== null){ + print_unescaped('<span class="open">' . $l->t('Expires on %s', array(date('d.m.Y', strtotime($poll->getExpire())))) . '</span>'); + } else { + print_unescaped('<span class="open">' . $l->t('Expires never') . '</span>'); + } + } + + if ($access === 'public' || $access === 'hidden' || $access === 'registered') { + print_unescaped('<span class="information">' . $access . '</span>'); + } else { + print_unescaped('<span class="information">' . $l->t('Invitation access') . '</span>'); + } + if ($isAnonymous) { + print_unescaped('<span class="information">' . $l->t('Anononymous poll') . '</span>'); + if ($hideNames) { + print_unescaped('<span class="information">' . $l->t('Usernames hidden to Owner') . '</span>'); + } else { + print_unescaped('<span class="information">' . $l->t('Usernames visible to Owner') . '</span>'); + } + } + ?> </div> + + </div> + <div class="pollActions column"> + <ul class="with-icons"> + <li> + <a id="id_copy_<?php p($poll->getId()); ?>" class="icon-clippy svg copy-link" data-clipboard-text="<?php p($pollUrl); ?>" title="<?php p($l->t('Click to get link')); ?>" href="#"> + <?php p($l->t('Copy Link')); ?> + </a> + </li> + + <?php if ($poll->getOwner() === $userId) : ?> + <li class=""> + <a id="id_del_<?php p($poll->getId()); ?>" class="icon-delete svg delete-poll" data-value="<?php p($poll->getTitle()); ?>" href="#"> + <?php p($l->t('Delete poll')); ?> + </a> + </li> + <li> + <a id="id_edit_<?php p($poll->getId()); ?>" class="icon-rename svg" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>"> + <?php p($l->t('Edit Poll')); ?> + </a> + </li> + <?php endif; ?> + </ul> </div> - <div class="col-30"> - <div class="input-group share"> - <div class="input-group-addon"> - <span class="icon-share"></span><?php p($l->t('Link')); ?> + </div> + + + <?php if ($expired) : ?> + <div id="expired_info"> + <h2><?php p($l->t('Poll expired')); ?></h2> + <p> + <?php p($l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire()))))); ?> + </p> + </div> + <?php endif; ?> + <ul class="tabHeaders"> + <li class="tabHeader selected" data-tabid="commentsTabView" data-tabindex="0"> + <a href="#"><?php p($l->t('Comments')); ?></a> + </li> + </ul> + <div class="tabsContainer"> + <div id="commentsTabView" class="tab commentsTabView"> + <div class="newCommentRow comment new-comment"> + <?php if (User::isLoggedIn()) : ?> + <div class="authorRow user-cell row"> + <div class="avatar has-tooltip" title="<?php p($userId)?>"></div> + <div class="author"><?php p($userMgr->get($userId)->getDisplayName()) ?></div> </div> - <input type="text" value="<?php p($pollUrl);?>" readonly="readonly"> - </div> - <?php if ($expired) : ?> - <div id="expired_info"> - <h2><?php p($l->t('Poll expired')); ?></h2> - <p> - <?php p($l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire()))))); ?> - </p> + + <?php else: ?> + <a href="<?php p($urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); ?>"><?php p($l->t('Login or ...')); ?></a> + <div class="authorRow user-cell row"> + <div class="avatar has-tooltip" title="?"></div> + <div id="id_ac_detected" class="author column external"> + <input type="text" name="user_name_comm" id="user_name_comm" placeholder="<?php p($l->t('Your name here')); ?>" /> + </div> </div> <?php endif; ?> - <h2><?php p($l->t('Comments')); ?></h2> - <div class="comments"> - <div class="comment new-comment"> - <form name="send_comment" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_comment')); ?>" method="POST"> - <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" /> - <input type="hidden" name="userId" value="<?php p($userId); ?>" /> - <div class="comment-content"> - <?php if (!User::isLoggedIn()) : ?> - <a href="<?php p($urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); ?>"><?php p($l->t('Login')); ?></a> - <?php p($l->t('or')); ?> - <?php print_unescaped('<th id="id_ac_detected" class="external current-user"><input type="text" name="user_name_comm" id="user_name_comm" placeholder="' . $l->t('Your name here') . '" /></th>'); ?> - <?php else: ?> - <?php p($l->t('Logged in as') . ' ' . $userId); ?> - <?php endif; ?> - <textarea id="commentBox" name="commentBox"></textarea> - <p> - <input type="button" id="submit_send_comment" class="button btn" value="<?php p($l->t('Send!')); ?>" /> - <span class="icon-loading-small" style="float:right;"></span> - </p> - </div> - </form> - </div> - <?php if ($comments != null) : ?> - <?php foreach ($comments as $comment) : ?> - <div class="comment"> - <div class="comment-header"> - <?php - print_unescaped('<span class="comment-date">' . date('d.m.Y H:i:s', strtotime($comment->getDt())) . '</span>'); - if ($isAnonymous || $hideNames) { - p('Anonymous'); - } else { - if ($userMgr->get($comment->getUserId()) != null) { - p($userMgr->get($comment->getUserId())->getDisplayName()); - } else { - print_unescaped('<i>'); - p($comment->getUserId()); - print_unescaped('</i>'); - } - } - ?> - </div> - <div class="wordwrap comment-content"> - <?php p($comment->getComment()); ?> - </div> - </div> - <?php endforeach; ?> - <?php else : ?> - <?php p($l->t('No comments yet. Be the first.')); ?> - <?php endif; ?> + <form class="newCommentForm row" name="send_comment" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_comment')); ?>" method="POST"> + <input type="hidden" name="pollId" value="<?php p($poll->getId()); ?>" /> + <input type="hidden" name="userId" value="<?php p($userId); ?>" /> + <div id="commentBox" name="commentBox" class="message" data-placeholder="<?php p($l->t('New comment …'))?>" contenteditable="true"></div> + <input id="submit_send_comment" class="submitComment icon-confirm" value="" type="submit"> + <span class="icon-loading-small" style="float:right;"></span> + </form> </div> + + <ul class="comments column"> + + <?php if ($comments == null) : ?> + <li id="no-comments" class="emptycontent"> + <?php else : ?> + <li id="no-comments" class="emptycontent hidden"> + <?php endif; ?> + + <div class="icon-comment"></div> + <p><?php p($l->t('No comments yet. Be the first.')); ?></p> + </li> + + <?php foreach ($comments as $comment) : ?> + + <?php + if ( $comment->getUserId() === $userId ) { + // Comment is from current user + // -> display user + $avatarName = $userId; + $displayName = $userMgr->get($userId)->getDisplayName(); + + } else if ( !$isAnonymous && !$hideNames ) { + // comment is from another user, + // poll is not anoymous (for current user) + // users are not hidden + // -> display user + $avatarName = $comment->getUserId(); + $displayName = $avatarName; + if ($userMgr->get($comment->getUserId()) !== null) { + $displayName = $userMgr->get($avatarName)->getDisplayName(); + } + } else { + // in all other cases + // -> make user anonymous + // poll is anonymous and current user is not owner + // or names are hidden + $displayName = 'Anonymous'; + $avatarName = $displayName; + } + ?> + + <li id="comment_<?php p($comment->getId()); ?>" class="comment column"> + <div class="authorRow user-cell row"> + <div class="avatar has-tooltip" title="<?php p($avatarName)?>"></div> + <div class="author"><?php p($displayName) ?></div> + <div class="date has-tooltip live-relative-timestamp datespan" data-timestamp="<?php p(strtotime($comment->getDt())*1000); ?>" title="<?php p($comment->getDt()) ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($comment->getDt()))) ?></div> + </div> + <div class="message wordwrap comment-content"><?php p($comment->getComment()); ?></div> + </li> + <?php endforeach; ?> + </ul> + </div> </div> </div> </div> diff --git a/templates/main.tmpl.php b/templates/main.tmpl.php index a9c19373..18cc9058 100644 --- a/templates/main.tmpl.php +++ b/templates/main.tmpl.php @@ -25,36 +25,43 @@ \OCP\Util::addStyle('polls', 'main'); \OCP\Util::addStyle('polls', 'list'); + \OCP\Util::addScript('polls', 'app'); \OCP\Util::addScript('polls', 'start'); $userId = $_['userId']; + /** @var \OCP\IUserManager $userMgr */ $userMgr = $_['userMgr']; + /** @var \OCP\IURLGenerator $urlGenerator */ $urlGenerator = $_['urlGenerator']; + /** @var \OCA\Polls\Db\Event[] $polls */ + $polls = $_['polls']; ?> + +<div id="app"> <div id="app-content"> <div id="app-content-wrapper"> <div id="controls"> <div id="breadcrump"> <div class ="crumb svg last" data-dir="/"> <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>"> - <img class="svg" src="<?php print_unescaped(OCP\image_path("core", "places/home.svg")); ?>" alt="Home"> + <img class="svg" src="<?php print_unescaped(\OCP\Template::image_path('core', 'places/home.svg')); ?>" alt="Home"> </a> </div> </div> - <div class="creatable" style=""> + <div class="actions creatable" style=""> <a href="<?php p($urlGenerator->linkToRoute('polls.page.create_poll')); ?>" class="button new"> <span class="symbol icon-add"></span><span class="hidden-visually">Neu</span> </a> <input class="stop icon-close" style="display:none" value="" type="button"> </div> </div> - <?php if (count($_['polls']) == 0) : ?> + <?php if (count($_['polls']) === 0) : ?> <div id="emptycontent" class=""> <div class="icon-polls"></div> <h2><?php p($l->t('No existing polls.')); ?></h2> </div> <?php else : ?> - <div class="table has-controls"> + <div class="table main-container has-controls"> <div class ="row table-header"> <div class="wrapper group-master"> @@ -81,69 +88,71 @@ </div> </div> - <?php foreach ($_['polls'] as $poll) : ?> + <?php foreach ($polls as $poll) : ?> <?php - if (!userHasAccess($poll, $userId)) continue; + if (!userHasAccess($poll, $userId)) { + continue; + } // direct url to poll $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash())); $owner = $poll->getOwner(); $expiry_style = ''; - if ($poll->getType() == '0') { + if ($poll->getType() === 0) { $participated = $_['participations']; } else { $participated = $_['participations_text']; } $participated_class = 'partic_no'; - $participated_title = $l->t('You did not vote'); + $participated_title = 'You did not vote'; $participated_count = count($participated); $comments = $_['comments']; $commented_class = 'commented_no'; - $commented_title = $l->t('You did not comment'); + $commented_title = 'You did not comment'; $commented_count = count($comments); - if ($owner == $userId) { + if ($owner === $userId) { $owner = $l->t('Yourself'); } - if ($poll->getExpire() != null) { - // $expiry_date = date('d.m.Y', strtotime($poll->getExpire())); - $expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs + $timestamp_style = ''; + $expiry_style = ' endless'; + $expiry_date = $l->t('Never'); + + if ($poll->getExpire() !== null) { + $expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs $expiry_style = ' progress'; + $timestamp_style = ' live-relative-timestamp'; if (date('U') > strtotime($poll->getExpire())) { - $expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire())); + $expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire())); $expiry_style = ' expired'; } - } else { - $expiry_style = ' endless'; - $expiry_date = $l->t('Never'); } for ($i = 0; $i < count($participated); $i++) { - if ($poll->getId() == intval($participated[$i]->getPollId())) { + if ($poll->getId() === $participated[$i]->getPollId()) { $participated_class = 'partic_yes'; - $participated_title = $l->t('You voted'); + $participated_title = 'You voted'; array_splice($participated, $i, 1); break; } } for ($i = 0; $i < count($comments); $i++) { - if ($poll->getId() == intval($comments[$i]->getPollId())) { + if ($poll->getId() === $comments[$i]->getPollId()) { $commented_class = 'commented_yes'; - $commented_title = $l->t('You commented'); + $commented_title = 'You commented'; array_splice($comments, $i, 1); break; } } ?> - <div class="row table-body"> <div class="wrapper group-master"> <div class="wrapper group-1"> - <div class="thumbnail <?php p($expiry_style . " " . $commented_class. " " . $participated_class); ?>"></div> <!-- Image to display status or type of poll */ --> + <div class="thumbnail <?php p($expiry_style . ' ' . $commented_class. ' ' . $participated_class); ?>"></div><!-- Image to display the status or type of poll --> <a href="<?php p($pollUrl); ?>" class="wrapper group-1-1"> <div class="column name"> <?php p($poll->getTitle()); ?></div> <div class="column description"> <?php p($poll->getDescription()); ?></div> @@ -153,20 +162,20 @@ <div class="popovermenu bubble menu hidden" id="expanddiv_<?php p($poll->getId()); ?>"> <ul> <li> - <button class="menuitem copy_link action permanent" data-url="<?php p($pollUrl); ?>" title="<?php p($l->t('Click to get link')); ?>"> - <span class="cl_link icon-clippy"></span> + <a class="menuitem alt-tooltip copy-link has-tooltip action permanent" data-toggle="tooltip" data-clipboard-text="<?php p($pollUrl); ?>" title="<?php p($l->t('Click to get link')); ?>" href="#"> + <span class="icon-clippy"></span> <span>Copy Link</span> - </button> + </a> </li> - <?php if ($poll->getOwner() == $userId) : ?> + <?php if ($poll->getOwner() === $userId) : ?> <li> - <button class="menuitem delete_poll action permanent" id="id_del_<?php p($poll->getId()); ?>" data-value="<?php p($poll->getTitle()); ?>"> - <span class="cl_delete icon-delete"></span> + <a id="id_del_<?php p($poll->getId()); ?>" class="menuitem alt-tooltip delete-poll action permanent" data-value="<?php p($poll->getTitle()); ?>" href="#"> + <span class="icon-delete"></span> <span>Delete poll</span> - </button> + </a> </li> <li> - <a href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>" class="menuitem action permanent" id="id_edit_<?php p($poll->getId()); ?>"> + <a id="id_edit_<?php p($poll->getId()); ?>" class="menuitem action permanent" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>"> <span class="icon-rename"></span> <span>Edit Poll</span> </a> @@ -185,13 +194,13 @@ </div> <div class="wrapper group-2-1"> <div class="column access"><?php p($l->t($poll->getAccess())); ?></div> - <div class="column created" data-timestamp="<?php p(strtotime($poll->getCreated())); ?>" data-value="<?php p($poll->getCreated()); ?>"><?php p(OCP\relative_modified_date(strtotime($poll->getCreated()))); ?></div> + <div class="column created has-tooltip live-relative-timestamp" data-timestamp="<?php p(strtotime($poll->getCreated())*1000); ?>" data-value="<?php p($poll->getCreated()); ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($poll->getCreated()))); ?></div> </div> <div class="wrapper group-2-2"> - <div class="column expiry<?php p($expiry_style); ?>" data-value="<?php p($poll->getExpire()); ?>"> <?php p($expiry_date); ?></div> + <div class="column has-tooltip expiry<?php p($expiry_style . $timestamp_style); ?>" data-timestamp="<?php p(strtotime($poll->getExpire())*1000); ?>" data-value="<?php p($poll->getExpire()); ?>"> <?php p($expiry_date); ?></div> <div class="column participants"> - <div class="symbol partic_voted icon-<?php p($participated_class); ?>" title="<?php p($participated_title); ?>"></div> - <div class="symbol partic_commented icon-<?php p($commented_class); ?>" title="<?php p($commented_title); ?>"></div> + <div class="symbol alt-tooltip partic_voted icon-<?php p($participated_class); ?>" title="<?php p($participated_title); ?>"></div> + <div class="symbol alt-tooltip partic_commented icon-<?php p($commented_class); ?>" title="<?php p($commented_title); ?>"></div> </div> </div> </div> @@ -203,18 +212,18 @@ <?php endif; ?> </div> </div> +</div> <?php // ---- helper functions ---- // from spreed.me /** - * @param $userId - * @return array with groups + * @param string $userId + * @return \OCP\IGroup[] */ function getGroups($userId) { - // $this->requireLogin(); - if (class_exists('\OC_Group', true)) { + if (class_exists('\OC_Group')) { // Nextcloud <= 11, ownCloud return \OC_Group::getUserGroups($userId); } @@ -226,12 +235,12 @@ function getGroups($userId) { } /** - * @param $poll - * @param $userId - * @return boolean + * @param OCA\Polls\Db\Event $poll + * @param string $userId + * @return boolean */ -function userHasAccess($poll, $userId) { - if ($poll == null) { +function userHasAccess(OCA\Polls\Db\Event $poll, $userId) { + if ($poll === null) { return false; } $access = $poll->getAccess(); @@ -239,32 +248,30 @@ function userHasAccess($poll, $userId) { if (!User::isLoggedIn()) { return false; } - if ($access == 'public') { + if ($access === 'public' || $access === 'hidden' || $access === 'registered') { return true; } - if ($access == 'hidden') { + if ($owner === $userId) { return true; } - if ($access == 'registered') { - return true; - } - if ($owner == $userId) { - return true; - } - $user_groups = getGroups($userId); + $user_groups = getGroups($userId); $arr = explode(';', $access); foreach ($arr as $item) { - if (strpos($item, 'group_') == 0) { + if (strpos($item, 'group_') === 0) { $grp = substr($item, 6); foreach ($user_groups as $user_group) { - if ($user_group == $grp) return true; + if ($user_group === $grp) { + return true; + } } } - else if (strpos($item, 'user_') == 0) { + else if (strpos($item, 'user_') === 0) { $usr = substr($item, 5); - if ($usr == $userId) return true; + if ($usr === $userId) { + return true; + } } } return false; diff --git a/templates/no.acc.tmpl.php b/templates/no.acc.tmpl.php index 7ff2058b..ed31ad7a 100644 --- a/templates/no.acc.tmpl.php +++ b/templates/no.acc.tmpl.php @@ -26,18 +26,16 @@ <div id="app"> <div id="app-content"> <div id="app-content-wrapper"> - <header> - <div class="row"> - <div class="col-100"> - <h1> - <?php p($l->t('Access denied')); ?> - </h1> - <h2> - <?php p($l->t('You are not allowed to view this poll or the poll does not exist.')); ?> - </h2> - </div> - </div> - </header> + <div id="emptycontent" class=""> + <div class="icon-polls"></div> + <h1> + <?php p($l->t('Access denied')); ?> + </h1> + <h2> + <?php p($l->t('You are not allowed to view this poll or the poll does not exist.')); ?> + </h2> + </div> </div> </div> </div> + diff --git a/templates/no.create.tmpl.php b/templates/no.create.tmpl.php new file mode 100644 index 00000000..883cdc3b --- /dev/null +++ b/templates/no.create.tmpl.php @@ -0,0 +1,40 @@ +<?php + /** + * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + \OCP\Util::addStyle('polls', 'main'); +?> +<div id="app"> + <div id="app-content"> + <div id="app-content-wrapper"> + <div id="emptycontent" class=""> + <div class="icon-polls"></div> + <h1> + <?php p($l->t('Access denied')); ?> + </h1> + <h2> + <?php p($l->t('You are not allowed to edit this poll or the poll does not exist.')); ?> + </h2> + </div> + </div> + </div> +</div> diff --git a/templates/no.delete.tmpl.php b/templates/no.delete.tmpl.php new file mode 100644 index 00000000..0374f9bf --- /dev/null +++ b/templates/no.delete.tmpl.php @@ -0,0 +1,40 @@ +<?php + /** + * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + \OCP\Util::addStyle('polls', 'main'); +?> +<div id="app"> + <div id="app-content"> + <div id="app-content-wrapper"> + <div id="emptycontent" class=""> + <div class="icon-polls"></div> + <h1> + <?php p($l->t('Access denied')); ?> + </h1> + <h2> + <?php p($l->t('You are not allowed to delete this poll or the poll does not exist.')); ?> + </h2> + </div> + </div> + </div> +</div> |