File: //opt/plugins/atalantini/data/service_utente.php
<?php
/**
* Atom Publishing Protocol support for WordPress
*
* @version 1.0.5-dc
*/
/**
* WordPress is handling an Atom Publishing Protocol request.
*
* @var bool
*/
define('APP_REQUEST', true);
/** Set up WordPress environment */
require_once('../../../../wp-load.php');
/** Atom Publishing Protocol Class */
require_once(ABSPATH . WPINC . '/atomlib.php');
/** Admin Image API for metadata updating */
require_once(ABSPATH . '/wp-admin/includes/image.php');
$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
/**
* Whether to enable Atom Publishing Protocol Logging.
*
* @name app_logging
* @var int|bool
*/
$app_logging = 0;
/**
* Whether to always authenticate user. Permanently set to true.
*
* @name always_authenticate
* @var int|bool
* @todo Should be an option somewhere
*/
$always_authenticate = 1;
/**
* Writes logging info to a file.
*
* @since 2.2.0
* @uses $app_logging
* @package WordPress
* @subpackage Logging
*
* @param string $label Type of logging
* @param string $msg Information describing logging reason.
*/
function log_app($label,$msg) {
global $app_logging;
if ($app_logging) {
$fp = fopen( 'wp-app.log', 'a+');
$date = gmdate( 'Y-m-d H:i:s' );
fwrite($fp, "\n\n$date - $label\n$msg\n");
fclose($fp);
}
}
global $wpdb;
$table = "wp_plugin_elettroteca_utenti";
$azione = $_GET['azione'];
if ($azione == "INSERT") {
$msg = "true";
$userExist = 0;
$rs = $wpdb->get_results("select id from " . $table . " where email = '" . $_POST['email'] . "';");
foreach ( $rs as $line ) {
$userExist = 1;
$msg = "false";
}
if ($userExist == 0) {
$wpdb->insert(
$table,
array(
'nome' => str_replace("\\","",$_POST['nome']),
'cognome' => str_replace("\\","",$_POST['cognome']),
'email' => str_replace("\\","",$_POST['email']),
'password' => str_replace("\\","",$_POST['password']),
'societa' => str_replace("\\","",$_POST['societa']),
'tipo_utente' => str_replace("\\","",$_POST['tipo_utente']),
'indirizzo' => str_replace("\\","",$_POST['indirizzo']),
'attivo' => str_replace("\\","",$_POST['attivo']),
'sottoscrizione_bacheca' => str_replace("\\","",$_POST['sottoscrizione_bacheca']),
'promozione' => str_replace("\\","",$_POST['promozione'])
),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
)
);
if ($_POST['invia_password'] == "S") {
$headers = 'From: Elettroteca <info@elettroteca.com>' . "\r\n";
wp_mail($_POST['email'], 'Conferma attivazione utente', "Il tuo account per accedere al sito elettroteca e':\n\nUsername: " . $_POST['email'] . "\nPassword:" . $_POST['password'] . "\n\n", $headers, "" );
wp_mail("webmaster@elettroteca.it", 'Conferma attivazione utente', "Il tuo account per accedere al sito elettroteca e':\n\nUsername: " . $_POST['email'] . "\nPassword:" . $_POST['password'] . "\n\n", $headers, "" );
}
}
echo $msg;
}
if ($azione == "UPDATE") {
$wpdb->update(
$table,
array(
'nome' => str_replace("\\","",$_POST['nome']),
'cognome' => str_replace("\\","",$_POST['cognome']),
'email' => str_replace("\\","",$_POST['email']),
'password' => str_replace("\\","",$_POST['password']),
'societa' => str_replace("\\","",$_POST['societa']),
'tipo_utente' => str_replace("\\","",$_POST['tipo_utente']),
'indirizzo' => str_replace("\\","",$_POST['indirizzo']),
'attivo' => str_replace("\\","",$_POST['attivo']),
'sottoscrizione_bacheca' => str_replace("\\","",$_POST['sottoscrizione_bacheca']),
'promozione' => str_replace("\\","",$_POST['promozione'])
),
array( 'id' => $_POST['id'] ),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
),
array( '%d' )
);
if ($_POST['invia_password'] == "S") {
$headers = 'From: Elettroteca <info@elettroteca.com>' . "\r\n";
wp_mail($_POST['email'], 'Conferma attivazione utente', "Il tuo account per accedere al sito elettroteca e':\n\nUsername: " . $_POST['email'] . "\nPassword:" . $_POST['password'] . "\n\n", $headers, "" );
wp_mail("webmaster@elettroteca.it", 'Conferma attivazione utente', "Il tuo account per accedere al sito elettroteca e':\n\nUsername: " . $_POST['email'] . "\nPassword:" . $_POST['password'] . "\n\n", $headers, "" );
}
}
if ($azione == "DELETE") {
$wpdb->query("delete from " . $table . " where id = " . $_POST['id']);
}
if ($azione == "LIST") {
$limit = "";
if ($_GET['pageNo'] == '1') {
$limit = "limit 0, " . $_GET['pageSize'];
}
if ($_GET['pageNo'] != '1') {
$page = $_GET['pageNo'];
$size = $_GET['pageSize'];
$page = $size * ($page - 1);
$limit = "limit " . $page . ", " . $_GET['pageSize'];
}
$where = "";
if ($_GET['searchkey'] != '') {
$where = " where nome like '%" . $_GET['searchkey'] . "%' or cognome like '%" . $_GET['searchkey'] . "%' or email like '%" . $_GET['searchkey'] . "%'";
}
$rs = $wpdb->get_results("select * from " . $table . " " . $where . " " . $limit . ";");
foreach ( $rs as $line ) {
$elementiSingoli[] = json_encode(array('id' => $line->id, 'nome' => $line->nome, 'cognome' => $line->cognome, 'societa' => $line->societa, 'username' => $line->username, 'email' => $line->email, 'promozione' => $line->promozione,'tipo_utente' => $line->tipo_utente));
}
// estraggo totaleValori
$totaleValori = 0;
$rs = $wpdb->get_results("select count(*) as contatore from " . $table . ";");
foreach ( $rs as $line ) {
$totaleValori = $line->contatore;
}
if (count($elementiSingoli) > 0) {
?>
{"totaleValori":"<?= $totaleValori ?>","lista":[<?= implode(",", $elementiSingoli) ?>]}
<?php
} else {
?>
{"totaleValori":"<?= $totaleValori ?>","lista":[]}
<?php
}
}
if ($azione == "DETAIL") {
$rs = $wpdb->get_results("select * from " . $table . " where id = " . $_GET['id'] . ";");
foreach ( $rs as $line ) {
$elementiSingoli[] = json_encode(array('id' => $line->id, 'nome' => $line->nome, 'cognome' => $line->cognome, 'societa' => $line->societa, 'email' => $line->email, 'password' => $line->password, 'tipo_utente' => $line->tipo_utente, 'indirizzo' => $line->indirizzo, 'attivo' => $line->attivo, 'sottoscrizione_bacheca' => $line->sottoscrizione_bacheca, 'promozione' => $line->promozione));
}
?>
{"dettaglio":[<?= implode(",", $elementiSingoli) ?>]}
<?php
}
if ($azione == "SETPROMOZIONE") {
$wpdb->query("update " . $table . " set promozione = 'Y' where id = " . $_POST['id'] . ";");
}
if ($azione == "DELPROMOZIONE") {
$wpdb->query("update " . $table . " set promozione = 'N' where id = " . $_POST['id'] . ";");
}
?>