<commit_before><?php
/**
 *COPYRIGHT (C) 2016 Campfire. All Rights Reserved.
 * CreateEvent.php is the controller for createEvent_view.php
 * Solves SE165 Semester Project Fall 2016
 * @author <NAME>, <NAME>, <NAME>, <NAME>, 
 *     <NAME>, <NAME>, <NAME>, <NAME>
*/
class CreateEvent extends CI_Controller {

	// constructor used for needed initialization
	public function __construct() {
		parent::__construct();
		$this->load->helper(array('form','url','html','security', 'date'));
		// $this->load->library(array('session','javascript','javascript/jquery','form_validation'));
		$this->load->library(array('session','form_validation'));
		$this->load->database();
		$this->load->model('user_model');
		$this->load->model('event_model');
		$this->load->model('group_model');
		// $this->jquery->event('#startDate', jsFunction());

		if (!$this->session->userdata('login')) {
			redirect('home/index');
		}
	}
	function index() {
		//dynamically populate the tag_list for the dropdown
		$data['tag_list'] = $this->event_model->get_dropdown_list();

		// get user information from session data to create basic profile
		$details = $this->user_model->get_user_by_id($this->session->userdata('uid'));
		$data['uname'] = $details[0]->user_fname . " " . $details[0]->user_lname;
		$data['uemail'] = $details[0]->user_email;

		// $this->load->view('createEvent_view', $data);
	// }

	/*
	* Responsible for creating the event
	* Validate, prep data in validate order, pass to model, provide feedback.
	*/
	// function createEvent(){	
		//Event pictures
		//new directory for event images
		// $targetDir = './uploads/';

		//Event form
		//set form validations
		$this->form_validation->set_rules('eventTitle', 'Event Title', 'trim|required|callback_check_text|min_length[1]|max_length[30]|xss_clean');
			// array('check_text' => 'This text is not allowed.')

		$this->form_validation->set_rules('address1','Street address', 'trim|required|xss_clean'); 
		$this->form_validation->set_rules('address2','Street address', 'trim|xss_clean'); 
		$this->form_validation->set_rules('eventCity','City', 'trim|required|xss_clean'); 
		$this->form_validation->set_rules('eventState','State', 'trim|required|min_length[2]|max_length[2]|xss_clean');
		$this->form_validation->set_rules('eventZip','Event Zip Code', 
			'trim|required|numeric|min_length[5]|max_length[10]|xss_clean');

		$this->form_validation->set_rules('eventDTStart', 'Event Start', 'trim|required|xss_clean');
		$this->form_validation->set_rules('eventDTEnd', 'Event End', 'trim|xss_clean');

		$this->form_validation->set_rules('eventDescription', 'Event Description', 'trim|required|max_length[200]|xss_clean');

		// submit the form and validate
		if ($this->form_validation->run() == FALSE) {
			// if it fails just load the view again
			$this->load->view('createEvent_view', $data);
		}else{ //form validations work correctly
            // redirect('home/index'); 

        //translate user dates to "yyyy-mm-dd hh:mm:ss format"
	    $startdate = $this->input->post('eventDTStart');
   		$eventData["startTime"] = date('Y-m-d H:i:s', strtotime($startdate));

	    $enddate = $this->input->post('eventDTEnd');
		$eventData["endTime"] = date('Y-m-d H:i:s', strtotime($enddate));
		//works
		//put back in post

		//prepare to insert group details into event table
		$event_data = array(
			'event_title' => $this->input->post('eventTitle'),
			'event_description' => $this->input->post('eventDescription'),
			'event_begin_datetime' => $eventData["startTime"],
			'event_end_datetime' => $eventData["endTime"],
			'event_picture' => "test picture"
		);
		// print_r($event_data);

		//prepare to insert user location details into location table
			$location_data = array(
				'address_one' => $this->input->post('address1'),
				'address_two' => $this->input->post('address2'),
				'city' => $this->input->post('eventCity'),
				'state' => $this->input->post('eventState'),
				'zipcode' => $this->input->post('eventZip'),
			  	'geolat' =>'',
				'geolng' =>''
			);

			//prepare to tag title into tag table
			$tag_title = $this->input->post('tag');

		//prepare to insert owner id into owner table
		$eventowner_data = array(
			'owner_id' => $this->session->userdata('uid')
		);	

		if ($this->event_model->insert_event($event_data, $location_data, $tag_title, $eventowner_data)){
			// success!!!
			// echo "event success";

			$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your Event has been successfully created!</div>');
			redirect('createEvent/index');

			} else {
				// error!!!
				// $this->removeImage($simpleNewFileName); // Remove image upload if group was not created
				$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
				echo "event error";
				redirect('createEvent/index');

			}
		} //else	
	}//createEvent

