Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fdl_resetprofiling.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * reset profiling use when restore context from archive
8  * all document has the same profil
9  *
10  * @author Anakeen
11  * @version $Id: $
12  *
13  * @package FDL
14  *
15  *
16  * @global login string Http var : login
17  * @global password string Http var : password
18  /**
19  */
20 
21 include_once ("FDL/Class.Doc.php");
22 
23 $usage = new ApiUsage();
24 
25 $usage->setDefinitionText("Reset profiling use when restore context from archive");
26 $user = $usage->addRequiredParameter("login", "login");
27 $password = $usage->addRequiredParameter("password", "password");
28 
29 $usage->verify();
30 /*
31  * @var Action $action
32  */
33 global $action;
34 $dbaccess = $action->dbaccess;
35 $coreaccess = $action->dbaccess;
36 
37 if ($dbaccess == "") {
38  print "Database not found : action->dbaccess";
39  exit;
40 }
41 
42 $u = new Account($coreaccess);
43 $u->setLoginName($user);
44 $uid = $u->id;
45 $err = '';
46 if (!$uid) {
47  $du = createDoc($dbaccess, "IUSER");
48  if ($du) {
49  $du->setValue("us_login", $user);
50  $du->setValue("us_lname", $user);
51  $du->setValue("us_fname", "");
52  $du->setValue("us_passwd1", $password);
53  $du->setValue("us_passwd2", $password);
54  $err = $du->Add();
55  if ($err == "") {
56  $err = $du->postStore();
57  if ($err == "") {
58  $err = $du->modify();
59  if ($err == "") {
60  printf(_("new user # %d") , $du->getRawValue("us_whatid")); // affichage de l'identifiant système
61 
62  /*
63  * @var Dir $g
64  */
65  $g = new_Doc($dbaccess, "GDEFAULT");
66  if ($g) {
67  $err = $g->insertDocument($du->initid);
68  }
69  }
70  }
71  }
72  if ($err) print "\nerreur:$err\n";
73  $uid = $du->getRawValue("us_whatid");
74  }
75 }
76 if ($uid > 0) {
77  $pname = strtoupper($user . "PROFIL");
78  $pdoc = new_doc($dbaccess, $pname);
79 
80  if (!$pdoc->isAffected()) {
81  $pdoc = createDoc($dbaccess, "PDIR");
82  if ($pdoc) {
83  $pdoc->setValue("ba_title", "profil de " . $user);
84  $pdoc->setValue("prf_desc", "profil de " . $user);
85  $pdoc->name = strtoupper($pname); // on donne un nom logique pour le retrouver après
86  $err = $pdoc->Add();
87  if ($err == "") {
88  // ajout d'ACLs
89  $pdoc->setControl(false); // activ profil
90  printf(_("new profil %d") , $pdoc->id);
91 
92  $perm = new DocPerm($dbaccess);
93  $perm->docid = $pdoc->id;
94  $perm->userid = $uid;
95  $perm->upacl = - 2 & (~(1 << 2)); // all privileges except read => read only
96  // add all privileges to user
97  $err = $perm->Add();
98  if ($err == "") {
99  // reset all profil big security
100  $err = simpleQuery($dbaccess, sprintf("update doc set profid=%d,dprofid=0", $pdoc->id) , $res);
101  $err.= simpleQuery($dbaccess, sprintf("INSERT INTO permission (id_user, id_application, id_acl) SELECT users.id as uid, id_application as appid,acl.id as aclid from acl, users where users.id=%d", $uid));
102  }
103  }
104  }
105  if ($err) print "\nerreur:$err\n";
106  }
107 }
← centre documentaire © anakeen