You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/models/logs_model.php

210 lines
6.6 KiB
PHTML

<?php
class Logs_model extends CI_Model {
var $insert_id = -1;
var $top_num = false;
var $log_res_id = false;
var $log_id = false;
var $log_action = false;
var $order_by = false;
var $log_datetime = false;
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
}
function init() {
$this->top_num = false;
$this->log_res_id = false;
$this->log_id = false;
$this->log_action = false;
$this->log_datetime = false;
$this->order_by = " ORDER BY il.log_id DESC ";
}
//获取日志详情
function read($log_id) {
$this->init();
$this->top_num = 1;
$this->log_id = " AND il.log_id =" . $this->HT->escape($log_id);
return $this->get_list();
}
//获取备份信息内容
function get_backup_list($is_id) {
$this->init();
$this->top_num = 16;
$this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id);
$this->log_action = " AND il.log_action = 'backup_info'";
return $this->get_list();
}
//获取所有备份信息内容
function get_all_backup_list($is_id) {
$this->init();
$this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id);
$this->log_action = " AND il.log_action = 'backup_info'";
return $this->get_list();
}
//获取最后操作信息
function get_last_edit($is_id) {
$this->init();
$this->top_num = 1;
$this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id);
return $this->get_list();
}
public function get_last_log() {
$this->init();
$this->top_num = 1;
$this->log_action = " AND il.log_action = 'backup_info'";
$this->order_by = " ORDER BY log_id DESC";
return $this->get_list();
}
public function get_last_cdn_update_info() {
$this->init();
$this->top_num = 1;
$this->log_action = " AND il.log_action = 'update_cdn'";
return $this->get_list();
}
public function get_uncdn_list($last_id = false) {
$map = '';
if ($last_id)
$map = " AND log_id > $last_id";
$sql = " SELECT log_id,is_sitecode,ic_url
FROM infoLogs
LEFT JOIN infoStructures ON is_id=log_res_id
LEFT JOIN infoContents ON is_ic_id=ic_id
WHERE ic_url != ''
AND log_action = 'backup_info'
$map
ORDER BY log_id ASC";
$query = $this->HT->query($sql);
return $query->result();
}
public function get_list_by_action() {
$this->init();
$this->top_num = 50;
$this->log_action = " AND il.log_action = 'send_mail'";
$this->order_by = " ORDER BY log_id DESC";
return $this->get_list();
}
function get_list() {
$this->top_num ? $sql = "SELECT TOP " . $this->top_num : $sql = "SELECT ";
$sql .= " il.log_id, \n"
. " il.log_action, \n"
. " il.log_res_id, \n"
. " il.log_ht_usercode, \n"
. " il.log_ht_username, \n"
. " il.log_content, \n"
. " il.log_datetime \n"
. "FROM infoLogs il \n"
. "WHERE 1=1 \n";
$this->log_res_id ? $sql.=$this->log_res_id : false;
$this->log_id ? $sql.=$this->log_id : false;
$this->log_action ? $sql.=$this->log_action : false;
$this->log_datetime ? $sql.=$this->log_datetime : false;
$this->order_by ? $sql.=$this->order_by : false;
$query = $this->HT->query($sql);
if ($this->top_num == 1) {
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
} else {
return $query->result();
}
}
//备份信息内容
function backup_project($p_id, $log_content) {
return $this->write('backup_project', $p_id, $log_content);
}
//备份信息内容
function backup($is_id, $log_content) {
return $this->write('backup_info', $is_id, $log_content);
}
//备份信息简介
function backup_summary($is_id, $log_content) {
return $this->write('backup_summary', $is_id, $log_content);
}
//添加信息
function add($is_id) {
return $this->write('add_info', $is_id);
}
//删除信息
function delete($is_id, $log_content) {
return $this->write('delete_info', $is_id, $log_content);
}
//移动信息
function move($is_id_array) {
//移动是很多个信息节点变动的在日志内容中记录所有几点id
return $this->write('move_info', 0, $is_id_array);
}
//写入测试,看看数据库写入是否正常
function write_test() {
$sql = "
INSERT INTO infoLogs
(
log_action
,log_res_id
,log_content
,log_ht_usercode
,log_ht_username
,log_datetime
)
VALUES
( ?,?,N?,?,?,GETDATE())
";
$query = $this->HT->query($sql, array('write_test', 0, '数据库写入测试', 'system', 'system'));
$this->insert_id = $this->HT->last_id('infoLogs');
if (empty($this->insert_id)) {
return false;
} else {
return $this->insert_id;
}
}
//写入操作日志
function write($log_action, $is_id, $log_content = '') {
$admin_info = $this->session->userdata('session_admin');
$sql = "INSERT INTO infoLogs \n"
. " ( \n"
. " log_action, log_res_id, log_content, log_ht_usercode, log_ht_username, \n"
. " log_datetime \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, ?, N?, ?, ?, GETDATE() \n"
. " )";
$query = $this->HT->query($sql, array($log_action, $is_id, $log_content, $admin_info['OPI_Code'], $admin_info['OPI_Name']));
$this->insert_id = $this->HT->last_id('infoLogs');
return $query;
//print_r($this->HT->queries);
}
function update($log_action, $log_res_id) {
$sql = "UPDATE infoLogs SET log_res_id=? WHERE log_action=?";
$query = $this->HT->query($sql, array($log_res_id, $log_action));
return $query;
}
}