forked from rafajefer/marketing-multinivel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atualizarPatente.php
42 lines (32 loc) · 1003 Bytes
/
atualizarPatente.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
session_start();
require_once 'config.php';
require_once 'funcoes.php';
// Busca id de todos os usuários
$sql = "SELECT id FROM usuarios";
$stmt = $pdo->query($sql);
$usuarios = array();
if($stmt->rowCount() > 0) {
$usuarios = $stmt->fetchAll();
foreach($usuarios as $chave => $usuario) {
$usuarios[$chave]['filhos'] = calcular_cadastros($usuario['id'], $limite);
}
}
$sql = "SELECT * FROM patentes ORDER BY min DESC";
$stmt = $pdo->query($sql);
$patentes = array();
if($stmt->rowCount() > 0) {
$patentes = $stmt->fetchAll();
}
foreach ($usuarios as $usuario) {
foreach ($patentes as $patente) {
if(intval($usuario['filhos']) >= intval($patente['min'])) {
$sql = "UPDATE usuarios SET patente = :patente WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":patente", $patente['id']);
$stmt->bindValue(":id", $usuario['id']);
$stmt->execute();
break;
}
}
}