File: /var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_plans.php
<?php
/***
* @purpose : Used for selfanalyse plans
* @author Rohit Kashyap
* @since 22/07/2020 >> dd/mm/yyyy
* @version 0.1
* @copyright Copyright (C) 2020 Graposs Edutech Ltd. All rights reserved.
* @license Graposs Edutech Ltd.
*/
/***
* define header and include config
*/
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include("../../../../wp-config.php");
global $wpdb;
$PSY_PLANS = $wpdb->prefix . PSY_PLANS;
$type = $_REQUEST['type'];
if ($type == 'single') {
$plan_id = $_REQUEST['wht_plan'];
if ($plan_id != '' && is_numeric($plan_id) && strlen($plan_id) <= 3) {
$getPlans = $wpdb->get_row("SELECT plan_id, plan_name, plan_price FROM $PSY_PLANS where plan_id='$plan_id' and status='1'");
$plansArray = array();
// foreach($getPlans as $p) {
$plansArray[] = array("plan_id" => $getPlans->plan_id, "plan_name" => $getPlans->plan_name, "plan_price" => $getPlans->plan_price);
// }
} else {
$plansArray[] = array("error" => "No data found");
}
}
if ($type == 'select') {
$getPlans = $wpdb->get_results("SELECT plan_id, plan_name, plan_price FROM $PSY_PLANS where status='1'");
$plansArray = array();
foreach ($getPlans as $p) {
$plansArray[] = array("plan_id" => $p->plan_id, "plan_name" => $p->plan_name, "plan_price" => $p->plan_price);
}
}
echo json_encode($plansArray);