Advertisement
lukicdarkoo

Da vidimo dal' ćemo biti primljeni

Jul 3rd, 2013
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.88 KB | None | 0 0
  1. <?php
  2. class Helper
  3. {
  4.     public static function xml2array($file)
  5.     {
  6.         $xml = simplexml_load_file($file);
  7.         $json = json_encode($xml);
  8.         return json_decode($json, TRUE);
  9.     }
  10. }
  11.  
  12.  
  13. class Lister
  14. {
  15.     /*
  16.     0 - redni broj
  17.     1 - konkursni broj
  18.     2 - prezime
  19.     3 - ime
  20.     4 - skola
  21.     9 - bodovi
  22.    
  23.     http://nservisi.ftn.uns.ac.rs/php/getPrijavljeniKandidati.php?MK_OZNAKA=RA
  24.     */
  25.     private $_people = array(
  26.         'row' => array(),
  27.     );
  28.    
  29.    
  30.     /*
  31.     0 - redni broj
  32.     1 - konkursni broj
  33.     2 - prezime
  34.     3 - ime
  35.     6 - osvojeni bodovi
  36.    
  37.     http://nservisi.ftn.uns.ac.rs/php/getRezultatiTesta.php?VRT_SIFRA=02
  38.     */
  39.     private $_people_tests = array();
  40.    
  41.     public $courses = array(
  42.         'ra' => array('budget' => 180, 'label' => 'Računarstvo i automatika'),
  43.         'sw' => array('budget' => 20, 'label' => 'Softversko inžinjerstvo i informacione tehnologije'),
  44.         'e3' => array('budget' => 50, 'label' => 'Elektroenergetski softverski inžinjering'),
  45.         'mh' => array('budget' => 50, 'label' => 'Mehatronika'),
  46.         'ee' => array('budget' => 160, 'label' => 'Energetika, elektronika i telekomunikacije'),
  47.     );
  48.    
  49.     public $people = array();
  50.     public $codes = array();
  51.     public $min_points;
  52.  
  53.    
  54.     private function findTest($array, $number)
  55.     {
  56.         foreach ($array['row'] as $array_node)
  57.             if ($array_node['cell'][1] == $number)
  58.                 return $array_node['cell'];
  59.     }
  60.  
  61.     private function putFilesToArray()
  62.     {
  63.         foreach($this->codes as $code)
  64.         {
  65.             $people = Helper::xml2array($code.'.xml');
  66.            
  67.             foreach ($people['row'] as $student)
  68.             {
  69.                 $student['course'] = $this->courses[$code]['label'];
  70.                 array_push($this->_people['row'], $student);
  71.             }
  72.         }
  73.        
  74.         $this->_people_tests = Helper::xml2array('matematika.xml');
  75.     }
  76.    
  77.     private function sortPeopleByPoints()
  78.     {
  79.         for ($i = count($this->people) - 2; $i > 1; $i--)
  80.         {
  81.             for ($j = 0; $j <= $i; $j++)
  82.             {
  83.                 if ($this->people[$j]['points'] > $this->people[$j + 1]['points'])
  84.                 {
  85.                     $t = $this->people[$j + 1];
  86.                     $this->people[$j + 1] = $this->people[$j];
  87.                     $this->people[$j] = $t;
  88.                 }
  89.             }
  90.         }
  91.     }
  92.    
  93.     public function find()
  94.     {
  95.         $this->putFilesToArray();
  96.    
  97.         $this->people = array();
  98.         foreach ($this->_people['row'] as $points_node)
  99.         {
  100.             $points_test_node = $this->findTest($this->_people_tests, $points_node['cell'][1]);
  101.             $num_people = strip_tags($points_test_node[6]) + $points_node['cell'][9];
  102.            
  103.             if ($num_people >= $this->min_points)
  104.             {  
  105.                 array_push($this->people, array(
  106.                     'ordinal' => $points_node['cell'][0],
  107.                     'number' => $points_node['cell'][1],
  108.                     'lastname' => $points_node['cell'][2],
  109.                     'firstname' => $points_node['cell'][3],
  110.                     'school' => $points_node['cell'][4],
  111.                     'school_people' => $points_node['cell'][9],
  112.                     'test_people' => strip_tags($points_test_node[6]),
  113.                     'points' => $num_people,
  114.                     'course' => $points_node['course'],
  115.                 ));
  116.             }
  117.         }
  118.        
  119.         $this->sortPeopleByPoints();
  120.     }
  121. }
  122.  
  123.  
  124. $lister = new Lister();
  125.  
  126. if (isset($_POST['code']))
  127. {
  128.     $lister->min_points = str_replace(',', '.', $_POST['min']);
  129.     $lister->codes = $_POST['code'];
  130.     $lister->find();
  131. }
  132. ?>
  133.  
  134.  
  135. <head>
  136.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  137.     <title>Da vidimo dal' ćemo biti primljeni</title>
  138. </head>
  139.  
  140. <body>
  141.     <form action="" method="POST"> 
  142.         <p>
  143.             Moja prva želja i smjerovi za koje mislim da su to ostalima druga ili treća želja:<br />
  144.             <select name="code[]" multiple>
  145.                 <?php foreach ($lister->courses as $key => $value) : ?>
  146.                     <option value="<?= $key; ?>" <?php if (isset($_POST['code']) && in_array($key, $_POST['code'], true)) echo 'selected'; ?> ><?= $value['label']; ?></option>
  147.                 <?php endforeach; ?>
  148.             </select>
  149.         </p>
  150.        
  151.         <p>
  152.             Moj broj bodova:<br />
  153.             <input type="text" name="min" value="<?= isset($_POST['min']) ? $lister->min_points : 0 ?>" />
  154.         </p>
  155.        
  156.         <button>Bože pomozi</button>
  157.     </form>
  158.    
  159.     <i>by Darko Lukić (SPES), source <a href="http://pastebin.com/84ThzjdL">http://pastebin.com/84ThzjdL</a></i>
  160.    
  161.     <hr />
  162.    
  163.     <?php if (isset($_POST['code'])) : ?>
  164.         <p><b><?= (count($lister->people) - 1) ?> učenika ima isto ili više bodova od tebe</b></p>
  165.    
  166.         <table width="1100px">
  167.             <tr>
  168.                 <th>Redni broj</th>
  169.                 <th>Konkursni broj</th>
  170.                 <th>Prezime</th>
  171.                 <th>Ime</th>
  172.                 <th>Škola</th>
  173.                 <th>Smjer</th>
  174.                 <th>Bodova iz škole</th>
  175.                 <th>Bodova na prijemnom</th>
  176.                 <th>Ukupno bodova</th>
  177.             </tr>
  178.        
  179.             <?php foreach ($lister->people as $student) : ?>
  180.                 <tr>
  181.                     <td><?= $student['ordinal'] ?></td>
  182.                     <td><?= $student['number'] ?></td>
  183.                     <td><?= $student['lastname'] ?></td>
  184.                     <td><?= $student['firstname'] ?></td>
  185.                     <td><?= $student['school'] ?></td>
  186.                     <td><?= $student['course'] ?></td>
  187.                     <td><?= $student['school_people'] ?></td>
  188.                     <td><?= $student['test_people'] ?></td>
  189.                     <td><?= $student['points'] ?></td>
  190.                 </tr>
  191.             <?php endforeach; ?>
  192.         </table>
  193.     <?php endif; ?>
  194. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement