"; $API['VERSION'] = "1.03"; //Constants $CONSTANTS['bgcolor'] = '#CCCCCC'; $CONSTANTS['scrollareacolor'] = '#FFFFFF'; if(isset($_REQUEST['Login'])) { if(isset($_REQUEST['mobile'])) { $_SESSION['userinfo']['mobile'] = $_REQUEST['mobile']; } if(isset($_REQUEST['password'])) { $_SESSION['userinfo']['password'] = $_REQUEST['password']; } get_preferences(); get_friendsList(); } else if(isset($_REQUEST['action'])) { switch(strtolower($_REQUEST['action'])) { case 'delete': delete_friend($_REQUEST['friendid']); break; case 'editpreferences': edit_preferences(); break; case 'signout': signout(); break; default: get_friendsList(); } } else if(isset($_REQUEST['addFriend'])) { add_friend(); } else if(isset($_REQUEST['setPreferences'])) { set_preferences(); } else if(isset($_REQUEST['startNew'])) { if(isset($_REQUEST['friend_id'])) { foreach($_REQUEST['friend_id'] as $key => $value) { $arrArgs['friend_id['.$key.']'] = $value; } } $arrArgs['message'] = $_REQUEST['message']; $arrArgs['method'] = "3jam.conversations.startNew"; $result = send_to_server($arrArgs); if(preg_match("//",$result)) { display_3jam_started(); } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; get_friendsList($sErrorMsg); } } else { get_friendsList($sErrorMsg); } function send_to_server($arrArgs) { global $API; //Set API Version number $arrArgs['api_version'] = $API['VERSION']; //Set API URL $url = "https://api.3jam.com/webapi.php"; //Set username/password $arrArgs['mobile'] = $_SESSION['userinfo']['mobile']; $arrArgs['password'] = create_md5password($_SESSION['userinfo']['mobile'],$_SESSION['userinfo']['password']); //Set authentication keys $arrArgs['api_key'] = $API['KEY']; $creq = curl_init(); curl_setopt($creq, CURLOPT_URL, $url); curl_setopt($creq, CURLOPT_TIMEOUT, 20); //set timeout in case other side hangs, which won't return for a while curl_setopt($creq, CURLOPT_RETURNTRANSFER, 1); curl_setopt($creq, CURLOPT_POST,1); curl_setopt($creq, CURLOPT_POSTFIELDS, $arrArgs); curl_setopt($creq, CURLOPT_SSL_VERIFYPEER, FALSE); //Turn off certificate verification so Curl works $curl_result = curl_exec($creq); if(curl_errno($creq)) { //If there's a problem with Curl on your machine print "Curl error on local machine: ".curl_error($creq); } return $curl_result; } function get_preferences(&$firstname,&$lastname) { //First get user's name from preferences. $arrArgs['method'] = "3jam.user.getPreferences"; $result = send_to_server($arrArgs); if(preg_match("//",$result)) { //Logged in ok, now get the first and last name preg_match("/firstname=\"(.*?)\"/",$result,$matches); $firstname = $_SESSION['userinfo']['firstname'] = $matches[1]; preg_match("/lastname=\"(.*?)\"/",$result,$matches); $lastname = $_SESSION['userinfo']['lastname'] = $matches[1]; return TRUE; } else { //Error getting preferences $firstname = ""; $lastname = ""; return FALSE; } } function get_friendsList($sSelectFriendsErrorMsg='',$sAddFriendErrorMsg='') { global $CONSTANTS; //Now get friends list $arrArgs['method'] = "3jam.friends.getList"; $result = send_to_server($arrArgs); if(preg_match("//",$result)) { preg_match_all("/'; $html .= '

Start a 3jam!

'.($sSelectFriendsErrorMsg == '' ? '' : ''.$sSelectFriendsErrorMsg.''); $html .= '
'; $html .= '
'; $html .= ''; $count = 1; foreach($matches as $eachmatch) { $friendId = $eachmatch[1]; $friendName = $eachmatch[2]; $html .= ''; $html .= ''; $html .= ''."\n"; } $html .= '
Friends
'.$friendName.' [delete]
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= ''; //Add friend part $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '

Add a new friend 

'.($sAddFriendErrorMsg == '' ? '' : ''.$sAddFriendErrorMsg.'').'
Friend name:
Mobile Number:
'; $html .= '
'; $html .= '
'; print $html; } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; display_login($sErrorMsg); } } function signout() { if(isset($_SESSION['userinfo'])) { unset($_SESSION['userinfo']); } display_login("You have signed out successfully"); } function delete_friend($friendId) { $friendId = trim($friendId); //Clean up if($friendId == "") { $sSelectFriendsErrorMsg = "No friend selected"; $result = FALSE; } else { $arrArgs['method'] = "3jam.friends.remove"; $arrArgs['friend_id'] = $friendId; $result = send_to_server($arrArgs); } if(preg_match("//",$result)) { preg_match("/friend id=\"(.*?)\" name=\"(.*?)\"/",$result,$matches); get_friendsList($matches[2]." deleted"); } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; get_friendsList($sErrorMsg); } } function add_friend() { $errorMsg = ""; $result = FALSE; $friend_name = ""; $friend_mobile = ""; $sAddFriendErrorMsg = ''; $sSelectFriendsErrorMsg = ''; if(isset($_REQUEST['friend_name']) && isset($_REQUEST['friend_mobile'])) { $friend_name = trim($_REQUEST['friend_name']); //Clean up $friend_mobile = trim($_REQUEST['friend_mobile']); //Clean up if($friend_name == "") { $sAddFriendErrorMsg = "Friend name cannot be blank"; $result = FALSE; } else if($friend_mobile == "") { $sAddFriendErrorMsg = "Friend mobile cannot be blank"; $result = FALSE; } else { $arrArgs['method'] = "3jam.friends.add"; $arrArgs['friend_name'] = $friend_name; $arrArgs['friend_mobile'] = $friend_mobile; $result = send_to_server($arrArgs); } } if($result !== FALSE) { if(preg_match("//",$result)) { preg_match("/friend id=\"(.*?)\" name=\"(.*?)\"/",$result,$matches); $sAddFriendErrorMsg = $matches[2]." added to friend list!"; } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sAddFriendErrorMsg = $matches[1]; } } get_friendsList($sSelectFriendsErrorMsg,$sAddFriendErrorMsg); } function display_login($sErrorMsg='') { $html = '

Log in to your 3jam account:

'.($sErrorMsg == '' ? '' : ''.$sErrorMsg.'').' '; print $html; } function display_3jam_started() { $html = '

3jam started!

Click here to start another.'; print $html; } function create_md5password($mobile,$password) { return md5($mobile.$password); } function edit_preferences($sErrorMsg = "") { global $CONSTANTS; $html = html_header(); $html .= '
'; $html .= '

Edit Preferences:

'.($sErrorMsg == '' ? '' : ''.$sErrorMsg.'').'
Mobile number:Password:
  Need an account / password?
'; print $html; } function set_preferences() { $sErrorMsg = "Preferences saved"; if(isset($_REQUEST['firstname'])) { $arrArgs['firstname'] = trim($_REQUEST['firstname']); } if(isset($_REQUEST['lastname'])) { $arrArgs['lastname'] = trim($_REQUEST['lastname']); } $arrArgs['method'] = "3jam.user.setPreferences"; $result = send_to_server($arrArgs); if($result !== FALSE) { if(preg_match("//",$result)) { get_preferences(); $sErrorMsg = "Preferences saved"; } else { //Error found so re-display form and error preg_match("/msg=\"(.*)\"/",$result,$matches); $sErrorMsg = $matches[1]; } } edit_preferences($sErrorMsg); } function html_header() { $html = ''; $html .= '

3jam Reply-All Texting

'; $html .= 'Hello '.$_SESSION['userinfo']['firstname'].' '.$_SESSION['userinfo']['lastname'].'!
[Main] [Preferences] [Sign Out]
'; return $html; } ?>
Firstname:
Lastname: