<?php
class LoginProcess extends ActionPerformed
{
function initialize()
{
}
function run( & $action )
{
$user = $_POST['email'];
$passwd = sha1($_POST['passwd']);
$res = $this->env->db->query(sprintf("SELECT id_user FROM users INNER JOIN user_info USING(id_user) WHERE users.login = '%s' AND users.passwd = '%s' AND user_info.ativo = 1", $user, $passwd));
$row = $res->fetch();
if ($row['id_user'] <= 0) {
header("location: index/error,1");
exit(0);
}
else {
$res = $this->env->db->query(sprintf("SELECT COUNT(*) as tot
FROM bar A
INNER JOIN user_plan B USING ( id_user_plan )
WHERE B.id_user = %d"
,$row['id_user']));
$rowTot = $res->fetch();
$res = $this->env->db->query(sprintf("SELECT C.id_profile
FROM user_info A
JOIN user_profile B
USING ( id_user )
JOIN profile C
USING ( id_profile )
WHERE A.id_user = %d"
,$row['id_user']));
$rowUserProfile = $res->fetch(); //
$res = $this->env->db->query(sprintf("SELECT COUNT(*) FROM plan"));
$rowPlan = $res->fetch();
for($i=1;$i<=$rowPlan[0];$i++) {
//how many bar has in each plan
$res = $this->env->db->query(sprintf(" SELECT count( * ) as tot
FROM bar A
INNER JOIN user_plan B USING ( id_user_plan )
WHERE B.id_user = %d AND B.id_plan = %d "
,$row['id_user'],$i));
/*
printf(" SELECT count( * ) as tot
FROM bar A
INNER JOIN user_plan B USING ( id_user_plan )
WHERE B.id_user = %d AND B.id_plan = %d "
,$row['id_user'],$i);
*/
$row1 = $res->fetch();
//how many credits by plan
$res = $this->env->db->query(sprintf("SELECT sum( numb_location ) as soma
FROM user_plan
WHERE id_user =%d
AND id_plan =%d
GROUP BY (
id_plan
)",$row['id_user'],$i));
/*
$sql = sprintf("SELECT sum( numb_location ) as soma
FROM user_plan
WHERE id_user =%d
AND id_plan =%d
GROUP BY (
id_plan
)",$row['id_user'],$i);
echo $sql;
*/
$row2 = $res->fetch();
//echo 'val: ' . $row2['soma'] ."-" . $row1['tot'] . "<br>";
$availPlan = ($row2['soma']==null)?0:$row2['soma'];
// = $row2['soma']; //-$row1['tot'];
$this->env->session->set("availPlan$i",$availPlan);
}
//die();
if (!$this->env->session->has("email")) {
echo 'user = '.$user;
$this->env->session->set("email", $user);
$this->env->session->set("id_user", $row['id_user']);
$this->env->session->set("totActive", $rowTot['tot']);
$this->env->session->set("id_profile", $rowUserProfile['id_profile']);
//$this->env->redirect( $this->env->config->get( "LoginRedirect" ) );
//header("Location: ../Account/AccountEditLocation.class.php");
header("location: ../Account/editlocation/");
}
}
}
}
?>