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/controllers/info_amp.php

126 lines
4.0 KiB
PHP

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Info_amp extends CI_Controller
{
function __construct()
{
parent::__construct();
//$this->permission->is_admin();
$this->load->model('InfoMetas_model');
$this->load->model('InfoContents_model');
//CORS TEST
header('Access-Control-Allow-Origin:*');
}
public function save_amp()
{
$icid = $this->input->post('icid');
$json = $this->input->post('json');
$html = $this->input->post('html');
$css = $this->input->post('css');
$status = $this->input->post('status');
if ($icid && $json && $html) {
try {
//html
$meta = $this->InfoMetas_model->get($icid, 'AMP_BODY');
if ($meta === false) {
$this->InfoMetas_model->add($icid, 'AMP_BODY', $html);
} else {
$this->InfoMetas_model->update($icid, 'AMP_BODY', $html);
}
//json
$meta = $this->InfoMetas_model->get($icid, 'AMP_JSON');
if ($meta === false) {
$this->InfoMetas_model->add($icid, 'AMP_JSON', $json);
} else {
$this->InfoMetas_model->update($icid, 'AMP_JSON', $json);
}
//css
$meta = $this->InfoMetas_model->get($icid, 'AMP_CSS');
if ($meta === false) {
$this->InfoMetas_model->add($icid, 'AMP_CSS', $css);
} else {
$this->InfoMetas_model->update($icid, 'AMP_CSS', $css);
}
//status
$meta = $this->InfoMetas_model->get($icid, 'AMP_STATUS');
if ($meta === false) {
$this->InfoMetas_model->add($icid, 'AMP_STATUS', $status);
} else {
$this->InfoMetas_model->update($icid, 'AMP_STATUS', $status);
}
echo json_encode(array(
"succ" => true
));
} catch(Exception $e) {
echo json_encode(array(
"succ" => false,
"message" => "save_amp() -> ".$e->getMessage()
));
}
} else {
echo json_encode(array(
"succ" => false,
"message" => "save_amp() -> 参数传递错误。"
));
}
}
public function load_amp()
{
$icid = $this->input->post('icid');
if (!$icid) {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 参数传递错误。"
));
return false;
}
$json = $this->InfoMetas_model->get($icid, 'AMP_JSON');
$status = $this->InfoMetas_model->get($icid, 'AMP_STATUS');
if ($json) {
echo json_encode(array(
"succ" => true,
"icid" => $icid,
"json" => $json,
"status" => $status
));
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_amp() -> 无数据返回。"
));
}
}
public function load_info()
{
$icid = $this->input->post('icid');
if ($icid) {
$ic = $this->InfoContents_model->get_ic_contents2($icid);
if ($ic) {
echo json_encode(array(
"succ" => true,
"info" => $ic->ic_content
));
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_info() -> 无数据返回。"
));
}
} else {
echo json_encode(array(
"succ" => false,
"message" => "load_info() -> 参数传递错误。"
));
}
}
}