| Server IP : 14.225.204.176 / Your IP : 216.73.216.6 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/wit-crm/modules/sales_agent/controllers/ |
Upload File : |
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
* This class describes an authentication sales agent.
*/
class Authentication_sales_agent extends App_Controller
{
public $template = [];
public $data = [];
public $use_footer = true;
public $use_submenu = true;
public $use_navigation = true;
public function __construct()
{
parent::__construct();
$this->load->library('app_sale_agent_area_constructor');
}
/**
* { index }
*/
public function index()
{
$this->login();
}
// Added for backward compatibilies
public function admin()
{
redirect(admin_url('authentication'));
}
/**
* { login }
*/
public function login()
{
if (is_sale_agent_logged_in()) {
redirect(site_url('sales_agent/portal'));
}
$this->form_validation->set_rules('password', _l('clients_login_password'), 'required');
$this->form_validation->set_rules('email', _l('clients_login_email'), 'trim|required|valid_email');
if (get_option('use_recaptcha_customers_area') == 1
&& get_option('recaptcha_secret_key') != ''
&& get_option('recaptcha_site_key') != '') {
$this->form_validation->set_rules('g-recaptcha-response', 'Captcha', 'callback_recaptcha');
}
if ($this->form_validation->run() !== false) {
$this->load->model('Authentication_sale_agent_model');
$success = $this->Authentication_sale_agent_model->login(
$this->input->post('email'),
$this->input->post('password', false),
$this->input->post('remember'),
false
);
if (is_array($success) && isset($success['memberinactive'])) {
set_alert('danger', _l('inactive_account'));
redirect(site_url('sales_agent/authentication_sales_agent/login'));
} elseif ($success == false) {
set_alert('danger', _l('client_invalid_username_or_password'));
redirect(site_url('sales_agent/authentication_sales_agent/login'));
}
redirect(site_url('sales_agent/portal'));
}
if (get_option('allow_registration') == 1) {
$data['title'] = _l('clients_login_heading_register');
} else {
$data['title'] = _l('clients_login_heading_no_register');
}
$data['bodyclass'] = 'customers_login';
$this->data($data);
$this->view('portal/login');
$this->layout();
}
/**
* { register }
*/
public function register()
{
if (get_option('company_is_required') == 1) {
$this->form_validation->set_rules('company', _l('client_company'), 'required');
}
if (is_gdpr() && get_option('gdpr_enable_terms_and_conditions') == 1) {
$this->form_validation->set_rules(
'accept_terms_and_conditions',
_l('terms_and_conditions'),
'required',
['required' => _l('terms_and_conditions_validation')]
);
}
$this->form_validation->set_rules('firstname', _l('client_firstname'), 'required');
$this->form_validation->set_rules('lastname', _l('client_lastname'), 'required');
$this->form_validation->set_rules('email', _l('client_email'), 'trim|required|is_unique[' . db_prefix() . 'contacts.email]|valid_email');
$this->form_validation->set_rules('password', _l('clients_register_password'), 'required');
$this->form_validation->set_rules('passwordr', _l('clients_register_password_repeat'), 'required|matches[password]');
if (show_recaptcha_in_customers_area()) {
$this->form_validation->set_rules('g-recaptcha-response', 'Captcha', 'callback_recaptcha');
}
$custom_fields = get_custom_fields('customers', [
'show_on_client_portal' => 1,
'required' => 1,
]);
$custom_fields_contacts = get_custom_fields('contacts', [
'show_on_client_portal' => 1,
'required' => 1,
]);
foreach ($custom_fields as $field) {
$field_name = 'custom_fields[' . $field['fieldto'] . '][' . $field['id'] . ']';
if ($field['type'] == 'checkbox' || $field['type'] == 'multiselect') {
$field_name .= '[]';
}
$this->form_validation->set_rules($field_name, $field['name'], 'required');
}
foreach ($custom_fields_contacts as $field) {
$field_name = 'custom_fields[' . $field['fieldto'] . '][' . $field['id'] . ']';
if ($field['type'] == 'checkbox' || $field['type'] == 'multiselect') {
$field_name .= '[]';
}
$this->form_validation->set_rules($field_name, $field['name'], 'required');
}
if ($this->input->post()) {
if ($this->form_validation->run() !== false) {
$data = $this->input->post();
define('CONTACT_REGISTERING', true);
$clientid = $this->clients_model->add([
'billing_street' => $data['address'],
'billing_city' => $data['city'],
'billing_state' => $data['state'],
'billing_zip' => $data['zip'],
'billing_country' => is_numeric($data['country']) ? $data['country'] : 0,
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'contact_phonenumber' => $data['contact_phonenumber'] ,
'website' => $data['website'],
'title' => $data['title'],
'password' => $data['passwordr'],
'company' => $data['company'],
'vat' => isset($data['vat']) ? $data['vat'] : '',
'phonenumber' => $data['phonenumber'],
'country' => $data['country'],
'city' => $data['city'],
'address' => $data['address'],
'zip' => $data['zip'],
'state' => $data['state'],
'client_type' => 'agent',
'custom_fields' => isset($data['custom_fields']) && is_array($data['custom_fields']) ? $data['custom_fields'] : [],
'default_language' => (get_contact_language() != '') ? get_contact_language() : get_option('active_language'),
], true);
if ($clientid) {
hooks()->do_action('after_client_register', $clientid);
if (get_option('customers_register_require_confirmation') == '1') {
send_customer_registered_email_to_administrators($clientid);
$this->clients_model->require_confirmation($clientid);
set_alert('success', _l('customer_register_account_confirmation_approval_notice'));
redirect(site_url('authentication_sales_agent/login'));
}
$this->load->model('sales_agent/authentication_sale_agent_model');
$logged_in = $this->authentication_sale_agent_model->login(
$this->input->post('email'),
$this->input->post('password', false),
false,
false
);
$redUrl = site_url('sales_agent/portal');
if ($logged_in) {
hooks()->do_action('after_client_register_logged_in', $clientid);
set_alert('success', _l('clients_successfully_registered'));
} else {
set_alert('warning', _l('clients_account_created_but_not_logged_in'));
$redUrl = site_url('authentication_sales_agent/login');
}
redirect($redUrl);
}
}
}
$data['title'] = _l('clients_register_heading');
$data['bodyclass'] = 'register';
$this->data($data);
$this->view('portal/register');
$this->layout();
}
/**
* { forgot password }
*/
public function forgot_password()
{
if (is_affiliate_logged_in()) {
redirect(site_url());
}
$this->form_validation->set_rules(
'email',
_l('customer_forgot_password_email'),
'trim|required|valid_email|callback_contact_email_exists'
);
if ($this->input->post()) {
if ($this->form_validation->run() !== false) {
$this->load->model('Authentication_affiliate_model');
$success = $this->Authentication_affiliate_model->forgot_password($this->input->post('email'));
if (is_array($success) && isset($success['memberinactive'])) {
set_alert('danger', _l('inactive_account'));
} elseif ($success == true) {
set_alert('success', _l('check_email_for_resetting_password'));
} else {
set_alert('danger', _l('error_setting_new_password_key'));
}
redirect(site_url('authentication/forgot_password'));
}
}
$data['title'] = _l('customer_forgot_password');
$this->data($data);
$this->view('forgot_password');
$this->layout();
}
/**
* { reset password }
*
* @param <type> $staff The staff
* @param <type> $userid The userid
* @param <type> $new_pass_key The new pass key
*/
public function reset_password($staff, $userid, $new_pass_key)
{
$this->load->model('Authentication_affiliate_model');
if (!$this->Authentication_affiliate_model->can_reset_password($staff, $userid, $new_pass_key)) {
set_alert('danger', _l('password_reset_key_expired'));
redirect(site_url('authentication/login'));
}
$this->form_validation->set_rules('password', _l('customer_reset_password'), 'required');
$this->form_validation->set_rules('passwordr', _l('customer_reset_password_repeat'), 'required|matches[password]');
if ($this->input->post()) {
if ($this->form_validation->run() !== false) {
hooks()->do_action('before_user_reset_password', [
'staff' => $staff,
'userid' => $userid,
]);
$success = $this->Authentication_affiliate_model->reset_password(
0,
$userid,
$new_pass_key,
$this->input->post('passwordr', false)
);
if (is_array($success) && $success['expired'] == true) {
set_alert('danger', _l('password_reset_key_expired'));
} elseif ($success == true) {
hooks()->do_action('after_user_reset_password', [
'staff' => $staff,
'userid' => $userid,
]);
set_alert('success', _l('password_reset_message'));
} else {
set_alert('danger', _l('password_reset_message_fail'));
}
redirect(site_url('authentication/login'));
}
}
$data['title'] = _l('admin_auth_reset_password_heading');
$this->data($data);
$this->view('reset_password');
$this->layout();
}
/**
* { logout }
*/
public function logout()
{
$this->load->model('Authentication_sale_agent_model');
$this->Authentication_sale_agent_model->logout(false);
redirect(site_url('sales_agent/authentication_sales_agent/login'));
}
/**
* { recaptcha }
*
* @param string $str The string
*
* @return <type> ( description_of_the_return_value )
*/
public function recaptcha($str = '')
{
return do_recaptcha_validation($str);
}
/**
* { layout }
*
* @param boolean $notInThemeViewFiles Not in theme view files
*/
public function layout($notInThemeViewFiles = false)
{
/**
* Navigation and submenu
* @deprecated 2.3.2
* @var boolean
*/
$this->data['use_navigation'] = $this->use_navigation == true;
$this->data['use_submenu'] = $this->use_submenu == true;
/**
* @since 2.3.2 new variables
* @var array
*/
$this->data['navigationEnabled'] = $this->use_navigation == true;
$this->data['subMenuEnabled'] = $this->use_submenu == true;
/**
* Theme head file
* @var string
*/
$this->template['head'] = $this->load->view('portal/head', $this->data, true);
$GLOBALS['customers_head'] = $this->template['head'];
/**
* Load the template view
* @var string
*/
$module = CI::$APP->router->fetch_module();
$this->data['current_module'] = $module;
$viewPath = !is_null($module) || $notInThemeViewFiles ? $this->view : 'portal/' . $this->view;
$this->template['view'] = $this->load->view($viewPath, $this->data, true);
$GLOBALS['customers_view'] = $this->template['view'];
/**
* Theme footer
* @var string
*/
$this->template['footer'] = $this->use_footer == true
? $this->load->view('portal/footer', $this->data, true)
: '';
$GLOBALS['customers_footer'] = $this->template['footer'];
/**
* @deprecated 2.3.0
* Theme scripts.php file is no longer used since vresion 2.3.0, add app_customers_footer() in themes/[theme]/index.php
* @var string
*/
$this->template['scripts'] = '';
if (file_exists(VIEWPATH . 'portal/scripts.php')) {
if (ENVIRONMENT != 'production') {
trigger_error(sprintf('%1$s', 'Clients area theme file scripts.php file is no longer used since version 2.3.0, add app_customers_footer() in themes/[theme]/index.php. You can check the original theme index.php for example.'));
}
$this->template['scripts'] = $this->load->view('portal/scripts', $this->data, true);
}
/**
* Load the theme compiled template
*/
$this->load->view('portal/index', $this->template);
}
/**
* Sets view data
* @param array $data
* @return core/ClientsController
*/
public function data($data)
{
if (!is_array($data)) {
return false;
}
$this->data = array_merge($this->data, $data);
return $this;
}
/**
* Set view to load
* @param string $view view file
* @return core/ClientsController
*/
public function view($view)
{
$this->view = $view;
return $this;
}
/**
* Sets view title
* @param string $title
* @return core/ClientsController
*/
public function title($title)
{
$this->data['title'] = $title;
return $this;
}
/**
* Disables theme navigation
* @return core/ClientsController
*/
public function disableNavigation()
{
$this->use_navigation = false;
return $this;
}
/**
* Disables theme navigation
* @return core/ClientsController
*/
public function disableSubMenu()
{
$this->use_submenu = false;
return $this;
}
/**
* Disables theme footer
* @return core/ClientsController
*/
public function disableFooter()
{
$this->use_footer = false;
return $this;
}
}