All pastes #551088 Raw Edit

vodo

public text v1 · immutable
·published 2007-06-08 17:24 UTC
rendered paste body
<?php

require('inc/Predefined.php');
require('inc/Mysql.php');
require('inc/SaveInputFile.php');
require('parts/u_start.php');
require('parts/u_menu.php');

// save form data

if ($_POST['submit'] == 'save')
{

    $sql = '';

    // delete image
    if ($_POST['del_img'])
    {
        // delete if exists
        $file = UPLOAD_DIR .'roster_'. intval($_POST['user_id']) .'.'. @mysql_result(
                        $sdb->get_query("SELECT img_type FROM s_roster
                        WHERE user_id=". intval($userdata['user_id'])),0);
        if (file_exists($file))
        {
            @unlink($file);
        }
        $sql = "img_type=NULL,";

    }
    else
    {
        // we need this because img_type in database would be erased
        // due to we use replace and not update
        $sql = "img_type='".
                @mysql_result($sdb->get_query("SELECT img_type FROM s_roster WHERE user_id=". intval($userdata['user_id'])), 0)
                ."',";
    }



    $birth_date = $_POST['birth_y'] .'-'. $_POST['birth_m'] .'-'. $_POST['birth_d'];

    if (!preg_match('/(19|20)\d\d-\d\d-\d\d/', $birth_date) || !checkdate(intval($_POST['birth_m']), intval($_POST['birth_d']), intval($_POST['birth_y'])))
    {
        $birth_date = '0000-00-00';
        ?><div id="error">Wrong birth date.</div><?php
    }


    // zapis do bazy
    $sql = "UPDATE s_roster SET



           nickname=" . $sdb->quote_smart($_POST['nickname']) .",

           {$sql}

           name=" . $sdb->quote_smart($_POST['name']) .",

           origin=" . intval($_POST['origin']) .",

           location=" . $sdb->quote_smart($_POST['location']) .",

           birth_date='" . $birth_date ."',

           sex='" . ( ($_POST['sex'] == 'male') ? 'm' : 'f' ) ."',

           website=" . $sdb->quote_smart($_POST['website']) .",

               email=" . $sdb->quote_smart($_POST['email']) .",

               msn=" . $sdb->quote_smart($_POST['msn']) .",

               mouse=" . $sdb->quote_smart($_POST['mouse']) .",

           storage=" . $sdb->quote_smart($_POST['storage']) .",

           headphones=" . $sdb->quote_smart($_POST['headphones']) .",

           monitor=" . $sdb->quote_smart($_POST['monitor']) .",

           cpu=" . $sdb->quote_smart($_POST['cpu']) .",

           memory=" . $sdb->quote_smart($_POST['memory']) .",

           graphic_card=" . $sdb->quote_smart($_POST['graphic_card']) .",

           soundcard=" . $sdb->quote_smart($_POST['soundcard']) .",

           motherboard=" . $sdb->quote_smart($_POST['motherboard']) .",

               connection=" . $sdb->quote_smart($_POST['connection']) .",

               about=" . $sdb->quote_smart($_POST['about'])." WHERE user_id=". 
               intval($userdata['user_id']);

   $sdb->get_query($sql);


    // jesli jest obrazek - zapisz go
    if ($_FILES['image']['error'] != 4)
    {
        $status = $sf->saveImg('image', UPLOAD_DIR .'roster_'. intval($userdata['user_id']), ROSTER_IMG_WIDTH, ROSTER_IMG_HEIGHT, 3);
        // zapis udany
        if ($status[0])
        {
            $sql = "UPDATE s_roster SET img_type=". $sdb->quote_smart($status[1]) ."
                    WHERE user_id=". intval($userdata['user_id']) ."
                    LIMIT 1";
	    $sdb->get_query($sql);
        }
        else
        {
            ?><div id="error"><?php echo $status[1] ?></div><?php
        }
    }

}



 /*************************************
  * cofigs start
  *************************************/


    // delete configs
    if ($_POST['del_cfg'])
    {
        foreach (array_values($_POST['del_cfg']) as $gameID)
        {
             // delete if exists
             $file = UPLOAD_DIR .'game_cfg_'. intval($userdata['user_id'])  .'_'. intval($gameID) .'.'.
             @mysql_result(
                             $sdb->get_query("SELECT file_ext FROM s_game_cfg
                             WHERE user_id=". intval($userdata['user_id']) ."
                             AND gameID=". intval($gameID) )
                        ,0);
             if (file_exists($file))
             {
                 @unlink($file);
             }
             $sql = "DELETE FROM s_game_cfg
                     WHERE user_id=". intval($userdata['user_id']) ."
                     AND gameID=". intval($gameID) ."
                     LIMIT 1";
             $sdb->get_query($sql);
        }
    }



    // save configs
    if (is_array($_POST['configs']))
    {
	    foreach ($_POST['configs'] as $key )
	    {
	        // jesli jest obrazek - zapisz go
	        if ($_FILES['config_'.$key]['error'] != 4)
	        {
	            $status = $sf->writeFile('config_'.intval($key), UPLOAD_DIR .'game_cfg_'. intval($userdata['user_id'])  .'_'. intval($key), array('cfg','config','txt','zip','rar','gz','bz2'));
	            // zapis udany
	            if ($status[0])
	            {
	                $sql = "REPLACE s_game_cfg SET
	                        filename=". $sdb->quote_smart($_FILES['config_'.$key]['name']) .",
	                        file_ext=". $sdb->quote_smart($status[1]) .",
	                        user_id=". intval($userdata['user_id']) .",
	                        gameID=". intval($key);
	                $sdb->get_query($sql);
		        }
	            else
	            {
	                ?><div id="error"><?php echo $status[1] ?></div><?php
	            }
	        }


	    }
    }


 /*************************************
  * configs end
  *************************************/







// find all roster
$sql = "SELECT * FROM s_roster
	    WHERE user_id=". intval($userdata['user_id']);
$res = $sdb->get_query($sql);


if (mysql_num_rows($res))
{
    $row = mysql_fetch_assoc($res);
}
else
{
    $row = array();
}



if ($_POST)
{
    $row = $_POST;
    $row['birth_date'] = $_POST['birth_y'] .'-'. $_POST['birth_m'] .'-'. $_POST['birth_d'];
}




?>
<div class="form_body">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="user_id" value="<?php echo $userdata['user_id'] ?>">
<div class="form_cell">

<label for="nickname">Nickname</label>
<input type="text" class="text" name="nickname" id="nickname" value="<?php echo htmlspecialchars($row['nickname']) ?>"><br>
</div>
<div class="form_cell">

<label for="name">Name</label>
<input type="text" class="text" name="name" id="name" value="<?php echo htmlspecialchars($row['name']) ?>"><br>
</div>
<div class="form_cell">

<label for="origin">Origin</label>
<select class="select" name="origin" id="origin">
<?php
$sql2 = "SELECT * FROM s_countries ORDER BY country";
$res2 = $sdb->get_query($sql2);

while ($row2 = mysql_fetch_assoc($res2))
{
    ?><option value="<?php echo $row2['countryID'].'"'; if ($row2['countryID'] == $row['origin']) echo ' selected'; ?>><?php echo $row2['country'] ?></option><?php
}

?>
</select><br>
</div>
<div class="form_cell">

<label for="location">Location</label>
<input type="text" class="text" name="location" id="location" value="<?php echo htmlspecialchars($row['location']) ?>"><br>
</div>
<div class="form_cell">

<label for="birth_d">Birth day</label>
<select class="select" name="birth_d" id="birth_d">
<option value="00"<?php if (!preg_match('/\d\d/',substr($row['birth_date'],8,2))) echo ' selected' ?>>--</option>
<?php
for ($i = 1; $i<32; $i++)
{
    ?><option value="<?php echo sprintf("%'02d",$i) ?>"<?php if (substr($row['birth_date'],8,2) == $i) echo ' selected' ?>><?php echo $i ?></option><?php
}
?>
</select>
</div>


<div class="form_cell">

<label for="birth_m">Birth month</label>
<select class="select" name="birth_m" id="birth_m">
<option value="00"<?php if (!preg_match('/\d\d/',substr($row['birth_date'],5,2))) echo ' selected' ?>>--</option>
<?php
$month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'Novemeber', 'December');
for ($i = 1; $i<13; $i++)
{
    ?><option value="<?php echo sprintf("%'02d",$i) ?>"<?php if (substr($row['birth_date'],5,2) == $i) echo ' selected' ?>><?php echo $month[$i-1] ?></option><?php
}
?>
</select>
</div>


<div class="form_cell">

<label for="birth_y">Birth year</label>
<select class="select" name="birth_y" id="birth_y">
<option value="0000"<?php if (!preg_match('/19\d\d/',substr($row['birth_date'],0,4))) echo ' selected' ?>>--</option>
<?php
for ($i = 2005; $i>=1950; $i--)
{
    ?><option value="<?php echo $i ?>"<?php if (substr($row['birth_date'],0,4) == $i) echo ' selected' ?>><?php echo $i ?></option><?php
}
?>
</select>
</div>

<div class="form_cell">

<label  for="sex">sex</label>
<select class="select" name="sex" id="sex">
<option <?php if ($row['sex'] == 'f') echo ' selected' ?>>female</option>
<option <?php if ($row['sex'] == 'm') echo ' selected' ?>>male</option>
</select>
<br>
</div>
<div class="form_cell">

<label for="website">Website</label>
<input type="text" class="text" name="website" id="website" value="<?php echo htmlspecialchars($row['website']) ?>"><br>
</div>
<div class="form_cell">

<label for="email">Email</label>
<input type="text" class="text" name="email" id="email" value="<?php echo htmlspecialchars($row['email']) ?>"><br>
</div>
<div class="form_cell">

<label for="msn">MSN</label>
<input type="text" class="text" name="msn" id="msn" value="<?php echo htmlspecialchars($row['msn']) ?>"><br>
</div>
<div class="form_cell">

<label for="mouse">Mouse</label>
<input type="text" class="text" name="mouse" id="mouse" value="<?php echo htmlspecialchars($row['mouse']) ?>"><br>
</div>
<div class="form_cell">

<label for="storage">Storage</label>
<input type="text" class="text" name="storage" id="storage" value="<?php echo htmlspecialchars($row['storage']) ?>"><br>
</div>
<div class="form_cell">

<label for="headphones">Headphones</label>
<input type="text" class="text" name="headphones" id="headphones" value="<?php echo htmlspecialchars($row['headphones']) ?>"><br>
</div>
<div class="form_cell">

<label for="monitor">Monitor</label>
<input type="text" class="text" name="monitor" id="monitor" value="<?php echo htmlspecialchars($row['monitor']) ?>"><br>
</div>
<div class="form_cell">

<label for="cpu">CPU</label>
<input type="text" class="text" name="cpu" id="cpu" value="<?php echo htmlspecialchars($row['cpu']) ?>"><br>
</div>
<div class="form_cell">

<label for="memory">Memory</label>
<input type="text" class="text" name="memory" id="memory" value="<?php echo htmlspecialchars($row['memory']) ?>"><br>
</div>
<div class="form_cell">

<label for="graphic_card">Graphis card</label>
<input type="text" class="text" name="graphic_card" id="graphis_card" value="<?php echo htmlspecialchars($row['graphic_card']) ?>"><br>
</div>
<div class="form_cell">

<label for="soundcard">Soundcard</label>
<input type="text" class="text" name="soundcard" id="soundcard" value="<?php echo htmlspecialchars($row['soundcard']) ?>"><br>
</div>
<div class="form_cell">

<label for="motherboard">Motherboard</label>
<input type="text" class="text" name="motherboard" id="motherboard" value="<?php echo htmlspecialchars($row['motherboard']) ?>"><br>
</div>
<div class="form_cell">

<label for="connection">Connection</label>
<input type="text" class="text" name="connection" id="connection" value="<?php echo htmlspecialchars($row['connection']) ?>"><br>
</div>
<div class="form_cell">

<label for="about">About</label>
<textarea class="textarea" name="about" id="about" class="txt"><?php echo htmlspecialchars($row['about']) ?></textarea><br>
</div>
<?php
$file = UPLOAD_DIR .'roster_'. intval($row['user_id']) .'.'. @mysql_result(
$sdb->get_query("SELECT img_type FROM s_roster
                WHERE user_id=". intval($userdata['user_id'])),0);
if (file_exists($file))
{
    ?>
        <div class="form_cell">

        <label for="del_img">Delete the image</label><input type="checkbox" name="del_img" id="del_img" value="1">

        <img src="<?php echo $file ?>" alt="">
        </div>

    <?php
}
?>

<div class="form_cell">

<label for="image">Image</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_UPLOAD_FILE_SIZE ?>">
<input type="file" name="image" id="image"><br>
</div>
<?php


$sql = "SELECT sga.* FROM s_teams ste
        INNER JOIN s_games sga USING(gameID)
        WHERE ste.user_id = ". intval($row['user_id']);
$res = $sdb->get_query($sql);


// configs delete-show/upload
while ($row = mysql_fetch_assoc($res))
{

    $file = UPLOAD_DIR .'game_cfg_'.intval($userdata['user_id'])  .'_'.intval($row['gameID']) .'.'. @mysql_result(
    $sdb->get_query("SELECT file_ext FROM s_game_cfg
                     WHERE user_id=". intval($userdata['user_id']) ."
                     AND gameID=". intval($row['gameID'])),0);
    if (file_exists($file))
    {
        ?>
        <div class="form_cell">
        <label for="del_cfg_<?php echo intval($row['gameID']) ?>">Delete <?php echo htmlspecialchars($row['short_name']) ?> config</label><input type="checkbox" name="del_cfg[]" id="del_cfg_<?php echo intval($row['gameID']) ?>" value="<?php echo intval($row['gameID']) ?>">
        <?php echo htmlspecialchars($row['filename']) ?>
        </div>
        <?php
    }


    ?>
     <div class="form_cell">
     <label for="config_<?php echo intval($row['gameID']) ?>">Config - <?php echo htmlspecialchars($row['short_name']) ?></label>
     <input type="file" name="config_<?php echo intval($row['gameID']) ?>" id="config_<?php echo intval($row['gameID']) ?>"><br>
     <input type="hidden" name="configs[]" value="<?php echo intval($row['gameID']) ?>">
     </div>

    <?php
}
?>
<div class="sub">
<input type="hidden" name="submit" value="save">
<input type="submit" class="black_box" value="save">
</div>
</form>
</div>
<?php

require('parts/end.php');

?>