<commit_before><?php

/*
|--------------------------------------------------------------------------
|   Oculus XMS
|--------------------------------------------------------------------------
|
|   This file is part of the Oculus XMS Framework package.
|	
|	(c) <NAME> <<EMAIL>>
|	
|	For the full copyright and license information, please view the LICENSE
|	file that was distributed with this source code.
|	
*/

namespace Front\Model\Affiliate;
use Oculus\Engine\Model;
use Oculus\Library\Mail as Mail;

class Affiliate extends Model {
    public function addAffiliate($data) {
        $this->db->query("
			INSERT INTO {$this->db->prefix}affiliate 
			SET 
				firstname = '" . $this->db->escape($data['firstname']) . "', 
				lastname = '" . $this->db->escape($data['lastname']) . "', 
				email = '" . $this->db->escape($data['email']) . "', 
				telephone = '" . $this->db->escape($data['telephone']) . "', 
				salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', 
				password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', 
				company = '" . $this->db->escape($data['company']) . "', 
				address_1 = '" . $this->db->escape($data['address_1']) . "', 
				address_2 = '" . $this->db->escape($data['address_2']) . "', 
				city = '" . $this->db->escape($data['city']) . "', 
				postcode = '" . $this->db->escape($data['postcode']) . "', 
				country_id = '" . (int)$data['country_id'] . "', 
				zone_id = '" . (int)$data['zone_id'] . "', 
				code = '" . $this->db->escape(uniqid()) . "', 
				commission = '" . (float)$this->config->get('config_commission') . "', 
				tax = '" . $this->db->escape($data['tax']) . "', 
				payment = '" . $this->db->escape($data['payment']) . "', 
				`check` = '" . $this->db->escape($data['check']) . "', 
				paypal = '" . $this->db->escape($data['paypal']) . "', 
				bank_name = '" . $this->db->escape($data['bank_name']) . "', 
				bank_branch_number = '" . $this->db->escape($data['bank_branch_number']) . "', 
				bank_swift_code = '" . $this->db->escape($data['bank_swift_code']) . "', 
				bank_account_name = '" . $this->db->escape($data['bank_account_name']) . "', 
				bank_account_number = '" . $this->db->escape($data['bank_account_number']) . "', 
				status = '1', 
				date_added = NOW()
		");
        
        $affiliate_id = $this->db->getLastId();
        
        $this->language->load('mail/affiliate');
        
        $subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
        
        $message = sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "\n\n";
        $message.= $this->language->get('text_approval') . "\n";
        $message.= $this->url->link('affiliate/login', '', 'SSL') . "\n\n";
        $message.= $this->language->get('text_services') . "\n\n";
        $message.= $this->language->get('text_thanks') . "\n";
        $message.= $this->config->get('config_name');
        
        $mail = new Mail();
        $mail->protocol = $this->config->get('config_mail_protocol');
        $mail->parameter = $this->config->get('config_mail_parameter');
        $mail->hostname = $this->config->get('config_smtp_host');
        $mail->username = $this->config->get('config_smtp_username');
        $mail->password = $this->config->get('config_smtp_password');
        $mail->port = $this->config->get('config_smtp_port');
        $mail->timeout = $this->config->get('config_smtp_timeout');
        $mail->setTo($this->request->post['email']);
        $mail->setFrom($this->config->get('config_email'));
        $mail->setSender($this->config->get('config_name'));
        $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
        $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
        $mail->send();
        
        $this->theme->trigger('affiliate_add', array('affiliate_id' => $affiliate_id));
    }
    
    public function editAffiliate($data) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				firstname = '" . $this->db->escape($data['firstname']) . "', 
				lastname = '" . $this->db->escape($data['lastname']) . "', 
				email = '" . $this->db->escape($data['email']) . "', 
				telephone = '" . $this->db->escape($data['telephone']) . "', 
				company = '" . $this->db->escape($data['company']) . "', 
				address_1 = '" . $this->db->escape($data['address_1']) . "', 
				address_2 = '" . $this->db->escape($data['address_2']) . "', 
				city = '" . $this->db->escape($data['city']) . "', 
				postcode = '" . $this->db->escape($data['postcode']) . "', 
				country_id = '" . (int)$data['country_id'] . "', 
				zone_id = '" . (int)$data['zone_id'] . "' 
				WHERE affiliate_id = '" . (int)$this->affiliate->getId() . "'
		");
        
        $this->theme->trigger('affiliate_edit', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function editPayment($data) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				tax = '" . $this->db->escape($data['tax']) . "', 
				payment = '" . $this->db->escape($data['payment']) . "', 
				`check` = '" . $this->db->escape($data['check']) . "', 
				paypal = '" . $this->db->escape($data['paypal']) . "', 
				bank_name = '" . $this->db->escape($data['bank_name']) . "', 
				bank_branch_number = '" . $this->db->escape($data['bank_branch_number']) . "', 
				bank_swift_code = '" . $this->db->escape($data['bank_swift_code']) . "', 
				bank_account_name = '" . $this->db->escape($data['bank_account_name']) . "', 
				bank_account_number = '" . $this->db->escape($data['bank_account_number']) . "' 
			WHERE affiliate_id = '" . (int)$this->affiliate->getId() . "'
		");
        
        $this->theme->trigger('affiliate_edit_payment', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function editPassword($email, $password) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', 
				password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "' 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        $this->theme->trigger('affiliate_edit_password', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function getAffiliate($affiliate_id) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE affiliate_id = '" . (int)$affiliate_id . "'
		");
        
        return $query->row;
    }
    
    public function getAffiliateByEmail($email) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        return $query->row;
    }
    
    public function getAffiliateByCode($code) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE code = '" . $this->db->escape($code) . "'
		");
        
        return $query->row;
    }
    
