<?php
/*********************************************
Desciption: Editar registos
File: /bsk/artigos/registos/editar/index.php
Project: Basikus.Net
Developers: João Vieira
Start Date: 2009/05/21
*********************************************/

//Included main configuration file
require_once($_SERVER['DOCUMENT_ROOT'] . "/bsk/includes/configuracao.default.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/bsk/includes/funcoes.default.php");

$localTabela    = 'utilizadores';

if ( !isset($_SERVER['QUERY_STRING']) ) exit();
elseif ( $_SERVER['QUERY_STRING'] != md5($pwdWord . Date('Ymd')) ) exit();

if ( !isset($_POST['id']) ) exit();   
$_POST['id'] = (int)$_POST['id'];
$sqlStmtUp = "";

if (isset($_POST['activo'])) {
    if ( strlen($_POST['activo']) > 2 )  $sqlStmtUp .= " " . $localTabela . ".estado = '" . safe($_POST['activo']) . "',";
    else exit();
}
if (isset($_POST['nome'])) {
    if ( strlen($_POST['nome']) > 2 )  $sqlStmtUp .= " " . $localTabela . ".nome = '" . safe($_POST['nome']) . "',";
    else exit();
}

$sqlStmtUp = substr($sqlStmtUp, 0, strlen($sqlStmtUp)-1);

if ( isset($_POST['oper']) ) {
    if ( $_POST['oper'] == 'addxXx' ) {
        $sqlStmt = "INSERT INTO " . $localTabela . " (nome) VALUES('" . safe($_POST['ednome']) . "')";
    }elseif ( $_POST['oper'] == 'del' ){
        $sqlStmt = "DELETE FROM " . $localTabela . " WHERE id = '" . $_POST['id'] . "'";
    }
}else {
    $sqlStmt = "UPDATE " . $localTabela . " SET " . $sqlStmtUp . " WHERE id = '" . $_POST['id'] . "'";
}

//executar whatever que vier de cima
$connectDb->pedido($sqlStmt);

?>
