Código de: api/imagem.php
<?
# Variáveis
$ID = $_POST['ID'] == 'false' ? false : $_POST['ID'];
$acao = $_POST['acao'];
$secao = $_POST['secao'];
$legenda = trim($_POST['legenda']);
$link = $_POST['link'];
$tipo = $_POST['tipo'];
$ordem = (int) $_POST['ordem'];
$target = $_POST['target'];
if ($acao == 'criar') {
$tag = stringTag($legenda);
$dados = array(
'usuario' => $AUTH->usuario->ID,
'ordem' => $ordem,
'secao' => $secao,
'legenda' => $legenda,
'link' => $link,
'entidade' => $AUTH->entidade->id,
);
if ( $ID = $IMAGEM->criar($dados) ) {
$return = array(
'success' => true,
'href' => SDIR.'editar/'.$ID,
'msg' => 'Cadastrado com sucesso, você será redirecionado.',
'mtipo' => 'info',
);
} else {
$return = array(
'success' => false,
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
} else if ( $acao == 'editar' AND $ID) {
$tag = $secao;
$dados = array(
'usuario' => $AUTH->usuario->ID,
'secao' => $secao,
'legenda' => $legenda,
'link' => $link,
'target' => $target
);
$p = $IMAGEM->getImagemID($ID);
if ( $SC = $IMAGEM->editar($ID, $dados) ) {
$return = array(
'success' => true,
'href' => SDIR,
'msg' => 'Atualizado com sucesso, você será redirecionado.',
'mtipo' => 'info',
);
} else {
$return = array(
'success' => false,
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
} else if ( $acao == 'status' AND $tipo AND $ID ) {
$c = $IMAGEM->getImagemID($ID);
if($tipo == 'ativar') {
if($IMAGEM->ativar($ID, $c->secao_id)) {
$return = array(
'success' => true,
'msg' => 'Atualizado com sucesso!',
'mtipo' => 'info',
'acao' => 1,
);
} else {
$return = array(
'success' => false,
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
} else if ($tipo == 'desativar') {
if($IMAGEM->desativar($ID)) {
$return = array(
'success' => true,
'msg' => 'Atualizado com sucesso!',
'mtipo' => 'info',
'acao' => 0,
);
} else {
$return = array(
'success' => false,
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
}
} else if ($acao == 'ordenar' AND $ID) {
$ordem = explode(',', $ID);
$sql = 'SET @a=0;';
$sql2 = 'UPDATE imagem SET ordem=@a := @a+1 WHERE id IN('.$ID.') ORDER BY FIELD(id,'.$ID.')';
$IMAGEM->db->rawQuery($sql);
$IMAGEM->db->rawQuery($sql2);
if($IMAGEM->db->getLastError() == '') {
$return = array(
'success' => true,
'ID' => $ID,
'msg' => 'Lista atualizado com sucesso!',
'mtipo' => 'info',
);
} else {
$return = array(
'success' => false,
'titulo' => 'Lista não atualizada!',
'msg' => $AUDIOS->db->getLastError(),
//'msg' => 'Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
} else if ($acao == 'deletar') {
if ( $IMAGEM->excluir($ID) ) {
$return = array(
'success' => true,
'msg' => 'Excluido com sucesso!',
'mtipo' => 'info',
);
} else {
$return = array(
'success' => false,
'msg' => 'Não foi possível confirmar algumas informações. Atualize a página.',
'mtipo' => 'error',
);
}
} else {
$return = array(
'success' => false,
'msg' => 'Dados inválidos. Atualize a página e tente novamente.',
'mtipo' => 'error',
);
}
header("Content-Type: application/json; charset=utf-8");
echo json_encode($return);