Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.DocIntranet.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  * Intranet User & Group manipulation
9  *
10  * @author Anakeen 2004
11  * @version $Id: Method.DocIntranet.php,v 1.23 2008/04/15 07:11:04 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 _IGROUPUSER extends Doc
23 {
24  /*
25  * @end-method-ignore
26  */
27  /**
28  * verify if the login syntax is correct and if the login not already exist
29  * @param string $login login to test
30  * @return array 2 items $err & $sug for view result of the constraint
31  */
32  function ConstraintLogin($login, $iddomain)
33  {
34  $sug = array(
35  "-"
36  );
37 
38  if ($login == "") {
39  $err = _("the login must not be empty");
40  } else if ($login == "-") {
41  } else {
42  if (!preg_match("/^[a-z0-9][-_@a-z0-9\.]*[a-z0-9]+$/i", $login)) {
43  $err = _("the login syntax is like : john.doe");
44  }
45  if ($err == "") {
46  return $this->ExistsLogin($login, $iddomain);
47  }
48  }
49  return array(
50  "err" => $err,
51  "sug" => $sug
52  );
53  }
54  /**
55  * verify if the login not already exist
56  * @param string $login login to test
57  * @return array 2 items $err & $sug for view result of the constraint
58  */
59  function ExistsLogin($login, $iddomain = 0)
60  {
61  $sug = array();
62  $err = "";
63  $id = $this->GetValue("US_WHATID");
64  $user = new User("", $id);
65  $q = new QueryDb("", "User");
66  $q->AddQuery("login='" . strtolower(pg_escape_string($login)) . "'");
67  if ($id) $q->AddQuery("id != $id");
68  $iddomain = intval($iddomain);
69  $q->AddQuery("iddomain=$iddomain");
70  $q->Query(0, 0, "TABLE");
71  $err = $q->basic_elem->msg_err;
72  if (($err == "") && ($q->nb > 0)) $err = _("login yet use");
73 
74  return array(
75  "err" => $err,
76  "sug" => $sug
77  );
78  }
79 
80  function preCreated()
81  {
82  if ($this->getValue("US_WHATID") != "") {
83  include_once ('FDL/Lib.Dir.php');
84 
85  $filter = array(
86  "us_whatid = '" . intval($this->getValue("US_WHATID")) . "'"
87  );
88  $tdoc = getChildDoc($this->dbaccess, 0, 0, "ALL", $filter, 1, "TABLE", $this->fromid);
89  if (count($tdoc) > 0) return _("what id already set in freedom\nThis kind of document can not be duplicated");
90  }
91  }
92  /**
93  * avoid deletion of system document
94  */
95  function preDocDelete()
96  {
97  $err = parent::preDocDelete();
98  if ($err == "") {
99  $uid = $this->getValue("us_whatid");
100  if (($uid > 0) && ($uid < 10)) $err = _("this system user cannot be deleted");
101  }
102  return $err;
103  }
104  /**
105  * interface to affect group for an user
106  *
107  * @param string $target window target name for hyperlink destination
108  * @param bool $ulink if false hyperlink are not generated
109  * @param bool $abstract if true only abstract attribute are generated
110  */
111  function ChooseGroup($target = "_self", $ulink = true, $abstract = false)
112  {
113  global $action;
114 
115  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/mktree.js");
116 
117  $iduser = $this->getValue("US_WHATID");
118  if ($iduser > 0) {
119  $user = $this->getWUser();
120  if (!$user->isAffected()) return sprintf(_("user #%d does not exist") , $iduser);
121  $ugroup = $user->GetGroupsId();
122  } else {
123  $user = new User();
124  $ugroup = array(
125  "2"
126  ); // default what group
127 
128  }
129 
130  $this->lay->set("wid", ($iduser == "") ? "0" : $iduser);
131 
132  $q2 = new queryDb("", "User");
133  $groups = $q2->Query(0, 0, "TABLE", "select users.*, groups.idgroup, domain.name as domain from users, groups, domain where users.id = groups.iduser and users.iddomain=domain.iddomain and users.isgroup='Y'");
134 
135  $q2 = new queryDb("", "User");
136  $mgroups = $q2->Query(0, 0, "TABLE", "select users.*, domain.name as domain from users,domain where users.iddomain=domain.iddomain and isgroup='Y' and id not in (select iduser from groups)");
137 
138  if ($groups) {
139  foreach ($groups as $k => $v) {
140  $groupuniq[$v["id"]] = $v;
141  $groupuniq[$v["id"]]["checkbox"] = "";
142  if (in_array($v["id"], $ugroup)) $groupuniq[$v["id"]]["checkbox"] = "checked";
143  }
144  }
145  if (!$groups) $groups = array();
146  if ($mgroups) {
147  foreach ($mgroups as $k => $v) {
148  $cgroup = $this->_getChildsGroup($v["id"], $groups);
149  $tgroup[$k] = $v;
150  $tgroup[$k]["SUBUL"] = $cgroup;
151  $fid = $v["fid"];
152  if ($fid) {
153  $tdoc = getTDoc($this->dbaccess, $fid);
154  $icon = $this->getIcon($tdoc["icon"]);
155  $tgroup[$k]["icon"] = $icon;
156  } else {
157  $tgroup[$k]["icon"] = "Images/igroup.gif";
158  }
159  $groupuniq[$v["id"]] = $v;
160  $groupuniq[$v["id"]]["checkbox"] = "";
161  if (in_array($v["id"], $ugroup)) $groupuniq[$v["id"]]["checkbox"] = "checked";
162  }
163  }
164  $this->lay->setBlockData("LI", $tgroup);
165  uasort($groupuniq, array(
166  get_class($this) ,
167  "_cmpgroup"
168  ));
169  $this->lay->setBlockData("SELECTGROUP", $groupuniq);
170  }
171  /**
172  * internal function use for choosegroup
173  * use to compute displayed group tree
174  */
175  function _getChildsGroup($id, $groups)
176  {
177 
178  $tlay = array();
179  foreach ($groups as $k => $v) {
180  if ($v["idgroup"] == $id) {
181  $tlay[$k] = $v;
182  $tlay[$k]["SUBUL"] = $this->_getChildsGroup($v["id"], $groups);
183  $fid = $v["fid"];
184  if ($fid) {
185  $tdoc = getTDoc($this->dbaccess, $fid);
186  $icon = $this->getIcon($tdoc["icon"]);
187  $tlay[$k]["icon"] = $icon;
188  } else {
189  $tlay[$k]["icon"] = "Images/igroup.gif";
190  }
191  }
192  }
193 
194  if (count($tlay) == 0) return "";
195  global $action;
196  $lay = new Layout("USERCARD/Layout/ligroup.xml", $action);
197  uasort($tlay, array(
198  get_class($this) ,
199  "_cmpgroup"
200  ));
201  $lay->setBlockData("LI", $tlay);
202  return $lay->gen();
203  }
204  /**
205  * to sort group by name
206  */
207  static function _cmpgroup($a, $b)
208  {
209  return strcasecmp($a['lastname'], $b['lastname']);
210  }
211  /**
212  * affect new groups to the user
213  * @global gidnew Http var : egual Y to say effectif change (to not suppress group if gid not set)
214  * @global gid Http var : array of new groups id
215  */
216  function setGroups()
217  {
218  include_once ("FDL/Lib.Usercard.php");
219 
220  global $_POST;
221  $gidnew = $_POST["gidnew"];
222  $tgid = array(); // group ids will be modified
223  if ($gidnew == "Y") {
224  $gid = $_POST["gid"];
225  if ($gid == "") $gid = array();
226 
227  $user = $this->getWUser();
228  $rgid = $user->GetGroupsId();
229  if ((count($rgid) != count($gid)) || (count(array_diff($rgid, $gid)) != 0)) {
230  $gdel = array_diff($rgid, $gid);
231  $gadd = array_diff($gid, $rgid);
232  // add group
233  $g = new Group("", $user->id);
234  foreach ($gadd as $gid) {
235  $g->iduser = $user->id;
236  $g->idgroup = $gid;
237  // $aerr.=$g->Add(true);
238  if ($aerr == "") {
239  // insert in folder group
240  $gdoc = $this->getDocUser($gid);
241  // $gdoc->insertMember($this->id);
242  $gdoc->addFile($this->id);
243  $tgid[$gid] = $gid;
244  }
245  $err.= $aerr;
246  }
247  foreach ($gdel as $gid) {
248  $g->iduser = $gid;
249  //$aerr.=$g->SuppressUser($user->id,true);
250  // delete in folder group
251  $gdoc = $this->getDocUser($gid);
252  if (!method_exists($gdoc, "deleteMember")) AddWarningMsg("no group $gid/" . $gdoc->id);
253  else {
254  // $gdoc->deleteMember($this->id);
255  $err = $gdoc->delFile($this->id);
256  $tgid[$gid] = $gid;
257  }
258  }
259  // $g->FreedomCopyGroup();
260  //if ($user->isgroup=='Y') $tgid[$user->id]=$user->id;
261 
262  }
263  }
264  // it is now set in bacground
265  // refreshGroups($tgid,true);
266  return $err;
267  }
268  /**
269  * return document objet from what id (user or group)
270  * @param int $wid what identificator
271  * @return Doc the object document (false if not found)
272  */
273  function getDocUser($wid)
274  {
275  $u = new User("", $wid);
276  if ($u->isAffected()) {
277  if ($u->fid > 0) {
278  $du = new_Doc($this->dbaccess, $u->fid);
279  if ($du->isAlive()) return $du;
280  }
281  }
282  return false;
283  }
284  /**
285  * return what user object conform to whatid
286  * @return User return false if not found
287  */
288  function getWuser($nocache = false)
289  {
290  if ($nocache) {
291  $u = new User();
292  unset($this->wuser); // needed for reaffect new values
293 
294  }
295  if (!isset($this->wuser)) {
296  $wid = $this->getValue("us_whatid");
297  if ($wid > 0) {
298  $this->wuser = new User("", $wid);
299  }
300  }
301  if (!isset($this->wuser)) return false;
302  return $this->wuser;
303  }
304  /**
305  * reset wuser
306  */
307  function Complete()
308  {
309  if (isset($this->wuser)) unset($this->wuser);
310  }
311  /**
312  * @begin-method-ignore
313  * this part will be deleted when construct document class until end-method-ignore
314  */
315 }
316 /*
317  * @end-method-ignore
318 */
319 ?>
← centre documentaire © anakeen - published under CC License - Dynacase