diff options
author | René Gieling <github@dartcafe.de> | 2017-10-21 15:41:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-21 15:41:34 +0300 |
commit | 540e09bcade129f22e2682041dcf4e704385ee79 (patch) | |
tree | 0dc96520deae6a36083dc33f4cceaec40d61a7dc /templates | |
parent | 4788739b6470cebd2ca32b6f74600952738dcfca (diff) |
Code cleaning (#185)
* Update no.acc.tmpl.php
* update for scutinizer
* Update PageController.php
* Update PageController.php
* coding style
* dito
* more fixes
* update
* Added scrutinizer config
* Coding style
Adopting style guide from docs.nextcloud.com
* More changes
* disabled external code coverage
* changes
* Changes
* changes
* changes
* More changes
* Update to version 2.5.11
* Update .scrutinizer.yml
* Update .scrutinizer.yml
* created vendor
[ci skip]
* config
[skip scrutinizer] [skip ci]
* fix
[skip ci]
* Minor
* continuing
[skip ci]
* just a test
* removed unused function declarations
Commenting out some functions, which seem not to be used.
* css tests?
* again
* formatting
* removed comment
and converted spaces in tabs
Diffstat (limited to 'templates')
-rw-r--r-- | templates/create.tmpl.php | 366 | ||||
-rw-r--r-- | templates/goto.tmpl.php | 738 | ||||
-rw-r--r-- | templates/main.tmpl.php | 475 | ||||
-rw-r--r-- | templates/no.acc.tmpl.php | 76 |
4 files changed, 835 insertions, 820 deletions
diff --git a/templates/create.tmpl.php b/templates/create.tmpl.php index 6d84ff52..1b7c178e 100644 --- a/templates/create.tmpl.php +++ b/templates/create.tmpl.php @@ -1,191 +1,193 @@ <?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'); - \OCP\Util::addStyle('polls', 'createpoll'); - \OCP\Util::addStyle('polls', 'jquery.datetimepicker'); - \OCP\Util::addScript('polls', 'create_edit'); - \OCP\Util::addScript('polls', 'jquery.datetimepicker.full.min'); - - $userId = $_['userId']; - $userMgr = $_['userMgr']; - $urlGenerator = $_['urlGenerator']; - $isUpdate = isset($_['poll']) && $_['poll'] !== null; - $isAnonymous = false; - $hideNames = false; - - if ($isUpdate) { - $poll = $_['poll']; - $isAnonymous = $poll->getIsAnonymous(); - $hideNames = $isAnonymous && $poll->getFullAnonymous(); - $dates = $_['dates']; - $chosen = '['; - foreach ($dates as $d) { - if ($poll->getType() == '0') { - $chosen .= strtotime($d->getDt()); - } else { - $chosen .= '"' . $d->getText() . '"'; - } - $chosen .= ','; - } - $chosen = trim($chosen, ','); - $chosen .= ']'; - $title = $poll->getTitle(); - $desc = $poll->getDescription(); - 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') { - $access = 'select'; - } - } + /** + * @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'); + \OCP\Util::addStyle('polls', 'createpoll'); + \OCP\Util::addStyle('polls', 'jquery.datetimepicker'); + \OCP\Util::addScript('polls', 'create_edit'); + \OCP\Util::addScript('polls', 'vendor/jquery.datetimepicker.full.min'); + + $userId = $_['userId']; + $userMgr = $_['userMgr']; + $urlGenerator = $_['urlGenerator']; + $isUpdate = isset($_['poll']) && $_['poll'] != null; + $isAnonymous = false; + $hideNames = false; + + if ($isUpdate) { + $poll = $_['poll']; + $isAnonymous = $poll->getIsAnonymous(); + $hideNames = $isAnonymous && $poll->getFullAnonymous(); + $dates = $_['dates']; + $chosen = '['; + foreach ($dates as $d) { + if ($poll->getType() == '0') { + $chosen .= strtotime($d->getDt()); + } else { + $chosen .= '"' . $d->getText() . '"'; + } + $chosen .= ','; + } + $chosen = trim($chosen, ','); + $chosen .= ']'; + $title = $poll->getTitle(); + $desc = $poll->getDescription(); + 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' + ) { + $access = 'select'; + } + } ?> <div id="app"> <div id="app-content"> - <div id="app-content-wrapper"> + <div id="app-content-wrapper"> <div id="controls"> - <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"> - </a> - </div> - <div class="crumb svg last"> - <span> - <?php if ($isUpdate): ?> - <?php p($l->t('Edit poll') . ' ' . $poll->getTitle()); ?> - <?php else: ?> - <?php p($l->t('Create new poll')); ?> - <?php endif; ?> - </span> - </div> - </div> + <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"> + </a> + </div> + <div class="crumb svg last"> + <span> + <?php if ($isUpdate): ?> + <?php p($l->t('Edit poll') . ' ' . $poll->getTitle()); ?> + <?php else: ?> + <?php p($l->t('Create new poll')); ?> + <?php endif; ?> + </span> + </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()); ?>" /> -<?php else: ?> -<form name="finish_poll" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_poll')); ?>" method="POST"> -<?php endif; ?> - <input type="hidden" name="chosenDates" id="chosenDates" value="<?php if (isset($chosen)) p($chosen); ?>" /> - <input type="hidden" name="expireTs" id="expireTs" value="<?php if (isset($expireTs)) p($expireTs); ?>" /> - <input type="hidden" name="userId" id="userId" value="<?php p($userId); ?>" /> - - <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> - <input type="text" class="input_field" id="pollTitle" name="pollTitle" value="<?php if (isset($title)) p($title); ?>" /> - <label for="pollDesc" class="input_title"><?php p($l->t('Description')); ?></label> - <textarea class="input_field" id="pollDesc" name="pollDesc"><?php if (isset($desc)) p($desc); ?></textarea> - - <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'); ?> /> - <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'); ?> /> - <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'); ?> /> - <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'); ?>> - <label for="select"><?php p($l->t('Select')); ?></label> - <span id="id_label_select">...</span> - - <div id="selected_access" class="row user-group-list"> - <ul id="selected-search-list-id"> - </ul> - </div> - <div id="access_rights" class="row user-group-list"> - <div class="col-50"> - <input type="text" class="live-search-box" id="user-group-search-box" placeholder="<?php p($l->t('User/Group search')); ?>" /> - <ul class="live-search-list" id="live-search-list-id"> - </ul> - </div> - </div> - - <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> - - <div id="anonOptions" style="display:none;"> - <input id="hideNames" name="hideNames" type="checkbox" class="checkbox" <?php $hideNames ? print_unescaped('value="true" checked') : print_unescaped('value="false"'); ?> /> - <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"'); ?> /> - <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" /> - </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'); ?> /> - <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'); ?>> - <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;"'); ?> > - <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;"'); ?> > - <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...'); ?>" /> - <div class="input-group-btn"> - <input type="button" id="text-submit" class="button btn" value="<?php p($l->t('Add')); ?>" class="btn"/> - </div> - </div> - <table id="selected-texts-table" class="choices"> - </table> - </div> - </div> - </div> - <div class="form-actions"> - <?php if ($isUpdate): ?> - <input type="submit" id="submit_finish_poll" class="button btn primary" value="<?php p($l->t('Update poll')); ?>" /> - <?php else: ?> - <input type="submit" id="submit_finish_poll" class="button btn primary" value="<?php p($l->t('Create poll')); ?>" /> - <?php endif; ?> - <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>" id="submit_cancel_poll" class="button"><?php p($l->t('Cancel')); ?></a> - </div> -</form> -</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()); ?>" /> + <?php else: ?> + <form name="finish_poll" action="<?php p($urlGenerator->linkToRoute('polls.page.insert_poll')); ?>" method="POST"> + <?php endif; ?> + <input type="hidden" name="chosenDates" id="chosenDates" value="<?php if (isset($chosen)) p($chosen); ?>" /> + <input type="hidden" name="expireTs" id="expireTs" value="<?php if (isset($expireTs)) p($expireTs); ?>" /> + <input type="hidden" name="userId" id="userId" value="<?php p($userId); ?>" /> + + <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> + <input type="text" class="input_field" id="pollTitle" name="pollTitle" value="<?php if (isset($title)) p($title); ?>" /> + <label for="pollDesc" class="input_title"><?php p($l->t('Description')); ?></label> + <textarea class="input_field" id="pollDesc" name="pollDesc"><?php if (isset($desc)) p($desc); ?></textarea> + + <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'); ?> /> + <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'); ?> /> + <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'); ?> /> + <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'); ?>> + <label for="select"><?php p($l->t('Select')); ?></label> + <span id="id_label_select">...</span> + + <div id="selected_access" class="row user-group-list"> + <ul id="selected-search-list-id"> + </ul> + </div> + <div id="access_rights" class="row user-group-list"> + <div class="col-50"> + <input type="text" class="live-search-box" id="user-group-search-box" placeholder="<?php p($l->t('User/Group search')); ?>" /> + <ul class="live-search-list" id="live-search-list-id"> + </ul> + </div> + </div> + + <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> + + <div id="anonOptions" style="display:none;"> + <input id="hideNames" name="hideNames" type="checkbox" class="checkbox" <?php $hideNames ? print_unescaped('value="true" checked') : print_unescaped('value="false"'); ?> /> + <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"'); ?> /> + <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" /> + </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'); ?> /> + <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'); ?>> + <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;"'); ?> > + <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;"'); ?> > + <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...'); ?>" /> + <div class="input-group-btn"> + <input type="button" id="text-submit" class="button btn" value="<?php p($l->t('Add')); ?>" class="btn"/> + </div> + </div> + <table id="selected-texts-table" class="choices"> + </table> + </div> + </div> + </div> + <div class="form-actions"> + <?php if ($isUpdate): ?> + <input type="submit" id="submit_finish_poll" class="button btn primary" value="<?php p($l->t('Update poll')); ?>" /> + <?php else: ?> + <input type="submit" id="submit_finish_poll" class="button btn primary" value="<?php p($l->t('Create poll')); ?>" /> + <?php endif; ?> + <a href="<?php p($urlGenerator->linkToRoute('polls.page.index')); ?>" id="submit_cancel_poll" class="button"><?php p($l->t('Cancel')); ?></a> + </div> + </form> + </div> + </div> </div> diff --git a/templates/goto.tmpl.php b/templates/goto.tmpl.php index 2456cec1..12a74ffb 100644 --- a/templates/goto.tmpl.php +++ b/templates/goto.tmpl.php @@ -1,71 +1,73 @@ <?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/>. - * - */ + /** + * @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/>. + * + */ - use OCP\User; + use OCP\User; - \OCP\Util::addStyle('polls', 'main'); - \OCP\Util::addStyle('polls', 'vote'); - \OCP\Util::addScript('polls', 'vote'); - - $userId = $_['userId']; - $userMgr = $_['userMgr']; - $urlGenerator = $_['urlGenerator']; - $avaMgr = $_['avatarManager']; + \OCP\Util::addStyle('polls', 'main'); + \OCP\Util::addStyle('polls', 'vote'); + \OCP\Util::addScript('polls', 'vote'); + + $userId = $_['userId']; + $userMgr = $_['userMgr']; + $urlGenerator = $_['urlGenerator']; + $avaMgr = $_['avatarManager']; - $poll = $_['poll']; - $dates = $_['dates']; - $votes = $_['votes']; - $comments = $_['comments']; - $isAnonymous = $poll->getIsAnonymous() && $userId != $poll->getOwner(); - $hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous(); - $notification = $_['notification']; + $poll = $_['poll']; + $dates = $_['dates']; + $votes = $_['votes']; + $comments = $_['comments']; + $isAnonymous = $poll->getIsAnonymous() && $userId != $poll->getOwner(); + $hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous(); + $notification = $_['notification']; - if ($poll->getExpire() === null) { - $expired = false; - } else { - $expired = time() > strtotime($poll->getExpire()); - } + 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 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 = nl2br($poll->getDescription()); +if ( $poll->getDescription() != null + && $poll->getDescription() != '' +) { + $description = nl2br($poll->getDescription()); } else { - $description = $l->t('No description provided.'); + $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; + $total_y[$i] = 0; + $total_n[$i] = 0; } $user_voted = array(); @@ -73,325 +75,327 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => ?> <div id="app"> - <div id="app-content"> - <div id="app-content-wrapper"> + <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="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; ?> - <?php if (!User::isLoggedIn()) : ?> - <div class="col-100"> - <h2><?php p($poll->getTitle()); ?></h2> - </div> - <?php endif; ?> - </div> - </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>'); - } 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); - } - $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>'); + <?php if (!User::isLoggedIn()) : ?> + <div class="col-100"> + <h2><?php p($poll->getTitle()); ?></h2> + </div> + <?php endif; ?> + </div> + </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>'); + } 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); + } + $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++; - } - print_unescaped('</tr>'); - } - } - $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()); - } 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') . '" />'); - } - 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(); - } - // 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>'); + // 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++; + } + print_unescaped('</tr>'); + } + } + $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()); + } 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') . '" />'); + } + 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(); + } + // 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++; - } - } - ?> - </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; ?> - </div> - </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> - <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> - </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; ?> - </div> - </div> - </div> - </div> - </div> + $i_tot++; + } + } + ?> + </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; ?> + </div> + </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> + <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> + </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; ?> + </div> + </div> + </div> + </div> + </div> </div> diff --git a/templates/main.tmpl.php b/templates/main.tmpl.php index aa4825a4..ba9866a3 100644 --- a/templates/main.tmpl.php +++ b/templates/main.tmpl.php @@ -1,263 +1,272 @@ <?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/>. - * - */ + /** + * @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/>. + * + */ - use OCP\User; + use OCP\User; - \OCP\Util::addStyle('polls', 'main'); - \OCP\Util::addStyle('polls', 'list'); - \OCP\Util::addScript('polls', 'start'); + \OCP\Util::addStyle('polls', 'main'); + \OCP\Util::addStyle('polls', 'list'); + \OCP\Util::addScript('polls', 'start'); - $userId = $_['userId']; - $userMgr = $_['userMgr']; - $urlGenerator = $_['urlGenerator']; + $userId = $_['userId']; + $userMgr = $_['userMgr']; + $urlGenerator = $_['urlGenerator']; ?> - <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"> - </a> - </div> - </div> - <div class="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) : ?> - <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 ="row table-header"> + <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"> + </a> + </div> + </div> + <div class="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) : ?> + <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 ="row table-header"> - <div class="wrapper group-master"> - <div class="wrapper group-1"> - <div class="wrapper group-1-1"> - <div class="column name"> <?php p($l->t('Title')); ?></div> - <div class="column description"></div> - </div> - <div class="wrapper group-1-2"> - <div class="column actions"></div> - </div> - </div> - <div class="wrapper group-2"> - <div class="column owner"> <?php p($l->t('By')); ?></div> - <div class="wrapper group-2-1"> - <div class="column access"> <?php p($l->t('Access')); ?></div> - <div class="column created"> <?php p($l->t('Created')); ?></div> - </div> - <div class="wrapper group-2-2"> - <div class="column expiry"> <?php p($l->t('Expires')); ?></div> - <div class="column participants"> <?php p($l->t('participated')); ?></div> - </div> - </div> - </div> - </div> + <div class="wrapper group-master"> + <div class="wrapper group-1"> + <div class="wrapper group-1-1"> + <div class="column name"> <?php p($l->t('Title')); ?></div> + <div class="column description"></div> + </div> + <div class="wrapper group-1-2"> + <div class="column actions"></div> + </div> + </div> + <div class="wrapper group-2"> + <div class="column owner"> <?php p($l->t('By')); ?></div> + <div class="wrapper group-2-1"> + <div class="column access"> <?php p($l->t('Access')); ?></div> + <div class="column created"> <?php p($l->t('Created')); ?></div> + </div> + <div class="wrapper group-2-2"> + <div class="column expiry"> <?php p($l->t('Expires')); ?></div> + <div class="column participants"> <?php p($l->t('participated')); ?></div> + </div> + </div> + </div> + </div> - <?php foreach ($_['polls'] as $poll) : ?> - <?php - if (!userHasAccess($poll, $userId)) continue; - // direct url to poll - $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash())); - $owner = $poll->getOwner(); + <?php foreach ($_['polls'] as $poll) : ?> + <?php + 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') { - $participated = $_['participations']; - } else { - $participated = $_['participations_text']; - } - $participated_class = 'partic_no'; - $participated_title = 'You did not vote'; - $participated_count = count($participated); + $expiry_style = ''; + if ($poll->getType() == '0') { + $participated = $_['participations']; + } else { + $participated = $_['participations_text']; + } + $participated_class = 'partic_no'; + $participated_title = 'You did not vote'; + $participated_count = count($participated); - $comments = $_['comments']; - $commented_class = 'commented_no'; - $commented_title = 'You did not comment'; - $commented_count = count($comments); + $comments = $_['comments']; + $commented_class = 'commented_no'; + $commented_title = 'You did not comment'; + $commented_count = count($comments); - if ($owner === $userId) { - $owner = $l->t('Yourself'); - } + 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 - $expiry_style = ' progress'; - if (date('U') > strtotime($poll->getExpire())) { - $expiry_date = OCP\relative_modified_date(strtotime($poll->getExpire())); - $expiry_style = ' expired'; - } - } else { - $expiry_style = ' endless'; - $expiry_date = $l->t('Never'); - } + 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 + $expiry_style = ' progress'; + if (date('U') > strtotime($poll->getExpire())) { + $expiry_date = OCP\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())) { - $participated_class = 'partic_yes'; - $participated_title = 'You voted'; - array_splice($participated, $i, 1); - break; - } - } + for ($i = 0; $i < count($participated); $i++) { + if ($poll->getId() == intval($participated[$i]->getPollId())) { + $participated_class = 'partic_yes'; + $participated_title = 'You voted'; + array_splice($participated, $i, 1); + break; + } + } - for ($i = 0; $i < count($comments); $i++) { - if ($poll->getId() === intval($comments[$i]->getPollId())) { - $commented_class = 'commented_yes'; - $commented_title = 'You commented'; - array_splice($comments, $i, 1); - break; - } - } - ?> + for ($i = 0; $i < count($comments); $i++) { + if ($poll->getId() == intval($comments[$i]->getPollId())) { + $commented_class = 'commented_yes'; + $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 */ --> - <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> - </a> - <div class="column actions"> - <div class="icon-more popupmenu" value="<?php p($poll->getId()); ?>" id="expand_<?php p($poll->getId()); ?>"></div> - <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> - <span>Copy Link</span> - </button> - </li> - <?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> - <span>Delete poll</span> - </button> - </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()); ?>"> - <span class="icon-rename"></span> - <span>Edit Poll</span> - </a> - </li> - <?php endif; ?> - </ul> + <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 */ --> + <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> + </a> + <div class="column actions"> + <div class="icon-more popupmenu" value="<?php p($poll->getId()); ?>" id="expand_<?php p($poll->getId()); ?>"></div> + <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> + <span>Copy Link</span> + </button> + </li> + <?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> + <span>Delete poll</span> + </button> + </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()); ?>"> + <span class="icon-rename"></span> + <span>Edit Poll</span> + </a> + </li> + <?php endif; ?> + </ul> - </div> + </div> - </div> - </div> - <div class="wrapper group-2"> - <div class="column owner"> - <div class="avatardiv" title="<?php p($poll->getOwner()); ?>" style="height: 32px; width: 32px;"></div> - <div class="name-cell"><?php p($owner); ?></div> - </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> - <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 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> - </div> - </div> - </div> - </div> - <?php endforeach; ?> - </div> - <form id="form_delete_poll" name="form_delete_poll" action="<?php p($urlGenerator->linkToRoute('polls.page.delete_poll')); ?>" method="POST"></form> - <?php endif; ?> - </div> - </div> + </div> + </div> + <div class="wrapper group-2"> + <div class="column owner"> + <div class="avatardiv" title="<?php p($poll->getOwner()); ?>" style="height: 32px; width: 32px;"></div> + <div class="name-cell"><?php p($owner); ?></div> + </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> + <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 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> + </div> + </div> + </div> + </div> + <?php endforeach; ?> + </div> + <form id="form_delete_poll" name="form_delete_poll" action="<?php p($urlGenerator->linkToRoute('polls.page.delete_poll')); ?>" method="POST"></form> + <?php endif; ?> + </div> + </div> <?php // ---- helper functions ---- // from spreed.me +/** + * @param $userId + * @return array with groups + */ function getGroups($userId) { - // $this->requireLogin(); - if (class_exists('\OC_Group', true)) { - // Nextcloud <= 11, ownCloud - return \OC_Group::getUserGroups($userId); - } - // Nextcloud >= 12 - $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser()); - return array_map(function ($group) { - return $group->getGID(); - }, $groups); + // $this->requireLogin(); + if (class_exists('\OC_Group', true)) { + // Nextcloud <= 11, ownCloud + return \OC_Group::getUserGroups($userId); + } + // Nextcloud >= 12 + $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser()); + return array_map(function ($group) { + return $group->getGID(); + }, $groups); } +/** + * @param $poll + * @param $userId + * @return boolean + */ function userHasAccess($poll, $userId) { - if ($poll === null) { - return false; - } - $access = $poll->getAccess(); - $owner = $poll->getOwner(); - if (!User::isLoggedIn()) { - return false; - } - if ($access === 'public') { - return true; - } - if ($access === 'hidden') { - return true; - } - if ($access === 'registered') { - return true; - } - if ($owner === $userId) { - return true; - } - $user_groups = getGroups($userId); + if ($poll == null) { + return false; + } + $access = $poll->getAccess(); + $owner = $poll->getOwner(); + if (!User::isLoggedIn()) { + return false; + } + if ($access == 'public') { + return true; + } + if ($access == 'hidden') { + return true; + } + if ($access == 'registered') { + return true; + } + if ($owner == $userId) { + return true; + } + $user_groups = getGroups($userId); - $arr = explode(';', $access); + $arr = explode(';', $access); - foreach ($arr as $item) { - if (strpos($item, 'group_') === 0) { - $grp = substr($item, 6); - foreach ($user_groups as $user_group) { - if ($user_group === $grp) return true; - } - } - else if (strpos($item, 'user_') === 0) { - $usr = substr($item, 5); - if ($usr === $userId) return true; - } - } - return false; + foreach ($arr as $item) { + if (strpos($item, 'group_') == 0) { + $grp = substr($item, 6); + foreach ($user_groups as $user_group) { + if ($user_group == $grp) return true; + } + } + else if (strpos($item, 'user_') == 0) { + $usr = substr($item, 5); + if ($usr == $userId) return true; + } + } + return false; } ?> diff --git a/templates/no.acc.tmpl.php b/templates/no.acc.tmpl.php index f95a7049..7ff2058b 100644 --- a/templates/no.acc.tmpl.php +++ b/templates/no.acc.tmpl.php @@ -1,43 +1,43 @@ <?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/>. - * - */ + /** + * @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'); + \OCP\Util::addStyle('polls', 'main'); ?> <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> - </div> + <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> + </div> </div> |