โค้ด: เลือกทั้งหมด
<?php
namespace mm\set\controller;
use Symfony\Component\DependencyInjection\Container;
class pest {
var $u_action;
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, $root_path, $php_ext, $m_pest
) {
$this->config = $config;
$this->db = $db;
$this->request = $request;
$this->template = $template;
$this->user = $user;
$this->helper = $helper;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->m_pest = $m_pest;
$this->user->add_lang_ext('mm/set', 'simple');
}
public function pest($action) {
$error = array();
switch ($action) {
case 'show_pest':
$this->show_pest_all();
$this->template->assign_vars(array(
'SHOW_PEST' => true,
'U_ADDPEST' => $this->helper->route('mm_pest_controller', array('action' => 'add_pest'))
));
break;
case 'add_pest':
$pest = array(
'pest_name'=> $this->request->variable('pest_name', '', true),
'pest_detail'=> $this->request->variable('pest_detail', '', true),
'user_add_id'=> 0,
'time_add'=> time(),
'user_edit_id'=>0,
'time_edit'=> 0,
);
if ($this->request->is_set_post('submit')) {
$error = $this->validate_input($pest);
if (!$error) {
$insert_ok = $this->insert($pest);
if ($insert_ok) {
$mode_url_error = $this->helper->route('mm_pest_controller', array('action' => 'show_pest'));
meta_refresh(3, $mode_url_error);
trigger_error('<a href=" ' . $mode_url_error . ' ">' . $this->user->lang['INSERT_OK'] . '</a>', E_USER_WARNING);
}
}
}
$this->template->assign_vars(array(
'ERROR' => (sizeof($error)) ? implode('<br/>', $error) : '',
'SHOW_FORM_PEST' => true,
'A_ACTION' => $this->helper->route('mm_pest_controller', array('action' => 'add_pest'))
));
break;
default:
break;
}
$page_title = $this->user->lang('pest');
$this->template->assign_block_vars('navlinks', array(
'FORUM_NAME' => $page_title,
'U_VIEW_FORUM' => $this->helper->route('mm_set_controller', array('name' => 'mm')),
));
return $this->helper->render('pest.html', $this->user->lang('M_KASET'));
}
public function insert($pest) {
$sql ='INSERT INTO' . $this->m_pest. ''. $this->db->sql_build_array('INSERT',$pest);
$this->db->sql_query($sql);
return true;
}
public function validate_input($pest) {
$error = array();
if (empty($pest['pest_name'])) {
$error[] = $this->user->lang ['ERROR_PEST_NAME'];
}
return $error;
}
public function show_pest_all() {
$per_page = $this->request->variable('this', $this->config ['topics_per_page']);
$start = $this->request->variable('stat', 0);
$sql_arr = array(
'SELECT' => '*',
'FROM' => array(
$this->m_pest => 'pe'
),
);
$sql = $this->db->sql_build_query('SELECT', $sql_arr);
$result = $this->db->sql_query_limit($sql, $per_page, $start);
while ($row = $this->db->sql_fetchrow($result)) {
$this->template->assign_block_vars('pest', array(
'PEST_ID'=> $row['pest_id'],
'PEST_NAME'=> $row['pest_name'],
'PEST_DETAIL'=> $row['pest_detail'],
'USER_ADD_ID'=> $row ['user_add_id'],
'TIME_ADD'=> $row['time_add'],
'USER_EDIT_ID'=> $row['user_edit_id'],
'TIME_EDIT'=> $row['time_edit'],
));
}
}