Add helpers for the user session and fix bug edit_user admin checkbox

This commit is contained in:
Frédéric Guillot
2014-02-23 20:25:49 -05:00
parent b664175b04
commit 2298594455
5 changed files with 18 additions and 8 deletions

View File

@@ -2,6 +2,16 @@
namespace Helper;
function is_current_user($user_id)
{
return $_SESSION['user']['id'] == $user_id;
}
function is_admin()
{
return $_SESSION['user']['is_admin'] == 1;
}
function markdown($text)
{
require_once __DIR__.'/../vendor/Michelf/MarkdownExtra.inc.php';

View File

@@ -1,7 +1,7 @@
<section id="main">
<div class="page-header">
<h2><?= t('Projects') ?><span id="page-counter"> (<?= $nb_projects ?>)</span></h2>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<ul>
<li><a href="?controller=project&amp;action=create"><?= t('New project') ?></a></li>
</ul>
@@ -18,7 +18,7 @@
<th><?= t('Tasks') ?></th>
<th><?= t('Board') ?></th>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<th><?= t('Actions') ?></th>
<?php endif ?>
</tr>
@@ -56,7 +56,7 @@
<?php endforeach ?>
</ul>
</td>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<td>
<ul>
<li>

View File

@@ -4,7 +4,7 @@
<ul>
<li><a href="?controller=board&amp;action=show&amp;project_id=<?= $project['id'] ?>"><?= t('Back to the board') ?></a></li>
<li><a href="?controller=project&amp;action=index"><?= t('List of projects') ?></a></li>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<li><a href="?controller=project&amp;action=create"><?= t('New project') ?></a></li>
<?php endif ?>
</ul>

View File

@@ -22,7 +22,7 @@
<?= Helper\form_label(t('Default Project'), 'default_project_id') ?>
<?= Helper\form_select('default_project_id', $projects, $values, $errors) ?><br/>
<?php if ($values['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<?= Helper\form_checkbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?>
<?php endif ?>

View File

@@ -1,7 +1,7 @@
<section id="main">
<div class="page-header">
<h2><?= t('Users') ?><span id="page-counter"> (<?= $nb_users ?>)</span></h2>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<ul>
<li><a href="?controller=user&amp;action=create"><?= t('New user') ?></a></li>
</ul>
@@ -30,10 +30,10 @@
<?= (isset($user['default_project_id']) && isset($projects[$user['default_project_id']])) ? $projects[$user['default_project_id']] : t('None'); ?>
</td>
<td>
<?php if ($_SESSION['user']['is_admin'] == 1 || $_SESSION['user']['id'] == $user['id']): ?>
<?php if (Helper\is_admin() || Helper\is_current_user($user['id'])): ?>
<a href="?controller=user&amp;action=edit&amp;user_id=<?= $user['id'] ?>"><?= t('edit') ?></a>
<?php endif ?>
<?php if ($_SESSION['user']['is_admin'] == 1): ?>
<?php if (Helper\is_admin()): ?>
<?php if (count($users) > 1): ?>
<?= t('or') ?>
<a href="?controller=user&amp;action=confirm&amp;user_id=<?= $user['id'] ?>"><?= t('remove') ?></a>