Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.CVDoc.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  * Control view Class Document
9  *
10  * @author Anakeen 2003
11  * @version $Id: Class.CVDoc.php,v 1.7 2006/04/03 14:56:26 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 include_once ('FDL/Class.Doc.php');
19 /**
20  * Control view Class
21  */
22 class CVDoc extends Doc
23 {
24  /**
25  * CVDoc has its own special access depend on special views
26  * by default the three access are always set
27  *
28  * @var array
29  */
30  var $acls = array(
31  "view",
32  "edit",
33  "delete"
34  );
35 
36  var $nbId = 0;
37 
38  var $usefor = 'W';
39  var $defDoctype = 'P';
40  var $attrPrefix = "CVI"; // prefix attribute
41  // --------------------------------------------------------------------
42  function CVDoc($dbaccess = '', $id = '', $res = '', $dbid = 0)
43  {
44  // first construct acl array
45  if (isset($this->fromid)) $this->defProfFamId = $this->fromid; // it's a profil itself
46 
47  // don't use Doc constructor because it could call this constructor => infinitive loop
49 
50  $this->setAcls();
51  }
52 
53  function setAcls()
54  {
55  $ti = $this->getTValue("CV_IDVIEW");
56  $tl = $this->getTValue("CV_LVIEW");
57  $tz = $this->getTValue("CV_ZVIEW");
58  $tk = $this->getTValue("CV_KVIEW");
59  $tm = $this->getTValue("CV_MSKID");
60 
61  $ka = POS_WF;
62  while (list($k, $v) = each($tk)) {
63  if ($ti[$k] == "") $cvk = "CV$k";
64  else $cvk = $ti[$k];
65  $this->dacls[$cvk] = array(
66  "pos" => $ka,
67  "description" => $tl[$k]
68  );
69  $this->acls[] = $cvk;
70  $ka++;
71  }
72  }
73 
74  function isIdValid($value)
75  {
76  $err = "";
77  $sug = array();
78  $this->nbId++;
79 
80  $dc = new DocCtrl($this->dbaccess);
81  $originals = $dc->dacls;
82 
83  if ($this->nbId > 20) {
84  $err = _("Maximum 20 views by control");
85  } elseif (!preg_match('!^[0-9a-z_-]+$!i', $value)) {
86  $err = _("You must use only a-z, 0-9, _, - caracters");
87  } elseif (array_key_exists($value, $originals)) {
88  $err = _("Impossible to name a view like a control acl");
89  } else {
90  $id_list = $this->getTValue('CV_IDVIEW');
91  $id_count = 0;
92  foreach ($id_list as $id) {
93  if ($id == $value) {
94  $id_count++;
95  }
96  }
97  if ($id_count > 1) {
98  $err = _("Impossible to have several identical names");
99  }
100  }
101  return array(
102  "err" => $err,
103  "sug" => $sug
104  );
105  }
106 
107  function getView($vid)
108  {
109  $ti = $this->getTValue("CV_IDVIEW");
110  foreach ($ti as $k => $v) {
111  if ($v == $vid) {
112  // found it
113  $tl = $this->getTValue("CV_LVIEW");
114  $tz = $this->getTValue("CV_ZVIEW");
115  $tk = $this->getTValue("CV_KVIEW");
116  $tm = $this->getTValue("CV_MSKID");
117 
118  return array(
119  "CV_IDVIEW" => $v,
120  "CV_LVIEW" => $tl[$k],
121  "CV_ZVIEW" => $tz[$k],
122  "CV_KVIEW" => $tk[$k],
123  "CV_MSKID" => $tm[$k]
124  );
125  }
126  }
127  return false;
128  }
129 
130  function getViews()
131  {
132  $ti = $this->getTValue("CV_IDVIEW");
133  $tv = array();
134  foreach ($ti as $k => $v) {
135 
136  $tv[$v] = $this->getView($v);
137  }
138  return $tv;
139  }
140 
141  function postModify()
142  {
143 
144  $ti = $this->getTValue("CV_IDVIEW");
145  foreach ($ti as $k => $v) {
146  if ($v == "") $ti[$k] = "CV$k";
147  }
148  $this->setValue("CV_IDVIEW", $ti);
149  }
150 
151  function DocControl($aclname)
152  {
153  return Doc::Control($aclname);
154  }
155  /**
156  * Special control in case of dynamic controlled profil
157  */
158  function Control($aclname)
159  {
160 
161  $err = $this->DocControl($aclname);
162  if ($err == "") return $err; // normal case
163  if ($this->getValue("DPDOC_FAMID") > 0) {
164  if ($this->doc) {
165  // special control for dynamic users
166  if (!isset($this->pdoc)) {
167  $pdoc = createDoc($this->dbaccess, $this->fromid, false);
168  $pdoc->doctype = "T"; // temporary
169  // $pdoc->setValue("DPDOC_FAMID",$this->getValue("DPDOC_FAMID"));
170  $err = $pdoc->Add();
171  if ($err != "") return "CVDoc::Control:" . $err; // can't create profil
172  $pdoc->setProfil($this->profid, $this->doc);
173  $pdoc->dacls = $this->dacls;
174 
175  $this->pdoc = & $pdoc;
176  }
177  $err = $this->pdoc->DocControl($aclname);
178  }
179  }
180  return $err;
181  }
182 
183  function Set(&$doc)
184  {
185  if (!isset($this->doc)) {
186  $this->doc = & $doc;
187  }
188  }
189  /**
190  * retrieve first compatible view
191  * @param bool $edition if true edition view else consultation view
192  * @return array view definition "cv_idview", "cv_mskid"
193  */
194  function getPrimaryView($edition = false)
195  {
196  if ($this->doc) {
197  if ($edition && (!$this->doc->id)) {
198  $vidcreate = $this->getValue("cv_idcview");
199  if ($vidcreate) {
200  // control must be done by the caller
201  $viewU = $this->getView($vidcreate); // use it first if exist
202  $view = array();
203  foreach ($viewU as $k => $v) $view[strtolower($k) ] = $v;
204  }
205  }
206 
207  if (!$view) {
208  $type = ($edition) ? "VEDIT" : "VCONS";
209  // search preferred view
210  $tv = $this->getAValues("cv_t_views");
211  // sort
212  usort($tv, "cmp_cvorder3");
213  foreach ($tv as $k => $v) {
214  if ($v["cv_order"] > 0) {
215  if ($v["cv_kview"] == $type) {
216  $err = $this->control($v["cv_idview"]); // control special view
217  if ($err == "") {
218  $view = $v;
219  break;
220  }
221  }
222  }
223  }
224  }
225  }
226  return $view;
227  }
228 }
229 ?>
← centre documentaire © anakeen - published under CC License - Dynacase