function deactivate($phone, $service) { $users_phone = removePlus($phone); $data = R::findOne('users', ' mobile_number = :phone', array('phone' => $users_phone)); //var_dump($data->id); exit; if (!$data) { $msg = "Sorry you are not a subscriber to any mHealth services. To subscribe text mhealth or the package name of your choice to 33121"; //echo $msg; echo smsSender($phone, $msg); exit; } if ($service == '' || strtoupper($service) == "MHEALTH") { // R::exec("delete from users where id =" . $data->id); R::exec("delete from subscription where user_phone =" . $phone); $msg = "You have been stopped from all mHealth services. To re-subscribe text mhealth or the package name of your choice to 33121"; //echo $msg; echo smsSender($phone, $msg); exit; } if (!($service == '' || strtoupper($service) == "MHEALTH")) { $cat_id = findUnsubcribeCategory($service); if ($cat_id != 0) { $sub_data = R::findOne('subscription', ' user_phone = :phone and category_id = :cat', array('phone' => $phone, 'cat' => $cat_id)); if (!$sub_data) { $msg = "Sorry you are not a subscriber to {$service} category. To subscribe under this category, text {$service} to 33121"; //echo $msg; echo smsSender($phone, $msg); exit; } else { R::exec("delete from subscription where user_phone =" . $phone); $msg = "You have been stopped from {$service} category on mHealth. To re-subscribe text mhealth or the package name of your choice to 33121"; echo smsSender($phone, $msg); //echo $msg; exit; } } else { //$msg = "Sorry you are not a subscriber to $service category. To subscribe under this category, text $service to 35123"; $msg = "The category you want to subscribe for doest not exist on mHealth services"; //echo $msg; echo smsSender($phone, $msg); exit; } } exit; }
$bean2->user_phone = $phone; $bean2->category_id = $cat_id; $id = R::store($bean2); $msg .= "Your subscription on " . $_SESSION['cat_name'] . " package has been activated. You will receive daily alerts for 30 days. Expires on " . date('d-m-Y', $new_period); } } } else { #a new user $new_period = strtotime(PERIOD . ' day', strtotime(date('d-M-Y'))); $bean = R::dispense('users'); $bean->mobile_number = $phone; $bean->group_id = 10; $bean->location_id = 1; $id = R::store($bean); $sub_id = $gen->subscriberIDGenerator(); $sub = removePlus($phone) . $sub_id; R::exec("update users set subscriber_id = " . $sub . " where id= {$id}"); #Register subscriber subscription $cat_id = findCategory($user_msg); $msg = $_SESSION['not']; if ($cat_id) { $new_period = strtotime(PERIOD . ' day', strtotime(date('d-M-Y'))); $bean2 = R::dispense('subscription'); $bean2->expire_date = $new_period; $bean2->user_phone = $phone; $bean2->category_id = $cat_id; $id = R::store($bean2); } if ($_SESSION['not'] != '' || strtoupper($user_msg) == 'MHEALTH') { #Wrong subscribed $msg = "Sorry we dont have tips for " . $user_msg . " but you have been subscribed under General Health package. Your subscription ID is " . $sub_id . ". You will receive daily alerts for 30 days and it expires on " . date('d-m-Y', $new_period) . ", To renew, please send mhealth or name of category you want to 35123";