Commit 101df853 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

fixes #62 - template pour methode inexistante

parent 06b6179b
......@@ -6,6 +6,7 @@ class User extends Record {
public $alert_msg = "";
// roles is just an array of role name, not objects
public $roles;
public $table = "users";
......@@ -78,15 +79,18 @@ class User extends Record {
} else {
$list_to_delete = "";
while(list($key, $val) = each($this->roles)) {
if($val->selected && !in_array($val->name, $_REQUEST["roles"])) {
$list_to_delete .= $val->id.",";
if(!in_array($key, $_REQUEST["roles"])) {
$list_to_delete .= "'".$key."',";
}
}
reset($this->roles);
if($list_to_delete != "") {
// SQL DELETE user_roles
$sql = " DELETE FROM user_roles WHERE user_id = ".$this->id.
" AND role_id IN ( ".substr($list_to_delete, 0, -1).") ";
// SQL DELETE user_roles JOIN roles
$sql = " DELETE ur
FROM user_roles ur
JOIN roles r ON ur.role_id = r.id
WHERE ur.user_id = ".$this->id."
AND r.name IN ( ".substr($list_to_delete, 0, -1).") ";
$GLOBALS["data"]->delete($sql);
}
$list_to_add = "";
......@@ -99,8 +103,8 @@ class User extends Record {
// SQL INSERT user_roles SELECT roles
$sql = " INSERT INTO user_roles (user_id, role_id, created_at)
SELECT ".$this->id.", id, now()
FROM roles
WHERE name IN (".substr($list_to_add, 0, -1).")";
FROM roles r
WHERE r.name IN (".substr($list_to_add, 0, -1).")";
$GLOBALS["data"]->insert($sql);
}
}
......
......@@ -20,6 +20,11 @@ class AppController {
));
$this->context["global"] = $GLOBALS;
$this->context["request"] = $_REQUEST;
if(!method_exists($this, "_".$_REQUEST["a"])) {
$this->render("bad_method");
exit();
}
}
function set($var, &$val) {
......
......@@ -4,8 +4,12 @@ class HomeController extends AppController {
function HomeController () {
$this->AppController();
$render = "home/index";
$function_name = "_".$_REQUEST["a"];
// to the view
$this->render($this->$function_name());
}
function _index() {
// fetch the N oldest loans order by due date ASC
$loans = array();
Loan::fetch_all($loans, 0, 10);
......@@ -16,7 +20,6 @@ class HomeController extends AppController {
Member::fetch_last($members);
$this->set("members", $members);
// view part
$this->render("home/index");
return "home/index";
}
}
......@@ -24,12 +24,14 @@ if(!array_key_exists("user_id", $_SESSION)) {
if($logged_user->id != 0) {
$_SESSION["user_id"] = $logged_user->id;
$_REQUEST["o"] = "home";
$_REQUEST["a"] = "index";
}
} // stay not authenticated
} else {
if(array_key_exists("a", $_REQUEST) && $_REQUEST["a"] == "logout") {
// logout
unset($_SESSION["user_id"]);
$_REQUEST["a"] = "login";
} else {
// stay authenticated
$logged_user = User::fetch($_SESSION["user_id"]);
......
{% extends "base.html" %}
{% block title %}Erreur{% endblock %}
{% block content %}
<div class="panel panel-danger">
<div class="panel-heading">
<span class="glyphicon glyphicon-remove-sign" style="font-size:150%" ></span>
<span style="font-size: 150%; font-weight: bold">
Erreur de routage
</span>
</div>
<div class="panel-body">
{% if global['debug'] %}
<table class="table table-striped">
<tr>
<th>Le Fameux Controlleur</th>
<td>{{ request['o'] }}</td>
</tr>
<tr>
<th>La Méthode Problématique</th>
<td>{{ request['a'] }}</td>
</tr>
</table>
{% else %}
Si vous voulez (et pouvez), vous pouvez activer le mode debug dans le fichier de configuration pour voir ce qui n'a pas marché.
{% endif %}
</div>
</div>
{% endblock %}
......@@ -15,7 +15,7 @@
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="roles">Roles</label>
<div class="col-sm-4">
<div class="col-sm-10">
<select id="roles" name="roles[]" class="form-control" multiple="multiple">
</select>
<script>
......@@ -41,17 +41,24 @@
});
</script>
</div>
</div>
{% if object.id != global['logged_user'].id %}
<div class="form-group">
<label class="control-label col-sm-2" for="active">Activé</label>
<div class="col-sm-1">
<div class="col-sm-4">
<input type="hidden" id="active" name="active" value="{{ object.active ? 1 : 0 }}"/>
<input type="checkbox" id="active_cbx" class="form-control" {{ object.active ? "checked" }}/>
</div>
</div>
{% endif %}
<script>
$(document).ready(function () {
// special checkbox
$('#active_cbx').on('switchChange.bootstrapSwitch', function(event, state) {
$('#active_cbx').bootstrapSwitch({
onText: "Oui",
offText: "Non",
}).on('switchChange.bootstrapSwitch', function(event, state) {
$('#active').val(state == true ? 1 : 0);
});
});
......
......@@ -48,10 +48,12 @@
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i>
</button>
{% if val.id != global['logged_user'].id %}
<a href="#" onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</a>
{% endif %}
</td>
</tr>
{% else %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment