Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
refreshUserAccount.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @subpackage
10  */
11 /**
12  */
13 // refreah for a classname
14 // use this only if you have changed title attributes
15 include_once ("FDL/Class.Doc.php");
16 include_once ("FDL/Lib.Dir.php");
17 
19 $appl->Set("FDL", $core);
20 
21 $dbaccess = $appl->dbaccess;
22 if ($dbaccess == "") {
23  print "Database not found : appl->dbaccess";
24  return;
25 }
26 
27 $usage = new ApiUsage();
28 
29 $usage->setDefinitionText("Update usercard");
30 $whatid = $usage->addOptionalParameter("whatid", "document"); // document
31 $fbar = $usage->addOptionalParameter("bar", "for progress bar"); // for progress bar
32 $onlygroup = ($usage->addOptionalParameter("onlygroup", "for progress bar") != ""); // for progress bar
33 $usage->verify();
34 
35 $query = new QueryDb("", "Account");
36 
37 if ($whatid > 0) {
38  $query->AddQuery("id=$whatid");
39 } else {
40  $query->order_by = "accounttype desc,id";
41 }
42 
43 if ($onlygroup) $query->AddQuery("accounttype='G'");
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 = new Doc($dbaccess);
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  $udoc = false;
63  $foundoc = false;
64  $fid = $v["fid"];
65  if ($fid > 0) {
66  $udoc = new_doc($dbaccess, $fid);
67  $foundoc = $udoc->isAlive();
68  }
69 
70  if (!$foundoc) {
71  // search same doc with us_what id
72  if ($v["accounttype"] == "G") {
73  $filter = array(
74  "us_whatid = '" . $v["id"] . "'"
75  );
76  $tdoc = internalGetDocCollection($dbaccess, 0, 0, "ALL", $filter, 1, "TABLE", "IGROUP");
77  } else {
78  $filter = array(
79  "us_whatid = '" . $v["id"] . "'"
80  );
81  $tdoc = internalGetDocCollection($dbaccess, 0, 0, "ALL", $filter, 1, "TABLE", "IUSER");
82  }
83 
84  if (count($tdoc) > 0) {
85  $fid = $tdoc["id"];
86  $udoc = new_doc($dbaccess, $fid);
87  $foundoc = $udoc->isAlive();
88  }
89  }
90  if ($foundoc) {
91  /**
92  * @var \Dcp\Family\IUSER|\Dcp\Family\IGROUP $udoc
93  */
94  if (method_exists($udoc, "RefreshGroup")) $udoc->RefreshGroup();
95  else if (method_exists($udoc, "RefreshDocUser")) $udoc->RefreshDocUser();
96  //if (method_exists($tdoc[0],"SetGroupMail")) $tdoc[0]->SetGroupMail();
97  //$tdoc[0]->refresh();
98  //$tdoc[0]->postModify();
99  $err = $udoc->modify();
100  if ($err != "") print "$err\n";
101  else {
102  print "$reste)";
103  printf(_("%s updated\n") , $udoc->title);
104  $fid = $udoc->id;
105  }
106  } else {
107  // search in all usercard same title
108  if ($mail != "") $filter = array(
109  "us_mail = '" . pg_escape_string($mail) . "'"
110  );
111  else $filter = array(
112  "lower(title) = '" . pg_escape_string($title) . "'"
113  );
114  $tdoc = internalGetDocCollection($dbaccess, 0, 0, "ALL", $filter, 1, "LIST", getFamIdFromName($dbaccess, "IUSER"));
115  if (count($tdoc) > 0) {
116  if (count($tdoc) > 1) {
117  printf(_("find %s more than one, created aborded\n") , $title);
118  } else {
119 
120  $udoc = new_Doc($dbaccess, $tdoc[0]->id);
121  /**
122  * @var \Dcp\Family\IUSER $udoc
123  */
124  $udoc->setValue("US_WHATID", $v["id"]);
125  $udoc->refresh();
126  $udoc->RefreshDocUser();
127  $udoc->modify();
128  $fid = $udoc->id;
129  print "$reste)";
130  printf(_("%s updated\n") , $title);
131  unset($udoc);
132  }
133  } else {
134  // create new card
135  if ($v["accounttype"] == "G") {
136  $iuser = createDoc($dbaccess, getFamIdFromName($dbaccess, "IGROUP"));
137  $iuser->setValue("US_WHATID", $v["id"]);
138  $iuser->Add();
139  $iuser->refresh();
140  $iuser->postStore();
141  $iuser->modify();
142  print "$reste)";
143  printf(_("%s igroup created\n") , $title);
144  } else {
145  $iuser = createDoc($dbaccess, getFamIdFromName($dbaccess, "IUSER"));
146  $iuser->setValue("US_WHATID", $v["id"]);
147  $err = $iuser->Add();
148  if ($err == "") {
149  //$iuser->refresh();
150  //$iuser->RefreshDocUser();
151  //$iuser->modify();
152  print "$reste)";
153  printf(_("%s iuser created\n") , $title);
154  } else {
155  print "$reste)$err";
156  printf(_("%s iuser aborded\n") , $title);
157  }
158  }
159  $fid = $iuser->id;
160  unset($iuser);
161  }
162  }
163 
164  if (($v["fid"] == 0) && ($fid > 0)) {
165  $u = new Account("", $v["id"]);
166  $u->fid = $fid;
167  $u->modify();
168  unset($u);
169  }
170 
171  wbar($reste, $card, $title);
172  }
173 
174  $doc->exec_query("update doc127 set name='GADMIN' where us_whatid='4'");
175  $doc->exec_query("update doc127 set name='GDEFAULT' where us_whatid='2'");
176  $doc->exec_query("update doc128 set name='USER_ADMIN' where us_whatid='1'");
177  $doc->exec_query("update doc128 set name='USER_GUEST' where us_whatid='3'");
178  $doc->exec_query("update doc128 set cvid=508 where us_whatid='1'");
179  $doc->exec_query("update doc128 set cvid=508 where us_whatid='3'");
180 }
$tdoc
getMailAddr($userid, $full=false)
Definition: Lib.Common.php:133
wbar($reste, $total, $text="", $fbar=false)
Definition: Lib.Common.php:642
if($dbaccess=="") $usage
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
internalGetDocCollection($dbaccess, $dirid, $start="0", $slice="ALL", $sqlfilters=array(), $userid=1, $qtype="LIST", $fromid="", $distinct=false, $orderby="title", $latest=true, $trash="", &$debug=null, $folderRecursiveLevel=2, $join= '',\SearchDoc &$searchDoc=null)
Definition: Lib.Dir.php:428
getFamIdFromName($dbaccess, $name)
print
Definition: checklist.php:49
new_Doc($dbaccess, $id= '', $latest=false)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.
$core
Definition: chgpasswd.php:33
← centre documentaire © anakeen