Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.DocIGroup.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Set WHAT user & mail parameters
9  *
10  * @author Anakeen 2003
11  * @version $Id: Method.DocIGroup.php,v 1.40 2008/09/04 09:48:26 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage USERCARD
15  */
16 /**
17  */
18 /**
19  * @begin-method-ignore
20  * this part will be deleted when construct document class until end-method-ignore
21  */
22 class _IGROUP extends _GROUP
23 {
24  /*
25  * @end-method-ignore
26  */
27  var $cviews = array(
28  "FUSERS:FUSERS_IGROUP"
29  );
30  var $eviews = array(
31  "USERCARD:CHOOSEGROUP"
32  );
33  //var $defaultview="FUSERS:FUSERS_IGROUP:V";
34  var $defaultedit = "FUSERS:FUSERS_EIGROUP:T";
35  var $exportLdap = array(
36  // posixGroup
37  "gidNumber" => "GRP_GIDNUMBER",
38  // "mail" => "GRP_MAIL", // not in schema but used in mailing client application
39  "description" => "GRP_DESC"
40  );
41  var $ldapobjectclass = "posixGroup";
42  function specRefresh()
43  {
44  // $err=$this->ComputeGroup();
45  $err = "";
46  $this->AddParamRefresh("US_WHATID", "GRP_MAIL,US_LOGIN");
47  if ($this->getValue("US_IDDOMAIN", 1) > 1) $this->AddParamRefresh("US_WHATID", "US_DOMAIN");
48  $this->AddParamRefresh("US_IDDOMAIN", "US_DOMAIN");
49  // refresh MEID itself
50  $this->SetValue("US_MEID", $this->id);
51  $iduser = $this->getValue("US_WHATID");
52  if ($iduser > 0) {
53  $user = $this->getWUser();
54  if (!$user) return sprintf(_("group #%d does not exist") , $iduser);
55  } else {
56  return _("group has not identificator");
57  }
58 
59  if ($this->getValue("grp_isrefreshed") == "0") $err.= _("this groups must be refreshed");
60  return $err;
61  }
62  /**
63  * test if the document can be set in LDAP
64  */
65  function canUpdateLdapCard()
66  {
67  return true;
68  }
69  /**
70  * get LDAP title for group
71  */
72  function getLDAPTitle()
73  {
74  return sprintf(_("%s group") , $this->title);
75  }
76  /**
77  * get LDAP array of members
78  * @return array
79  */
80  function getLDAPMember()
81  {
82  $t = $this->getTValue("GRP_IDUSER");
83  $tdn = array();
84  foreach ($t as $k => $v) {
85  $du = getTDoc($this->dbaccess, $v);
86  $tdnu = explode("\n", $du["ldapdn"]);
87  if (count($tdnu) > 0) {
88  $dnu = $tdnu[0];
89  if ($dnu) $tdn[] = $dnu;
90  }
91  }
92  if (count($tdn) == 0) $tdn = "cn=nobody,dc=users," . $this->racine;
93  return $tdn;
94  }
95  /**
96  * recompute only parent group
97  * call {@see ComputeGroup()}
98  *
99  * @return string error message, if no error empty string
100  */
101  function RefreshGroup()
102  {
103  if ($this->norefreshggroup) return;
104  include_once ("FDL/Lib.Usercard.php");
105  // $err=_GROUP::RefreshGroup();
106  $err.= $this->RefreshDocUser();
107  //$err.=$this->refreshMembers();
108  // refreshGroups(array($this->getValue("us_whatid")));
109  $err.= $this->insertGroups();
110  //$err.=$this->SetGroupMail(($this->GetValue("US_IDDOMAIN")>1));
111  $err.= $this->Modify();
112  //AddWarningMsg(sprintf("RefreshGroup %d %s",$this->id, $this->title));
113  if ($err == "") {
114  refreshGroups(array(
115  $this->getValue("us_whatid")
116  ) , true);
117  /*$this->setValue("grp_isrefreshed","1");
118  $this->modify(true,array("grp_isrefreshed"),true);*/
119  }
120  return $err;
121  }
122  /**
123  * Refresh folder parent containt
124  */
126  {
127  $tgid = $this->getTValue("GRP_IDPGROUP");
128  foreach ($tgid as $gid) {
129  $gdoc = new_Doc($this->dbaccess, $gid);
130  if ($gdoc->isAlive()) {
131  $gdoc->insertGroups();
132  }
133  }
134  }
135  function postModify()
136  {
137  $uid = $this->GetValue("US_WHATID");
138  $gname = $this->GetValue("GRP_NAME");
139  $login = $this->GetValue("US_LOGIN");
140  $iddomain = $this->GetValue("US_IDDOMAIN");
141 
142  $fid = $this->id;
143  $user = $this->getWUser();
144  if (!$user) {
145  $user = new User(""); // create new user
146  $this->wuser = & $user;
147  }
148  $err.= $user->SetGroups($fid, $gname, $login, $iddomain);
149  if ($err == "") {
150  $this->setValue("US_WHATID", $user->id);
151  $this->modify(false, array(
152  "us_whatid"
153  ));
154  if ($user) $err = $this->setGroups();
155  // get members
156  //$this->RefreshGroup(); // in postinsert
157  // $this->refreshParentGroup();
158  $wrg = $this->RefreshLdapCard();
159  if ($wrg) AddWarningMsg($wrg);
160  // add in default folder root groups : usefull for import
161  $tgid = $this->getTValue("GRP_IDPGROUP");
162  $fdoc = $this->getFamdoc();
163  $dfldid = $fdoc->dfldid;
164  if ($dfldid != "") {
165  $dfld = new_doc($this->dbaccess, $dfldid);
166  if ($dfld->isAlive()) {
167  if (count($tgid) == 0) $dfld->AddFile($this->initid);
168  else $dfld->delFile($this->initid);
169  }
170  }
171 
172  $err = $this->refreshMailMembersOnChange();
173  }
174 
175  if ($err == "") $err = "-"; // don't do modify after because it is must be set by USER::setGroups
176  return $err;
177  }
178  /**
179  * update LDAP menbers after imodification of containt
180  */
181  function specPostInsert()
182  {
183  return $this->RefreshLdapCard();
184  }
185  /**
186  * update groups table in USER database
187  * @return string error message
188  */
189  function postInsertDoc($docid, $multiple)
190  {
191  $err = "";
192  if ($multiple == false) {
193  $gid = $this->getValue("US_WHATID");
194  if ($gid > 0) {
195  $du = new_Doc($this->dbaccess, $docid);
196  $uid = $du->getValue("us_whatid");
197  if ($uid > 0) {
198  $g = new Group("", $uid);
199  $g->iduser = $uid;
200  $g->idgroup = $gid;
201  $err = $g->Add();
202  if ($err == "OK") $err = "";
203  if ($err == "") {
204  $du->RefreshDocUser(); // to refresh group of user attributes
205  $this->RefreshGroup();
206  }
207  }
208  }
209  }
210  return $err;
211  }
212  /**
213  * update groups table in USER database
214  * @return string error message
215  */
216  function postMInsertDoc($tdocid)
217  {
218 
219  $err = "";
220 
221  $gid = $this->getValue("US_WHATID");
222  if ($gid > 0) {
223 
224  $g = new Group("", $uid);
225  foreach ($tdocid as $k => $docid) {
226  $du = new_Doc($this->dbaccess, $docid);
227  $uid = $du->getValue("us_whatid");
228  if ($uid > 0) {
229  $g->iduser = $uid;
230  $g->idgroup = $gid;
231  $err = $g->Add();
232  if ($err == "") $du->RefreshDocUser();
233  }
234  }
235 
236  $this->RefreshGroup();
237  }
238  return $err;
239  }
240  /**
241  * update groups table in USER database before suppress
242  * @return string error message
243  */
245  {
246 
247  $err = "";
248  $gid = $this->getValue("US_WHATID");
249  if ($gid > 0) {
250  $du = new_Doc($this->dbaccess, $docid);
251  $uid = $du->getValue("us_whatid");
252  if ($uid > 0) {
253  $g = new Group("", $gid);
254  $g->iduser = $gid;
255  $err = $g->SuppressUser($uid);
256  if ($err == "") {
257  $du->RefreshDocUser();
258  $this->RefreshGroup();
259  }
260  }
261  }
262  return $err;
263  }
264  function PostDelete()
265  {
266 
267  $user = $this->getWUser();
268  if ($user) $user->Delete();
269  }
270  /**
271  * (re)insert members of the group in folder from USER databasee
272  *
273  * @return string error message, if no error empty string
274  */
275  function insertGroups()
276  {
277  $user = $this->getWUser();
278  $err = "";
279  // get members
280  $tu = $user->GetUsersGroupList($user->id);
281 
282  if (is_array($tu)) {
283  $this->Clear();
284  $tfid = array();
285  foreach ($tu as $k => $v) {
286  // if ($v["fid"]>0) $err.=$this->AddFile($v["fid"]);
287  if ($v["fid"] > 0) $tfid[] = $v["fid"];
288  }
289  $err = $this->QuickInsertMSDocId($tfid); // without postInsert
290  $this->specPostInsert();
291  }
292  return $err;
293  }
294  /**
295  * insert members in a group in folder
296  * it does not modify anakeen database (use only when anakeen database if updated)
297  * must be use after a group add in anakeen database (use only for optimization in ::setGroups
298  *
299  * @param int $docid user doc parameter
300  * @return string error message, if no error empty string
301  */
303  {
304  $err = $this->AddFile($docid, "latest", true); // without postInsert
305  $this->setValue("grp_isrefreshed", "0");
306  $this->modify(true, array(
307  "grp_isrefreshed"
308  ) , true);
309 
310  return $err;
311  }
312  /**
313  * suppress members of the group in folder
314  * it does not modify anakeen database (use only when anakeen database if updated)
315  * must be use after a group add in anakeen database (use only for optimization in ::setGroups
316  *
317  * @param int $docid user doc parameter
318  * @return string error message, if no error empty string
319  */
321  {
322  $err = $this->DelFile($docid, true); // without postInsert
323  $this->setValue("grp_isrefreshed", "0");
324  $this->modify(true, array(
325  "grp_isrefreshed"
326  ) , true);
327 
328  return $err;
329  }
330  /**
331  * recompute intranet values from USER database
332  */
333  function RefreshDocUser()
334  {
335  $err = "";
336  $wid = $this->getValue("us_whatid");
337  if ($wid > 0) {
338  $wuser = $this->getWUser(true);
339  if ($wuser->isAffected()) {
340  $this->SetValue("US_WHATID", $wuser->id);
341  $this->SetValue("GRP_NAME", $wuser->lastname);
342  // $this->SetValue("US_FNAME",$wuser->firstname);
343  $this->SetValue("US_LOGIN", $wuser->login);
344  $this->SetValue("US_IDDOMAIN", $wuser->iddomain);
345  include_once ("Class.Domain.php");
346  $dom = new Domain("", $wuser->iddomain);
347  $this->SetValue("US_DOMAIN", $dom->name);
348  if ($wuser->iddomain > 1) $this->SetValue("GRP_MAIL", getMailAddr($wid));
349 
350  $this->SetValue("US_MEID", $this->id);
351  // search group of the group
352  $g = new Group("", $wid);
353 
354  if (count($g->groups) > 0) {
355  foreach ($g->groups as $gid) {
356  $gt = new User("", $gid);
357  $tgid[$gid] = $gt->fid;
358  $tglogin[$gid] = $this->getTitle($gt->fid);
359  }
360  $this->SetValue("GRP_PGROUP", $tglogin);
361  $this->SetValue("GRP_IDPGROUP", $tgid);
362  } else {
363  $this->SetValue("GRP_PGROUP", " ");
364  $this->SetValue("GRP_IDPGROUP", " ");
365  }
366  $err = $this->modify(true, array(
367  "us_whatid",
368  "grp_name",
369  "us_login",
370  "us_iddomain",
371  "us_domain",
372  "us_meid",
373  "grp_pgroup",
374  "grp_idgroup"
375  ));
376  } else {
377  $err = sprintf(_("group %d does not exist") , $wid);
378  }
379  }
380  return $err;
381  }
382  /**
383  * refresh members of the group from USER database
384  */
385  function refreshMembers()
386  {
387  $norefresh = ($this->getValue("grp_hasmembers") == "no");
388  if ($norefrash) {
389  $this->DeleteValue("GRP_USER");
390  $this->DeleteValue("GRP_IDUSER");
391  }
392  $wid = $this->getValue("us_whatid");
393  if ($wid > 0) {
394  $u = $this->getWUser(true);
395 
396  $tu = $u->GetUsersGroupList($wid, $norefresh);
397  if (count($tu) > 0) {
398 
399  foreach ($tu as $uid => $tvu) {
400  if ($tvu["isgroup"] == "Y") {
401  $tgid[$uid] = $tvu["fid"];
402  // $tglogin[$uid]=$this->getTitle($tvu["fid"]);
403  $tglogin[$tvu["fid"]] = $tvu["lastname"];
404  } else {
405  $tuid[$uid] = $tvu["fid"];
406  // $tulogin[$uid]=$this->getTitle($tvu["fid"]);
407  $tulogin[$tvu["fid"]] = trim($tvu["lastname"] . " " . $tvu["firstname"]);
408  }
409  }
410  }
411  if (is_array($tulogin)) {
412  uasort($tulogin, "strcasecmp");
413  $this->SetValue("GRP_USER", $tulogin);
414  $this->SetValue("GRP_IDUSER", array_keys($tulogin));
415  } else {
416  $this->DeleteValue("GRP_USER");
417  $this->DeleteValue("GRP_IDUSER");
418  }
419  if (is_array($tglogin)) {
420  uasort($tglogin, "strcasecmp");
421  $this->SetValue("GRP_GROUP", $tglogin);
422  $this->SetValue("GRP_IDGROUP", array_keys($tglogin));
423  } else {
424  $this->DeleteValue("GRP_GROUP");
425  $this->DeleteValue("GRP_IDGROUP");
426  }
427 
428  $user = $this->getTvalue("grp_ruser");
429  $toomany = (count($user) > 100);
430  if ($norefresh) $this->setValue("grp_toomany", sprintf(_("Members detection are disactived for the group")));
431  elseif ($toomany) $this->setValue("grp_toomany", sprintf(_("Too many members to display there here (%d). Use Open menu to display them.") , count($user)));
432  else $this->deleteValue("grp_toomany");
433  $err = $this->modify();
434  }
435  }
436 
437  function preConsultation()
438  {
439  $user = $this->getTvalue("grp_ruser");
440  $toomany = (count($user) > 100);
441  if ($toomany) {
442  $oa = $this->getAttribute("grp_users");
443  $oa->setVisibility('H');
444  $oa = $this->getAttribute("grp_rusers");
445  $oa->setVisibility('H');
446  $oa = $this->getAttribute("grp_user");
447  $oa->setVisibility('H');
448  $oa = $this->getAttribute("grp_ruser");
449  $oa->setVisibility('H');
450  }
451  }
452 
453  function fusers_igroup($target = "finfo", $ulink = true, $abstract = "Y")
454  {
455  global $action;
456 
457  $user = $this->getTvalue("grp_ruser");
458  $toomany = (count($user) > 100);
459  //setHttpVar("specialmenu","menuab");
460  $this->viewdefaultcard($target, $ulink, $abstract);
461  $action->parent->AddCssRef("USERCARD:faddbook.css", true);
462  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/USERCARD/Layout/faddbook.js");
463  // list of attributes displayed directly in layout
464  $ta = array(
465  "grp_groups",
466  "grp_rusers",
467  "grp_users",
468  "grp_parent",
469  "us_login",
470  "us_whatid",
471  "grp_mail",
472  "us_iddomain",
473  "us_domain",
474  "grp_name",
475  "grp_role",
476  "grp_type"
477  );
478  //$ta["ident"]=array("us_lo
479  $la = $this->getAttributes();
480  $to = array();
481  $tabs = array();
482  foreach ($la as $k => $v) {
483  $va = $this->getValue($v->id);
484  if (($va || ($v->type == "array")) && (!in_array($v->id, $ta)) && (!$v->inArray())) {
485 
486  if ((($v->mvisibility == "R") || ($v->mvisibility == "W"))) {
487  if ($v->type == "array") {
488  $hv = $this->getHtmlValue($v, $va, $target, $ulink);
489  if ($hv) {
490  $to[] = array(
491  "lothers" => $v->labelText,
492  "aid" => $v->id,
493  "vothers" => $hv,
494  "isarray" => true
495  );
496  $tabs[$v->fieldSet->labelText][] = $v->id;
497  }
498  } else {
499  $to[] = array(
500  "lothers" => $v->labelText,
501  "aid" => $v->id,
502  "vothers" => $this->getHtmlValue($v, $va, $target, $ulink) ,
503  "isarray" => false
504  );
505  $tabs[$v->fieldSet->labelText][] = $v->id;
506  }
507  }
508  }
509  }
510  $this->lay->setBlockData("OTHERS", $to);
511  $this->lay->set("HasOTHERS", (count($to) > 0));
512  $this->lay->set("Toomany", $toomany);
513  $ltabs = array();
514  foreach ($tabs as $k => $v) {
515  $ltabs[$k] = array(
516  "tabtitle" => $k,
517  "aids" => "['" . implode("','", $v) . "']"
518  );
519  }
520  $this->lay->setBlockData("TABS", $ltabs);
521  $this->lay->set("ICON", $this->getIcon());
522  $this->lay->set("nmembers", count($this->getTValue("GRP_IDUSER")));
523  $this->lay->set("HasDOMAIN", ($this->getValue("US_IDDOMAIN") > 9));
524  $this->lay->set("CanEdit", ($this->control("edit") == ""));
525  }
526  function fusers_eigroup()
527  {
528  global $action;
529  $this->editattr();
530  $action->parent->AddCssRef("USERCARD:faddbook.css", true);
531  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/USERCARD/Layout/faddbook.js");
532  $firsttab = getHttpVars("tab"); // first tab displayed
533  // list of attributes displayed directly in layout
534  $ta = array(
535  "us_login",
536  "us_whatid",
537  "grp_mail",
538  "us_iddomain",
539  "us_domain",
540  "grp_name",
541  "grp_role",
542  "grp_type",
543  "grp_hasmail",
544  "grp_hasmembers"
545  );
546 
547  $q = new QueryDb("", "Domain");
548  $q->AddQuery("iddomain>9");
549  $this->lay->set("hasdomain", ($q->count() > 0));
550 
551  $this->lay->set("firsttab", $firsttab);
552  $la = $this->getNormalAttributes();
553  $to = array();
554  $tabs = array();
555  foreach ($la as $k => $v) {
556  $va = $this->getValue($v->id);
557  if (!$v->inArray() && (!in_array($v->id, $ta))) {
558  if ($v->mvisibility != "I") {
559  if ($v->type == "array") {
560  $hv = getHtmlInput($this, $v, $va);
561  if ($hv) {
562  if ($v->mvisibility != "H") {
563  $to[] = array(
564  "lothers" => $v->labelText,
565  "aid" => $v->id,
566  "vothers" => $hv,
567  "isarray" => true
568  );
569  $tabs[$v->fieldSet->labelText][] = $v->id;
570  } else {
571  $th[] = array(
572  "aid" => $v->id,
573  "vothers" => getHtmlInput($this, $v, $va)
574  );
575  }
576  }
577  } else {
578  if ($v->mvisibility != "H") {
579  $to[] = array(
580  "lothers" => $v->labelText,
581  "aid" => $v->id,
582  "vothers" => getHtmlInput($this, $v, $va) ,
583  "isarray" => false
584  );
585  $tabs[$v->fieldSet->labelText][] = $v->id;
586  } else {
587  $th[] = array(
588  "aid" => $v->id,
589  "vothers" => getHtmlInput($this, $v, $va)
590  );
591  }
592  }
593  }
594  }
595  }
596  $this->lay->setBlockData("OTHERS", $to);
597  $this->lay->setBlockData("IHIDDENS", $th);
598  $ltabs = array();
599  foreach ($tabs as $k => $v) {
600  $ltabs[$k] = array(
601  "tabtitle" => $k,
602  "aids" => "['" . implode("','", $v) . "']"
603  );
604  }
605  $this->lay->setBlockData("TABS", $ltabs);
606  $this->viewprop();
607  $this->lay->set("HasOTHERS", (count($to) > 0));
608  $this->lay->set("ICON", $this->getIcon());
609  }
610  /**
611  * @begin-method-ignore
612  * this part will be deleted when construct document class until end-method-ignore
613  */
614 }
615 /*
616  * @end-method-ignore
617 */
618 ?>
← centre documentaire © anakeen - published under CC License - Dynacase