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

class Order_model extends CI_Model {

	public $mrh_login = 'plecle';

	public $mrh_pass1 = '<PASSWORD>';

	public $mrh_pass2 = '<PASSWORD>';

	public $frequency = array(
		'once'          => 'Только один раз',
		'every_week'    => 'Еженедельно',
		'every_2_weeks' => 'Каждые две недели',
	);

	public $duration = array(
		'1'   => '1 час',
		'1.5' => '1.5 часа',
		'2'   => '2 часа',
		'2.5' => '2.5 часа',
		'3'   => '3 часа',
		'3.5' => '3.5 часа',
		'4'   => '4 часа',
		'4.5' => '4.5 часа',
	);

	public $special = array(
		'need_ironing' => 'Нужна глажка',
		'have_pets'    => 'Есть домашнее животное',
	);

	function __construct() {
		parent::__construct();
		$this->load->database();
	}

	function get_user_order($order_id, $user_id = false, $user_type = false) {
		if (empty($user_type)) {
			if (!empty($this->data['user_info']['is_cleaner'])) {
				$user_type = 'cleaner';
			} else {
				$user_type = 'client';
			}
		}
		if (empty($user_id) && !empty($this->data['user_info'])) {
			$user_id = $this->data['user_info']['id'];
		}

		if ($user_type == 'no_cleaner') {
			if (empty($this->data['user_info']['is_cleaner'])) {
				return false;
			}
			$this->db->where('cleaner_id', 0);
			$this->db->where('(status = 2 AND start_date > '.time().')');
		} else {
			$this->db->where($user_type.'_id', $user_id);
		}
		return $this->db
			->where('id', $order_id)
			->order_by('id', 'desc')
			->get('orders')
			->row_array();
	}

	function get_order_payments($order_id) {
		return $this->db
			->where('order_id', $order_id)
			->where('status', 1)
			->order_by('id', 'desc')
			->get('payments');
	}

	function get_all_orders($status = '0', $user_id = false, $user_type = false) {
		if (empty($user_type)) {
			if (!empty($this->data['user_info']['is_cleaner'])) {
				$user_type = 'cleaner';
			} else {
				$user_type = 'client';
			}
		}
		if (empty($user_id) && !empty($this->data['user_info'])) {
			$user_id = $this->data['user_info']['id'];
		}

		if ($status == 0) {
			$this->db->where('cleaner_id', 0);
			$this->db->where_in('status', array(0,1,2));
			$this->db->where('start_date >', time() + 86400);
		} elseif ($status == 1) {
			$this->db->where('cleaner_id !=', 0);
			$this->db->where('(status = 2 OR (status = 1 AND start_date > '.(time() + 86400).'))');
		} elseif ($status == 3) {
			$this->db->where('cleaner_id', 0);
			$this->db->where('((status = 2 AND start_date > '.time().') OR (status IN (1) AND start_date > '.(time() + 86400).') )');
		} else {
			$this->db->where('(status > 2 OR (status IN (0,1) AND start_date < '.(time() + 86400).') OR (status = 2 AND start_date < '.time().' AND cleaner_id = 0))');
		}

		if ($status != 3) {
			$this->db->where($user_type.'_id', $user_id);
		}

		return $this->db
			->order_by('id', 'desc')
			->get('orders');
	}

	function get_all_cleaners($zip = false) {
		if (!empty($zip)) {
			$this->db->like('zip', ','.$zip.',');
		}
		return $this->db
			->where('active', 1)
			->where('is_cleaner', 1)
			->get('users')
			->result_array();
	}

