function mk_checkbox($eid, $f) { global $not; $fid = $f['fieldid']; if (isset($_SESSION['cache']['f' . $fid])) { if (!is_array($_SESSION['cache']['f' . $fid])) { $_SESSION['cache']['f' . $fid] = array(); } $defval = $_SESSION['cache']['f' . $fid]; } else { $defval = linebreak($f['default']); } $options = array(); while ($e = sql('SELECT `optionid`,`caption` FROM `options` WHERE `eventid`="' . $eid . '" AND `fieldid`="' . $fid . '" ORDER BY `optionid`')) { $options[] = $e; } if (count($options) == 1) { echo '<input type="checkbox" name="f' . $fid . '[]" id="f' . $fid . '-' . $e['optionid'] . '" value="' . condom($e['caption']) . '"' . (in_array($e['caption'], $defval) ? ' checked="checked"' : '') . $not . ' />'; } else { foreach ($options as $e) { echo '<span style="float:leftl"><input type="checkbox" name="f' . $fid . '[]" id="f' . $fid . '-' . $e['optionid'] . '" value="' . condom($e['caption']) . '"' . (in_array($e['caption'], $defval) ? ' checked="checked"' : '') . $not . ' /><label for="f' . $fid . '-' . $e['optionid'] . '">' . condom($e['caption']) . '</label></span>' . "\n"; } } }
} else { $pat[] = true; } $opt_pat[] = 0; $th .= '<th rowspan="2">' . $e['caption'] . '</th>'; $id_pat[] = intval($e['fieldid']); } } if (admin()) { $th .= '<th rowspan="2">#</th>'; } $th .= '</tr>' . "\n" . $th2 . '</tr>' . "\n"; while ($e = sql('SELECT `recordid`,`fieldid`,`value` FROM `pool` WHERE `eventid`="' . $eventid . '" ORDER BY `recordid` DESC')) { $e['value'] = condom($e['value']); if ($checkbox[$e['fieldid']]) { $e['value'] = linebreak($e['value']); } $data[$e['recordid']][$e['fieldid']] = $e['value']; } $i = 0; echo $th; while ($e = sql('SELECT `recordid` FROM `records` WHERE `eventid`="' . $eventid . '" ORDER BY `recordid` DESC')) { ++$i; if ($i % 30 == 0) { echo $th; } echo '<tr style="background:#' . ($i % 2 == 0 ? 'fff' : 'eee') . ';">'; foreach ($id_pat as $idx => $fid) { if ($pat[$idx] === true) { #other echo admin() ? '<td id="' . $e['recordid'] . '-' . $fid . '-' . $opt_pat[$idx] . '" onClick="beg(' . $e['recordid'] . ',' . $fid . ',' . $opt_pat[$idx] . ')">' : '<td>';
while ($e = sql('SELECT `optionid`,`caption` FROM `options` WHERE `eventid`="' . $eventid . '" AND `fieldid`="' . $fid . '"')) { $options[$fid][$e['optionid']] = $e['caption']; } } else { if (sql('SELECT 1 FROM `pool` WHERE `eventid`="' . $eventid . '" AND `fieldid`="' . $fid . '" AND `recordid`="' . $rid . '"')) { sql_update('pool', array('value' => $_POST['data'][$k]), array('eventid' => $eventid, 'fieldid' => $fid, 'recordid' => $rid)); } else { sql_insert('pool', array('value' => $_POST['data'][$k]), array('eventid' => $eventid, 'fieldid' => $fid, 'recordid' => $rid)); } } } foreach ($records as $rid) { foreach ($checkbox[$rid] as $fid => $list) { if ($e = sql('SELECT `value` FROM `pool` WHERE `eventid`="' . $eventid . '" AND `fieldid`="' . $fid . '" AND `recordid`="' . $rid . '"')) { $dlist = $nlist = array(); $olist = linebreak($e['value']); foreach ($list as $optid => $opt) { if ($opt) { $nlist[] = $options[$fid][$optid]; } else { $dlist[] = $options[$fid][$optid]; } } foreach ($olist as $opt) { if (!in_array($opt, $dlist) && !in_array($opt, $nlist)) { $nlist[] = $opt; } } sql_update('pool', array('value' => implode("\n", $nlist)), array('eventid' => $eventid, 'fieldid' => $fid, 'recordid' => $rid)); } else { $nlist = array();