Author: Casiva Agustin
Example #1
0
 public static function create($url, $options = array())
 {
     $request = new Requester($options);
     $returning = $request->send($url);
     $request->close();
     return $returning;
 }
Example #2
0
    function getByPhoneNum()
    {
        if (!($phone = $_REQUEST['From'])) {
            Error::sms("The SMS sender's phone number was not detected.");
        }
        if (!($body = $_REQUEST['Body'])) {
            Error::sms("Missing email address.");
        }
        $sql = "SELECT user_id, email, wallet FROM users WHERE phone=?";
        $row = DBquery::get($sql, array($phone));
        if ($row) {
            if ($body != $row[0]['email']) {
                Error::sms("The email address does not match the one set for phone #{$phone}.");
            } else {
                $this->user_id = $row[0]['user_id'];
                Requester::$consumer_id = $row[0]['wallet'];
                return $this->setToken();
            }
        } else {
            require_once "models/UserCollection.php";
            $Users = new UserCollection(json_decode('{
				"email": "' . $body . '",
				"name": "' . $body . '",
				"password": "******",
				"phone": "' . $phone . '",
				"login_provider": "phone",
				"wallet": 2
			}'));
            $arr = $Users->add();
            $this->user_id = $arr[0]->user_id;
            return $this->setToken();
        }
    }
Example #3
0
 function get()
 {
     $sql = "SELECT promo_id, brand_id, b.name AS brand_name,\n\t\t\t\tp.name, p.description, amount, imageURL, infoURL, \n\t\t\t\tp.created, p.updated, expires,\n\t\t\t\trelay_id, keyword,\n\t\t\t\tby_all_limit, by_brand_limit, by_user_limit, by_user_wait\n\t\t\tFROM promos p\n\t\t\tJOIN relays USING (relay_id)\n\t\t\tJOIN brands b USING (brand_id)\n\t\t\tWHERE promo_id=?";
     $rows = DBquery::get($sql, array($this->promo_id));
     if (!$rows) {
         return array(new stdClass());
     }
     $r = $rows[0];
     /*if (!Requester::isMember($rows[0]['brand_id'])) {
     			$this->setForms();
     		}*/
     foreach ($r as $k => $v) {
         $this->{$k} = $v;
     }
     if (!$this->imageURL) {
         $this->imageURL = Requester::$ProtDomain . "/ui/css/logo5.png";
     }
     //."/ui/logo.php?brand=". $rows[0]['brand_name'];
     $this->code = "{$r['keyword']}-{$r['promo_id']}";
     $this->payURL = Requester::$ProtDomain . "/for/{$this->code}";
     $this->promoPage = "/ad/{$r['amount']}";
     if (!$this->expires) {
         $this->expires = "2019-12-31 11:59:59";
     }
     if (Requester::isMember($rows[0]['brand_id'])) {
         $this->edit = "/form/promo-edit";
     }
     return array($this);
 }
Example #4
0
 function set()
 {
     if (!in_array($this->holder_id, Requester::holderIDs())) {
         Error::http(403, "The user does not have access to this accountholder's information.");
     }
     return $this->add();
 }
Example #5
0
 function get()
 {
     $graph = array($this);
     $tracked = array();
     $this->add = "{$this->root}/form/promo-add";
     $this->setFilters($_GET);
     $nestingRef = array("brand_" => array("@id" => "{$this->root}/team/{id}", "@type" => "brand"), "relay_" => array("@id" => "{$this->root}/relay/{id}", "@type" => "relay", "edit" => "/form/relay-edit", "by_all_limit" => "{by_all_limit}"));
     $sql = "SELECT promo_id AS id, \n\t\t\t\tbrand_id, \n\t\t\t\tbrands.name AS brand_name, \n\t\t\t\tp.name AS name, \n\t\t\t\tp.description AS description, \n\t\t\t\tamount, \n\t\t\t\timageURL, \n\t\t\t\tinfoURL, \n\t\t\t\tp.created, \n\t\t\t\tp.updated, \n\t\t\t\texpires, \n\t\t\t\trelay_id, \n\t\t\t\tkeyword, \n\t\t\t\tby_all_limit AS relay_by_all_limit, \n\t\t\t\tby_brand_limit AS relay_by_brand_limit, \n\t\t\t\tby_user_limit AS relay_by_user_limit, \n\t\t\t\tby_user_wait AS relay_by_user_wait\n\t\t\tFROM promos p\n\t\t\tJOIN relays r USING (relay_id)\n\t\t\tJOIN brands USING (brand_id)\n\t\t\tWHERE brand_id={$this->brand_id} {$this->filterCond} AND promo_id {$this->ltgt} {$this->limitID}\n\t\t\tORDER BY id ASC\n\t\t\tLIMIT {$this->itemsLimit}";
     $items = DBquery::get($sql, $this->filterValArr);
     foreach ($items as &$r) {
         $this->nestResources($r, $nestingRef, $graph, $tracked);
         $r['@id'] = "{$this->root}/promo/" . $r['id'];
         $r['@type'] = 'promo';
         $r['payURL'] = Requester::$ProtDomain . "/for/{$r['keyword']}-{$r['id']}";
         $r['code'] = "{$r['keyword']}-{$r['id']}";
         $r['promoPage'] = Requester::$ProtDomain . "/ad/{$r['id']}";
         if (!$r['infoURL']) {
             $r['infoURL'] = $r['promoPage'];
         }
         $r['edit'] = '/form/promo-edit';
         $relayHoldings = array();
         if (in_array($r['relay_id'], $relayHoldings) or Requester::isRelayHolder($r['relay_id'])) {
             $relayHoldings[] = $r['relay_id'];
             $r['relay-edit'] = '/form/relay-edit';
             $r['relay-edit-target'] = "/relay/" . $r['relay_id'];
         }
         $r['brand'] = "{$this->root}/brand/{$this->brand_id}";
         $this->{$this->collectionOf}[] = $r['@id'];
         $graph[] = $r;
     }
     $this->paginate('promo_id');
     return $graph;
 }
Example #6
0
 /**
  * Retrieve an access token for the given grant_type and payload.
  *
  * @param string $grant_type the grant type to use
  * @param array $data extra data to send to the oauth server
  *
  * @return string a valid access token
  */
 public static function getToken($grant_type, $data)
 {
     $payload = array_merge(['grant_type' => $grant_type, 'client_id' => Api::$client_id, 'client_secret' => Api::$client_secret], $data);
     if ($grant_type == 'authorization_code') {
         $payload['redirect_uri'] = Api::$redirect_url;
     }
     return Requester::post('oauth/token', $payload);
 }
Example #7
0
 function set()
 {
     $this->setDetails();
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "The requester is not an admin for brand #{$this->brand_id}.");
     }
     $this->update(array("throttle_id" => $this->throttle_id));
     return array($this->obj);
 }
