Beispiel #1
0
 function __construct($id = false, $withings_id = false)
 {
     global $user, $config;
     dbConnect();
     if ($id != false && $withings_id == true) {
         $sql = "SELECT uRec FROM deviceAuth WHERE device=" . WITHINGS . " AND userId='" . $id . "'";
         if ($rc = dbQuery($sql)) {
             if ($row = dbFetch($rc)) {
                 $this->uRec = $row['uRec'];
                 $this->user = new User($row['uRec']);
                 $this->user->getUser($row['uRec']);
             } else {
                 logit(WARN, " Not a Withings id in " . __FILE__ . " on line: " . __LINE__);
                 return false;
             }
         } else {
             logit(WARN, " DB Error:  {$sql} in " . __FILE__ . " on line: " . __LINE__);
             return false;
         }
     } elseif (is_uRec($id)) {
         $this->uRec = $id;
         $this->user = new User($id);
         $this->user->getUser($id);
     } elseif (is_uRec($user->uRec)) {
         $this->uRec = $user->uRec;
         $this->user = $user;
     } else {
         return false;
     }
     $this->reqToken = $this->reqSecret = $this->oauthToken = $this->oauthVerifier = $this->userid = null;
     // Withings config
     $this->key = $config['withingsKey'];
     $this->secretKey = $config['withingsSecretKey'];
     $this->c3url = $config['url'];
     $this->device = WITHINGS;
     $this->hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
     $this->sig_method = $this->hmac_method;
     $this->callback_url = $config["url"] . "/user/withingsLinkAuth.php";
     $this->oauth_url = "https://oauth.withings.com/account/";
     $this->req_url = $this->oauth_url . 'request_token';
     $this->auth_url = $this->oauth_url . 'authorize';
     $this->acc_url = $this->oauth_url . 'access_token';
     $this->base_url = "http://wbsapi.withings.net/measure?action=getmeas";
     $this->notify_url = "http://wbsapi.withings.net/notify?action=";
     $this->subscription_url = urlencode($config["url"] . "/api/devices/withings.php");
     $this->consumer = new OAuthConsumer($this->key, $this->secretKey, $this->callback_url);
     // Withings data type definitions
     $this->weight = 1;
     $this->systolic_bp = 10;
     $this->diastolic_bp = 9;
     $this->pulse = 11;
     $this->fetchAllTokens();
     $this->providerLink = false;
     $this->caregiverLink = false;
     $this->fetchPermissions();
 }
Beispiel #2
0
 function setUser($uRec)
 {
     global $user, $stripeConfig;
     if (is_uRec($uRec)) {
         $this->uRec = $uRec;
         $this->user = new User($uRec);
         $this->user->getUser($uRec);
         return true;
     } elseif (is_uRec($user->uRec)) {
         $this->uRec = $user->uRec;
         $this->user = $user;
         return true;
     }
     return false;
 }
Beispiel #3
0
 function saveLastSurveyPage()
 {
     if (is_array($this->lastResponseArray) and is_uRec($this->uRec)) {
         $survey = new Survey();
         $survey->setUser($this->uRec);
         $survey->responseVector = "appSurvey";
         //$survey->surveyGoalResponses = $this->goalResponseArray;
         $survey->surveyId = $this->surveyId;
         $survey->saveDiaryComment($this->lastResponseArray);
         if (is_array($this->lastResponseArray["otherMeds"])) {
             $survey->otherMeds = $this->lastResponseArray["otherMeds"];
             $survey->saveOtherMeds();
         }
         if (is_array($this->lastResponseArray["sideEffects"])) {
             $survey->sideEffects = $this->lastResponseArray["sideEffects"];
             $survey->saveSideEffects();
         }
         $survey->setSurveyStatus(4);
     } else {
         $this->addError(ERRORTEXT . ": empty lastResponseArray response object or bad user rec");
         logit(WAR, "");
         logit(WARN, "Error: lastResponseArray was empty  or bad user rec in " . __FILE__ . " on line: " . __LINE__);
     }
     return true;
 }