From 26af0cb262a850595f5060c8a3c9bd674704d2d2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 7 Apr 2008 15:32:24 +0000 Subject: [PATCH] Fix: Error in code generator --- dev/skeletons/build_class_from_table.php | 39 ++++++++++++++++++------ htdocs/adherents/fiche.php | 7 +++-- htdocs/core/events.class.php | 8 ++--- htdocs/user.class.php | 12 ++++---- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/dev/skeletons/build_class_from_table.php b/dev/skeletons/build_class_from_table.php index 3ea11ffc451..a51457400c0 100644 --- a/dev/skeletons/build_class_from_table.php +++ b/dev/skeletons/build_class_from_table.php @@ -163,7 +163,9 @@ foreach($property as $key => $prop) { if ($prop['field'] != 'rowid') { - $varprop.="\tvar \$".$prop['field'].";"; + $varprop.="\tvar \$".$prop['field']; + if ($prop['istime']) $varprop.="=''"; + $varprop.=";"; if ($prop['comment']) $varprop.="\t// ".$prop['extra']; $varprop.="\n"; } @@ -192,7 +194,11 @@ $i=0; foreach($property as $key => $prop) { $i++; - if ($prop['field'] != 'rowid' || $prop['extra'] != 'auto_increment') + $addfield=1; + if ($prop['field'] == 'tms') $addfield=0; // This is a field of type timestamp edited automatically + if ($prop['extra'] == 'auto_increment') $addfield=0; + + if ($addfield) { $varprop.="\t\t\$sql.= \"".$prop['field']; if ($i < sizeof($property)) $varprop.=","; @@ -210,16 +216,29 @@ $i=0; foreach($property as $key => $prop) { $i++; - if ($prop['field'] != 'rowid' || $prop['extra'] != 'auto_increment') + $addfield=1; + if ($prop['field'] == 'tms') $addfield=0; // This is a field of type timestamp edited automatically + if ($prop['extra'] == 'auto_increment') $addfield=0; + + if ($addfield) { $varprop.="\t\t\$sql.= \" "; - if ($prop['istime']) $varprop.='".$this->db->idate('; - else $varprop.="'\"."; - $varprop.="\$this->".$prop['field'].""; - if ($prop['istime']) $varprop.=')."'; - else $varprop.=".\"'"; - if ($i < sizeof($property)) $varprop.=","; - $varprop.="\";"; + if ($prop['istime']) + { + $varprop.='".(! isset($this->'.$prop['field'].') || $this->'.$prop['field'].'==\'\'?\'NULL\':$this->db->idate('; + $varprop.="\$this->".$prop['field'].""; + $varprop.='))."'; + if ($i < sizeof($property)) $varprop.=","; + $varprop.="\";"; + } + else + { + $varprop.='".(! isset($this->'.$prop['field'].')?\'NULL\':"\'".'; + $varprop.="\$this->".$prop['field'].""; + $varprop.='."\'")."'; + if ($i < sizeof($property)) $varprop.=","; + $varprop.='";'; + } $varprop.="\n"; } } diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index aab9b2bfa66..c2a5f321076 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -976,7 +976,8 @@ if ($rowid && $action != 'edit') */ print '
'; - if ($user->rights->adherent->creer || ($user->rights->adherent->self->creer && $adh->user_id == $user->id)) + // Modify + if ($user->rights->adherent->creer || ($user->rights->adherent->self->creer && $adh->user_id == $user->id)) { print "".$langs->trans("Modify").""; } @@ -1037,7 +1038,7 @@ if ($rowid && $action != 'edit') } } - // Barre d'actions + // Create user if (! $user->societe_id && ! $adh->user_id) { if ($user->rights->user->user->creer) diff --git a/htdocs/core/events.class.php b/htdocs/core/events.class.php index 0ba0d01e990..c43dd7db134 100644 --- a/htdocs/core/events.class.php +++ b/htdocs/core/events.class.php @@ -76,16 +76,13 @@ class Events // extends CommonObject global $conf, $langs; // Clean parameters - $this->id=trim($this->id); $this->fk_action=trim($this->fk_action); $this->label=trim($this->label); $this->description=trim($this->description); - - // Check parameters - // Put here code to add control on parameters values + if (! $user->id) { $this->error='ErrorBadValueForParameter'; return -1; } // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; @@ -96,9 +93,8 @@ class Events // extends CommonObject $sql.= "label,"; $sql.= "description"; - $sql.= ") VALUES ("; - + $sql.= " '".$this->type."',"; $sql.= " ".$this->db->idate($this->dateevent).","; $sql.= " '".$user->id."',"; diff --git a/htdocs/user.class.php b/htdocs/user.class.php index 19b4daf3ebc..8e59b0c5335 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -689,9 +689,9 @@ class User extends CommonObject * \param notrigger 1 ne declenche pas les triggers, 0 sinon * \return int <0 si KO, id compte cree si OK */ - function create($user='',$notrigger=0) + function create($user,$notrigger=0) { - global $conf; + global $conf,$langs; // Nettoyage parametres $this->login = trim($this->login); @@ -798,7 +798,7 @@ class User extends CommonObject */ function create_from_contact($contact) { - global $langs; + global $user,$langs; // Positionne parametres $this->nom = $contact->nom; @@ -812,7 +812,7 @@ class User extends CommonObject $this->db->begin(); // Cree et positionne $this->id - $result=$this->create(); + $result=$this->create($user); if ($result > 0) { @@ -853,7 +853,7 @@ class User extends CommonObject */ function create_from_member($member) { - global $conf, $user,$langs; + global $conf,$user,$langs; // Positionne parametres $this->nom = $member->nom; @@ -868,7 +868,7 @@ class User extends CommonObject $this->db->begin(); // Cree et positionne $this->id - $result=$this->create(); + $result=$this->create($user); if ($result > 0) { $result=$this->setPassword($user,$this->pass);