Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
usercard_iuser.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  * Generated Header (not documented yet)
9  *
10  * @author Anakeen 2000
11  * @version $Id: usercard_iuser.php,v 1.18 2007/03/21 15:32:57 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 // refreah for a classname
19 // use this only if you have changed title attributes
20 include_once ("FDL/Class.Doc.php");
21 include_once ("FDL/Lib.Dir.php");
22 
24 $appl->Set("FDL", $core);
25 
26 $dbaccess = $appl->GetParam("FREEDOM_DB");
27 if ($dbaccess == "") {
28  print "Database not found : param FREEDOM_DB";
29  return;
30 }
31 
32 $whatid = GetHttpVars("whatid", ""); // document
33 $fbar = GetHttpVars("bar"); // for progress bar
34 $onlygroup = (GetHttpVars("onlygroup") != ""); // for progress bar
35 $query = new QueryDb("", "User");
36 
37 if ($whatid > 0) {
38  $query->AddQuery("id=$whatid");
39 } else {
40  $query->order_by = "isgroup,id";
41 }
42 
43 if ($onlygroup) $query->AddQuery("isgroup='Y'");
44 
45 $table1 = $query->Query(0, 0, "TABLE");
46 
47 if ($query->nb > 0) {
48 
49  printf("\n%d user to update\n", count($table1));
50  $card = count($table1);
51  $doc = createDoc($dbaccess, $famId, false);
52  $reste = $card;
53  foreach ($table1 as $k => $v) {
54  $fid = 0;
55 
56  $reste--;
57  // search already created card
58  $title = strtolower($v["lastname"] . " " . $v["firstname"]);
59  $mail = getMailAddr($v["id"]);
60  // first in IUSER
61  unset($tdoc);
62  $foundoc = false;
63  $fid = $v["fid"];
64  if ($fid > 0) {
65  $udoc = new_doc($dbaccess, $fid);
66  $foundoc = $udoc->isAlive();
67  }
68 
69  if (!$foundoc) {
70  // search same doc with us_what id
71  if ($v["isgroup"] == "Y") {
72  $filter = array(
73  "us_whatid = '" . $v["id"] . "'"
74  );
75  $tdoc = getChildDoc($dbaccess, 0, 0, "ALL", $filter, 1, "TABLE", "IGROUP");
76  } else {
77  $filter = array(
78  "us_whatid = '" . $v["id"] . "'"
79  );
80  $tdoc = getChildDoc($dbaccess, 0, 0, "ALL", $filter, 1, "TABLE", "IUSER");
81  }
82 
83  if (count($tdoc) > 0) {
84  $fid = $tdoc["id"];
85  $udoc = new_doc($dbaccess, $fid);
86  $foundoc = $udoc->isAlive();
87  }
88  }
89  if ($foundoc) {
90 
91  if (method_exists($udoc, "RefreshGroup")) $udoc->RefreshGroup();
92  else if (method_exists($udoc, "RefreshDocUser")) $udoc->RefreshDocUser();
93  //if (method_exists($tdoc[0],"SetGroupMail")) $tdoc[0]->SetGroupMail();
94  //$tdoc[0]->refresh();
95  //$tdoc[0]->postModify();
96  $err = $udoc->modify();
97  if ($err != "") print "$err\n";
98  else {
99  print "$reste)";
100  printf(_("%s updated\n") , $udoc->title);
101  $fid = $udoc->id;
102  }
103  } else {
104  // search in all usercard same title
105  if ($mail != "") $filter = array(
106  "us_mail = '$mail'"
107  );
108  else $filter = array(
109  "lower(title) = '" . pg_escape_string($title) . "'"
110  );
111  $tdoc = getChildDoc($dbaccess, 0, 0, "ALL", $filter, 1, "LIST", getFamIdFromName($dbaccess, "USER"));
112  if (count($tdoc) > 0) {
113  if (count($tdoc) > 1) {
114  printf(_("find %s more than one, created aborded\n") , $title);
115  } else {
116  if ($tdoc[0]->fromid == getFamIdFromName($dbaccess, "USER")) {
117  $tdoc[0]->convert(getFamIdFromName($dbaccess, "IUSER") , array(
118  "US_WHATID" => $v["id"]
119  ));
120  print "$reste)";
121  printf(_("%s migrated\n") , $title);
122  $fid = $tdoc[0]->id;
123  } else {
124  $udoc = new_Doc($dbaccess, $tdoc[0]->id);
125  $udoc->setValue("US_WHATID", $v["id"]);
126  $udoc->refresh();
127  $udoc->RefreshDocUser();
128  $udoc->modify();
129  $fid = $udoc->id;
130  print "$reste)";
131  printf(_("%s updated\n") , $title);
132  unset($udoc);
133  }
134  }
135  } else {
136  // create new card
137  if ($v["isgroup"] == "Y") {
138  $iuser = createDoc($dbaccess, getFamIdFromName($dbaccess, "IGROUP"));
139  $iuser->setValue("US_WHATID", $v["id"]);
140  $iuser->Add();
141  $iuser->refresh();
142  $iuser->postmodify();
143  $iuser->modify();
144  print "$reste)";
145  printf(_("%s igroup created\n") , $title);
146  } else {
147  $iuser = createDoc($dbaccess, getFamIdFromName($dbaccess, "IUSER"));
148  $iuser->setValue("US_WHATID", $v["id"]);
149  $err = $iuser->Add();
150  if ($err == "") {
151  //$iuser->refresh();
152  //$iuser->RefreshDocUser();
153  //$iuser->modify();
154  print "$reste)";
155  printf(_("%s iuser created\n") , $title);
156  } else {
157  print "$reste)$err";
158  printf(_("%s iuser aborded\n") , $title);
159  }
160  }
161  $fid = $iuser->id;
162  unset($iuser);
163  }
164  }
165 
166  if (($v["fid"] == 0) && ($fid > 0)) {
167  $u = new User("", $v["id"]);
168  $u->fid = $fid;
169  $u->modify();
170  unset($u);
171  }
172 
173  wbar($reste, $card, $title);
174  }
175 
176  $doc->exec_query("update doc127 set name='GADMIN' where us_whatid=4");
177  $doc->exec_query("update doc127 set name='GDEFAULT' where us_whatid=2");
178 }
179 ?>
← centre documentaire © anakeen - published under CC License - Dynacase