'); die (); } // security check $editable = $userinfo["sa"]; if ($g > 0) { $r = query ("select * from groups where groupid=" . $g . ";"); $g_info = mysql_fetch_array($r, MYSQL_ASSOC) or die ("Error accessing database for group id=" . $g); if (!$editable) { $editable = is_allowed (ACCESS_ADMIN); } } if (!$editable) { include "accessdenied.php"; } // circular-affiliation test // - a group cannot be an affiliate of itself, nor a descendant of itself by affiliation // - initial $idlist should be the id of the proposed new affiliation in array form, // e.g. array($g) function circular ($newaffiliate_id, $idlist) { $found = FALSE; $idliststr = implode ($idlist,','); unset ($idlist); $q = 'select affiliationid from affiliations where affiliateid in (' . $idliststr . ')'; $r = query ($q) or die ('error using query: "' . $q . '"'); while ($info = mysql_fetch_array($r, MYSQL_ASSOC)) { $affiliation = $info["affiliationid"]; $idlist[] = $affiliation; $found = ($affiliation == $newaffiliate_id); } if (isset($idlist) and (!$found)) $found = circular($newaffiliate_id,$idlist); return $found; } // ADD AFFILIATE // - uses $g2 variable, set by masthead_group2_search below if ($g2) { // ensure no duplicates $r = query ('select groupname from groups,affiliations where groupid=affiliateid and affiliateid=' . $g2 . ' and affiliationid=' . $g . ';'); if ($info = mysql_fetch_array($r, MYSQL_ASSOC)) { noteerror ('"' . crunchtext($info["groupname"]) . '" is already an affiliate of this group.'); } else if ($g2==$g) { noteerror ('a group cannot be an affiliate of itself.'); } else if (circular($g2,array($g))) { noteerror ('circular affiliation path detected.'); } else if (query('insert into affiliations set affiliateid=' . $g2 . ', affiliationid=' . $g . ';')) { $change_report = 'Subgroup successfully added.'; } else { noteerror ('Could not add subgroup.'); } } // DELETE AFFILIATES $affiliatecount = 0; while (isset($_POST["edit_affiliate_id_" . ++$affiliatecount])) { // get information $affiliateid = $_POST["edit_affiliate_id_" . $affiliatecount]; $affiliatedelete = $_POST["edit_affiliate_delete_" . $affiliatecount]; // delete affiliate if ($affiliatedelete) { $q = 'delete from affiliations where affiliateid=' . $affiliateid . ' and affiliationid=' . $g . ';'; if (query ($q)) { $change_report = 'Subgroup successfully removed.'; } else { noteerror ('Could not remove subgroup.'); } } } // ============================================================================================= // ----- BEGIN VISIBLE PAGE ----- // ============================================================================================= function masthead_affiliation_edit () { global $g, $userinfo, $BGCOLOUR_LIGHT, $BGCOLOUR_DARK; masthead_group_search('g'); if ($g) { print ''; print ' '; print 'Edit group | '; print 'Browse group | '; print ''; print 'Create new subgroup |'; print ""; } } printhtmlheader ('Change Subgroups: ' . crunchtext($g_info["groupname"])); printmasthead ('Change Subgroups','masthead_affiliation_edit'); printeditfeedback(); print '

' . crunchtext($g_info["groupname"]) . "

\n"; // add affiliate print "

Claim Subgroup

\n"; print '' . "\n"; masthead_group2_search(); print "
\n"; // get current affiliates $q = 'select * from groups'; $q .= ' left join affiliations on affiliateid=groupid'; $q .= ' where affiliationid=' . $g; $q .= ' order by groupname;'; $r = query ($q) or die ('Error accessing group affiliates with:

' . $q); $affiliatecount = 0; function displayaffiliate ($affiliate) { global $affiliatecount; // install relevant data into POST variable $affiliateformid="edit_affiliate_id_" . ++$affiliatecount; $_POST[$affiliateformid] = $affiliate["affiliateid"]; $affiliateformdelete="edit_affiliate_delete_" . $affiliatecount; $_POST[$affiliateformdelete] = false; print ''; formhiddeninput ($affiliateformid); formcheckboxinput ($affiliateformdelete); print crunchtext($affiliate["groupname"]); print "\n"; } print "

Remove Subgroups

\n"; if (mysql_num_rows($r)) { formstart(); $_POST["g"] = $g; formhiddeninput ("g"); print "\n"; while ($affiliate = mysql_fetch_array($r, MYSQL_ASSOC)) { displayaffiliate($affiliate); } print "
\n

"; formend(); } else { print "No subgroups."; } ?>