function split_csv_line($record) { $first = NULL; if (strlen($record) == 0) { return array(''); } if ($record[0] === '"') { $first = ''; $start = 1; while ($start < strlen($record) && ($end = strpos($record, '"', $start)) !== FALSE && $end < strlen($record) - 1 && $record[$end + 1] !== ',') { if ($record[$end + 1] !== '"') { die("Found characters between double-quoted field and comma."); } $first .= substr($record, $start, $end - $start - 1); $start = $end + 2; } if ($start < strlen($record) || $end === FALSE) { die("Could not find end-quote for double-quoted field"); } $first .= substr($record, $start, $end - $start - 1); if ($end >= strlen($record) - 1) { return array($first); } /* Assertion: $record[$end + 1] == ',' */ $rest = substr($record, $end + 2); } else { $end = strpos($record, ','); if ($end === FALSE) { return array($record); } /* Assertion: $end < strlen($record) */ $first = substr($record, 0, $end); $rest = substr($record, $end + 1); } $fields = split_csv_line($rest); array_unshift($fields, $first); return $fields; }
* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. */ $fake_register_globals = false; $sanitize_all_escapes = true; require_once '../../globals.php'; require_once $GLOBALS['srcdir'] . '/patient.inc'; require_once $GLOBALS['srcdir'] . '/csv_like_join.php'; require_once $GLOBALS['fileroot'] . '/custom/code_types.inc.php'; $info_msg = ""; $codetype = $_REQUEST['codetype']; if (!empty($codetype)) { $allowed_codes = split_csv_line($codetype); } $form_code_type = $_POST['form_code_type']; // Determine which code type will be selected by default. $default = ''; if (!empty($form_code_type)) { $default = $form_code_type; } else { if (!empty($allowed_codes) && count($allowed_codes) == 1) { $default = $allowed_codes[0]; } else { if (!empty($_REQUEST['default'])) { $default = $_REQUEST['default']; } } }