/**
  * Authenticates a dummy user.
  * @return boolean always true.
  */
 public function authenticate()
 {
     $student = Student::model()->findByAttributes(array('username' => $this->username));
     if ($student === null) {
         $student = new Student();
         $faculty = Faculty::model()->findByPk(1);
         if ($faculty === null) {
             $faculty = new Faculty();
             $faculty->id = 1;
             $faculty->name = 'Dummy Faculty';
             $faculty->save(false);
         }
         $student->username = $this->username;
         $student->name = $this->name;
         $student->is_admin = $this->isAdmin;
         $student->faculty_id = $faculty->id;
         $student->photo = Yii::app()->params['defaultProfilePhoto'];
     }
     $student->last_login_timestamp = date('Y-m-d H:i:s');
     $student->save();
     $this->id = $student->id;
     $this->name = $student->name;
     $this->setState('isAdmin', $student->is_admin);
     $this->setState('profilePhoto', $student->photo);
     return true;
 }
 function add()
 {
     $model = new Student();
     // var_dump($_POST);exit;
     if (isset($_POST['student']) and $_POST['student']['first_name'] != '' and $_POST['student']['last_name'] != '' and $_POST['student']['f_number'] != '') {
         $student = $_POST['student'];
         $first_name = $student['first_name'];
         $last_name = $student['last_name'];
         $f_number = $student['f_number'];
         $group = $student['group'];
         $flow = $student['flow'];
         $alumni = $student['alumni'];
         $subject = $student['subject'];
         $model->first_name = $first_name;
         $model->last_name = $last_name;
         $model->f_number = $f_number;
         $model->group = $group;
         $model->flow = $flow;
         $model->alumni = $alumni;
         $model->subject = $subject;
         if ($model->save()) {
             header('Location: ' . 'index.php?url=students/index');
             die;
         }
     } else {
         $this->set("title", "Empty field! Add failed!");
     }
 }
Exemple #3
0
 public function register()
 {
     $id = Input::get('stu_id');
     $name = Input::get('stu_name');
     $nick = Input::get('stu_nick');
     $email = Input::get('stu_email');
     if (Student::where("account", "=", $id)->count() > 0) {
         $student = Student::where("account", "=", $id)->first();
         $student->name = $name;
         $student->nick = str_replace("root", "**", str_replace("admin", "*", str_replace("管理員", "***", $nick)));
         $student->email = $email;
         $student->account = $id;
         $auth = $student->auth;
         $student->save();
         return $auth;
     } else {
         $student = new Student();
         $student->name = $name;
         $student->nick = str_replace("root", "**", str_replace("admin", "*", str_replace("管理員", "***", $nick)));
         $student->email = $email;
         $student->account = $id;
         $auth = str_random(20);
         while (true) {
             if (Student::where("auth", "=", $auth)->count() == 0) {
                 $student->auth = $auth;
                 break;
             } else {
                 $auth = str_random(20);
             }
         }
         $student->save();
         return $auth;
     }
 }
