function action($actions) { $factory = new MP_Factory(); require_once $factory->find_wp_load(); $myDB = $factory->myDB(); $myDB->connect_db(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); switch ($actions) { case "uua": $myDB->add_post_to_db($_POST, 'MP_Admin'); $args = $myDB->print_all_items_from_tables("MP_Admin"); $formulario = $factory->myUtils()->arr_to_form($args); echo $formulario; break; case "nPr": $myDB->add_post_to_db($_POST, 'Productos'); $args = $myDB->print_all_items_from_tables("Productos"); $formulario = $factory->myUtils()->arr_to_form($args); echo $formulario; break; case "update": $es = preg_split("/-/", $_POST['data']); update_tables_by_ID($es[2], $es[0], $es[1], $_POST['value']); break; case "delete": $es = preg_split("/-/", $_POST['data']); kill_tables_by_ID($es[2], $es[1]); break; } }
<?php require_once dirname(__DIR__) . "/mvc/Factory.php"; $factory = new MP_Factory(); require_once $factory->find_wp_load(); actions($_GET['action']); function actions($action) { $factory = new MP_Factory(); $myDB = $factory->myDB(); $myDB->connect_db(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); switch ($action) { case 'login': $user = $myDB->print_all_items_from_tables('MP_user', 'id,MP_email,MP_password', 'MP_email', $_POST['MP_email']); $encrypt = md5($_POST['MP_password']); if ($user[1]['MP_password'] == $encrypt) { $token = $user[1]['id'] . "-" . $encrypt; $domain = $_SERVER['HTTP_HOST'] != 'localhost' ? $_SERVER['HTTP_HOST'] : false; setcookie('MP_user', $token, 0, '/', $domain, false); header('location:' . $_SERVER['HTTP_REFERER']); } break; case 'register': $_POST['MP_password'] = md5($_POST['MP_password']); $encrypt = $_POST['MP_password']; $update = $myDB->add_post_to_db($_POST, 'MP_user'); if ($update != false) { $domain = $_SERVER['HTTP_HOST'] != 'localhost' ? $_SERVER['HTTP_HOST'] : false; setcookie('MP_user', $token, 0, '/', $domain, false); header('location:' . $_SERVER['HTTP_REFERER']); } else {