avitoholix

OOP

Jul 16th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.11 KB | None | 0 0
  1. //Class cars
  2.  
  3. <?php
  4.  
  5. class Car{
  6.     private $mark;
  7.     private $model;
  8.     private $year;
  9.     private $engine;
  10.    
  11.     public function __construct($mk,$models,$years,$theengen) {
  12.         $this->mark=$mk;
  13.         $this->model=$models;
  14.         $this->year=$years;
  15.         $this->engine=$theengen;
  16.     }
  17.    
  18.     public function getMark(){
  19.         return $this->mark;
  20.     }
  21.    
  22.     public function getModel(){
  23.         return $this->model;
  24.     }
  25.    
  26.     public function getYear(){
  27.         return $this->year;
  28.     }
  29.    
  30.     public function getEngen(){
  31.         return $this->engine;
  32.     }
  33.    
  34.     public function printCars(){
  35.         echo "Your car is {$this->mark} model {$this->model} production yera "
  36.         . "{$this->year} with size on the engien {$this->engine}cc".'<br>';
  37.     }
  38. }
  39. if($hidden == 1){
  40.     $newcar = new Car($mark,$model,$year,$engine);
  41.     $newcar->printCars();
  42. }
  43. ?>
  44.  
  45.  
  46. //Form for cars___________________________________________________________________|
  47.  
  48.  
  49. <form action="formForCars.php" method="post">
  50.     <div>Input your's car...</div>
  51.     <input type="hidden" name="hidden" value="1">
  52.     Mark:<input type="text" name="mark">
  53.     Model:<input type="text" name="model">
  54.     Year:<input type="text" name="year">
  55.     Engine:<input type="text" name="engine">
  56.     <input type="submit" value="Submit">
  57. </form>
  58. <?php
  59. if(isset($_POST['mark'])
  60.         || isset($_POST['model'])
  61.         || isset($_POST['year'])
  62.         || isset($_POST['engine'])
  63.         || isset($_POST['hidden'])){
  64.    
  65.     $mark = trim($_POST['mark']);
  66.     $model = trim($_POST['model']);
  67.     $year = trim($_POST['year']);
  68.     $engine = trim($_POST['engine']);
  69.     $hidden = trim($_POST['hidden']);
  70.    
  71.    
  72.             if(strlen($mark)>=2 && strlen($mark)>=2 && strlen($mark)>=2 && strlen($mark)>=2 ){
  73.                 include 'cars.php';
  74.             }
  75.                 else {
  76.                      echo '<div style="color:red">'.'FAILURE!'.'</div>';
  77.             }
  78.         }
  79. ?>
  80. //User calss__________________________|
  81.  
  82. <?php
  83. class User{
  84.     protected $firstname;
  85.     protected $lastyname;
  86.     protected $age;
  87.     protected $profilpic;
  88.     protected $sex;
  89.     protected $password;
  90.     protected $squestion;
  91.     protected $sanswer;
  92.     protected $email;
  93.    
  94.     function __construct($firstname, $lastyname, $age, $profilpic, $sex, $password, $squestion, $sanswer, $email) {
  95.         $this->firstname = $firstname;
  96.         $this->lastyname = $lastyname;
  97.         $this->age       = $age;
  98.         $this->profilpic = $profilpic;
  99.         $this->sex       = $sex;
  100.         $this->password  = $password;
  101.         $this->squestion = $squestion;
  102.         $this->sanswer   = $sanswer;
  103.         $this->email     = $email;
  104.     }
  105.  
  106.     public function printForm(){
  107.         $printData = "Name:{$this->firstname}:LastName:{$this->lastyname}:"
  108.         . "Age:{$this->age}:Picture:{$this->profilpic}:Sex:{$this->sex}:"
  109.         . "Password:{$this->password}:Question:{$this->squestion}:"
  110.         . "Answer:{$this->sanswer}:Email:{$this->email}:";
  111.         file_put_contents('userdata.txt', $printData."\n",FILE_APPEND);
  112.     }
  113.  
  114. }
  115.  
  116. class Workman extends User{
  117.     protected $profession;
  118.     protected $payment;
  119.    
  120.     function __construct($profession, $payment) {
  121.         $this->profession = $profession;
  122.         $this->payment    = $payment;
  123.     }
  124.    
  125.     public function printForm(){
  126.         $printData = "Profession:{$this->profession}:"
  127.         . "Payment{$this->payment}:";
  128.         file_put_contents('userdata.txt', $printData."\n",FILE_APPEND);
  129.     }
  130. }
  131.  
  132.  
  133.  
  134. if($hidden==1){
  135.     $file=1;
  136.     $users=new User($firstname,$lastname,$age,$file,$sex,$pass,$question,$answer,$email);
  137.     $extend=new Workman($pro, $pay);
  138.     $users->printForm();
  139.     $extend->printForm();
  140. }
  141. ?>
  142.  
  143. //Form for user_________________________|
  144.  
  145.  
  146.  
  147. <form action="formForUser.php" method="post" accept-charset=""enctype="multipart/form-data">  
  148.     <input type="hidden" name="submitForm" value="1">
  149.     First name:<input type="text" name="firstname"></br>
  150.     Last name:<input type="text" name="lastname"></br>
  151.     Age:<input type="text" name="age"></br>
  152.     Password:<input type="password" name="pass"></br>
  153.     Security question:<input type="text" name="question"></br>
  154.     Security answer:<input type="text" name="answer"></br>
  155.     Email:<input type="email" name="email"></br>
  156.     sex:
  157.         male:<input type="radio" name="sex" value="male" class="male">
  158.         female:<input type="radio" name="sex" value="female" class="female"></br>
  159.     Picture:<input type="file" name="file" id="file"></br>
  160.     Profession:<input type="text" name="pro"></br>
  161.     Payment:<input type="text" name="pay"></br>
  162.     <input type="submit" value="Submit">
  163. </form>
  164. <?php
  165.  
  166. if(isset($_POST['firstname'])
  167.         || isset($_POST['lastname'])
  168.         || isset($_POST['age'])
  169.         || isset($_POST['pass'])
  170.         || isset($_POST['question'])
  171.         || isset($_POST['answer'])
  172.         || isset($_POST['email'])
  173.         || isset($_POST['submitForm'])
  174.         || isset($_POST['sex'])
  175.         || isset($_FILES["file"]["error"])
  176.         || isset($_POST['pro'])
  177.         || isset($_POST['pay'])){
  178.    
  179.     $firstname = trim($_POST['firstname']);
  180.     $lastname = trim($_POST['lastname']);
  181.     $age = trim($_POST['age']);
  182.     $pass = trim($_POST['pass']);
  183.     $question = trim($_POST['question']);
  184.     $answer = trim($_POST['answer']);
  185.     $email = trim($_POST['email']);
  186.     $sex = trim($_POST['sex']);
  187.     $hidden = trim($_POST['submitForm']);
  188.     $file = trim($_FILES["file"]["error"]);
  189.     $pro = trim($_POST['pro']);
  190.     $pay = trim($_POST['pay']);
  191.     include 'userClass.php';
  192.    
  193.             if ($_FILES["file"]["error"] > 0)
  194.         {
  195.             echo "Error: " . $_FILES["file"]["error"] . "<br>";
  196.         }
  197.         else {
  198.               echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  199.               echo "Type: " . $_FILES["file"]["type"] . "<br>";
  200.               echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  201.               echo "Stored in: " . $_FILES["file"]["tmp_name"];
  202.              
  203.               }
  204.  
  205. }
  206.  
  207. ?>
Advertisement
Add Comment
Please, Sign In to add comment