Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.22 KB | None | 0 0
  1. public function addAction() {
  2.     $this->view->headScript()->appendFile( '/js/jquery.autotab.js' );
  3.     $this->view->form = new Forms_Newuser();
  4.     $this->setDefault('sitekey', $this->_session->user['sitekey_phrase']);;
  5.     $this->view->sitekey_img_path = Instacare_Sitekey::getImgPath();
  6.     $this->view->sitekeySet = true;  
  7.     $this->view->sitekey_img_path = Instacare_Sitekey::getImgPath();
  8.     if( $this->_request->isPost() ) {
  9.       if( $this->view->form->isValid( $this->_request->getParams() ) ) {
  10.         $query = Doctrine_Query::create()->from( 'Instacare_User u' )->where( "id = ?", $this->_session->user[ 'id' ] );
  11.         $user = $query->fetchOne();
  12.         if( $user ) {
  13.           $user->sitekey_id = $this->_request->getParam( 'sitekey' );
  14.           $user->sitekey_phrase = $this->_request->getParam( 'phrase' );
  15.           $user->save();
  16.           //Update user session
  17.          
  18.           $this->_session->user[ 'sitekey_id' ] = $this->_request->getParam( 'sitekey' );
  19.           $this->_session->user[ 'sitekey_phrase' ] = $this->_request->getParam( 'phrase' );
  20.           //Redirect to password authentication
  21.           //$this->_redirect( '/identity/auth/' );
  22.           if(!$this->view->sitekeySet)
  23.           {
  24.     if( $this->_request->isPost() ) {
  25.       if( $this->view->form->isValid( $this->_request->getParams() ) ) {
  26.     // @todo: add sitekey, etc. to form
  27.         $created = date( 'Y-m-d H:i:s' );
  28.         $person = new People_Person( );
  29.         $person->prefix = $this->_request->getParam( 'prefix' ) == 'None' ? NULL : $this->_request->getParam( 'prefix' );
  30.         $person->first = $this->_request->getParam( 'firstName' );
  31.         $person->last = $this->_request->getParam( 'lastName' );
  32.         $person->suffix = $this->_request->getParam( 'suffix' ) == 'None' ? NULL : $this->_request->getParam( 'suffix' );
  33.         $person->dob = $this->_request->getParam( 'dobYear' ) . "-" . $this->_request->getParam( 'dobMonth' ) . "-" . $this->_request->getParam( 'dobDay' );
  34.         $person->gender = $this->_request->getParam( 'gender' );
  35.         $person->created = $created;
  36.         $person->save();
  37.         $user = new Instacare_User( );
  38.         $user->username = $this->_request->getParam( 'email' );
  39.         $user->password = Auth_User::get_hashed_password( $this->_request->getParam( 'password' ), $created );
  40.         $user->person_id = $person->id;
  41.         $user->role_id = $this->_request->getParam( 'role' );
  42.         $user->created = $created;
  43.         $user->sitekey_id = $this->_request->getParam( 'sitekey' );
  44.         $user->sitekey_phrase = $this->_request->getParam( 'phrase' );
  45.         $user->verified = 1;
  46.         $user->save();
  47.         $location = new Locations_Location( );
  48.         $location->label = 'Current Residence';
  49.         $location->street1 = $this->_request->getParam( 'address' );
  50.         $location->city = $this->_request->getParam( 'city' );
  51.         $location->state_id = $this->_request->getParam( 'state' );
  52.         $location->zip = $this->_request->getParam( 'zip' );
  53.         $location->country_id = '1';
  54.         $location->save();
  55.         $phone = new Contacts_Phone( );
  56.         $phone->type_id = '1';
  57.         $phone->number = $this->_request->getParam( 'primaryPhone1' ) . $this->_request->getParam( 'primaryPhone2' ) . $this->_request->getParam( 'primaryPhone3' );
  58.         $phone->save();
  59.         $email = new Contacts_Email( );
  60.         $email->address = $this->_request->getParam( 'email' );
  61.         $email->save();
  62.         $pLocation = new People_PersonsLocations( );
  63.         $pLocation->person_id = $person->id;
  64.         $pLocation->location_id = $location->id;
  65.         $pLocation->label = 'Current Residence';
  66.         $pLocation->save();
  67.         $pPhone = new People_PersonsPhones( );
  68.         $pPhone->person_id = $person->id;
  69.         $pPhone->phone_id = $phone->id;
  70.         $pPhone->label = 'Primary';
  71.         $pPhone->save();
  72.         $pEmail = new People_PersonsEmails( );
  73.         $pEmail->person_id = $person->id;
  74.         $pEmail->email_id = $email->id;
  75.         $pEmail->label = 'Primary';
  76.         $pEmail->save();
  77.     if ($this->_request->getParam('role') == '1') {
  78.       $patient = new Instacare_Patient( );
  79.       $patient->person_id = $person->id;
  80.       $patient->default_location_id = $location->id;
  81.       $patient->default_phone_id = $phone->id;
  82.       $patient->save();
  83.       $record = new Records_Record( );
  84.       $record->person_id = $person->id;
  85.       $record->save();
  86.     } else {
  87.       $employee = new Businesses_Employee();
  88.       $employee->person_id = $person->id;
  89.       $employee->business_id = Doctrine_Query::create()
  90.         ->select('id')
  91.         ->from('Businesses_Business')
  92.         ->where('name LIKE ?', '%Summerlin Health%')
  93.         ->fetchOne()
  94.         ->id;
  95.       $employee->save();
  96.       // @todo: add new roles
  97.       switch ($this->_request->getParam('role')) {
  98.       case '2': $iEmployee = new Instacare_Nurse();
  99.         $iEmployee->npi = $this->_request->getParam('npi');
  100.         $phoneUserType = 2;
  101.         break;
  102.       case '3': $iEmployee = new Instacare_Doctor();
  103.         $iEmployee->npi = $this->_request->getParam('npi');
  104.         $phoneUserType = 3;
  105.         break;
  106.       case '4': $iEmployee = new Instacare_Scheduler();
  107.         $phoneUserType = 4;
  108.         break;
  109.       case '5': $iEmployee = new Instacare_Admissions();
  110.         $phoneUserType = 1;
  111.         break;
  112.           case '6': $iEmployee = new Instacare_Admin();
  113.         break;
  114.           case '10': $iEmployee = new Instacare_Manager();
  115.         break;
  116.           case '11': $iEmployee = new Instacare_Executive();
  117.         break;
  118.           case '12': $iEmployee = new Instacare_Accounting();
  119.         break;
  120.           case '9': $iEmployee = new Instacare_Cmo();
  121.         break;
  122.       }
  123.       $iEmployee->title = $this->_request->getParam('title');
  124.       $iEmployee->employee_id = $employee->id;
  125.       $iEmployee->save();
  126.       if (isset($phoneUserType)) {
  127.         $phoneUser = new Instacare_phone_IcpUsers();
  128.         $phoneUser->user_id = $user->id;
  129.         $phoneUser->type = $phoneUserType;
  130.         switch ($person->default_language) {
  131.         case 'en': $phoneUser->language = 1;
  132.           break;
  133.         case 'es': $phoneUser->language = 2;
  134.         }
  135.         $phoneUser->save();
  136.       }
  137.     }
  138.     $this->_helper->FlashMessenger('User '.$user->username.'successfully created');
  139.     $this->_redirect('/user/index/add');
  140.       }
  141.     }
  142.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement