1: <?php
2: 3: 4: 5:
6: use Nette\Forms\Form,
7: Nette\Diagnostics\Debugger;
8: 9: 10: 11: 12: 13:
14: abstract class BasePresenter extends Nette\Application\UI\Presenter
15: {
16:
17: 18: 19: 20:
21: protected function startup(){
22: parent::startup();
23:
24: setlocale(LC_ALL,'cs_CZ.utf8');
25:
26: if (!$this->user->isLoggedIn()) {
27: $this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
28: }
29: }
30:
31: 32: 33: 34: 35:
36: public function handleAddNavsteva($id = null) {
37: if ($this->presenter->isAjax()) {
38: $this->template->showNavstevaForm = true;
39: if (!is_null($id)) {
40: $form = $this['navstevaForm'];
41:
42: $pacient = $this->getService('model')->getPacient($id);
43: if (!$pacient) $this->error('Pacient nenalezen');
44:
45: $form['pacient_name']->setDefaultValue($pacient->prijmeni.' '.$pacient->jmeno);
46: $form['pacient_id']->setDefaultValue($pacient->id);
47: }
48:
49: $this->invalidateControl('navstevaForm');
50: }
51: }
52: 53: 54: 55: 56:
57: public function handleEditNavsteva($id) {
58: if ($this->presenter->isAjax()) {
59: $this->template->showNavstevaForm = true;
60: $form = $this['navstevaForm'];
61: $row = $this->getService('model')->getNavsteva($id);
62: $row->pacient_name = $row->pacient->prijmeni .' '. $row->pacient->jmeno;
63:
64: $row->cas = $row->datum->format('H:i');
65: $row->datum = $row->datum->format('d.m.Y');
66: if (!$row) $this->error('Návštěva nenalezena');
67:
68: $form->setDefaults($row);
69: $this->invalidateControl('navstevaForm');
70: }
71: }
72:
73: 74: 75: 76:
77: public function handleAddPacient() {
78: if ($this->presenter->isAjax()) {
79: $this->template->showPacientForm = true;
80: $this->invalidateControl('pacientForm');
81: }
82: }
83:
84: 85: 86: 87: 88:
89: public function handleEditPacient($id) {
90: if ($this->presenter->isAjax()) {
91: $this->template->showPacientForm = true;
92: $form = $this['pacientForm'];
93: $form['id']->setAttribute('class', 'gray');
94: $form['id']->setAttribute('readonly', 'readonly');
95: $form['new']->setDefaultValue(1);
96:
97: if (!$form->isSubmitted()) {
98: $row = $this->getService('model')->getPacient($id);
99: if (!$row) $this->error('Pacient nenalezen');
100: }
101: $form->setDefaults($row);
102: $this->invalidateControl('pacientForm');
103: }
104: }
105:
106:
107: 108: 109: 110: 111:
112: protected function createComponentNavstevaForm($name) {
113: $form = new Nette\Application\UI\Form;
114:
115: $datum = new DateTime;
116:
117: $form->addHidden('id');
118: $form->addText('datum', 'Datum',30)
119: ->setRequired('Vyplňte datum')
120: ->setAttribute('type','date')
121: ->setAttribute('readonly', 'readonly')
122: ->setDefaultValue($datum->format('d.m.Y'));
123: $form->addText('cas', 'Čas',5)
124: ->addRule(Form::LENGTH, 'Čas musí mít právě %d znaků',5)
125: ->addRule(Form::PATTERN, 'Čas musí být ve formátu HH:MM', '[0-2]{1}\d{1}:[0-5]{1}\d{1}')
126: ->setRequired('Vyplňte čas')
127: ->setAttribute('type','time')
128: ->setDefaultValue($datum->format('H:i'));
129: $form->addText('pacient_name', 'Pacient',30)
130: ->setRequired('Vyberte pacienta')
131: ->setAttribute('placeholder', 'napište alespoň 3 písmena');;
132: $form->addHidden('pacient_id')
133: ->setRequired('Vyberte pacineta ze seznamu');
134:
135: $form->addSelect('pracoviste_id', 'Pracoviště',
136: $this->getService('model')->getSelectArray('pracoviste')
137: );
138:
139: $form->addSelect('oddeleni_id', 'Oddělení',
140: $this->getService('model')->getSelectArray('oddeleni')
141: );
142:
143: $form->addText('cislo_mistnosti', 'Číslo místnosti')
144: ->setRequired('Vyplňte číslo místnoti')
145: ->addRule(Form::INTEGER,'Číslo místnosti musí být číslo')
146: ->addRule(Form::RANGE, 'Číslo místnosti musí být od %d do %d', array(1, 999));
147:
148: $form['oddeleni_id']->setDefaultValue('chi');
149: $form['pracoviste_id']->setDefaultValue('00829838000');
150:
151: $form->addSubmit('submitButton', 'Uložit');
152: $form->onSuccess[] = callback($this, 'submitNavstevaForm');
153:
154: return $form;
155: }
156:
157: 158: 159: 160: 161:
162: public function submitNavstevaForm($form) {
163: $values = $form->getValues();
164: $id = (int) $values['id'];
165:
166: unset($values['pacient_name']);
167: unset($values['id']);
168:
169: $datum = new DateTime($values['datum'].' '.$values['cas']);
170: unset($values['cas']);
171: $values['datum'] = $datum;
172:
173: if ($id > 0) {
174: $this->getService('model')->getNavsteva($id)->update($values);
175: $this->flashMessage('Návštěva byla aktualizována.');
176: } else {
177: $this->getService('model')->addNavsteva($values);
178: $this->flashMessage('Návštěva byla vytvořena.');
179: }
180:
181: if (isset($this->params['id'])) $this->redirect($this->backlink(),$this->params['id']);
182: else $this->redirect($this->backlink());
183: }
184:
185: 186: 187: 188: 189:
190: protected function createComponentPacientForm($name) {
191: $form = new Nette\Application\UI\Form;
192:
193: $form->addHidden('new', 0);
194:
195: $form->addGroup('Osobní údaje');
196:
197: $form->addText('id', 'Rodné číslo',10)
198: ->setRequired('Vyplňte rodné číslo')
199: ->addRule(Form::INTEGER, 'Rodné číslo musí být číslo')
200: ->addRule(Form::LENGTH, 'Rodné číslo musí mít přesně %d znaků', 10)
201: ->setAttribute('type','number');
202:
203: $form->addText('titul_pred', 'Titul před jménem',30);
204: $form->addText('jmeno', 'Jméno',30)
205: ->setRequired('Vyplňte jméno pacienta');
206: $form->addText('prijmeni', 'Příjmení',30)
207: ->setRequired('Vyplňte příjmení pacienta');
208: $form->addText('titul_za', 'Titul za jménem',30);
209:
210: $form->addRadioList('pohlavi', 'Pohlaví', array('muž','žena'))
211: ->setDefaultValue(0)
212: ->getSeparatorPrototype()->setName(NULL);
213:
214: $form->addSelect('pojistovna_id', 'Pojišťovna',
215: $this->getService('model')->getSelectArray('pojistovna'))
216: ->setDefaultValue('111')
217: ->setAttribute('data-placeholder','Vyberte pojišťovnu');
218:
219:
220: $form->addSelect('rodiny_stav_id', 'Rodinny stav',
221: $this->getService('model')->getSelectArray('rodiny_stav'))
222: ->setDefaultValue(1)
223: ->setAttribute('data-placeholder','Vyberte rodinný stav');
224:
225: $form->addGroup('Adresa');
226:
227: $form->addText('ulice', 'Ulice',30)
228: ->setRequired('Vyplňte název ulice');
229:
230: $form->addText('cp', 'Číslo popisné',30)
231: ->addRule(Form::INTEGER, 'Číslo popisné musí být číslo')
232: ->addRule(Form::RANGE, 'Číslo popisné musí být od %d do %d', array(1, 10000))
233: ->setAttribute('type','number')
234: ->setRequired('Vyplňte číslo popisné');
235:
236: $form->addText('mesto', 'Město',30)
237: ->setRequired('Vyplňte název obce');
238:
239: $form->addText('psc', 'PSČ',30)
240: ->addRule(Form::INTEGER, 'PSČ musí být číslo')
241: ->addRule(Form::LENGTH, 'PSČ musí mít přesně %d znaků', 5)
242: ->addRule(Form::RANGE, 'PSČ musí být od %d do %d', array(10000, 99999))
243: ->setAttribute('type','number')
244: ->setRequired('Vyplňte poštovní směrovací číslo');
245:
246: $form->setCurrentGroup(NULL);
247:
248: $form->addSubmit('submitButton', 'Uložit');
249: $form->onSuccess[] = callback($this, 'submitPacientForm');
250:
251: return $form;
252: }
253:
254: 255: 256: 257: 258:
259: public function submitPacientForm($form) {
260: $values = $form->getValues();
261: $new = $values['new'];
262: unset($values['new']);
263:
264: if ($new > 0) {
265: $id = $values['id'];
266: unset($values['id']);
267: $this->getService('model')->getPacient($id)->update($values);
268: $this->flashMessage('Pacient byl aktualizován.');
269: } else {
270: $this->getService('model')->addPacient($values);
271: $this->flashMessage('Pacient byl přidán.');
272: }
273:
274: if (isset($this->params['id'])) $this->redirect($this->backlink(),$this->params['id']);
275: else $this->redirect($this->backlink());
276: }
277:
278: 279: 280: 281: 282:
283: public function actionDeleteNavsteva($id) {
284: $this->getService('model')->getNavsteva($id)->delete();
285: $this->flashMessage('Návštěva byla smazána');
286: $this->redirect('Cekarna:view');
287: }
288: }
289: