0) { $q = mysql_query("SELECT * FROM presentation_frame WHERE agency_id = $agent_id"); if ($frame = mysql_fetch_assoc($q)) { // http://localhost:8080 $frame['url'] = "$site_url/new-buildings-frame/#/catalogs/" . $frame['token']; echo json_encode([ 'status' => true, 'data' => $frame, ]); exit; } echo json_encode([ 'status' => false, 'message' => 'Frame not found', ]); exit; } break; case 'POST': if(!isset($_POST['id'])) { $agent_id = $_SESSION['agency_id']; } else { $agent_id = $_POST['id']; } if ($_SESSION['id'] && $agent_id && (int)$agent_id > 0) { $region_id = isset($_POST['region']) ? (int)$_POST['region'] : null; $end_date = isset($_POST['endDate']) ? $_POST['endDate'] : null; $color = isset($_POST['color']) ? $_POST['color'] : null; $q = mysql_query("SELECT * FROM presentation_frame WHERE agency_id = $agent_id"); $update_fields = []; if ($region_id !== null) { $update_fields[] = "rf_region_id = $region_id"; } if ($end_date !== null) { $update_fields[] = "end_date = '$end_date'"; } if ($color !== null) { $update_fields[] = "color = '$color'"; } if ($frame = mysql_fetch_assoc($q)) { if (!empty($update_fields)) { $update_query = "UPDATE presentation_frame SET " . implode(', ', $update_fields) . " WHERE agency_id = $agent_id"; $query = mysql_query($update_query); } } else { $token = md5($agent_id . time()); $query = mysql_query("INSERT INTO presentation_frame SET token = '$token', agency_id = $agent_id," . implode(', ', $update_fields)); die(mysql_error()); } echo ($query); } break; default: break; }