Example #8
0
 function get()
 {
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "Only admins of brand #{$this->brand_id} can view details of its budget issuance records.");
     }
     $sql = "SELECT r.record_id, r.created, from_acct, from_user, to_acct, to_user, amount, `note`\n\t\tFROM records r JOIN accounts a ON (r.from_acct = a.account_id)\n\t\tWHERE brand_id=? AND txntype='pn' \n\t\tORDER BY record_id DESC LIMIT 50";
     $this->items = DBquery::get($sql, array($this->brand_id));
     $this->setForms();
     return array($this);
 }
Example #9
0
 function get()
 {
     $info = $this->getInfo()[0];
     if (Requester::$user_id == $info['user_id']) {
         return array($info);
     }
     if (Requester::isAccountAdmin($info['account_id'])) {
         unset($info['limkey']);
         return array($info);
     }
     return array();
 }
Example #10
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "The '/team/{$this->brand_id}' resource is only viewable by members of brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'brand';
     $this->{"@id"} = "{$this->root}/team/{$this->brand_id}";
     $this->table = "members";
     $this->init($data);
     $this->okToFilterBy = array("brand_id", "member_id");
     $this->okToSet = array("joined", "revoked");
 }
Example #11
0
 function __construct($data = '')
 {
     $this->relay_id = $this->getID();
     if (Router::$resource == 'relay' and !Requester::isRelayHolder($this->relay_id)) {
         Error::http(403, "The user does not have access to this accountholder's information.");
     }
     $this->{"@type"} = "relay";
     $this->{'@id'} = "{$this->root}/relay/{$this->relay_id}";
     $this->table = "relays";
     $this->idkey = 'relay_id';
     $this->init($data);
     $this->okToFilterBy = array('relay_id');
 }