	/*
	* used to check description & title text
	*/
	function check_text($str){
		$pattern = '/^[a-z0-9]\-_/i';
			//cibtaubstgese characters
		if(preg_match($pattern, $str)){
			$this->form_validation->set_message('check_text','This is not valid for {field}. Please try again.');
			return FALSE;
		}else{
			return TRUE;
		}
		// $this->form_validation->set_rules('eventTitle', 'Event Title', 'trim|required|regex_match[#^[ \'a-zA-Z0-9]-]+$#]|min_length[1]|max_length[30]|xss_clean');
		// regex_match[#^[ \'a-zA-Z0-9]-]+$#]

	}<commit_msg>added inappropriate word check in create event<commit_after><?php
/**
 *COPYRIGHT (C) 2016 Campfire. All Rights Reserved.
 * CreateEvent.php is the controller for createEvent_view.php
 * Solves SE165 Semester Project Fall 2016
 * @author <NAME>, <NAME>, <NAME>, <NAME>, 
 *     <NAME>, <NAME>, <NAME>, <NAME>
*/
class CreateEvent extends CI_Controller {

	// constructor used for needed initialization
	public function __construct() {
		parent::__construct();
		$this->load->helper(array('form','url','html','security', 'date'));
		// $this->load->library(array('session','javascript','javascript/jquery','form_validation'));
		$this->load->library(array('session','form_validation'));
		$this->load->database();
		$this->load->model('user_model');
		$this->load->model('event_model');
		$this->load->model('group_model');
		// $this->jquery->event('#startDate', jsFunction());

		if (!$this->session->userdata('login')) {
			redirect('home/index');
		}
	}
	function index() {
		//dynamically populate the tag_list for the dropdown
		$data['tag_list'] = $this->event_model->get_dropdown_list();

		// get user information from session data to create basic profile
		$details = $this->user_model->get_user_by_id($this->session->userdata('uid'));
		$data['uname'] = $details[0]->user_fname . " " . $details[0]->user_lname;
		$data['uemail'] = $details[0]->user_email;

		// $this->load->view('createEvent_view', $data);
	// }

	/*
	* Responsible for creating the event
	* Validate, prep data in validate order, pass to model, provide feedback.
	*/
	// function createEvent(){	
		//Event pictures
		//new directory for event images
		// $targetDir = './uploads/';

		//Event form
		//set form validations
		$this->form_validation->set_rules('eventTitle', 'Event Title', 'trim|required|callback_check_text|min_length[1]|max_length[30]|xss_clean');
			// array('check_text' => 'This text is not allowed.')
		$this->form_validation->set_rules('eventTitle', 'Event Title', 'callback_badWord_check');
		$this->form_validation->set_rules('address1','Street address', 'trim|required|xss_clean'); 
		$this->form_validation->set_rules('address2','Street address', 'trim|xss_clean'); 
		$this->form_validation->set_rules('eventCity','City', 'trim|required|xss_clean'); 
		$this->form_validation->set_rules('eventState','State', 'trim|required|min_length[2]|max_length[2]|xss_clean');
		$this->form_validation->set_rules('eventZip','Event Zip Code', 
			'trim|required|numeric|min_length[5]|max_length[10]|xss_clean');

		$this->form_validation->set_rules('eventDTStart', 'Event Start', 'trim|required|xss_clean');
		$this->form_validation->set_rules('eventDTEnd', 'Event End', 'trim|xss_clean');

		$this->form_validation->set_rules('eventDescription', 'Event Description', 'trim|required|max_length[200]|xss_clean');
		$this->form_validation->set_rules('eventDescription', 'Event Description', 'callback_badWord_check');

		// submit the form and validate
		if ($this->form_validation->run() == FALSE) {
			// if it fails just load the view again
			$this->load->view('createEvent_view', $data);
		}else{ //form validations work correctly
            // redirect('home/index'); 

        //translate user dates to "yyyy-mm-dd hh:mm:ss format"
	    $startdate = $this->input->post('eventDTStart');
   		$eventData["startTime"] = date('Y-m-d H:i:s', strtotime($startdate));

	    $enddate = $this->input->post('eventDTEnd');
		$eventData["endTime"] = date('Y-m-d H:i:s', strtotime($enddate));
		//works
		//put back in post

		//prepare to insert group details into event table
		$event_data = array(
			'event_title' => $this->input->post('eventTitle'),
			'event_description' => $this->input->post('eventDescription'),
			'event_begin_datetime' => $eventData["startTime"],
			'event_end_datetime' => $eventData["endTime"],
			'event_picture' => "test picture"
		);
		// print_r($event_data);

		//prepare to insert user location details into location table
			$location_data = array(
				'address_one' => $this->input->post('address1'),
				'address_two' => $this->input->post('address2'),
				'city' => $this->input->post('eventCity'),
				'state' => $this->input->post('eventState'),
				'zipcode' => $this->input->post('eventZip'),
			  	'geolat' =>'',
				'geolng' =>''
			);

			//prepare to tag title into tag table
			$tag_title = $this->input->post('tag');

		//prepare to insert owner id into owner table
		$eventowner_data = array(
			'owner_id' => $this->session->userdata('uid')
		);	

		if ($this->event_model->insert_event($event_data, $location_data, $tag_title, $eventowner_data)){
			// success!!!
			// echo "event success";

			$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your Event has been successfully created!</div>');
			redirect('createEvent/index');

			} else {
				// error!!!
				// $this->removeImage($simpleNewFileName); // Remove image upload if group was not created
				$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
				echo "event error";
				redirect('createEvent/index');

			}
		} //else	
	}//createEvent

