Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.Mask.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: Method.Mask.php,v 1.23 2008/09/12 10:14:48 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 // ---------------------------------------------------------------
19 // $Id: Method.Mask.php,v 1.23 2008/09/12 10:14:48 eric Exp $
20 // $Source: /home/cvsroot/anakeen/freedom/freedom/Class/Freedom/Method.Mask.php,v $
21 // ---------------------------------------------------------------
22 
23 /**
24  * @begin-method-ignore
25  * this part will be deleted when construct document class until end-method-ignore
26  */
27 class _MASK extends Doc
28 {
29  /*
30  * @end-method-ignore
31  */
32 
33  var $defaultedit = "FREEDOM:EDITMASK";
34  var $defaultview = "FREEDOM:VIEWMASK";
35 
36  function SpecRefresh()
37  {
38  // gettitle(D,AR_IDCONST):AR_CONST,AR_IDCONST
39  $this->refreshDocTitle("MSK_FAMID", "MSK_FAM");
40 
41  return $err;
42  }
43 
44  function getLabelVis()
45  {
46  return array(
47  "-" => " ",
48  "R" => _("read only") ,
49  "W" => _("read write") ,
50  "O" => _("write only") ,
51  "H" => _("hidden") ,
52  "S" => _("read disabled") ,
53  "U" => _("static array") ,
54  "I" => _("invisible")
55  );
56  }
57  function getLabelNeed()
58  {
59  return array(
60  "-" => " ",
61  "Y" => _("Y") ,
62  "N" => _("N")
63  );
64  }
65  /**
66  * suppress unmodified attributes visibilities
67  * to simplify the mask structure
68  */
69  function postModify()
70  {
71  $tneed = $this->getTValue("MSK_NEEDEEDS");
72  $tattrid = $this->getTValue("MSK_ATTRIDS");
73  $tvis = $this->getTValue("MSK_VISIBILITIES");
74 
75  $tvisibilities = array();
76  foreach ($tattrid as $k => $v) {
77  if (($tneed[$k] == '-') && ($tvis[$k] == '-')) {
78  unset($tneed[$k]);
79  unset($tvis[$k]);
80  unset($tattrid[$k]);
81  }
82  }
83 
84  $this->setValue("MSK_NEEDEEDS", $tneed);
85  $this->setValue("MSK_ATTRIDS", $tattrid);
86  $this->setValue("MSK_VISIBILITIES", $tvis);
87  $err = $this->modify();
88  return $err;
89  }
90 
91  function getVisibilities()
92  {
93  $tvisid = $this->getTValue("MSK_VISIBILITIES");
94  $tattrid = $this->getTValue("MSK_ATTRIDS");
95 
96  $tvisibilities = array();
97  while (list($k, $v) = each($tattrid)) {
98  $tvisibilities[$v] = $tvisid[$k];
99  }
100  return $tvisibilities;
101  }
102 
103  function getCVisibilities()
104  {
105  $tvisid = $this->getTValue("MSK_VISIBILITIES");
106  $tattrid = $this->getTValue("MSK_ATTRIDS");
107  $docid = $this->getValue("MSK_FAMID", 1);
108  $doc = new_Doc($this->dbaccess, $docid);
109 
110  $tsvis = $this->getVisibilities();
111  $tvisibilities = array();
112 
113  foreach ($tattrid as $k => $v) {
114  $attr = $doc->getAttribute($v);
115  $fvisid = $attr->fieldSet->id;
116  if ($tvisid[$k] == "-") $vis = $attr->visibility;
117  else $vis = $tvisid[$k];
118 
119  $tvisibilities[$v] = ComputeVisibility($vis, $tvisibilities[$fvisid]);
120  }
121  return $tvisibilities;
122  }
123  function getNeedeeds()
124  {
125  $tvisid = $this->getTValue("MSK_NEEDEEDS");
126  $tattrid = $this->getTValue("MSK_ATTRIDS");
127 
128  $tvisibilities = array();
129  while (list($k, $v) = each($tattrid)) {
130  $tvisibilities[$v] = $tvisid[$k];
131  }
132  return $tvisibilities;
133  }
134 
135  function viewmask($target = "_self", $ulink = true, $abstract = false)
136  {
137 
138  $docid = $this->getValue("MSK_FAMID", 1);
139 
140  $tvisibilities = $this->getCVisibilities();
141  $tkey_visibilities = array_keys($tvisibilities);
142  $tinitvisibilities = $tvisibilities;
143 
144  $tneedeeds = $this->getNeedeeds();
145 
146  $this->lay->Set("docid", $docid);
147 
148  $doc = new_Doc($this->dbaccess, $docid);
149  $doc->applyMask();
150  $origattr = $doc->attributes->attr;
151 
152  $tmpdoc = createTmpDoc($this->dbaccess, $docid);
153  $tmpdoc->applyMask($this->id);
154  // display current values
155  $tmask = array();
156 
157  $labelvis = $this->getLabelVis();
158 
159  uasort($tmpdoc->attributes->attr, "tordered");
160 
161  foreach ($tmpdoc->attributes->attr as $k => $attr) {
162  if (!$attr->visibility) continue;
163  if ($attr->usefor == 'Q') continue;
164  $tmask[$k]["attrname"] = $attr->getLabel();
165  $tmask[$k]["type"] = $attr->type;
166  $tmask[$k]["visibility"] = $labelvis[$attr->visibility];
167  $tmask[$k]["wneed"] = ($origattr[$k]->needed) ? "bold" : "normal";
168  $tmask[$k]["bgcolor"] = "inherits";
169  $tmask[$k]["mvisibility"] = $labelvis[$attr->mvisibility];
170  $tmask[$k]["classtype"] = strtok($attr->type, '(');
171 
172  if (in_array($k, $tkey_visibilities)) {
173  $tmask[$k]["classtype"].= " directmodified";
174  } elseif ($tmask[$k]["visibility"] != $tmask[$k]["mvisibility"]) {
175  if ($tmask[$k]["mvisibility"] != $labelvis[$origattr[$k]->mvisibility]) $tmask[$k]["classtype"].= " inheritmodified";
176  }
177 
178  if (isset($tneedeeds[$attr->id])) {
179  if (($tneedeeds[$attr->id] == "Y") || (($tneedeeds[$attr->id] == "-") && ($attr->needed))) $tmask[$k]["waneed"] = "bold";
180  else $tmask[$k]["waneed"] = "normal";
181  if ($tneedeeds[$attr->id] != "-") $tmask[$k]["bgcolor"] = getParam("CORE_BGCOLORALTERN");
182  } else $tmask[$k]["waneed"] = $tmask[$k]["wneed"];
183 
184  if ($tmask[$k]["wneed"] != $tmask[$k]["waneed"]) {
185  $tmask[$k]["bgcolor"] = getParam("COLOR_B5");
186  }
187 
188  if ($attr->fieldSet && $attr->fieldSet->id && $attr->fieldSet->id != "FIELD_HIDDENS") $tmask[$k]["framelabel"] = $attr->fieldSet->getLabel();
189  else $tmask[$k]["framelabel"] = "";
190  if ($attr->waction != "") $tmask[$k]["framelabel"] = _("Action");
191 
192  $tmask[$k]["displayorder"] = ($attr->ordered) ? $attr->ordered : -2;
193  if ($attr->type == "menu" || $attr->type == "action") $tmask[$k]["displayorder"]+= 1000000; // at then end
194  if (($attr->ordered > 0) && $attr->fieldSet->id && $attr->fieldSet->ordered < - 1) {
195  $attr->fieldSet->ordered = $attr->ordered - 1;
196  $tmask[$attr->fieldSet->id]["displayorder"] = $attr->ordered - 1;
197  if ($attr->fieldSet->fieldSet && $attr->fieldSet->fieldSet->id) {
198  if ($attr->fieldSet->fieldSet->ordered < - 1) {
199  $attr->fieldSet->fieldSet->ordered = $attr->fieldSet->ordered - 1;
200  $tmask[$attr->fieldSet->fieldSet->id]["displayorder"] = $attr->fieldSet->ordered - 1;
201  }
202  }
203  }
204  }
205  unset($tmask["FIELD_HIDDENS"]);
206  uasort($tmask, array(
207  get_class($this) ,
208  'sortnewelem'
209  ));
210  $this->lay->SetBlockData("MASK", $tmask);
211  }
212 
213  function editmask()
214  {
215  global $action;
216 
217  $docid = $this->getValue("MSK_FAMID");
218 
219  $this->lay->Set("docid", $docid);
220 
221  $doc = new_Doc($this->dbaccess, $docid);
222 
223  $tvisibilities = $this->getVisibilities();
224  $tneedeeds = $this->getNeedeeds();
225 
226  if ($docid == 0) {
227  // only choose family in creation
228  $selectclass = array();
229  $tclassdoc = GetClassesDoc($this->dbaccess, $this->userid, 0, "TABLE");
230  foreach ($tclassdoc as $k => $cdoc) {
231  $selectclass[$k]["idcdoc"] = $cdoc["id"];
232  $selectclass[$k]["classname"] = $cdoc["title"];
233  $selectclass[$k]["selected"] = "";
234  }
235 
236  $this->lay->SetBlockData("SELECTCLASS", $selectclass);
237  }
238  // display current values
239  $newelem = array();
240  $this->lay->set("creation", ($docid == 0));
241  $this->lay->set("family", $doc->getTitle());
242 
243  if ($docid > 0) {
244  $ka = 0; // index attribute
245  $labelvis = $this->getLabelVis();
246  while (list($k, $v) = each($labelvis)) {
247  $selectvis[] = array(
248  "visid" => $k,
249  "vislabel" => $v
250  );
251  }
252  $labelneed = $this->getLabelNeed();
253  while (list($k, $v) = each($labelneed)) {
254  $selectneed[] = array(
255  "needid" => $k,
256  "needlabel" => $v
257  );
258  }
259  // ------------------------------------------
260  // -------------------- NORMAL ----------------------
261  $tattr = $doc->getAttributes();
262  uasort($tattr, "tordered");
263  foreach ($tattr as $k => $attr) {
264  if ($attr->usefor == "Q") continue; // not parameters
265  if ($attr->docid == 0) continue; // not parameters
266  $newelem[$k]["attrid"] = $attr->id;
267  $newelem[$k]["attrname"] = $attr->getLabel();
268  $newelem[$k]["type"] = strtok($attr->type, '(');
269  $newelem[$k]["visibility"] = $labelvis[$attr->visibility];
270 
271  $newelem[$k]["wneed"] = ($attr->needed) ? "bold" : "normal";
272  $newelem[$k]["neweltid"] = $k;
273  $newelem[$k]["attrinfo"] = $attr->id;
274  if ($attr->fieldSet->id && $attr->fieldSet->id != 'FIELD_HIDDENS') {
275  $newelem[$k]["attrinfo"].= '/' . $attr->fieldSet->id;
276  if ($attr->fieldSet->fieldSet->id && $attr->fieldSet->fieldSet->id != 'FIELD_HIDDENS') $newelem[$k]["attrinfo"].= '/' . $attr->fieldSet->fieldSet->id;
277  }
278 
279  if (($attr->type == "array") || (strtolower(get_class($attr)) == "fieldsetattribute")) $newelem[$k]["fieldweight"] = "bold";
280  else $newelem[$k]["fieldweight"] = "";
281 
282  if ($attr->docid == $docid) {
283  $newelem[$k]["disabled"] = "";
284  } else {
285  $newelem[$k]["disabled"] = "disabled";
286  }
287 
288  if ($attr->fieldSet->docid > 0) $newelem[$k]["framelabel"] = $attr->fieldSet->getLabel();
289  else $newelem[$k]["framelabel"] = "";
290  if ($attr->waction != "") $newelem[$k]["framelabel"] = _("Action");
291 
292  reset($selectvis);
293  while (list($kopt, $opt) = each($selectvis)) {
294  if ($opt["visid"] == $tvisibilities[$attr->id]) {
295  $selectvis[$kopt]["selected"] = "selected";
296  } else {
297  $selectvis[$kopt]["selected"] = "";
298  }
299  }
300  // idem for needed
301  reset($selectneed);
302  while (list($kopt, $opt) = each($selectneed)) {
303  if ($opt["needid"] == $tneedeeds[$attr->id]) {
304  $selectneed[$kopt]["selectedneed"] = "selected";
305  } else {
306  $selectneed[$kopt]["selectedneed"] = "";
307  }
308  }
309  $newelem[$k]["displayorder"] = ($attr->ordered) ? $attr->ordered : -2;
310  if ($attr->type == "menu" || $attr->type == "action") $newelem[$k]["displayorder"]+= 1000000; // at then end
311  if (($attr->ordered > 0) && $attr->fieldSet->id && $attr->fieldSet->ordered < - 1) {
312  $attr->fieldSet->ordered = $attr->ordered - 1;
313  $newelem[$attr->fieldSet->id]["displayorder"] = $attr->ordered - 1;
314  if ($attr->fieldSet->fieldSet && $attr->fieldSet->fieldSet->id) {
315  if ($attr->fieldSet->fieldSet->ordered < - 1) {
316  $attr->fieldSet->fieldSet->ordered = $attr->fieldSet->ordered - 1;
317  $newelem[$attr->fieldSet->fieldSet->id]["displayorder"] = $attr->fieldSet->ordered - 1;
318  }
319  }
320  }
321  $newelem[$k]["SELECTVIS"] = "SELECTVIS_$k";
322  $this->lay->SetBlockData($newelem[$k]["SELECTVIS"], $selectvis);
323  $newelem[$k]["SELECTNEED"] = "SELECTNEED_$k";
324  $this->lay->SetBlockData($newelem[$k]["SELECTNEED"], $selectneed);
325 
326  $ka++;
327  }
328  unset($newelem["FIELD_HIDDENS"]);
329  uasort($newelem, array(
330  get_class($this) ,
331  'sortnewelem'
332  ));
333  $this->lay->SetBlockData("NEWELEM", $newelem);
334  }
335  $this->editattr();
336  }
337  /**
338  * use to usort attributes
339  * @param BasicAttribute $a
340  * @param BasicAttribute $b
341  */
342  static function sortnewelem($a, $b)
343  {
344  if (isset($a["displayorder"]) && isset($b["displayorder"])) {
345  if ($a["displayorder"] == $b["displayorder"]) return 0;
346  if ($a["displayorder"] > $b["displayorder"]) return 1;
347  return -1;
348  }
349  if (isset($a["displayorder"])) return 1;
350  if (isset($b["displayorder"])) return -1;
351  return 0;
352  }
353  /**
354  * @begin-method-ignore
355  * this part will be deleted when construct document class until end-method-ignore
356  */
357 }
358 /*
359  * @end-method-ignore
360 */
361 ?>
← centre documentaire © anakeen - published under CC License - Dynacase