Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   ZenTracker (http://www.bvlist.com/forumdisplay.php?f=81)
-   -   help needed with zen fixes... (http://www.bvlist.com/showthread.php?t=10248)

Giorgatzelos 3rd February 2015 01:10

help needed with zen fixes...
 
Hi i am posting the code that deletes, checks if invalid or adds your ip @ zentracker...i noticed that there is no check if the current ip is in use already and gines a message that Your current ip is already in use and redirects to /membres/options as the other checks do, so when trying to add the ip and the system already has it added you get an integrity sql error...can anyone help me add this check?Thanks in advance...

Code:

/**
  * Suppression d'une IP
  */
  public function executeSupprimerip(sfWebRequest $r) {
    $q = Doctrine_Query::create()
      ->delete('Ip i')
      ->where("UNIX_TIMESTAMP(i.creation) = ?", $r->getUrlParameter("t"))
      ->andWhere("i.mid = ?", $this->getUser()->getAttribute("id"))
      ->execute();
    $this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Your IP address has been deleted."));
    $this->redirect("membres/options");
  }
 
 /**
  * Ajout d'une IP
  */
  public function executeAjouterip(sfWebRequest $r) {
    if (!filter_var($r->getPostParameter("adresseip"), FILTER_VALIDATE_IP)) {
      $this->getUser()->setFlash("error", $this->getContext()->getI18N()->__("Invalid IP address."));
      $this->redirect("membres/options");
    }
   
    // On ajoute la nouvelle IP
    $ip = new Ip();
    $ip->setIp(inet_pton($r->getPostParameter("adresseip")));
    $ip->setMid($this->getUser()->getAttribute("id"));
    $ip->setCreation(date("Y-m-d H:i:s"));
    $ip->setLastconnect(date("Y-m-d H:i:s"));
    $ip->save();
    $this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Your IP address has been added !"));
    $this->redirect("membres/options");
  }


LEGEND 3rd February 2015 18:03

I think it would be better to write own DQL (or raw SQL query if you know...) with part ON DUPLICATE KEY update... Something like http://stackoverflow.com/a/24384768 And you can save on SQL query :)

Bump: I understand the problem now... You can write small query for check if given IP and user exist in database, because there is unique key...

PHP Code:

 /**
  * Ajout d'une IP
  */
  
public function executeAjouterip(sfWebRequest $r) {
    if (!
filter_var($r->getPostParameter("adresseip"), FILTER_VALIDATE_IP)) {
      
$this->getUser()->setFlash("error"$this->getContext()->getI18N()->__("Invalid IP address."));
      
$this->redirect("membres/options");
    }
    

    
$exists Doctrine_Query::create()
        ->
select('mid')
        ->
from('Ip')
        ->
where("mid = ?"$this->getUser()->getAttribute("id"))
        ->
andWhere('ip = ?'inet_pton($r->getPostParameter("adresseip")))
        ->
execute();

    if (
$exists) {
        
$this->getUser()->setFlash("notice"$this->getContext()->getI18N()->__("Your IP exists in database!"));
        
$this->redirect("membres/options");
    }

    
// On ajoute la nouvelle IP
    
$ip = new Ip();
    
$ip->setIp(inet_pton($r->getPostParameter("adresseip")));
    
$ip->setMid($this->getUser()->getAttribute("id"));
    
$ip->setCreation(date("Y-m-d H:i:s"));
    
$ip->setLastconnect(date("Y-m-d H:i:s"));
    
$ip->save();
    
$this->getUser()->setFlash("notice"$this->getContext()->getI18N()->__("Your IP address has been added !"));
    
$this->redirect("membres/options");
  } 

Maybe you need little fix this small code, because i don't know the complete structure. But i hope it helps ;)

Giorgatzelos 3rd February 2015 18:53

3 Attachment(s)
thanx...i will try it and post the results

Bump: if the ip is not in use it still says ip already in use!
I added pictures....As you can see in second picture the message and in third picture no ip added!

How can i send you result of var_dump($exists); in both cases?

Bump: :muscle:


All times are GMT +2. The time now is 06:55.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.