Example #12
0
 function __construct($data = '')
 {
     $this->{"@type"} = "teamOrders";
     $this->brand_id = $this->getID();
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "Only members or admins of brand #{$this->brand_id} can view its orders.");
     }
     $this->{'@id'} = "{$this->root}/team/{$this->brand_id}/orders";
     $this->table = "records";
     $this->collectionOf = "order";
     $this->init($data);
     $this->okToFilterBy = array("record_id");
 }
Example #13
0
 function __construct($data = '')
 {
     $this->user_id = $this->getID();
     if (!Requester::isUser($this->user_id)) {
         Error::http(401, "The requester must be logged in as the requested user.");
     }
     $this->{"@id"} = "/user/{$this->user_id}/apps";
     $this->{'@type'} = "userApps";
     $this->collectionOf = "app";
     $this->table = "consumers";
     $this->init($data);
     $this->okToAdd = array("name", "secret", "type", "redirect_url");
 }
Example #14
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "The requester is not an admin for brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'brand';
     $this->{"@id"} = "{$this->root}/brand/{$this->brand_id}";
     $this->role = "admin";
     $this->table = "brands";
     $this->init($data);
     $this->okToSet = array("name", "ended", "mission", "description", "url", "advisor", "type_system", "type_id", "country_code", "area_code", "logo");
     $this->okToFilterBy = array("brand_id");
 }
Example #15
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "The requester is not a member of brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'accounts';
     $this->{"@id"} = "{$this->root}/team/{$this->brand_id}/accounts";
     $this->table = "accounts";
     $this->idkey = 'account_id';
     $this->collectionOf = "account";
     $this->init($data);
     $this->okToGet = array("brand_id", "account_id", "name", "balance", "unit", "authcode");
 }
Example #16
0
 function __construct($data = '')
 {
     $this->{"@type"} = 'userMemberships';
     $this->user_id = $this->getID();
     if (!Requester::isUser($this->user_id)) {
         Error::http(401, "The requester must be logged in as the requested user.");
     }
     $this->{"@id"} = "{$this->root}/user/{$this->user_id}/memberships";
     $this->table = "members";
     $this->idkey = 'user_id';
     $this->collectionOf = "memberships";
     $this->init($data);
     $this->okToSet = array("joined", "revoked");
     $this->okToFilterBy = array("member_id");
 }
Example #17
0
 function __construct($data = '')
 {
     $this->{"@type"} = 'userAccounts';
     //print_r($data);
     $this->user_id = Router::$id ? $this->getID() : Requester::$user_id;
     //print_r($this);
     if (!Requester::isUser($this->user_id)) {
         Error::http(401, "The requester must be logged in as the requested user.");
     }
     $this->{"@id"} = "{$this->root}/user/{$this->user_id}/accounts";
     $this->collectionOf = "holding";
     $this->init($data);
     $this->okToSet = array("alias", "limkey");
     $this->okToFilterBy = array("user_id", "holder_id");
 }
Example #18
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "The '/team/{$this->brand_id}/members' resource is only viewable by members of brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'members';
     $this->{"@id"} = "{$this->root}/team/{$this->brand_id}/members";
     $this->table = "members";
     $this->idkey = 'member_id';
     $this->collectionOf = "member";
     $this->init($data);
     $this->okToSet = array("role", 'hours', 'ended');
     $this->okToFilterBy = array("member_id", "user_id");
 }
Example #19
0
 function get()
 {
     $info = $this->getInfo()[0];
     if (!$info) {
         return array();
     }
     if (Requester::isBrandAdmin($info['brand_id'])) {
         $info['holders'] = $this->getByAdmin();
     } else {
         if (Requester::isAccountHolder($this->account_id)) {
             $info['holders'] = $this->getByHolder();
         } else {
             return array(array("balance" => $info['sign'] * $info['balance'], "unit" => $info['unit']));
         }
     }
     return array($info);
 }
Example #20
0
 function __construct($data = '')
 {
     //if (!isset($_GET['txntype'])) Error::http(400, "The request must have a value for the URL query parameter 'txntype'.");
     if (isset($_GET['txntype']) and !in_array($_GET['txntype'], array('np', 'nn', 'pp', 'pn'))) {
         Error::http(400, "The URL query parameter 'txntype' value must be 'np', 'nn', 'pp, OR 'pn'.");
     }
     $this->txntype = $_GET['txntype'];
     $this->subtype = (isset($_GET['subtype']) and $_GET['subtype']) ? $_GET['subtype'] : '';
     $this->{"@type"} = "budgetRecords";
     $this->brand_id = $this->getID();
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "Only members or admins of brand #{$this->brand_id} can view details of its budget activity.");
     }
     $this->{'@id'} = "{$this->root}/budget/{$this->brand_id}/records";
     $this->table = "records";
     $this->init($data);
 }
Example #21
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "The requester is not an admin for brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'brandHolders';
     $this->{"@id"} = "{$this->root}/brand/{$this->brand_id}/holders";
     $this->table = "holders";
     $this->idkey = 'holder_id';
     $this->collectionOf = "holder";
     $this->init($data);
     $this->okToAdd = array("user_id", "account_id", "authcode", "limkey");
     $this->okToSet = array("authcode", "ended");
     $this->okToFilterBy = array("account_id", "user_id", "holder_id");
     $this->okToGet = array('holder_id', 'account_id', 'authcode');
 }
Example #22
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "The requester is not an admin for brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'brandAccounts';
     $this->{"@id"} = "{$this->root}/brand/{$this->brand_id}/accounts";
     $this->table = "accounts";
     $this->idkey = 'account_id';
     $this->collectionOf = "account";
     $this->init($data);
     $this->okToGet = array("brand_id", "account_id", "name", "balance", "unit", "authcode");
     $this->okToAdd = array("brand_id", 'name', 'authcode', 'unit', 'sign');
     $this->okToSet = array("name", "authcode", "throttle_id");
     $this->okToFilterBy = array("brand_id", "account_id");
 }
Example #23
0
 function __construct($data = '')
 {
     $this->{"@type"} = 'user';
     $this->user_id = $this->getID();
     if (!Requester::isUser($this->user_id)) {
         Error::http(401, "The requester must be logged in as the requested user.");
     }
     $this->{"@id"} = "{$this->root}/user/{$this->user_id}";
     $this->table = 'users';
     $this->idkey = 'user_id';
     $this->init($data);
     $this->name = Requester::$name;
     $this->email = Requester::$email;
     $this->okToSet = array("ended", "email", "name", "password");
     $this->okToFilterBy = array("user_id", "email");
     $this->login_provider = Requester::$login_provider;
 }
Example #24
0
 function __construct($data = '')
 {
     $this->account_id = $this->getID();
     $this->setDetails();
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "Only brand admins can access member accounts resource.");
     }
     $this->{"@type"} = "accountHolders";
     $this->{'@id'} = "{$this->root}/account/{$this->account_id}/holders";
     $this->table = "holders";
     $this->idkey = 'holder_id';
     $this->collectionOf = "holder";
     $this->init($data);
     $this->okToAdd = array("user_id", "account_id", "authcode", "limkey");
     $this->okToGet = array("holder_id", "holder_auth", "brand_id", "account_id", "name", "account_auth");
     $this->okToSet = array("authcode", "ended");
     $this->okToFilterBy = array("holder_id");
 }
Example #25
0
 function get()
 {
     if (!Requester::isMember($this->brand_id)) {
         Error::http(403, "Only brand #{$this->brand_id} members have access to this brandThrottles view.");
     }
     $sql = "SELECT * FROM {$this->table} WHERE brand_id=? AND ended IS NULL";
     $items = DBquery::get($sql, array($this->brand_id));
     foreach ($items as &$t) {
         $t['id'] = $t['throttle_id'];
         unset($t['throttle_id']);
         $t['@id'] = "{$this->root}/throttle/" . $t['id'];
         $t['brand'] = "{$this->root}/team/{$this->brand_id}";
         unset($t['brand_id']);
         $this->{$this->collectionOf}[] = $t;
     }
     $this->setForms();
     return array($this);
 }
Example #26
0
 function set()
 {
     if ($this->member_id) {
         $this->setDetails();
     }
     if (Requester::isBrandAdmin($this->brand_id)) {
         array_push($this->okToSet, "role", 'hours', 'ended');
         array_push($this->okToFilterBy, "brand_id", "member_id");
     }
     if ($this->user_id == Requester::$user_id) {
         array_push($this->okToSet, "hours", 'ended');
         array_push($this->okToFilterBy, "member_id");
         if ($this->ended and $this->user_id == Requester::$user_id) {
             Error::http(403, 'To prevent a brand from not having an admin, an admin cannot deactivate his own membership.');
         }
     }
     $this->update("WHERE member_id=?", array($this->member_id));
     return $this;
 }
Example #27
0
 function add($data = '')
 {
     if (!isset($this->email) and !isset($this->fb_id) and !isset($this->gp_id) and !isset($this->tw_id)) {
         Error::http(400, "When registerng a user, an email, facebook id (fb_id), google+ id (gp_id) , or twitter id (tw_id) must be used as input.");
     }
     foreach ($this->okToAdd as $key) {
         $this->addKeyVal($key, "NULL", "ifMissing");
     }
     $this->obj->password = password_hash($this->obj->password, PASSWORD_DEFAULT);
     $this->valArr[array_search('password', $this->keyArr)] = $this->obj->password;
     $User = $this->obj;
     $User->user_id = $this->insert();
     require_once "utils/Router.php";
     Requester::$user_id = $User->user_id;
     unset($User->password);
     //no need to communicate this back for privacy
     $this->setDefaultBrand();
     return array($User);
 }
Example #28
0
 function __construct($data = '')
 {
     $this->brand_id = $this->getID();
     if (!$this->brand_id and $data->brand_id) {
         $this->brand_id = $data->brand_id;
     }
     if (!Requester::isBrandAdmin($this->brand_id)) {
         Error::http(403, "The requester is not an admin for brand #{$this->brand_id}.");
     }
     $this->{"@type"} = 'brandMembers';
     $this->{"@id"} = "{$this->root}/brand/{$this->brand_id}/members";
     $this->table = "members";
     $this->idkey = 'member_id';
     $this->collectionOf = "member";
     $this->init($data);
     $this->okToAdd = array("brand_id", 'user_id', 'role', 'hours');
     $this->okToSet = array("role", 'hours', 'ended');
     $this->okToFilterBy = array("member_id", "user_id");
 }
Example #29
0
 function get()
 {
     $this->setAddlCond();
     //if (!$this->cond) $this->setForms();
     $graph = array($this);
     $tracked = array();
     $nestingRef = array("brand_" => array("@id" => "{$this->root}/brand/{id}/about", "@type" => "brand"));
     $sql = "SELECT promo_id, \n\t\t\t\tp.brand_id AS brand_id, \n\t\t\t\tbrands.name AS brand_name, \n\t\t\t\tp.name AS name, \n\t\t\t\tp.description AS description, \n\t\t\t\tamount, \n\t\t\t\timageURL, \n\t\t\t\tinfoURL, \n\t\t\t\tp.created, \n\t\t\t\tp.updated, \n\t\t\t\tp.expires, \n\t\t\t\tkeyword,\n\t\t\t\tby_all_limit, \n\t\t\t\tby_brand_limit, \n\t\t\t\tby_user_limit, \n\t\t\t\tby_user_wait,\n\t\t\t\tnumUsers\n\t\t\tFROM promos p\n\t\t\tJOIN (\n\t\t\t\tSELECT promo_id, COUNT(DISTINCT from_user) as numUsers\n\t\t\t\tFROM records\n\t\t\t\twhere status=7 AND TIMESTAMPDIFF(DAY,created,NOW())<100\n\t\t\t\tGROUP BY promo_id\n\t\t\t\tORDER BY numUsers DESC\n\t\t\t) records USING (promo_id)\n\t\t\tJOIN relays USING (relay_id)\n\t\t\tJOIN brands USING (brand_id)\n\t\t\tWHERE promo_id {$this->ltgt} {$this->limitID} {$this->cond}\n\t\t\t\tAND (expires IS NULL OR expires>NOW())\n\t\t\t\tAND by_user_limit > 0 AND by_brand_limit > 0 AND by_all_limit > 0\n\t\t\tORDER BY promo_id {$this->pageOrder}\n\t\t\tLIMIT {$this->itemsLimit}";
     $items = DBquery::get($sql, $this->condVals);
     Requester::detectMemberships();
     foreach ($items as &$r) {
         $r['id'] = $r['promo_id'];
         $r['@id'] = "{$this->root}/promo/" . $r['promo_id'];
         $r['@type'] = 'promo';
         if (Requester::isMember($r['brand_id'])) {
             $r['edit'] = '/form/promo-edit';
         }
         $this->nestResources($r, $nestingRef, $graph, $tracked);
         $r['promoPage'] = Requester::$ProtDomain . "/ad/{$r['promo_id']}";
         $r['code'] = "{$r['keyword']}-{$r['promo_id']}";
         $r['payURL'] = Requester::$ProtDomain . "/for/{$r['code']}";
         $r['amount'] = round($r['amount'], 2);
         if (!$r['imageURL']) {
             //$r['imageURL'] = "/ui/logo.php?brand=". $r['brand_name'];
             //$images[] = BrandLogo::wrap($r['brand_name'], $r['imageURL'], 'base64svg');
             //$r['imageURL'] = BrandLogo::base64svg($r['brand_name'], $r['imageURL']);
             //$r['imageURL'] = BrandLogo::dataURL($r['brand_name']);
             $r['imageTemplate'] = "/ui/logo.php";
         }
         if (!$r['expires']) {
             $r['expires'] = "2019-12-31 11:59:59";
         }
         $this->{$this->collectionOf}[] = $r['@id'];
         $p[] = $r;
         $graph[] = $r;
     }
     $this->setPageOf(array("brand_id", "for", "keyword", "id"));
     $this->paginate('promo_id', $p);
     if ($this->cond) {
         return $graph;
     }
     return array_merge($graph, array(BrandLogo::svgTemplate()));
 }
 public function executeGetRequesters(sfWebRequest $request)
 {
     $result = Requester::getChatMessengerDetails($_SESSION['userId']);
     $requester = array();
     $member_ids = array();
     foreach ($result as $v) {
         if ($v['requester_id'] != $_SESSION['userId']) {
             $member_ids[$v['posting_id']][] = $v['requester_id'];
         }
         if ($v['member_id'] != $_SESSION['userId']) {
             $member_ids[$v['posting_id']][] = $v['member_id'];
         }
         $requester['Upcoming Hangouts'][$v['posting_id']] = $v['posting_title'];
     }
     $data = array();
     foreach ($member_ids as $posting_id => $requester_ids) {
         $data['Upcoming Hangouts'][$posting_id . '_' . implode("_", array_unique($requester_ids))] = $requester['Upcoming Hangouts'][$posting_id];
     }
     die(json_encode($data));
 }