// New ticket form
add_shortcode( 'sf_questions_add_new', 'sf_questions_add_new_shortcode' );
function sf_questions_add_new_shortcode( $atts ) {
global $wpdb;
if(strlen($_POST['sf-name'])>0 && strlen($_POST['sf-description'])>0 && $_POST['sf-code']==$_SESSION['captcha']['code']) {
sf_add_question($_POST['sf-name'], $_POST['sf-status'], $_POST['sf-email'], $_POST['sf-description']);
$return = 'Ваше сообщение отправлено модератору сайта.
В ближайшее время модератор проверит это сообщение и опубликует его на сайте.
Вернуться в раздел консультация.';
} else {
$capt='';
$_SESSION['captcha'] = simple_php_captcha();
if(isset($_POST['sf-code'])) {
if($_POST['sf-code']!=$_SESSION['captcha']['code']) {
$capt = '
Неверно введена капча.
';
}
}
$return = '
';
$return .= 'Всего вопросов: '.sf_count_question().'
';
global $paged;
require_once('pagination.class.php');
$pagination_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(`id`) FROM `" . $wpdb->prefix . "sf_questions_questions` WHERE `status`='1'"));
if($pagination_count > 0) {
$this_page = ($paged && $paged > 0)? (int) $paged : 1; //get current page
$per_page = 8; //Records per page
$total_page = ceil($pagination_count/$per_page); //Total Pages
$pag = new pagination(); //initiate the pagination variable
//Set the pagination variable values
$pag->Items($pagination_count);
$pag->limit($per_page);
$pag->target("?page_id=15154");
$pag->currentPage($this_page);
$pag->parameterName('paged');
//Done with the pagination
//Now get the entries
//But before that a little anomaly checking
$list_start = ($this_page - 1)*$per_page;
if($list_start >= $pagination_count) //Start of the list should be less than pagination count
$list_start = ($pagination_count - $per_page);
if($list_start < 0) //list start cannot be negative
$list_start = 0;
$list_end = ($this_page * $per_page) - 1;
//Get the data from the database
$records = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->prefix . "sf_questions_questions`".$sql_where." WHERE `status`='1' ORDER BY `date_added` DESC LIMIT %d, %d", $list_start, $per_page));
if($records) {
$return .= '';
//loop through
foreach($records as $record) {
$q = sf_get_question($record->id);
$return .= '
|
|
'.$q['question']->name.'
, '.$q['question']->f_status.', '.substr( $q['question']->date_added, 0, 10).'
ВОПРОС: '.$q['question']->description.' |
|
Ответ:
'.$q['answers'][0]->comment.'
|
'.$q['answers'][0]->who_added.', '.substr( $q['answers'][0]->date_added, 0, 10).' |
|
';
}
$return .= '
';
}
else {
echo 'Something Went wrong! Check
';
}
}
}
/* $return .= '
|
|
NAME
, F_STATUS, WHEN
ВОПРОС: QUESTION |
|
Ответ:
ANSWER TEXT
|
WHO, WHEN |
|
';*/
return $return;
}
if ( function_exists( 'register_nav_menu' ) ) {
register_nav_menu( 'left_menu', 'Левое меню' );
}
if (!session_id()) {
session_start();
}