30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31 if (!empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.
"/core/class/ldap.class.php";
42 public $element =
'usergroup';
47 public $table_element =
'usergroup';
53 public $ismultientitymanaged = 1;
58 public $picto =
'group';
98 public $members = array();
102 private $_tab_loaded = array();
106 public $fields = array(
107 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
108 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>5),
109 'nom'=>array(
'type'=>
'varchar(180)',
'label'=>
'Name',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1,
'comment'=>
'Group name'),
110 'note' => array(
'type'=>
'html',
'label'=>
'Description',
'enabled'=>1,
'visible'=>1,
'position'=>20,
'notnull'=>-1,),
111 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>50,
'notnull'=>1,),
112 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'position'=>60,
'notnull'=>1,),
113 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPDF',
'enabled'=>1,
'visible'=>0,
'position'=>100),
119 public $fk_element =
'fk_usergroup';
124 protected $childtables = array();
129 protected $childtablesoncascade = array(
'usergroup_rights',
'usergroup_user');
140 $this->nb_rights = 0;
152 public function fetch($id =
'', $groupname =
'', $load_members =
true)
156 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
157 if (!empty($groupname))
159 $result = $this->
fetchCommon(0,
'',
' AND nom = \''.$this->
db->escape($groupname).
'\'');
164 $this->
name = $this->nom;
175 $this->error = $this->
db->lasterror();
194 $sql =
"SELECT g.rowid, ug.entity as usergroup_entity";
195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g,";
196 $sql .=
" ".MAIN_DB_PREFIX.
"usergroup_user as ug";
197 $sql .=
" WHERE ug.fk_usergroup = g.rowid";
198 $sql .=
" AND ug.fk_user = ".$userid;
199 if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
201 $sql .=
" AND g.entity IS NOT NULL";
203 $sql .=
" AND g.entity IN (0,".$conf->entity.
")";
205 $sql .=
" ORDER BY g.nom";
207 dol_syslog(get_class($this).
"::listGroupsForUser", LOG_DEBUG);
208 $result = $this->
db->query($sql);
211 while ($obj = $this->
db->fetch_object($result))
213 if (!array_key_exists($obj->rowid, $ret))
216 $newgroup->fetch($obj->rowid,
'', $load_members);
217 $ret[$obj->rowid] = $newgroup;
220 $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
223 $this->
db->free($result);
227 $this->error = $this->
db->lasterror();
245 $sql =
"SELECT u.rowid";
246 if (!empty($this->
id)) $sql .=
", ug.entity as usergroup_entity";
247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
248 if (!empty($this->
id)) $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
249 $sql .=
" WHERE 1 = 1";
250 if (!empty($this->
id)) $sql .=
" AND ug.fk_user = u.rowid";
251 if (!empty($this->
id)) $sql .=
" AND ug.fk_usergroup = ".$this->id;
252 if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
254 $sql .=
" AND u.entity IS NOT NULL";
256 $sql .=
" AND u.entity IN (0,".$conf->entity.
")";
258 if (!empty($excludefilter)) $sql .=
' AND ('.$excludefilter.
')';
260 dol_syslog(get_class($this).
"::listUsersForGroup", LOG_DEBUG);
264 while ($obj = $this->
db->fetch_object(
$resql))
266 if (!array_key_exists($obj->rowid, $ret))
270 $newuser =
new User($this->
db);
271 $newuser->fetch($obj->rowid);
272 $ret[$obj->rowid] = $newuser;
273 }
else $ret[$obj->rowid] = $obj->rowid;
275 if ($mode != 1 && !empty($obj->usergroup_entity))
277 $ret[$obj->rowid]->usergroup_entity[] = $obj->usergroup_entity;
285 $this->error = $this->
db->lasterror();
299 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
301 global $conf, $user, $langs;
303 $entity = (!empty($entity) ? $entity : $conf->entity);
305 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
313 $module = $perms = $subperms =
'';
317 $sql =
"SELECT module, perms, subperms";
318 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
319 $sql .=
" WHERE id = ".((int) $rid);
320 $sql .=
" AND entity = ".((int) $entity);
322 $result = $this->
db->query($sql);
324 $obj = $this->
db->fetch_object($result);
326 $module = $obj->module;
327 $perms = $obj->perms;
328 $subperms = $obj->subperms;
336 $whereforadd =
"id=".((int) $rid);
338 if ($subperms) $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
339 elseif ($perms) $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
342 if (!empty($allmodule))
344 if ($allmodule ==
'allmodules')
346 $whereforadd =
'allmodules';
348 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
349 if (!empty($allperms)) $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
355 if (!empty($whereforadd))
359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
360 $sql .=
" WHERE entity = ".$entity;
361 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
362 $sql .=
" AND ".$whereforadd;
365 $result = $this->
db->query($sql);
368 $num = $this->
db->num_rows($result);
372 $obj = $this->
db->fetch_object($result);
375 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"usergroup_rights WHERE fk_usergroup = $this->id AND fk_id=".$nid.
" AND entity = ".$entity;
376 if (!$this->
db->query($sql)) $error++;
377 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".$entity.
", ".$this->
id.
", ".$nid.
")";
378 if (!$this->
db->query($sql)) $error++;
389 $langs->load(
"other");
390 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
393 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
394 if ($result < 0) { $error++; }
400 $this->
db->rollback();
418 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0)
420 global $conf, $user, $langs;
425 $entity = (!empty($entity) ? $entity : $conf->entity);
431 $module = $perms = $subperms =
'';
435 $sql =
"SELECT module, perms, subperms";
436 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
437 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
438 $sql .=
" AND entity = ".$entity;
440 $result = $this->
db->query($sql);
442 $obj = $this->
db->fetch_object($result);
444 $module = $obj->module;
445 $perms = $obj->perms;
446 $subperms = $obj->subperms;
454 $wherefordel =
"id=".$this->db->escape($rid);
456 if ($subperms ==
'lire' || $subperms ==
'read') $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
457 if ($perms ==
'lire' || $perms ==
'read') $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
464 if (!empty($allmodule))
466 if ($allmodule ==
'allmodules')
468 $wherefordel =
'allmodules';
470 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
471 if (!empty($allperms)) $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
477 if (!empty($wherefordel))
481 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
482 $sql .=
" WHERE entity = ".$entity;
483 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
484 $sql .=
" AND ".$wherefordel;
487 $result = $this->
db->query($sql);
490 $num = $this->
db->num_rows($result);
496 $obj = $this->
db->fetch_object($result);
501 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"usergroup_rights";
502 $sql .=
" WHERE fk_usergroup = $this->id AND fk_id=".$nid;
503 $sql .=
" AND entity = ".$entity;
504 if (!$this->
db->query($sql)) $error++;
515 $langs->load(
"other");
516 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
519 $result = $this->
call_trigger(
'USERGROUP_MODIFY', $user);
520 if ($result < 0) { $error++; }
526 $this->
db->rollback();
545 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag])
551 if (!empty($this->all_permissions_are_loaded))
560 $sql =
"SELECT r.module, r.perms, r.subperms ";
561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as u, ".MAIN_DB_PREFIX.
"rights_def as r";
562 $sql .=
" WHERE r.id = u.fk_id";
563 $sql .=
" AND r.entity = ".$conf->entity;
564 $sql .=
" AND u.entity = ".$conf->entity;
565 $sql .=
" AND u.fk_usergroup = ".$this->id;
566 $sql .=
" AND r.perms IS NOT NULL";
567 if ($moduletag) $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
569 dol_syslog(get_class($this).
'::getrights', LOG_DEBUG);
577 $obj = $this->
db->fetch_object(
$resql);
580 $module = $obj->module;
581 $perms = $obj->perms;
582 $subperms = $obj->subperms;
586 if (!isset($this->rights)) $this->rights =
new stdClass();
587 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module =
new stdClass();
590 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms =
new stdClass();
591 if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++;
592 $this->rights->$module->$perms->$subperms = 1;
594 if (empty($this->rights->$module->$perms)) $this->nb_rights++;
595 $this->rights->$module->$perms = 1;
605 if ($moduletag ==
'')
609 $this->all_permissions_are_loaded = 1;
612 $this->_tab_loaded[$moduletag] = 1;
624 public function delete(
User $user)
640 if (!empty($this->
name)) {
641 $this->
nom = $this->name;
644 if (!isset($this->entity)) $this->entity = $conf->entity;
659 if (!empty($this->
name)) {
660 $this->
nom = $this->name;
690 $langs->load(
'users');
705 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
707 global $langs, $conf, $db, $hookmanager;
708 global $dolibarr_main_authentication, $dolibarr_main_demo;
711 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0;
713 $result =
''; $label =
'';
715 $label .=
'<div class="centpercent">';
716 $label .=
'<u>'.$langs->trans(
"Group").
'</u><br>';
717 $label .=
'<b>'.$langs->trans(
'Name').
':</b> '.$this->name;
718 $label .=
'<br><b>'.$langs->trans(
"Description").
':</b> '.$this->note;
721 $url = DOL_URL_ROOT.
'/user/group/card.php?id='.$this->id;
723 if ($option !=
'nolink')
726 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
727 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
728 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
732 if (empty($notooltip))
734 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
736 $langs->load(
"users");
737 $label = $langs->trans(
"ShowGroup");
738 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
740 $linkclose .=
' title="'.dol_escape_htmltag($label, 1, 1).
'"';
741 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
751 $linkstart =
'<a href="'.$url.
'"';
752 $linkstart .= $linkclose.
'>';
755 $result = $linkstart;
756 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
757 if ($withpicto != 2) $result .= $this->name;
761 $hookmanager->initHooks(array(
'groupdao'));
762 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
763 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
764 if ($reshook > 0) $result = $hookmanager->resPrint;
765 else $result .= $hookmanager->resPrint;
786 if ($mode == 0) $dn = $conf->global->LDAP_KEY_GROUPS.
"=".$info[$conf->global->LDAP_KEY_GROUPS].
",".$conf->global->LDAP_GROUP_DN;
787 if ($mode == 1) $dn = $conf->global->LDAP_GROUP_DN;
788 if ($mode == 2) $dn = $conf->global->LDAP_KEY_GROUPS.
"=".$info[$conf->global->LDAP_KEY_GROUPS];
808 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_GROUP_OBJECT_CLASS);
811 if ($this->
name && !empty($conf->global->LDAP_GROUP_FIELD_FULLNAME)) $info[$conf->global->LDAP_GROUP_FIELD_FULLNAME] = $this->name;
813 if ($this->
note && !empty($conf->global->LDAP_GROUP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->
note, 2);
814 if (!empty($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS))
816 $valueofldapfield = array();
817 foreach ($this->members as $key=>$val)
819 $muser =
new User($this->
db);
820 $muser->fetch($val->id);
821 $info2 = $muser->_load_ldap_info();
822 $valueofldapfield[] = $muser->_load_ldap_dn($info2);
824 $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield :
'');
826 if (!empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID])) {
827 $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id;
842 global $conf, $user, $langs;
846 $this->ref =
'SPECIMEN';
849 $this->
name =
'DOLIBARR GROUP SPECIMEN';
850 $this->
note =
'This is a note';
851 $this->datec = time();
852 $this->datem = time();
855 $this->members = array(
871 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
873 global $conf, $user, $langs;
875 $langs->load(
"user");
880 if (!empty($conf->global->USERGROUP_ADDON_PDF))
882 $modele = $conf->global->USERGROUP_ADDON_PDF;
888 $modelpath =
"core/modules/usergroup/doc/";
890 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
getLibStatut($mode=0)
Return label of status of user (active, inactive)
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
delrights($rid, $allmodule= '', $allperms= '', $entity=0)
Remove a permission from group.
getrights($moduletag= '')
Charge dans l'objet group, la liste des permissions auquels le groupe a droit.
initAsSpecimen()
Initialise an instance with random values.
listGroupsForUser($userid, $load_members=true)
Return array of groups objects for a particular user.
listUsersForGroup($excludefilter= '', $mode=0)
Return array of User objects for group this->id (or all if this->id not defined)
dol_now($mode= 'auto')
Return date for now.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the user card (with optionaly the picto) Use this->id,this->lastname, this->firstname.
Class to manage Dolibarr users.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=false)
Create object into database.
Class to manage user groups.
$conf db name
Only used if Module[ID]Name translation string is not found.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
$conf db
API class for accounts.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
if(!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'] s nom
__construct($db)
Constructor de la classe.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
create($notrigger=0)
Create group into database.
updateCommon(User $user, $notrigger=false)
Update object into database.
print $_SERVER["PHP_SELF"]
Edit parameters.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
update($notrigger=0)
Update group into database.
fetch($id= '', $groupname= '', $load_members=true)
Charge un objet group avec toutes ses caracteristiques (except ->members array)
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
addrights($rid, $allmodule= '', $allperms= '', $entity=0)
Add a permission to a group.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.