Qual: Fix two awful code with hardcoded values. This remove also 2 TODO.

This commit is contained in:
Laurent Destailleur 2013-09-26 15:41:04 +02:00
parent 8e72727163
commit 470ccba80a
3 changed files with 6 additions and 6 deletions

View File

@ -4092,14 +4092,14 @@ function dol_osencode($str)
/** /**
* Return an id or code from a code or id. Store Code-Id in a cache. * Return an id or code from a code or id. Store also Code-Id into a cache for next use.
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param string $key Code to get Id * @param string $key Code to get Id
* @param string $tablename Table name without prefix * @param string $tablename Table name without prefix
* @param string $fieldkey Field for code * @param string $fieldkey Field for code
* @param string $fieldid Field for id * @param string $fieldid Field for id
* @return int Id of code * @return int <0 if KO, Id of code if OK
* @see getLabelFromKey * @see getLabelFromKey
*/ */
function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id') function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
@ -4118,7 +4118,7 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
$sql = "SELECT ".$fieldid." as id"; $sql = "SELECT ".$fieldid." as id";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename; $sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$key."'"; $sql.= " WHERE ".$fieldkey." = '".$key."'";
dol_syslog('dol_getIdFromCode sql='.$sql,LOG_DEBUG); dol_syslog('dol_getIdFromCode sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
@ -4130,7 +4130,7 @@ function dol_getIdFromCode($db,$key,$tablename,$fieldkey='code',$fieldid='id')
} }
else else
{ {
dol_syslog("dol_getIdFromCode error=".$db->lasterror(),LOG_ERR); dol_syslog("dol_getIdFromCode error=".$db->lasterror(), LOG_ERR);
return -1; return -1;
} }
} }

View File

@ -160,7 +160,7 @@ abstract class ActionsCardCommon
$this->object->effectif_id = $_POST["effectif_id"]; $this->object->effectif_id = $_POST["effectif_id"];
if (GETPOST("private") == 1) if (GETPOST("private") == 1)
{ {
$this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid $this->object->typent_id = dol_getIdFromCode($db,'TE_PRIVATE','c_typent');
} }
else else
{ {

View File

@ -158,7 +158,7 @@ if (empty($reshook))
$object->effectif_id = GETPOST('effectif_id'); $object->effectif_id = GETPOST('effectif_id');
if (GETPOST("private") == 1) if (GETPOST("private") == 1)
{ {
$object->typent_id = 8; // TODO predict another method if the field "special" change of rowid $object->typent_id = dol_getIdFromCode($db,'TE_PRIVATE','c_typent');
} }
else else
{ {