Hallo,
ich habe mir ein hangman modul besorgt, dass ich in PMX integrieren konnte, jedoch wird der Gewinner nicht eingetragen.
Nachdem das Spiel gewonnen wurde kommt eine Eingabemaske wie folgt:
Gratulation! Du hast das Wort erraten ...
xxxx Dein Name: EINGABEFELD FÜR NAME ok(zum absenden)
Nun möchte ich, dass das EINGABEFELD FÜR NAME den Namen aus dem Cookie von PMX nimmt und diesen selbst einträgt, sodass man diesen auch nicht mehr überschrieben kann, sondern lediglich auf OK klicken kann zum übermitteln.
Der Code sieht derzeit wie folgt aus:
<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>?name=Hangman&file=insbest">
<input type="hidden" name="wordid" value="<?=$_SESSION['gcid']; ?>" />
<input type="hidden" name="besttime" value="<?=$tempo; ?>" />
<input type="hidden" name="besttent" value="<?=$tentativi; ?>" />
<p><?=_INSRT; ?><input type="text" name="newbest" size="15" maxlength="15" />
<input type="submit" value="<?=_SBMT; ?>" name="go" /></p>
</form>
<?php
}
ich habe es nun schon mit mehreren variablen versucht. Das einzige was ich hinbekomme ist, dass anstatt OK in dem Button der Username steht, aber mehr auch nicht. Irgendwo hab ich da wohl eine denksperre oder sowas.
Ich hoffe mir kann jemand weiterhelfen. Danke schonmal im Voraus
Hallo, wenn mich nicht alles täuscht stehen in cms-cookies nie usernamen ;)
Ich hole mir den Usernamen so
Du kannst Ihn mit dem Formular versenden, oder erst in der zielPHP datei holen in dem du das Formular verarbeitest.
Mit $userinfo = mxGetUserData() bekommst du jedes Feld von $prefix_users welches du eben möchtest.
$userinfo = mxGetUserData();
$userDaten['uname'] = $userinfo['uname']; liefert den Username
oder
$userDaten['uid'] = $userinfo['uid']; liefert die Userid
usw
einfach die Eckigen Klammern so umbenennen wie das Feld $prefix_users heist das du abfragen möchtest.
$module_name = basename(dirname(__file__));
$userinfo = mxGetUserData();
$userDaten['uname'] = $userinfo['uname'];
echo "<form action=\"modules.php?name=".$module_name."\" method=\"post\" name=\"username_uebergeben\">\n";
echo " <input name=\"username\" type=\"checkbox\" id=\"richtigkeit\" value=\"".$userDaten['uname']."\" />\n";
echo "</form>\n";
Gruß
Thorsten
Hallo Lausbub,
danke für die schnelle Hilfe, doch leider bekomm ich das eben genau so nicht hin. Dies hatte ich versucht, aber ich dachte das ich einfach nur den falschen code genommen habe.
Nun habe ich mir den von Dir kopiert und festgestellt, dass ich den bereits verwendet hatte. Es klappt einfach nicht. Das muss ein blöder denkfehler von mir sein denn soweit ich mich an php erinnere muss es so gehen, da ich in anderen Modulen auch den uname so ausgelesen habe.
Kannst Du mir vielleicht hier nochmal einen tip geben oder schaun wo da was falsch sein könnte? Ich poste das gesamte script mal kurz hier rein. Ich denke langsam, dass das gesamte script nicht so wirklich korrekt ist.
<?php
function mxShowUserinfo($uname)
{
global $prefix, $user_prefix, $bgcolor1, $bgcolor2, $bgcolor3;
require_once("modules/Your_Account/config.php");
require_once(PMX_SYSTEM_DIR . '/mx_userfunctions.php');
$uinfo = mxGetUserDataFromUsername($uname);
// mxDebugFuncVars($uinfo);
if (empty($uinfo['uname'])) {
mxErrorScreen("<b>" . _NOINFOFOR . " " . $uname . "</b>", _PERSONALINFO);
return;
}
include_once("modules/Userinfo/view.php");
viewuserinfo($uinfo);
}
// ##################################################
$showsol = false; //set it to true if you want to show the word after someone hangs himself
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- $module_name";
// functions and variables
$alfabeto = array ('A' => 'a','B' => 'b','C' => 'c','D' => 'd','E' => 'e',
'F' => 'f','G' => 'g','H' => 'h','I' => 'i','J' => 'j','K' => 'k','L' => 'l',
'M' => 'm','N' => 'n','O' => 'o','P' => 'p','Q' => 'q','R' => 'r','S' => 's',
'T' => 't','U' => 'u','V' => 'v','W' => 'w','X' => 'x','Y' => 'y','Z' => 'z');
session_start ();
// choose a random word from the database
function ScegliParola () {
global $prefix, $dbi;
$result = sql_query("select max(id) from ".$prefix."_hangman", $dbi);
$numero_parole = sql_fetch_row($result, $dbi);
$posizione_parola = rand (1, $numero_parole[0]);
$result = sql_query("select id, word from ".$prefix.'_hangman where id = '.$posizione_parola, $dbi);
$parola = sql_fetch_row($result, $dbi);
return ($parola);
}
// check if the player can be added to the top list
function ControllaRecord ($wordid, $tempo, $tentativi) {
global $prefix, $dbi;
$chk = array(false);
$result = sql_query("select * from ".$prefix."_hangman where id = ".$wordid, $dbi);
$riga = sql_fetch_row($result, $dbi);
if ($tentativi<$riga[3] or ($tentativi==$riga[3] and $tempo<$riga[4]))
$chk[0] = true;
if ($riga[3]==6) $riga[2]='*nuovo**';
$chk[1] = $riga[2];
$chk[2] = $riga[3];
$chk[3] = $riga[4];
return $chk;
}
// read the actual best score
function CercaRecord ($wordid) {
global $prefix, $dbi;
$result = sql_query("select best, errors, time from ".$prefix."_hangman where id = ".$wordid, $dbi);
$riga = sql_fetch_row($result, $dbi);
return $riga;
}
// changes all the unguessed letters with _
function CalcolaIndovinata ($parola, $escludi, $alfabeto) {
$alfabeto = array_flip ($alfabeto);
$escluse = strtr ($escludi, $alfabeto);
$escluse = '['.$escluse.']';
$escluse = ereg_replace ($escluse, '', '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]');
$indovinata = ereg_replace ($escluse, '_', $parola);
return $indovinata;
}
// seeks the chosen letter in the word
function TrovaLettera ($lettera, $parola, $scelte, $alfabeto) {
$alfabeto = array_flip ($alfabeto);
$lettera = substr ($lettera, 0, 1);
$lettera = strtr ($lettera, $alfabeto);
$scelte.= $lettera;
if (ereg ($lettera, $parola)) {
$controllo = true;
}
else {
$controllo = false;
}
$risposta = array ($scelte, $controllo);
return $risposta;
}
// and this is the programme!
include("header.php");
OpenTable();
?>
<p style="font-family:Arial, Helvetica,sans-serif;font-size:28px;font-weight:bold;color:black">
Hangman
</p>
<?php
// the word to be guessed has already been chosen
if (isset($_GET['letter']) and isset($_SESSION['gchangman'])) {
$variab = explode ('/', $_SESSION['gchangman']);
$indovina = $variab[0];
$scelte = $variab[1];
$tentativi = $variab[2];
$checklet = TrovaLettera ($_GET['letter'], $indovina, $scelte, $alfabeto);
$scelte = $checklet[0];
if (!$checklet[1]) {
$tentativi = $tentativi +1;
}
$indovinata = CalcolaIndovinata ($indovina, $scelte, $alfabeto);
}
else {
// reset everything and choose a new word
$tentativi=0;
$scelte = ('_');
$parola = ScegliParola ();
$indovina = $parola[1];
$_SESSION['gcid'] = $parola[0];
$indovinata = CalcolaIndovinata ($indovina, $scelte, $alfabeto);
$_SESSION['gctempo'] = time();
}
// set the cookie (or the get variable) via PHP sessions
$_SESSION['gchangman'] = ($indovina.'/'.$scelte.'/'.$tentativi);
if ($tentativi>6) $tentativi=6;
// print the word hiding the unfound letters
print ('<p><img src="modules/Hangman/images/hang_'.($tentativi+1).'.gif" style="border:0;width:100px;height:100px" alt="Miss '.$tentativi.'/6" /></p>');
echo ("\n<p>\n");
$caratteri = preg_split('//', $indovinata, -1, PREG_SPLIT_NO_EMPTY);
foreach ($caratteri as $lettalf) {
$lettalf = strtr ($lettalf, $alfabeto);
if ($lettalf==' ') {
print (' <img src="modules/Hangman/images/lb_~.gif" style="border:0;width:20px;height:20px" alt="" />');
}
else {
print (' <img src="modules/Hangman/images/lb_'.$lettalf.'.gif" style="border:0;width:20px;height:20px" alt="'.$lettalf.'" />');
}
echo ("\n");
print (' <img src="modules/Hangman/images/lb_~.gif" style="border:0;width:20px;height:20px" alt="" />');
echo ("\n");
}
print ('</p>');
// last part
if ($indovina!=$indovinata) {
if ($tentativi>=6) {
// ahi! hanged!
print ('<p>'._HANGED);
if ($showsol) print(' '._WORDWAS.' '.$indovina);
$bestnow = CercaRecord ($_SESSION['gcid']);
if ($bestnow[1]==6)
print ('<br />'._GCHNONE.'</p>');
else {
if ($bestnow[0]=='') $bestnow[0]=_ANON;
print ('<br />'.$bestnow[0].' '._GUESSEDIT.' '.$bestnow[2].' '._GCHSEC.' '.$bestnow[1].' '._CHANCES.'.</p>');
}
}
else {
// shows the full alphabet from which the letters can be chosen
$scelt = preg_split('//', $scelte, -1, PREG_SPLIT_NO_EMPTY);
echo ("\n<p>\n");
foreach ($alfabeto as $lettalf) {
$contrl = false;
foreach ($scelt as $lett) {
if (!strcasecmp ($lettalf, $lett)) {
$contrl = true;
}
}
if ($contrl) {
print (' <img src="modules/Hangman/images/lr_'.$lettalf.'.gif" style="border:0;width:20px;height:20px" alt="'.$lettalf.'" />');
}
else {
print (' <a href="'.$_SERVER['PHP_SELF'].'?name=Hangman&letter='.$lettalf.'"><img src="modules/Hangman/images/lb_'.$lettalf.'.gif" style="border:0;width:20px;height:20px" alt="'.$lettalf.'" /></a>');
}
if ($lettalf=='m') echo ("\n <br />");
echo ("\n");
}
echo ("</p>\n");
}
}
else {
// the word has been guessed!
echo ("\n<p>\n");
print (_CONGRAT);
$tempo = time() - $_SESSION['gctempo'];
$oldbest = ControllaRecord ($_SESSION['gcid'], $tempo, $tentativi);
if ($oldbest[1]=='') $oldbest[1]=_ANON2;
if ($oldbest[0]) {
// and there's a new record
print ('<br />'._GUESST);
if ($oldbest[1]!='*nuovo**') print (' '._BEAT.' '.$oldbest[1]);
$result = sql_query("update ".$prefix."_hangman set errors = "
.$tentativi.", time = ".$tempo.
" where id = ".$_SESSION['gcid'], $dbi);
// here is the form to insert own name
?>
</p>
<?php /*
<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>?name=Hangman&file=insbest">
<input type="hidden" name="wordid" value="<?=$_SESSION['gcid']; ?>" />
<input type="hidden" name="besttime" value="<?=$tempo; ?>" />
<input type="hidden" name="besttent" value="<?=$tentativi; ?>" />
*/
$module_name = basename(dirname(__file__));
$userinfo = mxGetUserData();
$userDaten['uname'] = $userinfo['uname'];
echo "<form action=\"modules.php?name=".$module_name."\" method=\"post\" name=\"_SBMT\">\n";
echo " <input name=\"username\" type=\"checkbox\" id=\"richtigkeit\" value=\"".$userDaten['uname']."\" />\n";
echo "</form>\n";
?>
<p><?=_INSRT; ?><input type="$uname" name="newbest" size="15" maxlength="15" />
<input type="submit" value="<?=_SBMT; ?>" name="go" /></p>
</form>
<?php
}
// word guessed, but someone did better
else print('<br />'._SOMEBUT.' '.$oldbest[1].' '._GUESSEDIT.' '.$oldbest[3].' '._GCHSEC.' '.$oldbest[2].' '._CHANCES.'.</p>');
}
print ('<p><a href="'.$_SERVER['PHP_SELF'].'?name=Hangman">'._NWGAME.'</a></p>');
CloseTable();
include("footer.php");
?>
Übrigends, eine Fehlermeldung kommt nicht, so wie es nun hier steht kommt halt nur die chackbox dazu und der rest ist geblieben wie es oben gepostet wurde von mir.
Zudem...es haben ja bereits einige nach Hangman gefragt, vielleicht können sie damit ja auch noch was anfangen. Der code um den es meiner Meinung nach geht ist ziemlich weit unten...
Sorry da muß ich passen so gut bin ich auch nicht.
Dachte aber dein Submit muss innerhalb des Formtag liegen oder?
Ich steig da nicht so ganz durch, einmal html und dann PHP ausgabe. Bleib doch einfach be PHP dann wäre es auf jedenfall Übersichtlicher.
Wenn ich es mir umbasteln könnte, würde ich das sogar machen, aber meine PHP Kenntnisse sind so lange her, dass ich froh bin die ganzen Module wenigstens für mich anpassen zu können, aber eins dann auch noch umbauen, da traue ich mich im moment nicht mehr dran.
Wie dem auch sei, ich habe es zumindest soweit, dass mir der Benutzername ausgelesen wird, nur leider fehlt mir dann das absenden oder es steht drunter immer noch Dein name ...feld... OK ... ich werd die nacht mal weiter basteln da hab ich noch ein wenig Zeit. Wenn ichs raus finde, dann poste ich es hier fals es jemand brauchen kann, wenn nicht hoffe ich immer noch auf Hilfe *freu*
Danke Dir aber trotzdem schonmal für den versuch.
:)
Ich habe das Modul auch, leider bisher auch vergeblich rumgetestet :red:
Aber vll hat ja inzwischen jemand eine Lösung parat und nur vergessen hier zu posten?
Liebe Grüße
trulla