function eventform($data, $uid) { global $xoopsUser, $xoopsModuleConfig; $poster = $uid ? new XoopsUser($uid) : $xoopsUser; $uid = is_object($poster) ? $poster->getVar('uid') : 0; $myts =& MyTextSanitizer::getInstance(); if (empty($data['reservation'])) { return null; } $form = array('uid' => $uid, 'poster' => $poster, 'uname' => display_username($uid)); $optfield = $data['optfield']; // reservation form if (isset($_POST['email'])) { $email = $myts->stripSlashesGPC($_POST['email']); } else { $email = is_object($poster) ? $poster->email() : ""; } $conf = isset($_POST['email_conf']) ? $myts->stripSlashesGPC($_POST['email_conf']) : $email; $form['email'] = $myts->makeTboxData4Edit($email); $form['email_conf'] = $myts->makeTboxData4Edit($conf); $form['user_notify'] = $xoopsModuleConfig['user_notify']; $form['check'] = array(); $mo = $xoopsModuleConfig['member_only'] != ACCEPT_EMAIL && is_object($poster); $form['member_only'] = $mo; if (!$mo) { $form['check']['email'] = preg_replace('/\\*$/', '', _MD_EMAIL) . ": " . strip_tags(_MD_ORDER_NOTE1); } $items = array(); $field = 0; $note1 = $note2 = ""; foreach (explode("\n", $optfield) as $n) { $field++; $n = rtrim($n); if ($n == "") { continue; } $attr = ""; $require = false; if (preg_match('/^\\s*#/', $n)) { $opts = preg_replace('/^\\s*#\\s*/', "", $n); $type = "#"; $name = " "; } else { $opt = array(); $p = 0; $len = strlen($n); while ($p < $len) { $w = ''; while ($p < $len) { $c = $n[$p++]; if ($c == ',') { break; } if ($c == '\\' && $p < $len) { $c = $n[$p++]; if ($c == 'n') { $c = "\n"; } elseif ($c != '\\' && $c != ',') { $c = "\\{$c}"; } } $w .= $c; } $opt[] = $w; } $name = array_shift($opt); if (preg_match('/[\\*#]$/', $name)) { $require = true; $attr = 'evms'; $note1 = _MD_ORDER_NOTE1; } if (preg_match('/^!/', $name)) { $name = preg_replace('/^!/', '', $name); $attr = 'evop'; $note2 = _MD_ORDER_NOTE2; } $v = ""; $type = "text"; $aname = isset($opt[0]) ? strtolower($opt[0]) : ""; switch ($aname) { case "hidden": case "const": case "text": case "checkbox": case "radio": case "textarea": case "select": $type = $aname; array_shift($opt); } if ($type == 'hidden') { continue; } $size = eguide_form_options('size', 60); $cols = eguide_form_options('cols', 40); $rows = eguide_form_options('rows', 5); $opts = ""; $comment = ""; $fname = "opt{$field}"; $sub = 0; $prop = ''; if (isset($_POST[$fname])) { $v = $myts->stripSlashesGPC($_POST[$fname]); } while ($opt) { $op = array_shift($opt); if (preg_match("/^#/", $op)) { array_unshift($opt, preg_replace("/^#/", "", $op)); $comment .= join(',', $opt); $opt = array(); continue; } $args = explode("=", $op, 2); // XXX: strtolower PHP4 mbstring bug escape. $aname = isset($args[1]) ? strtolower($args[0]) : $args[0]; switch ($aname) { case "size": $size = $args[1]; break; case "rows": $rows = $args[1]; break; case "cols": $cols = $args[1]; break; case 'prop': $prop = $args[1]; break; default: $an = preg_replace('/\\+$/', "", $args[0]); if ($v) { $ck = $an == $v ? " checked='checked'" : ""; } else { $ck = $an != $args[0] ? " checked='checked'" : ""; } if ($type == 'radio') { $sub++; if (isset($args[1])) { $opts .= "<label><input type='{$type}' name='{$fname}' value='{$an}'{$ck} {$prop}/>" . $args[1] . "</label> "; } else { $opts .= "<label><input type='{$type}' name='{$fname}' value='{$an}'{$ck} {$prop}/>{$an}</label> "; } } elseif (in_array($type, array('text', 'textarea', 'const'))) { if (!isset($_POST[$fname])) { $v .= ($v == "" ? "" : ",") . $op; } } elseif ($type == 'checkbox') { if (isset($_POST[$fname])) { $ck = in_array($an, $_POST[$fname]) ? ' checked' : ''; } $lab = empty($args[1]) ? "{$an} " : $args[1] . " "; $opts .= "<label><input type='{$type}' name='{$fname}[]' id='{$fname}[]' value='{$an}'{$ck} {$prop}/>" . $lab . "</label>"; } elseif ($type == 'select') { if ($ck != "") { $ck = " selected"; } $lab = empty($args[1]) ? $an : $args[1]; $opts .= "<option value='{$an}'{$ck}>{$lab}</option>\n"; } } } if (!isset($_POST[$fname])) { if (empty($v) && $poster && preg_match(_MD_NAME, $name)) { // compat old version $v = $poster->getVar('name'); } else { $v = apply_user_vars($v); } $v = htmlspecialchars($v); } if ($type == "text") { $opts .= "<input size='{$size}' name='{$fname}' value=\"{$v}\" {$prop}/>"; } elseif ($type == "textarea") { $opts .= "<textarea name='{$fname}' rows='{$rows}' cols='{$cols}' wrap='virtual' {$prop}>{$v}</textarea>"; } elseif ($type == "select") { $opts = "<select name='{$fname}' {$prop}>\n{$opts}</select>"; } elseif ($type == "const") { $opts = $v; } } if ($require) { if ($type == 'checkbox') { $fname .= '[]'; } $form['check'][$fname] = preg_replace('/\\*$/', '', $name) . ": " . strip_tags(_MD_ORDER_NOTE1); } $name = preg_replace('/\\*$/', _MD_REQUIRE_MARK, $name); if ($attr == 'evop') { $name = sprintf(_MD_LISTITEM_FMT, $name); } $items[] = array('attr' => $attr, 'label' => $name, 'value' => $opts, 'comment' => $comment); } $form['op'] = $xoopsModuleConfig['has_confirm'] && (count($items) || !$mo) ? 'confirm' : 'order'; $form['items'] = $items; $form['note'] = $note1 . (!empty($note1) && !empty($note2) ? " " : "") . $note2; $form['eid'] = empty($data['eid']) ? 0 : $data['eid']; $form['options'] = eguide_form_options(); return $form; }
function get_opt_values($optfield, &$errs, $hidden = false, $view = true) { $myts =& MyTextSanitizer::getInstance(); $result = array(); $field = 0; foreach (explode("\n", $optfield) as $n) { $field++; if (preg_match('/^\\s*#/', $n)) { continue; } if (preg_match('/^\\s*$/', $n)) { continue; } $a = preg_split("/,\\s*/", preg_replace('/[\\n\\r]/', "", $n)); $name = preg_replace('/^!\\s*/', '', array_shift($a)); $fname = preg_replace('/[\\*\\#]$/', "", $name); $type = "text"; $iname = "opt{$field}"; if (isset($a[0])) { $ty = strtolower(array_shift($a)); switch ($ty) { case 'hidden': case 'const': if (!$hidden) { // pseudo POST variable $_POST[$iname] = $result[$fname] = apply_user_vars(join(',', $a)); } case "checkbox": case 'textarea': $type = $ty; break; } } $input = ""; if ($type == 'hidden' || $type == 'const') { continue; } elseif ($type == 'checkbox') { $v = ""; if (!empty($_POST[$iname])) { foreach ($_POST[$iname] as $vv) { $v .= ($v == "" ? "" : ",") . $myts->stripSlashesGPC($vv); if ($hidden) { $input .= "<input type='hidden' name='{$iname}[]' id='{$iname}[]' value='" . $myts->makeTboxData4Edit($vv) . "'/>"; } } } } else { $v = $myts->stripSlashesGPC($_POST["opt{$field}"]); if ($type != 'textarea') { $v = preg_replace('/\\n.*$/s', '', $v); } if ($hidden) { $input .= "<input type='hidden' name='opt{$field}' value='" . $myts->makeTboxData4Edit($v) . "'/>"; } // remove control char except textarea if ($type != 'textarea') { $v = preg_replace('/[\\x00-\\x1f]/', '', $v); } } $must = preg_match('/\\*$/', $name); $nums = preg_match('/\\#$/', $name); if ($must) { // check for NULL if (preg_match('/^\\s*$/', $v)) { $errs[] = "{$fname}: " . _MD_NOITEM_ERR; } } elseif ($nums) { // check Number if (!preg_match('/^-?\\d+$/', $v)) { $errs[] = "{$fname}: {$v} - " . _MD_NUMITEM_ERR; } } $result[$fname] = $hidden ? $input : ($view ? $myts->displayTarea($v) : $v); } return $result; }