Commit 3290548d authored by thejoelinux's avatar thejoelinux

correction creation du compte

parent 4b9f44c2
......@@ -113,7 +113,8 @@ class Member extends Record {
}
public function delete_subscription() {
$subscription = Subscription::delete($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$subscription->delete();
}
public function fetch_loans() {
......@@ -222,4 +223,11 @@ class Member extends Record {
$GLOBALS["data"]->select($sql, $members, "Member");
return sizeof($members);
}
public function save_account() {
// SQL UPDATE members
$sql = " UPDATE members SET account_id = ".$this->account_id.
" WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql);
}
}
......@@ -3,6 +3,8 @@ class AppController {
public $context;
public $format;
function AppController() {
include_once("vendor/autoload.php");
$this->context = array();
......@@ -11,6 +13,8 @@ class AppController {
$_REQUEST["a"] = "list";
}
$this->format = (preg_match("/api.php/", $_SERVER["REQUEST_URI"])) ? "json" : "html";
// Twig init
Twig_Autoloader::register();
......
......@@ -173,9 +173,10 @@ class MembersController extends AppController {
if($member->id != 0) {
$_REQUEST["member_id"] = $member->id;
// the user must first have an account in the accounting part
if($member->account_id == 0) {
if(!$member->account_id) {
$member->account = Account::create_for_member($member->id);
$member->account_id = $member->account->id;
$member->save_account();
}
$member->create_subscription();
$member->fetch_subscriptions();
......@@ -229,7 +230,20 @@ class MembersController extends AppController {
function _list() {
try {
if($this->format == "json" && $_REQUEST["i"] != "") {
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($member->id != 0) {
echo json_encode($member);
} else {
}
exit();
}
Member::fetch_all($members);
if($this->format == "json") {
echo json_encode($members);
exit();
}
$this->set("members", $members);
return "members/list";
} catch(data_exception $e) {
......
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