<?php

/**
 *  Izracun manjkajocega dela sorazmerja
 */

// Dobi podatke

if ($_POST['a1'] != "" && $_POST['a2'] != "" && $_POST['b1'] != "" && $_POST['b2'] != "")
{
    
$a1 $_POST['a1'];
    
$a2 $_POST['a2'];
    
    
$b1 $_POST['b1'];
    
$b2 $_POST['b2'];
} else {
    
$text "Izpolnite polja!";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr" lang="sl-SI">
<head>
    <title>Sorazmerje</title>
    <style type="text/css">
    
    input[type="submit"] {
        margin-top: 10px;
    }
    
    input[type="text"] {
        margin-top: 10px;
        width: 35px;
        border: none;
        border: 1px solid black;
    }
    
    #main {
        padding: 10px;
        border: 1px solid black;
        width: 310px;
        margin-left: auto;
        margin-right: auto;    
        text-align: center;
    }
    
    #text {
        margin: 2px;
        font-size: 12px;
    }
    
    </style>
    <script type="text/javascript">
      <!--
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode == 88 || charCode == 120)
             return true;
             
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      //-->
   </script>

</head>

<body>
<div id="main">
<p id="text">Ta pripomo&#269;ek vam bo izra&#269;unal manjkajo&#269;i &#269;len sorazmerja.
Pri vpisu morajo biti vsa polja (razen neznani del) celo&scaron;tevil&#269;na in spremenljivka mora biti ozna&#269;ena z X.
</p>
<hr noshade="noshade" />
    <form action="" method="post">
        <em>Vpis sorazmerja:</em><br />
        <input type="text" name="a1" onkeypress="return isNumberKey(event)" value="<?php echo $a1?>" />
        :
        <input type="text" name="a2" onkeypress="return isNumberKey(event)" value="<?php echo $a2?>" />
        =
        <input type="text" name="b1" onkeypress="return isNumberKey(event)" value="<?php echo $b1?>" />
        :
        <input type="text" name="b2" onkeypress="return isNumberKey(event)" value="<?php echo $b2?>" />
        <br />
        <input type="submit" value="Izra&#269;unaj" />
        <br /><br />
    </form>
    <div id="rezultat">
    <?php
    
    
// Glavna funkcija
    
function dobi_x($a1$a2$b1$b2)
    {
        if (
$a1 == "X" || $a1 == "x")
        {
            
$x $a2 $b1 $b2;
                        
        } elseif (
$a2 == "X" || $a2 == "x")
        {
            
$x $a1 $b2 $b1;
            
        } elseif (
$b1 == "X" || $b1 == "x")
        {
            
$x $a1 $b2 $a2;
            
        } elseif (
$b2 == "X" || $b2 == "x")
        {
            
$x $b1 $a2 $a1;
            
        }
        
        return 
$x
    }
    
    if (isset(
$text))
    {
        echo 
$text;
        
    } else {
        
        echo 
"<hr noshade=\"noshade\" />X = ".dobi_x($a1$a2$b1$b2)."\n";
    }
    
?>
    </div>
</div>
</body>
</html>