0) { $bg_row=get_bg($BrewerNo, $GroupNum); if ($bg_row['brewer'] > 0 && $bg_row['group_num'] > 0) { $GoodGroup=TRUE; $Action='u'; } } if (!$GoodGroup) { $GroupNum=FALSE; $Page='0;brewgrp_list.php?k='.$Key.$Add; } } $Reload=array_key_exists('RELOAD', $_POST) && !empty($_POST['RELOAD']); $bg=array(); $o_bg=array(); $e_bg=array(); if (!$Reload) { $bg=GetTags($Len); $o_bg=GetTags($Len, '_ORIG'); $e_bg=array(); if (strlen($bg['FNAME']) == 0) { $e_bg['FNAME_R']=TRUE; } if (strlen($bg['LNAME']) == 0) { $e_bg['LNAME_R']=TRUE; } $query='select group_num from brew_group where brewer="'.$BrewerNo.'" and fname="'.$bg['FNAME'].'" and lname="'.$bg['LNAME'].'"'.($Action == 'u' ? ' and group_num!="'.$GroupNum.'"' : ''); $bg_res=mysqli_query($db, $query); if (mysqli_num_rows($bg_res) > 0) { $bg_row=mysqli_fetch_assoc($bg_res); $e_bg['DUP']=(mysqli_num_rows($bg_res) > 1 ? 0 : $bg_row['group_num']); } if (count($e_bg) == 0) { if ($Action == 'a') { $query='select max(group_num) from brew_group where brewer="'.$BrewerNo.'"'; $next_res=mysqli_query($db, $query); $next_row=mysqli_fetch_row($next_res); $GroupNum=$next_row[0] == 'NULL' ? 1 : $next_row[0]+1; $query='insert into brew_group values(null, "'.$BrewerNo.'", "'.$GroupNum.'", "'.$bg['FNAME'].'"'; $query.=', "'.$bg['LNAME'].'", "N", null, now())'; if (!mysqli_query($db, $query)) { $e_bg['ADD']=TRUE; } else { $query='insert into changelog values(null, null, "'.$Key.'", "brew_group", "A", "", "'.$BrewerNo.':'.$GroupNum.'", "", "")'; mysqli_query($db, $query); } } if ($Action == 'u' && $GoodGroup) { $bg_row=get_bg($BrewerNo, $GroupNum); if ($o_bg['FNAME'] != $bg_row['fname']) { $e_bg['FNAME_C']=TRUE; } if ($o_bg['LNAME'] != $bg_row['lname']) { $e_bg['LNAME_C']=TRUE; } if (count($e_bg) == 0) { $Set=''; if ($bg['FNAME'] != $bg_row['fname']) { $Set='fname="'.$bg['FNAME'].'"'; } if ($bg['LNAME'] != $bg_row['lname']) { $Set.=(strlen($Set) != 0 ? ', ' : '').'lname="'.$bg['LNAME'].'"'; } if (strlen($Set) != 0) { $query='update brew_group set '.$Set.' where brewer="'.$BrewerNo.'" and group_num="'.$GroupNum.'"'; if (!mysqli_query($db, $query)) { $e_bg['UPDATE']=TRUE; } else { if ($bg['FNAME'] != $bg_row['fname']) { $query='insert into changelog values (null, null, "'.$Key.'", "brew_group", "C", "fname", "'.$BrewerNo.':'.$GroupNum.'", "'.$bg_row['fname'].'", "'.$bg['FNAME'].'")'; mysqli_query($db, $query); } if ($bg['LNAME'] != $bg_row['lname']) { $query='insert into changelog values (null, null, "'.$Key.'", "brew_group", "C", "lname", "'.$BrewerNo.':'.$GroupNum.'", "'.$bg_row['lname'].'", "'.$bg['LNAME'].'")'; mysqli_query($db, $query); } } } } } } } ?>

Updating Group Members