Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?
- class exports
- {
- public $campaigns = [];
- public $users = [];
- public $offers = [];
- public $prelanders = [];
- public $results = [];
- public $days = [];
- public $daysData = 5;
- public $minTraff = 1;
- public $defPassword = '';
- public $env = 'tequila';
- public $envOrig = 'test';
- public $limit = false;
- public $oss = [
- 0 => 'Linux',
- 1 => 'Windows',
- 2 => 'Mac OS',
- 3 => 'Android',
- 4 => 'iOS',
- 5 => 'AIX',
- 6 => 'Amiga OS',
- 7 => 'Arch',
- 8 => 'Bada',
- 9 => 'BeOS',
- 10 => 'BlackBerry',
- 11 => 'CentOS',
- 12 => 'Chromium OS',
- 13 => 'Contiki',
- 14 => 'Fedora',
- 15 => 'Firefox OS',
- 16 => 'FreeBSD',
- 17 => 'Debian',
- 18 => 'DragonFly',
- 19 => 'Gentoo',
- 20 => 'GNU',
- 21 => 'Haiku',
- 22 => 'Hurd',
- 23 => 'Joli',
- 24 => 'Linpus',
- 25 => 'Mageia',
- 26 => 'Mandriva',
- 27 => 'MeeGo',
- 28 => 'Minix',
- 29 => 'Mint',
- 30 => 'Morph OS',
- 31 => 'NetBSD',
- 32 => 'Nintendo',
- 33 => 'OpenBSD',
- 34 => 'OpenVMS',
- 35 => 'OS/2',
- 36 => 'Palm',
- 37 => 'PCLinuxOS',
- 38 => 'Plan9',
- 39 => 'Playstation',
- 40 => 'QNX',
- 41 => 'RedHat',
- 42 => 'RIM Tablet OS',
- 43 => 'RISC OS',
- 44 => 'Sailfish',
- 45 => 'Series40',
- 46 => 'Slackware',
- 47 => 'Solaris',
- 49 => 'SUSE',
- 50 => 'Symbian',
- 51 => 'Tizen',
- 52 => 'Ubuntu',
- 53 => 'UNIX',
- 54 => 'VectorLinux',
- 55 => 'WebOS',
- 56 => 'Windows Phone',
- 57 => 'Windows Mobile',
- 58 => 'Zenwalk'
- ];
- /**
- * Device Types / Traffic Type
- */
- public $types = [
- 0 => 'mobile',
- 1 => 'desktop',
- 2 => 'tablet',
- 3 => 'smarttv',
- 4 => 'console',
- 5 => 'werable',
- 6 => 'embedded'
- ];
- public $rates = [];
- /**
- * Device Vendors
- */
- public $vendors = [
- 0 => 'Acer',
- 1 => 'Alcatel',
- 2 => 'Amazon',
- 3 => 'Apple',
- 4 => 'Archos',
- 5 => 'Asus',
- 6 => 'BenQ',
- 7 => 'BlackBerry',
- 8 => 'Dell',
- 9 => 'GeeksPhone',
- 10 => 'Google',
- 11 => 'HP',
- 12 => 'HTC',
- 13 => 'Huawei',
- 14 => 'Jolla',
- 15 => 'Lenovo',
- 16 => 'LG',
- 17 => 'Meizu',
- 18 => 'Microsoft',
- 19 => 'Motorola',
- 20 => 'Nexian',
- 21 => 'Nintendo',
- 22 => 'Nokia',
- 23 => 'Nvidia',
- 24 => 'Ouya',
- 25 => 'Palm',
- 26 => 'Panasonic',
- 28 => 'Polytron',
- 29 => 'RIM',
- 30 => 'Samsung',
- 31 => 'Sharp',
- 32 => 'Siemens',
- 33 => 'Sony-Ericsson',
- 34 => 'Sprint',
- 35 => 'Xbox',
- 36 => 'ZTE',
- ];
- /*
- // DEFAULT user
- TRUNCATE accounts CASCADE;
- ALTER SEQUENCE accounts_id_seq RESTART WITH 1;
- TRUNCATE campaigns CASCADE;
- ALTER SEQUENCE campaigns_id_seq RESTART WITH 1;
- TRUNCATE companies CASCADE;
- ALTER SEQUENCE companies_id_seq RESTART WITH 1;
- TRUNCATE offers CASCADE;
- ALTER SEQUENCE offers_id_seq RESTART WITH 1;
- TRUNCATE prelanders CASCADE;
- ALTER SEQUENCE prelanders_id_seq RESTART WITH 1;
- TRUNCATE "additionalManagers" CASCADE;
- TRUNCATE prelanders CASCADE;
- TRUNCATE "offerPrelanders" CASCADE;
- TRUNCATE prelanders CASCADE;
- TRUNCATE "campaignOffers" CASCADE;
- TRUNCATE "payouts" CASCADE;
- TRUNCATE prelanders CASCADE;
- TRUNCATE "targetingDetailIsps" CASCADE;
- TRUNCATE "targetingDetails" CASCADE;
- TRUNCATE "targetingRules" CASCADE;
- TRUNCATE "targetingRulesItems" CASCADE;
- INSERT INTO "public"."accounts" ("id", "email", "secondaryEmails", "password", "languages", "phoneNumbers", "addresses", "role", "lastAccess", "activationEmailToken", "path", "createdAt", "updatedAt", "deletedAt") VALUES (E'1', E'admin@proxima.si', NULL, E'$2a$10$vdUSp7WkeWEXIzJch.fTRe589I8LnTVLHezlnV1thoZNupejWJRsy', E'{}', E'{}', NULL, E'ADMIN', E'2017-06-01 07:48:23.26+00', E'a4f24b28-73e4-4d2e-b4e3-95884c6b1c11', NULL, E'2017-05-31 15:25:42.025+00', E'2017-06-01 07:48:23.26+00', NULL);
- INSERT INTO "public"."companies" ("id", "name", "alias", "description", "domain", "billingInformation", "createdAt", "updatedAt", "deletedAt", "createdById") VALUES (E'1', E'Default Company', E'Default Company', E'Default Company', E'default.com', NULL, E'2017-05-31 15:25:42.066+00', E'2017-05-31 15:25:42.066+00', NULL, E'1');
- */
- /**
- * Operating Systems
- * @see https://github.com/faisalman/ua-parser-js#methods
- */
- public function __construct($days = false){
- set_time_limit(0);
- ini_set('mysql.connect_timeout','0');
- ini_set('max_execution_time', '0');
- for($i = 0; $i < $this->daysData; $i++)
- $this->days[] = date("Y-m-d", strtotime('-'. $i .' days'));
- $this->connect();
- echo PHP_EOL . 'CONNECTED TO MYSQL DATABASE';
- $this->connect_psql();
- echo PHP_EOL . 'CONNECTED TO postgres DATABASE';
- echo PHP_EOL . 'GETTIG CONVERSION RATE...';
- $this->rates = json_decode(file_get_contents('http://api.fixer.io/latest'))->rates->USD ;
- echo PHP_EOL . ' 1 EUR = USD ' . $this->rates ;
- //USERS AND USER RELATIONS!
- $users = $this->getUsers();
- if($this->limit)
- $users = array_slice($users, 0, 20,true);
- $companies = $this->getCompanies($users);
- if($this->limit)
- $companies = array_slice($companies, 0, 20,true);
- //we need users to know companies, but we need to insert companies and generate unique ids first.
- $companies = $this->insertCompanies($companies);
- $this->insertUsers($users, $companies);
- echo PHP_EOL . 'INSERTING USER RELATIONS...';
- foreach($users as $k => $v){
- if($v['role'] == 'MANAGER'){
- $relations = $this->getUserRelations($v['id'], $users);
- echo "\r Relations for : " . $v['email'] . ' has access to ' . count($relations) . ' users. ';
- $this->insertUserRelations($v['id'], $relations);
- }
- }
- echo PHP_EOL . 'GETTING USED OFFERS AND CAMPAIGNS LAST MONTH ...';
- $res = $this->getOfferIdsLastDays();
- //companies needs users so we can know each company default currency
- $offids = $cgids = [];
- foreach($res as $k => $v){
- $cgids[] = $v['campaignid'];
- $offids[]= $v['offerid'];
- }
- echo PHP_EOL . 'GETTING CAMPAIGNS ...';
- $campaigns = $this->getCampaigns($cgids);
- $this->insertCampaigns($campaigns);
- echo PHP_EOL . 'GETTING OFFERS ...';
- $offers = $this->getOffers($cgids);
- echo PHP_EOL . 'GETTING OFFER DETAILS ...';
- $offers = $this->getOffersTargetingDetails($offers);
- /*
- Give the advertiserid get the right currency
- */
- foreach($offers as $k => $offer){
- foreach($users as $u){
- if($u['id'] == $offer['advertiser']){
- $offers[$k]['currency']= $u['currency'];
- break;
- }
- }
- }
- $offers = $this->getOffersRevenues($offers);
- echo PHP_EOL . 'INSERTING OFFERS ';
- $offers = $this->insertOffers($offers);
- echo PHP_EOL . 'INSERT OFFERS TARGETING';
- $this->insertOffersTargeting($offers);
- echo PHP_EOL . 'INSERT OFFERS REVENUES';
- $this->insertOffersRevenues($offers);
- echo PHP_EOL . 'INSERTING OFFERS TO CAMPAIGNS....' . PHP_EOL;
- foreach($offers as $offer)
- $this->insertOfferCampaigns($offer);
- //getPrelnaders based, on prelanders used per offer.
- echo PHP_EOL . 'GETTING PRELANDERS';
- $prelanders = array();
- foreach($offers as $ok => $offer)
- $prelanders[] = $offers[$ok]['prelanders'] = $this->getPrelanders($offer);
- $prelanders = array_values($prelanders);
- //prelanders should have unique urls... but that's too complicated for now, they only have if the coincide.
- //returns the offer , includes all prelanders and the new ids for those prelanders.
- echo PHP_EOL . 'INSERTING PRELANDERS' . PHP_EOL;
- foreach($offers as $ko => $offer)
- $offers[$ko] = $this->insertPrelanders($offer);
- echo PHP_EOL . 'INSERTING PRELANDER TARGETING' . PHP_EOL;
- foreach($offers as $ko => $offer)
- $this->insertPrelanderTargeting($offer);
- echo PHP_EOL . 'INSERT PRELANDER/OFFERS RELATIONS' . PHP_EOL;
- foreach($offers as $ko => $offer)
- $this->insertPrelanderOfferRelations($offer);
- }
- /*for each offfer we insert the prelander*/
- public function insertPrelanderTargeting($offer){
- if(isset($offer['prelanders']) && !empty($offer['prelanders'])){
- foreach($offer['prelanders'] as $kl => $pl){
- $sql = "INSERT INTO \"targetingDetails\" (\"countries\", \"countriesInclude\", \"ispsInclude\", \"prelanderId\") ";
- $sql .= "VALUES ";
- $sql .= "('{".implode(',',$pl['targeting']['countries'])."}', true, true, " . $pl['id'] . ") RETURNING \"id\";";
- $result = pg_query($sql);
- $id = false;
- while ($row = pg_fetch_array($result)) $id = $row['id'];
- if($id && !empty($pl['targeting']['carriers'])){
- foreach($pl['targeting']['carriers'] as $isps){
- if(is_int($isps)){
- $sql2 = "INSERT INTO \"targetingDetailIsps\" (\"createdAt\", \"updatedAt\", \"targetingDetailId\", \"ispId\") VALUES (current_timestamp, current_timestamp, $id, $isps);";
- $result = pg_query($sql2);
- }else{
- echo PHP_EOL . 'unknown carrier: '.$isp ;
- }
- }
- }
- }
- }
- }
- public function insertPrelanderOfferRelations($offer){
- foreach($offer['prelanders'] as $k => $v){
- $cmd = './../Serhii/scripts/app -p ' . $v['id'] . ' -o ' . $offer['id'];
- shell_exec($cmd);
- echo "\r". ' campaign: ' . $offer['id'] . ' prelander: ' . $v['id'] ;
- }
- }
- public function insertPrelanders($offer){
- if($offer && !empty($offer['prelanders'])){
- $i = 1;
- foreach ($offer['prelanders'] as $k=> $pl){
- $sql ="INSERT INTO prelanders (\"name\", \"url\",\"createdAt\", \"updatedAt\", \"managerId\", \"createdById\") VALUES ";
- $sql .=" ('" . $pl['name'] . "', '" . $pl['url'] . "', current_timestamp, current_timestamp,1,1 ) RETURNING \"id\" ";
- $result = pg_query($sql);
- while ($row = pg_fetch_array($result)) $id = $offer['prelanders'][$k]['id'] = $row['id'];
- echo "\r Inserted prelander($id) from offer: ".$offer['id']." ( $i of " . count($offer['prelanders']) . " ).";
- $i++;
- }
- }
- return $offer;
- }
- public function __destruct(){
- echo PHP_EOL ;
- }
- public function toPgArray($set) {
- settype($set, 'array'); // can be called with a scalar or array
- $result = array();
- foreach ($set as $t) {
- if (is_array($t)) {
- $result[] = to_pg_array($t);
- } else {
- $t = str_replace('"', '\\"', $t); // escape double quote
- if (! is_numeric($t)) // quote only non-numeric values
- $t = '"' . $t . '"';
- $result[] = $t;
- }
- }
- return '{' . implode(",", $result) . '}'; // format
- }
- public function getPrelanders($offer, $prelanders = array() ){
- $campaigns = " AND CL_CAMPAIGNID IN (".implode(',', $offer['campaigns']).") ";
- foreach($this->days as $k => $d ){
- echo "\r Getting prelanders and targetting for offer: " . $offer['id'] . ". On date ($d)";
- $sql ="SELECT count(1) c, CSO_URL url, CL_OFFERID offerid, CSO_NAME name, CL_COUNTRY country, CLE_WAP_CARRIER carrier FROM `CLICKS_$d`, `CLICKS_EXTRA_$d`, CAMPAIGNS_SPLASH_OFFER WHERE CL_ID = CLE_CLICKID AND CSO_CAMPAIGNID = CL_CAMPAIGNID AND CSO_SPOFID = CL_OFFERID AND CSO_SPOFTYPE = 1 AND CL_OFFERID = " . $offer['offid'] . " $campaigns AND (CL_CLICKDATE IS NULL OR CL_CLICKDATE <> CL_VIEWDATE) GROUP BY CL_COUNTRY, CLE_WAP_CARRIER ORDER BY c desc LIMIT 10";
- try{
- $stmt = $this->pdo->query($sql);
- $t_prelanders = $stmt->fetchAll();
- }catch(Exception $e){
- echo PHP_EOL . 'Connection broke.... Reconnecting ';
- $this->connect();
- $stmt = $this->pdo->query($sql);
- $t_prelanders = $stmt->fetchAll();
- }
- if($t_prelanders && !empty($t_prelanders)){
- foreach( $t_prelanders as $k => $v ){
- $carrier = false;
- $checkCarriersSQL = "SELECT id FROM isps WHERE isp LIKE '%" . $v['carrier'] . "%'";
- $response = pg_query($checkCarriersSQL);
- $response = pg_fetch_assoc($response);
- if(isset($response['id'])){
- $carrier = (int)$response['id'];
- }else{
- $carrier = $v['carrier'];
- }
- if(isset($prelanders[$v['url']])){
- $prelanders[$v['url']]['targeting']['countries'][] = $v['country'];
- $prelanders[$v['url']]['targeting']['carriers'][] = $carrier;
- $prelanders[$v['url']]['oldIds'][] = $v['offerid'];
- }else{
- $prelanders[$v['url']] = [
- 'url'=>$v['url'],
- 'name'=>$v['name'],
- 'oldIds'=>[$v['offerid']],
- 'targeting'=>[
- 'countries'=>[$v['country']],
- 'carriers'=>[$carrier]
- ]
- ];
- }
- $prelanders[$v['url']]['targeting']['countries'] = array_unique($prelanders[$v['url']]['targeting']['countries']);
- $prelanders[$v['url']]['targeting']['carriers'] = array_unique($prelanders[$v['url']]['targeting']['carriers']);
- }
- }
- }
- return $prelanders;
- }
- public function checkForSid($sid){
- for($i = 0; $i < 30; $i++)
- $days[] = date("Y-m-d", strtotime('-'. $i .' days'));
- foreach($days as $day){
- $sql = "SELECT * FROM `SIDS_$day` WHERE SID_TRANSACTIONID LIKE '$sid';";
- $stmt = $this->pdo->query($sql);
- $res = $stmt->fetchAll();
- echo $day . PHP_EOL;
- print_r($res);
- }
- }
- public function connect(){
- $host = '';
- $db = '';
- $user = '';
- $pass = '';
- $charset = 'utf8';
- $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
- $opt = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false,
- ];
- $this->pdo = new PDO($dsn, $user, $pass, $opt);
- }
- public function connect_psql(){
- $host = "host = 127.0.0.1";
- $port = "port = 5433";
- $dbname = "dbname = maverick";
- $credentials = "user = postgres password=cfvceyu";
- $this->psql = pg_connect( "$host $port $dbname $credentials" );
- if(!$this->psql) {
- echo "Error : Unable to open database\n";
- } else {
- }
- }
- public function getOffersRevenues($offers){
- echo PHP_EOL . "GETTING OFFER REVENUES...." . PHP_EOL ;
- $i = 0;
- foreach($offers as $k => $v ) {
- $i++;
- $offers[$k]['quantity'] = $v['revenue'] ;
- $offers[$k]['precentage'] = 0 ;
- unset($offers[$k]['revenue']);
- foreach($v['campaigns'] as $kc => $vc){
- $sql = "SELECT CCP_STARTD `date`,CCP_ADPUBID pubid ,CCP_CAMPAIGNID cgid, CCP_AMOUNT/100 as quantity, CCP_PERCENT as percentage
- FROM CAMPAIGNS_CUSTOM_PAYOUT
- WHERE CCP_TYPE = 3 AND CCP_CAMPAIGNID = " . $vc . " AND CCP_ADPUBID = ". $v['advertiser'] . "
- ORDER BY CCP_STARTD DESC LIMIT 1";
- // echo PHP_EOL . $sql . PHP_EOL;
- echo "\r(".$i." of ".count($offers).") - Offer in campaignid: ". $vc . " ";
- try{
- $stmt = $this->pdo->query($sql);
- $revenues = $stmt->fetchAll();
- } catch (Exception $e) {
- echo $sql;
- die("Oh noes! There's an error in the query!");
- }
- foreach($revenues as $m => $n)
- $offers[$k]['revenues'][] = ['quantity'=>$n['quantity'],'default'=>'no','startDate'=>$n['date']];
- }
- foreach($v['campaigns'] as $mk=>$mv){
- $msql = "SELECT * FROM CUSTOM_PAYOUT WHERE CP_CAMPAIGNID = " . $mv . " AND CP_ADVERTISERID = " . $v['advertiser'];
- $stmt = $this->pdo->query($msql);
- $c_revenues = $stmt->fetchAll();
- if($c_revenues && !empty($c_revenues)){
- foreach($c_revenues as $z => $y)
- $offers[$k]['global_campaigns'][] = $y;
- }
- }
- }
- return $offers;
- }
- public function insertOffersRevenues($offers){
- foreach($offers as $k => $offer){
- $this->insertOfferRevenues($offer);
- }
- return $offers;
- }
- public function insertOfferRevenues($offer){
- $priority = 1;
- if(isset($offer['revenues']) && !empty($offer['revenues'])){
- $payoutModel = $offer['revenueModel'] == 1 ? 'RPA' : $offer['revenueModel'] == 3 ? 'RPC' : false ;
- $i = 1;
- foreach($offer['revenues'] as $k => $revenues){
- echo "\r INSERTING CUSTOM REVENUES OFFER ID: ".$offer['id']." (".$i." of ".count($offer['revenues']).") ";
- $i++;
- $payout = $offer['currency'] == 'USD' ? ['EUR'=> round($revenues['quantity'] * (1/$this->rates),4), 'USD'=>round($revenues['quantity'],4)] : ['EUR'=>round($revenues['quantity'],4),'USD' => round($revenues['quantity']*$this->rates ,4)];
- $payout = json_encode($payout);
- $sql = 'INSERT INTO "public"."payouts" ("payout", "priority" ,"payoutModel", "createdAt", "offerId","startDate", "updatedAt", "createdById","updatedById", "publisherId")';
- $sql .= " VALUES " ;
- $sql .= " ('$payout' , $priority ,'$payoutModel', current_timestamp, ".$offer['id'].", ('".$revenues['startDate']." 00:00:00')::timestamp, current_timestamp ,1,1,1)" ;
- pg_query($sql);
- $priority++;
- }
- }
- $i = 1;
- if(isset($offer['global_campaigns']) && !empty($offer['global_campaigns'])){
- foreach($offer['global_campaigns'] as $gk => $gc){
- $payout = '{"EUR": '.round($gc['CP_REVENUE_EUR'],4).',"USD":'.round($gc['CP_REVENUE_USD'],4).'}';
- $payoutModel = $gc['CP_REVENUE_MODEL'] == 1 ? 'RPA' : $gc['CP_REVENUE_MODEL'] == 3 ? 'RPC' : false ;
- echo "\r Inserting offer id: ".$offer['id']." (" . $i++ . " of ".count($offer['global_campaigns']).") ";
- $sql = 'INSERT INTO "public"."payouts" ("payout", "priority" ,"payoutModel", "createdAt", "offerId","startDate", "updatedAt", "createdById","updatedById", "publisherId")';
- $sql .= " VALUES " ;
- $sql .= " ('$payout' , $priority ,'$payoutModel', current_timestamp, ".$offer['id'].", current_timestamp, current_timestamp ,1,1,1)" ;
- pg_query($sql);
- $priority++;
- }
- }
- }
- public function insertOffersTargeting($offers){
- foreach($offers as $offer){
- $sql = "INSERT INTO \"targetingDetails\" (\"countries\", \"countriesInclude\", \"ispsInclude\", \"offerId\") ";
- $sql .= "VALUES ";
- if(!isset($offer['targeting'])) continue;
- $sql .= "('{".implode(',',$offer['targeting']['countries'])."}', true, true, " . $offer['id'] . ") RETURNING \"id\";";
- $result = pg_query($sql);
- $id = false;
- while ($row = pg_fetch_array($result)) $id = $row['id'];
- if($id && !empty($offer['targeting']['carriers'])){
- foreach($offer['targeting']['carriers'] as $isps){
- if(is_int($isps)){
- $sql2 = "INSERT INTO \"targetingDetailIsps\" (\"createdAt\", \"updatedAt\", \"targetingDetailId\", \"ispId\") VALUES (current_timestamp, current_timestamp, $id, $isps);";
- $result = pg_query($sql2);
- }else{
- echo PHP_EOL . 'unknown carrier: '.$isps ;
- }
- }
- }
- }
- }
- public function getOffersTargetingDetails($offers){
- echo PHP_EOL ;
- $campaigns = '';
- foreach($offers as $v => $o){
- $campaigns = "AND CL_CAMPAIGNID IN (" . implode(',', $o['campaigns']) . ")";
- foreach($this->days as $k => $d ){
- //check Countries
- echo "\r Checking for Countries on Offer id: " .$o['offid'] . ". Day($d) ";
- $sqlCountries = "SELECT count(1) max, CL_COUNTRY FROM `CLICKS_$d`, `CLICKS_EXTRA_$d` WHERE CL_ID = CLE_CLICKID AND CL_OFFERID = " . $o['offid'] . " $campaigns GROUP BY CL_COUNTRY ORDER BY max desc LIMIT 10";
- $stmt = $this->pdo->query($sqlCountries);
- $res = $stmt->fetchAll();
- if($res && count($res)> 0){
- foreach($res as $m=> $n){
- $offers[$v]['targeting']['countries'][] = $n['CL_COUNTRY'];
- }
- $offers[$v]['targeting']['countries'] = array_unique( $offers[$v]['targeting']['countries']);
- }
- //check OS
- echo "\r Checking for OS types on Offer id: " .$o['offid'] . ". Day($d) ";
- $sqlOS = "SELECT count(1) max, CLE_WAP_OS FROM `CLICKS_$d`, `CLICKS_EXTRA_$d` WHERE CL_ID = CLE_CLICKID AND CL_OFFERID = " . $o['offid'] . " $campaigns GROUP BY CLE_WAP_OS ORDER BY max desc LIMIT 10";
- $stmt = $this->pdo->query($sqlOS);
- $res = $stmt->fetchAll();
- if($res && count($res)> 0){
- foreach($res as $m=> $n){
- $offers[$v]['targeting']['os'][] = $n['CLE_WAP_OS'];
- }
- $offers[$v]['targeting']['os'] = array_unique( $offers[$v]['targeting']['os']);
- }
- //check ISP
- echo "\r Checking for Carriers types on Offer id: " .$o['offid'] . ". Day($d) ";
- $sqlISP = "SELECT count(1) max, CLE_WAP_CARRIER FROM `CLICKS_$d`, `CLICKS_EXTRA_$d` WHERE CL_ID = CLE_CLICKID AND CL_OFFERID = " . $o['offid'] . " $campaigns GROUP BY CLE_WAP_CARRIER ORDER BY max desc LIMIT 10";
- $stmt = $this->pdo->query($sqlISP);
- $res = $stmt->fetchAll();
- if($res && count($res)> 0){
- foreach($res as $m=> $n){
- $checkCarriersSQL = "SELECT id FROM isps WHERE isp LIKE '%" . $n['CLE_WAP_CARRIER'] . "%'";
- $response = pg_query($checkCarriersSQL);
- $response = pg_fetch_assoc($response);
- if(isset($response['id'])){
- $offers[$v]['targeting']['carriers'][] = (int)$response['id'];
- }else{
- $offers[$v]['targeting']['carriers'][] = $n['CLE_WAP_CARRIER'];
- }
- }
- $offers[$v]['targeting']['carriers'] = array_unique($offers[$v]['targeting']['carriers']);
- }
- }
- }
- return $offers;
- }
- public function insertOffers($offers){
- $i = 0;
- echo PHP_EOL;
- foreach($offers as $k=> $offer){
- $i++;
- echo "\r(".$i." of ".count($offers).") - Inserting Offer... : ";
- $offers[$k]['id'] = $this->insertOffer($offer);
- echo "\r(".$i." of ".count($offers).") - Offer " . $offers[$k]['id'] . " INSERTED ";
- }
- return $offers;
- }
- public function insertOfferCampaigns($offer = []){
- foreach($offer['campaigns'] as $c){
- $cmd = './../Serhii/scripts/app -c ' . $c . ' -o ' . $offer['id'];
- shell_exec($cmd);
- echo "\r". ' campaign: ' . $c . ' offerid: ' . $offer['id'] ;
- }
- }
- public function insertOffer($v){
- extract($v);
- $payout = $currency == 'USD' ? ['EUR'=> round($quantity * (1/$this->rates),4), 'USD'=>round($v['quantity'],4)] : ['EUR'=>round($quantity,4), 'USD'=>round($quantity * $this->rates,4)];
- $payoutModel = $revenueModel == 1 ? 'RPA' : $revenueModel == 3 ? 'RPC' : false ;
- $abs = !isset($percentage) || !$precentage ? json_encode($payout,true) : $percentage ;
- $abs = isset($percentage) ? $percentage : json_encode($payout,true) ;
- $sql = "INSERT INTO \"offers\" (\"name\",\"description\",\"payout\", \"payoutModel\",\"url\", \"updatedAt\",\"createdAt\", \"createdById\", \"accountId\", \"managerId\", \"advertiserId\",\"updatedById\") ";
- $sql .= " VALUES ( '" . str_replace("'","''",$name) . "', '', '". $abs ."','$payoutModel' ,'".$url."', current_timestamp , current_timestamp , 1,1,1, $advertiser,1) RETURNING \"id\" ";
- $result = pg_query($sql);
- $id = false;
- while ($row = pg_fetch_array($result)) $id = $row['id'];
- return $id;
- }
- public function getOffers($ids){
- $sql ="SELECT GROUP_CONCAT(DISTINCT t.cgid) campaigns,t.type as `revenueModel`, MAX(t.name) as `name`,t.offid offid, t.url, t.advid advertiser,t.revenue/100 `revenue` FROM (
- SELECT CSO_REVENUE_TYPE as type, CSO_REVENUE_AMOUNT as `revenue`, CSO_CAMPAIGNID cgid, COUNT(1) AS counter, MAX(CSO_NAME) AS name, CSO_URL url, CSO_SPOFID AS offid, CSO_ADVERTISERID advid
- FROM CAMPAIGNS_SPLASH_OFFER, CAMPAIGNS
- WHERE CSO_CAMPAIGNID = CA_ID AND CSO_SPOFTYPE = 2
- AND CSO_CAMPAIGNID IN (".implode(',',$ids).")
- GROUP BY CSO_URL
- UNION ALL
- SELECT CSO_REVENUE_TYPE as type, CSO_REVENUE_AMOUNT as `revenue`,CSO_CAMPAIGNID cgid, COUNT(1) AS counter, MAX(CSO_NAME) AS name, CSO_URL url, CSO_SPOFID AS offid, CSO_ADVERTISERID advid
- FROM CAMPAIGNS_SPLASH_OFFER, CAMPAIGNS
- WHERE CSO_CAMPAIGNID = CA_ID AND CA_OFFER_RULES NOT LIKE '{}' AND CA_OFFER_RULES NOT LIKE '[]' AND CA_OFFER_RULES IS NOT NULL
- AND CSO_SPOFTYPE = 2 AND CSO_ACTIVE = 1 AND CSO_SHARE > 0
- AND CSO_CAMPAIGNID IN (".implode(',',$ids).")
- GROUP BY CSO_URL
- ) t GROUP BY t.url
- ";
- $stmt = $this->pdo->query($sql);
- $res = $stmt->fetchAll();
- foreach($res as $k=> $v){
- $res[$k]['campaigns'] = explode(',',$v['campaigns']);
- }
- return $res;
- }
- public function hotfixes(){
- echo PHP_EOL . 'ADDITIONAL PATCHES:';
- echo PHP_EOL . 'REMOVING NON EXISTING COUNTRY CODES (AN):';
- $sql1 ="DELETE FROM public.payouts WHERE country like 'AN';";
- }
- public function insertCustomCost($costs, $globalCampaigns, $payoutModel, $cgid, $currency){
- //we insert campaign custom costs.
- $priority = 1;
- $l = 0;
- foreach($costs as $k=> $v){
- $l++;
- echo "\r Campaign $cgid. Custom Costs( $l of ".count($costs)." ) ";
- $payout = $currency == 'USD' ? ['EUR'=> round($v['quantity'] * (1/$this->rates),4), 'USD'=>round($v['quantity'],4)] : ['EUR'=>round($v['quantity'],4), 'USD'=>round($v['quantity'] * $this->rates,4)];
- $payout = json_encode($payout);
- if($payoutModel == 'REVENUE_SHARE'){
- $payout = json_encode(['share'=>$v['percentage']]);
- }
- if($v['managerId'] == 74)
- $v['managerId'] = 1;
- $sql = 'INSERT INTO "public"."payouts" ("payout", "priority" ,"payoutModel", "createdAt", "updatedAt", "campaignId", "createdById","updatedById", "publisherId")';
- $sql .= " VALUES " ;
- $sql .= " ('$payout' , $priority ,'$payoutModel', current_timestamp, current_timestamp, $cgid, ".$v['managerId'].",".$v['managerId'].",".$v['publisher']." )" ;
- $result = pg_query($sql);
- $priority++;
- }
- //we insert global campaigns
- $e = 0;
- foreach($globalCampaigns as $gk => $gv){
- $e++;
- echo "\r Campaign $cgid. Global campaigns( $e of ".count($globalCampaigns)." ) ";
- $priority++;
- $payout = json_encode(['EUR'=>round((float)$gv['CP_COST_EUR'],4), 'USD'=>round((float)$gv['CP_COST_USD'],4)]);
- $payoutModel = $gv['CP_COST_MODEL'] == '1' ? 'CPA' : 'CPC';
- if($gv['CP_MANAGERID'])
- $gv['CP_MANAGERID'] = 1 ;
- $sqla = 'INSERT INTO "public"."payouts" ("payout", "priority" ,"country","payoutModel", "createdAt", "updatedAt", "campaignId", "createdById","updatedById", "publisherId")';
- $sqla .= " VALUES " ;
- $sqla .= " ('$payout' , $priority ,'".$gv['CP_COUNTRY']."','$payoutModel', current_timestamp, current_timestamp, ".$gv['CP_CAMPAIGNID'].", ".$gv['CP_MANAGERID'].",".$gv['CP_MANAGERID'].",".$gv['CP_PUBLISHERID']." )" ;
- $result = pg_query($sqla);
- }
- /*
- INSERT INTO "public"."payouts" ("id", "payout", "payoutModel", "createdAt", "updatedAt", "deletedAt", "campaignId", "createdById", "publisherId") VALUES (E'1', E'{"EUR": 0.0001, "USD": 0.00011179}', E'CPC', E'2017-05-26 14:41:51.742+00', E'2017-05-26 14:41:51.742+00', NULL, E'1', E'1', E'138');
- */
- }
- public function insertCampaigns($campaigns){
- echo PHP_EOL . 'INSERTING CAMPAIGNS' . PHP_EOL;
- $count = 1;
- foreach($campaigns as $k=> $c){
- echo "\r Campaign ".$c['id'].". INSERTING ";
- $this->insertCampaign($c);
- echo "\r Campaign ".$c['id'].". DONE ";
- $count ++;
- }
- }
- public function insertCampaign($campaign){
- extract($campaign);
- $hideReferer = $hideReferer == 1 ? 'true' : 'false' ;
- $payout = $currency == 'USD' ? ['EUR'=>($cost*(1/$this->rates)), 'USD'=>$cost] : ['EUR'=>$cost, 'USD'=>$cost*$this->rates];
- $payout = json_encode($payout,true);
- $description = str_replace("'","''",$description);
- $name = str_replace("'","''",$name);
- $payoutModel = $costModel == 1 ? 'CPA' : $costModel == 3 ? 'CPC' : 'REVENUE_SHARE';
- if($payoutModel == 'REVENUE_SHARE'){
- $payout = json_encode(['share'=>(int)$percent]);
- }
- if($managerId == 74){
- $managerId = 1;
- }
- $sql = 'INSERT INTO "public"."campaigns" ("id","payoutModel", "status","description", "hideReferrer","name", "payout", "createdAt", "updatedAt", "managerId", "createdById", "updatedById")';
- $sql .= " VALUES " ;
- $sql .= " ( $id, '$payoutModel', 1, '$description', $hideReferer, '$name', '$payout', current_timestamp,current_timestamp, $managerId, $managerId, $managerId)" ;
- $result = pg_query($sql);
- $this->insertCustomCost($costs, $globalCampaigns, $payoutModel, $id , $currency );
- /*
- INSERT INTO "public"."campaigns" ("id", "status", "name", "schedule", "payout", "createdAt", "updatedAt", "deletedAt", "managerId", "createdById", "updatedById") VALUES (E'2', E'1', E'Flashlight Smart Link', NULL, E'{"EUR": 0, "USD": 0}', E'2017-05-25 18:21:52.999+00', E'2017-05-25 19:37:41.569+00', NULL, E'1', E'1', E'1');
- */
- }
- public function getCampaigns($cgids){
- echo PHP_EOL . 'GETTING ('.count($cgids).')CAMPAIGNS INFO:... ';
- $cgids = array_unique($cgids);
- $sql2 = "SELECT CA_ID as id, CA_CUT as scrub, CA_NAME as name, CA_DESC as description,UR_EMAIL email,CA_COST_PERCENT percent, CA_PREVIEW_URL as 'preview url', CA_COST_TYPE costModel , CA_COST_AMOUNT/100 as cost, CA_COST_CURRENCY as currency, CA_CUT scrub, CA_HIDE_REF as `hideReferer`,CA_CUT as scrub, CA_OFFER_RULES rules,CA_OWNERID managerId FROM CAMPAIGNS LEFT JOIN USERS ON UR_ID = CA_OWNERID ";
- /*
- if($this->envOrig == 'test')
- $cgids= [18786,18785];
- */
- $sql2 .= "WHERE CA_ID IN (" . implode(',',$cgids) . ")";
- $this->connect();
- $stmt2 = $this->pdo->query($sql2);
- $campaigns = $stmt2->fetchAll();
- foreach( $campaigns as $k => $v ){
- $this->campaigns[$v['id']] = $v;
- }
- echo PHP_EOL . 'GETTING COST DATA CUSTOM_PAYOUT + GLOBAL_CAMPAIGNS'. PHP_EOL ;
- $i = 1;
- foreach( $this->campaigns as $k => $v ){
- $sql = "SELECT latest.amount/100 quantity , latest.percent percentage , CCP_ADPUBID as publisher, CCP_ACCOUNTID managerId FROM CAMPAIGNS_CUSTOM_PAYOUT
- LEFT JOIN
- (
- SELECT CCP_ADPUBID pubid ,CCP_CAMPAIGNID cgid, CCP_AMOUNT as amount, CCP_PERCENT as percent
- FROM CAMPAIGNS_CUSTOM_PAYOUT
- WHERE CCP_TYPE = 2
- ORDER BY CCP_STARTD DESC
- ) latest
- ON latest.pubid = CCP_ADPUBID AND latest.cgid = CCP_CAMPAIGNID
- WHERE CCP_CAMPAIGNID = " . $v['id'] . " AND CCP_TYPE = 2 GROUP BY CCP_ADPUBID ORDER BY CCP_ID DESC;";
- $stmt = $this->pdo->query($sql);
- $cost = $stmt->fetchAll();
- $this->campaigns[$k]['costs'] = $cost;
- // echo 'Campaign Cost (' . $i++ . ' of '. count($this->campaigns) .')'. '\r';
- $sqlSub = "SELECT * FROM CUSTOM_PAYOUT WHERE CP_CAMPAIGNID = " . (int) $v['id'];
- $stmt = $this->pdo->query($sqlSub);
- $globalCampaigns = $stmt->fetchAll();
- $this->campaigns[$k]['globalCampaigns'] = $globalCampaigns ;
- $this->displayProgress($i++, count($this->campaigns));
- }
- return $this->campaigns;
- }
- public function displayProgress($current, $total) {
- echo "\r ($current of $total) Completed";
- }
- public function getOfferIdsLastDays(){
- $offerIds = [];
- foreach($this->days as $k => $d ){
- $sql = "SELECT DISTINCT CL_CAMPAIGNID as cgid, CL_OFFERID AS offerid, count(1) as `counter` FROM `CLICKS_$d` GROUP BY CL_CAMPAIGNID, CL_OFFERID";
- $stmt = $this->pdo->query($sql);
- $res = $stmt->fetchAll();
- foreach($res as $k => $v){
- if($v['counter'] > $this->minTraff)
- $offerIds[$v['cgid'] . '.' . $v['offerid']] = [
- 'offerid'=>$v['offerid'],
- 'campaignid'=>$v['cgid']
- ];
- }
- }
- return $offerIds;
- }
- public function getCompanies($users){
- echo PHP_EOL . 'GETTING COMPANIES...' ;
- $sql = "SELECT DISTINCT(SUBSTRING_INDEX(SUBSTRING_INDEX(UR_COMPANY_NAME, '_', -1), '@', 1)) company, SUBSTRING_INDEX(SUBSTRING_INDEX(UR_COMPANY_NAME, '@', -1), '_', -1) managing_company, UR_EMAIL as email FROM USERS";
- $stmt = $this->pdo->query($sql);
- $res = $stmt->fetchAll();
- $companies = [];
- $i = 0;
- foreach($res as $v){
- if(!isset($companies[trim($v['company'])]))
- $companies[trim($v['company'])] = $i++ ;
- if(!isset($companies[trim($v['managing_company'])]))
- $companies[trim($v['managing_company'])] = $i++;
- }
- $t_companies = [];
- $sql2 = "SELECT SUBSTRING_INDEX(UR_COMPANY_NAME ,'@',-1) as company FROM USERS WHERE UR_COMPANY_NAME LIKE '%@%' AND SUBSTRING_INDEX(UR_COMPANY_NAME ,'@',-1) NOT LIKE '' GROUP BY SUBSTRING_INDEX(UR_COMPANY_NAME ,'@',-1);";
- $stmt2 = $this->pdo->query($sql2);
- $res2 = $stmt2->fetchAll();
- foreach ($companies as $k => $v){
- $email = null;
- $direct_partner = 0;
- foreach($res as $t => $z){
- if(trim($z['company']) == trim($k)){
- $email = $z['email'];
- }
- }
- foreach ($res2 as $l => $m)
- if(trim($m['company']) == trim($k))
- $direct_partner = 1;
- $currency = 'USD';
- $createdBy = 1;
- foreach ($users as $u){
- if(trim($u['email']) == $email){
- $currency = $u['currency'];
- $createdBy = $u['id'];
- }
- }
- $t_companies[] = [
- 'email'=>$email,
- 'name'=>$k,
- 'direct'=>$direct_partner,
- 'currency'=>$currency,
- 'createdBy'=>$createdBy
- ];
- }
- echo count($t_companies) . ' COMPANIES FOUND';
- return $t_companies;
- }
- public function insertCompanies($companies){
- echo PHP_EOL . 'STARTING COMPANY INSERTS...' .PHP_EOL;
- $count = 1;
- foreach($companies as $k => $v){
- echo "\r (".$count." of ".count($companies).") - Company: ". $v['name'] . "[XX] INSERTING ";
- $d = $v['direct'] == 1 ? 'true' : 'false';
- $sql = "INSERT INTO \"companies\" (\"email\",\"directPartner\",\"name\",\"currency\", \"createdAt\", \"updatedAt\", \"createdById\") VALUES ( '" . str_replace("'","''",$v['email']) . "', " . $d . ", '" . str_replace("'","''",$v['name']) . "', '".$v['currency']."' ,current_timestamp,current_timestamp, ".$v['createdBy'].") RETURNING \"id\"";
- $result = pg_query($sql);
- while ($row = pg_fetch_array($result)) $companies[$k]['id'] = $row['id'];
- echo "\r (".$count." of ".count($companies).") - Company: ". $v['name'] . "[".$companies[$k]['id']."] INSERTED ";
- $count++;
- }
- echo PHP_EOL . $count . ' INSERTED COMPANIES';
- return $companies;
- }
- public function insertUsers($users, $companies){
- echo PHP_EOL . 'USER INSERTS' . PHP_EOL;
- $i = 1;
- foreach($users as $user){
- echo "\r (".$i." of ".count($users).") - User ". $user['email'] ." [". $user['id'] ."] INSERTING ";
- //calculate the company ID from the company array.
- $companyId = 1;
- foreach($companies as $kk => $kv){
- if(trim(strtolower($kv['name'])) == trim(strtolower($user['company']))){
- $companyId = (int) $kv['id'];
- break;
- }
- }
- //who is the main manager of a MANAGER? (By default MAVERICK'S SUPER USER which is userid = 1)
- //David is Userid 2.
- $managerId = 1;
- if($user['role'] == 'MANAGER'){
- $managerId = 1;
- }else{
- foreach($users as $tk => $tv){
- if($tv['role'] == 'MANAGER'){
- if($tv['firstName'] == $user['manager']){
- $managerId = $tv['id'];
- }
- }else{
- break;
- }
- }
- }
- $user['is_advertiser'] = $user['is_advertiser'] == 1 ? 'true' : 'false';
- $user['is_publisher'] = $user['is_publisher'] == 1 ? 'true' : 'false';
- $sql = "INSERT INTO \"accounts\" (\"id\",\"email\", \"secondaryEmails\",\"firstName\", \"lastName\",\"languages\", \"phoneNumbers\", \"role\", \"advertiser\", \"publisher\", \"currency\", \"companyId\", \"managerId\", \"createdAt\", \"updatedAt\" )";
- $sql .= "VALUES(" . $user['id'] . ",'" . $user['email'] . "', '" . $this->toPgArray([$user['email_2']]) . "', '".str_replace("'","''",$user['firstname'])."', '".str_replace("'","''",$user['surname'])."', '" . $this->toPgArray([$user['language']]) . "', " ;
- $sql .= "'" . $this->toPgArray([$user['phone']]) . "', '".$user['role']."', " . $user['is_advertiser'] . ", ".$user['is_publisher'].", '".strtoupper($user['currency'])."', " . $companyId . " , 1 , CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)";
- $result = pg_query($sql);
- echo "\r (".$i." of ".count($users).") - User ". $user['email'] ." [". $user['id'] ."] INSERTED ";
- $i++;
- }
- return $result;
- }
- public function getUserRelations($managerid = false , $allUsers = [] ){
- $sqlP = "SELECT P2M_PUBLISHERID as userid FROM PUBLISHERS2MANAGER WHERE P2M_MANAGERID = $managerid";
- $sqlA = "SELECT A2M_ADVERTISERID as userid FROM ADVERTISERS2MANAGER WHERE A2M_MANAGERID = $managerid";
- $this->pdo = null;
- $this->connect();
- $stmt1 = $this->pdo->query($sqlP);
- $stmt2 = $this->pdo->query($sqlA);
- $relationsA = $stmt1->fetchAll();
- $relationsB = $stmt2->fetchAll();
- $relations = array_merge($relationsA,$relationsB) ;
- //some users (not managers have two ids because they were two different kind of users.)
- foreach($relations as $r=> $u){
- foreach($allUsers as $k => $v){
- if($v['id'] !== $v['oldids']){
- if($u['userid'] == $v['oldids']){
- //then the old id is also a user ID that needs to be inserted in the new user relations.So we add to relations the old userid.
- $relations[] = ['userid'=>$v['oldids']];
- }
- }
- }
- }
- $rel = [];
- foreach($relations as $k=> $v) $rel[] = $v['userid'];
- $rel = array_unique(array_filter($rel));
- return $rel;
- }
- public function insertUserRelations($managerId = false, $managedUserIds = []){
- if(!$managerId) return ;
- if(empty($managedUserIds)) return ;
- foreach($managedUserIds as $accountId){
- $sql = "INSERT INTO \"additionalManagers\" (\"accountId\",\"managerId\",\"createdAt\",\"updatedAt\",\"type\") ";
- $sql .= "VALUES (".$accountId.",$managerId, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'view')";
- $result = @pg_query($sql);
- }
- }
- public function getUsers(){
- echo PHP_EOL . 'GETTING USERS...' ;
- $sql = "SELECT
- u.id,
- u.oldids oldids,
- SUBSTRING_INDEX(SUBSTRING_INDEX(u.name, '_', -1), '@', 1) AS company,
- u.currency AS currency,
- u.email AS email,
- u.email_2 email_2,
- if(u.firstname = '1', '',if(u.firstname = '?', '',if(u.firstname = '.', '',u.firstname))) AS firstname,
- if(u.surname = '1', '',if(u.surname = '?', '', if(u.surname = '.', '',u.surname ) )) AS surname,
- SUBSTRING_INDEX(u.name, '_', 1) AS manager, SUBSTRING_INDEX(SUBSTRING_INDEX(u.name, '@', -1), '_', -1) managing_company, u.is_publisher, u.is_advertiser, u.is_manager,u.role, u.`language`, IF(LENGTH(u.phone) < 7,'', IF(u.phone REGEXP '[0-9]',u.phone, '')) AS phone, IF(u.`status` = 1, 1, 0) `active`
- FROM (
- (SELECT UR_ID as id, MAX(UR_ID) oldids, 'USER' role, UR_PHONE AS phone, UR_LANGUAGE AS `language`, UR_STATUS AS `status`, UR_COMPANY_NAME name, UR_EMAIL email, UR_EMAIL2 email_2, UR_FIRSTNAME AS firstname, UR_LASTNAME AS surname, UR_CURRENCY currency, 1 is_publisher, 1 is_advertiser, 0 is_manager
- FROM USERS
- GROUP BY UR_COMPANY_NAME
- HAVING COUNT(1) > 1
- )
- UNION ALL
- (
- SELECT UR_ID as id,UR_ID oldids, 'USER' role, UR_PHONE AS phone, UR_LANGUAGE AS `language`, UR_STATUS AS `status`, UR_COMPANY_NAME name, UR_EMAIL email, UR_EMAIL2 email_2, UR_FIRSTNAME AS firstname, UR_LASTNAME AS surname, UR_CURRENCY currency, 1 is_publisher, 0 is_advertiser, 0 is_manager
- FROM USERS
- WHERE UR_ID NOT IN (
- SELECT UR_ID
- FROM USERS
- GROUP BY UR_COMPANY_NAME
- HAVING COUNT(1) > 1) AND UR_TYPE = 2
- )
- UNION ALL
- (
- SELECT UR_ID as id,UR_ID oldids, 'USER' role, UR_PHONE AS phone, UR_LANGUAGE AS `language`, UR_STATUS AS `status`, UR_COMPANY_NAME name, UR_EMAIL email, UR_EMAIL2 email_2, UR_FIRSTNAME AS firstname, UR_LASTNAME AS surname, UR_CURRENCY currency, 0 is_publisher, 1 is_advertiser, 0 is_manager
- FROM USERS
- WHERE UR_ID NOT IN (
- SELECT UR_ID
- FROM USERS
- GROUP BY UR_COMPANY_NAME
- HAVING COUNT(1) > 1) AND UR_TYPE = 3
- )
- UNION ALL
- (
- SELECT UR_ID as id,UR_ID oldids, 'MANAGER' role, UR_PHONE AS phone, UR_LANGUAGE AS `language`, UR_STATUS AS `status`, UR_COMPANY_NAME name, UR_EMAIL email, UR_EMAIL2 email_2,UR_FIRSTNAME AS firstname, UR_LASTNAME AS surname, UR_CURRENCY currency, 0 is_publisher, 0 is_advertiser,1 is_manager
- FROM USERS
- WHERE UR_ID NOT IN (
- SELECT UR_ID
- FROM USERS
- GROUP BY UR_COMPANY_NAME
- HAVING COUNT(1) > 1) AND UR_TYPE = 4)
- ) u ";
- if($this->limit) $sql .= 'LIMIT 100';
- $stmt = $this->pdo->query($sql);
- $res = $stmt->fetchAll();
- echo count($res) . ' USERS FOUND';
- return $res;
- }
- public function domains(){
- echo 'GETTING DOMAINS' . PHP_EOL;
- }
- }
- $export = new exports(10);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement