Prepare perms on extrafields

This commit is contained in:
Laurent Destailleur 2015-03-09 21:40:24 +01:00
parent 84695845bb
commit 94acbeaa22
3 changed files with 28 additions and 12 deletions

View File

@ -48,11 +48,13 @@ class ExtraFields
var $attribute_required; var $attribute_required;
// Array to store parameters of attribute (used in select type) // Array to store parameters of attribute (used in select type)
var $attribute_param; var $attribute_param;
// Int to store position of attribute // Array to store position of attribute
var $attribute_pos; var $attribute_pos;
// Int to store if attribute is editable regardless of the document status // Array to store if attribute is editable regardless of the document status
var $attribute_alwayseditable; var $attribute_alwayseditable;
// Array to store permission to check
var $attribute_perms;
var $error; var $error;
var $errno; var $errno;
@ -90,6 +92,7 @@ class ExtraFields
$this->attribute_elementtype = array(); $this->attribute_elementtype = array();
$this->attribute_unique = array(); $this->attribute_unique = array();
$this->attribute_required = array(); $this->attribute_required = array();
$this->attribute_perms = array();
} }
/** /**
@ -106,9 +109,10 @@ class ExtraFields
* @param string $default_value Defaulted value * @param string $default_value Defaulted value
* @param array $param Params for field * @param array $param Params for field
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
* @return int <=0 if KO, >0 if OK * @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) function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param=0, $alwayseditable=0, $perms='')
{ {
if (empty($attrname)) return -1; if (empty($attrname)) return -1;
if (empty($label)) return -1; if (empty($label)) return -1;
@ -124,7 +128,7 @@ class ExtraFields
if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
{ {
// Add declaration of field into table // Add declaration of field into table
$result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable); $result2=$this->create_label($attrname,$label,$type,$pos,$size,$elementtype, $unique, $required, $param, $alwayseditable, $perms);
$err2=$this->errno; $err2=$this->errno;
if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
{ {
@ -225,9 +229,10 @@ class ExtraFields
* @param int $required Is field required or not * @param int $required Is field required or not
* @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array||string $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
* @return int <=0 if KO, >0 if OK * @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) private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='')
{ {
global $conf; global $conf;
@ -251,7 +256,7 @@ class ExtraFields
$params=''; $params='';
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(name, label, type, pos, size, entity, elementtype, fieldunique, fieldrequired, param, alwayseditable, perms)";
$sql.= " VALUES('".$attrname."',"; $sql.= " VALUES('".$attrname."',";
$sql.= " '".$this->db->escape($label)."',"; $sql.= " '".$this->db->escape($label)."',";
$sql.= " '".$type."',"; $sql.= " '".$type."',";
@ -263,6 +268,7 @@ class ExtraFields
$sql.= " '".$required."',"; $sql.= " '".$required."',";
$sql.= " '".$params."',"; $sql.= " '".$params."',";
$sql.= " '".$alwayseditable."'"; $sql.= " '".$alwayseditable."'";
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null");
$sql.=')'; $sql.=')';
dol_syslog(get_class($this)."::create_label", LOG_DEBUG); dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
@ -363,9 +369,10 @@ class ExtraFields
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
* @return int >0 if OK, <=0 if KO * @return int >0 if OK, <=0 if KO
*/ */
function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0) function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='')
{ {
if ($elementtype == 'thirdparty') $elementtype='societe'; if ($elementtype == 'thirdparty') $elementtype='societe';
@ -402,7 +409,7 @@ class ExtraFields
{ {
if ($label) if ($label)
{ {
$result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable); $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms);
} }
if ($result > 0) if ($result > 0)
{ {
@ -451,12 +458,13 @@ class ExtraFields
* @param int $pos Position of attribute * @param int $pos Position of attribute
* @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) ) * @param array $param Params for field (ex for select list : array('options' => array(value'=>'label of option')) )
* @param int $alwayseditable Is attribute always editable regardless of the document status * @param int $alwayseditable Is attribute always editable regardless of the document status
* @param string $perms Permission to check
* @return int <=0 if KO, >0 if OK * @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) private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='')
{ {
global $conf; global $conf;
dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required); dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms);
if ($elementtype == 'thirdparty') $elementtype='societe'; if ($elementtype == 'thirdparty') $elementtype='societe';
@ -485,6 +493,7 @@ class ExtraFields
$sql.= " elementtype,"; $sql.= " elementtype,";
$sql.= " fieldunique,"; $sql.= " fieldunique,";
$sql.= " fieldrequired,"; $sql.= " fieldrequired,";
$sql.= " perms,";
$sql.= " pos,"; $sql.= " pos,";
$sql.= " alwayseditable,"; $sql.= " alwayseditable,";
$sql.= " param"; $sql.= " param";
@ -497,6 +506,7 @@ class ExtraFields
$sql.= " '".$elementtype."',"; $sql.= " '".$elementtype."',";
$sql.= " '".$unique."',"; $sql.= " '".$unique."',";
$sql.= " '".$required."',"; $sql.= " '".$required."',";
$sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null");
$sql.= " '".$pos."',"; $sql.= " '".$pos."',";
$sql.= " '".$alwayseditable."',"; $sql.= " '".$alwayseditable."',";
$sql.= " '".$param."'"; $sql.= " '".$param."'";
@ -542,7 +552,7 @@ class ExtraFields
// For avoid conflicts with external modules // For avoid conflicts with external modules
if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; 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"; $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms";
$sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
$sql.= " WHERE entity IN (0,".$conf->entity.")"; $sql.= " WHERE entity IN (0,".$conf->entity.")";
if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";
@ -571,6 +581,7 @@ class ExtraFields
$this->attribute_param[$tab->name]=unserialize($tab->param); $this->attribute_param[$tab->name]=unserialize($tab->param);
$this->attribute_pos[$tab->name]=$tab->pos; $this->attribute_pos[$tab->name]=$tab->pos;
$this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
$this->attribute_perms[$tab->name]=$tab->perms;
} }
} }
} }
@ -603,6 +614,7 @@ class ExtraFields
$unique=$this->attribute_unique[$key]; $unique=$this->attribute_unique[$key];
$required=$this->attribute_required[$key]; $required=$this->attribute_required[$key];
$param=$this->attribute_param[$key]; $param=$this->attribute_param[$key];
$perms=$this->attribute_perms[$key];
if ($type == 'date') if ($type == 'date')
{ {
$showsize=10; $showsize=10;
@ -1040,6 +1052,7 @@ class ExtraFields
$unique=$this->attribute_unique[$key]; $unique=$this->attribute_unique[$key];
$required=$this->attribute_required[$key]; $required=$this->attribute_required[$key];
$params=$this->attribute_param[$key]; $params=$this->attribute_param[$key];
$perms=$this->attribute_perms[$key];
if ($type == 'date') if ($type == 'date')
{ {
$showsize=10; $showsize=10;

View File

@ -19,6 +19,8 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
ALTER TABLE llx_extrafields ADD COLUMN perms varchar(255) after fieldrequired;
UPDATE llx_projet_task_time SET task_datehour = task_date where task_datehour IS NULL; UPDATE llx_projet_task_time SET task_datehour = task_date where task_datehour IS NULL;
ALTER TABLE llx_projet_task_time ADD COLUMN task_date_withhour integer DEFAULT 0 after task_datehour; ALTER TABLE llx_projet_task_time ADD COLUMN task_date_withhour integer DEFAULT 0 after task_datehour;

View File

@ -29,6 +29,7 @@ create table llx_extrafields
size varchar(8) DEFAULT NULL, size varchar(8) DEFAULT NULL,
fieldunique integer DEFAULT 0, fieldunique integer DEFAULT 0,
fieldrequired integer DEFAULT 0, fieldrequired integer DEFAULT 0,
perms varchar(255),
pos integer DEFAULT 0, pos integer DEFAULT 0,
alwayseditable integer DEFAULT 0, alwayseditable integer DEFAULT 0,
param text param text