<commit_before><?php

class Device extends CI_Controller {
	function __construct() {
		// Call the Controller constructor
    	parent::__construct();
    }
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index() {
		$this->load->model('device_model');
		$data['devices'] = $this->device_model->getAll();
		$this->load->view('home', $data);
	}

	// load view for edit device page
	public function editDevice() {
		$this->load->model('Device_model');
		$data['title'] = "EDIT DEVICE";
		$this->load->view('deviceForm',$data);
	}

	// load view for new device page
	public function newDevice() {
		$data['title'] = "NEW DEVICE";
		$this->load->view('deviceForm', $data);
		redirect(base_url().'device/index');
	}

	// create new device
	public function createDevice(){
		// normal form elements
		$device['device_name'] = $this->input->post('device_name');
		$device['location'] = $this->input->post('location');
		$device['device_type'] = $this->input->post('device_type');
		$device['allow_notif'] = $this->input->post('allow_notif');
		
		$this->load->model('device_model');
		$id = $this->device_model->insert($device);
		$device['id'] = $id;

		// uploaded files
		$config['upload_path'] = './images/devices/';
		$config['allowed_types'] = 'gif|jpg|png';

		if (empty($_FILES['audioFile']['name']) {
			$device['audioFile'] = "default.mp3";
		} else {
			$this->upload->do_upload('audioFile');
			$filename = $_FILES['audioFile']['name'];
			$device['audioFile'] = $filename;
		}

		if (empty($_FILES['photo']['name']) {
			$device['photo'] = "default.jpg";
		} else {
			$this->upload->do_upload('photo');
			$filename = $_FILES['photo']['name'];
			$device['photo'] = $filename;
		}
		
		$this->device_model->update($device);

	}

	// save device details (grab data from AJAX)
	public function saveDevice(){
		//$config['upload_path'] = './images/devices/';
		//$config['file_name'] = "1.jpg";
		$device = Array();
		$device['id'] = $this->input->post('deviceId');
		$device['name'] = $this->input->post('deviceName');
		$device['location'] = $this->input->post('location');
		$device['type'] = $this->input->post('deviceType');
		$device['notification'] = $this->input->post('notification');
		$device['audioFile'] = $this->input->post('audioFile');
		$device['photo'] = $this->input->post('photo');

		$this->load->model('device_model');
		$this->device_model->update($device);

		redirect(base_url().'device/index');
	}

	// Call SMS Gateway to send alert text<commit_msg>syntax error<commit_after><?php

class Device extends CI_Controller {
	function __construct() {
		// Call the Controller constructor
    	parent::__construct();
    }
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index() {
		$this->load->model('device_model');
		$data['devices'] = $this->device_model->getAll();
		$this->load->view('home', $data);
	}

	// load view for edit device page
	public function editDevice() {
		$this->load->model('Device_model');
		$data['title'] = "EDIT DEVICE";
		$this->load->view('deviceForm',$data);
	}

	// load view for new device page
	public function newDevice() {
		$data['title'] = "NEW DEVICE";
		$this->load->view('deviceForm', $data);
		redirect(base_url().'device/index');
	}

	// create new device
	public function createDevice(){
		// normal form elements
		$device['device_name'] = $this->input->post('device_name');
		$device['location'] = $this->input->post('location');
		$device['device_type'] = $this->input->post('device_type');
		$device['allow_notif'] = $this->input->post('allow_notif');
		
		$this->load->model('device_model');
		$id = $this->device_model->insert($device);
		$device['id'] = $id;

		// uploaded files
		$config['upload_path'] = './images/devices/';
		$config['allowed_types'] = 'gif|jpg|png';

		if (empty($_FILES['audioFile']['name'])) {
			$device['audioFile'] = "default.mp3";
		} else {
			$this->upload->do_upload('audioFile');
			$filename = $_FILES['audioFile']['name'];
			$device['audioFile'] = $filename;
		}

		if (empty($_FILES['photo']['name'])) {
			$device['photo'] = "default.jpg";
		} else {
			$this->upload->do_upload('photo');
			$filename = $_FILES['photo']['name'];
			$device['photo'] = $filename;
		}
		
		$this->device_model->update($device);

	}

	// save device details (grab data from AJAX)
	public function saveDevice(){
		//$config['upload_path'] = './images/devices/';
		//$config['file_name'] = "1.jpg";
		$device = Array();
		$device['id'] = $this->input->post('deviceId');
		$device['name'] = $this->input->post('deviceName');
		$device['location'] = $this->input->post('location');
		$device['type'] = $this->input->post('deviceType');
		$device['notification'] = $this->input->post('notification');
		$device['audioFile'] = $this->input->post('audioFile');
		$device['photo'] = $this->input->post('photo');

		$this->load->model('device_model');
		$this->device_model->update($device);

		redirect(base_url().'device/index');
	}

	// Call SMS Gateway to send alert text
{'fraction_non_alphanumeric': 0.21158091356766853, 'fraction_numerical': 0.0006792324673119375, 'mean_word_length': 4.277777777777778, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 101, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2956930', 'n_tokens_mistral': 2109, 'n_tokens_neox': 1909, 'n_words': 366}