<?php namespace App\Controllers;

/**
 * @author Andy Brookes 
 * @author Andy Brookes <andybrookestar  at gmail dot   com>
 */


use CodeIgniter\Controller;
use \App\Models\Setupmodel;


class Setup  extends BaseController
{

protected $userName;
protected $password;
protected $role;
 protected $myTime;

				 public function __construct() 
				    {
						parent::__construct();
						$this->myTime = parent::getTime();
						$this->myDate= date("d/m/Y",$this->myTime); 	
					
			       }










	public function setUpForm()

	{
	  



	  $data =[
			'title'=>'admin set up',
			'date'=>$this->myDate
			];
				
			
			echo view('setUpAdmin',$data);
			
	}


      public function process()
      
      {
   $this->userName=   $this->request->getVar('name'); 
   
   $pass=  $this->request->getVar('password'); 
   $this->password =    password_hash($pass,PASSWORD_DEFAULT);
   $this->role= $this->request->getVar('list'); 
  
  
  
  
   
   $handle= new Setupmodel();
      $handle->adminUser($this->userName,$this->password,$this->role);
    
    $data= [
		
		'title'=>'setup done ',
		
		'info'=>  ' <p>done, you can now go to url   /orange  which is default login  url unless you changed it </p><br>
		
		<h8>PLEASE note </h8><p>there are some re-directs using whatever you change "orange" to in the file app/Controllers/Login.php 
		on lines 168 and 195 .So if you change /orange to something else for login  in routes, reflect 
			this on lines 168 and 195 in app/Controllers/Login.php </p>    '            ,
		'date'=>$this->myDate
		
		];
		
		  
        echo view('info', $data);
    
      
      /*  please note the way its set up you can only have one admin user because db select gets first entry,regardlress 
       * of other db entries
       */
      
      }
      


}
