Fix bug on Extrafield checkbox

Fix bug on ActionComm Update
[ task #900 ] Review code of ficheinter.class.php
This commit is contained in:
fhenry 2013-05-18 12:17:43 +02:00
parent 7a6a74f43e
commit fefb21a56e
10 changed files with 1844 additions and 1810 deletions

View File

@ -54,6 +54,7 @@ For users:
- New: [ task #741 ] Add intervention box. - New: [ task #741 ] Add intervention box.
- New: [ task #826 ] Optionnal increase stock when deleting an invoice already validated. - New: [ task #826 ] Optionnal increase stock when deleting an invoice already validated.
- New: [ task #823 ] Shipping_validate email notification. - New: [ task #823 ] Shipping_validate email notification.
- New: [ task #900 ] Review code of ficheinter.class.php
For translators: For translators:
- Update language files. - Update language files.

View File

@ -188,7 +188,7 @@ class ActionComm extends CommonObject
$sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").","; $sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").",";
$sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").","; $sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").",";
$sql.= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").","; $sql.= (isset($this->durationp) && $this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").",";
$sql.= (isset($this->type_id)?$this->type_id:"null"); $sql.= (isset($this->type_id)?$this->type_id:"null").",";
$sql.= (isset($this->code)?" '".$this->code."'":"null").","; $sql.= (isset($this->code)?" '".$this->code."'":"null").",";
$sql.= (isset($this->societe->id) && $this->societe->id > 0?" '".$this->societe->id."'":"null").","; $sql.= (isset($this->societe->id) && $this->societe->id > 0?" '".$this->societe->id."'":"null").",";
$sql.= (isset($this->fk_project) && $this->fk_project > 0?" '".$this->fk_project."'":"null").","; $sql.= (isset($this->fk_project) && $this->fk_project > 0?" '".$this->fk_project."'":"null").",";

View File

@ -1845,7 +1845,11 @@ else
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') {
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
} else {
$value=$object->array_options["options_".$key];
}
if ($extrafields->attribute_type[$key] == 'separate') if ($extrafields->attribute_type[$key] == 'separate')
{ {
print $extrafields->showSeparator($key); print $extrafields->showSeparator($key);

View File

@ -2834,7 +2834,7 @@ class Commande extends CommonOrder
} }
/** /**
* Update value of extrafields on the proposal * Update value of extrafields on order
* *
* @param User $user Object user that modify * @param User $user Object user that modify
* @return int <0 if ko, >0 if ok * @return int <0 if ko, >0 if ok

View File

@ -2145,7 +2145,11 @@ else
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') {
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
} else {
$value=$object->array_options["options_".$key];
}
if ($extrafields->attribute_type[$key] == 'separate') if ($extrafields->attribute_type[$key] == 'separate')
{ {
print $extrafields->showSeparator($key); print $extrafields->showSeparator($key);

View File

@ -3291,7 +3291,11 @@ else if ($id > 0 || ! empty($ref))
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
if ($action == 'edit_extras') {
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
} else {
$value=$object->array_options["options_".$key];
}
if ($extrafields->attribute_type[$key] == 'separate') if ($extrafields->attribute_type[$key] == 'separate')
{ {
print $extrafields->showSeparator($key); print $extrafields->showSeparator($key);

View File

@ -445,7 +445,7 @@ class ExtraFields
if(is_array($param) && count($param) > 0) if(is_array($param) && count($param) > 0)
{ {
$param = serialize($param); $param = $this->db->escape(serialize($param));
} }
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";

View File

@ -49,8 +49,8 @@
else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();} else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();}
else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();} else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();}
else if (type == 'sellist') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();} else if (type == 'sellist') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();}
else if (type == 'checkbox') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();} else if (type == 'checkbox') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();}
else if (type == 'radio') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();} else if (type == 'radio') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();}
else if (type == 'separate') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); required.val('').attr('disabled','disabled'); default_value.val('').attr('disabled','disabled'); jQuery("#value_choice").hide();} else if (type == 'separate') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); required.val('').attr('disabled','disabled'); default_value.val('').attr('disabled','disabled'); jQuery("#value_choice").hide();}
else size.val('').attr('disabled','disabled'); else size.val('').attr('disabled','disabled');
} }

View File

@ -82,16 +82,20 @@ class Fichinter extends CommonObject
/** /**
* Create an intervention into data base * Create an intervention into data base
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function create() function create($user, $notrigger=0)
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
dol_syslog(get_class($this)."::create ref=".$this->ref); dol_syslog(get_class($this)."::create ref=".$this->ref);
// Check parameters // Check parameters
if (! is_numeric($this->duree)) { $this->duree = 0; } if (! is_numeric($this->duree)) {
$this->duree = 0;
}
if ($this->socid <= 0) if ($this->socid <= 0)
{ {
$this->error='ErrorBadParameterForFunc'; $this->error='ErrorBadParameterForFunc';
@ -142,7 +146,7 @@ class Fichinter extends CommonObject
$sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->db->idate($now)."'";
$sql.= ", '".$this->ref."'"; $sql.= ", '".$this->ref."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", ".$this->author; $sql.= ", ".$user->id;
$sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null"); $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null");
$sql.= ", '".$this->modelpdf."'"; $sql.= ", '".$this->modelpdf."'";
$sql.= ", ".($this->fk_project ? $this->fk_project : 0); $sql.= ", ".($this->fk_project ? $this->fk_project : 0);
@ -173,16 +177,16 @@ class Fichinter extends CommonObject
if (! $ret) dol_print_error($this->db); if (! $ret) dol_print_error($this->db);
} }
if (! $notrigger)
{
// Appel des triggers // Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$tmpuser=new User($this->db); $result=$interface->run_triggers('FICHINTER_CREATE',$this,$user,$langs,$conf);
$tmpuser->fetch($this->author);
$result=$interface->run_triggers('FICHINTER_CREATE',$this,$tmpuser,$langs,$conf);
if ($result < 0) { if ($result < 0) {
$error++; $this->errors=$interface->errors; $error++; $this->errors=$interface->errors;
} }
// Fin appel triggers }
if (! $error) if (! $error)
{ {
@ -210,12 +214,18 @@ class Fichinter extends CommonObject
/** /**
* Update an intervention * Update an intervention
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function update() function update($user, $notrigger=0)
{ {
if (! is_numeric($this->duree)) { $this->duree = 0; } if (! is_numeric($this->duree)) {
if (! dol_strlen($this->fk_project)) { $this->fk_project = 0; } $this->duree = 0;
}
if (! dol_strlen($this->fk_project)) {
$this->fk_project = 0;
}
$this->db->begin(); $this->db->begin();
@ -229,6 +239,9 @@ class Fichinter extends CommonObject
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{
if (! $notrigger)
{ {
// Appel des triggers // Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@ -238,6 +251,7 @@ class Fichinter extends CommonObject
$error++; $this->errors=$interface->errors; $error++; $this->errors=$interface->errors;
} }
// Fin appel triggers // Fin appel triggers
}
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -396,7 +410,9 @@ class Fichinter extends CommonObject
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('FICHINTER_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers // Fin appel triggers
if (! $error) if (! $error)

View File

@ -134,7 +134,6 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$object->socid = $socid; $object->socid = $socid;
$object->duree = GETPOST('duree','int'); $object->duree = GETPOST('duree','int');
$object->fk_project = GETPOST('projectid','int'); $object->fk_project = GETPOST('projectid','int');
$object->author = $user->id;
$object->description = GETPOST('description'); $object->description = GETPOST('description');
$object->ref = $ref; $object->ref = $ref;
$object->modelpdf = GETPOST('model','alpha'); $object->modelpdf = GETPOST('model','alpha');
@ -155,9 +154,15 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
} }
// For compatibility // For compatibility
if ($element == 'order') { $element = $subelement = 'commande'; } if ($element == 'order') {
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } $element = $subelement = 'commande';
if ($element == 'contract') { $element = $subelement = 'contrat'; } }
if ($element == 'propal') {
$element = 'comm/propal'; $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
}
$object->origin = $origin; $object->origin = $origin;
$object->origin_id = $originid; $object->origin_id = $originid;
@ -270,7 +275,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
} }
else else
{ {
$result = $object->create(); $result = $object->create($user);
if ($result > 0) if ($result > 0)
{ {
$id=$result; // Force raffraichissement sur fiche venant d'etre cree $id=$result; // Force raffraichissement sur fiche venant d'etre cree
@ -300,7 +305,10 @@ else if ($action == 'update' && $user->rights->ficheinter->creer)
$object->description = GETPOST('description','alpha'); $object->description = GETPOST('description','alpha');
$object->ref = $ref; $object->ref = $ref;
$object->update(); $result=$object->update($user);
if ($result<0) {
setEventMessage($object->error,'errors');
}
} }
/* /*
@ -632,11 +640,7 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA
if ($object->fetch($id) > 0) if ($object->fetch($id) > 0)
{ {
// $objectref = dol_sanitizeFileName($object->ref);
// $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf';
// if (is_readable($file))
// {
$object->fetch_thirdparty(); $object->fetch_thirdparty();
if (GETPOST('sendto','alpha')) if (GETPOST('sendto','alpha'))
@ -722,7 +726,9 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($db); $interface=new Interfaces($db);
$result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf); $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers // Fin appel triggers
if ($error) if ($error)
@ -760,13 +766,6 @@ if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MA
$mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>'; $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
dol_syslog('Recipient email is empty'); dol_syslog('Recipient email is empty');
} }
/*}
else
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
dol_syslog('Failed to read file: '.$file);
}*/
} }
else else
{ {
@ -881,9 +880,15 @@ if ($action == 'create')
else else
{ {
// For compatibility // For compatibility
if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } if ($element == 'order' || $element == 'commande') {
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } $element = $subelement = 'commande';
if ($element == 'contract') { $element = $subelement = 'contrat'; } }
if ($element == 'propal') {
$element = 'comm/propal'; $subelement = 'propal';
}
if ($element == 'contract') {
$element = $subelement = 'contrat';
}
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');