<commit_before><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Contract extends CI_Controller {

	public function __construct() {
        parent::__construct();
		$this->load->model('status_model');
		$this->load->model('offer_model');
        $this->load->model('contract_model');
    }
	
	public function index() {
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
            $data['user_id'] = $session_data['user_id'];
            $data['contracts'] = $this->contract_model->get_all_contracts_by_user($session_data['user_id']);
            $data['header'] = 'My Contracts';   
            $data['view'] = 'contract_view';
            $data['page_title'] = 'My Contracts';
            $this->load->view('application_view', $data);
        }
        else {
            redirect('login', 'refresh');
        }
	}
	
	public function validate(){
		$this->form_validation->set_rules('completion_status', 'Completion Status', 'required');
		$session_data = $this->session->userdata('logged_in');
        $task_id = $this->input->post('id');
		
        if ($this->form_validation->run() === false) {
            $this->create($task_id);

        } else {
            $user_id = $session_data['user_id'];
            $completion_status = $this->input->post('completion_status');
			$employer_id = $this->input->post('employer_id');
			$employee_id = $this->input->post('acceptee_id');
			$task_id = $this->input->post('task_id');
			$offer_id = $this->input->post('offer_id');

            if ($this->contract_model->create($employer_id, $employee_id, $task_id, $offer_id, $completion_status)) {
                $this->success("created");

            } else {
                $this->failure("created");
            }
        }
	}
	
	public function create($offer_id){
		if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
			$data['completion_status'] = array_merge([''=>'Please Select'], $this->status_model->get_all_statuses());
			
            if ($data['offer'] = $this->offer_model->get($offer_id)) {
                // Set start and end date and time input fields 
                // in data array
                $start_datetime_arr = explode(" ",$data['offer']['start_datetime']);
                $end_datetime_arr = explode(" ", $data['offer']['end_datetime']);
                $data['offer']['start_date'] = $start_datetime_arr[0];
                $data['offer']['start_time'] = $start_datetime_arr[1];
                $data['offer']['end_date'] = $end_datetime_arr[0];
                $data['offer']['end_time'] = $end_datetime_arr[1];

                $data['header'] = 'Accept an offer';
				$data['page_title'] = 'Accept an offer';
				$data['view'] = 'contract_create_view';
				$this->load->view('application_view', $data);
			} 
			
		} else {
            redirect('login', 'refresh');
        }
	}
    
    public function validate_update() {
        $this->form_validation->set_rules('completion_status', 'Completion Status', 'required');
        $session_data = $this->session->userdata('logged_in');
        $contract_id = $this->input->post('id');<commit_msg>AL fixed contract creation failure view<commit_after><?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Contract extends CI_Controller {

	public function __construct() {
        parent::__construct();
		$this->load->model('status_model');
		$this->load->model('offer_model');
        $this->load->model('contract_model');
    }
	
	public function index() {
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
            $data['user_id'] = $session_data['user_id'];
            $data['contracts'] = $this->contract_model->get_all_contracts_by_user($session_data['user_id']);
            $data['header'] = 'My Contracts';   
            $data['view'] = 'contract_view';
            $data['page_title'] = 'My Contracts';
            $this->load->view('application_view', $data);
        }
        else {
            redirect('login', 'refresh');
        }
	}
	
	public function validate(){
		$offer_id = $this->input->post('offer_id');
		$this->form_validation->set_rules('completion_status', 'Completion Status', 'required');
		
        if ($this->form_validation->run() === false) {
            $this->confirm_create($offer_id);

        } else {
			$employer_id = $this->input->post('employer_id');
			$employee_id = $this->input->post('acceptee_id');
			$task_id = $this->input->post('task_id');
			$completion_status = $this->input->post('completion_status');

            if ($this->contract_model->create($employer_id, $employee_id, $task_id, $offer_id, $completion_status)) {
                $this->success("created");

            } else {
                $this->failure("created");
            }
        }
	}
    
    public function validate_update() {
        $this->form_validation->set_rules('completion_status', 'Completion Status', 'required');
        $session_data = $this->session->userdata('logged_in');
        $contract_id = $this->input->post('id');
{'fraction_non_alphanumeric': 0.18181818181818182, 'fraction_numerical': 0.0007436326454731362, 'mean_word_length': 2.915574963609898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195267', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1568, 'n_words': 241}