<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/global.php'; require_once DOC_ROOT . '/includes/classes/class.user.php'; require_once DOC_ROOT . '/includes/classes/class.tell_friend.php'; require_once DOC_ROOT . '/includes/classes/class.city.php'; require_once DOC_ROOT . '/includes/classes/class.legislation.php'; require_once DOC_ROOT . '/includes/classes/class.announcement.php'; $code = get_param('code'); $fyi_data = Tell_Friend::get_data($code); if (!empty($fyi_data) && $fyi_data['city_id']) { $city = new City($fyi_data['city_id']); } if ($fyi_data['issue_type'] == ANNOUNCEMENT_TYPE) { $issue = new Announcement($fyi_data['issue_id']); } elseif ($fyi_data['issue_type'] == LEGISLATION_TYPE) { $issue = new Legislation($fyi_data['issue_id']); } $user = new User($user_id); $user->mobile_phone($fyi_data['phone']); $user->update(); $user_region = new UserRegion(); $user_region->add_city($user_id, $fyi_data['city_id']); $data = array('status' => -1); if (!empty($city)) { $data = array('user_id' => $user_id, 'phone' => $fyi_data['phone'], 'issue' => array('id' => $fyi_data['issue_id'], 'type' => $fyi_data['issue_type'], 'category' => array('id' => $issue->category['id'], 'name' => $issue->category['name']), 'feedback_id' => '', 'filter_type' => '', 'title' => $issue->title(), 'sponsor' => $issue->sponsors), 'region' => $city->region_data()); } return_jsonp_data($data);
public function tell_friend($address, $data) { $sms = new SMSified(SMS_USER, SMS_PWD); if ($address) { $code = User::generate_user_code(); $link = $_SERVER['HTTP_HOST'] . "/fyi/{$code}"; $message = sprintf("%s\n%s\n%s\n- %s", $link, $data['title'], $data['message'], $data['name']); $request = sprintf("address=%s&message=%s", $address, $message); $url = PUSHURL; $response = $sms->sendMessage(SMS_SENDER, $address, $message); $responseJson = json_decode($response); //print 'Response:<pre>'; //print_r($responseJson); //print "</pre>"; $success = $responseJson; $tf = new Tell_Friend(); $tf->code($code); $tf->user_id($data['user_id']); $tf->phone($address); $tf->city_id($data['city_id']); $tf->issue_type($data['issue_type']); $tf->issue_id($data['issue_id']); $tf->message($data['message']); $tf->created_date(TODAY_DATETIME); $tf->insert(); } elseif (0) { $contents = array('badge' => '1', 'alert' => 'New item for ' . $tag); $push = array('aps' => $contents); $json = json_encode($push); $session = curl_init(PUSHURL); curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET); curl_setopt($session, CURLOPT_POST, true); curl_setopt($session, CURLOPT_POSTFIELDS, $json); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); $content = curl_exec($session); echo $content; // just for testing what was sent // Check if any error occured $response = curl_getinfo($session); curl_close($session); $success = $response['http_code'] == 200; } return $success; }