Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DbObjCtrl.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: Class.DbObjCtrl.php,v 1.9 2003/08/18 15:46:42 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage CORE
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: Class.DbObjCtrl.php,v 1.9 2003/08/18 15:46:42 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/core/Class/Appmng/Class.DbObjCtrl.php,v $
21 // ---------------------------------------------------------------
22 
23 $CLASS_DBOBJCTRL_PHP = '$Id: Class.DbObjCtrl.php,v 1.9 2003/08/18 15:46:42 eric Exp $';
24 
25 include_once ('Class.ObjectPermission.php');
26 include_once ('Class.Application.php');
27 
28 class DbObjCtrl extends DbObj
29 {
30  var $obj_acl = array(); //should be replaced by the Child Class
31  var $operm;
32  var $action;
33  // --------------------------------------------------------------------
34  function DbObjCtrl($dbaccess = '', $id = '', $res = '', $dbid = 0)
35  {
36  // --------------------------------------------------------------------
37  global $action; // necessary to see information about user privilege
38  if (isset($action)) {
39  $this->classid = $this->getClassId();
40  $cid = $this->classid;
41  $this->userid = $action->parent->user->id;
42  }
43  DbObj::DbObj($dbaccess, $id, $res, $dbid);
44  }
45 
46  function getClassId()
47  {
48  // must be set by child
49  return 0;
50  }
51  function PostSelect()
52  {
53 
54  if ($this->IsControlled()) {
55 
56  $this->operm = new ObjectPermission("", array(
57  $this->userid,
58  $this->id,
59  $this->classid
60  ));
61  }
62  }
63  // --------------------------------------------------------------------
64  function Control($aclname)
65  {
66  // --------------------------------------------------------------------
67  if ($this->IsAffected()) if ($this->IsControlled()) return $this->operm->Control($this, $aclname);
68  else return "";
69 
70  return "object not initialized : $aclname";
71  }
72  // --------------------------------------------------------------------
73  function PostUpdate()
74  // --------------------------------------------------------------------
75 
76  {
77  // add controlled object
78  if (!isset($this->id)) return "";
79 
80  $cobj = new ControlObject("", array(
81  $this->id,
82  $this->classid
83  ));
84 
85  $cobj->description = $this->Description();
86  $cobj->Modify();
87  }
88  // --------------------------------------------------------------------
89  function SetControl()
90  // --------------------------------------------------------------------
91 
92  {
93  // record object as controlled object
94  //print "SetControl:$this->id, $this->classid";
95  if (!isset($this->id)) return "";
96 
97  $cobj = new ControlObject();
98  $cobj->id_obj = $this->id;
99  $cobj->id_class = $this->classid;
100  $cobj->description = $this->Description();
101  $cobj->Add();
102 
103  $this->operm = new ObjectPermission("", array(
104  $this->userid,
105  $this->id,
106  $this->classid
107  ));
108 
109  $this->operm->Delete();
110  $acl = new Acl();
111 
112  $acl->Set("modifyacl", $this->classid);
113  $this->operm->AddAcl($acl->id);
114 
115  $acl->Set("viewacl", $this->classid);
116  $this->operm->AddAcl($acl->id);
117  // set all permissions
118  while (list($k, $v) = each($this->obj_acl)) {
119  $acl->Set($v["name"], $this->classid);
120  $this->operm->AddAcl($acl->id);
121  }
122 
123  $this->operm->Add();
124  }
125  // --------------------------------------------------------------------
126  function UnsetControl()
127  // --------------------------------------------------------------------
128 
129  {
130  // delete object as controlled object
131  if (!isset($this->id)) return "";
132 
133  $this->operm->delete();
134  $cobj = new ControlObject("", array(
135  $this->id,
136  $this->classid
137  ));
138 
139  $cobj->Delete();
140  }
141  // --------------------------------------------------------------------
142  function IsControlled()
143  {
144  // --------------------------------------------------------------------
145  $cobj = new ControlObject("", array(
146  $this->id,
147  $this->classid
148  ));
149  return $cobj->IsAffected();
150  }
151  // --------------------------------------------------------------------
152  function PostDelete()
153  // --------------------------------------------------------------------
154 
155  {
156  // ------------------------------
157  // delete control object
158  $cobj = new ControlObject($this->dbaccess, array(
159  $this->id,
160  $this->classid
161  ));
162  $cobj->Delete();
163  }
164  // --------------------------------------------------------------------
165  function Description()
166  {
167  // --------------------------------------------------------------------
168  // This function should be replaced by the Child Class
169  return "None";
170  }
171  // --------------------------------------------------------------------
172  function InitObjectAcl()
173  // init ACL table with object acls
174  // --------------------------------------------------------------------
175 
176  {
177 
178  $defacl = array(
179  array(
180  "name" => "modifyacl",
181  "description" => N_("modify object acl")
182  ) ,
183  array(
184  "name" => "viewacl",
185  "description" => N_("view object acl")
186  )
187  );
188 
189  if (!((isset($obj->obj_acl)) && (is_array($obj->obj_acl)))) {
190  $this->log->warning("InitObjectAcl no Acl for object class " . get_class($this));
191  }
192 
193  $this->obj_acl = array_merge($this->obj_acl, $defacl);
194 
195  $app = new Application();
196 
197  if (($id_app = $app->GetIdFromName(get_class($this))) == 0) {
198  // create if not exist
199  $app->name = get_class($this);
200  $app->short_name = get_class($this) . " Class";
201  $app->description = get_class($this) . " Class";
202  $app->access_free = "N";
203  $app->available = "N";
204  $app->icon = "";
205  $app->displayable = "N";
206  $app->objectclass = "Y";
207  $app->Add();
208  $id_app = $app->id;
209  } else {
210  $app->Select($id_app);
211  }
212 
213  $acl = new Acl();
214 
215  $acl->Init($app, $this->obj_acl, true);
216  }
217 }
218 ?>
← centre documentaire © anakeen - published under CC License - Dynacase