' : '<').'0 and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'" order by brewer'; $pref_res=mysqli_query($db, $query); while ($pref_row = mysqli_fetch_assoc($pref_res)) { if (!array_key_exists($pref_row['brewer'], $Prefs)) { $Prefs[$pref_row['brewer']]=array(); } $Prefs[$pref_row['brewer']][]=$pref_row['rank']; } foreach ($Prefs as $Brewer => $Ranks) { foreach ($Ranks as $Rank) { $ChgId=$Brewer.':'.$Rank; $query='select * from style_prefs where brewer="'.$Brewer.'" and rank="'.$Rank.'"'; $pref_res=mysqli_query($db, $query); $pref_row=mysqli_fetch_assoc($pref_res); $query='delete from style_prefs where brewer="'.$Brewer.'" and rank="'.$Rank.'"'; if (mysqli_query($db, $query)) { $query='insert into changelog values(null, null, "'.$Key.'", "style_prefs", "C", "cat", "'.$ChgId.'", "'.$pref_row['cat'].'", "")'; mysqli_query($db, $query); if ($pref_row['sub_cat'] != '') { $query='insert into changelog values(null, null, "'.$Key.'", "style_prefs", "C", "sub_cat", "'.$ChgId.'", "'.$pref_row['sub_cat'].'", "")'; mysqli_query($db, $query); } $query='insert into changelog values(null, null, "'.$Key.'", "style_prefs", "D", "", "'.$ChgId.'", "", "")'; mysqli_query($db, $query); } } if ($Likes) { $Ranks=array(2, 1, 2, 1); $RankOffset=1; } else { $Ranks=array(-2, -1, -2, -1); $RankOffset=-1; } foreach ($Ranks as $Rank) { $query='select count(*) from style_prefs where brewer="'.$Brewer.'" and rank="'.$Rank.'"'; $cnt_res=mysqli_query($db, $query); $cnt_row=mysqli_fetch_row($cnt_res); if ($cnt_row[0] == 0) { $ToRank=$Rank + $RankOffset; $query='select count(*) from style_prefs where brewer="'.$Brewer.'" and rank="'.$ToRank.'"'; $cnt_res=mysqli_query($db, $query); $cnt_row=mysqli_fetch_row($cnt_res); if ($cnt_row[0] != 0) { $query='update style_prefs set rank="'.$Rank.'" where brewer="'.$Brewer.'" and rank="'.$ToRank.'"'; if (mysqli_query($db, $query)) { $query='insert into changelog values(null, null, "'.$Key.'", "style_prefs", "C", "rank", "'.$Brewer.':'.$ToRank.'", "'.$ToRank.'", "'.$Rank.'")'; mysqli_query($db, $query); } } } } } } // $Map_SubCat=array('cat_desc', 'note_num', 'req_comment', 'req_base', 'req_strength', 'req_sweetness', 'req_carbonation', 'req_color', 'add_ts'); $SubCat=array(); $query='select sub_cat from style_sub where sg="'.$Comp_SG.'" and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'" order by sub_cat'; $subcat_res=mysqli_query($db, $query); while ($subcat_row = mysqli_fetch_row($subcat_res)) { $SubCat[]=$subcat_row[0]; } foreach ($SubCat as $Sub) { $query='select * from style_sub where sg="'.$Comp_SG.'" and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'" and sub_cat="'.$Sub.'" order by sub_cat'; $subcat_res=mysqli_query($db, $query); $subcat_row=mysqli_fetch_assoc($subcat_res); $query='delete from style_sub where sg="'.$Comp_SG.'" and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'" and sub_cat="'.$subcat_row['sub_cat'].'"'; if (mysqli_query($db, $query)) { $ChgId=$Comp_SG.':'.$TypeSeq.':'.$Cat.':'.$subcat_row['sub_cat']; foreach ($Map_SubCat as $row) { $query='insert into changelog values(null, null, "'.$Key.'", "style_sub", "C", "'.$row.'", "'.$ChgId.'", "'.$subcat_row[$row].'", "")'; mysqli_query($db, $query); } $query='insert into changelog values(null, null, "'.$Key.'", "style_sub", "D", "", "'.$ChgId.'", "", "")'; mysqli_query($db, $query); } } RemPrefs (TRUE); RemPrefs (FALSE); $query='select * from style where sg="'.$Comp_SG.'" and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'"'; $cat_res=mysqli_query($db, $query); $cat_row=mysqli_fetch_assoc($cat_res); $query='delete from style where sg="'.$Comp_SG.'" and type_seq="'.$TypeSeq.'" and cat="'.$Cat.'"'; if (mysqli_query($db, $query)) { $ChgId=$Comp_SG.':'.$TypeSeq.':'.$Cat; foreach ($Map as $row) { $query='insert into changelog values(null, null, "'.$Key.'", "style", "C", "'.$row.'", "'.$ChgId.'", "'.$cat_row[$row].'", "")'; mysqli_query($db, $query); } $query='insert into changelog values(null, null, "'.$Key.'", "style", "C", "add_ts", "'.$ChgId.'", "'.$cat_row['add_ts'].'", "")'; mysqli_query($db, $query); $query='insert into changelog values(null, null, "'.$Key.'", "style", "D", "", "'.$ChgId.'", "", "")'; mysqli_query($db, $query); } ?>