/** * do several things??? with groups and memberships * * TODO: rename, maybe to groupMembership? * @return string; html form */ function subscribeGroup() { global $user; include_once CHURCHDB . '/churchdb_db.php'; $sql_gruppenteilnahme = "select g.bezeichnung, gpg.* from {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp, {cdb_gruppe} g \n where gpg.gemeindeperson_id=gp.id and gp.person_id=:person_id \n and gpg.gruppe_id=g.id and g.id=:g_id"; if (isset($_GET["subscribegroup"]) && $_GET["subscribegroup"] > 0) { $res = db_query("select * from {cdb_gruppe} where id=:id and offen_yn=1", array(":id" => $_GET["subscribegroup"]))->fetch(); if (!$res) { addErrorMessage(t("error.requesting.group.membership")); } else { include_once CHURCHDB . '/churchdb_ajax.php'; $grp = db_query($sql_gruppenteilnahme, array(":person_id" => $user->id, ":g_id" => $_GET["subscribegroup"]))->fetch(); if (!$grp) { churchdb_addPersonGroupRelation($user->id, $res->id, -2, null, null, null, t("request.by.form")); } else { _churchdb_editPersonGroupRelation($user->id, $res->id, -2, null, "null", t("request.quitting.by.form")); } addInfoMessage(t("membership.requested.by.form.leader.will.be.informed"), $res->bezeichnung); } } if (isset($_GET["unsubscribegroup"]) && $_GET["unsubscribegroup"] > 0) { $res = db_query($sql_gruppenteilnahme, array(":person_id" => $user->id, ":g_id" => $_GET["unsubscribegroup"]))->fetch(); if (!$res) { addErrorMessage(t("error.quitting.membership")); } else { include_once CHURCHDB . '/churchdb_ajax.php'; _churchdb_editPersonGroupRelation($user->id, $res->gruppe_id, -1, null, "null", t("request.quitting.by.form")); addInfoMessage(t("membership.marked.for.deleting", $res->bezeichnung)); } } // get groups the user is member of or requested membership $res = db_query("select gpg.gruppe_id, status_no from {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp\n where gpg.gemeindeperson_id=gp.id and gp.person_id={$user->id}"); $mygroups = array(); foreach ($res as $p) { $mygroups[$p->gruppe_id] = $p; } // get all open groups $res = db_query("select * from {cdb_gruppe} p where offen_yn=1 and \n ((abschlussdatum is null) or (DATE_ADD( abschlussdatum, INTERVAL 1 DAY ) > NOW( )))"); $txt = ""; $txt_subscribe = ""; $txt_unsubscribe = ""; foreach ($res as $g) { // groups i am not member of if (!isset($mygroups[$g->id]) || $mygroups[$g->id]->status_no == -1) { if ($g->max_teilnehmer == null || churchdb_countMembersInGroup($g->id) < $g->max_teilnehmer) { $txt_subscribe .= "<option value=\"" . $g->id . "\">" . $g->bezeichnung; if ($g->max_teilnehmer != null) { $txt_subscribe .= " (max. {$g->max_teilnehmer})"; } } } else { if ($mygroups[$g->id]->status_no <= 0) { $txt_unsubscribe .= '<option value="' . $g->id . '">' . $g->bezeichnung; if ($mygroups[$g->id]->status_no == -2) { $txt_unsubscribe .= " [beantragt]"; } } } } if ($txt_subscribe || $txt_unsubscribe) { $txt = '<form method="GET" action="?q=home">'; if ($txt_subscribe) { $txt .= '<p>' . t("apply.for.group.membership") . ':<p><select name="subscribegroup"><option>' . $txt_subscribe . '</select>'; } if ($txt_unsubscribe) { $txt .= '<p>' . t("quit.group.membership") . ':<p><select name="unsubscribegroup"><option>' . $txt_unsubscribe . '</select>'; } $txt .= '<P><button class="btn" type="submit" name="btn">' . t("send") . '</button>'; $txt .= '</form>'; } return $txt; }
/** * do several things??? with groups and memberships * * TODO: rename, maybe to groupMembership? * * @return string; html form */ function subscribeGroup() { global $user; include_once CHURCHDB . '/churchdb_db.php'; $sql_gruppenteilnahme = "SELECT g.bezeichnung, gpg.*\n FROM {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp, {cdb_gruppe} g\n WHERE gpg.gemeindeperson_id=gp.id AND gp.person_id=:person_id AND gpg.gruppe_id=g.id AND g.id=:g_id"; $sGroup = getVar("subscribegroup"); // if ($sGroup = getVar("subscribegroup")) { // should also work if ($sGroup > 0) { $res = db_query("SELECT * FROM {cdb_gruppe}\n WHERE id=:id AND offen_yn=1", array(":id" => $sGroup))->fetch(); if (!$res) { addErrorMessage(t("error.requesting.group.membership")); } else { include_once CHURCHDB . '/churchdb_ajax.php'; $grp = db_query($sql_gruppenteilnahme, array(":person_id" => $user->id, ":g_id" => $sGroup))->fetch(); if (!$grp) { churchdb_addPersonGroupRelation($user->id, $res->id, -2, null, null, null, t("request.by.form")); } else { _churchdb_editPersonGroupRelation($user->id, $res->id, -2, null, "null", t("request.quit.membership.by.form")); } addInfoMessage(t("membership.requested.by.form.leader.will.be.informed", "<i>{$res->bezeichnung}</i>")); } } $uGroup = getVar("unsubscribegroup"); // if ($uGroup = getVar("unsubscribegroup")) { // should also work if ($uGroup > 0) { $res = db_query($sql_gruppenteilnahme, array(":person_id" => $user->id, ":g_id" => $uGroup))->fetch(); if (!$res) { addErrorMessage(t("error.quitting.membership")); } else { include_once CHURCHDB . '/churchdb_ajax.php'; _churchdb_editPersonGroupRelation($user->id, $res->gruppe_id, -1, null, "null", t("request.quit.membership.by.form")); addInfoMessage(t("membership.marked.for.deleting", "<i>{$res->bezeichnung}</i>")); } } // get groups the user is member of or requested membership $res = db_query("SELECT gpg.gruppe_id, status_no\n FROM {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp\n WHERE gpg.gemeindeperson_id=gp.id AND gp.person_id={$user->id}"); $mygroups = array(); foreach ($res as $p) { $mygroups[$p->gruppe_id] = $p; } // get all open groups $res = db_query("SELECT * FROM {cdb_gruppe} p\n WHERE offen_yn=1 AND ((abschlussdatum IS NULL) OR (DATE_ADD( abschlussdatum, INTERVAL 1 DAY ) > NOW( )))"); $txt = ""; $txt_subscribe = ""; $txt_unsubscribe = ""; foreach ($res as $g) { // groups user is not member of if (!isset($mygroups[$g->id]) || $mygroups[$g->id]->status_no == -1) { if ($g->max_teilnehmer == null || churchdb_countMembersInGroup($g->id) < $g->max_teilnehmer) { $txt_subscribe .= "<option value='{$g->id}'>{$g->bezeichnung}"; if ($g->max_teilnehmer) { $txt_subscribe .= " (max. {$g->max_teilnehmer})"; } } } else { if ($mygroups[$g->id]->status_no <= 0) { $txt_unsubscribe .= "<option value='{$g->id}'>{$g->bezeichnung}"; if ($mygroups[$g->id]->status_no == -2) { $txt_unsubscribe .= " [beantragt]"; } } } } if ($txt_subscribe || $txt_unsubscribe) { $txt = '<form method="GET" action="?q=home">'; if ($txt_subscribe) { $txt .= '<p>' . t("apply.for.group.membership") . ':<p><select name="subscribegroup"><option>' . $txt_subscribe . '</select>'; } if ($txt_unsubscribe) { $txt .= '<p>' . t("quit.group.membership") . ':<p><select name="unsubscribegroup"><option>' . $txt_unsubscribe . '</select>'; } $txt .= '<P><button class="btn" type="submit" name="btn">' . t("send") . '</button>'; $txt .= '</form>'; } return $txt; }