d3v1l500 Posted July 5, 2022 Share Posted July 5, 2022 Hello... i cant show the list with states from a country based on id country... im using laravel and iluminatedb.. here is my code... ... so.. based on tari ... show list of judete Strazi.php <?php namespace App\Controllers; use App\Helpers\SystemLogger; use App\Models\Files; use App\Models\Tari; use App\Models\Judete; use App\Models\Localitati; use App\Models\Sate; use Core\ArrayForm; use Core\ArrayUtility; use Core\Controller; use Core\DebuggerUtility; use Core\Request; use Core\Session; use Core\Validation; use Core\View; class Strazi extends Controller { public function list() { $page = Request::hasArgument('page', 'GET') ? Request::getArgument('page', 'GET') : 1; $perPage = 30; $columns = ['*']; $pageName = 'page'; $strazi = \App\Models\Strazi::query(); $strazi = $strazi->orderByDesc('created_at'); if (Request::hasArgument('nume_strada') && !empty(Request::getArgument('nume_strada'))) { $keywords = Request::getArgument('nume_strada'); if (explode(',', $keywords)) { foreach (explode(',', $keywords) as $keyword) { $keyword = '%' . $keyword . '%'; $strazi = $strazi->orwhere('nume_strada', 'like', $keyword); } } else { $keywords = '%' . $keywords . '%'; $strazi = $strazi->orwhere('nume_strada', 'like', $keywords); } } if (Request::hasArgument('sort') && !empty(Request::getArgument('sort'))) { $orderBy = Request::getArgument('sort'); switch ($orderBy) { case 'desc': $strazi = $strazi->orderBy('created_at', 'desc'); break; case 'asc': $strazi = $strazi->orderBy('created_at', 'asc'); break; default: $strazi = $strazi->orderBy('created_at', 'desc'); } } $strazi = $strazi->paginate($perPage, $columns, $pageName, $page)->appends(Request::getQueryString(['page'])); View::render('admin/strazi', [ 'pageTitle' => 'Străzi / Listă Străzi', 'pageHeader' => 'Baza de Date Străzi', 'strazi' => $strazi->items(), 'nextPageUrl' => $strazi->nextPageUrl(), 'prevPageUrl' => $strazi->previousPageUrl(), 'lastPage' => $strazi->lastPage(), 'perPage' => $strazi->perPage(), 'total' => $strazi->total(), 'sort' => Request::getArgument('sort'), 'nume_strada' => Request::getArgument('nume_strada'), 'currentPageInput' => $page ]); } public function add() { $tari = Tari::all()->toArray(); $judete = Judete::all()->toArray(); $localitati = Localitati::all()->toArray(); $sate = Sate::all()->toArray(); $tariSelect = []; $tariSelect[''] = 'Selecteaza Țara'; if($tari) { foreach ($tari as $tara) { $tariSelect[$tara['id']] = $tara['nume_tara']; } } $judetSelected = []; $judetSelected[''] = 'Selectează judeţul'; if(Session::getParam('form-add-strazi')['id_judet']) { $judet = Judete::where('id', '=', Session::getParam('form-add-strazi')['id_judet'])->get(['id','nume_judet'])->first(); if($judet) { $judetSelected[$judet['id']] = $judet['nume_judet']; } } $judeteSelect = []; $judeteSelect[''] = 'Selecteaza Judetul'; if($judete) { foreach ($judete as $judet) { $judeteSelect[$judet['id']] = $judet['nume_judet']; } } $localitatiSelect = []; $localitatiSelect[''] = 'Selecteaza Localitatea'; if($localitati) { foreach ($localitati as $localitate) { $localitatiSelect[$localitate['id']] = $localitate['nume_localitate']; } } $sateSelect = []; $sateSelect[''] = 'Selecteaza Satul'; if($sate) { foreach ($sate as $sat) { $sateSelect[$sat['id']] = $sat['nume_sat']; } } $form = [ 'action' => $this->appUrl.'/admin/strazi/save', 'method' => 'POST', 'enctype' => 'multipart/form-data', 'display' => 'table' ]; $fields = [ [ 'label' => 'Țara', 'name' => 'id_tara', 'id' => 'id_tara', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/judete', 'defaultOption' => Session::getParam('form-add-strazi')['id_tara'] ], [ 'label' => 'Județ', 'name' => 'id_judet', 'id' => 'id_judet', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $judetSelected, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/orase', 'defaultOption' => Session::getParam('form-add-strazi')['id_judet'] ], [ 'label' => 'Localitate', 'name' => 'id_localitate', 'id' => 'id_localitate', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $localitatiSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/localitati', 'defaultOption' => Session::getParam('form-add-strazi')['id_localitate'] ], [ 'label' => 'Sat', 'name' => 'id_sat', 'id' => 'id_sat', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $sateSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/sate', 'defaultOption' => Session::getParam('form-add-strazi')['id_sat'] ], [ 'label' => 'Nume Strada', 'name' => 'nume_strada', 'id' => 'nume_strada', 'placeholder' => 'ex: 32E', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-strazi')['nume_strada'] ], [ 'label' => 'OFP', 'name' => 'ofp', 'id' => 'ofp', 'placeholder' => 'ex: 32E', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-strazi')['ofp'] ], [ 'label' => 'Cod poștal', 'name' => 'cod_postal', 'id' => 'cod_postal', 'placeholder' => 'ex: 107244', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-strazi')['cod_postal'] ], [ 'label' => 'Cod poștal nou', 'name' => 'cod_postal_nou', 'id' => 'cod_postal_nou', 'placeholder' => 'ex: 1242', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-strazi')['cod_postal_nou'] ], [ 'id' => 'save', 'name' => 'save', 'type' => 'submit', 'class' => 'btn btn-success btn-sm', 'value' => 'Adaugă strada' ] ]; View::render('admin/add_strazi', [ 'pageTitle' => 'Strazi / Adaugă strada', 'pageHeader' => 'Crează strada', 'form' => ArrayForm::build($form,$fields) ]); } /** * @throws \ReflectionException */ public function save() { if(Request::hasArgument('save','POST')) { $error = null; $data = Request::post(); unset($data['save']); /** * Map form params to session in case we need * to correct something */ Session::sendTheseToSession ( [ 'form-add-strazi' => $data ] ); $fileId = 0; /** * Add elev entry */ $rules = [ 'nume_strada' => ['required'], 'id_tara' => ['required'], 'id_judet' => ['required'], 'id_localitate' => ['required'] ]; $errors = [ 'nume_strada' => 'Câmpul este obligatoriu', 'id_tara' => 'Câmpul este obligatoriu', 'id_judet' => 'Câmpul este obligatoriu', 'id_localitate' => 'Câmpul este obligatoriu', ]; $validate = Validation::validate($rules,$errors); if($validate['status']) { /** * Begin saving data */ if(\App\Models\Strazi::all()->where('nume_strada','=',Request::getArgument('nume_strada','POST'))->count() < 1000) { try{ $create = \App\Models\Strazi::create($data); SystemLogger::log('strazi','O strada a fost adaugata! :'. ArrayUtility::arrayToList($data)); Session::unsetSession('form-add-strazi'); } catch (\Exception $e) { $error = $e->getMessage(); } } else { $error = 'Exista deja o strada cu numele introdus!'; } } else { $error = Validation::renderErrors($validate['error']); } View::render('admin/save_strazi', [ 'pageTitle' => 'Strazi / Adaugă strada', 'pageHeader' => 'Crează strada', 'error' => $error ]); } } Models Tari.php <?php namespace App\Models; use Core\Model; class Tari extends Model { protected $table = "tari"; protected $fillable = ["nume_tara", "nume_capitala", "updated_at", "created_at"]; public function judete() { return $this->hasMany(Judete::class, 'id_judet', 'id'); } } ?> Models Judete.php <?php namespace App\Models; use Core\Model; class Judete extends Model { /** * @var string */ protected $table = "judete"; /** * @var string[] */ protected $fillable = [ "nume_judet", "id_tara" ]; /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function tara() { return $this->hasOne(Tari::class, 'id', 'id_tara'); } /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function getTara() { return $this->hasOne(Tari::class, 'id', 'id_tara'); } } ?> Models ajax.php <?php namespace App\Controllers; use Core\Controller; use Core\Request; use Core\IlluminateDb; class Ajax extends Controller { public function judete() { $id_tara = Request::hasArgument('id_tara', 'POST') ? Request::getArgument('id_tara', 'POST') : null; $judete = IlluminateDb::table('judete')->where('id_tara', '=', $id_tara)->get(['id', 'nume_judet'])->toJson(); echo $judete; } /** * @return string */ public function clase() { $scoala = Request::hasArgument('scoala_id', 'POST') ? Request::getArgument('scoala_id', 'POST') : null; $scoli = IlluminateDb::table('clase')->where('scoala','=',$scoala)->get(['id','nume'])->toJson(); return $scoli; } /** * @return string */ public function elevi() { $clasa = Request::hasArgument('clasa','POST') ? Request::getArgument('clasa','POST'):null; $elevi = IlluminateDb::table('elevi')->where('clasa','=',$clasa)->get(['id','cnp','nume','prenume','nr_matricol'])->toJson(); return $elevi; } } Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/ Share on other sites More sharing options...
requinix Posted July 5, 2022 Share Posted July 5, 2022 5 hours ago, d3v1l500 said: i cant show the list with states from a country based on id country... What do you see happening and what is it that you expected to see? In detail. Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1597981 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 soo.. my friend.. look! i will upload some photos to make myself understood in 1.png its all my code where users can select their countries states citites and county i guess.. i dont know hot to tranlate this.. in 2 png if i select Roumanie... i can go at the states(selecteaza judetul) to show me just the states that have id of roumanie not states from another country... its an dependend drop down based on a drop drown.... the problem is that someone made this code for me... im newbie in progamming and php but i can understand something.... So i want to make this 4 drop downs menu dependent on the above lists... the first 3 go to 4 doesn't go. my code its here.. https://we.tl/t-rvpGgTsySS help me pls.. where its the mistake... Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598011 Share on other sites More sharing options...
Barand Posted July 6, 2022 Share Posted July 6, 2022 Do you have a data structure to support that process? For example +-------------------+ | country | +-------------------+ | id |-----+ | country_name | | +-------------------+ +-------------------+ | | state | | +-------------------+ | | id |-----+ +----<| country_id | | | state_name | | +-------------------+ +-------------------+ | | city | | +-------------------+ | | id |-----+ +-----<| state_id | | | city_name | | +-------------------+ +-------------------+ | | area | | +-------------------+ | | id | +-----<| city _id | | area_name | +-------------------+ Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598012 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 i gues... link with some photos from database https://we.tl/t-LJkEfSnsmp Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598014 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 this... table 'sate' its something wrong here... or in code ... Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598015 Share on other sites More sharing options...
Barand Posted July 6, 2022 Share Posted July 6, 2022 Your tables have too many keys. See my diagram above. A city only needs FK link to its parent state. A state has a FK link to its parent country so from city you know its state then from state you know its country. Example SELECT country_name , state_name , city_name FROM city ct JOIN state s ON ct.state_id = s.id JOIN country c ON s.country_id = c.id ORDER BY country_name, state_name, city_name; Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598016 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 (edited) i did... its not working 🤯 i cant understand why the first 3 columns are working and 'sate' doesent work Edited July 6, 2022 by d3v1l500 Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598017 Share on other sites More sharing options...
Barand Posted July 6, 2022 Share Posted July 6, 2022 Perhaps it's the code that's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598019 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 can you help me with code? Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598020 Share on other sites More sharing options...
Barand Posted July 6, 2022 Share Posted July 6, 2022 Not unless you post the relevant code that's giving the problem 1 Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598021 Share on other sites More sharing options...
d3v1l500 Posted July 6, 2022 Author Share Posted July 6, 2022 look this is the code.. this file its called elevi.php(students.php) where the code is for show list with students add students, update students, delete students.. code for sate is here... use App\Models\Sate; here its initialized the list with table "sate" based on id from cities lists $satNastereSelected = []; $satNastereSelected[''] = 'Selecteaza sat'; if(Session::getParam('form-add-elev')['sat_nastere']) { $satNastere = Sate::where('id','=',Session::getParam('form-add-elev')['sat_nastere'])->get(['id','name'])->first(); if($satNastere) { $satNastereSelected[$satNastere['id']] = $satNastere['name']; } } here is code where "sate" list its showed in field where "localitate nastere"(table cities) have 'data-post-endpoint' => $this->appUrl . '/ajax/sate', for sate can display sates by id from cities Quote [ 'label' => 'Localitate nastere*', 'id' => 'localitate', 'name' => 'localitate_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/sate', 'data-live-search' => 'true', 'required' => 'required', 'options' => $localitateNastereSelected, 'defaultOption' => Session::getParam('form-add-elev')['localitate_nastere'] ], [ 'label' => 'Sat nastere*', 'id' => 'sat_nastere', 'name' => 'sat_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $satNastereSelected, 'defaultOption' => Session::getParam('form-add-elev')['sat_nastere'] ], <?php namespace App\Controllers; use App\Helpers\Misc; use App\Helpers\SystemLogger; use App\Models\Cities; use App\Models\Sate; use App\Models\Countries; use App\Models\EleviRepetenti; use App\Models\Files; use App\Models\ScoalaDeProvenienta; use App\Models\States; use Core\ArrayForm; use Core\ArrayUtility; use Core\Controller; use Core\DebuggerUtility; use Core\Request; use Core\Session; use Core\Validation; use Core\View; class Elevi extends Controller { public function list() { $page = Request::hasArgument('page', 'GET') ? Request::getArgument('page', 'GET') : 1; $perPage = 30; $columns = ['*']; $pageName = 'page'; $clase = \App\Models\Clase::all(); $elevi = \App\Models\Elevi::query(); $elevi = $elevi->orderByDesc('created_at'); if (Request::hasArgument('nume') && !empty(Request::getArgument('nume'))) { $keywords = Request::getArgument('nume'); if (explode(',', $keywords)) { foreach (explode(',', $keywords) as $keyword) { $keyword = '%' . $keyword . '%'; $elevi = $elevi->orwhere('nume', 'like', $keyword); $elevi = $elevi->orWhere('prenume', 'like',$keyword); } } else { $keywords = '%' . $keywords . '%'; $elevi = $elevi->orwhere('nume', 'like', $keywords); $elevi = $elevi->orWhere('prenume', 'like',$keywords); } } if(Request::getArgument('cnp')) { $elevi = $elevi->orWhere('cnp','=',Request::getArgument('cnp')); } if(Request::getArgument('clasa')) { $elevi = $elevi->orWhere('clasa','=',Request::getArgument('clasa')); } if(Request::hasArgument('sex') && Request::getArgument('sex') != '') { $elevi = $elevi->orWhere('sex','=',Request::getArgument('sex')); } if(Request::hasArgument('rrom') && Request::getArgument('rrom') != '') { $elevi = $elevi->orWhere('rrom','=',Request::getArgument('rrom')); } if (Request::hasArgument('sort') && !empty(Request::getArgument('sort'))) { $orderBy = Request::getArgument('sort'); switch ($orderBy) { case 'desc': $elevi = $elevi->orderBy('created_at', 'desc'); break; case 'asc': $elevi = $elevi->orderBy('created_at', 'asc'); break; default: $elevi = $elevi->orderBy('created_at', 'desc'); } } $elevi = $elevi->paginate($perPage, $columns, $pageName, $page)->appends(Request::getQueryString(['page'])); View::render('admin/elevi', [ 'pageTitle' => 'Elevi / Lista elevi', 'pageHeader' => 'Baza de date elevi', 'elevi' => $elevi->items(), 'nextPageUrl' => $elevi->nextPageUrl(), 'prevPageUrl' => $elevi->previousPageUrl(), 'lastPage' => $elevi->lastPage(), 'perPage' => $elevi->perPage(), 'total' => $elevi->total(), 'clase' => $clase, 'sort' => Request::getArgument('sort'), 'clasaInput' => Request::getArgument('clasa'), 'cnp' => Request::getArgument('cnp'), 'nume' => Request::getArgument('nume'), 'currentPageInput' => $page, 'sex_values' => Misc::sex(), 'rrom_values' => Misc::yes_no(), 'rrom_v' => Request::getArgument('rrom'), 'sex_v' => Request::getArgument('sex') ]); } public function add() { $scoli = \App\Models\Scoli::all()->toArray(); $discipline = \App\Models\Discipline::all()->toArray(); $aniScolari = Misc::ani_scolari(); $aniStudiu = Misc::ani_studiu(); $sexValues = Misc::sex(); $tari = Countries::all()->toArray(); $scoliDeProvenienta = ScoalaDeProvenienta::all()->toArray(); $medii = Misc::mediu(); $yesno = Misc::yes_no(); $scoliSelect = []; $scoliSelect[''] = 'Selecteaza scoala'; if ($scoli) { foreach ($scoli as $scoala) { $scoliSelect[$scoala['id']] = $scoala['nume']; } } $aniScolariSelect = []; $aniScolariSelect[''] = 'Selecteaza anul scolar'; if ($aniScolari) { foreach ($aniScolari as $anScolar) { $aniScolariSelect[$anScolar] = $anScolar; } } $aniStudiuSelect = []; $aniStudiuSelect[''] = 'Selecteaza anul de studiu'; if ($aniStudiu) { foreach ($aniStudiu as $anStudiu) { $aniStudiuSelect[$anStudiu] = $anStudiu; } } $sexValuesSelect = []; $sexValuesSelect[''] = 'Selecteza sex-ul'; if($sexValues) { foreach ($sexValues as $sexValue){ $sexValuesSelect[$sexValue] = $sexValue; } } $tariSelect = []; $tariSelect[''] = 'Selecteaza tara'; if($tari) { foreach ($tari as $tara) { $tariSelect[$tara['id']] = $tara['name']; } } $scoliDeProvenientaSelect = []; $scoliDeProvenientaSelect[''] = 'Selecteaza scoala de provenienta'; if($scoliDeProvenienta) { foreach ($scoliDeProvenienta as $item) { $scoliDeProvenientaSelect[$item['id']] = $item['nume']; } } $mediiSelect = []; $mediiSelect[''] = 'Selecteaza mediul'; if($medii) { foreach ($medii as $mediu) { $mediiSelect[$mediu] = $mediu; } } $yesnoSelect = []; $yesnoSelect[''] = 'Alege o optiune'; if($yesno) { foreach ($yesno as $item) { $yesnoSelect[$item] = $item; } } $disciplineSelect = []; $disciplineSelect[''] = 'Selecteaza una sau mai multe discipline'; if ($discipline) { foreach ($discipline as $disciplina) { $disciplineSelect[$disciplina['id']] = $disciplina['disciplina']; } } $judetNastereSelected = []; $judetNastereSelected[''] = 'Selecteaza judetul'; if(Session::getParam('form-add-elev')['judet_nastere']) { $judetNastere = States::where('id', '=', Session::getParam('form-add-elev')['judet_nastere'])->get(['id','name'])->first(); if($judetNastere) { $judetNastereSelected[$judetNastere['id']] = $judetNastere['name']; } } $localitateNastereSelected = []; $localitateNastereSelected[''] = 'Selecteaza localitate'; if(Session::getParam('form-add-elev')['localitate_nastere']) { $localitateNastere = Cities::where('id','=',Session::getParam('form-add-elev')['localitate_nastere'])->get(['id','name'])->first(); if($localitateNastere) { $localitateNastereSelected[$localitateNastere['id']] = $localitateNastere['name']; } } $satNastereSelected = []; $satNastereSelected[''] = 'Selecteaza sat'; if(Session::getParam('form-add-elev')['sat_nastere']) { $satNastere = Sate::where('id','=',Session::getParam('form-add-elev')['sat_nastere'])->get(['id','name'])->first(); if($satNastere) { $satNastereSelected[$satNastere['id']] = $satNastere['name']; } } $selectedScoala = ''; $selectedClase = []; $selectedClase[''] = 'Selecteaza clasa'; if(Session::getParam('form-add-elev')['clasa']) { $selectedScoalaQuery = \App\Models\Clase::where('id', '=',Session::getParam('form-add-elev')['clasa'])->get(['scoala','id','nume'])->first(); if($selectedScoalaQuery) { $selectedScoala = $selectedScoalaQuery['scoala']; $selectedClase[$selectedScoalaQuery['id']] = $selectedScoalaQuery['nume']; } } $judetDomiciliuSelected = []; $judetDomiciliuSelected[''] = 'Selecteaza judetul'; if(Session::getParam('form-add-elev')['jud_domiciliu']) { $judetDomiciliu = States::where('id', '=', Session::getParam('form-add-elev')['jud_domiciliu'])->get(['id','name'])->first(); if($judetDomiciliu) { $judetDomiciliuSelected[$judetDomiciliu['id']] = $judetDomiciliu['name']; } } $localitateDomiciliuSelected = []; $localitateDomiciliuSelected[''] = 'Selecteaza localitate'; if(Session::getParam('form-add-elev')['localitate_domiciliu']) { $localitateDomiciliu = Cities::where('id','=',Session::getParam('form-add-elev')['localitate_domiciliu'])->get(['id','name'])->first(); if($localitateDomiciliu) { $localitateDomiciliuSelected[$localitateDomiciliu['id']] = $localitateDomiciliu['name']; } } $judetDomiciliuParinteSelected = []; $judetDomiciliuParinteSelected[''] = 'Selecteaza judetul'; if(Session::getParam('form-add-elev')['judet_domiciliu_parinte']) { $judetDomiciliuParinte = States::where('id', '=', Session::getParam('form-add-elev')['judet_domiciliu_parinte'])->get(['id','name'])->first(); if($judetDomiciliuParinte) { $judetDomiciliuParinteSelected[$judetDomiciliuParinte['id']] = $judetDomiciliuParinte['name']; } } $localitateDomiciliuParinteSelected = []; $localitateDomiciliuParinteSelected[''] = 'Selecteaza localitate'; if(Session::getParam('form-add-elev')['localitate_domiciliu_parinte']) { $localitateDomiciliuParinte = Cities::where('id','=',Session::getParam('form-add-elev')['localitate_domiciliu_parinte'])->get(['id','name'])->first(); if($localitateDomiciliuParinte) { $localitateDomiciliuParinteSelected[$localitateDomiciliuParinte['id']] = $localitateDomiciliuParinte['name']; } } $form = [ 'action' => $this->appUrl.'/admin/elevi/save', 'method' => 'POST', 'enctype' => 'multipart/form-data', 'display' => 'table' ]; $fields = [ [ 'id' => 'an_scolar', 'label' => 'An scolar *', 'name' => 'an_scolar', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $aniScolariSelect, 'defaultOption' => Session::getParam('form-add-elev')['an_scolar'] ], [ 'id' => 'cnp', 'name' => 'cnp', 'label' => 'Cod Numeric Personal (CNP) *', 'placeholder' => 'Introdu codul numeric personal', 'type' => 'text', 'required' => 'required', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-elev')['cnp'] ], [ 'id' => 'sex', 'name' => 'sex', 'label' => 'Sex *', 'placeholder' => 'Selecteaza sex-ul', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $sexValuesSelect, 'required' => 'required', 'defaultOption' => Session::getParam('form-add-elev')['sex'] ], [ 'id' => 'data_nastere', 'name' => 'data_nastere', 'label' => 'Data nasterii (ZZ/LL/AAAA) *', 'placeholder' => 'Click pentru a seta data nasterii', 'class' => 'pick-date form-control form-control-sm', 'required' => 'required', 'value' => Session::getParam('form-add-elev')['data_nastere'] ], [ 'id' => 'nume', 'name' => 'nume', 'label' => 'Numele *', 'placeholder' => 'ex: Popescu', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => Session::getParam('form-add-elev')['nume'] ], [ 'id' => 'initiala_tatalui', 'name' => 'initiala_tatalui', 'label' => 'Initiala tatalui *', 'placeholder' => 'ex: F', 'class' => 'form-control form-control-sm', 'required' => 'required', 'maxlength' => '1', 'value' => Session::getParam('form-add-elev')['initiala_tatalui'] ], [ 'id' => 'prenume', 'name' => 'prenume', 'label' => 'Prenumele *', 'placeholder' => 'ex: Constantin', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => Session::getParam('form-add-elev')['prenume'] ], [ 'id' => 'prenume_tata', 'name' => 'prenume_tata', 'label' => 'Prenumele Tatalui *', 'placeholder' => 'ex: Adrian', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => Session::getParam('form-add-elev')['prenume_tata'] ], [ 'id' => 'prenume_mama', 'name' => 'prenume_mama', 'label' => 'Prenumele Mamei *', 'placeholder' => 'ex: Maria', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => Session::getParam('form-add-elev')['prenume_mama'] ], [ 'id' => 'tara', 'label' => 'Tara nasterii *', 'name' => 'tara_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => Session::getParam('form-add-elev')['tara_nastere'] ], [ 'label' => 'Judet nastere *', 'id' => 'judet', 'name' => 'judet_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'options' => $judetNastereSelected, 'defaultOption' => Session::getParam('form-add-elev')['judet_nastere'] ], [ 'label' => 'Localitate nastere*', 'id' => 'localitate', 'name' => 'localitate_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/sate', 'data-live-search' => 'true', 'required' => 'required', 'options' => $localitateNastereSelected, 'defaultOption' => Session::getParam('form-add-elev')['localitate_nastere'] ], [ 'label' => 'Sat nastere*', 'id' => 'sat_nastere', 'name' => 'sat_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $satNastereSelected, 'defaultOption' => Session::getParam('form-add-elev')['sat_nastere'] ], [ 'id' => 'nationalitate', 'label' => 'Nationalitate *', 'name' => 'nationalitate', 'class' => 'form-control form-control-sm', 'required' => 'required', 'placeholder' => 'ex: Roman, Spaniol', 'value' => Session::getParam('form-add-elev')['nationalitate'] ], [ 'id' => 'scoala_de_provenienta', 'label' => 'Scoala de provenienta', 'name' => 'scoala_de_provenienta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'options' => $scoliDeProvenientaSelect, 'defaultValue' => Session::getParam('form-add-elev')['scoala_de_provenienta'] ], [ 'id' => 'scoala', 'label' => 'Scoala actuala', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/clase', 'options' => $scoliSelect, 'defaultOption' => $selectedScoala ], [ 'id' => 'clasa', 'label' => 'Clasa *', 'type' => 'select', 'name' => 'clasa', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $selectedClase, 'defaultOption' => Session::getParam('form-add-elev')['clasa'] ], [ 'id' => 'limba1', 'label' => 'Limba 1 *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba1', 'required' => 'required', 'placeholder' => 'ex: Romana', 'value' => Session::getParam('form-add-elev')['limba1'] ], [ 'id' => 'limba2', 'label' => 'Limba 2 ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba2', 'placeholder' => 'ex: Spaniola', 'value' => Session::getParam('form-add-elev')['limba2'] ], [ 'id' => 'asistent_social', 'label' => 'Asistent social', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'asistent_social', 'placeholder' => 'ex: Popescu Laura', 'value' => Session::getParam('form-add-elev')['asistent_social'] ], [ 'id' => 'nr_matricol', 'label' => 'Numar matricol *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'nr_matricol', 'required' => 'required', 'placeholder' => 'ex: CJ-122', 'value' => Session::getParam('form-add-elev')['nr_matricol'] ], [ 'id' => 'vol', 'label' => 'Volum *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'vol', 'required' => 'required', 'placeholder' => 'ex: 1', 'value' => Session::getParam('form-add-elev')['vol'] ], [ 'id' => 'pag', 'label' => 'Pagina *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'pag', 'required' => 'required', 'placeholder' => 'ex: 2', 'value' => Session::getParam('form-add-elev')['pag'] ], [ 'id' => 'responsabil_isj', 'label' => 'Responsabil ISJ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'responsabil_isj', 'placeholder' => 'ex: Aurelian Temisan', 'value' => Session::getParam('form-add-elev')['responsabil_isj'] ], [ 'id' => 'tara_domiciliu', 'label' => 'Tara domiciliu *', 'name' => 'tara_domiciliu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => Session::getParam('form-add-elev')['tara_domiciliu'] ], [ 'label' => 'Judet domiciliu *', 'id' => 'judet_domiciliu', 'name' => 'jud_domiciliu', 'type' => 'select', 'options' => $judetDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => Session::getParam('form-add-elev')['jud_domiciliu'] ], [ 'label' => 'Localitate domiciliu *', 'id' => 'localitate_domiciliu', 'name' => 'localitate_domiciliu', 'type' => 'select', 'options' => $localitateDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => Session::getParam('form-add-elev')['localitate_domiciliu'] ], [ 'id' => 'adresa_domiciliu', 'label' => 'Adresa de domiciliu *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'adresa_domiciliu', 'required' => 'required', 'placeholder' => 'ex: Strada nr 1 , Plopeni Ell', 'value' => Session::getParam('form-add-elev')['adresa_domiciliu'] ], [ 'id' => 'mediu', 'label' => 'Mediul (Rural/Urban) *', 'name' => 'mediu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => Session::getParam('form-add-elev')['mediu'] ], [ 'id' => 'telefon_elev', 'label' => 'Telefon elev *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'telefon_elev', 'required' => 'required', 'placeholder' => 'ex: 0745111554', 'value' => Session::getParam('form-add-elev')['telefon_elev'] ], [ 'id' => 'email_elev', 'label' => 'Email elev', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'email_elev', 'placeholder' => 'ex: elevescu@popescunescu.com', 'value' => Session::getParam('form-add-elev')['email_elev'] ], [ 'id' => 'plasament', 'label' => 'Plasament *', 'name' => 'plasament', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => Session::getParam('form-add-elev')['plasament'] ], [ 'id' => 'incris_prima_data', 'label' => 'Inscris prima data *', 'name' => 'incris_prima_data', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => Session::getParam('form-add-elev')['incris_prima_data'] ], [ 'id' => 'din_promotia_curenta', 'label' => 'Din Promotia curenta *', 'name' => 'din_promotia_curenta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => Session::getParam('form-add-elev')['din_promotia_curenta'] ], [ 'id' => 'rrom', 'label' => 'Rrom *', 'name' => 'rrom', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => Session::getParam('form-add-elev')['rrom'] ], [ 'id' => 'fotografie', 'label' => 'Fotografie', 'name' => 'fotografie', 'type' => 'file', 'class' => 'form-control form-control-sm btn btn-danger btn-sm', 'accept' => 'image/*' ], [ 'id' => 'tara_domiciliu_parinte', 'label' => 'Tara domiciliu parinte*', 'name' => 'tara_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => Session::getParam('form-add-elev')['tara_domiciliu_parinte'] ], [ 'label' => 'Judet domiciliu parinte *', 'id' => 'judet_domiciliu_parinte', 'name' => 'judet_domiciliu_parinte', 'type' => 'select', 'options' => $judetDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => Session::getParam('form-add-elev')['judet_domiciliu_parinte'] ], [ 'label' => 'Localitate domiciliu parinte *', 'id' => 'localitate_domiciliu_parinte', 'name' => 'localitate_domiciliu_parinte', 'type' => 'select', 'options' => $localitateDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => Session::getParam('form-add-elev')['localitate_domiciliu_parinte'] ], [ 'id' => 'adresa_domiciliu_parinte', 'name' => 'adresa_domiciliu_parinte', 'required' => 'required', 'label' => 'Adresa de domiciliu parinte *', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-elev')['adresa_domiciliu_parinte'] ], [ 'id' => 'mediu_domiciliu_parinte', 'label' => 'Mediu domiciliu parinte (Rural/Urban) *', 'name' => 'mediu_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => Session::getParam('form-add-elev')['mediu_domiciliu_parinte'] ], [ 'id' => 'telefon_parinte', 'name' => 'telefon_parinte', 'required' => 'required', 'label' => 'Telefon parinte *', 'placeholder' => 'ex: 0744555441', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-elev')['telefon_parinte'] ], [ 'id' => 'email_parinte', 'name' => 'email_parinte', 'label' => 'Adresa de email parinte', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => Session::getParam('form-add-elev')['email_parinte'] ], [ 'id' => 'discipline', 'label' => 'Discipline', 'name' => 'discipline[]', 'type' => 'select', 'class' => 'form-control form-control-sm', 'multiple' => 'multiple', 'options' => $disciplineSelect, 'defaultOption' => Session::hasParam('form-add-elev')['discipline'] ? Session::getParam('form-add-elev')['discipline']:'' ], [ 'id' => 'observatii', 'label' => 'Observatii', 'name' => 'observatii', 'type' => 'textarea', 'class' => 'form-control form-control-sm', 'placeholder' => 'Introdu observatii', 'style' => 'width: 100%; min-height: 145px; resize: none;', 'value' => Session::hasParam('form-add-elev')['observatii'] ], [ 'id' => 'save', 'name' => 'save', 'type' => 'submit', 'class' => 'btn btn-success btn-sm', 'value' => 'Adauga elevul' ] ]; View::render('admin/add_elevi', [ 'pageTitle' => 'Elevi / Adauga Elevi', 'pageHeader' => 'Creaza elev', 'form' => ArrayForm::build($form,$fields) ]); } /** * @throws \ReflectionException */ public function save() { if(Request::hasArgument('save','POST')) { $error = null; $discipline = 0; if(Request::getArgument('discipline','POST')) { $discipline = implode(',',Request::getArgument('discipline','POST')); } $data = Request::post(); unset($data['save']); /** * Map form params to session in case we need * to correct something */ Session::sendTheseToSession ( [ 'form-add-elev' => $data ] ); unset($data['discipline']); $data = Misc::applyDefaultValues($data); $data['discipline'] = $discipline; $data = array_merge($data,['fotografie' => 0]); $responsabil_isj = 0; $asistent_social = 0; if($data['clasa']) { $clasa = \App\Models\Clase::where('id','=',$data['clasa'])->first(); if($clasa->getScoala) { $responsabil_isj = $clasa->getScoala->responsabil_isj; $asistent_social = $clasa->getScoala->asistent_social; } } if($data['asistent_social'] == 0) { $data['asistent_social'] = $asistent_social; } if($data['responsabil_isj'] == 0) { $data['responsabil_isj'] = $responsabil_isj; } $fileId = 0; /** * Upload fotografie */ if(Request::hasFile('fotografie')) { if(Request::getFile('fotografie')) { $file = Request::getFile('fotografie'); $upload = Request::uploadFile('fotografie',time()); $fileId = 0; if($upload['status']) { if($upload['data']) { foreach ($upload['data'] as $datum) { try { $file = Files::create ( [ 'file_name' => $datum['new_name'], 'location' => $datum['full_path_new_name'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ] ); $fileId = $file->id; SystemLogger::log('files','Uploaded file with details: '. ArrayUtility::arrayToList($datum)); } catch (\Exception $exception) { SystemLogger::log('files','Could not upload file with details: '. ArrayUtility::arrayToList($datum) .' <br/> Error:' .$exception->getMessage()); } } } } else { $error = ArrayUtility::arrayToList($upload['errors']); SystemLogger::log('files','There was an error uploading the file. Error: '.ArrayUtility::arrayToList($upload['errors'])); } } } /** * Add elev entry */ $rules = [ 'an_scolar' => ['required'], 'cnp' => ['required' , 'min:13' ,'max: 16'], 'sex' => ['required'], 'data_nastere' => ['required'], 'nume' => ['required', 'min: 3', 'max: 40'], 'initiala_tatalui' => ['required', 'min: 1', 'max: 1'], 'prenume' => ['required', 'min: 3', 'max: 40'], 'prenume_tata' => ['required', 'min: 3', 'max: 40'], 'prenume_mama' => ['required' , 'min: 3', 'max: 40'], 'tara_nastere' => ['required'], 'judet_nastere' => ['required'], 'localitate_nastere' => ['required'], 'nationalitate' => ['required', 'min: 3', 'max: 20'], 'clasa' => ['required'], 'limba1' => ['required' ,'min: 3' , 'max: 10'], 'limba2' => ['max: 10'], 'asistent_social' => ['max: 40'], 'nr_matricol' => ['required'], 'vol' => ['required'], 'pag' => ['required'], 'tara_domiciliu' => ['required'], 'jud_domiciliu' => ['required'], 'localitate_domiciliu' => ['required'], 'adresa_domiciliu' => ['required', 'min: 3'], 'mediu' => ['required'], 'telefon_elev' => ['required', 'min: 10', 'max: 15'], 'email_elev' => ['max: 60'], 'plasament' => ['required'], 'incris_prima_data' => ['required'], 'din_promotia_curenta' => ['required'], 'rrom' => ['required'], 'tara_domiciliu_parinte' => ['required'], 'judet_domiciliu_parinte' => ['required'], 'localitate_domiciliu_parinte' => ['required'], 'adresa_domiciliu_parinte' => ['required'], 'mediu_domiciliu_parinte' => ['required'], 'telefon_parinte' => ['required', 'min:10', 'max: 15'], 'email_parinte' => ['max: 60'], 'observatii' => ['max: 500'] ]; $errors = [ 'an_scolar.required' => 'Anul scolar trebuie selectat', 'cnp.required' => 'CPN-ul trebuie completat', 'cnp.min' => 'CNP-ul trebuie sa contina minim :min caractere', 'cnp.max' => 'CNP-ul trebuie sa contina maxim :max caractere', 'data_nastere.required' => 'Data nasterii trebuie completata', 'nume.required' => 'Numele trebuie completat', 'nume.min' => 'Numele trebuie sa contina macar :min caractere', 'nume.max' => 'Numele trebuie sa contina maxim :min caractere', 'initiala_tatalui.required' => 'Initiala tatalui trebuie completata', 'initiala_tatalui.min' => 'Initiala tatalui nu trebuie sa depaseasca :min caractere', 'initiala_tatalui.max' => 'Initiala tatalui nu trebuie sa depaseasca :max caractere', 'prenume.required' => 'Prenumele trebuie completat', 'prenume.min' => 'Prenumele trebuie sa contina macar :min caractere', 'prenume.max' => 'Prenumele trebuie sa contina maxim :max caractere', 'prenume_tata.required' => 'Prenumele tatalui trebuie sa fie completat', 'prenume_tata.min' => 'Prenumele tatalui trebuie sa contina macar :min caractere', 'prenume_tata.max' => 'Prenumele tatalui trebuie sa nu depaseasca :max caractere', 'prenume_mama.required' => 'Prenumele mamei trebuie sa fie completat', 'prenume_mama.min' => 'Prenumele mamei trebuie sa contina macar :min caractere', 'prenume_mama.max' => 'Prenumele mamei nu trebuie sa depaseasca :max caractere', 'tara_nastere.required' => 'Tara nasterii trebuie selectata', 'judet_nastere.required' => 'Judelul nasterii trebuie selectat', 'localitate_nastere.required' => 'Localitatea nasterii trebuie selectata', 'nationalitate.required' => 'Nationalitatea trebuie completata', 'nationalitate.min' => 'Nationalitatea trebuie sa contina macar :min caractere', 'nationalitate.max' => 'Nationalitatea nu trebuie sa depaseasca :max caractere', 'clasa.required' => 'Clasa curenta trebuie selectata', 'limba1.required' => 'Limba 1 trebuie completata', 'limba1.min' => 'Limba 1 trebuie sa contina macar :min caractere', 'limba1.max' => 'Limba 1 nu trebuie sa depaseasca :max caractere', 'limba2.min' => 'Limba 2 trebuie sa contina macar :min caractere', 'limba2.max' => 'Limba 2 nu trebuie sa depaseasca :max caractere', 'asistent_social.min' => 'Numele asistentului social trebuie sa contina macar :min caractere', 'asistent_social.max' => 'Numele asistentului social nu trebuie sa depaseasca :max caractere', 'nr_matricol.required' => 'Numarul matricol trebuie completat', 'vol.required' => 'Volumul trebuie completat', 'pag.required' => 'Pagina trebuie completata', 'tara_domiciliu.required' => 'Tara de domiciliu trebuie selectata', 'jud_domiciliu.required' => 'Judetul de domiciliu trebuie selectata', 'localitate_domiciliu.required' => 'Localitatea de domiciliu trebuie selectata', 'adresa_domiciliu.required' => 'Adresa de domiciliu trebuie completata', 'adresa_domiciliu.min' => 'Adresa de domiciliu trebuie sa contina macar :min caractere', 'mediu.required' => 'Mediul trebuie selectat', 'telefon_elev.required' => 'Telefonul elevului trebuie completat', 'telefon_elev.min' => 'Telefonul elevului trebuie sa contina macar :min caractere', 'telefon_elev.max' => 'Telefonul elevului nu trebuie sa depaseasca :max caractere', 'email_elev.min' => 'Email-ul elevului trebuie sa contina macar :min caractere', 'email_elev.max' => 'Email-ul elevului nu trebuie sa depaseasca :max caractere', 'plasament.required' => 'Plasamentul trebuie selectat', 'incris_prima_data.required' => 'Trebuie selectat daca elevul a fost inscris prima data', 'din_promotia_curenta.required' => 'Trebuie selectat daca elevul face parte din promotia curenta', 'rrom.required' => 'Trebuie selectat daca elevul este sau nu rrom', 'tara_domiciliu_parinte.required' => 'Tara de domiciliu a parintilor trebuie selectata', 'judet_domiciliu_parinte.required' => 'Judetul de domiciliu al parintilor trebuie selectat', 'localitate_domiciliu_parinte.required' => 'Localitatea de domiciliu a parintilor trebuie selectata', 'adresa_domiciliu_parinte.required' => 'Adresa de domiciliu a parintilor trebuie completata', 'mediu_domiciliu_parinte.required' => 'Mediul domiciliului parintilor trebuie selectat', 'telefon_parinte.required' => 'Telefonul parintilor trebuie completat', 'telefon_parinte.min' => 'Telefonul parintilor trebuie sa contina macar :min caractere', 'telefon_parinte.max' => 'Telefonul parintilor nu trebuie sa depaseasca :max caractere', 'email_parinte.min' => 'Adresa de email a parintilor trebuie sa contina macar :min caractere', 'email_parinte.max' => 'Adresa de email a parintilor nu trebuie sa depaseasca :max caractere', 'observatii.max' => 'Campul de observatii nu trebuie sa depaseasca :max caractere' ]; $validate = Validation::validate($rules,$errors); if($validate['status']) { /** * Begin saving data */ if(\App\Models\Elevi::all()->where('cnp','=',Request::getArgument('cnp','POST'))->count() < 1) { try{ $create = \App\Models\Elevi::create($data); SystemLogger::log('elevi','A student was added within the system with data :'. ArrayUtility::arrayToList($data)); \App\Models\Elevi::where('id','=',$create->id)->update(['fotografie' => $fileId]); Session::unsetSession('form-add-elev'); } catch (\Exception $e) { $error = $e->getMessage(); } } else { $error = 'Exista deja un elev cu CNP-ul introdus!'; } } else { $error = Validation::renderErrors($validate['error']); } View::render('admin/save_elevi', [ 'pageTitle' => 'Elevi / Adauga Elevi', 'pageHeader' => 'Creaza elev', 'error' => $error ]); } } /** * @param $request */ public function view($request) { $id = (int) $request; $data = \App\Models\Elevi::all()->where('id', '=', $id)->first(); if($data) { $scoli = \App\Models\Scoli::all()->toArray(); $discipline = \App\Models\Discipline::all()->toArray(); $aniScolari = Misc::ani_scolari(); $aniStudiu = Misc::ani_studiu(); $sexValues = Misc::sex(); $tari = Countries::all()->toArray(); $scoliDeProvenienta = ScoalaDeProvenienta::all()->toArray(); $medii = Misc::mediu(); $yesno = Misc::yes_no(); $scoliSelect = []; $scoliSelect[''] = 'Selecteaza scoala'; if ($scoli) { foreach ($scoli as $scoala) { $scoliSelect[$scoala['id']] = $scoala['nume']; } } $aniScolariSelect = []; $aniScolariSelect[''] = 'Selecteaza anul scolar'; if ($aniScolari) { foreach ($aniScolari as $anScolar) { $aniScolariSelect[$anScolar] = $anScolar; } } $aniStudiuSelect = []; $aniStudiuSelect[''] = 'Selecteaza anul de studiu'; if ($aniStudiu) { foreach ($aniStudiu as $anStudiu) { $aniStudiuSelect[$anStudiu] = $anStudiu; } } $sexValuesSelect = []; $sexValuesSelect[''] = 'Selecteza sex-ul'; if($sexValues) { foreach ($sexValues as $sexValue){ $sexValuesSelect[$sexValue] = $sexValue; } } $tariSelect = []; $tariSelect[''] = 'Selecteaza tara'; if($tari) { foreach ($tari as $tara) { $tariSelect[$tara['id']] = $tara['name']; } } $scoliDeProvenientaSelect = []; $scoliDeProvenientaSelect[''] = 'Selecteaza scoala de provenienta'; if($scoliDeProvenienta) { foreach ($scoliDeProvenienta as $item) { $scoliDeProvenientaSelect[$item['id']] = $item['nume']; } } $mediiSelect = []; $mediiSelect[''] = 'Selecteaza mediul'; if($medii) { foreach ($medii as $mediu) { $mediiSelect[$mediu] = $mediu; } } $yesnoSelect = []; $yesnoSelect[''] = 'Alege o optiune'; if($yesno) { foreach ($yesno as $item) { $yesnoSelect[$item] = $item; } } $disciplineSelect = []; $disciplineSelect[''] = 'Selecteaza una sau mai multe discipline'; if ($discipline) { foreach ($discipline as $disciplina) { $disciplineSelect[$disciplina['id']] = $disciplina['disciplina']; } } $judetNastereSelected = []; $judetNastereSelected[''] = 'Selecteaza judetul'; if($data->judet_nastere) { $judetNastere = States::where('id', '=', $data->judet_nastere)->get(['id','name'])->first(); if($judetNastere) { $judetNastereSelected[$judetNastere['id']] = $judetNastere['name']; } } $localitateNastereSelected = []; $localitateNastereSelected[''] = 'Selecteaza localitate'; if($data->localitate_nastere) { $localitateNastere = Cities::where('id','=',$data->localitate_nastere)->get(['id','name'])->first(); if($localitateNastere) { $localitateNastereSelected[$localitateNastere['id']] = $localitateNastere['name']; } } $selectedScoala = ''; $selectedClase = []; $selectedClase[''] = 'Selecteaza clasa'; if($data->clasa) { $selectedScoalaQuery = \App\Models\Clase::where('id', '=',$data->clasa)->get(['scoala','id','nume'])->first(); if($selectedScoalaQuery) { $selectedScoala = $selectedScoalaQuery['scoala']; $selectedClase[$selectedScoalaQuery['id']] = $selectedScoalaQuery['nume']; } } $judetDomiciliuSelected = []; $judetDomiciliuSelected[''] = 'Selecteaza judetul'; if($data->jud_domiciliu) { $judetDomiciliu = States::where('id', '=', $data->jud_domiciliu)->get(['id','name'])->first(); if($judetDomiciliu) { $judetDomiciliuSelected[$judetDomiciliu['id']] = $judetDomiciliu['name']; } } $localitateDomiciliuSelected = []; $localitateDomiciliuSelected[''] = 'Selecteaza localitate'; if($data->localitate_domiciliu) { $localitateDomiciliu = Cities::where('id','=',$data->localitate_domiciliu)->get(['id','name'])->first(); if($localitateDomiciliu) { $localitateDomiciliuSelected[$localitateDomiciliu['id']] = $localitateDomiciliu['name']; } } $judetDomiciliuParinteSelected = []; $judetDomiciliuParinteSelected[''] = 'Selecteaza judetul'; if($data->judet_domiciliu_parinte) { $judetDomiciliuParinte = States::where('id', '=', $data->judet_domiciliu_parinte)->get(['id','name'])->first(); if($judetDomiciliuParinte) { $judetDomiciliuParinteSelected[$judetDomiciliuParinte['id']] = $judetDomiciliuParinte['name']; } } $localitateDomiciliuParinteSelected = []; $localitateDomiciliuParinteSelected[''] = 'Selecteaza localitate'; if($data->localitate_domiciliu_parinte) { $localitateDomiciliuParinte = Cities::where('id','=',$data->localitate_domiciliu_parinte)->get(['id','name'])->first(); if($localitateDomiciliuParinte) { $localitateDomiciliuParinteSelected[$localitateDomiciliuParinte['id']] = $localitateDomiciliuParinte['name']; } } $form = [ 'action' => $this->appUrl.'/admin/elevi/update/'.$id, 'method' => 'POST', 'enctype' => 'multipart/form-data', 'display' => 'table' ]; $fields = [ [ 'id' => 'an_scolar', 'label' => 'An scolar *', 'name' => 'an_scolar', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $aniScolariSelect, 'defaultOption' => $data->an_scolar, 'readonly' => 'readonly' ], [ 'id' => 'cnp', 'name' => 'cnp', 'label' => 'Cod Numeric Personal (CNP) *', 'placeholder' => 'Introdu codul numeric personal', 'type' => 'text', 'required' => 'required', 'class' => 'form-control form-control-sm', 'value' => $data->cnp, 'readonly' => 'readonly' ], [ 'id' => 'sex', 'name' => 'sex', 'label' => 'Sex *', 'placeholder' => 'Selecteaza sex-ul', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $sexValuesSelect, 'required' => 'required', 'defaultOption' => $data->sex, 'readonly' => 'readonly' ], [ 'id' => 'data_nastere', 'name' => 'data_nastere', 'label' => 'Data nasterii (ZZ/LL/AAAA) *', 'placeholder' => 'Click pentru a seta data nasterii', 'class' => 'pick-date form-control form-control-sm', 'required' => 'required', 'value' => $data->data_nastere, 'readonly' => 'readonly' ], [ 'id' => 'nume', 'name' => 'nume', 'label' => 'Numele *', 'placeholder' => 'ex: Popescu', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->nume, 'readonly' => 'readonly' ], [ 'id' => 'initiala_tatalui', 'name' => 'initiala_tatalui', 'label' => 'Initiala tatalui *', 'placeholder' => 'ex: F', 'class' => 'form-control form-control-sm', 'required' => 'required', 'maxlength' => '1', 'value' => $data->initiala_tatalui, 'readonly' => 'readonly' ], [ 'id' => 'prenume', 'name' => 'prenume', 'label' => 'Prenumele *', 'placeholder' => 'ex: Constantin', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume, 'readonly' => 'readonly' ], [ 'id' => 'prenume_tata', 'name' => 'prenume_tata', 'label' => 'Prenumele Tatalui *', 'placeholder' => 'ex: Adrian', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume_tata, 'readonly' => 'readonly' ], [ 'id' => 'prenume_mama', 'name' => 'prenume_mama', 'label' => 'Prenumele Mamei *', 'placeholder' => 'ex: Maria', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume_mama, 'readonly' => 'readonly' ], [ 'id' => 'tara', 'label' => 'Tara nasterii *', 'name' => 'tara_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_nastere, 'readonly' => 'readonly' ], [ 'label' => 'Judet nastere *', 'id' => 'judet', 'name' => 'judet_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'options' => $judetNastereSelected, 'defaultOption' => $data->judet_nastere, 'readonly' => 'readonly' ], [ 'label' => 'Localitate nastere*', 'id' => 'localitate', 'name' => 'localitate_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $localitateNastereSelected, 'defaultOption' => $data->localitate_nastere, 'readonly' => 'readonly' ], [ 'id' => 'nationalitate', 'label' => 'Nationalitate *', 'name' => 'nationalitate', 'class' => 'form-control form-control-sm', 'required' => 'required', 'placeholder' => 'ex: Roman, Spaniol', 'value' => $data->nationalitate, 'readonly' => 'readonly' ], [ 'id' => 'scoala_de_provenienta', 'label' => 'Scoala de provenienta', 'name' => 'scoala_de_provenienta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'options' => $scoliDeProvenientaSelect, 'defaultOption' => $data->scoala_de_provenienta, 'readonly' => 'readonly' ], [ 'id' => 'scoala', 'label' => 'Scoala actuala', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/clase', 'options' => $scoliSelect, 'defaultOption' => $selectedScoala, 'readonly' => 'readonly' ], [ 'id' => 'clasa', 'label' => 'Clasa *', 'type' => 'select', 'name' => 'clasa', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $selectedClase, 'defaultOption' => $data->clasa, 'readonly' => 'readonly' ], [ 'id' => 'limba1', 'label' => 'Limba 1 *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba1', 'required' => 'required', 'placeholder' => 'ex: Romana', 'value' => $data->limba1, 'readonly' => 'readonly' ], [ 'id' => 'limba2', 'label' => 'Limba 2 ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba2', 'placeholder' => 'ex: Spaniola', 'value' => $data->limba2, 'readonly' => 'readonly' ], [ 'id' => 'asistent_social', 'label' => 'Asistent social', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'asistent_social', 'placeholder' => 'ex: Popescu Laura', 'value' => $data->asistent_social, 'readonly' => 'readonly' ], [ 'id' => 'nr_matricol', 'label' => 'Numar matricol *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'nr_matricol', 'required' => 'required', 'placeholder' => 'ex: CJ-122', 'value' => $data->nr_matricol, 'readonly' => 'readonly' ], [ 'id' => 'vol', 'label' => 'Volum *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'vol', 'required' => 'required', 'placeholder' => 'ex: 1', 'value' => $data->vol, 'readonly' => 'readonly' ], [ 'id' => 'pag', 'label' => 'Pagina *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'pag', 'required' => 'required', 'placeholder' => 'ex: 2', 'value' => $data->pag, 'readonly' => 'readonly' ], [ 'id' => 'responsabil_isj', 'label' => 'Responsabil ISJ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'responsabil_isj', 'placeholder' => 'ex: Aurelian Temisan', 'value' => $data->responsabil_isj, 'readonly' => 'readonly' ], [ 'id' => 'tara_domiciliu', 'label' => 'Tara domiciliu *', 'name' => 'tara_domiciliu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_domiciliu, 'readonly' => 'readonly' ], [ 'label' => 'Judet domiciliu *', 'id' => 'judet_domiciliu', 'name' => 'jud_domiciliu', 'type' => 'select', 'options' => $judetDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->jud_domiciliu, 'readonly' => 'readonly' ], [ 'label' => 'Localitate domiciliu *', 'id' => 'localitate_domiciliu', 'name' => 'localitate_domiciliu', 'type' => 'select', 'options' => $localitateDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->localitate_domiciliu, 'readonly' => 'readonly' ], [ 'id' => 'adresa_domiciliu', 'label' => 'Adresa de domiciliu *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'adresa_domiciliu', 'required' => 'required', 'placeholder' => 'ex: Strada nr 1 , Plopeni Ell', 'value' => $data->adresa_domiciliu, 'readonly' => 'readonly' ], [ 'id' => 'mediu', 'label' => 'Mediul (Rural/Urban) *', 'name' => 'mediu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => $data->mediu, 'readonly' => 'readonly' ], [ 'id' => 'telefon_elev', 'label' => 'Telefon elev *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'telefon_elev', 'required' => 'required', 'placeholder' => 'ex: 0745111554', 'value' => $data->telefon_elev, 'readonly' => 'readonly' ], [ 'id' => 'email_elev', 'label' => 'Email elev', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'email_elev', 'placeholder' => 'ex: elevescu@popescunescu.com', 'value' => $data->email_elev, 'readonly' => 'readonly' ], [ 'id' => 'plasament', 'label' => 'Plasament *', 'name' => 'plasament', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->plasament, 'readonly' => 'readonly' ], [ 'id' => 'incris_prima_data', 'label' => 'Inscris prima data *', 'name' => 'incris_prima_data', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->incris_prima_data, 'readonly' => 'readonly' ], [ 'id' => 'din_promotia_curenta', 'label' => 'Din Promotia curenta *', 'name' => 'din_promotia_curenta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->din_promotia_curenta, 'readonly' => 'readonly' ], [ 'id' => 'rrom', 'label' => 'Rrom *', 'name' => 'rrom', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->rrom, 'readonly' => 'readonly' ], [ 'id' => 'tara_domiciliu_parinte', 'label' => 'Tara domiciliu parinte*', 'name' => 'tara_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_domiciliu_parinte, 'readonly' => 'readonly' ], [ 'label' => 'Judet domiciliu parinte *', 'id' => 'judet_domiciliu_parinte', 'name' => 'judet_domiciliu_parinte', 'type' => 'select', 'options' => $judetDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->judet_domiciliu_parinte, 'readonly' => 'readonly' ], [ 'label' => 'Localitate domiciliu parinte *', 'id' => 'localitate_domiciliu_parinte', 'name' => 'localitate_domiciliu_parinte', 'type' => 'select', 'options' => $localitateDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->localitate_domiciliu_parinte, 'readonly' => 'readonly' ], [ 'id' => 'adresa_domiciliu_parinte', 'name' => 'adresa_domiciliu_parinte', 'required' => 'required', 'label' => 'Adresa de domiciliu parinte *', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->adresa_domiciliu_parinte, 'readonly' => 'readonly' ], [ 'id' => 'mediu_domiciliu_parinte', 'label' => 'Mediu domiciliu parinte (Rural/Urban) *', 'name' => 'mediu_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => $data->mediu_domiciliu_parinte, 'readonly' => 'readonly' ], [ 'id' => 'telefon_parinte', 'name' => 'telefon_parinte', 'required' => 'required', 'label' => 'Telefon parinte *', 'placeholder' => 'ex: 0744555441', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->telefon_parinte, 'readonly' => 'readonly' ], [ 'id' => 'email_parinte', 'name' => 'email_parinte', 'label' => 'Adresa de email parinte', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->email_parinte, 'readonly' => 'readonly' ], [ 'id' => 'discipline', 'label' => 'Discipline', 'name' => 'discipline[]', 'type' => 'select', 'class' => 'form-control form-control-sm', 'multiple' => 'multiple', 'options' => $disciplineSelect, 'defaultOption' => $data->discipline ? explode(',',$data->discipline) : 'null' ] ]; View::render('admin/view_elevi', [ 'pageTitle' => 'Elevi / Detalii elev', 'pageHeader' => 'Detalii elev', 'form' => ArrayForm::build($form,$fields), 'data' => $data, 'id' => $id ]); } else { Request::redirect($this->appUrl.'/admin/elevi'); } } /** * @param $request */ public function edit($request) { $id = (int) $request; $data = \App\Models\Elevi::all()->where('id', '=', $id)->first(); if($data) { $scoli = \App\Models\Scoli::all()->toArray(); $discipline = \App\Models\Discipline::all()->toArray(); $aniScolari = Misc::ani_scolari(); $aniStudiu = Misc::ani_studiu(); $sexValues = Misc::sex(); $tari = Countries::all()->toArray(); $scoliDeProvenienta = ScoalaDeProvenienta::all()->toArray(); $medii = Misc::mediu(); $yesno = Misc::yes_no(); $scoliSelect = []; $scoliSelect[''] = 'Selecteaza scoala'; if ($scoli) { foreach ($scoli as $scoala) { $scoliSelect[$scoala['id']] = $scoala['nume']; } } $aniScolariSelect = []; $aniScolariSelect[''] = 'Selecteaza anul scolar'; if ($aniScolari) { foreach ($aniScolari as $anScolar) { $aniScolariSelect[$anScolar] = $anScolar; } } $aniStudiuSelect = []; $aniStudiuSelect[''] = 'Selecteaza anul de studiu'; if ($aniStudiu) { foreach ($aniStudiu as $anStudiu) { $aniStudiuSelect[$anStudiu] = $anStudiu; } } $sexValuesSelect = []; $sexValuesSelect[''] = 'Selecteza sex-ul'; if($sexValues) { foreach ($sexValues as $sexValue){ $sexValuesSelect[$sexValue] = $sexValue; } } $tariSelect = []; $tariSelect[''] = 'Selecteaza tara'; if($tari) { foreach ($tari as $tara) { $tariSelect[$tara['id']] = $tara['name']; } } $scoliDeProvenientaSelect = []; $scoliDeProvenientaSelect[''] = 'Selecteaza scoala de provenienta'; if($scoliDeProvenienta) { foreach ($scoliDeProvenienta as $item) { $scoliDeProvenientaSelect[$item['id']] = $item['nume']; } } $mediiSelect = []; $mediiSelect[''] = 'Selecteaza mediul'; if($medii) { foreach ($medii as $mediu) { $mediiSelect[$mediu] = $mediu; } } $yesnoSelect = []; $yesnoSelect[''] = 'Alege o optiune'; if($yesno) { foreach ($yesno as $item) { $yesnoSelect[$item] = $item; } } $disciplineSelect = []; $disciplineSelect[''] = 'Selecteaza una sau mai multe discipline'; if ($discipline) { foreach ($discipline as $disciplina) { $disciplineSelect[$disciplina['id']] = $disciplina['disciplina']; } } $judetNastereSelected = []; $judetNastereSelected[''] = 'Selecteaza judetul'; if($data->judet_nastere) { $judetNastere = States::where('id', '=', $data->judet_nastere)->get(['id','name'])->first(); if($judetNastere) { $judetNastereSelected[$judetNastere['id']] = $judetNastere['name']; } } $localitateNastereSelected = []; $localitateNastereSelected[''] = 'Selecteaza localitate'; if($data->localitate_nastere) { $localitateNastere = Cities::where('id','=',$data->localitate_nastere)->get(['id','name'])->first(); if($localitateNastere) { $localitateNastereSelected[$localitateNastere['id']] = $localitateNastere['name']; } } $selectedScoala = ''; $selectedClase = []; $selectedClase[''] = 'Selecteaza clasa'; if($data->clasa) { $selectedScoalaQuery = \App\Models\Clase::where('id', '=',$data->clasa)->get(['scoala','id','nume'])->first(); if($selectedScoalaQuery) { $selectedScoala = $selectedScoalaQuery['scoala']; $selectedClase[$selectedScoalaQuery['id']] = $selectedScoalaQuery['nume']; } } $judetDomiciliuSelected = []; $judetDomiciliuSelected[''] = 'Selecteaza judetul'; if($data->jud_domiciliu) { $judetDomiciliu = States::where('id', '=', $data->jud_domiciliu)->get(['id','name'])->first(); if($judetDomiciliu) { $judetDomiciliuSelected[$judetDomiciliu['id']] = $judetDomiciliu['name']; } } $localitateDomiciliuSelected = []; $localitateDomiciliuSelected[''] = 'Selecteaza localitate'; if($data->localitate_domiciliu) { $localitateDomiciliu = Cities::where('id','=',$data->localitate_domiciliu)->get(['id','name'])->first(); if($localitateDomiciliu) { $localitateDomiciliuSelected[$localitateDomiciliu['id']] = $localitateDomiciliu['name']; } } $judetDomiciliuParinteSelected = []; $judetDomiciliuParinteSelected[''] = 'Selecteaza judetul'; if($data->judet_domiciliu_parinte) { $judetDomiciliuParinte = States::where('id', '=', $data->judet_domiciliu_parinte)->get(['id','name'])->first(); if($judetDomiciliuParinte) { $judetDomiciliuParinteSelected[$judetDomiciliuParinte['id']] = $judetDomiciliuParinte['name']; } } $localitateDomiciliuParinteSelected = []; $localitateDomiciliuParinteSelected[''] = 'Selecteaza localitate'; if($data->localitate_domiciliu_parinte) { $localitateDomiciliuParinte = Cities::where('id','=',$data->localitate_domiciliu_parinte)->get(['id','name'])->first(); if($localitateDomiciliuParinte) { $localitateDomiciliuParinteSelected[$localitateDomiciliuParinte['id']] = $localitateDomiciliuParinte['name']; } } if($data->clasa) { $clasa = \App\Models\Clase::where('id','=',$data->clasa)->first(); if($clasa->getScoala) { $responsabil_isj = $clasa->getScoala->responsabil_isj; $asistent_social = $clasa->getScoala->asistent_social; } else { $responsabil_isj = 0; $asistent_social = 0; } } else { $responsabil_isj = 0; $asistent_social = 0; } $form = [ 'action' => $this->appUrl.'/admin/elevi/update/'.$id, 'method' => 'POST', 'enctype' => 'multipart/form-data', 'display' => 'table' ]; $fields = [ [ 'id' => 'an_scolar', 'label' => 'An scolar *', 'name' => 'an_scolar', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $aniScolariSelect, 'defaultOption' => $data->an_scolar ], [ 'id' => 'cnp', 'name' => 'cnp', 'label' => 'Cod Numeric Personal (CNP) *', 'placeholder' => 'Introdu codul numeric personal', 'type' => 'text', 'required' => 'required', 'class' => 'form-control form-control-sm', 'value' => $data->cnp ], [ 'id' => 'sex', 'name' => 'sex', 'label' => 'Sex *', 'placeholder' => 'Selecteaza sex-ul', 'type' => 'select', 'class' => 'form-control form-control-sm', 'options' => $sexValuesSelect, 'required' => 'required', 'defaultOption' => $data->sex ], [ 'id' => 'data_nastere', 'name' => 'data_nastere', 'label' => 'Data nasterii (ZZ/LL/AAAA) *', 'placeholder' => 'Click pentru a seta data nasterii', 'class' => 'pick-date form-control form-control-sm', 'required' => 'required', 'value' => $data->data_nastere ], [ 'id' => 'nume', 'name' => 'nume', 'label' => 'Numele *', 'placeholder' => 'ex: Popescu', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->nume ], [ 'id' => 'initiala_tatalui', 'name' => 'initiala_tatalui', 'label' => 'Initiala tatalui *', 'placeholder' => 'ex: F', 'class' => 'form-control form-control-sm', 'required' => 'required', 'maxlength' => '1', 'value' => $data->initiala_tatalui ], [ 'id' => 'prenume', 'name' => 'prenume', 'label' => 'Prenumele *', 'placeholder' => 'ex: Constantin', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume ], [ 'id' => 'prenume_tata', 'name' => 'prenume_tata', 'label' => 'Prenumele Tatalui *', 'placeholder' => 'ex: Adrian', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume_tata ], [ 'id' => 'prenume_mama', 'name' => 'prenume_mama', 'label' => 'Prenumele Mamei *', 'placeholder' => 'ex: Maria', 'class' => 'form-control form-control-sm', 'required' => 'required', 'value' => $data->prenume_mama ], [ 'id' => 'tara', 'label' => 'Tara nasterii *', 'name' => 'tara_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_nastere ], [ 'label' => 'Judet nastere *', 'id' => 'judet', 'name' => 'judet_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'options' => $judetNastereSelected, 'defaultOption' => $data->judet_nastere ], [ 'label' => 'Localitate nastere*', 'id' => 'localitate', 'name' => 'localitate_nastere', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $localitateNastereSelected, 'defaultOption' => $data->localitate_nastere ], [ 'id' => 'nationalitate', 'label' => 'Nationalitate *', 'name' => 'nationalitate', 'class' => 'form-control form-control-sm', 'required' => 'required', 'placeholder' => 'ex: Roman, Spaniol', 'value' => $data->nationalitate ], [ 'id' => 'scoala_de_provenienta', 'label' => 'Scoala de provenienta', 'name' => 'scoala_de_provenienta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'options' => $scoliDeProvenientaSelect, 'defaultOption' => $data->scoala_de_provenienta ], [ 'id' => 'scoala', 'label' => 'Scoala actuala', 'type' => 'select', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/clase', 'options' => $scoliSelect, 'defaultOption' => $selectedScoala ], [ 'id' => 'clasa', 'label' => 'Clasa *', 'type' => 'select', 'name' => 'clasa', 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'options' => $selectedClase, 'defaultOption' => $data->clasa ], [ 'id' => 'limba1', 'label' => 'Limba 1 *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba1', 'required' => 'required', 'placeholder' => 'ex: Romana', 'value' => $data->limba1 ], [ 'id' => 'limba2', 'label' => 'Limba 2 ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'limba2', 'placeholder' => 'ex: Spaniola', 'value' => $data->limba2 ], [ 'id' => 'asistent_social', 'label' => 'Asistent social', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'asistent_social', 'placeholder' => 'ex: Popescu Laura', 'value' => $data->asistent_social ? $asistent_social : 0 ], [ 'id' => 'nr_matricol', 'label' => 'Numar matricol *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'nr_matricol', 'required' => 'required', 'placeholder' => 'ex: CJ-122', 'value' => $data->nr_matricol ], [ 'id' => 'vol', 'label' => 'Volum *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'vol', 'required' => 'required', 'placeholder' => 'ex: 1', 'value' => $data->vol ], [ 'id' => 'pag', 'label' => 'Pagina *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'pag', 'required' => 'required', 'placeholder' => 'ex: 2', 'value' => $data->pag ], [ 'id' => 'responsabil_isj', 'label' => 'Responsabil ISJ', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'responsabil_isj', 'placeholder' => 'ex: Aurelian Temisan', 'value' => $data->responsabil_isj ? $responsabil_isj : 0 ], [ 'id' => 'tara_domiciliu', 'label' => 'Tara domiciliu *', 'name' => 'tara_domiciliu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_domiciliu ], [ 'label' => 'Judet domiciliu *', 'id' => 'judet_domiciliu', 'name' => 'jud_domiciliu', 'type' => 'select', 'options' => $judetDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->jud_domiciliu ], [ 'label' => 'Localitate domiciliu *', 'id' => 'localitate_domiciliu', 'name' => 'localitate_domiciliu', 'type' => 'select', 'options' => $localitateDomiciliuSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->localitate_domiciliu ], [ 'id' => 'adresa_domiciliu', 'label' => 'Adresa de domiciliu *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'adresa_domiciliu', 'required' => 'required', 'placeholder' => 'ex: Strada nr 1 , Plopeni Ell', 'value' => $data->adresa_domiciliu ], [ 'id' => 'mediu', 'label' => 'Mediul (Rural/Urban) *', 'name' => 'mediu', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => $data->mediu ], [ 'id' => 'telefon_elev', 'label' => 'Telefon elev *', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'telefon_elev', 'required' => 'required', 'placeholder' => 'ex: 0745111554', 'value' => $data->telefon_elev ], [ 'id' => 'email_elev', 'label' => 'Email elev', 'type' => 'text', 'class' => 'form-control form-control-sm', 'name' => 'email_elev', 'placeholder' => 'ex: elevescu@popescunescu.com', 'value' => $data->email_elev ], [ 'id' => 'plasament', 'label' => 'Plasament *', 'name' => 'plasament', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->plasament ], [ 'id' => 'incris_prima_data', 'label' => 'Inscris prima data *', 'name' => 'incris_prima_data', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->incris_prima_data ], [ 'id' => 'din_promotia_curenta', 'label' => 'Din Promotia curenta *', 'name' => 'din_promotia_curenta', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->din_promotia_curenta ], [ 'id' => 'rrom', 'label' => 'Rrom *', 'name' => 'rrom', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $yesnoSelect, 'defaultOption' => $data->rrom ], [ 'id' => 'fotografie', 'label' => 'Fotografie', 'name' => 'fotografie', 'type' => 'file', 'class' => 'form-control form-control-sm btn btn-danger btn-sm', 'accept' => 'image/*' ], [ 'id' => 'tara_domiciliu_parinte', 'label' => 'Tara domiciliu parinte*', 'name' => 'tara_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $tariSelect, 'data-live-search' => 'true', 'data-post-endpoint' => $this->appUrl . '/ajax/states', 'defaultOption' => $data->tara_domiciliu_parinte ], [ 'label' => 'Judet domiciliu parinte *', 'id' => 'judet_domiciliu_parinte', 'name' => 'judet_domiciliu_parinte', 'type' => 'select', 'options' => $judetDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-post-endpoint' => $this->appUrl . '/ajax/cities', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->judet_domiciliu_parinte ], [ 'label' => 'Localitate domiciliu parinte *', 'id' => 'localitate_domiciliu_parinte', 'name' => 'localitate_domiciliu_parinte', 'type' => 'select', 'options' => $localitateDomiciliuParinteSelected, 'class' => 'form-control form-control-sm', 'data-live-search' => 'true', 'required' => 'required', 'defaultOption' => $data->localitate_domiciliu_parinte ], [ 'id' => 'adresa_domiciliu_parinte', 'name' => 'adresa_domiciliu_parinte', 'required' => 'required', 'label' => 'Adresa de domiciliu parinte *', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->adresa_domiciliu_parinte ], [ 'id' => 'mediu_domiciliu_parinte', 'label' => 'Mediu domiciliu parinte (Rural/Urban) *', 'name' => 'mediu_domiciliu_parinte', 'type' => 'select', 'class' => 'form-control form-control-sm', 'required' => 'required', 'options' => $mediiSelect, 'defaultOption' => $data->mediu_domiciliu_parinte ], [ 'id' => 'telefon_parinte', 'name' => 'telefon_parinte', 'required' => 'required', 'label' => 'Telefon parinte *', 'placeholder' => 'ex: 0744555441', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->telefon_parinte ], [ 'id' => 'email_parinte', 'name' => 'email_parinte', 'label' => 'Adresa de email parinte', 'placeholder' => 'ex: Undeva, pe langa casa 123', 'type' => 'text', 'class' => 'form-control form-control-sm', 'value' => $data->email_parinte ], [ 'id' => 'discipline', 'label' => 'Discipline', 'name' => 'discipline[]', 'type' => 'select', 'class' => 'form-control form-control-sm', 'multiple' => 'multiple', 'options' => $disciplineSelect, 'defaultOption' => $data->discipline ? explode(',',$data->discipline) : 'null' ], [ 'id' => 'observatii', 'label' => 'Observatii', 'name' => 'observatii', 'type' => 'textarea', 'class' => 'form-control form-control-sm', 'placeholder' => 'Introdu observatii', 'style' => 'width: 100%; min-height: 145px; resize: none;', 'text' => $data->observatii ], [ 'id' => 'update', 'value' => 'Modifica', 'name' => 'update', 'type' => 'submit', 'class' => 'btn btn-primary btn-sm' ] ]; View::render('admin/edit_elevi', [ 'pageTitle' => 'Elevi / Editeaza elev', 'pageHeader' => 'Editeaza elev', 'form' => ArrayForm::build($form,$fields), 'data' => $data, 'id' => $id ]); } else { Request::redirect($this->appUrl.'/admin/elevi'); } } /** * @param $request */ public function update($request) { $id = (int) $request; if(\App\Models\Elevi::where('id','=',$id)->count() == 1) { $error = null; $discipline = 0; if(Request::getArgument('discipline','POST')) { $discipline = implode(',',Request::getArgument('discipline','POST')); } $data = Request::post(); unset($data['update']); unset($data['discipline']); $data = Misc::applyDefaultValues($data); $data['discipline'] = $discipline; $responsabil_isj = 0; $asistent_social = 0; if($data['clasa']) { $clasa = \App\Models\Clase::where('id','=',$data['clasa'])->first(); if($clasa->getScoala) { $responsabil_isj = $clasa->getScoala->responsabil_isj; $asistent_social = $clasa->getScoala->asistent_social; } } if($data['asistent_social'] == 0 or empty($data['asistent_social'])) { $data['asistent_social'] = $asistent_social; } if($data['responsabil_isj'] == 0 or empty($data['asistent_social'])) { $data['responsabil_isj'] = $responsabil_isj; } $fileId = 0; /** * Upload fotografie */ if(Request::hasFile('fotografie')) { if(Request::getFile('fotografie')) { $file = Request::getFile('fotografie'); $upload = Request::uploadFile('fotografie',time()); $fileId = 0; if($upload['status']) { if($upload['data']) { foreach ($upload['data'] as $datum) { try { $file = Files::create ( [ 'file_name' => $datum['new_name'], 'location' => $datum['full_path_new_name'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ] ); $fileId = $file->id; SystemLogger::log('files','Uploaded file with details: '. ArrayUtility::arrayToList($datum)); } catch (\Exception $exception) { SystemLogger::log('files','Could not upload file with details: '. ArrayUtility::arrayToList($datum) .' <br/> Error:' .$exception->getMessage()); } } } } else { $error = ArrayUtility::arrayToList($upload['errors']); SystemLogger::log('files','There was an error uploading the file. Error: '.ArrayUtility::arrayToList($upload['errors'])); } } } /** * Add elev entry */ $rules = [ 'an_scolar' => ['required'], 'cnp' => ['required' , 'min:13' ,'max: 16'], 'sex' => ['required'], 'data_nastere' => ['required'], 'nume' => ['required', 'min: 3', 'max: 40'], 'initiala_tatalui' => ['required', 'min: 1', 'max: 1'], 'prenume' => ['required', 'min: 3', 'max: 40'], 'prenume_tata' => ['required', 'min: 3', 'max: 40'], 'prenume_mama' => ['required' , 'min: 3', 'max: 40'], 'tara_nastere' => ['required'], 'judet_nastere' => ['required'], 'localitate_nastere' => ['required'], 'nationalitate' => ['required', 'min: 3', 'max: 20'], 'clasa' => ['required'], 'limba1' => ['required' ,'min: 3' , 'max: 10'], 'limba2' => ['max: 10'], 'asistent_social' => ['max: 40'], 'nr_matricol' => ['required'], 'vol' => ['required'], 'pag' => ['required'], 'tara_domiciliu' => ['required'], 'jud_domiciliu' => ['required'], 'localitate_domiciliu' => ['required'], 'adresa_domiciliu' => ['required', 'min: 3'], 'mediu' => ['required'], 'telefon_elev' => ['required', 'min: 10', 'max: 15'], 'email_elev' => ['max: 60'], 'plasament' => ['required'], 'incris_prima_data' => ['required'], 'din_promotia_curenta' => ['required'], 'rrom' => ['required'], 'tara_domiciliu_parinte' => ['required'], 'judet_domiciliu_parinte' => ['required'], 'localitate_domiciliu_parinte' => ['required'], 'adresa_domiciliu_parinte' => ['required'], 'mediu_domiciliu_parinte' => ['required'], 'telefon_parinte' => ['required', 'min:10', 'max: 15'], 'email_parinte' => ['max: 60'], 'observatii' => ['max: 500'] ]; $errors = [ 'an_scolar.required' => 'Anul scolar trebuie selectat', 'cnp.required' => 'CPN-ul trebuie completat', 'cnp.min' => 'CNP-ul trebuie sa contina minim :min caractere', 'cnp.max' => 'CNP-ul trebuie sa contina maxim :max caractere', 'data_nastere.required' => 'Data nasterii trebuie completata', 'nume.required' => 'Numele trebuie completat', 'nume.min' => 'Numele trebuie sa contina macar :min caractere', 'nume.max' => 'Numele trebuie sa contina maxim :min caractere', 'initiala_tatalui.required' => 'Initiala tatalui trebuie completata', 'initiala_tatalui.min' => 'Initiala tatalui nu trebuie sa depaseasca :min caractere', 'initiala_tatalui.max' => 'Initiala tatalui nu trebuie sa depaseasca :max caractere', 'prenume.required' => 'Prenumele trebuie completat', 'prenume.min' => 'Prenumele trebuie sa contina macar :min caractere', 'prenume.max' => 'Prenumele trebuie sa contina maxim :max caractere', 'prenume_tata.required' => 'Prenumele tatalui trebuie sa fie completat', 'prenume_tata.min' => 'Prenumele tatalui trebuie sa contina macar :min caractere', 'prenume_tata.max' => 'Prenumele tatalui trebuie sa nu depaseasca :max caractere', 'prenume_mama.required' => 'Prenumele mamei trebuie sa fie completat', 'prenume_mama.min' => 'Prenumele mamei trebuie sa contina macar :min caractere', 'prenume_mama.max' => 'Prenumele mamei nu trebuie sa depaseasca :max caractere', 'tara_nastere.required' => 'Tara nasterii trebuie selectata', 'judet_nastere.required' => 'Judelul nasterii trebuie selectat', 'localitate_nastere.required' => 'Localitatea nasterii trebuie selectata', 'nationalitate.required' => 'Nationalitatea trebuie completata', 'nationalitate.min' => 'Nationalitatea trebuie sa contina macar :min caractere', 'nationalitate.max' => 'Nationalitatea nu trebuie sa depaseasca :max caractere', 'clasa.required' => 'Clasa curenta trebuie selectata', 'limba1.required' => 'Limba 1 trebuie completata', 'limba1.min' => 'Limba 1 trebuie sa contina macar :min caractere', 'limba1.max' => 'Limba 1 nu trebuie sa depaseasca :max caractere', 'limba2.min' => 'Limba 2 trebuie sa contina macar :min caractere', 'limba2.max' => 'Limba 2 nu trebuie sa depaseasca :max caractere', 'asistent_social.min' => 'Numele asistentului social trebuie sa contina macar :min caractere', 'asistent_social.max' => 'Numele asistentului social nu trebuie sa depaseasca :max caractere', 'nr_matricol.required' => 'Numarul matricol trebuie completat', 'vol.required' => 'Volumul trebuie completat', 'pag.required' => 'Pagina trebuie completata', 'tara_domiciliu.required' => 'Tara de domiciliu trebuie selectata', 'jud_domiciliu.required' => 'Judetul de domiciliu trebuie selectata', 'localitate_domiciliu.required' => 'Localitatea de domiciliu trebuie selectata', 'adresa_domiciliu.required' => 'Adresa de domiciliu trebuie completata', 'adresa_domiciliu.min' => 'Adresa de domiciliu trebuie sa contina macar :min caractere', 'mediu.required' => 'Mediul trebuie selectat', 'telefon_elev.required' => 'Telefonul elevului trebuie completat', 'telefon_elev.min' => 'Telefonul elevului trebuie sa contina macar :min caractere', 'telefon_elev.max' => 'Telefonul elevului nu trebuie sa depaseasca :max caractere', 'email_elev.min' => 'Email-ul elevului trebuie sa contina macar :min caractere', 'email_elev.max' => 'Email-ul elevului nu trebuie sa depaseasca :max caractere', 'plasament.required' => 'Plasamentul trebuie selectat', 'incris_prima_data.required' => 'Trebuie selectat daca elevul a fost inscris prima data', 'din_promotia_curenta.required' => 'Trebuie selectat daca elevul face parte din promotia curenta', 'rrom.required' => 'Trebuie selectat daca elevul este sau nu rrom', 'tara_domiciliu_parinte.required' => 'Tara de domiciliu a parintilor trebuie selectata', 'judet_domiciliu_parinte.required' => 'Judetul de domiciliu al parintilor trebuie selectat', 'localitate_domiciliu_parinte.required' => 'Localitatea de domiciliu a parintilor trebuie selectata', 'adresa_domiciliu_parinte.required' => 'Adresa de domiciliu a parintilor trebuie completata', 'mediu_domiciliu_parinte.required' => 'Mediul domiciliului parintilor trebuie selectat', 'telefon_parinte.required' => 'Telefonul parintilor trebuie completat', 'telefon_parinte.min' => 'Telefonul parintilor trebuie sa contina macar :min caractere', 'telefon_parinte.max' => 'Telefonul parintilor nu trebuie sa depaseasca :max caractere', 'email_parinte.min' => 'Adresa de email a parintilor trebuie sa contina macar :min caractere', 'email_parinte.max' => 'Adresa de email a parintilor nu trebuie sa depaseasca :max caractere', 'observatii.max' => 'Campul de observatii trebuie sa contina maxim :max caractere' ]; $validate = Validation::validate($rules,$errors); if($validate['status']) { /** * Begin updating data */ try{ $update = \App\Models\Elevi::where('id','=',$id)->update($data); SystemLogger::log('elevi','A student with id '.$id.' was updated within the system with data :'. ArrayUtility::arrayToList($data)); if($fileId != 0) { \App\Models\Elevi::where('id','=',$id)->update(['fotografie' => $fileId]); } } catch (\Exception $e) { $error = $e->getMessage(); } } else { $error = Validation::renderErrors($validate['error']); } View::render('admin/update_elevi', [ 'pageTitle' => 'Elevi / Editeaza Elevi', 'pageHeader' => 'Editeaza elev', 'error' => $error, 'id' => $id ]); } else { Request::redirect($this->appUrl.'/admin/elevi'); } } /** * @param $request */ public function promote($request) { $id = (int) $request; $error = null; if(\App\Models\Elevi::where('id','=',$id)->count() == 1) { if(EleviRepetenti::where('elev','=',$id)->first()) { try { EleviRepetenti::where('elev',$id)->delete(); SystemLogger::log('elevi_repetenti','An entity with id:'.$id.' was removed from elevi_repetenti. Reason: Entity promoted!'); } catch (\Exception $e) { $error = $e->getMessage(); } } else { $error = 'Nu s-au gasit elevi cu id-ul '.$id.' in sectiunea de elevi repetenti'; } View::render('admin/promoveaza_elevi', [ 'pageTitle' => 'Elevi / Promoveaza elev', 'pageHeader' => 'Promoveaza elev', 'error' => $error, 'id' => $id ]); } else { Request::redirect($this->appUrl.'/admin/elevi'); } } /** * @param $request */ public function repetent($request) { $id = (int) $request; $error = null; if(\App\Models\Elevi::where('id','=',$id)->count() == 1) { $an = \App\Models\Elevi::where('id','=',$id)->get(['an_scolar'])->first(); if(EleviRepetenti::where('elev','=',$id)->count() != 1) { try { EleviRepetenti::create( [ 'elev' => $id, 'an' => $an->an_scolar, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ] ); SystemLogger::log('elevi_repetenti', 'An entity was added to elevi_repetenti for id : '. $id); } catch (\Exception $e) { $error = $e->getMessage(); SystemLogger::log('elevi_repetenti', 'Could not add entity in elevi_repetenti for id : '. $id. ' Error: '.$e->getMessage()); } } else { $error = 'Exista deja o intrare in elevi repetenti pentru id-ul specificat!'; } View::render('admin/repetent_elevi', [ 'pageTitle' => 'Elevi / Repetent', 'pageHeader' => 'Elev repetent', 'error' => $error, 'id' => $id ]); } else { Request::redirect($this->appUrl.'/admin/elevi'); } } } here is ajax.php <?php namespace App\Controllers; use Core\Controller; use Core\Request; use Core\IlluminateDb; class Ajax extends Controller { /** * @return false | string */ public function states() { $country_id = Request::hasArgument('country_id', 'POST') ? Request::getArgument('country_id', 'POST') : null; $states = IlluminateDb::table('states')->where('country_id', '=', $country_id)->get(['id', 'name'])->toJson(); echo $states; } /** * @return false|string */ public function cities() { $state_id = Request::hasArgument('state_id', 'POST') ? Request::getArgument('state_id', 'POST') : null; $cities = IlluminateDb::table('cities')->where('state_id', '=', $state_id)->get(['id', 'name'])->toJson(); echo $cities; } public function sate() { $cities_id = Request::hasArgument('cities_id', 'POST') ? Request::getArgument('cities_id', 'POST') : null; $sate = IlluminateDb::table('sate')->where('cities_id', '=', $cities_id)->get(['id', 'name'])->toJson(); echo $sate; } /** * @return string */ public function clase() { $scoala = Request::hasArgument('scoala_id', 'POST') ? Request::getArgument('scoala_id', 'POST') : null; $scoli = IlluminateDb::table('clase')->where('scoala','=',$scoala)->get(['id','nume'])->toJson(); return $scoli; } /** * @return string */ public function elevi() { $clasa = Request::hasArgument('clasa','POST') ? Request::getArgument('clasa','POST'):null; $elevi = IlluminateDb::table('elevi')->where('clasa','=',$clasa)->get(['id','cnp','nume','prenume','nr_matricol'])->toJson(); return $elevi; } } where sates code is here ... this is for dependend lists... i guess <?php namespace App\Controllers; use Core\Controller; use Core\Request; use Core\IlluminateDb; class Ajax extends Controller { public function sate() { $cities_id = Request::hasArgument('cities_id', 'POST') ? Request::getArgument('cities_id', 'POST') : null; $sate = IlluminateDb::table('sate')->where('cities_id', '=', $cities_id)->get(['id', 'name'])->toJson(); echo $sate; } } here is the code from models where table from data base its intiliazed <?php namespace App\Models; use Core\Model; class Sate extends Model { protected $table = "sate"; protected $fillable = ["name", "cities_id", "state_code", "country_id", "country_code", "latitude", "longitude", "created_at", "updated_at", "flag", "wikiDataId"]; /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function city() { return $this->hasOne(Cities::class, 'id', 'cities_id'); } /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function country() { return $this->hasOne(Countries::class, 'id', 'country_id'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/314997-dependent-list-by-another-list/#findComment-1598023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.