<?php include "Connection.php"; include "Usr.php"; $u = new Usr(); $u->email = $_GET['email']; $u->password = $_GET['password']; $p = Usr::recherche($bd, $u); if ($p == 1) { header('location: cart.html'); } else { header("Location: index.php?erreur=2"); }
/** * @before _secure * @after _cleanUp */ public function advertiser($id = null) { $view = $this->getActionView(); $org = $this->_org; if ($id) { $advertiser = User::first(['org_id' => $org->_id, 'type' => 'advertiser', '_id' => $id]); } else { $advertiser = null; } if ($id && !$advertiser) { return $this->failure('30'); } $type = RequestMethods::type(); switch ($type) { case 'GET': $data = Usr::display($org, 'advertiser', $id); $view->set('data', $data); break; case 'POST': if ($id) { // edit an advertiser $allowedFields = ['name', 'phone', 'country', 'currency']; foreach ($allowedFields as $f) { $advertiser->{$f} = RequestMethods::post($f, $publisher->{$f}); } $advertiser->save(); $view->set('message', 'Advertiser Updated!!')->set('success', true); } else { // create new $this->_registerUser('advertiser', ['template' => 'advertReg']); } break; case 'DELETE': $this->_deleteUser($advertiser, 'Advertiser'); break; } }
/** * Process the Meta table for campaign urls and create the * campaign from the corresponding URL */ protected function importCampaigns() { $metas = \Meta::all(['prop = ?' => 'campImport']); $users = []; $orgs = []; foreach ($metas as $m) { $user = Usr::find($users, $m->propid, ['_id', 'org_id', 'email', 'meta']); $org = \Organization::find($orgs, $user->org_id); $categories = \Category::all(['org_id' => $org->_id], ['_id', 'name']); $categories = array_values($categories); $category = $categories[array_rand($categories)]; // fetch ad info foreach URL $advert_id = $m->value['advert_id']; $comm = $m->value['campaign'] ?? $org->meta; if (!isset($comm['model']) || !isset($comm['rate'])) { continue; } $urls = $m->value['urls']; foreach ($urls as $url) { $ad = \Ad::first(['org_id' => $org->_id, 'url' => $url]); if ($ad) { continue; } // already crawled URL may be due to failed cron earlier $data = Utils::fetchCampaign($url); $image = Utils::downloadImage($data['image']); if (!$image) { $image = ''; } $ad = new \Ad(['user_id' => $advert_id, 'org_id' => $org->_id, 'title' => $data['title'], 'description' => $data['description'], 'url' => $url, 'image' => $image, 'category' => [$category->_id], 'type' => 'article', 'live' => false, 'device' => ['ALL']]); if ($ad->validate()) { $ad->save(); $rev = $comm['revenue'] ?? 1.25 * (double) $comm['rate']; $commission = new \Commission(['ad_id' => $ad->_id, 'model' => $comm['model'], 'rate' => $comm['rate'], 'revenue' => round($rev, 6), 'coverage' => ['ALL']]); $commission->save(); } else { var_dump($ad->getErrors()); } } $msg = 'Campaigns imported for the user: ' . $user->email; $this->log($msg); $m->delete(); } }