Exemple #4
0
 public function agregar()
 {
     $data = array();
     if ($_POST) {
         $this->load->helper('date');
         $this->load->library('Utils');
         $insert = $_POST;
         $insert['fecha_nacimiento'] = $this->utils->fecha_formato('%Y-%m-%d', $insert['fecha_nacimiento']);
         $insert['fecha_inscripcion'] = $this->utils->fecha_formato('%Y-%m-%d', $insert['fecha_inscripcion']);
         $tutor = new Student(elements(array('city_id', 'nombre', 'apellido', 'fecha_nacimiento', 'sexo', 'tipo_documento', 'nro_documento', 'domicilio', 'tenencia', 'nacionalidad', 'grupo_sanguineo', 'telefono', 'celular', 'obs_medicas', 'observaciones', 'colegio_procedencia', 'fecha_inscripcion'), $insert));
         if ($tutor->is_valid()) {
             $tutor->save();
             $this->session->set_flashdata('msg', '<div class="success">El tutor se guardó correctamente.</div>');
             redirect('tutores/agregar');
         } else {
             $data['errors'] = $tutor->errors;
         }
     }
     $data['paises'] = Country::all();
     $data['provincias'] = State::all();
     $data['ciudades'] = City::all();
     $data['titulo'] = "Agregar tutor";
     $data['action'] = "tutores/agregar";
     $this->template->write_view('content', 'tutores/agregar', $data);
     $this->template->render();
 }
 public function actionCreate()
 {
     $model = new User();
     $model->scenario = 'create';
     $this->performAjaxValidation($model);
     $student = new Student();
     $valid = true;
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->setRole = $_POST['User']['setRole'];
         $valid = $valid && $model->validate();
     }
     if (isset($_POST['Student'])) {
         $student->attributes = $_POST['Student'];
         if ($_POST['User']['setRole'] == 3) {
             $valid = $valid && $student->validate();
         }
     }
     if (isset($_POST['User']) && $valid) {
         $model->save();
         $student->id_user = $model->id_user;
         if (isset($_POST['Student']) && $_POST['User']['setRole'] == 3) {
             $student->save();
         }
         $this->redirect(array('allusers'));
     }
     $this->render('create', array('model' => $model, 'student' => $student));
 }
 public function importData()
 {
     $siswas = Siswa::all();
     foreach ($siswas as $siswa) {
         ini_set('max_execution_time', 300);
         $student = new Student();
         $student->name = $siswa->FullName;
         if ($siswa->Sex == 'MALE') {
             $student->sex = 'L';
             $student->photo = 'boy.png';
         } else {
             $student->sex = 'P';
             $student->photo = 'girl.png';
         }
         $student->birthplace = $siswa->BirthPlace;
         $student->birthdate = $siswa->BirthDate;
         $student->religion = $siswa->Religion;
         $student->address = $siswa->FullAddress;
         $student->contact = $siswa->CellPhone;
         $student->father_name = $siswa->FatherName;
         $student->father_occupation = $siswa->FatherOccupation;
         $student->father_address = $siswa->FatherAddress;
         $student->father_contact = $siswa->FatherContact;
         $student->mother_name = $siswa->MotherName;
         $student->mother_occupation = $siswa->MotherOccupation;
         $student->mother_address = $siswa->MotherAddress;
         $student->mother_contact = $siswa->MotherContact;
         $student->save();
     }
     Session::flash('message', 'Sukses mengimport Data Siswa');
     return Redirect::to('/');
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $names = array('Martin', 'Pedro', 'Lucas', 'Agustin', 'Cristian', 'Matias', 'Tomas', 'Cludio', 'Nancy', 'Emilia', 'Alejandra', 'Barbara', 'Luciana', 'Lucia', 'Belen', 'Natalia', 'Adriana', 'Patricio', 'Diego', 'Gonzalo', 'Juan', 'Pablo');
     $last_names = array('Ramirez', 'Rodriguez', 'Cordoba', 'Brown', 'Osorio', 'Diaz', 'Ayesa', 'Ramirez', 'Perez', 'Ripoll', 'Bottini', 'Ponce', 'Casella', 'Martinez', 'Erviti', 'Rodgriguez', 'Gonzalez', 'Fernandez', 'Benitez');
     $this->createContextInstance('backend');
     for ($i = 1; $i <= 100; $i++) {
         $person = new Person();
         $person->setLastname($last_names[rand(0, 18)]);
         $person->setFirstName($names[rand(0, 21)]);
         $person->setIdentificationType(1);
         $person->setIdentificationNumber($i);
         $person->setSex(rand(1, 2));
         $person->setBirthDate('2000-06-30');
         $student = new Student();
         $student->setGlobalFileNumber($i);
         $student->setPerson($person);
         $person->save();
         $student->save();
         $this->logSection("Person created", $person->__toString());
     }
     // add your code here
 }
 public function save($data)
 {
     $student = new Student();
     $student->first_name = $data['first_name'];
     $student->last_name = $data['last_name'];
     $student->dob = $data['dob'];
     $student->irs_number = $data['irs_number'];
     $student->save();
     return $student;
 }