	function order_form() {
		if (!$this->ion_auth->logged_in()) {
			//------------------------------------------
			$this->form
				->text('email', array(
					'valid_rules' => 'required|trim|xss_clean|max_length[150]|valid_email',
					'label'       => lang('create_user_email_label'),
					'width'       => 12, 'group_class' => 'col-sm-6'
				))
				->password('password', array(
					'valid_rules' => 'required|min_length['.$this->config->item('min_password_length', 'ion_auth').']|max_length['.$this->config->item('max_password_length', 'ion_auth').']',
					'label'       => $this->lang->line('create_user_password_label'),
					'width'       => 12, 'group_class' => 'col-sm-6'<commit_msg>sort cleaners<commit_after><?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order_model extends CI_Model {

	public $mrh_login = 'plecle';

	public $mrh_pass1 = '<PASSWORD>';

	public $mrh_pass2 = '<PASSWORD>';

	public $frequency = array(
		'once'          => 'Только один раз',
		'every_week'    => 'Еженедельно',
		'every_2_weeks' => 'Каждые две недели',
	);

	public $duration = array(
		'1'   => '1 час',
		'1.5' => '1.5 часа',
		'2'   => '2 часа',
		'2.5' => '2.5 часа',
		'3'   => '3 часа',
		'3.5' => '3.5 часа',
		'4'   => '4 часа',
		'4.5' => '4.5 часа',
	);

	public $special = array(
		'need_ironing' => 'Нужна глажка',
		'have_pets'    => 'Есть домашнее животное',
	);

	function __construct() {
		parent::__construct();
		$this->load->database();
	}

	function get_user_order($order_id, $user_id = false, $user_type = false) {
		if (empty($user_type)) {
			if (!empty($this->data['user_info']['is_cleaner'])) {
				$user_type = 'cleaner';
			} else {
				$user_type = 'client';
			}
		}
		if (empty($user_id) && !empty($this->data['user_info'])) {
			$user_id = $this->data['user_info']['id'];
		}

		if ($user_type == 'no_cleaner') {
			if (empty($this->data['user_info']['is_cleaner'])) {
				return false;
			}
			$this->db->where('cleaner_id', 0);
			$this->db->where('(status = 2 AND start_date > '.time().')');
		} else {
			$this->db->where($user_type.'_id', $user_id);
		}
		return $this->db
			->where('id', $order_id)
			->order_by('id', 'desc')
			->get('orders')
			->row_array();
	}

	function get_order_payments($order_id) {
		return $this->db
			->where('order_id', $order_id)
			->where('status', 1)
			->order_by('id', 'desc')
			->get('payments');
	}

	function get_all_orders($status = '0', $user_id = false, $user_type = false) {
		if (empty($user_type)) {
			if (!empty($this->data['user_info']['is_cleaner'])) {
				$user_type = 'cleaner';
			} else {
				$user_type = 'client';
			}
		}
		if (empty($user_id) && !empty($this->data['user_info'])) {
			$user_id = $this->data['user_info']['id'];
		}

		if ($status == 0) {
			$this->db->where('cleaner_id', 0);
			$this->db->where_in('status', array(0,1,2));
			$this->db->where('start_date >', time() + 86400);
		} elseif ($status == 1) {
			$this->db->where('cleaner_id !=', 0);
			$this->db->where('(status = 2 OR (status = 1 AND start_date > '.(time() + 86400).'))');
		} elseif ($status == 3) {
			$this->db->where('cleaner_id', 0);
			$this->db->where('((status = 2 AND start_date > '.time().') OR (status IN (1) AND start_date > '.(time() + 86400).') )');
		} else {
			$this->db->where('(status > 2 OR (status IN (0,1) AND start_date < '.(time() + 86400).') OR (status = 2 AND start_date < '.time().' AND cleaner_id = 0))');
		}

		if ($status != 3) {
			$this->db->where($user_type.'_id', $user_id);
		}

		return $this->db
			->order_by('id', 'desc')
			->get('orders');
	}

	function get_all_cleaners($zip = false) {
		$sql = 'SELECT u.*, SUM(IFNULL(m.amount,0)) as rating
			FROM users AS u
			LEFT JOIN marks AS m ON u.id = m.cleaner_id
			WHERE u.active = 1
			AND u.is_cleaner = 1';
		if (!empty($zip)) {
		$sql .= ' AND u.zip LIKE \'%,'.$zip.',%\'';
		}
		$sql .= ' GROUP BY u.id ORDER BY rating desc';
		return $this->db
			->query($sql)
			->result_array();
	}

	function order_form() {
		if (!$this->ion_auth->logged_in()) {
			//------------------------------------------
			$this->form
				->text('email', array(
					'valid_rules' => 'required|trim|xss_clean|max_length[150]|valid_email',
					'label'       => lang('create_user_email_label'),
					'width'       => 12, 'group_class' => 'col-sm-6'
				))
				->password('password', array(
					'valid_rules' => 'required|min_length['.$this->config->item('min_password_length', 'ion_auth').']|max_length['.$this->config->item('max_password_length', 'ion_auth').']',
					'label'       => $this->lang->line('create_user_password_label'),
					'width'       => 12, 'group_class' => 'col-sm-6'
{'fraction_non_alphanumeric': 0.24611631788419566, 'fraction_numerical': 0.020926948260367183, 'mean_word_length': 3.337416481069042, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 185, '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': '7038870', 'n_tokens_mistral': 3471, 'n_tokens_neox': 3052, 'n_words': 563}