<commit_before><?php

class Entreprise extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->library('hash');
		$this->load->model('entreprise_model');
		$this->load->model('sujet_model');
		$this->load->model('etudiant_model');
		$this->load->model('filiere_model');
		$this->load->model('user_model');
	}

	public function signup()
	{
		$this->form_validation->set_rules('nom_entreprise', "Nom Entreprise",'required|trim');
		$this->form_validation->set_rules('pays','Pays','required');
		$this->form_validation->set_rules('adresse','Adresse','required|trim');
		$this->form_validation->set_rules('ville','Ville','required');
		$this->form_validation->set_rules('numtel','Numero de Telephone','required|trim');
		$this->form_validation->set_rules('email','Email','trim|required|valid_email|is_unique[Entreprise.email]');
		$this->form_validation->set_rules('description','Description','trim|required');
		$this->form_validation->set_message('required', 'Le champ %s est obligatoire');
		$this->form_validation->set_message('valid_mail', 'Email invalide');
		$this->form_validation->set_message('is_unique', 'Une entreprise est déjà enregistrée avec cet email');
		if ($this->form_validation->run() == false) {
			$data['NOSIDEBAR'] = true;
			$data['title'] = 'Inscription entreprises';
			$this->render('signup',$data);
		} else {
			$data = array(
				'nom'=>$this->input->post('nom_entreprise'),
				'pays'=>$this->input->post('pays'),
				'ville'=>$this->input->post('ville'),
				'adresse'=>$this->input->post('adresse'),
				'fax'=>$this->input->post('fax'),
				'numTel'=>$this->input->post('numtel'),
				'email'=>$this->input->post('email'),
				'description'=>$this->input->post('description'),
			);
			$this->entreprise_model->createEntreprise($data);
			echo 'Validé';
		}
	}

	public function index()
	{
		if(currentSession()['role'] != 'entreprise'){
			return redirect('home');
		}
		$data['filieres'] = $this->filiere_model->getFilieres();
		$data['sujets'] = $this->sujet_model->getSujets(['entrepriseId' => currentSession()['id']]);
		$data['title'] = 'Accueil Entreprise';
		$this->render('entreprise/accueil', $data);
	}

	public function ajouter_sujet()
	{
		if (!isEntreprise())
			return show_404();
		$this->form_validation->set_rules('titre', 'Titre', 'required|trim|is_unique[Sujet.titre]');
		$this->form_validation->set_rules('description', 'Description', 'required|trim|max_length[255]');
		$this->form_validation->set_rules('prerequis', 'Description', 'required|trim|max_length[500]');
		$this->form_validation->set_rules('filiere', 'Filiere', 'required|trim');
		$this->form_validation->set_rules('niveau', 'niveau', 'required|trim');
		
		if (!$this->form_validation->run()) {
			$this->index();
		} else {
			$data = array(
				'titre' => $this->input->post('titre'),
				'description' =>$this->input->post('description'),
				'prerequis' =>$this->input->post('prerequis'),
				'filiere' =>$this->input->post('filiere'),
				'niveau' => $this->input->post('niveau'),
				'entrepriseId' => currentsession()['id']
			);
			$this->sujet_model->createSujet($data);
			redirect('entreprise');
		}
	}

	public function edit_profile($id)
	{
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => $id]);
		if (currentSession()['id'] != $entreprise->entrepriseId)
			return show_404();
		$this->form_validation->set_rules('numTel', 'Téléphone', 'trim|required');
		$this->form_validation->set_rules('adresse', 'Adresse', 'trim|required');
		$this->form_validation->set_rules('ville', 'Ville', 'trim|required');
		$this->form_validation->set_rules('pays', 'Pays', 'trim|required');
		$this->form_validation->set_rules('new_password', '<PASSWORD>', 'trim|min_length[6]');
		$this->form_validation->set_rules('password', '<PASSWORD>', '<PASSWORD>');
		$this->form_validation->set_rules('logo', 'Logo', 'callback_check_logo');
		$this->form_validation->set_message('required', 'Le champ %s est obligatoire');
		
		if ($this->form_validation->run() == false) {
			$data['title'] = 'Modification du Profil';
			$data['entreprise'] = $entreprise;
			$this->render('entreprise/edit_infos', $data);
		} else {
			// Update entreprise
			$data = array(
				'numTel' => $this->input->post('numTel'),
				'adresse' => $this->input->post('adresse'),
				'ville' => $this->input->post('ville'),
				'pays' => $this->input->post('pays'),
			);
			$this->entreprise_model->updateEntreprise(currentSession()['id'], $data);
			// Update user
			$new_pwd = $this->input->post('new_password');
			if (!empty($new_pwd)) {
				$userData['password'] = $this-><PASSWORD>($<PASSWORD>);
				$this->user_model->updateUser(['userId' => currentSession()['id']], $userData);
			}
			return redirect("entreprise/$id");
			// If the form was submitted
		}

	}

	public function profile($id)
	{
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => $id]);
		$data['title'] = "Profil de $entreprise->nom";
		$data['entreprise'] = $entreprise;
		$this->render('entreprise/profile', $data);
	}

	// Form validation callbacks
	public function check_password($password)
	{
		$user = $this->user_model->getUser(['userId' => currentSession()['id']]);
		$this->form_validation->set_message('check_password', 'Mot de passe incorrect');
		return $this->hash->check_password($password, $user->password);
	}

	public function check_logo()
	{
		// If no photo was chosen, then don't bother trying to do any validation
		if (empty($_FILES['logo']['name']))
			return true;
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => currentSession()['id']]);
		$config['allowed_types'] = 'jpg|png';
		$config['upload_path'] = FCPATH.'uploads/logos/';
		$config['file_name'] = $entreprise->entrepriseId;
		$config['max_size'] = 1024;
		$config['overwrite'] = true;
		$this->load->library('upload', $config);
		// If upload failed display error
		if ($this->upload->do_upload('logo')) {
			return true;
		} else {
			$this->form_validation->set_message('check_logo', strip_tags($this->upload->display_errors()));
			return false;
		}
	}
}<commit_msg> accueil tuteur(affichage tuteurs)<commit_after><?php