	/*
	* used to check description & title text
	*/
	function check_text($str){
		$pattern = '/^[a-z0-9]\-_/i';
			//cibtaubstgese characters
		if(preg_match($pattern, $str)){
			$this->form_validation->set_message('check_text','This is not valid for {field}. Please try again.');
			return FALSE;
		}else{
			return TRUE;
		}
		// $this->form_validation->set_rules('eventTitle', 'Event Title', 'trim|required|regex_match[#^[ \'a-zA-Z0-9]-]+$#]|min_length[1]|max_length[30]|xss_clean');
		// regex_match[#^[ \'a-zA-Z0-9]-]+$#]

	}
	
	/**
	* used for validation check on event title and description
	*/
	function badWord_check($input) {
		$fh = fopen(base_url().'assets/text_input/badWords.txt', 'r') or die($php_errormsg);
		while (!feof($fh)) {
			$line = fgets($fh, 4096);
			if (preg_match($line, strtolower($input))) {
				$this->form_validation->set_message('badWord_check', 'You have entered an inappropriate word! Lets keep it clean!!!.');
				return FALSE;
			} else {
				return TRUE;
			}
		}
		fclose($fh);
	}
{'fraction_non_alphanumeric': 0.1909513160158266, 'fraction_numerical': 0.006881128505074832, 'mean_word_length': 4.666179337231969, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 229, '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': '658203', 'n_tokens_mistral': 4221, 'n_tokens_neox': 3778, 'n_words': 749}