NEW Extrafields support formulas to be computed using PHP expressions

This commit is contained in:
Laurent Destailleur 2017-05-24 22:48:44 +02:00
parent 3782bc4458
commit e5fe629a0e
16 changed files with 335 additions and 171 deletions

View File

@ -597,7 +597,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
@ -664,7 +664,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}

View File

@ -14,6 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*
* $elementype must be defined.
*/
/**
@ -24,11 +26,14 @@
$maxsizestring=255;
$maxsizeint=10;
$extrasize=GETPOST('size');
if (GETPOST('type')=='double' && strpos($extrasize,',')===false) $extrasize='24,8';
if (GETPOST('type')=='date') $extrasize='';
if (GETPOST('type')=='datetime') $extrasize='';
if (GETPOST('type')=='select') $extrasize='';
$extrasize=GETPOST('size','int');
$type=GETPOST('type','alpha');
$param=GETPOST('param','alpha');;
if ($type=='double' && strpos($extrasize,',')===false) $extrasize='24,8';
if ($type=='date') $extrasize='';
if ($type=='datetime') $extrasize='';
if ($type=='select') $extrasize='';
// Add attribute
@ -37,73 +42,73 @@ if ($action == 'add')
if ($_POST["button"] != $langs->trans("Cancel"))
{
// Check values
if (! GETPOST('type'))
if (! $type)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"));
$action = 'create';
}
if (GETPOST('type')=='varchar' && $extrasize <= 0)
if ($type=='varchar' && $extrasize <= 0)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size"));
$action = 'edit';
}
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
if ($type=='varchar' && $extrasize > $maxsizestring)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring);
$action = 'create';
}
if (GETPOST('type')=='int' && $extrasize > $maxsizeint)
if ($type=='int' && $extrasize > $maxsizeint)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint);
$action = 'create';
}
if (GETPOST('type')=='select' && !GETPOST('param'))
if ($type=='select' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForSelectType");
$action = 'create';
}
if (GETPOST('type')=='sellist' && !GETPOST('param'))
if ($type=='sellist' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForSelectListType");
$action = 'create';
}
if (GETPOST('type')=='checkbox' && !GETPOST('param'))
if ($type=='checkbox' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForCheckBoxType");
$action = 'create';
}
if (GETPOST('type')=='link' && !GETPOST('param'))
if ($type=='link' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForLinkType");
$action = 'create';
}
if (GETPOST('type')=='radio' && !GETPOST('param'))
if ($type=='radio' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForRadioType");
$action = 'create';
}
if (((GETPOST('type')=='radio') || (GETPOST('type')=='checkbox')) && GETPOST('param'))
if ((($type=='radio') || ($type=='checkbox')) && $param)
{
// Construct array for parameter (value of select list)
$parameters = GETPOST('param');
$parameters = $param;
$parameters_array = explode("\r\n",$parameters);
foreach($parameters_array as $param_ligne)
{
@ -134,11 +139,11 @@ if ($action == 'add')
if (isset($_POST["attrname"]) && preg_match("/^[a-z0-9-_]+$/",$_POST['attrname']) && !is_numeric($_POST["attrname"]))
{
// Construct array for parameter (value of select list)
$default_value = GETPOST('default_value');
$parameters = GETPOST('param');
$default_value = GETPOST('default_value','alpha');
$parameters = $param;
$parameters_array = explode("\r\n",$parameters);
//In sellist we have only one line and it can have come to do SQL expression
if (GETPOST('type')=='sellist') {
if ($type=='sellist') {
foreach($parameters_array as $param_ligne)
{
$params['options'] = array($parameters=>null);
@ -155,20 +160,21 @@ if ($action == 'add')
}
$result=$extrafields->addExtraField(
GETPOST('attrname'),
GETPOST('label'),
GETPOST('type'),
GETPOST('pos'),
GETPOST('attrname', 'alpha'),
GETPOST('label', 'alpha'),
$type,
GETPOST('pos', 'alpha'),
$extrasize,
$elementtype,
(GETPOST('unique')?1:0),
(GETPOST('required')?1:0),
(GETPOST('unique', 'alpha')?1:0),
(GETPOST('required', 'alpha')?1:0),
$default_value,
$params,
(GETPOST('alwayseditable')?1:0),
(GETPOST('perms')?GETPOST('perms'):''),
(GETPOST('list')?1:0),
(GETPOST('ishidden')?1:0)
(GETPOST('alwayseditable', 'alpha')?1:0),
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
(GETPOST('list', 'alpha')?1:0),
(GETPOST('ishidden', 'alpha')?1:0),
GETPOST('computed_value','alpha')
);
if ($result > 0)
{
@ -205,66 +211,66 @@ if ($action == 'update')
if ($_POST["button"] != $langs->trans("Cancel"))
{
// Check values
if (! GETPOST('type'))
if (! $type)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"));
$action = 'edit';
}
if (GETPOST('type')=='varchar' && $extrasize <= 0)
if ($type=='varchar' && $extrasize <= 0)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Size"));
$action = 'edit';
}
if (GETPOST('type')=='varchar' && $extrasize > $maxsizestring)
if ($type=='varchar' && $extrasize > $maxsizestring)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorSizeTooLongForVarcharType",$maxsizestring);
$action = 'edit';
}
if (GETPOST('type')=='int' && $extrasize > $maxsizeint)
if ($type=='int' && $extrasize > $maxsizeint)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorSizeTooLongForIntType",$maxsizeint);
$action = 'edit';
}
if (GETPOST('type')=='select' && !GETPOST('param'))
if ($type=='select' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForSelectType");
$action = 'edit';
}
if (GETPOST('type')=='sellist' && !GETPOST('param'))
if ($type=='sellist' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForSelectListType");
$action = 'edit';
}
if (GETPOST('type')=='checkbox' && !GETPOST('param'))
if ($type=='checkbox' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForCheckBoxType");
$action = 'edit';
}
if (GETPOST('type')=='radio' && !GETPOST('param'))
if ($type=='radio' && !$param)
{
$error++;
$langs->load("errors");
$mesg[]=$langs->trans("ErrorNoValueForRadioType");
$action = 'edit';
}
if (((GETPOST('type')=='radio') || (GETPOST('type')=='checkbox')) && GETPOST('param'))
if ((($type=='radio') || ($type=='checkbox')) && $param)
{
// Construct array for parameter (value of select list)
$parameters = GETPOST('param');
$parameters = $param;
$parameters_array = explode("\r\n",$parameters);
foreach($parameters_array as $param_ligne)
{
@ -295,10 +301,10 @@ if ($action == 'update')
{
$pos = GETPOST('pos','int');
// Construct array for parameter (value of select list)
$parameters = GETPOST('param');
$parameters = $param;
$parameters_array = explode("\r\n",$parameters);
//In sellist we have only one line and it can have come to do SQL expression
if (GETPOST('type')=='sellist') {
if ($type=='sellist') {
foreach($parameters_array as $param_ligne)
{
$params['options'] = array($parameters=>null);
@ -315,19 +321,21 @@ if ($action == 'update')
}
$result=$extrafields->update(
GETPOST('attrname'),
GETPOST('label'),
GETPOST('type'),
GETPOST('attrname', 'alpha'),
GETPOST('label', 'alpha'),
$type,
$extrasize,
$elementtype,
(GETPOST('unique')?1:0),
(GETPOST('required')?1:0),
(GETPOST('unique', 'alpha')?1:0),
(GETPOST('required', 'alpha')?1:0),
$pos,
$params,
(GETPOST('alwayseditable')?1:0),
(GETPOST('perms')?GETPOST('perms'):''),
(GETPOST('list')?1:0),
(GETPOST('ishidden')?1:0)
(GETPOST('alwayseditable', 'alpha')?1:0),
(GETPOST('perms', 'alpha')?GETPOST('perms', 'alpha'):''),
(GETPOST('list', 'alpha')?1:0),
(GETPOST('ishidden', 'alpha')?1:0),
GETPOST('default_value','alpha'),
GETPOST('computed_value','alpha')
);
if ($result > 0)
{

View File

@ -36,14 +36,22 @@
class ExtraFields
{
var $db;
// Tableau contenant le nom des champs en clef et la definition de ces champs
// type of element (for what object is the extrafield)
var $attribute_elementtype;
// Array with type of the extra field
var $attribute_type;
// Tableau contenant le nom des champs en clef et le label de ces champs en value
// Array with label of extra field
var $attribute_label;
// Tableau contenant le nom des champs en clef et la taille/longueur max de ces champs en value
// Array with size of extra field
var $attribute_size;
// Tableau contenant le nom des choix en clef et la valeur de ces choix en value
// array with list of possible values for some types of extra fields
var $attribute_choice;
// Array to store compute formula for computed fields
var $attribute_computed;
// Array to store default value
var $attribute_default;
// Array to store if attribute is unique or not
var $attribute_unique;
// Array to store if attribute is required or not
@ -77,16 +85,17 @@ class ExtraFields
'phone'=>'ExtrafieldPhone',
'mail'=>'ExtrafieldMail',
'url'=>'ExtrafieldUrl',
'password' => 'ExtrafieldPassword',
'select' => 'ExtrafieldSelect',
'sellist' => 'ExtrafieldSelectList',
'radio' => 'ExtrafieldRadio',
'checkbox' => 'ExtrafieldCheckBox',
'chkbxlst' => 'ExtrafieldCheckBoxFromList',
'link' => 'ExtrafieldLink',
'password' => 'ExtrafieldPassword',
'separate' => 'ExtrafieldSeparator',
);
/**
* Constructor
*
@ -96,10 +105,12 @@ class ExtraFields
{
$this->db = $db;
$this->error = array();
$this->attribute_elementtype = array();
$this->attribute_type = array();
$this->attribute_label = array();
$this->attribute_size = array();
$this->attribute_elementtype = array();
$this->attribute_computed = array();
$this->attribute_default = array();
$this->attribute_unique = array();
$this->attribute_required = array();
$this->attribute_perms = array();
@ -118,15 +129,16 @@ class ExtraFields
* @param string $elementtype Element type ('member', 'product', 'thirdparty', ...)
* @param int $unique Is field unique or not
* @param int $required Is field required or not
* @param string $default_value Defaulted value (Example: '', '0', 'null', 'avalue')
* @param string $default_value Defaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue')
* @param array $param Params for field
* @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
* @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
* @param string $computed Computed value
* @return int <=0 if KO, >0 if OK
*/
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0, $perms='', $list=0, $ishidden=0)
function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0, $perms='', $list=0, $ishidden=0, $computed='')
{
if (empty($attrname)) return -1;
if (empty($label)) return -1;
@ -137,13 +149,13 @@ class ExtraFields
// Create field into database except for separator type which is not stored in database
if ($type != 'separate')
{
$result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list);
$result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $copmputed);
}
$err1=$this->errno;
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{
// Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden);
$result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $ishidden, $default, $computed);
$err2=$this->errno;
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
{
@ -169,13 +181,14 @@ class ExtraFields
* @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...)
* @param int $unique Is field unique or not
* @param int $required Is field required or not
* @param string $default_value Default value for field
* @param string $default_value Default value for field (in database)
* @param array $param Params for field (ex for select list : array('options'=>array('value'=>'label of option'))
* @param string $perms Permission
* @param int $list Into list view by default
* @param string $computed Computed value
* @return int <=0 if KO, >0 if OK
*/
private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list=0)
private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list=0, $computed='')
{
if ($elementtype == 'thirdparty') $elementtype='societe';
if ($elementtype == 'contact') $elementtype='socpeople';
@ -258,9 +271,11 @@ class ExtraFields
* @param string $perms Permission to check
* @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @return int <=0 if KO, >0 if OK
*/
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list=0, $ishidden=0)
private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list=0, $ishidden=0, $default='', $computed='')
{
global $conf;
@ -286,7 +301,7 @@ class ExtraFields
$params='';
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable, perms, list, ishidden)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable, perms, list, ishidden, fielddefault, fieldcomputed)";
$sql.= " VALUES('".$attrname."',";
$sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$type."',";
@ -299,8 +314,10 @@ class ExtraFields
$sql.= " '".$params."',";
$sql.= " '".$alwayseditable."',";
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
$sql.= " ".$list;
$sql.= ", ".$ishidden;
$sql.= " ".$list.",";
$sql.= " ".$ishidden.",";
$sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null");
$sql.=')';
dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
@ -430,9 +447,11 @@ class ExtraFields
* @param string $perms Permission to check
* @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @return int >0 if OK, <=0 if KO
*/
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='',$ishidden=0)
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='',$ishidden=0,$default='',$computed='')
{
if ($elementtype == 'thirdparty') $elementtype='societe';
if ($elementtype == 'contact') $elementtype='socpeople';
@ -479,7 +498,7 @@ class ExtraFields
{
if ($label)
{
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden);
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$ishidden,$default,$computed);
}
if ($result > 0)
{
@ -531,12 +550,14 @@ class ExtraFields
* @param string $perms Permission to check
* @param int $list Into list view by default
* @param int $ishidden Is hidden extrafield (warning, do not rely on this. If your module need a hidden data, it must use its own table)
* @param string $default Default value (in database. use the default_value feature for default value on screen).
* @param string $computed Computed value
* @return int <=0 if KO, >0 if OK
*/
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list=0,$ishidden=0)
private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list=0,$ishidden=0,$default='',$computed='')
{
global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden);
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$ishidden.", ".$default.", ".$computed);
// Clean parameters
if ($elementtype == 'thirdparty') $elementtype='societe';
@ -557,7 +578,7 @@ class ExtraFields
$sql_del.= " WHERE name = '".$attrname."'";
$sql_del.= " AND entity = ".$conf->entity;
$sql_del.= " AND elementtype = '".$elementtype."'";
dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
$resql1=$this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(";
@ -573,8 +594,10 @@ class ExtraFields
$sql.= " pos,";
$sql.= " alwayseditable,";
$sql.= " param,";
$sql.= " list";
$sql.= ", ishidden";
$sql.= " list,";
$sql.= " ishidden,";
$sql.= " fielddefault,";
$sql.= " fieldcomputed";
$sql.= ") VALUES (";
$sql.= "'".$attrname."',";
$sql.= " ".$conf->entity.",";
@ -588,10 +611,12 @@ class ExtraFields
$sql.= " '".$pos."',";
$sql.= " '".$alwayseditable."',";
$sql.= " '".$param."',";
$sql.= " ".$list;
$sql.= ", ".$ishidden;
$sql.= " ".$list.", ";
$sql.= " ".$ishidden.", ";
$sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
$sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null");
$sql.= ")";
dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
$resql2=$this->db->query($sql);
if ($resql1 && $resql2)
@ -635,7 +660,7 @@ class ExtraFields
// For avoid conflicts with external modules
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label;
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list,ishidden";
$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list,ishidden,fielddefault,fieldcomputed";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
@ -658,6 +683,8 @@ class ExtraFields
$this->attribute_label[$tab->name]=$tab->label;
$this->attribute_size[$tab->name]=$tab->size;
$this->attribute_elementtype[$tab->name]=$tab->elementtype;
$this->attribute_default[$tab->name]=$tab->fielddefault;
$this->attribute_computed[$tab->name]=$tab->fieldcomputed;
$this->attribute_unique[$tab->name]=$tab->fieldunique;
$this->attribute_required[$tab->name]=$tab->fieldrequired;
$this->attribute_param[$tab->name]=($tab->param ? unserialize($tab->param) : '');
@ -699,6 +726,8 @@ class ExtraFields
$type =$this->attribute_type[$key];
$size =$this->attribute_size[$key];
$elementtype=$this->attribute_elementtype[$key];
$default=$this->attribute_default[$key];
$computed=$this->attribute_computed[$key];
$unique=$this->attribute_unique[$key];
$required=$this->attribute_required[$key];
$param=$this->attribute_param[$key];
@ -706,6 +735,8 @@ class ExtraFields
$list=$this->attribute_list[$key];
$hidden=$this->attribute_hidden[$key];
if ($computed) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
if (empty($showsize))
{
if ($type == 'date')
@ -1218,10 +1249,12 @@ class ExtraFields
{
global $conf,$langs;
$elementtype=$this->attribute_elementtype[$key];
$label=$this->attribute_label[$key];
$type=$this->attribute_type[$key];
$size=$this->attribute_size[$key];
$elementtype=$this->attribute_elementtype[$key];
$default=$this->attribute_default[$key];
$computed=$this->attribute_computed[$key];
$unique=$this->attribute_unique[$key];
$required=$this->attribute_required[$key];
$params=$this->attribute_param[$key];
@ -1229,6 +1262,14 @@ class ExtraFields
$list=$this->attribute_list[$key];
$hidden=$this->attribute_hidden[$key]; // warning, do not rely on this. If your module need a hidden data, it must use its own table.
// If field is a computed field, value must become result of compute
if ($computed)
{
// Make the eval of compute string
//var_dump($computed);
$value = dol_eval($computed, 1, 0);
}
$showsize=0;
if ($type == 'date')
{

View File

@ -5604,20 +5604,32 @@ function verifCond($strRights)
*
* @param string $s String to evaluate
* @param int $returnvalue 0=No return (used to execute eval($a=something)). 1=Value of eval is returned (used to eval($something)).
* @param int $hideerrors 1=Hide errors
* @return mixed Nothing or return of eval
*/
function dol_eval($s,$returnvalue=0)
function dol_eval($s, $returnvalue=0, $hideerrors=1)
{
// Only global variables can be changed by eval function and returned to caller
global $langs, $user, $conf;
global $leftmenu;
global $db, $langs, $user, $conf;
global $mainmenu, $leftmenu;
global $rights;
global $object;
global $soc;
global $mysoc;
global $obj; // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object
global $soc; // For backward compatibility
//print $s."<br>\n";
if ($returnvalue) return @eval('return '.$s.';');
else @eval($s);
if ($returnvalue)
{
if ($hideerrors) return @eval('return '.$s.';');
else return eval('return '.$s.';');
}
else
{
if ($hideerrors) @eval($s);
else eval($s);
}
}
/**

View File

@ -18,10 +18,12 @@
*/
/**
* The following vars must be defined
* The following vars must be defined:
* $type2label
* $form
* $conf, $lang,
* The following vars may also be defined:
* $elementtype
*/
?>
@ -31,15 +33,16 @@
jQuery(document).ready(function() {
function init_typeoffields(type)
{
console.log("select new type "+type);
console.log("selected type is "+type);
var size = jQuery("#size");
var computed_value = jQuery("#computed_value");
var default_value = jQuery("#default_value");
var unique = jQuery("#unique");
var required = jQuery("#required");
var default_value = jQuery("#default_value");
var alwayseditable = jQuery("#alwayseditable");
var list = jQuery("#list");
<?php
if((GETPOST('type') != "select") && (GETPOST('type') != "sellist"))
if ((GETPOST('type') != "select") && (GETPOST('type') != "sellist"))
{
print 'jQuery("#value_choice").hide();';
}
@ -51,6 +54,28 @@
}
?>
// Case of computed field
console.log(type);
if (type == '' || type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
jQuery("tr.extra_computed_value").show();
} else {
computed_value.val(''); jQuery("tr.extra_computed_value").hide();
}
if (computed_value.val())
{
console.log("We enter a computed formula");
jQuery("#default_value").val('');
/* jQuery("#unique, #required, #alwayseditable, #ishidden, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").hide();
}
else
{
console.log("No computed formula");
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").show();
}
if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
else if (type == 'double') { size.val('24,8').removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
@ -65,7 +90,10 @@
else if (type == 'checkbox') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
else if (type == 'chkbxlst') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").show();jQuery("#helplink").hide();}
else if (type == 'link') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").show();}
else if (type == 'separate') { size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true); default_value.val('').prop('disabled', true); jQuery("#value_choice").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();}
else if (type == 'separate') {
size.val('').prop('disabled', true); unique.removeAttr('checked').prop('disabled', true); required.val('').prop('disabled', true);
jQuery("#value_choice").hide();jQuery("#helpselect").hide();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();jQuery("#helplink").hide();
}
else { // type = string
size.val('').prop('disabled', true);
unique.removeAttr('disabled');
@ -73,10 +101,12 @@
if (type == 'separate')
{
unique.removeAttr('checked').prop('disabled', true); required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.val('').prop('disabled', true);
required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.val('').prop('disabled', true);
jQuery('#size, #default_value').val('').prop('disabled', true);
}
else
{
default_value.removeAttr('disabled');
required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.val('').removeAttr('disabled');
}
}
@ -84,6 +114,11 @@
jQuery("#type").change(function() {
init_typeoffields($(this).val());
});
// If we enter a formula, we disable other fields
jQuery("#computed_value").keyup(function() {
init_typeoffields(jQuery('#type').val());
});
});
</script>
@ -103,9 +138,7 @@
<?php print $form->selectarray('type',$type2label,GETPOST('type')); ?>
</td></tr>
<!-- Size -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size')?GETPOST('size'):''); ?>"></td></tr>
<!-- Position -->
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
<tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td class="valeur"><input id="size" type="text" name="size" size="5" value="<?php echo (GETPOST('size')?GETPOST('size'):''); ?>"></td></tr>
<!-- Default Value (for select list / radio/ checkbox) -->
<tr id="value_choice">
<td>
@ -124,17 +157,21 @@
</table>
</td>
</tr>
<!-- Default Value -->
<tr><td><?php echo $langs->trans("DefaultValue"); ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
<!-- Position -->
<tr><td class="titlefield"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo GETPOST('pos'); ?>"></td></tr>
<!-- Computed Value -->
<tr class="extra_computed_value"><td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td><td class="valeur"><input id="computed_value" type="text" name="computed_value" class="quatrevingtpercent" value="<?php echo (GETPOST('"computed_value"')?GETPOST('"computed_value"'):''); ?>"></td></tr>
<!-- Default Value (at sql setup level) -->
<tr class="extra_default_value"><td><?php echo $langs->trans("DefaultValue").' ('.$langs->trans("Database").')'; ?></td><td class="valeur"><input id="default_value" type="text" name="default_value" size="5" value="<?php echo (GETPOST('"default_value"')?GETPOST('"default_value"'):''); ?>"></td></tr>
<!-- Unique -->
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo (GETPOST('unique')?' checked':''); ?>></td></tr>
<tr class="extra_unique"><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo (GETPOST('unique')?' checked':''); ?>></td></tr>
<!-- Required -->
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo (GETPOST('required')?' checked':''); ?>></td></tr>
<tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo (GETPOST('required')?' checked':''); ?>></td></tr>
<!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ((GETPOST('alwayseditable') || ! GETPOST('button'))?' checked':''); ?>></td></tr>
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ((GETPOST('alwayseditable') || ! GETPOST('button'))?' checked':''); ?>></td></tr>
<!-- Is visible or not -->
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
<tr><td><?php echo $langs->trans("Hidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden"<?php echo (GETPOST('ishidden') ?' checked' : ''); ?>></td></tr>
<tr class="extra_ishidden"><td><?php echo $langs->trans("Hidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden"<?php echo (GETPOST('ishidden') ?' checked' : ''); ?>></td></tr>
<?php } ?>
<?php if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { ?>
<!-- By default visible into list -->

View File

@ -15,6 +15,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* The following vars must be defined:
* $type2label
* $form
* $conf, $lang,
* The following vars may also be defined:
* $elementtype
*/
?>
<!-- BEGIN PHP TEMPLATE admin_extrafields_edit.tpl.php -->
@ -24,9 +34,10 @@
{
console.log("select new type "+type);
var size = jQuery("#size");
var computed_value = jQuery("#computed_value");
var default_value = jQuery("#default_value");
var unique = jQuery("#unique");
var required = jQuery("#required");
var default_value = jQuery("#default_value");
var alwayseditable = jQuery("#alwayseditable");
var list = jQuery("#list");
<?php
@ -42,6 +53,27 @@
}
?>
// Case of computed field
if (type == 'varchar' || type == 'int' || type == 'double' || type == 'price') {
jQuery("tr.extra_computed_value").show();
} else {
computed_value.val(''); jQuery("tr.extra_computed_value").hide();
}
if (computed_value.val())
{
console.log("We enter a computed formula");
jQuery("#default_value").val('');
/* jQuery("#unique, #required, #alwayseditable, #ishidden, #list").removeAttr('checked'); */
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', true);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").hide();
}
else
{
console.log("No computed formula");
jQuery("#default_value, #unique, #required, #alwayseditable, #ishidden, #list").attr('disabled', false);
jQuery("tr.extra_default_value, tr.extra_unique, tr.extra_required, tr.extra_alwayseditable, tr.extra_ishidden, tr.extra_list").show();
}
if (type == 'date') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide(); }
else if (type == 'datetime') { size.val('').prop('disabled', true); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
else if (type == 'double') { size.removeAttr('disabled'); unique.removeAttr('disabled'); jQuery("#value_choice").hide(); jQuery("#helpchkbxlst").hide();}
@ -65,9 +97,11 @@
if (type == 'separate')
{
required.removeAttr('checked').prop('disabled', true); alwayseditable.removeAttr('checked').prop('disabled', true); list.val('').prop('disabled', true);
jQuery('#size, #default_value').val('').prop('disabled', true);
}
else
{
default_value.removeAttr('disabled');
required.removeAttr('disabled'); alwayseditable.removeAttr('disabled'); list.val('').removeAttr('disabled');
}
}
@ -75,6 +109,11 @@
jQuery("#type").change(function() {
init_typeoffields($(this).val());
});
// If we enter a formula, we disable other fields
jQuery("#computed_value").keyup(function() {
init_typeoffields(jQuery('#type').val());
});
});
</script>
@ -92,6 +131,8 @@
<?php
$type=$extrafields->attribute_type[$attrname];
$size=$extrafields->attribute_size[$attrname];
$computed=$extrafields->attribute_computed[$attrname];
$default=$extrafields->attribute_default[$attrname];
$unique=$extrafields->attribute_unique[$attrname];
$required=$extrafields->attribute_required[$attrname];
$pos=$extrafields->attribute_pos[$attrname];
@ -156,9 +197,7 @@ else
?>
</td></tr>
<!-- Size -->
<tr><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
<!-- Position -->
<tr><td><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo $extrafields->attribute_pos[$attrname]; ?>"></td></tr>
<tr class="extra_size"><td class="fieldrequired"><?php echo $langs->trans("Size"); ?></td><td><input id="size" type="text" name="size" size="5" value="<?php echo $size; ?>"></td></tr>
<!-- Value (for select list / radio) -->
<tr id="value_choice">
<td>
@ -177,12 +216,18 @@ else
</table>
</td>
</tr>
<!-- Position -->
<tr><td class="titlefield"><?php echo $langs->trans("Position"); ?></td><td class="valeur"><input type="text" name="pos" size="5" value="<?php echo dol_escape_htmltag($extrafields->attribute_pos[$attrname]); ?>"></td></tr>
<!-- Computed value -->
<tr class="extra_computed_value"><td><?php echo $form->textwithpicto($langs->trans("ComputedFormula"), $langs->trans("ComputedFormulaDesc"), 1, 'help', '', 0, 2, 'tooltipcompute'); ?></td><td class="valeur"><input id="computed_value" class="quatrevingtpercent" type="text" name="computed_value" value="<?php echo dol_escape_htmltag($computed); ?>"></td></tr>
<!-- Default value -->
<!-- Edit of default into sql structure not yet supported -->
<!-- Unique -->
<tr><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo ($unique?' checked':''); ?>></td></tr>
<tr class="extra_unique"><td><?php echo $langs->trans("Unique"); ?></td><td class="valeur"><input id="unique" type="checkbox" name="unique"<?php echo ($unique?' checked':''); ?>></td></tr>
<!-- Required -->
<tr><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required?' checked':''); ?>></td></tr>
<tr class="extra_required"><td><?php echo $langs->trans("Required"); ?></td><td class="valeur"><input id="required" type="checkbox" name="required"<?php echo ($required?' checked':''); ?>></td></tr>
<!-- Always editable -->
<tr><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
<tr class="extra_alwayseditable"><td><?php echo $langs->trans("AlwaysEditable"); ?></td><td class="valeur"><input id="alwayseditable" type="checkbox" name="alwayseditable"<?php echo ($alwayseditable?' checked':''); ?>></td></tr>
<!-- Is visible or not -->
<?php if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) { ?>
<tr><td><?php echo $langs->trans("Hidden"); ?></td><td class="valeur"><input id="ishidden" type="checkbox" name="ishidden"<?php echo ($ishidden ?' checked':''); ?>></td></tr>

View File

@ -37,12 +37,15 @@ print '<div class="div-table-responsive">';
print '<table summary="listofattributes" class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("Position").'</td>';
print '<td align="left">'.$langs->trans("Position");
print '<span class="nowrap"><img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/1downarrow.png" alt="" title="A-Z" class="imgdown"></span>';
print '</td>';
print '<td>'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("AttributeCode").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td align="center">'.$langs->trans("Unique").'</td>';
print '<td>'.$langs->trans("ComputedFormula").'</td>';
print '<td align="center">'.$langs->trans("Required").'</td>';
print '<td align="center">'.$langs->trans("AlwaysEditable").'</td>';
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.$langs->trans("Hidden").'</td>';
@ -61,6 +64,7 @@ if (count($extrafields->attribute_type))
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
print '<td align="center">'.yn($extrafields->attribute_unique[$key])."</td>\n";
print '<td>'.dol_trunc($extrafields->attribute_computed[$key], 20)."</td>\n";
print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n";
print '<td align="center">'.yn($extrafields->attribute_alwayseditable[$key])."</td>\n";
if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '<td align="center">'.yn($extrafields->attribute_hidden[$key])."</td>\n"; // Add hidden option on not working feature. Why hide if user can't see it.

View File

@ -34,6 +34,10 @@
-- VMYSQL4.3 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN date_fin DATETIME NULL DEFAULT NULL;
-- VPGSQL8.2 ALTER TABLE llx_opensurvey_sondage ALTER COLUMN date_fin DROP NOT NULL;
ALTER TABLE llx_extrafields ADD COLUMN fieldcomputed text;
ALTER TABLE llx_extrafields ADD COLUMN fielddefault varchar(255);
ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE llx_opensurvey_sondage ADD COLUMN fk_user_creat integer NOT NULL DEFAULT 0;
@ -251,7 +255,6 @@ ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_tx d
ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_price double(24,8) DEFAULT NULL;
ALTER TABLE llx_product_fournisseur_price_log ADD COLUMN multicurrency_price_ttc double(24,8) DEFAULT NULL;
create table llx_payment_various
(
rowid integer AUTO_INCREMENT PRIMARY KEY,

View File

@ -21,12 +21,14 @@ create table llx_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
name varchar(64) NOT NULL, -- name of field into extrafields tables
entity integer DEFAULT 1 NOT NULL, -- multi company id
elementtype varchar(64) NOT NULL DEFAULT 'member', -- for which element this extra fields is for
entity integer DEFAULT 1 NOT NULL, -- multi company id
elementtype varchar(64) NOT NULL DEFAULT 'member', -- for which element this extra fields is for
tms timestamp, -- date of last update
label varchar(255) NOT NULL, -- label to show for attribute
type varchar(8),
size varchar(8) DEFAULT NULL,
fieldcomputed text,
fielddefault varchar(255),
fieldunique integer DEFAULT 0,
fieldrequired integer DEFAULT 0,
perms varchar(255), -- not used yet

View File

@ -375,19 +375,21 @@ Int=Integer
Float=Float
DateAndTime=Date and hour
Unique=Unique
Boolean=Boolean (Checkbox)
Boolean=Boolean (one checkbox)
ExtrafieldPhone = Phone
ExtrafieldPrice = Price
ExtrafieldMail = Email
ExtrafieldUrl = Url
ExtrafieldSelect = Select list
ExtrafieldSelectList = Select from table
ExtrafieldSeparator=Separator
ExtrafieldSeparator=Separator (not a field)
ExtrafieldPassword=Password
ExtrafieldCheckBox=Checkbox
ExtrafieldRadio=Radio button
ExtrafieldCheckBoxFromList= Checkbox from table
ExtrafieldRadio=Radio buttons (on choice only)
ExtrafieldCheckBox=Checkboxes
ExtrafieldCheckBoxFromList=Checkboxes from table
ExtrafieldLink=Link to an object
ComputedFormula=Computed field
ComputedFormulaDesc=You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: <strong>$db, $conf, $langs, $mysoc, $user, $object</strong>.<br><strong>WARNING</strong>: Only some properties of $object may be available. If you need a properties not loaded, just fetch yourself the object into your formula like in the second example.<br>Using a computed field means you can't enter yourself any value from interface. Also, if there is a syntax error, the formula may return nothing.<br><br>Example of formula:<br>$object->id < 5 ? round($object->id / 2, 2) : ($object->id + 2*$user->id) * (int) substr($mysoc->zip, 1, 2)<br><br>Example of formula to force load of object and its parent object:<br>(($reloadedobj = new Task($db)) && ($reloadedobj->fetch($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetch($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref : 'Parent project not found'<br><br>Other example to reload object<br>(($reloadedobj = new Societe($db)) && ($reloadedobj->fetch($obj->id ? $obj->id : ($obj->rowid ? $obj->rowid : $object->id)) > 0)) ? round($reloadedobj->capital / 5) : '-1'
ExtrafieldParamHelpselect=Parameters list have to be like key,value<br><br> for example : <br>1,value1<br>2,value2<br>3,value3<br>...<br><br>In order to have the list depending on another complementary attribute list :<br>1,value1|options_<i>parent_list_code</i>:parent_key<br>2,value2|options_<i>parent_list_code</i>:parent_key <br><br>In order to have the list depending on another list :<br>1,value1|<i>parent_list_code</i>:parent_key<br>2,value2|<i>parent_list_code</i>:parent_key
ExtrafieldParamHelpcheckbox=Parameters list have to be like key,value<br><br> for example : <br>1,value1<br>2,value2<br>3,value3<br>...
ExtrafieldParamHelpradio=Parameters list have to be like key,value<br><br> for example : <br>1,value1<br>2,value2<br>3,value3<br>...

View File

@ -773,6 +773,7 @@ BulkActions=Bulk actions
ClickToShowHelp=Click to show tooltip help
HR=HR
HRAndBank=HR and Bank
AutomaticallyCalculated=Automatically calculated
# Week day
Monday=Monday
Tuesday=Tuesday

View File

@ -126,13 +126,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
}
// Load object if id or ref is provided as parameter
$object=new Skeleton_Class($db);
if (($id > 0 || ! empty($ref)) && $action != 'add')
{
$result=$object->fetch($id,$ref);
if ($result < 0) dol_print_error($db);
}
@ -354,7 +348,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}
@ -383,7 +379,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
@ -427,6 +423,14 @@ print '</td>';
print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine=0;
foreach ($extrafields->attribute_computed as $key => $val)
{
if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object
}
$i=0;
$totalarray=array();
while ($i < min($num, $limit))

View File

@ -141,6 +141,8 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
}
}
$object = new Project($db);
/*
* Actions
@ -200,7 +202,6 @@ if (empty($reshook))
* View
*/
$projectstatic = new Project($db);
$socstatic = new Societe($db);
$form = new Form($db);
$formother = new FormOther($db);
@ -212,12 +213,12 @@ $title=$langs->trans("Projects");
// Get list of project id allowed to user (in a string list separated by coma)
$projectsListId='';
if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
if (! $user->rights->projet->all->lire) $projectsListId = $object->getProjectsAuthorizedForUser($user,0,1,$socid);
// Get id of types of contacts for projects (This list never contains a lot of elements)
$listofprojectcontacttype=array();
$sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
$sql.= " WHERE ctc.element = '" . $projectstatic->element . "'";
$sql.= " WHERE ctc.element = '" . $object->element . "'";
$sql.= " AND ctc.source = 'internal'";
$resql = $db->query($sql);
if ($resql)
@ -232,7 +233,7 @@ if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0';
$distinct='DISTINCT'; // We add distinct until we are added a protection to be sure a contact of a project and task is only once.
$sql = "SELECT ".$distinct." p.rowid as projectid, p.ref, p.title, p.fk_statut, p.fk_opp_status, p.public, p.fk_user_creat";
$sql = "SELECT ".$distinct." p.rowid as id, p.ref, p.title, p.fk_statut, p.fk_opp_status, p.public, p.fk_user_creat";
$sql.= ", p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
$sql.= ", s.nom as name, s.rowid as socid";
$sql.= ", cls.code as opp_status_code";
@ -360,8 +361,7 @@ $arrayofselected=is_array($toselect)?$toselect:array();
if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
{
$obj = $db->fetch_object($resql);
$id = $obj->projectid;
header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$id);
header("Location: ".DOL_URL_ROOT.'/projet/card.php?id='.$obj->id);
exit;
}
@ -566,7 +566,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
@ -599,7 +599,7 @@ if (! empty($arrayfields['p.fk_statut']['checked']))
{
print '<td class="liste_titre nowrap" align="right">';
$arrayofstatus = array();
foreach($projectstatic->statuts_short as $key => $val) $arrayofstatus[$key]=$langs->trans($val);
foreach($object->statuts_short as $key => $val) $arrayofstatus[$key]=$langs->trans($val);
$arrayofstatus['99']=$langs->trans("NotClosed").' ('.$langs->trans('Draft').'+'.$langs->trans('Opened').')';
print $form->selectarray('search_status', $arrayofstatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
print '</td>';
@ -632,7 +632,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}
@ -652,15 +654,15 @@ while ($i < min($num,$limit))
{
$obj = $db->fetch_object($resql);
$projectstatic->id = $obj->projectid;
$projectstatic->user_author_id = $obj->fk_user_creat;
$projectstatic->public = $obj->public;
$projectstatic->ref = $obj->ref;
$projectstatic->datee = $db->jdate($obj->date_end);
$projectstatic->statut = $obj->fk_statut;
$projectstatic->opp_status = $obj->fk_opp_status;
$userAccess = $projectstatic->restrictedProjectArea($user); // why this ?
$object->id = $obj->id;
$object->user_author_id = $obj->fk_user_creat;
$object->public = $obj->public;
$object->ref = $obj->ref;
$object->datee = $db->jdate($obj->date_end);
$object->statut = $obj->fk_statut;
$object->opp_status = $obj->fk_opp_status;
$userAccess = $object->restrictedProjectArea($user); // why this ?
if ($userAccess >= 0)
{
print '<tr class="oddeven">';
@ -669,8 +671,8 @@ while ($i < min($num,$limit))
if (! empty($arrayfields['p.ref']['checked']))
{
print '<td class="nowrap">';
print $projectstatic->getNomUrl(1);
if ($projectstatic->hasDelay()) print img_warning($langs->trans('Late'));
print $object->getNomUrl(1);
if ($object->hasDelay()) print img_warning($langs->trans('Late'));
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
@ -851,8 +853,7 @@ while ($i < min($num,$limit))
// Status
if (! empty($arrayfields['p.fk_statut']['checked']))
{
$projectstatic->statut = $obj->fk_statut;
print '<td align="right">'.$projectstatic->getLibStatut(5).'</td>';
print '<td align="right">'.$object->getLibStatut(5).'</td>';
if (! $i) $totalarray['nbfield']++;
}
// Action column
@ -860,8 +861,8 @@ while ($i < min($num,$limit))
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected=0;
if (in_array($obj->projectid, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->projectid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->projectid.'"'.($selected?' checked="checked"':'').'>';
if (in_array($obj->id, $arrayofselected)) $selected=1;
print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected?' checked="checked"':'').'>';
}
print '</td>';
if (! $i) $totalarray['nbfield']++;
@ -871,7 +872,6 @@ while ($i < min($num,$limit))
}
$i++;
}
// Show total line

View File

@ -131,6 +131,8 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
}
}
$object = new Task($db);
/*
* Actions
@ -190,11 +192,11 @@ if (empty($search_projectstatus) && $search_projectstatus == '') $search_project
* View
*/
$now = dol_now();
$form=new Form($db);
$formother=new FormOther($db);
$socstatic=new Societe($db);
$projectstatic = new Project($db);
$taskstatic = new Task($db);
$puser=new User($db);
$tuser=new User($db);
if ($search_project_user > 0) $puser->fetch($search_project_user);
@ -231,7 +233,7 @@ if (count($listofprojectcontacttype) == 0) $listofprojectcontacttype[0]='0';
// Get id of types of contacts for tasks (This list never contains a lot of elements)
$listoftaskcontacttype=array();
$sql = "SELECT ctc.rowid, ctc.code FROM ".MAIN_DB_PREFIX."c_type_contact as ctc";
$sql.= " WHERE ctc.element = '" . $taskstatic->element . "'";
$sql.= " WHERE ctc.element = '" . $object->element . "'";
$sql.= " AND ctc.source = 'internal'";
$resql = $db->query($sql);
if ($resql)
@ -549,7 +551,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
@ -606,7 +608,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}
@ -624,14 +628,21 @@ $plannedworkloadoutputformat='allhourmin';
$timespentoutputformat='allhourmin';
if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
$now = dol_now();
$i=0;
$totalarray=array();
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($resql);
$object->id = $obj->id;
$object->ref = $obj->ref;
$object->label = $obj->label;
$object->fk_statut = $obj->fk_statut;
$object->progress = $obj->progress;
$object->datee = $db->jdate($obj->date_end); // deprecated
$object->date_end = $db->jdate($obj->date_end);
$projectstatic->id = $obj->projectid;
$projectstatic->ref = $obj->projectref;
$projectstatic->title = $obj->projecttitle;
@ -639,14 +650,6 @@ while ($i < min($num,$limit))
$projectstatic->statut = $obj->projectstatus;
$projectstatic->datee = $db->jdate($obj->projectdatee);
$taskstatic->id = $obj->id;
$taskstatic->ref = $obj->ref;
$taskstatic->label = $obj->label;
$taskstatic->fk_statut = $obj->fk_statut;
$taskstatic->progress = $obj->progress;
$taskstatic->datee = $db->jdate($obj->date_end); // deprecated
$taskstatic->date_end = $db->jdate($obj->date_end);
$userAccess = $projectstatic->restrictedProjectArea($user); // why this ?
if ($userAccess >= 0)
{
@ -656,8 +659,8 @@ while ($i < min($num,$limit))
if (! empty($arrayfields['t.ref']['checked']))
{
print '<td>';
print $taskstatic->getNomUrl(1,'withproject');
if ($taskstatic->hasDelay()) print img_warning("Late");
print $object->getNomUrl(1,'withproject');
if ($object->hasDelay()) print img_warning("Late");
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
@ -665,7 +668,7 @@ while ($i < min($num,$limit))
if (! empty($arrayfields['t.label']['checked']))
{
print '<td>';
print $taskstatic->label;
print $object->label;
print '</td>';
if (! $i) $totalarray['nbfield']++;
}

View File

@ -389,8 +389,6 @@ class Societe extends CommonObject
$this->forme_juridique_code = 0;
$this->tva_assuj = 1;
$this->status = 1;
return 1;
}

View File

@ -831,7 +831,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
$align=$extrafields->getAlignFlag($key);
$typeofextrafield=$extrafields->attribute_type[$key];
print '<td class="liste_titre'.($align?' '.$align:'').'">';
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key]))
{
$crit=$val;
$tmpkey=preg_replace('/search_options_/','',$key);
@ -907,7 +907,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
if (! empty($arrayfields["ef.".$key]['checked']))
{
$align=$extrafields->getAlignFlag($key);
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
$sortonfield = "ef.".$key;
if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
}
}
}