function load($classCall) { $names = getNames($classCall); if (checkRootNamespace($names)) { if (in_array('board', $names)) { loadBaseClass(end($names)); } elseif (in_array('apps', $names)) { loadApp(end($names), getAppType($names)); } else { findClass($names); } } }
/** * &query * Actualy the only one supported query is simple SELECT. * * @param string $sql * @return object(XMLResult) $result */ function &query($sql) { if (!isset($this->xmldoc)) { $err = new DB_Error("Error: Closed xmlConnection."); return $err; } if (1 === preg_match('/^\\s*SELECT\\s+([\\w\\W]+?)(?:\\s+FROM\\s+`?([^`]+?)`?)(?:\\s+WHERE\\s+([\\w\\W]+?))?(?:\\s+GROUP\\s+BY\\s+([\\w\\W]+?))?(?:\\s+ORDER\\s+BY\\s+([\\w\\W]+?))?(?:\\s+BETWEEN\\s+([\\w\\W]+?)\\s+AND\\s+([\\w\\W]+?))?(?:\\s+LIMIT\\s+(\\d+)\\s*,\\s*(\\d+))?\\s*$/im', $sql, $matches)) { $sqlColumns = $matches[1]; $sqlFrom = isset($matches[2]) ? $matches[2] : ''; $sqlWhere = isset($matches[3]) ? $matches[3] : ''; $sqlGroupBy = isset($matches[4]) ? $matches[4] : ''; $sqlOrderBy = isset($matches[5]) ? $matches[5] : ''; $sqlLowLimit = isset($matches[8]) ? $matches[8] : ''; $sqlHighLimit = isset($matches[9]) ? $matches[9] : ''; /* Start Block: Fields list */ $count = preg_match_all('/\\s*(\\*|[\\w\\.]+)(?:\\s+AS\\s+([\\w\\.]+))?/im', $sqlColumns, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $fieldsList = array(); for ($r = 0; $r < $count; $r++) { $name = is_array($match[2][$r]) && $match[2][$r][0] !== '' ? $match[2][$r][0] : $match[1][$r][0]; $fieldsList[$name] = $match[1][$r][0]; } /* End Block */ /* Start Block: Order list */ $count = preg_match_all('/\\s*(\\*|[\\w\\.]+)(\\s+ASC|\\s+DESC)?\\s*,?/im', $sqlOrderBy, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $orderList = array(); for ($r = $count - 1; $r >= 0; $r--) { $direction = is_array($match[2][$r]) && $match[2][$r][0] !== '' ? $match[2][$r][0] : 'ASC'; $direction = strtoupper($direction); $orderList[$match[1][$r][0]] = $direction; } /* End Block */ $xmlFrom = '/' . str_replace('.', '/', $sqlFrom); $node =& $this->xmldoc->findNode($xmlFrom); if (!isset($node)) { //$err = new DB_Error( "$xmlFrom node not found in $dsn." ); throw new Exception("{$xmlFrom} node not found in " . $this->xmlFile . "."); return $err; } else { $res = $this->fetchChildren($node); } /* Start Block: WHERE*/ if ($sqlWhere !== '') { /*Start Block: Replace the operator */ $blocks = preg_split('/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, -1, PREG_SPLIT_DELIM_CAPTURE); $sqlWhere = ''; for ($r = 0; $r < sizeof($blocks); $r++) { if ($r % 2 === 0) { $blocks[$r] = str_replace('=', '==', $blocks[$r]); $blocks[$r] = str_replace('<>', '!=', $blocks[$r]); $blocks[$r] = str_replace('AND', '&&', $blocks[$r]); $blocks[$r] = str_replace('and', '&&', $blocks[$r]); $blocks[$r] = str_replace('OR', '||', $blocks[$r]); $blocks[$r] = str_replace('or', '||', $blocks[$r]); $blocks[$r] = str_replace('NOT', '!', $blocks[$r]); $blocks[$r] = str_replace('not', '!', $blocks[$r]); $blocks[$r] = preg_replace('/\\b[a-zA-Z_][\\w\\.]*\\b/im', '$res[$r][\'$0\']', $blocks[$r]); $blocks[$r] = preg_replace('/\\$res\\[\\$r\\]\\[\'(like)\'\\]/im', '$1', $blocks[$r]); } $sqlWhere .= $blocks[$r]; } $sqlWhere = preg_replace_callback('/(.+)\\s+like\\s+("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', array('XMLConnection', 'sqlWhereLike'), $sqlWhere); $sqlWhere = preg_replace_callback('/"(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'/im', array('XMLConnection', 'sqlString'), $sqlWhere); $newRes = array(); for ($r = 0; $r < sizeof($res); $r++) { $evalWhere = false; @eval('$evalWhere = ' . $sqlWhere . ';'); if ($evalWhere) { $newRes[] = $res[$r]; } } $res = $newRes; } /* End Block */ /* Start Block: Expands the resultant data according to fill an array * with the required fields in the query. */ for ($r = 0; $r < sizeof($res); $r++) { $res[$r] = $this->expandFields($res[$r], $fieldsList); } /* End Block */ /* Start Block: ORDER BY*/ foreach ($orderList as $field => $direction) { for ($i = 0; $i < sizeof($res); $i++) { for ($j = $i + 1; $j < sizeof($res); $j++) { $condition = $direction === 'ASC' ? $res[$j] < $res[$i] : $res[$j] > $res[$i]; if ($condition) { $swap = $res[$i]; $res[$i] = $res[$j]; $res[$j] = $swap; } } } } /* End Block */ /* Start Block: Apply limits */ if ($sqlLowLimit != '' && $sqlHighLimit != '') { $sqlLowLimit = (int) $sqlLowLimit; $sqlHighLimit = (int) $sqlHighLimit; $res = array_slice($res, $sqlLowLimit, $sqlHighLimit); } /* End Block */ $result = new XMLResult($res); return $result; } elseif (1 === preg_match('/^\\s*DELETE\\s+FROM\\s+`?([^`]+?)`?(?:\\s+WHERE\\s+([\\w\\W]+?))?\\s*$/im', $sql, $matches)) { $sqlFrom = isset($matches[1]) ? $matches[1] : ''; $sqlWhere = isset($matches[2]) ? $matches[2] : '1'; /* Start Block: WHERE*/ /*Start Block: Replace the operator */ $blocks = preg_split('/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, -1, PREG_SPLIT_DELIM_CAPTURE); $sqlWhere = ''; for ($r = 0; $r < sizeof($blocks); $r++) { if ($r % 2 === 0) { $blocks[$r] = str_replace('=', '==', $blocks[$r]); $blocks[$r] = str_replace('<>', '!=', $blocks[$r]); $blocks[$r] = str_replace('AND', '&&', $blocks[$r]); $blocks[$r] = str_replace('and', '&&', $blocks[$r]); $blocks[$r] = str_replace('OR', '||', $blocks[$r]); $blocks[$r] = str_replace('or', '||', $blocks[$r]); $blocks[$r] = str_replace('NOT', '!', $blocks[$r]); $blocks[$r] = str_replace('not', '!', $blocks[$r]); $blocks[$r] = preg_replace('/\\b[a-zA-Z_][\\w\\.]*\\b/im', '$res[$r][\'$0\']', $blocks[$r]); $blocks[$r] = preg_replace('/\\$res\\[\\$r\\]\\[\'(like)\'\\]/im', '$1', $blocks[$r]); } $sqlWhere .= $blocks[$r]; } /* End Block */ $sqlWhere = preg_replace_callback('/(.+)\\s+like\\s+("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', array('XMLConnection', 'sqlWhereLike'), $sqlWhere); $sqlWhere = preg_replace_callback('/"(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'/im', array('XMLConnection', 'sqlString'), $sqlWhere); /*Start Block: Removing fields */ $xmlFrom = '/' . str_replace('.', '/', $sqlFrom); $node =& $this->xmldoc->findNode($xmlFrom); if (!isset($node)) { $err = new DB_Error("{$xmlFrom} node not found!."); return $err; } else { $res = $this->fetchChildren($node); } $newRes = array(); for ($r = 0; $r < sizeof($res); $r++) { $evalWhere = false; @eval('$evalWhere = ' . $sqlWhere . ';'); if ($evalWhere) { unset($node->children[$r]); $newRes[] = $res[$r]; } } //Re-index $node->children = array_values($node->children); /* End Block */ $this->xmldoc->save($this->xmlFile); $result = new XMLResult($newRes); return $result; } elseif (1 === preg_match('/^\\s*INSERT\\s+INTO\\s+`?([^`]+?)`?\\s*\\(([\\w\\W]+?)\\)\\s+VALUES\\s*\\(([\\w\\W]+?)\\)\\s*$/im', $sql, $matches)) { $sqlFrom = isset($matches[1]) ? $matches[1] : ''; $sqlColumns = isset($matches[2]) ? $matches[2] : '1'; $sqlValues = isset($matches[3]) ? $matches[3] : '1'; $xmlFrom = '/' . str_replace('.', '/', $sqlFrom); $node =& $this->xmldoc->findNode($xmlFrom); /* Start Block: Fields list */ $count = preg_match_all('/([\\w\\.]+)/im', $sqlColumns, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $fieldsList = array(); for ($r = 0; $r < $count; $r++) { $fieldsList[] = $match[1][$r][0]; } /* End Block */ /* Start Block: Fields Values */ $count = preg_match_all('/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\\d+)/im', $sqlValues, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $fieldsValues = array(); for ($r = 0; $r < $count; $r++) { if (substr($match[1][$r][0], 0, 1) === '"') { $match[1][$r][0] = substr($match[1][$r][0], 1, -1); $match[1][$r][0] = str_replace('""', '"', $match[1][$r][0]); $match[1][$r][0] = str_replace("''", "'", $match[1][$r][0]); } if (substr($match[1][$r][0], 0, 1) === "'") { $match[1][$r][0] = substr($match[1][$r][0], 1, -1); $match[1][$r][0] = str_replace("''", "'", $match[1][$r][0]); $match[1][$r][0] = str_replace('""', '"', $match[1][$r][0]); } $fieldsValues[$fieldsList[$r]] = $match[1][$r][0]; } /* End Block */ $AAA = getNames($this->xmldoc->children[0]->children); $this->insertRow($node, $fieldsValues); $DDD = getNames($this->xmldoc->children[0]->children); $this->xmldoc->save($this->xmlFile); $result = new XMLResult(array($fieldsValues)); return $result; } elseif (1 === preg_match('/^\\s*UPDATE\\s+`?([^`]+?)`?\\s+SET\\s+((?:(?:[a-z][\\w\\.]*)\\s*=\\s*(?:"(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\\d+)\\s*(?:,\\s*)?)+)(?:\\s+WHERE\\s+([\\w\\W]+?))?\\s*$/im', $sql, $matches)) { $sqlFrom = isset($matches[1]) ? $matches[1] : ''; $sqlColumns = isset($matches[2]) ? $matches[2] : ''; $sqlWhere = isset($matches[3]) ? $matches[3] : '1'; $count = preg_match_all('/([a-z][\\w\\.]*)\\s*=\\s*("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\\d+)/im', $sqlColumns, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); $fieldsValues = array(); for ($r = 0; $r < $count; $r++) { if (substr($match[2][$r][0], 0, 1) === '"') { $match[2][$r][0] = substr($match[2][$r][0], 1, -1); $match[2][$r][0] = str_replace('""', '"', $match[2][$r][0]); $match[2][$r][0] = str_replace("''", "'", $match[2][$r][0]); } if (substr($match[2][$r][0], 0, 1) === "'") { $match[2][$r][0] = substr($match[2][$r][0], 1, -1); $match[2][$r][0] = str_replace("''", "'", $match[2][$r][0]); $match[2][$r][0] = str_replace('""', '"', $match[2][$r][0]); } $fieldsValues[$match[1][$r][0]] = $match[2][$r][0]; } /* Start Block: WHERE*/ /*Start Block: Replace the operator */ $blocks = preg_split('/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, -1, PREG_SPLIT_DELIM_CAPTURE); $sqlWhere = ''; for ($r = 0; $r < sizeof($blocks); $r++) { if ($r % 2 === 0) { $blocks[$r] = str_replace('=', '==', $blocks[$r]); $blocks[$r] = str_replace('<>', '!=', $blocks[$r]); $blocks[$r] = str_replace('AND', '&&', $blocks[$r]); $blocks[$r] = str_replace('and', '&&', $blocks[$r]); $blocks[$r] = str_replace('OR', '||', $blocks[$r]); $blocks[$r] = str_replace('or', '||', $blocks[$r]); $blocks[$r] = str_replace('NOT', '!', $blocks[$r]); $blocks[$r] = str_replace('not', '!', $blocks[$r]); $blocks[$r] = preg_replace('/\\b[a-zA-Z_][\\w\\.]*\\b/im', '$res[$r][\'$0\']', $blocks[$r]); $blocks[$r] = preg_replace('/\\$res\\[\\$r\\]\\[\'(like)\'\\]/im', '$1', $blocks[$r]); } $sqlWhere .= $blocks[$r]; } /* End Block */ $sqlWhere = preg_replace_callback('/(.+)\\s+like\\s+("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', array('XMLConnection', 'sqlWhereLike'), $sqlWhere); $sqlWhere = preg_replace_callback('/"(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'/im', array('XMLConnection', 'sqlString'), $sqlWhere); /*Start Block: Removing fields */ $xmlFrom = '/' . str_replace('.', '/', $sqlFrom); $node =& $this->xmldoc->findNode($xmlFrom); if (!isset($node)) { $err = new DB_Error("{$xmlFrom} node not found in {$dsn}."); return $err; } else { $res = $this->fetchChildren($node); } $newRes = array(); for ($r = 0; $r < sizeof($res); $r++) { $evalWhere = false; @eval('$evalWhere = ' . $sqlWhere . ';'); if ($evalWhere) { $this->updateRow($node->children[$r], $fieldsValues); $newRes[] = array_merge($res[$r], $fieldsValues); } } /* End Block */ $nodeTEST =& $this->xmldoc->findNode($xmlFrom); $this->xmldoc->save($this->xmlFile); $result = new XMLResult($newRes); return $result; } else { echo $sql; $err = new DB_Error("SQL Query is not well formed."); return $err; } }
$MSH = $xml->queryNode("MSH"); $EVN = $xml->queryNode("EVN"); $PID = $xml->queryNode("PID"); $PV1 = $xml->queryNode("PV1"); $PV2 = $xml->queryNode("PV2"); $ZBE = $xml->queryNode("ZBE"); $IPP = $NDA = null; $data = array(); $data["personIdentifiers"] = $xml->getPersonIdentifiers("PID.3", $PID, $actor); $data["admitIdentifiers"] = $xml->getAdmitIdentifiers($PV1, $actor); $names = array("nom" => "", "nom_jeune_fille" => ""); $prenom = null; $PID5 = $xml->query("PID.5", $PID); foreach ($PID5 as $_PID5) { // Nom(s) getNames($xml, $_PID5, $PID5, $names); // Prenom(s) $prenom = getFirstNames($xml, $_PID5); } $queries = array("Message" => array("control_id" => $xml->queryTextNode("MSH.10", $MSH), "datetime" => CMbDT::dateToLocale($xml->queryTextNode("MSH.7/TS.1", $MSH))), "EVN" => array("planned_event" => CMbDT::dateToLocale($xml->queryTextNode("EVN.2/TS.1", $EVN)), "event_occurred" => CMbDT::dateToLocale($xml->queryTextNode("EVN.6/TS.1", $EVN))), "CPatient" => array("nom" => $names["nom"], "nom_jeune_fille" => $names["nom_jeune_fille"], "prenom" => $prenom, "naissance" => CMbDT::dateToLocale($xml->queryTextNode("PID.7", $PID)), "_IPP" => CValue::read($data["personIdentifiers"], "PI")), "CSejour" => array("type" => $xml->queryTextNode("PV1.2", $PV1), "entree_prevue" => CMbDT::dateToLocale($xml->queryTextNode("PV2.8/TS.1", $PV2)), "entree_reelle" => CMbDT::dateToLocale($xml->queryTextNode("PV1.44/TS.1", $PV1)), "sortie_prevue" => CMbDT::dateToLocale($xml->queryTextNode("PV2.9/TS.1", $PV2)), "sortie_reelle" => CMbDT::dateToLocale($xml->queryTextNode("PV1.45/TS.1", $PV1)), "_NDA" => CValue::read($data["personIdentifiers"], "AN"))); if ($ZBE) { $movement_id = null; foreach ($xml->queryNodes("ZBE.1", $ZBE) as $ZBE_1) { $movement_id .= $xml->queryTextNode("EI.1", $ZBE_1) . "\n"; } $queries_ZBE = array("CMovement" => array("movement_id" => $movement_id, "start_of_movement" => CMbDT::dateToLocale($xml->queryTextNode("ZBE.2/TS.1", $ZBE)))); $queries = array_merge($queries, $queries_ZBE); } function getNames(CHL7v2MessageXML $xml, DOMNode $node, DOMNodeList $PID5, &$names = array()) { $fn1 = $xml->queryTextNode("XPN.1/FN.1", $node);
if ($val != "." && $val != "..") { $a = strpos($val, "."); if ($a == 0) { $a = strlen($val); } $newentry = substr($val, 0, $a); if (substr($newentry, 0, 1) != $currval) { if ($currval != "1") { print "\n\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t "; } $currval = substr($newentry, 0, 1); if ($currval == "N") { print "</td><td valign=\"top\">"; } print "\n\t\t<br>\n\t\t<table class='ltable' cellpadding='0' cellspacing='0'>\n\t\t<tr>\n\t\t<td class='letter'>\n\t\t{$currval}\n\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t<td class='info' valign='top'>\n\t\t"; } print "<a href=\"profiles/{$newentry}.htm\">{$newentry}</a> <br>"; } } closedir($d); } } getNames("profiles/"); ?> </td> </tr> </table> </BODY> </HTML>
$studentCategories = array(); $teachers = array(); $teacherCategories = array(); $studentCouple1 = 0; $studentCouple2 = 0; if (isset($_POST['publicId']) && isset($_POST['voteCode'])) { $publicId = strip_tags($_POST['publicId']); $accountId = getAccountId($publicId, ''); $voteCode = strip_tags($_POST['voteCode']); if ($accountId !== FALSE) { $voteCodeId = checkVoteCode($voteCode, $accountId); if ($voteCodeId) { $votes = getVotes($voteCodeId); $students = getNames('student', $accountId); $studentCategories = getCategories('student', $accountId, $votes); $teachers = getNames('teacher', $accountId); $teacherCategories = getCategories('teacher', $accountId, $votes); $pdos = $GLOBALS['pdo']->prepare(' SELECT `Couple1`, `Couple2` FROM `CoupleVote` WHERE `VoteCode` = :voteCode '); $pdos->bindValue(':voteCode', $voteCodeId); $pdos->execute(); $result = $pdos->fetch(); $studentCouple1 = $result['Couple1']; $studentCouple2 = $result['Couple2']; $success = TRUE;
function print_all() { $params = func_get_args(); foreach ($params as $param) { echo "<br/>{$param}"; } } print_all('a', 'e', 'i', 'o', 'u'); // return by reference $names = array('a man', 'b man', 'c man'); function &getNames() { global $names; return $names; } $names_ref =& getNames(); $names_ref[0] = 'p-man'; echo "<br/>{$names['0']}"; // variable function $func = 'print_all'; $func('yo', 'momma', 'so', 'fat'); // anonymous function $array = array("really long string here, boy", "this", "middling length", "larger"); usort($array, function ($a, $b) { return strlen($a) - strlen($b); }); print_r($array); $sortOption = 'desc'; usort($array, function ($a, $b) use($sortOption) { if ($sortOption == 'desc') { return strlen($b) - strlen($a);
<th>合計</th> <th>最終履歴</th> <th>#</th> </tr> </thead> <tbody> <?php require "logic.php"; if (isset($_GET["name_id"])) { $result = checkin($_GET["name_id"]); } else { if (isset($_GET["id"])) { $result = checkout($_GET["id"]); } } $result = getNames(); $time_add = array(); $start = array(); $end = array(); $flag = array(); $ids = array(); while ($row = mysql_fetch_assoc($result)) { $time_result = getTimes($row["id"]); $time_add[$row["name"]] = 0; $flag[$row["name"]] = 0; $ids[$row["name"]] = $row["id"]; while ($time_row = mysql_fetch_assoc($time_result)) { if ($time_row["end"] === NULL) { $flag[$row["name"]] = $time_row["id"]; $start[$row["name"]] = date('Y-m-d H:i:s', strtotime($time_row["start"])); } else {
if (count($argv) < 4) { echo "Must enter 3 parameters: inputFile1.xml, inputFile2.xml, outputFile.xml\n"; $errorFound = true; } if (!$errorFound) { $file1 = file_get_contents($argv[1]); $file2 = file_get_contents($argv[2]); $outputFileName = $argv[3]; //Grab the header block and the footer block from the first file. We aren't going to merge those. $foo = explode("<types>", $file1, 2); $header = trim($foo[0]); $bar = explode("<version>", $file1, 2); $footer = INDENT . '<version>' . trim($bar[1]); $xml1 = simplexml_load_string($file1); $xml2 = simplexml_load_string($file2); $arrNames = getNames($xml1, $xml2); //a sorted, unique, indexed array of all the metadata type names merged from both files //parse these into associative arrays where the key is the <name> value and the value is an indexed array of all the <member> values $arrXml1 = transformToArray($xml1); $arrXml2 = transformToArray($xml2); $arrMergeSort = mergeAndSort($arrNames, $arrXml1, $arrXml2); $xmlOut = makeXML($arrNames, $arrMergeSort, $header, $footer); file_put_contents($outputFileName, $xmlOut); } function makeXML($arrNames, $arrMergeSort, $header, $footer) { $xmlOut = ''; $xmlOut .= $header . NEWLINE; //loop through the names foreach ($arrNames as $name) { $xmlOut .= INDENT . '<types>' . NEWLINE;