class Entreprise extends MY_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->helper('form');
		$this->load->library('form_validation');
		$this->load->library('hash');
		$this->load->model('entreprise_model');
		$this->load->model('sujet_model');
		$this->load->model('etudiant_model');
		$this->load->model('filiere_model');
		$this->load->model('user_model');
	}

	public function signup()
	{
		$this->form_validation->set_rules('nom_entreprise', "Nom Entreprise",'required|trim');
		$this->form_validation->set_rules('pays','Pays','required');
		$this->form_validation->set_rules('adresse','Adresse','required|trim');
		$this->form_validation->set_rules('ville','Ville','required');
		$this->form_validation->set_rules('numtel','Numero de Telephone','required|trim');
		$this->form_validation->set_rules('email','Email','trim|required|valid_email|is_unique[Entreprise.email]');
		$this->form_validation->set_rules('description','Description','trim|required');
		$this->form_validation->set_message('required', 'Le champ %s est obligatoire');
		$this->form_validation->set_message('valid_mail', 'Email invalide');
		$this->form_validation->set_message('is_unique', 'Une entreprise est déjà enregistrée avec cet email');
		if ($this->form_validation->run() == false) {
			$data['NOSIDEBAR'] = true;
			$data['title'] = 'Inscription entreprises';
			$this->render('signup',$data);
		} else {
			$data = array(
				'nom'=>$this->input->post('nom_entreprise'),
				'pays'=>$this->input->post('pays'),
				'ville'=>$this->input->post('ville'),
				'adresse'=>$this->input->post('adresse'),
				'fax'=>$this->input->post('fax'),
				'numTel'=>$this->input->post('numtel'),
				'email'=>$this->input->post('email'),
				'description'=>$this->input->post('description'),
			);
			$this->entreprise_model->createEntreprise($data);
			echo 'Validé';
		}
	}

	public function index()
	{
		if(currentSession()['role'] != 'entreprise'){
			return redirect('home');
		}
		$data['filieres'] = $this->filiere_model->getFilieres();
		$data['sujets'] = $this->sujet_model->getSujets(['entrepriseId' => currentSession()['id']]);
		$data['title'] = 'Accueil Entreprise';
		$this->render('entreprise/accueil', $data);
	}

	public function ajouter_sujet()
	{
		if (!isEntreprise())
			return show_404();
		$this->form_validation->set_rules('titre', 'Titre', 'required|trim|is_unique[Sujet.titre]');
		$this->form_validation->set_rules('description', 'Description', 'required|trim|max_length[255]');
		$this->form_validation->set_rules('prerequis', 'Description', 'required|trim|max_length[500]');
		$this->form_validation->set_rules('filiere', 'Filiere', 'required|trim');
		$this->form_validation->set_rules('niveau', 'niveau', 'required|trim');
		
		if (!$this->form_validation->run()) {
			$this->index();
		} else {
			$data = array(
				'titre' => $this->input->post('titre'),
				'description' =>$this->input->post('description'),
				'prerequis' =>$this->input->post('prerequis'),
				'filiere' =>$this->input->post('filiere'),
				'niveau' => $this->input->post('niveau'),
				'entrepriseId' => currentsession()['id']
			);
			$this->sujet_model->createSujet($data);
			redirect('entreprise');
		}
	}

	public function edit_profile($id)
	{
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => $id]);
		if (currentSession()['id'] != $entreprise->entrepriseId)
			return show_404();
		$this->form_validation->set_rules('numTel', 'Téléphone', 'trim|required');
		$this->form_validation->set_rules('adresse', 'Adresse', 'trim|required');
		$this->form_validation->set_rules('ville', 'Ville', 'trim|required');
		$this->form_validation->set_rules('pays', 'Pays', 'trim|required');
		$this->form_validation->set_rules('new_password', '<PASSWORD>', 'trim|min_length[6]');
		$this->form_validation->set_rules('password', '<PASSWORD>', '<PASSWORD>');
		$this->form_validation->set_rules('logo', 'Logo', 'callback_check_logo');
		$this->form_validation->set_message('required', 'Le champ %s est obligatoire');
		
		if ($this->form_validation->run() == false) {
			$data['title'] = 'Modification du Profil';
			$data['entreprise'] = $entreprise;
			$this->render('entreprise/edit_infos', $data);
		} else {
			// Update entreprise
			$data = array(
				'numTel' => $this->input->post('numTel'),
				'adresse' => $this->input->post('adresse'),
				'ville' => $this->input->post('ville'),
				'pays' => $this->input->post('pays'),
			);
			$this->entreprise_model->updateEntreprise(currentSession()['id'], $data);
			// Update user
			$new_pwd = $<PASSWORD>->input->post('new_password');
			if (!empty($new_pwd)) {
				$userData['password'] = $this-><PASSWORD>($<PASSWORD>);
				$this->user_model->updateUser(['userId' => currentSession()['id']], $userData);
			}
			return redirect("entreprise/$id");
			// If the form was submitted
		}

	}

	public function profile($id)
	{
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => $id]);
		$data['title'] = "Profil de $entreprise->nom";
		$data['entreprise'] = $entreprise;
		$this->render('entreprise/profile', $data);
	}

	// Form validation callbacks
	public function check_password($password)
	{
		$user = $this->user_model->getUser(['userId' => currentSession()['id']]);
		$this->form_validation->set_message('check_password', 'Mot de passe incorrect');
		return $this->hash->check_password($password, $user->password);
	}

	public function check_logo()
	{
		// If no photo was chosen, then don't bother trying to do any validation
		if (empty($_FILES['logo']['name']))
			return true;
		$entreprise = $this->entreprise_model->getEntreprise(['entrepriseId' => currentSession()['id']]);
		$config['allowed_types'] = 'jpg|png';
		$config['upload_path'] = FCPATH.'uploads/logos/';
		$config['file_name'] = $entreprise->entrepriseId;
		$config['max_size'] = 1024;
		$config['overwrite'] = true;
		$this->load->library('upload', $config);
		// If upload failed display error
		if ($this->upload->do_upload('logo')) {
			return true;
		} else {
			$this->form_validation->set_message('check_logo', strip_tags($this->upload->display_errors()));
			return false;
		}
	}
	public function tuteur(){
		if(currentSession()['role'] != 'entreprise'){
			return redirect('home');
		}

		$data['tuteurs'] = $this->tuteur_model->getTuteurExt(['entrepriseId' => currentSession()['id']])
		$data['title'] = 'Tuteurs';
		$this->render('entreprise/tuteurs', $data);

	}
	public function ajouter_tuteur(){

	}
}
{'fraction_non_alphanumeric': 0.21908570532423743, 'fraction_numerical': 0.0026660393632870695, 'mean_word_length': 5.8717672413793105, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 358, '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': '3296901', 'n_tokens_mistral': 4767, 'n_tokens_neox': 4301, 'n_words': 606}