function generateVesselName() { db_connect(); db("SELECT content FROM vessels WHERE name = 'Grecs'"); $serialized_greeks = dbr(1); db("SELECT content FROM vessels WHERE name = 'Stars'"); $serialized_stars = dbr(1); //la liste de noms est désérialisée $greeks = unserialize($serialized_greeks['content']); $stars = unserialize($serialized_stars['content']); $greek = array_rand($greeks); $star = array_rand($stars); $name = $greeks[$greek] . " " . $stars[$star]; //si un vaisseau a déjà un nom identique, incrémenter le numéro $counter = "2"; $new_name = $name; if (shipExists($new_name)) { while (shipExists($new_name)) { $new_name = $name; $new_name = $new_name . " " . roman($counter); $counter = $counter + 1; } } return $new_name; }
<?php function roman() { return array("I" => 1, "V" => 5, "X" => 10, "L" => 50, "C" => 100, "D" => 500, "M" => 1000); } // echo roman()["D"] $r = roman(); echo $r["D"];
function crear_pregunta($p) { $out = ''; foreach ($p as $key => $value) { ${$key} = $value; } $alternative = explode('||', $alternative); $options = explode('||', $options); $out = ''; // $out = '(***--'.$id.'--***)'; switch ($type) { case 'alt': $out .= '<p class="rotulo">' . $label . ':<br/>(' . $score . ' punto)</p>'; if (count($options) > 1) { $out .= '<table class="alt_opciones" cellpadding="0" cellspacing="0">'; for ($i = 0; $i < count($options); $i++) { $out .= '<tr><td align="right" valign="top" width="50px">' . roman($i + 1) . '. </td><td align="left">' . $options[$i] . '</td></tr>'; } $out .= '</table>'; } $out .= '<table class="alt_respuestas" cellpadding="3" cellspacing="0">'; foreach ($alternative as $k => $a) { $out .= '<tr><td align="right" width="40"><input type="radio" name="radio' . $id . '" value="' . $k . '" /></td><td class="alt" width="630">' . $a . '</td></tr>'; } $out .= '</table>'; break; case 'alt2': $out .= $label . '<br/>(' . $score . ' punto)'; $out .= '<table class="alt_respuestas" cellpadding="3" cellspacing="0">'; foreach ($alternative as $k => $o) { $out .= '<tr><td align="right" width="40" valign="top"><input type="checkbox" name="checkbox' . $id . '_' . $k . '" /></td><td valign="top" class="alt" width="630">' . $o . '</td></tr>'; } $out .= '</table>'; break; case 'emp': $out .= '<p class="rotulo">Asigne escriba la letra de la afirmación o definición de la columna izquierda en la casilla correspondiente de la columna derecha</p>'; $out .= $label ? '<p class="rotulo">' . $label . '<br/>(' . $score . ' puntos)</p>' : '(' . $score . ' punto)'; $out .= '<table class="vf emp" cellpadding="3" cellspacing="1"><tr><td width="55%" valign="top">'; foreach ($alternative as $o) { $o = explode('¬¬', $o); $out .= '<div class="emp_alternativa"><strong>' . $o[0] . '</strong> ' . $o[1] . '</div>'; } $out .= '</td><td valign="top">'; $aux = explode('||', $answer); foreach ($aux as $k => $o) { $o = explode('¬¬', $o); $out .= '<div class="emp_alternativa"><input type="text" name="' . $id . '_' . $k . '" id="' . $id . '_' . $k . '" maxlength="1" style="width:18px" /> ' . $o[1] . '</div>'; } $out .= '</td></tr></table>'; break; case 'vf': $out .= '<p class="rotulo">'; $out .= $label ? $label : 'Determine si la siguiente afirmación es verdadera (V) o falsa (F):'; $out .= '<br/>(' . $score . ' punto)</p><table class="vf" cellpadding="3" cellspacing="1"><tr><th> </th><th>V</th><th>F</th></tr>'; foreach ($alternative as $k => $o) { $out .= '<tr><td>' . $o . '</td><td><input type="radio" name="radio' . $id . '_' . $k . '" value="1" /></td><td><input type="radio" name="radio' . $id . '_' . $k . '" value="0" /></td></tr>'; } $out .= '</table>'; break; case 'ord': $out .= $label . '<br/>(' . $answer . ' puntos)'; $out .= '<table class="alt_respuestas" cellpadding="4" cellspacing="0">'; $answer = explode('||', $answer); foreach ($answer as $k => $o) { $o = explode('¬¬', $o); $out .= '<tr><td align="right" width="40"><input style="width:18px" type="text" name="ord' . $id . '_' . $k . '" /></td><td class="alt" width="630">' . $o[1] . '</td></tr>'; } $out .= '</table>'; break; default: return false; break; } return $out; }
$mypage->title_body('To Do list - printable'); $mypage->leaf('h3', 'To Do list - printable'); if ($QR === 'NONE') { $mypage->leaf('p', 'There are no To Do list items to display.'); } else { $mypage->opennode('ul'); while ($row = db_fetch_assoc($QR)) { $mypage->leaf('li', $row['Description'], 'style="margin-top: 1px;"'); if (!is_null($row['Item'])) { $QRX = dbquery(DBQUERY_READ_RESULTSET, 'SELECT "Description" FROM "ToDoListSubItem" WHERE "Item" = :item: ORDER BY "OrderingNumber"', 'item', $row['ItemID']); if ($QRX !== 'NONE') { $mypage->opennode('table', 'class="table_no_borders" style="text-align: right;"'); $i = 0; while ($rowx = db_fetch_assoc($QRX)) { $mypage->opennode('tr', 'style="height: 1em;"'); $mypage->leaf('td', roman($i), 'width=30 class="font_serif" style="vertical-align: top; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px;"'); $mypage->leaf('td', $rowx['Description'], 'align=left class="font_serif" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 2px;"'); $mypage->closenode(); // tr $i++; } $mypage->closenode(); // ol } } } $mypage->closenode(); // ul } $mypage->finish(); }
/** * @brief Handle OpenURL request * * We may have more than one parameter with same name, so need to access QUERY_STRING, not _GET * http://stackoverflow.com/questions/353379/how-to-get-multiple-parameters-with-same-name-from-a-url-in-php * */ function main() { global $config; global $couch; $debug_openurl = false; $webhook = ''; $callback = ''; // If no query parameters if (count($_GET) == 0) { //display_form(); exit(0); } if (isset($_GET['webhook'])) { $webhook = $_GET['webhook']; } if (isset($_GET['debug'])) { $debug_openurl = true; } if (isset($_GET['callback'])) { $callback = $_GET['callback']; } // Handle query and display results. $query = explode('&', html_entity_decode($_SERVER['QUERY_STRING'])); $params = array(); foreach ($query as $param) { list($key, $value) = explode('=', $param); $key = preg_replace('/^\\?/', '', urldecode($key)); $params[$key][] = trim(urldecode($value)); } // This is what we got from user $context_object = new stdclass(); parse_openurl($params, $context_object); //print_r($context_object); // OK, can we find this? // result object $openurl_result = new stdclass(); $openurl_result->status = 404; $openurl_result->context_object = $context_object; $openurl_result->results = array(); if ($debug_openurl) { $openurl_result->debug = new stdclass(); } // via DOI or other identifier if (count($openurl_result->results) == 0) { // identifier search if (isset($context_object->referent->identifier)) { //print_r($context_object->referent->identifier); $found = false; foreach ($context_object->referent->identifier as $identifier) { if ($debug_openurl) { $openurl_result->debug->identifiers[] = $identifier; } if (!$found) { switch ($identifier->type) { case 'doi': $url = $config['couchdb_options']['database'] . "/_design/identifier/_view/doi?key=" . urlencode('"' . $identifier->id . '"'); //echo $url . '<br />'; if ($config['stale']) { $url .= '&stale=ok'; } $resp = $couch->send("GET", "/" . $url . '&limit=1'); $result = json_decode($resp); if (count($result->rows) == 1) { $openurl_result->debug->found_from_identifiers = true; $found = true; $match = new stdclass(); $match->match = true; $match->id = $result->rows[0]->id; $match->{$identifier->type} = $identifier->id; $openurl_result->results[] = $match; $openurl_result->status = 200; } break; case 'pmid': $url = $config['couchdb_options']['database'] . "/_design/identifier/_view/pmid?key=" . $identifier->id; //echo $url . '<br />'; if ($config['stale']) { $url .= '&stale=ok'; } $resp = $couch->send("GET", "/" . $url . '&limit=1'); $result = json_decode($resp); if (count($result->rows) == 1) { $openurl_result->debug->found_from_identifiers = true; $found = true; $match = new stdclass(); $match->match = true; $match->id = $result->rows[0]->id; $match->{$identifier->type} = $identifier->id; $openurl_result->results[] = $match; $openurl_result->status = 200; } break; default: break; } } } } } // classical OpenURL lookup using [ISSN,volume,spage] triple if (count($openurl_result->results) == 0) { $triple = false; if (isset($context_object->referent->journal->name)) { $journal = $context_object->referent->journal->name; // Convert accented characters $journal = strtr(utf8_decode($journal), utf8_decode("ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž"), "aaaaaaaaaaaaaaaaaaccccccccccddddddeeeeeeeeeeeeeeeeeegggggggghhhhiiiiiiiiiiiiiiiiiijjkkkllllllllllnnnnnnnnnnnoooooooooooooooooorrrrrrsssssssssttttttuuuuuuuuuuuuuuuuuuuuwwyyyyyyzzzzzz"); $journal = utf8_encode($journal); $journal = strtolower($journal); $journal = preg_replace('/\\bfor\\b/', '', $journal); $journal = preg_replace('/\\band\\b/', '', $journal); $journal = preg_replace('/\\bof\\b/', '', $journal); $journal = preg_replace('/\\bthe\\b/', '', $journal); $journal = preg_replace('/\\bde\\b/', '', $journal); $journal = preg_replace('/\\bla\\b/', '', $journal); $journal = preg_replace('/\\bet\\b/', '', $journal); // whitespace $journal = preg_replace('/\\s+/', '', $journal); // punctuation $journal = preg_replace('/[\\.|,|\'|\\(|\\)]+/', '', $journal); if (isset($context_object->referent->journal->volume)) { $volume = $context_object->referent->journal->volume; if (isset($context_object->referent->journal->pages)) { if (is_numeric($context_object->referent->journal->pages)) { $spage = $context_object->referent->journal->pages; $triple = true; } else { if (preg_match('/^(?<spage>\\d+)--(?<epage>\\d+)$/', $context_object->referent->journal->pages, $m)) { $spage = $m['spage']; $triple = true; } } } } if ($triple) { if ($debug_openurl) { $openurl_result->debug->triple = $triple; $openurl_result->debug->journal = $journal; } $openurl_result->status = 200; // i. get ISSN $url = $config['couchdb_options']['database'] . "/_design/openurl/_view/journal_to_issn?key=" . urlencode('"' . $journal . '"'); //echo $url; if ($config['stale']) { $url .= '&stale=ok'; } //echo $url; $resp = $couch->send("GET", "/" . $url . '&limit=1'); $result = json_decode($resp); //print_r($resp); if (count($result->rows) == 1) { // we have an ISSN for this journal $issn = $result->rows[0]->value; if ($debug_openurl) { $openurl_result->debug->issn = $issn; } // build triple [ISSN, volume, spage] $keys = array($issn, $volume, $spage); if ($debug_openurl) { $openurl_result->debug->keys = $keys; } $url = $config['couchdb_options']['database'] . "/_design/openurl/_view/issn_triple?key=" . urlencode(json_encode($keys)); //echo $url . '<br />'; if ($config['stale']) { $url .= '&stale=ok'; } $resp = $couch->send("GET", "/" . $url); $r = json_decode($resp); //print_r($r); if (count($r->rows) > 0) { foreach ($r->rows as $row) { $match = new stdclass(); $match->match = true; $match->triple = $keys; $match->id = $row->id; $openurl_result->results[] = $match; } } else { // No hit, try converting volume to/from Roman if (is_numeric($volume)) { $volume = strtolower(roman($volume)); } else { $volume = arabic($volume); } $keys = array($issn, $volume, $spage); if ($debug_openurl) { $openurl_result->debug->keys = $keys; } $url = $config['couchdb_options']['database'] . "/_design/openurl/_view/triple?key=" . urlencode(json_encode($keys)); //echo $url . '<br />'; if ($config['stale']) { $url .= '&stale=ok'; } $resp = $couch->send("GET", "/" . $url); $r = json_decode($resp); //print_r($r); if (count($r->rows) > 0) { foreach ($r->rows as $row) { $match = new stdclass(); $match->match = true; $match->triple = $keys; $match->id = $row->id; $openurl_result->results[] = $match; } } } } } } } /* // full text search if (count($openurl_result->results) == 0) { // Has user supplied an unparsed string? if (isset($context_object->referent->dat)) { find_citation($context_object->referent->dat, $openurl_result, 0.7); } else { find_citation(reference_to_citation_string($context_object->referent), $openurl_result, 0.7); } } */ // ok, if we have one or more results we return these and let user/agent decide what to do $num_results = count($openurl_result->results); if ($context_object->redirect) { $id = 0; if ($num_results == 1) { if ($openurl_result->results[0]->match) { // I'm feeling lucky $id = $openurl_result->results[0]->id; } } // Redirect to reference display, if not found then id is 0 and so we get default error message header('Location: reference/' . $id . "\n\n"); } else { // API call return, populated with details for ($i = 0; $i < $num_results; $i++) { $resp = $couch->send("GET", "/" . $config['couchdb_options']['database'] . "/" . urlencode($openurl_result->results[$i]->id)); $reference = json_decode($resp); if (!isset($reference->error)) { $openurl_result->results[$i]->reference = $reference; } } api_output($openurl_result, $callback); } }