public function getForm($type, $action, $request, $isPost = false, $errors = array())
 {
     $promotions = Promotion::getList('SELECT * FROM session');
     $sessions = array();
     foreach ($promotions as $key => $session) {
         //$session_date_label = ucfirst(Lang::_(strtolower(date('F', strtotime($session->date_start))))).' '.date('Y', strtotime($session->date_start)).' - '.ucfirst(Lang::_(strtolower(date('F', strtotime($session->date_end))))).' '.date('Y', strtotime($session->date_end));
         $session_date_label = $session->label;
         $sessions[] = array('id' => $session->id, 'name' => $session_date_label);
     }
     $genders = array(array('id' => 1, 'name' => 'Homme'), array('id' => 0, 'name' => 'Femme'));
     $session_id = $request->get('promo', $this->_getfieldvalue('session_id', $type, $request));
     $form = new Form('form-post-' . $type, 'form-post-' . $type, $action, 'POST', 'form-horizontal', $errors, $isPost);
     $form->addField('session_id', Lang::_('Session'), 'select', $session_id, true, '', @$errors['session_id'], null, null, $sessions, $type == 'update' ? true : false);
     $form->addField('firstname', Lang::_('Firstname'), 'text', $this->_getfieldvalue('firstname', $type, $request), true, '', @$errors['firstname']);
     $form->addField('lastname', Lang::_('Lastname'), 'text', $this->_getfieldvalue('lastname', $type, $request), true, '', @$errors['lastname']);
     $form->addField('gender', Lang::_('Gender'), 'select', $this->_getfieldvalue('gender', $type, $request), true, '', @$errors['gender'], null, null, $genders);
     /*$form->addField('photo', Lang::_('Photo'), 'file', $this->_getfieldvalue('photo', $type, $request), false, '', @$errors['photo']);*/
     $form->addField('photo', Lang::_('Photo'), 'filecrop', $this->_getfieldvalue('photo', $type, $request), false, '', @$errors['photo']);
     $form->addField('date_birth', Lang::_('Date de naissance'), 'date', $this->_getfieldvalue('date_birth', $type, $request), true, '', @$errors['date_birth']);
     $form->addField('num_pe', Lang::_('Numero Pole Emploi'), 'text', $this->_getfieldvalue('num_pe', $type, $request), true, '', @$errors['num_pe']);
     $form->addField('from_city', Lang::_('From_city'), 'text', $this->_getfieldvalue('from_city', $type, $request), true, '', @$errors['from_city']);
     $form->addField('email', Lang::_('Email'), 'email', $this->_getfieldvalue('email', $type, $request), false, '', @$errors['email']);
     $form->addField('phone', Lang::_('Phone'), 'text', $this->_getfieldvalue('phone', $type, $request), false, '', @$errors['phone']);
     return $form;
 }
 public function student()
 {
     function isEmpty($value)
     {
         return strlen('' . $value) == 0;
     }
     //if ($this->user->firstname == 'fred'){
     //echo 'user->school_id &#9830; '.$this->user->school_id.'<br>';
     //echo (int)empty($this->request->get('school')).'<br>';
     //echo $this->request->get('school', 0).'<br>';
     //echo 'empty(user->school_id) &#9830; '.(int)isEmpty($this->user->school_id).'<br>';
     //}
     $school_id = !isEmpty($this->user->school_id) ? $this->user->school_id : 1;
     //if ($this->user->firstname == 'fred') echo '$school_id &#9830; '.$school_id.'<br>';
     $school_id = !empty($this->request->get('school')) ? $this->request->get('school') : $school_id;
     //if ($this->user->firstname == 'fred') echo '$school_id &#9830; '.$school_id.'<br>';
     $schools = '';
     if ($this->user->isRole('admin') or $this->user->isRole('pdt')) {
         $schools = School::getList('SELECT * FROM school ORDER BY name DESC');
     }
     $where = '';
     $where = 'AND school_id=' . $school_id;
     if ($this->user->isRole('admin')) {
         $where = 'AND school_id=' . $school_id;
     }
     if ($this->user->isRole('pdt')) {
         $where = 'AND school_id=' . $school_id;
     }
     if ($this->user->isRole('dir')) {
         //$school_id = $this->user->school_id;
         $where = 'AND school_id=' . $school_id;
     }
     if ($this->user->isRole('prof')) {
         $where = 'AND school_id=' . $school_id;
     }
     $promos = Promotion::getList('SELECT * FROM session WHERE true ' . $where . ' ORDER BY date_start DESC');
     function currentPromo_id($promos)
     {
         $now = date('Y-m-d');
         foreach ($promos as $index => $promo) {
             if ($now >= $promo->date_start and $now <= $promo->date_end) {
                 return $promo->id;
             }
         }
         if (!empty($promo[0])) {
             return $promo[0]->id;
         } else {
             return '0';
         }
     }
     $promo_id = $this->request->get('promo', 0);
     if ($promo_id == 0) {
         $promo_id = currentPromo_id($promos);
     }
     $students = Student::getList('SELECT s.*, CONCAT(s.firstname," ",s.lastname)as fullname FROM student as s, session as p WHERE p.id=s.session_id AND p.id=' . $promo_id);
     $edit_url = $this->user->canDo('student_update') ? ROOT_HTTP . 'admin/student/update' : '';
     $delete_url = $this->user->canDo('student_delete') ? ROOT_HTTP . 'admin/student/delete' : '';
     $tableStudents = new Table('data-table', 'student', $students, ['id', 'fullname', 'email'], $edit_url, $delete_url);
     //if ($this->user->firstname == 'fred') echo '$school_id &#9830; '.$school_id.'<br>';
     $vars = ['canAddStudent' => $this->user->canDo('student_create'), 'schools' => $schools, 'school_id' => $school_id, 'promos' => $promos, 'promo_id' => $promo_id, 'table' => $tableStudents->render()];
     $this->render('admin/student', $vars);
 }