    public function getTotalAffiliatesByEmail($email) {
        $query = $this->db->query("
			SELECT COUNT(*) AS total 
			FROM {$this->db->prefix}affiliate 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        return $query->row['total'];
    }
}
<commit_msg>affiliate registration text email<commit_after><?php

/*
|--------------------------------------------------------------------------
|   Oculus XMS
|--------------------------------------------------------------------------
|
|   This file is part of the Oculus XMS Framework package.
|	
|	(c) <NAME> <<EMAIL>>
|	
|	For the full copyright and license information, please view the LICENSE
|	file that was distributed with this source code.
|	
*/

namespace Front\Model\Affiliate;
use Oculus\Engine\Model;
use Oculus\Library\Mail as Mail;

class Affiliate extends Model {
    public function addAffiliate($data) {
        $this->db->query("
			INSERT INTO {$this->db->prefix}affiliate 
			SET 
				firstname = '" . $this->db->escape($data['firstname']) . "', 
				lastname = '" . $this->db->escape($data['lastname']) . "', 
				email = '" . $this->db->escape($data['email']) . "', 
				telephone = '" . $this->db->escape($data['telephone']) . "', 
				salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', 
				password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', 
				company = '" . $this->db->escape($data['company']) . "', 
				address_1 = '" . $this->db->escape($data['address_1']) . "', 
				address_2 = '" . $this->db->escape($data['address_2']) . "', 
				city = '" . $this->db->escape($data['city']) . "', 
				postcode = '" . $this->db->escape($data['postcode']) . "', 
				country_id = '" . (int)$data['country_id'] . "', 
				zone_id = '" . (int)$data['zone_id'] . "', 
				code = '" . $this->db->escape(uniqid()) . "', 
				commission = '" . (float)$this->config->get('config_commission') . "', 
				tax = '" . $this->db->escape($data['tax']) . "', 
				payment = '" . $this->db->escape($data['payment']) . "', 
				`check` = '" . $this->db->escape($data['check']) . "', 
				paypal = '" . $this->db->escape($data['paypal']) . "', 
				bank_name = '" . $this->db->escape($data['bank_name']) . "', 
				bank_branch_number = '" . $this->db->escape($data['bank_branch_number']) . "', 
				bank_swift_code = '" . $this->db->escape($data['bank_swift_code']) . "', 
				bank_account_name = '" . $this->db->escape($data['bank_account_name']) . "', 
				bank_account_number = '" . $this->db->escape($data['bank_account_number']) . "', 
				status = '1', 
				date_added = NOW()
		");
        
        $affiliate_id = $this->db->getLastId();
        
        $this->language->load('mail/affiliate');
        
        $subject = sprintf($this->language->get('text_subject'), $this->config->get('config_name'));
        
        $message = sprintf($this->language->get('text_welcome'), $this->config->get('config_name')) . "\n\n";
        $message.= $this->language->get('text_approval') . "\n";
        $message.= $this->url->link('affiliate/login', '', 'SSL') . "\n\n";
        $message.= $this->language->get('text_services') . "\n\n";
        $message.= $this->language->get('text_thanks') . "\n";
        $message.= $this->config->get('config_name');
        
        $text = sprintf($this->language->get('email_template'), $message);

        $this->mailer->build(
        	html_entity_decode($subject, ENT_QUOTES, 'UTF-8'),
        	$this->request->post['email'],
        	$data['firstname'] . ' ' . $data['lastname'],
        	html_entity_decode($text, ENT_QUOTES, 'UTF-8'),
        	false,
        	true
        );
        
        $this->theme->trigger('affiliate_add', array('affiliate_id' => $affiliate_id));
    }
    
    public function editAffiliate($data) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				firstname = '" . $this->db->escape($data['firstname']) . "', 
				lastname = '" . $this->db->escape($data['lastname']) . "', 
				email = '" . $this->db->escape($data['email']) . "', 
				telephone = '" . $this->db->escape($data['telephone']) . "', 
				company = '" . $this->db->escape($data['company']) . "', 
				address_1 = '" . $this->db->escape($data['address_1']) . "', 
				address_2 = '" . $this->db->escape($data['address_2']) . "', 
				city = '" . $this->db->escape($data['city']) . "', 
				postcode = '" . $this->db->escape($data['postcode']) . "', 
				country_id = '" . (int)$data['country_id'] . "', 
				zone_id = '" . (int)$data['zone_id'] . "' 
				WHERE affiliate_id = '" . (int)$this->affiliate->getId() . "'
		");
        
        $this->theme->trigger('affiliate_edit', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function editPayment($data) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				tax = '" . $this->db->escape($data['tax']) . "', 
				payment = '" . $this->db->escape($data['payment']) . "', 
				`check` = '" . $this->db->escape($data['check']) . "', 
				paypal = '" . $this->db->escape($data['paypal']) . "', 
				bank_name = '" . $this->db->escape($data['bank_name']) . "', 
				bank_branch_number = '" . $this->db->escape($data['bank_branch_number']) . "', 
				bank_swift_code = '" . $this->db->escape($data['bank_swift_code']) . "', 
				bank_account_name = '" . $this->db->escape($data['bank_account_name']) . "', 
				bank_account_number = '" . $this->db->escape($data['bank_account_number']) . "' 
			WHERE affiliate_id = '" . (int)$this->affiliate->getId() . "'
		");
        
        $this->theme->trigger('affiliate_edit_payment', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function editPassword($email, $password) {
        $this->db->query("
			UPDATE {$this->db->prefix}affiliate 
			SET 
				salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', 
				password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "' 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        $this->theme->trigger('affiliate_edit_password', array('affiliate_id' => $this->affiliate->getId()));
    }
    
    public function getAffiliate($affiliate_id) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE affiliate_id = '" . (int)$affiliate_id . "'
		");
        
        return $query->row;
    }
    
    public function getAffiliateByEmail($email) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        return $query->row;
    }
    
    public function getAffiliateByCode($code) {
        $query = $this->db->query("
			SELECT * 
			FROM {$this->db->prefix}affiliate 
			WHERE code = '" . $this->db->escape($code) . "'
		");
        
        return $query->row;
    }
    
    public function getTotalAffiliatesByEmail($email) {
        $query = $this->db->query("
			SELECT COUNT(*) AS total 
			FROM {$this->db->prefix}affiliate 
			WHERE LOWER(email) = '" . $this->db->escape($this->encode->strtolower($email)) . "'
		");
        
        return $query->row['total'];
    }
}

{'fraction_non_alphanumeric': 0.2540425239110989, 'fraction_numerical': 0.0031652102112433773, 'mean_word_length': 2.642606516290727, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 404, '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': '3505179', 'n_tokens_mistral': 5390, 'n_tokens_neox': 4925, 'n_words': 617}