Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.DocGroup.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  * Specials methods for GROUP family
9  *
10  * @author Anakeen 2003
11  * @version $Id: Method.DocGroup.php,v 1.15 2007/02/16 07:36:28 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  * @begin-method-ignore
18  * this part will be deleted when construct document class until end-method-ignore
19  */
20 class _GROUP extends Dir
21 {
22  /*
23  * @end-method-ignore
24  */
25  /**
26  * reconstruct mail group & recompute parent group
27  *
28  * @return string error message, if no error empty string
29  * @see Doc::PostModify()
30  */
31  function PostModify()
32  {
33 
34  $err = $this->SetGroupMail();
35  $this->refreshParentGroup();
36  return $err;
37  }
38  /**
39  * recompute only parent group
40  *
41  *
42  * @return string error message, if no error empty string
43  */
44  function RefreshGroup()
45  {
46  global $refreshedGrpId; // to avoid inifinitive loop recursion
47  $err = "";
48  if (!isset($refreshedGrpId[$this->id])) {
49  $err = $this->SetGroupMail();
50  $err.= $this->modify();
51  $this->specPostInsert();
52  $refreshedGrpId[$this->id] = true;
53  }
54  return $err;
55  }
56  /**
57  * update groups table in USER database
58  * @return string error message
59  */
60  function postInsertDoc($docid, $multiple)
61  {
62  $this->SetGroupMail();
63  $this->refreshMembers();
64  $this->specPostInsert();
65  }
66  /**
67  * update groups table in USER database
68  * @return string error message
69  */
70  function postMInsertDoc($tdocid)
71  {
72  $this->SetGroupMail();
73  $this->refreshMembers();
74  $this->specPostInsert();
75  }
76  /**
77  * update groups table in USER database before suppress
78  * @return string error message
79  */
81  {
82  $this->SetGroupMail();
83  $this->refreshMembers();
84  $this->specPostInsert();
85  }
86  /**
87  * special method for child classes
88  * call after insert user in group
89  * @return string error message
90  */
91  function specPostInsert()
92  {;
93  }
94  /**
95  * compute the mail of the group
96  * concatenation of each user mail and group member mail
97  *
98  *
99  * @return string error message, if no error empty string
100  */
101  function SetGroupMail($nomail = false)
102  {
103 
104  $err = "";
105  $gmail = " ";
106  $tmail = array();
107 
108  if (!$nomail) $nomail = ($this->getValue("grp_hasmail") == "no");
109  //------------------------------------------------------
110  // first compute mail from users members
111  $tiduser = $this->getTValue("GRP_IDUSER");
112  $tuser = $this->getTValue("GRP_USER");
113  if (count($tiduser) > 0) {
114  if (!$nomail) {
115  foreach ($tiduser as $k => $v) {
116 
117  $udoc = getTDoc($this->dbaccess, $v);
118  if ($udoc) {
119 
120  $mail = getv($udoc, "us_mail");
121 
122  if ($mail != "") $tmail[] = $mail;
123  } else {
124  if ($tuser[$k] != "") $err.= sprintf("%s does not exist", $tuser[$k]);
125  }
126  }
127  $gmail = implode(", ", array_unique($tmail));
128  }
129  }
130  $nodetectmembers = ($this->getValue("grp_hasmembers") == "no");
131  // add mail groups
132  //------------------------------------------------------
133  // second compute mail from groups members
134  $tgmemberid = $tiduser; // affiliated members ids
135  $tgmember = $tuser; // affiliated members
136  $tiduser = $this->getTValue("GRP_IDGROUP");
137  if (count($tiduser) > 0) {
138  while (list($k, $v) = each($tiduser)) {
139  $udoc = new_Doc($this->dbaccess, $v);
140  if ($udoc && $udoc->isAlive()) {
141  if (!$nomail) {
142  $mail = $udoc->getValue("GRP_MAIL");
143  if ($mail != "") {
144  $tmail1 = explode(",", str_replace(" ", "", $mail));
145  $tmail = array_merge($tmail, $tmail1);
146  }
147  }
148  if (!$nodetectmembers) {
149  $tgmemberid = array_merge($tgmemberid, $udoc->getTValue("GRP_IDRUSER"));
150  $tgmember = array_merge($tgmember, $udoc->getTValue("GRP_RUSER"));
151  }
152  }
153  }
154 
155  $gmail = implode(", ", array_unique($tmail));
156  }
157  $tgmembers = array();
158  reset($tgmemberid);
159  while (list($k, $v) = each($tgmemberid)) {
160  $tgmembers[$v] = $tgmember[$k];
161  }
162 
163  if ($nodetectmembers) {
164  $this->DeleteValue("GRP_IDRUSER");
165  $this->DeleteValue("GRP_RUSER");
166  } else {
167  if (count($tgmembers) > 0) {
168  $this->SetValue("GRP_IDRUSER", array_keys($tgmembers));
169  $this->SetValue("GRP_RUSER", $tgmembers);
170  } else {
171  $this->DeleteValue("GRP_IDRUSER");
172  $this->DeleteValue("GRP_RUSER");
173  }
174  }
175 
176  if (!$nomail) $this->SetValue("GRP_MAIL", $gmail);
177  else if ($this->getValue("grp_hasmail") == "no") $this->deleteValue("GRP_MAIL");
178 
179  return $err;
180  }
181  /**
182  * recompute parent group and its ascendant
183  *
184  * @return array/array parents group list refreshed
185  * @see RefreshGroup()
186  */
188  {
189  include_once ("FDL/freedom_util.php");
190  include_once ("FDL/Lib.Dir.php");
191 
192  $sqlfilters[] = "in_textlist(grp_idgroup,{$this->id})";
193  // $sqlfilters[]="fromid !=".getFamIdFromName($this->dbaccess,"IGROUP");
194  $tgroup = getChildDoc($this->dbaccess, 0, "0", "ALL", $sqlfilters, 1, "LIST", getFamIdFromName($this->dbaccess, "GROUP"));
195 
196  $tpgroup = array();
197  $tidpgroup = array();
198  while (list($k, $v) = each($tgroup)) {
199  $v->RefreshGroup();
200  $tpgroup[] = $v->title;
201  $tidpgroup[] = $v->id;
202  }
203 
204  $this->SetValue("GRP_PGROUP", implode("\n", $tpgroup));
205  $this->SetValue("GRP_IDPGROUP", implode("\n", $tidpgroup));
206  return $tgroup;
207  }
208  /**
209  * refresh members of the group from USER database
210  */
211  function refreshMembers()
212  {
213  include_once ("FDL/Lib.Dir.php");
214  // 1)users
215  $tu = getChildDoc($this->dbaccess, $this->initid, "0", "ALL", array() , 1, "TABLE", "USER");
216 
217  if (count($tu) > 0) {
218  foreach ($tu as $k => $v) {
219  $tmemid[] = $v["id"];
220  $tmem[] = $v["title"];
221  }
222  $this->SetValue("GRP_USER", $tmem);
223  $this->SetValue("GRP_IDUSER", $tmemid);
224  } else {
225  $this->DeleteValue("GRP_USER");
226  $this->DeleteValue("GRP_IDUSER");
227  $this->DeleteValue("GRP_GROUP");
228  $this->DeleteValue("GRP_IDGROUP");
229  }
230  // 2)groups
231  $tu = getChildDoc($this->dbaccess, $this->initid, "0", "ALL", array() , 1, "TABLE", "GROUP");
232  $tmemid = array();
233  $tmem = array();
234  if (count($tu) > 0) {
235  foreach ($tu as $k => $v) {
236  $tmemid[] = $v["id"];
237  $tmem[] = $v["title"];
238  }
239  $this->SetValue("GRP_GROUP", $tmem);
240  $this->SetValue("GRP_IDGROUP", $tmemid);
241  } else {
242  $this->DeleteValue("GRP_GROUP");
243  $this->DeleteValue("GRP_IDGROUP");
244  }
245  $err = $this->modify();
246  }
247 
249  {
250  // Recompute mail/members when the hasmail/hasmembers enum is changed
251  if ($this->getOldValue('GRP_HASMAIL') !== false || $this->getOldValue('GRP_HASMEMBERS') !== false) {
252  $err = $this->refreshGroup();
253  if ($err != '') {
254  return $err;
255  }
256  }
257  return '';
258  }
259  /**
260  * @begin-method-ignore
261  * this part will be deleted when construct document class until end-method-ignore
262  */
263 }
264 /*
265  * @end-method-ignore
266 */
267 ?>
← centre documentaire © anakeen - published under CC License - Dynacase