Commit 3c284538 authored by Simonas's avatar Simonas

pre save recommendation

parent e6ea63ab
......@@ -143,12 +143,13 @@ class Biuro_Contacts_Activator {
phone varchar(128) DEFAULT '',
city varchar(255) DEFAULT null,
city_id int DEFAULT null,
recommended_name tinytext,
recommended_email varchar(128) DEFAULT '',
recommended_phone varchar(128) DEFAULT '',
recommended_city varchar(255) DEFAULT null,
recommended_city_id int DEFAULT null,
confirm tinyint DEFAULT 0,
allow tinyint DEFAULT 0,
recommend_name tinytext,
recommend_email varchar(128) DEFAULT '',
recommend_phone varchar(128) DEFAULT '',
recommend_city varchar(255) DEFAULT null,
recommend_city_id int DEFAULT null,
recommend_allow tinyint DEFAULT 0,
referer text DEFAULT null,
request text DEFAULT null,
PRIMARY KEY (id)
......
......@@ -181,6 +181,9 @@ class Biuro_Contacts {
$this->loader->add_action('admin_post_position_post', $plugin_public, 'position_post');
$this->loader->add_action('admin_post_nopriv_position_post', $plugin_public, 'position_post');
$this->loader->add_action('admin_post_recommend_post', $plugin_public, 'recommend_post');
$this->loader->add_action('admin_post_nopriv_recommend_post', $plugin_public, 'recommend_post');
// $this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' );
/**
......
......@@ -44,14 +44,14 @@ class Biuro_Contacts_Public {
'employees' => ['name', 'phone', 'email'],
'employers' => ['name', 'phone', 'email'],
'position' => ['name', 'phone', 'email', 'city', 'city_id', 'message', 'confirm', 'job_id', 'cv'],
'recommend' => ['name', 'phone', 'email', 'city'],
'recommend' => ['name', 'phone', 'email', 'city', 'city_id', 'allow', 'recommend_name', 'recommend_phone', 'recommend_email', 'recommend_city', 'recommend_city_id', 'recommend_allow'],
];
const DB_NAMES = [
'employees' => ['name', 'phone', 'email'],
'employers' => ['name', 'phone', 'email'],
'position' => ['name', 'phone', 'email', 'city', 'city_id', 'message', 'confirm', 'job_id'],
'recommend' => ['name', 'phone', 'email', 'city'],
'recommend' => ['name', 'phone', 'email', 'city', 'city_id', 'allow', 'recommend_name', 'recommend_phone', 'recommend_email', 'recommend_city', 'recommend_city_id', 'recommend_allow'],
];
const BIURO_INSIGHTLY =[
......@@ -160,6 +160,7 @@ class Biuro_Contacts_Public {
switch($key) {
case 'name':
case 'recommend_name':
return (!$value) ? $required : $success;
......@@ -210,6 +211,53 @@ class Biuro_Contacts_Public {
return $success;
endif;
case 'recommend_phone':
if (!$value && !is_email($post['recommend_email'])):
return [
'status' => 'error',
'message' => 'Friend phone or email field is required',
'translation' => __('Friend phone or email field is required', 'biuro-contacts')
];
endif;
if (!$value):
return $empty;
endif;
if ( strlen($value) < 7 || !preg_match('/^[\d|\s|\+\-]+$/', $value) ):
return [
'status' => 'error',
'message' => 'Incorrect phone number',
'translation' => __('Incorrect phone number', 'biuro-contacts')
];
endif;
return $success;
case 'recommend_email':
if (!$post['recommend_phone'] && !$value):
return [
'status' => 'error',
'message' => 'Friend email or phone field is required',
'translation' => __('Friend email or phone field is required', 'biuro-contacts')
];
endif;
if (!$post['recommend_phone'] && !is_email($value)):
return [
'status' => 'error',
'message' => 'Email format is incorrect',
'translation' => __('Email format is incorrect', 'biuro-contacts')
];
else:
if (!$value):
return $empty;
endif;
return $success;
endif;
case 'agree':
if ($value != "1"):
return [
......@@ -221,9 +269,33 @@ class Biuro_Contacts_Public {
return $success;
case 'allow':
if ($value != "1"):
return [
'status' => 'error',
'message' => 'You agree with something',
'translation' => __('You agree with something', 'biuro-contacts')
];
endif;
return $success;
case 'recommend_allow':
if ($value != "1"):
return [
'status' => 'error',
'message' => 'Your friend agrees with conditions',
'translation' => __('Your friend agrees with conditions', 'biuro-contacts')
];
endif;
return $success;
case 'cv':
case 'city':
case 'city_id':
case 'recommend_city':
case 'recommend_city_id':
case 'message':
case 'confirm':
case 'job_id':
......@@ -240,9 +312,13 @@ class Biuro_Contacts_Public {
case 'name':
case 'phone':
case 'city':
case 'recommend_name':
case 'recommend_phone':
case 'recommend_city':
case 'company':
return sanitize_text_field($value);
case 'email':
case 'recommend_email':
return sanitize_email($value);
case 'message':
return sanitize_textarea_field($value);
......@@ -250,6 +326,9 @@ class Biuro_Contacts_Public {
return sanitize_text_field($value);
case 'agree':
case 'city_id':
case 'recommend_city_id':
case 'allow':
case 'recommend_allow':
case 'job_id':
case 'confirm':
return filter_var($value, FILTER_VALIDATE_INT) ? $value : 0;
......@@ -669,7 +748,7 @@ class Biuro_Contacts_Public {
curl_close($ch);
return json_decode($return, true);
}
}
public static function sendPost($firstName, $lastName, $phone, $email) {
$service_url = 'https://api.insight.ly/v2.2/Leads';
......@@ -948,7 +1027,6 @@ class Biuro_Contacts_Public {
exit;
}
public function recommend_form( $attr = array() ) {
ob_start();
......@@ -965,6 +1043,79 @@ class Biuro_Contacts_Public {
return $output;
} // position_form()
public function recommend_post() {
$nonce = $_POST['_wpnonce'];
$referer = $_POST['_wp_http_referer'];
if ( !isset( $nonce ) || !wp_verify_nonce($nonce, 'recommend_post_nonce' )) {
wp_redirect( $referer );
exit;
}
if ( $referer && substr($referer, -1) == '?') {
$referer = substr($referer, 0, -1);
}
$canSubmit = true;
$str = 'recommend';
$data = [
'created' => current_time('Y-m-d H:i:s'),
];
foreach (static::FIELDS[$str] as $key) {
$value = static::getValue($key, $_POST[$key]);
$validation = static::validate($str, $key, $value, $_POST);
if ($validation['status'] == 'error'):
$canSubmit = false;
endif;
if ( in_array($key, static::DB_NAMES[$str])):
$data[$key] = $value;
endif;
$_SESSION[$str . '--' . $key . '-value'] = $value;
$_SESSION[$str . '--' . $key . '-status'] = $validation['status'];
$_SESSION[$str . '--' . $key . '-message'] = $validation['message'];
}
if ($canSubmit && !static::isCaptchaValid($_POST, $str)) {
$_SESSION[$str . '--captcha-status'] = 'error';
wp_redirect( $referer );
exit;
}
$hash = '#action';
if ($canSubmit):
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
$data['request'] = ($_SESSION['request'] !== null) ? $_SESSION['request'] : null;
// $insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s', '%s', '%d', '%s' ), 'biuro_employers');
// if (!in_array(strstr($_SERVER['SERVER_NAME'], '.biuro', true), array('dev'))):
// static::sendEmail( static::emailContent($data['name'], static::BIURO_INSIGHTLY[get_current_blog_id()], $data['phone'], $data['email']), $data['name']);
// $return = static::sendPost($data['name'], static::BIURO_INSIGHTLY[get_current_blog_id()], $data['phone'], $data['email']);
// if ($return['LEAD_ID']):
// static::update_row_in_db(['lead_id' => $return['LEAD_ID']], $insert_id, ['%d'] , 'biuro_employers');
// endif;
// endif;
// $_SESSION[$str . '--step'] = 2;
// $_SESSION[$str . '--id'] = $insert_id;
// $_SESSION['employers--s'] = 1;
endif;
wp_redirect( $referer . $hash );
exit;
}
/**
* @method getContacts
......@@ -972,8 +1123,7 @@ class Biuro_Contacts_Public {
* @param WP_REST_Request $request
* @return json;
*/
public static function getContacts(WP_REST_Request $request)
{
public static function getContacts(WP_REST_Request $request) {
global $wpdb;
$params = $request->get_params();
......@@ -993,8 +1143,7 @@ class Biuro_Contacts_Public {
return $wpdb->get_results($sql, ARRAY_A);
}
public static function fetchRow($primaryKey, $table = 'biuro_employees')
{
public static function fetchRow($primaryKey, $table = 'biuro_employees') {
global $wpdb;
if(!is_numeric($primaryKey)) {
......
......@@ -25,6 +25,12 @@
}
}
.c-form--recommend { padding: 28px 20px 20px; border-radius: 3px; background-color: #ffffff;
@media (--min--medium) {
margin: -40px -15px 0; box-shadow: 0 1px 31px -23px #6A7481;
}
}
.c-form--success { margin: -28px -20px 20px; padding: 28px 20px 20px; border-radius: 3px 3px 0 0; text-align: center; color: #27b199; font-style: 18px; line-height: 25px; background: #e5fdf9; font-weight: 500;
@media (--min--medium) {
margin: -38px -35px 20px; padding: 28px 35px 20px;
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -148,7 +148,7 @@
<?php
endif;
?>
<script src="/wp-content/themes/biuro/js/main-1618cb33.min.js" async></script>
<script src="/wp-content/themes/biuro/js/main.min.js" async></script>
<?php
// global $time_start;
......
......@@ -31,16 +31,16 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core-bacf93be7c.min.css'; ?></style>
<style><?php include 'css/core.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
</noscript>
<?php wp_head(); ?>
......
......@@ -31,15 +31,15 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core-bacf93be7c.min.css'; ?></style>
<style><?php include 'css/core.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
</noscript>
<?php wp_head(); ?>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -224,10 +224,12 @@ if (search) {
}, false);
}
const node = document.getElementById('form-city');
const cityID = document.getElementById('form-city-id');
const setCityAwesomplete = (node, cityID) => {
if (!node || !cityID) {
return;
}
if (node) {
const nodeBox = new Awesomplete(node, {
minChars: 0,
maxItems: 1000,
......@@ -263,7 +265,10 @@ if (node) {
}
}
});
}
};
setCityAwesomplete(document.getElementById('form-city'), document.getElementById('form-city-id'));
setCityAwesomplete(document.getElementById('recommend-form-city'), document.getElementById('recommend-form-city-id'));
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
......
This diff is collapsed.
......@@ -61,9 +61,11 @@
</div><!-- .c-contact-landing-1 -->
<?php
/*
if ( is_active_sidebar( 'front_page_feedbacks' ) ) :
dynamic_sidebar( 'front_page_feedbacks' );
endif;
*/
?>
</main><!-- .l-main -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment