Bravo List
Register
Go Back   > Bravo List > Source Code > Archived Trackers > ZenTracker
Reply
  #1  
Old 3rd February 2015, 01:10
Giorgatzelos's Avatar
Giorgatzelos Giorgatzelos is offline
Senior Member
 
Join Date: Nov 2009
Greece
Posts: 300
Default 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");
  }
Reply With Quote
  #2  
Old 3rd February 2015, 18:03
LEGEND's Avatar
LEGEND LEGEND is offline
Senior Member
 
Join Date: Jun 2008
Czech Republic
Posts: 31
Default
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 ;)

Last edited by LEGEND; 3rd February 2015 at 18:45.
Reply With Quote
The Following User Says Thank You to LEGEND For This Useful Post:
Giorgatzelos (3rd February 2015)
  #3  
Old 3rd February 2015, 18:53
Giorgatzelos's Avatar
Giorgatzelos Giorgatzelos is offline
Senior Member
 
Join Date: Nov 2009
Greece
Posts: 300
Default
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:
Attached Thumbnails
Screen Shot 2015-02-03 at 7.13.33 PM.png   Screen Shot 2015-02-03 at 7.13.39 PM.png   Screen Shot 2015-02-03 at 7.13.45 PM.png  

Last edited by Giorgatzelos; 3rd February 2015 at 19:18.
Reply With Quote
Reply

Tags
fixes , needed , zen

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 20:33. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.