Commit 8a5906cd authored by Simonas's avatar Simonas

Merge branch 'design'

parents a8456448 5560195a
......@@ -38,6 +38,7 @@ class Biuro_Contacts_Activator {
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
self::create_db_employees();
self::create_db_employers();
restore_current_blog();
}
} else {
......@@ -70,6 +71,7 @@ class Biuro_Contacts_Activator {
updated datetime DEFAULT '0000-00-00 00:00:00',
confirm tinyint DEFAULT 0,
job_id int DEFAULT null,
referer varchar(255) DEFAULT null,
PRIMARY KEY (id)
) $charset_collate;";
......@@ -84,5 +86,42 @@ class Biuro_Contacts_Activator {
add_option( 'biuro-contacts_db_version', $plugin_name_db_version );
}
}
public static function create_db_employers() {
global $wpdb;
$table_name = $wpdb->prefix . "biuro_employers";
$version = get_option( 'biuro-employers_db_version', '1.0' );
if( $wpdb->get_var( "show tables like '{$table_name}'" ) != $table_name ||
version_compare( $version, '1.0' ) < 0 ) {
$charset_collate = $wpdb->get_charset_collate();
$sql[] = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
created datetime DEFAULT '0000-00-00 00:00:00',
name tinytext,
email varchar(128) DEFAULT '',
phone varchar(128) DEFAULT '',
company varchar(255) DEFAULT null,
message longtext DEFAULT null,
updated datetime DEFAULT '0000-00-00 00:00:00',
confirm tinyint DEFAULT 0,
referer varchar(255) DEFAULT null,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
/**
* It seems IF NOT EXISTS isn't needed if you're using dbDelta - if the table already exists it'll
* compare the schema and update it instead of overwriting the whole table.
*
* @link https://code.tutsplus.com/tutorials/custom-database-tables-maintaining-the-database--wp-28455
*/
dbDelta( $sql );
add_option( 'biuro-employers_db_version', $plugin_name_db_version );
}
}
}
......@@ -112,20 +112,22 @@ class Biuro_Contacts_Public {
}
public static function insert_row_to_db($data, $format) {
public static function insert_row_to_db($data, $format, $customName = 'biuro_employees')
{
global $wpdb;
$table = $wpdb->prefix . 'biuro_employees';
$table = $wpdb->prefix . $customName;
$wpdb->insert( $table, $data, $format );
return $wpdb->insert_id;
}
public static function update_row_in_db($data, $insert_id, $format) {
public static function update_row_in_db($data, $insert_id, $format, $customName = 'biuro_employees')
{
global $wpdb;
$table = $wpdb->prefix . 'biuro_employees';
$table = $wpdb->prefix . $customName;
$where = array('id' => $insert_id);
......@@ -213,6 +215,7 @@ class Biuro_Contacts_Public {
case 'message':
case 'confirm':
case 'job_id':
//?case 'company':
return $empty;
}
......@@ -227,6 +230,7 @@ class Biuro_Contacts_Public {
case 'name':
case 'phone':
case 'city':
case 'company':
return sanitize_text_field($value);
case 'email':
return sanitize_email($value);
......@@ -269,7 +273,9 @@ class Biuro_Contacts_Public {
}
if ($canSubmit):
$insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s' ));
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
$insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s', '%s' ));
$_SESSION[$str . '--step'] = 2;
$_SESSION[$str . '--id'] = $insert_id;
......@@ -338,8 +344,10 @@ class Biuro_Contacts_Public {
$_SESSION['employee_file_error'] = $movefile['error'];
}
}
static::update_row_in_db($data, $_SESSION['employees--id'], array( '%s', '%d', '%s', '%d', '%s', '%s' ));
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
static::update_row_in_db($data, $_SESSION['employees--id'], ['%s', '%d', '%s', '%d', '%s', '%s', '%s', ]);
endif;
......@@ -411,7 +419,10 @@ class Biuro_Contacts_Public {
}
if ($canSubmit):
// $insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s' ));
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
$insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s', '%s' ), 'biuro_employers');
$_SESSION[$str . '--step'] = 2;
$_SESSION[$str . '--id'] = $insert_id;
......@@ -422,32 +433,22 @@ class Biuro_Contacts_Public {
elseif ($_POST['s'] == "2"):
$data = [
'city' => static::getValue('city', $_POST['city']),
'city_id' => static::getValue('city_id', $_POST['city_id']),
'company' => static::getValue('city', $_POST['company']),
'message' => static::getValue('message', $_POST['message']),
'confirm' => static::getValue('confirm', $_POST['confirm']),
'updated' => current_time('Y-m-d H:i:s')
];
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
static::update_row_in_db($data, $_SESSION['employers--id'], ['%s', '%s', '%d', '%s', '%s'] , 'biuro_employers');
# isvalom klaidos teksta;
unset($_SESSION[$str.'file_error']);
// # upload file
// if($_FILES) {
// # gali nusirody: 'mimes' => array('csv' => 'text/csv')
// $movefile = wp_handle_upload($_FILES['cv'], [
// 'test_form' => false,
// //'unique_filename_callback' => 'custom_file_name'
// ]);
// if ( $movefile && ! isset( $movefile['error'] ) ) {
// $data['cv'] = static::getValue('cv', $movefile['url']);
// } else {
// $_SESSION['employee_file_error'] = $movefile['error'];
// }
// }
// static::update_row_in_db($data, $_SESSION['employers--id'], array( '%s', '%d', '%s', '%d', '%s', '%s' ));
debug($data);
exit();
//debug($data);
//exit();
endif;
......@@ -488,6 +489,7 @@ class Biuro_Contacts_Public {
$nonce = $_POST['_wpnonce'];
$referer = $_POST['_wp_http_referer'];
if ( !isset( $nonce ) || !wp_verify_nonce($nonce, 'position_post_nonce' ) ) {
wp_redirect( $referer );
......@@ -499,6 +501,7 @@ class Biuro_Contacts_Public {
if ($_POST['s'] == "1"):
$_SESSION['position--step'] = 2;
$_SESSION['position--s'] = 1;
elseif ($_POST['s'] == "2"):
......@@ -546,12 +549,16 @@ class Biuro_Contacts_Public {
$data['cv'] = static::getValue('cv', $movefile['url']);
} else {
$_SESSION['position_file_error'] = $movefile['error'];
//po klaidos setinimo reikia redirecto?
}
}
$data['referer'] = ($_SESSION['referer'] !== null) ? $_SESSION['referer'] : null;
$insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%s' ));
$insert_id = static::insert_row_to_db($data, array( '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%s', '%s' ));
$_SESSION['employee--id'] = $insert_id;
$_SESSION['position--s'] = 2;
endif;
......@@ -588,4 +595,18 @@ class Biuro_Contacts_Public {
where ". $orderBy. " >= '". $from. "' ORDER BY ". $orderBy ." DESC LIMIT 50";
return $wpdb->get_results($sql, ARRAY_A);
}
public static function fetchRow($primaryKey, $table = 'biuro_employees')
{
global $wpdb;
if(!is_numeric($primaryKey)) {
exit;
}
$sql = "SELECT * FROM `" . $wpdb->prefix. $table. "`
where id = " . $primaryKey . " LIMIT 1";
return $wpdb->get_row($sql, ARRAY_A);
}
}
......@@ -21,9 +21,30 @@ if ( ! defined( 'WPINC' ) ) die;
?>
<?php
# sitie po submito;
$nameValue = $_SESSION['position--name-value'];
$nameStatus = $_SESSION['position--name-status'];
$nameMessage = $_SESSION['position--name-message'];
$phoneValue = $_SESSION['position--phone-value'];
$phoneStatus = $_SESSION['position--phone-status'];
$phoneMessage = $_SESSION['position--phone-message'];
$emailValue = $_SESSION['position--email-value'];
$emailStatus = $_SESSION['position--email-status'];
$emailMessage = $_SESSION['position--email-message'];
if(is_numeric($_SESSION['employees--id']) && $_SESSION['position--s'] === 1) {
$employeeData = Biuro_Contacts_Public::fetchRow($_SESSION['employees--id']);
$nameValue = $employeeData['name'];
$phoneValue = $employeeData['phone'];
$emailValue = $employeeData['email'];
$city = $employeeData['city'];
# city reiks uzdet turbut?
}
?>
<div class="c-form--row">
<label class="c-form--label" for="form-name"><?php _e('Name, surname', 'biuro-contacts'); ?></label>
......@@ -37,11 +58,7 @@ if ( ! defined( 'WPINC' ) ) die;
<?php endif; ?>
</div><!-- .c-form--row -->
<?php
$phoneValue = $_SESSION['position--phone-value'];
$phoneStatus = $_SESSION['position--phone-status'];
$phoneMessage = $_SESSION['position--phone-message'];
?>
<div class="c-form--row">
<label class="c-form--label" for="form-phone"><?php _e('Phone no.', 'biuro-contacts'); ?></label>
<div class="c-form--input-wrap <?php if ($phoneStatus) { echo "c-form--input-wrap--$phoneStatus"; } ?>">
......@@ -54,11 +71,7 @@ if ( ! defined( 'WPINC' ) ) die;
<?php endif; ?>
</div><!-- .c-form--row -->
<?php
$emailValue = $_SESSION['position--email-value'];
$emailStatus = $_SESSION['position--email-status'];
$emailMessage = $_SESSION['position--email-message'];
?>
<div class="c-form--row">
<label class="c-form--label" for="form-email"><?php _e('Email address', 'biuro-contacts'); ?></label>
<div class="c-form--input-wrap <?php if ($emailStatus) { echo "c-form--input-wrap--$emailStatus"; } ?>">
......
......@@ -34,3 +34,15 @@ if ( ! defined( 'WPINC' ) ) die;
<input type="hidden" name="action" value="position_post">
<?php wp_nonce_field('position_post_nonce'); ?>
</form>
<?php if($_SESSION['position--s'] == 1) {
?> ok 1
<?php
unset($_SESSION['position--s']);
}?>
<?php if($_SESSION['position--s'] == 2) {
?> ok 2
<?php
unset($_SESSION['position--s']);
}?>
\ No newline at end of file
......@@ -459,6 +459,10 @@ function start_session() {
if(!session_id()) {
session_start();
}
if(!isset($_SESSION['referer']) && $_SERVER['HTTP_REFERER'] != null) {
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
}
}
......
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