Exemple #9
0
 public function executeNew(sfWebRequest $request)
 {
     $programSectionId = $request->getParameter('sectionId');
     $this->sectionDetail = Doctrine_Core::getTable('ProgramSection')->findOneById($programSectionId);
     $this->forward404Unless($this->sectionDetail);
     ## New Form
     $this->studentForm = new FrontendStudentForm();
     if ($request->isMethod('POST')) {
         $this->studentForm->bind($request->getParameter('studentform'));
         if ($this->studentForm->isValid()) {
             $formData = $this->studentForm->getValues();
             $student = new Student();
             $name = $formData['name'];
             $fathersName = $formData['fathers_name'];
             $grandfathersName = $formData['grandfathers_name'];
             $motherName = $formData['mother_name'];
             $dateOfBirth = $formData['date_of_birth'];
             $sex = $formData['sex'];
             $nationality = $formData['nationality'];
             $birthLocation = $formData['birth_location'];
             $residenceCity = $formData['residence_city'];
             $residenceWoreda = $formData['residence_woreda'];
             $residenceKebele = $formData['residence_kebele'];
             $residenceHourseNumber = $formData['residence_house_number'];
             $ethnicity = $formData['ethnicity'];
             $telephone = $formData['telephone'];
             $email = $formData['email'];
             $student->setName($name);
             $student->setFathersName($fathersName);
             $student->setGrandfathersName($grandfathersName);
             $student->setMotherName($motherName);
             $student->setDateOfBirth($dateOfBirth);
             $student->setSex($sex);
             $student->setAdmissionYear(date('Y'));
             $student->setNationality($nationality);
             $student->setBirthLocation($birthLocation);
             $student->setResidenceCity($residenceCity);
             $student->setResidenceWoreda($residenceWoreda);
             $student->setResidenceKebele($residenceKebele);
             $student->setResidenceHouseNumber($residenceHourseNumber);
             $student->setEthinicity($ethnicity);
             $student->setTelephone($telephone);
             $student->setEmail($email);
             $student->save();
             $enrollment = new EnrollmentInfo();
             $enrollment->makeEnrollment(null, null, null, null, $programSectionId, sfConfig::get('app_transfer_enrollment'), $student->getId());
             $auditlog = new AuditLog();
             $auditlog->addNewLogInfo($this->getUser()->getAttribute('userId'), 'Performed Enrollment of Transfered Student');
             $this->getUser()->setFlash('notice', 'Transfer Enrollment Was Successful ');
             $this->redirect('transfer/sectiondetail/?id=' . $programSectionId);
         } else {
             $this->getUser()->setFlash('error', 'Error with Transfer Enrollment Form');
         }
     }
 }
 protected function validate()
 {
     $required = array("teacher_id" => "Teacher Id", "admission_date" => "Admission Date", "name" => "Name", "subject_id" => "Subject", "date_of_birth" => "Date of Birth", "gender" => "Gender", "mobile" => "Mobile");
     global $user;
     if ($user->checkAdmin() == true) {
         if (isset($_POST)) {
             foreach ($required as $key => $value) {
                 if (!isset($_POST[$key]) || $_POST[$key] == '' || $_POST[$key] == 'select') {
                     echo $value . ' is Required<br/>';
                     return;
                 }
             }
             if (!is_numeric($_POST['mobile'])) {
                 echo "Mobile number must be Numeric";
             } else {
                 if (isset($_POST['permanent_pincode']) && $_POST['permanent_pincode'] != '' && !is_numeric($_POST['permanent_pincode']) || isset($_POST['correspondence_pincode']) && $_POST['correspondence_pincode'] != '' && !is_numeric($_POST['correspondence_pincode'])) {
                     echo "Pincode must be Numeric";
                 } else {
                     echo 'Saving...';
                     global $objPDO;
                     require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/student_class.php';
                     require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/student_profile_class.php';
                     $teacher = new Student($objPDO);
                     $teacherProfile = new Teacher($objPDO);
                     $temp_pass = substr(md5(microtime()), 5, 10);
                     $pass = md5($temp_pass);
                     $teacher_id = $_POST['teacher_id'];
                     if ($_POST['blood_group'] == 'select') {
                         unset($_POST['blood_group']);
                     }
                     $acct_type = 'teacher';
                     $teacher->setacctType($acct_type);
                     $teacher->loadByRoll($teacher_id);
                     $teacher->setRollNo($teacher_id);
                     $teacher->setPhone($_POST['phone']);
                     $teacher->setName($_POST['name']);
                     $teacher->setEmail($_POST['email']);
                     if ($teacher->getPassword() == '' || $teacher->getPassword() == NULL) {
                         $teacher->setPassword($pass);
                     }
                     $teacher->save();
                     $id = $teacher->getID();
                     $teacherProfile->setByArray($_POST);
                     $teacherProfile->setTempPass($temp_pass);
                     $teacherProfile->setUserId($id);
                     $teacherProfile->save();
                     echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/teacher/confirm/' . $teacherProfile->getUserId() . '"/>';
                 }
             }
         }
     } else {
         header('Location:http://localhost/cloud');
     }
 }
 function test_save()
 {
     //Arrange
     $name = "Joleen";
     $enrollment = "2015-09-18";
     $test_student = new Student($name, $enrollment);
     $test_student->save();
     //Act
     $result = Student::getAll();
     //Assert
     $this->assertEquals($test_student, $result[0]);
 }
 public function actionRegister()
 {
     $model = new Student();
     if (isset($_POST['Student'])) {
         $model->attributes = $_POST['Student'];
         if ($model->save()) {
             echo '提交成功,等待管理员确认';
             die;
         }
     }
     $this->render('register', array('model' => $model));
 }
 function testSave()
 {
     //Arrange
     $student_name = "Johnny Mcfly";
     $date_enrollment = "12-12-2012";
     $test_student = new Student($student_name, $date_enrollment);
     //Act
     $test_student->save();
     //Assert
     $result = Student::getAll();
     $this->assertEquals($test_student, $result[0]);
 }
 function testSave()
 {
     //Arrange
     $student_name = "Mike Laser";
     $date_enrollment = "2014-08-15";
     $id = 3;
     $test_student = new Student($student_name, $date_enrollment, $id);
     //Act
     $test_student->save();
     //Assert
     $result = Student::getAll();
     $this->assertEquals($test_student, $result[0]);
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Student();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Student'])) {
         $model->attributes = $_POST['Student'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->student_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 function testAddStudent()
 {
     $name = "Jimmy";
     $enrollment_date = "2015";
     $test_student = new Student($name, $enrollment_date);
     $test_student->save();
     $course_name = "Real Analysis I";
     $course_number = "Math 540";
     $test_course = new Course($course_name, $course_number);
     $test_course->save();
     $test_course->addStudent($test_student);
     $this->assertEquals([$test_student], $test_course->getStudent());
 }
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Student();
     if (isset($_POST['Student'])) {
         $acl = $this->_gets->getPost('acl');
         $model->attributes = $_POST['Student'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('student_create', array('model' => $model));
 }
Exemple #18
0
 /**
  * Create random password token for student.
  * If student is exists, it will be automaticaly updated (only password token information).
  */
 public function generate_random_password_token()
 {
     $this->load->library('form_validation');
     do {
         $this->password_token = sha1(time() . '-' . $this->config->item('encryption_key') . '-' . $_SERVER['SCRIPT_FILENAME'] . '-' . rand(1000000, 9999999));
     } while (!$this->form_validation->is_unique($this->password_token, 'students.password_token'));
     if (!is_null($this->id) && is_numeric($this->id) && intval($this->id) > 0) {
         $student = new Student(intval($this->id));
         if ($student->exists()) {
             $student->password_token = $this->password_token;
             $student->save();
         }
         unset($student);
     }
 }
 public function actionStudent()
 {
     $model = new Student();
     // if the post data is set, the user submitted the form
     if ($model->load(Yii::$app->request->post())) {
         // in that case, validate the data
         if ($model->validate()) {
             // save it to the database
             $model->save();
             return;
         }
     }
     // by default, diplay the form
     return $this->render('student', ['model' => $model]);
 }
 public function actionCreate()
 {
     $model = new Student();
     if (isset($_POST['Student'])) {
         $model->setAttributes($_POST['Student']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     //
     $faker = Faker\Factory::create();
     $minimum = $this->option('minimum');
     for ($is = 1; $is <= $minimum; $is++) {
         $first_name = $faker->firstname;
         $last_name = $faker->lastname;
         $email = $faker->safeEmail;
         $password = "******";
         $usergroup = rand(1, 3);
         $subjects = self::createSubjects();
         $user = Sentry::getUserProvider()->create(array('email' => $email, 'password' => $password, 'activated' => '1', 'first_name' => $first_name, 'last_name' => $last_name, 'created_at' => self::randDate('10th January 2013', date('jS F o'))));
         // Find the group using the group id
         $adminGroup = Sentry::getGroupProvider()->findById($usergroup);
         $user->addGroup($adminGroup);
         if ($usergroup == 1) {
             $teacher = new Teacher();
             $teacher->user_id = $user->id;
             $teacher->email = $email;
             $teacher->extra = $subjects;
             $teacher->dob = self::randDate('10th January 1950', '10th January 1995');
             $teacher->created_at = self::randDate('10th January 2013', date('jS F o'));
             $teacher->save();
         }
         if ($usergroup == 2) {
             $teacher = new Teacher();
             $teacher->user_id = $user->id;
             $teacher->email = $email;
             $teacher->extra = $subjects;
             $teacher->dob = self::randDate('10th January 1950', '10th January 1995');
             $teacher->created_at = self::randDate('10th January 2013', date('jS F o'));
             $teacher->save();
         }
         if ($usergroup == 3) {
             $student = new Student();
             $student->user_id = $user->id;
             $student->email = $email;
             $student->extra = $subjects;
             $student->dob = self::randDate('10th January 1995', '10th January 2005');
             $student->created_at = self::randDate('10th January 2013', date('jS F o'));
             $student->save();
         }
     }
 }
 public function savedata()
 {
     $data = Input::all();
     if (strcmp(App::make('RegisterController')->getid($data['student_id']), "NO") == 0 || $data['student_id'] == 'xxxxxxxxxxx') {
         $last_add = Student::orderby('id', 'desc')->first();
         if ($last_add == null) {
             $group = 1;
         } else {
             if ((int) $last_add->group == 16) {
                 $group = 1;
             } else {
                 $group = $last_add->group + 1;
             }
         }
         //return $last_add->group . " " . $group;
         //return substr($data['student_id'], 7, 2) . " " .(int)substr($data['student_id'], 9, 2);
         $student = new Student();
         $student->student_id = $data['student_id'];
         $student->id_section = substr($data['student_id'], 7, 2);
         $student->id_last = (int) substr($data['student_id'], 9, 2);
         $student->nickname = $data['nickname'];
         $student->name = $data['name_th'];
         $student->surname = $data['surname_th'];
         $student->name_en = $data['name_en'];
         $student->surname_en = $data['surname_en'];
         $student->age = $data['age'];
         $student->birthday = $data['birthday'];
         $student->address = $data['address'];
         $student->email = $data['email'];
         $student->hometel = $data['hometel'];
         $student->mobile = $data['mobile'];
         $student->group = $group;
         $student->ailment = $data['ailment'];
         $student->allergies = $data['allergies'];
         $student->save();
         return View::make('webcam', array('student_id' => $data['student_id']));
         /*DB::insert('insert into student_info (`id`, `student_id`, `nickname`, `name`, `surname`, `age`, `birthday`, `address`, `email`, `hometel`, `mobile`, `ailment`, `allergies`, `pic`, `group`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array(null, $data['stdid'], $data['nickname'], $data['name'], ));
          */
     }
     $data = array('title' => "Error", 'message' => $data['student_id']);
     return $data;
     //return View::make('error');
 }
 /**
  * Creates a new student
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "student", "action" => "index"));
     }
     $student = new Student();
     $student->id = $this->request->getPost("id");
     $student->first_name = $this->request->getPost("first_name");
     $student->last_name = $this->request->getPost("last_name");
     $student->user_name = $this->request->getPost("user_name");
     $student->email = $this->request->getPost("email", "email");
     $student->password = $this->request->getPost("password");
     if (!$student->save()) {
         foreach ($student->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "student", "action" => "new"));
     }
     $this->flash->success("student was created successfully");
     return $this->dispatcher->forward(array("controller" => "student", "action" => "index"));
 }
 public function registerStudent()
 {
     if (!is_null(Input::get('g-recaptcha-response'))) {
         $recaptcha = new \ReCaptcha\ReCaptcha(Config::get('recaptcha.private_key'));
         $resp = $recaptcha->verify(Input::get('g-recaptcha-response'), Request::server('REMOTE_ADDR'));
         if ($resp->isSuccess()) {
             $user = new User();
             $user->user = trim(strtolower(Input::get('guest_email')));
             $user->password = Hash::make(Input::get('guest_password'));
             $user->rank = "student";
             $user->last_activity = null;
             try {
                 $user->save();
             } catch (MongoDuplicateKeyException $e) {
                 return Redirect::back()->withErrors(array('error' => Lang::get('register_student.email_duplicated')));
             }
             $user = User::first(['user' => $user->user]);
             $student = new Student();
             $student->_id = $user->_id;
             $student->name = ucfirst(trim(Input::get('guest_name')));
             $student->last_name = ucfirst(trim(Input::get('guest_lastname')));
             $student->id_number = trim(Input::get('guest_id'));
             $student->email = trim(strtolower(Input::get('guest_email')));
             $student->genre = strtolower(trim(Input::get('guest_genre')));
             $student->has_a_job = strtolower(trim(Input::get('guest_job')));
             $student->profile_image = null;
             $student->save();
             return Redirect::to('/')->with('message', Lang::get('register_student.register_true'));
         } else {
             $errors = $resp->getErrorCodes();
             return Redirect::back()->withErrors(array('error' => Lang::get('register_student.message_captcha') . ' [' . $errors[0] . ']'));
         }
     } else {
         return Redirect::back()->withErrors(array('error' => Lang::get('register_student.message_captcha') . ' [ 99 ]'));
     }
 }
 function test_GetAll()
 {
     $name = "Coding 101";
     $enrollment_date = '0000-00-00';
     $id = null;
     $test_course = new Course($name, $id);
     $test_course->save();
     $student_name = "Aladdin";
     $course_id = $test_course->getId();
     $test_student = new Student($student_name, $id, $enrollment_date, $course_id);
     $test_student->save();
     $student_name2 = "Jasmine";
     $id2 = null;
     $course_id2 = $test_course->getId();
     $test_student2 = new Student($student_name2, $id2, $enrollment_date, $course_id2);
     $test_student->save();
     $result = Student::getAll();
     $this->assertEquals(['test_student, $test_student2'], $result);
 }
 function testDelete()
 {
     $name = "Math";
     $date = '0000-00-00';
     $id = null;
     $test_course = new Course($name, $id);
     $test_course->save();
     $student_name = "Student1";
     $course_id = $test_course->getId();
     $test_student = new Student($student_name, $id, $date, $course_id);
     $test_student->save();
     $test_student->addCourse($test_course);
     $test_student->delete();
     $this->assertEquals([], $test_course->getStudents());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $rules = ['nclass' => 'required', 'nsection' => 'required', 'nshift' => 'required', 'nsession' => 'required'];
     $validator = \Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('/promotion')->withInput(Input::all())->withErrors($validator);
     } else {
         if (Input::get('class') == Input::get('nclass')) {
             $errorMessages = new Illuminate\Support\MessageBag();
             $errorMessages->add('validation', 'Promotion From and Promotion To class shouldn not be same!');
             return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages);
         } else {
             $promotion = Input::get('promot');
             $promotion = array_keys($promotion);
             $newrollNo = Input::get('newrollNo');
             $ids = array_keys($newrollNo);
             if (count($promotion) < 1) {
                 $errorMessages = new Illuminate\Support\MessageBag();
                 $errorMessages->add('validation', 'Select Student!');
                 return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages);
             }
             $realPromot = array();
             for ($i = 0; $i < count($promotion); $i++) {
                 $rollnumber = $this->checkRollno($promotion[$i], $ids, $newrollNo);
                 if ($rollnumber == '') {
                     $errorMessages = new Illuminate\Support\MessageBag();
                     $errorMessages->add('validation', 'New Roll number can not be empty!');
                     return Redirect::to('/promotion')->withInput(Input::all())->withErrors($errorMessages);
                 }
                 if ($rollnumber != 'No') {
                     $foo = array($promotion[$i], $rollnumber);
                     array_push($realPromot, $foo);
                 }
             }
             //get new regiNo and student info
             foreach ($realPromot as $rpromt) {
                 $studentIno = Student::select('*')->where('regiNo', $rpromt[0])->first();
                 $newStudent = new Student();
                 if (Input::get('nclass') == "cl10" || Input::get('nclass') == "cl12") {
                     $newStudent->regiNo = $rpromt[0];
                 } else {
                     $newRegNo = $this->getRegi(Input::get('nclass'), Input::get('nsession'), Input::get('nsection'));
                     $newStudent->regiNo = $newRegNo[0];
                 }
                 $newStudent->rollNo = $rpromt[1];
                 $newStudent->session = trim(Input::get('nsession'));
                 $newStudent->class = Input::get('nclass');
                 $newStudent->section = Input::get('nsection');
                 $newStudent->shift = Input::get('nshift');
                 $newStudent->group = $studentIno->group;
                 $newStudent->firstName = $studentIno->firstName;
                 $newStudent->middleName = $studentIno->middleName;
                 $newStudent->lastName = $studentIno->lastName;
                 $newStudent->gender = $studentIno->gender;
                 $newStudent->religion = $studentIno->religion;
                 $newStudent->bloodgroup = $studentIno->bloodgroup;
                 $newStudent->nationality = $studentIno->nationality;
                 $newStudent->dob = $studentIno->dob;
                 $newStudent->photo = $studentIno->photo;
                 $newStudent->extraActivity = $studentIno->extraActivity;
                 $newStudent->remarks = $studentIno->remarks;
                 $newStudent->fatherName = $studentIno->fatherName;
                 $newStudent->fatherCellNo = $studentIno->fatherCellNo;
                 $newStudent->motherName = $studentIno->motherName;
                 $newStudent->motherCellNo = $studentIno->motherCellNo;
                 $newStudent->localGuardian = $studentIno->localGuardian;
                 $newStudent->localGuardianCell = $studentIno->localGuardianCell;
                 $newStudent->presentAddress = $studentIno->presentAddress;
                 $newStudent->parmanentAddress = $studentIno->parmanentAddress;
                 $newStudent->isActive = "Yes";
                 $newStudent->save();
             }
             return Redirect::to('/promotion')->with('success', count($realPromot) . ' Students Promoted.');
         }
     }
 }
Exemple #28
0
    $course->delete();
    return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll()));
});
$app->post("/add_courses", function () use($app) {
    $course = Course::find($_POST['course_id']);
    $student = Student::find($_POST['student_id']);
    $student->addCourse($course);
    return $app['twig']->render('student.html.twig', array('student' => $student, 'students' => Student::getAll(), 'courses' => $student->getCourses(), 'all_courses' => Course::getAll()));
});
//Students
$app->get("/students", function () use($app) {
    return $app['twig']->render('students.html.twig', array('students' => Student::getAll()));
});
$app->post("/students", function () use($app) {
    $student = new Student($_POST['name'], $_POST['date']);
    $student->save();
    return $app['twig']->render('students.html.twig', array('students' => Student::getAll()));
});
$app->get("/students/{id}", function ($id) use($app) {
    $student = Student::find($id);
    return $app['twig']->render('student.html.twig', array('student' => $student, 'courses' => $student->getCourses(), 'all_courses' => Course::getAll()));
});
$app->get("/students/{id}/edit", function ($id) use($app) {
    $student = Student::find($id);
    return $app['twig']->render('student_edit.html.twig', array('student' => $student));
});
$app->patch("/students/{id}", function ($id) use($app) {
    $name = $_POST['name'];
    $student = Student::find($id);
    $student->update($name);
    return $app['twig']->render('student.html.twig', array('student' => $student, 'courses' => $student->getCourses(), 'all_courses' => Course::getAll()));
 public function actionRegister()
 {
     $arrayAuthRoleItems = Yii::app()->authManager->getAuthItems(2, Yii::app()->user->getId());
     $arrayKeys = array_keys($arrayAuthRoleItems);
     $role = strtolower($arrayKeys[0]);
     if ($role == 'admin' || $role == 'teacher') {
         $this->redirect('/');
     }
     $this->layout = 'dangkyhoc';
     $model = new Student();
     if (isset($_GET['cid']) && (int) $_GET['cid']) {
         $model->class_id = $_GET['cid'];
     }
     $db = Yii::app()->db;
     if (isset($_POST['Student']) && $_POST['Student']) {
         $model->setAttributes($_POST['Student']);
         $gclass = ClassGuitar::model()->findByPk($model->class_id);
         $sql = "SELECT * FROM {{student}} WHERE user_id =" . Yii::app()->user->id . " ORDER BY id DESC";
         $cmd = $db->createCommand($sql);
         $student = $cmd->queryRow();
         if ($student) {
             //                var_dump($studentơclass_id);
             $gclass2 = ClassGuitar::model()->findByPk($student['class_id']);
             if ($student['status'] == 'comp') {
                 //Hoàn thành
                 if ($gclass->tid <= $gclass2->tid) {
                     $training = Training::model()->findByPk($gclass2->tid);
                     Yii::app()->user->setFlash('error', 'Bạn đã hoàn thành một lớp thuộc khóa <b>' . $training->title . '</b>. Vui lòng đăng ký khóa học cao hơn.');
                 }
             } elseif ($student['status'] == 'reg') {
                 // Mới đăng ký
                 Yii::app()->user->setFlash('error', 'Bạn đã đăng ký học tại lớp <b>' . $gclass2->title . '</b>. Vui lòng hủy đơn đăng ký này trước khi đăng ký tham gia lớp học khác!');
             } else {
                 $center = Center::model()->findByPk($gclass2->cid);
                 Yii::app()->user->setFlash('error', 'Bạn đang tham gia lớp học <b>' . $gclass2->title . '</b> tại cơ sở <b>' . $center->title . '</b>!');
             }
         } else {
         }
         if (!Yii::app()->user->hasFlash('error') && $model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 Yii::app()->user->setFlash('success', 'Bạn đã đăng ký lớp học thành công. LNT sẽ sớm liên lạc lại với bạn.');
             }
         }
     } else {
         $oldStudent = Student::model()->find('user_id=' . Yii::app()->user->id);
         if ($oldStudent) {
             $model->name = $oldStudent->name;
             $model->email = $oldStudent->email;
             $model->tel = $oldStudent->tel;
             $model->birthday = $oldStudent->birthday;
         }
     }
     $this->render('register', array('model' => $model));
 }
Exemple #30
0
 private function addstudents($filename, $t_no)
 {
     PHPExcel_Settings::setCacheStorageMethod(PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip);
     $files = scandir("./upload");
     array_shift($files);
     array_shift($files);
     $manager = $this->session->get("Manager");
     $school_id = $manager["school_id"];
     $errors = array();
     $j = 0;
     $this->db->begin();
     foreach ($files as $file) {
         if (strstr($file, $filename)) {
             $objexcel = PHPExcel_IOFactory::load("./upload/" . $file);
             $sheet = $objexcel->getSheet(0);
             $i = 2;
             $highestrow = $sheet->getHighestRow();
             while ($i <= $highestrow) {
                 // 增加了检测,但是没有用
                 $username = (string) $sheet->getCell("C" . $i)->getValue();
                 if ($username == "" || $username == null) {
                     break;
                 }
                 $student = new Student();
                 $student->stu_no = (string) $sheet->getCell("A" . $i)->getValue();
                 $student->name = (string) $sheet->getCell("B" . $i)->getValue();
                 $student->username = (string) $sheet->getCell("C" . $i)->getValue();
                 $student->password = hash("sha256", $sheet->getCell("D" . $i)->getValue());
                 $sex = (string) $sheet->getCell("E" . $i)->getValue();
                 if ($sex == "male") {
                     $student->sex = 1;
                 } else {
                     if ($sex == "female") {
                         $student->sex = 0;
                     }
                 }
                 $student->college = (string) $sheet->getCell("F" . $i)->getValue();
                 $student->major = (string) $sheet->getCell("G" . $i)->getValue();
                 $student->grade = (int) $sheet->getCell("H" . $i)->getValue();
                 $student->class = (string) $sheet->getCell("I" . $i)->getValue();
                 $student->birthday = (string) $sheet->getCell("J" . $i)->getValue();
                 $nativeplace = $sheet->getCell("K" . $i)->getValue() == "城市" ? 1 : 0;
                 $student->nativeplace = $nativeplace;
                 $singleton = $sheet->getCell("L" . $i)->getValue() == "是" ? 1 : 0;
                 $student->singleton = $singleton;
                 $student->nation = $sheet->getCell("M" . $i)->getValue();
                 $student->test_id = $t_no;
                 $student->school_id = $school_id;
                 $student->status = 0;
                 try {
                     if (!$student->save()) {
                         $errors[$j] = $student->getMessages();
                         $j++;
                     }
                 } catch (PDOException $ex) {
                     $errors[$j] = $ex->getMessage();
                     $j++;
                 }
                 $i++;
             }
             $objexcel->disconnectWorksheets();
             unlink("./upload/" . $file);
         }
     }
     if (count($errors) > 0) {
         $this->db->rollback();
     } else {
         $this->db->commit();
     }
     return $errors;
 }