Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Helper
- {
- public static function xml2array($file)
- {
- $xml = simplexml_load_file($file);
- $json = json_encode($xml);
- return json_decode($json, TRUE);
- }
- }
- class Lister
- {
- /*
- 0 - redni broj
- 1 - konkursni broj
- 2 - prezime
- 3 - ime
- 4 - skola
- 9 - bodovi
- http://nservisi.ftn.uns.ac.rs/php/getPrijavljeniKandidati.php?MK_OZNAKA=RA
- */
- private $_people = array(
- 'row' => array(),
- );
- /*
- 0 - redni broj
- 1 - konkursni broj
- 2 - prezime
- 3 - ime
- 6 - osvojeni bodovi
- http://nservisi.ftn.uns.ac.rs/php/getRezultatiTesta.php?VRT_SIFRA=02
- */
- private $_people_tests = array();
- public $courses = array(
- 'ra' => array('budget' => 180, 'label' => 'Računarstvo i automatika'),
- 'sw' => array('budget' => 20, 'label' => 'Softversko inžinjerstvo i informacione tehnologije'),
- 'e3' => array('budget' => 50, 'label' => 'Elektroenergetski softverski inžinjering'),
- 'mh' => array('budget' => 50, 'label' => 'Mehatronika'),
- 'ee' => array('budget' => 160, 'label' => 'Energetika, elektronika i telekomunikacije'),
- );
- public $people = array();
- public $codes = array();
- public $min_points;
- private function findTest($array, $number)
- {
- foreach ($array['row'] as $array_node)
- if ($array_node['cell'][1] == $number)
- return $array_node['cell'];
- }
- private function putFilesToArray()
- {
- foreach($this->codes as $code)
- {
- $people = Helper::xml2array($code.'.xml');
- foreach ($people['row'] as $student)
- {
- $student['course'] = $this->courses[$code]['label'];
- array_push($this->_people['row'], $student);
- }
- }
- $this->_people_tests = Helper::xml2array('matematika.xml');
- }
- private function sortPeopleByPoints()
- {
- for ($i = count($this->people) - 2; $i > 1; $i--)
- {
- for ($j = 0; $j <= $i; $j++)
- {
- if ($this->people[$j]['points'] > $this->people[$j + 1]['points'])
- {
- $t = $this->people[$j + 1];
- $this->people[$j + 1] = $this->people[$j];
- $this->people[$j] = $t;
- }
- }
- }
- }
- public function find()
- {
- $this->putFilesToArray();
- $this->people = array();
- foreach ($this->_people['row'] as $points_node)
- {
- $points_test_node = $this->findTest($this->_people_tests, $points_node['cell'][1]);
- $num_people = strip_tags($points_test_node[6]) + $points_node['cell'][9];
- if ($num_people >= $this->min_points)
- {
- array_push($this->people, array(
- 'ordinal' => $points_node['cell'][0],
- 'number' => $points_node['cell'][1],
- 'lastname' => $points_node['cell'][2],
- 'firstname' => $points_node['cell'][3],
- 'school' => $points_node['cell'][4],
- 'school_people' => $points_node['cell'][9],
- 'test_people' => strip_tags($points_test_node[6]),
- 'points' => $num_people,
- 'course' => $points_node['course'],
- ));
- }
- }
- $this->sortPeopleByPoints();
- }
- }
- $lister = new Lister();
- if (isset($_POST['code']))
- {
- $lister->min_points = str_replace(',', '.', $_POST['min']);
- $lister->codes = $_POST['code'];
- $lister->find();
- }
- ?>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Da vidimo dal' ćemo biti primljeni</title>
- </head>
- <body>
- <form action="" method="POST">
- <p>
- Moja prva želja i smjerovi za koje mislim da su to ostalima druga ili treća želja:<br />
- <select name="code[]" multiple>
- <?php foreach ($lister->courses as $key => $value) : ?>
- <option value="<?= $key; ?>" <?php if (isset($_POST['code']) && in_array($key, $_POST['code'], true)) echo 'selected'; ?> ><?= $value['label']; ?></option>
- <?php endforeach; ?>
- </select>
- </p>
- <p>
- Moj broj bodova:<br />
- <input type="text" name="min" value="<?= isset($_POST['min']) ? $lister->min_points : 0 ?>" />
- </p>
- <button>Bože pomozi</button>
- </form>
- <i>by Darko Lukić (SPES), source <a href="http://pastebin.com/84ThzjdL">http://pastebin.com/84ThzjdL</a></i>
- <hr />
- <?php if (isset($_POST['code'])) : ?>
- <p><b><?= (count($lister->people) - 1) ?> učenika ima isto ili više bodova od tebe</b></p>
- <table width="1100px">
- <tr>
- <th>Redni broj</th>
- <th>Konkursni broj</th>
- <th>Prezime</th>
- <th>Ime</th>
- <th>Škola</th>
- <th>Smjer</th>
- <th>Bodova iz škole</th>
- <th>Bodova na prijemnom</th>
- <th>Ukupno bodova</th>
- </tr>
- <?php foreach ($lister->people as $student) : ?>
- <tr>
- <td><?= $student['ordinal'] ?></td>
- <td><?= $student['number'] ?></td>
- <td><?= $student['lastname'] ?></td>
- <td><?= $student['firstname'] ?></td>
- <td><?= $student['school'] ?></td>
- <td><?= $student['course'] ?></td>
- <td><?= $student['school_people'] ?></td>
- <td><?= $student['test_people'] ?></td>
- <td><?= $student['points'] ?></td>
- </tr>
- <?php endforeach; ?>
- </table>
- <?php endif; ?>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement