Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Mask.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Mask document
8  *
9  */
10 namespace Dcp\Core;
11 use \Dcp\AttributeIdentifiers\Mask as myAttr;
12 class Mask extends \Dcp\Family\Base
13 {
14 
15  var $defaultedit = "FREEDOM:EDITMASK";
16  var $defaultview = "FREEDOM:VIEWMASK";
17 
18  function getLabelVis()
19  {
20  return array(
21  "-" => " ",
22  "R" => _("read only") ,
23  "W" => _("read write") ,
24  "O" => _("write only") ,
25  "H" => _("hidden") ,
26  "S" => _("read disabled") ,
27  "U" => _("static array") ,
28  "I" => _("invisible")
29  );
30  }
31  function getLabelNeed()
32  {
33  return array(
34  "-" => " ",
35  "Y" => _("Y") ,
36  "N" => _("N")
37  );
38  }
39  /**
40  * suppress unmodified attributes visibilities
41  * to simplify the mask structure
42  */
43  function postStore()
44  {
45  $tneed = $this->getMultipleRawValues("MSK_NEEDEEDS");
46  $tattrid = $this->getMultipleRawValues("MSK_ATTRIDS");
47  $tvis = $this->getMultipleRawValues("MSK_VISIBILITIES");
48 
49  foreach ($tattrid as $k => $v) {
50  if (($tneed[$k] === '-') && ($tvis[$k] === '-') || ($tneed[$k] === '') && ($tvis[$k] === '-')) {
51  unset($tneed[$k]);
52  unset($tvis[$k]);
53  unset($tattrid[$k]);
54  }
55  }
56  $this->setValue("MSK_NEEDEEDS", $tneed);
57  $this->setValue("MSK_ATTRIDS", $tattrid);
58  $this->setValue("MSK_VISIBILITIES", $tvis);
59 
60  return '';
61  }
62 
63  public function preImport(array $extra = array())
64  {
65  return $this->verifyIntegraty();
66  }
67  public function preRefresh()
68  {
69  return $this->verifyIntegraty();
70  }
71  /**
72  * Verify if family and attributes are coherents
73  * @return string error message
74  */
75  protected function verifyIntegraty()
76  {
77  $mskAttrids = $this->getMultipleRawValues(myAttr::msk_attrids);
78  $famid = $this->getRawValue(myAttr::msk_famid);
79  if (!$famid) {
80  return \ErrorCode::getError("MSK0001", $this->name);
81  }
82  $fam = new_doc($this->dbaccess, $famid);
83  if ($fam->doctype !== "C") {
84  return \ErrorCode::getError("MSK0002", $famid, $this->name);
85  }
86  $attributes = $fam->getAttributes();
87  $attrids = [];
88  foreach ($attributes as $attribute) {
89  if ($attribute->usefor !== "Q") {
90  $attrids[] = $attribute->id;
91  }
92  }
93  foreach ($mskAttrids as $mAttrid) {
94  if ($mAttrid && !in_array($mAttrid, $attrids)) {
95 
96  return \ErrorCode::getError("MSK0003", $mAttrid, $fam->name, $this->name);
97  }
98  }
99  return "";
100  }
101 
102  function getVisibilities()
103  {
104  $tvisid = $this->getMultipleRawValues("MSK_VISIBILITIES");
105  $tattrid = $this->getMultipleRawValues("MSK_ATTRIDS");
106 
107  $tvisibilities = array();
108  foreach ($tattrid as $k => $v) {
109  if ($tvisid[$k] !== "-") {
110  $tvisibilities[$v] = $tvisid[$k];
111  }
112  }
113  return $tvisibilities;
114  }
115 
116  function getNeedeeds()
117  {
118  $tvisid = $this->getMultipleRawValues("MSK_NEEDEEDS");
119  $tattrid = $this->getMultipleRawValues("MSK_ATTRIDS");
120 
121  $tvisibilities = array();
122  foreach ($tattrid as $k => $v) {
123  $tvisibilities[$v] = $tvisid[$k];
124  }
125  return $tvisibilities;
126  }
127  /**
128  * @templateController view attributes differences
129  * @param string $target
130  * @param bool $ulink
131  * @param bool $abstract
132  */
133  function viewmask($target = "_self", $ulink = true, $abstract = false)
134  {
135 
136  $docid = $this->getRawValue("MSK_FAMID", 1);
137 
138  $tvisibilities = $this->getVisibilities();
139  $tkey_visibilities = array_keys($tvisibilities);
140 
141  $tneedeeds = $this->getNeedeeds();
142 
143  $this->lay->Set("docid", $docid);
144 
145  $doc = new_Doc($this->dbaccess, $docid);
146  if (!$doc->isAlive()) {
147  addWarningMsg(sprintf("Family %s not found", $docid));
148  return;
149  }
150  $doc->applyMask();
151  $origattr = $doc->attributes->attr;
152 
153  $tmpdoc = createTmpDoc($this->dbaccess, $docid);
154  $tmpdoc->applyMask($this->id);
155  // display current values
156  $tmask = array();
157 
158  $labelvis = $this->getLabelVis();
159  $tmpdoc->attributes->orderAttributes();
160 
161  foreach ($tmpdoc->attributes->attr as $k => $attr) {
162  /**
163  * @var $attr \NormalAttribute|\ActionAttribute
164  */
165  if (!$attr->visibility) continue;
166  if ($attr->usefor == 'Q') continue;
167  $tmask[$k]["attrname"] = $attr->getLabel();
168  $tmask[$k]["type"] = $attr->type;
169  $tmask[$k]["attrid"] = $attr->id;
170  $tmask[$k]["visibility"] = $labelvis[$attr->visibility];
171  $tmask[$k]["wneed"] = (!empty($origattr[$k]->needed)) ? ___("mandatory", "mask") : ___("optional", "mask");
172  $tmask[$k]["bgcolor"] = "inherits";
173  $tmask[$k]["isNeed"] = (!empty($origattr[$k]->needed));
174  $tmask[$k]["mvisibility"] = $labelvis[$attr->mvisibility];
175  $tmask[$k]["classtype"] = strtok($attr->type, '(');
176 
177  if (in_array($k, $tkey_visibilities)) {
178  $tmask[$k]["classtype"].= " directmodified";
179  } elseif ($tmask[$k]["visibility"] != $tmask[$k]["mvisibility"]) {
180  if ($tmask[$k]["mvisibility"] != $labelvis[$origattr[$k]->mvisibility]) $tmask[$k]["classtype"].= " inheritmodified";
181  } else {
182  $tmask[$k]["classtype"].= " notmodified";
183  }
184  $tmask[$k]["isAneed"] = $tmask[$k]["isNeed"];
185  if (isset($tneedeeds[$attr->id])) {
186  if (($tneedeeds[$attr->id] == "Y") || (($tneedeeds[$attr->id] == "-") && (!empty($attr->needed)))) {
187  $tmask[$k]["waneed"] = ___("mandatory", "mask");
188  $tmask[$k]["isAneed"] = true;
189  } else {
190  $tmask[$k]["waneed"] = ___("optional", "mask");
191  $tmask[$k]["isAneed"] = false;
192  }
193  } else {
194  $tmask[$k]["waneed"] = $tmask[$k]["wneed"];
195  }
196 
197  if (in_array($attr->type, array(
198  "frame",
199  "tab",
200  "menu",
201  "action",
202  "array"
203  ))) {
204  $tmask[$k]["waneed"] = $tmask[$k]["wneed"] = '';
205  }
206 
207  if ($tmask[$k]["wneed"] != $tmask[$k]["waneed"]) {
208  $tmask[$k]["classtype"].= " needmodified";
209  }
210 
211  if ($attr->fieldSet && $attr->fieldSet->id && $attr->fieldSet->id != \Adoc::HIDDENFIELD) $tmask[$k]["framelabel"] = $attr->fieldSet->getLabel();
212  else $tmask[$k]["framelabel"] = "";
213  if (!empty($attr->waction)) $tmask[$k]["framelabel"] = _("Action");
214 
215  $tmask[$k]["displayorder"] = ($attr->ordered) ? $attr->ordered : -2;
216  if ($attr->type == "menu" || $attr->type == "action") $tmask[$k]["displayorder"]+= 1000000; // at then end
217  if (($attr->ordered > 0) && $attr->fieldSet && $attr->fieldSet->id && $attr->fieldSet->ordered < - 1) {
218  $attr->fieldSet->ordered = $attr->ordered - 1;
219  $tmask[$attr->fieldSet->id]["displayorder"] = $attr->ordered - 1;
220  if ($attr->fieldSet->fieldSet && $attr->fieldSet->fieldSet->id) {
221  if ($attr->fieldSet->fieldSet->ordered < - 1) {
222  $attr->fieldSet->fieldSet->ordered = $attr->fieldSet->ordered - 1;
223  $tmask[$attr->fieldSet->fieldSet->id]["displayorder"] = $attr->fieldSet->ordered - 1;
224  }
225  }
226  }
227  }
228  unset($tmask[\Adoc::HIDDENFIELD]);
229  uasort($tmask, array(
230  get_class($this) ,
231  'sortnewelem'
232  ));
233  $this->lay->SetBlockData("MASK", $tmask);
234  }
235  /**
236  * @templateController special edition for mask
237  */
238  function editmask()
239  {
240 
241  $docid = $this->getRawValue("MSK_FAMID");
242 
243  $this->lay->Set("docid", $docid);
244  /**
245  * @var \DocFam $family
246  */
247  $family = new_Doc($this->dbaccess, $docid);
248 
249  $tvisibilities = $this->getVisibilities();
250  $tneedeeds = $this->getNeedeeds();
251 
252  if ($docid == 0) {
253  // only choose family in creation
254  $selectclass = array();
255  $tclassdoc = GetClassesDoc($this->dbaccess, $this->userid, 0, "TABLE");
256  foreach ($tclassdoc as $k => $cdoc) {
257  $selectclass[$k]["idcdoc"] = $cdoc["id"];
258  $selectclass[$k]["classname"] = $cdoc["title"];
259  $selectclass[$k]["selected"] = "";
260  }
261 
262  $this->lay->SetBlockData("SELECTCLASS", $selectclass);
263  }
264  // display current values
265  $newelem = array();
266  $this->lay->set("creation", ($docid == 0));
267  $this->lay->set("family", $family->getTitle());
268 
269  if ($docid > 0) {
270  $ka = 0; // index attribute
271  $labelvis = $this->getLabelVis();
272  foreach ($labelvis as $k => $v) {
273  $selectvis[] = array(
274  "visid" => $k,
275  "vislabel" => $v
276  );
277  }
278  $labelneed = $this->getLabelNeed();
279  foreach ($labelneed as $k => $v) {
280  $selectneed[] = array(
281  "needid" => $k,
282  "needlabel" => $v
283  );
284  }
285  // ------------------------------------------
286  // -------------------- NORMAL ----------------------
287  $tattr = $family->getAttributes();
288 
289  foreach ($tattr as $k => $attr) {
290  /**
291  * @var $attr \NormalAttribute|\FieldSetAttribute|\ActionAttribute
292  */
293  if ($attr->usefor == "Q") continue; // not parameters
294  if ($attr->docid == 0) continue; // not parameters
295  $newelem[$k]["attrid"] = $attr->id;
296  $newelem[$k]["attrname"] = $attr->getLabel();
297  $newelem[$k]["type"] = strtok($attr->type, '(');
298  $newelem[$k]["visibility"] = $labelvis[$attr->visibility];
299 
300  $newelem[$k]["wneed"] = (!empty($attr->needed)) ? ___("mandatory", "mask") : ___("optional", "mask");
301  $newelem[$k]["isNeed"] = (!empty($attr->needed));
302  $newelem[$k]["neweltid"] = $k;
303  $newelem[$k]["attrinfo"] = $attr->id;
304  $newelem[$k]["useNeed"] = (!in_array($attr->type, array(
305  "frame",
306  "tab",
307  "menu",
308  "action",
309  "array"
310  )));
311 
312  if ($attr->fieldSet && $attr->fieldSet->id && $attr->fieldSet->id != \Adoc::HIDDENFIELD) {
313  $newelem[$k]["attrinfo"].= '/' . $attr->fieldSet->id;
314  if ($attr->fieldSet->fieldSet->id && $attr->fieldSet->fieldSet->id != \Adoc::HIDDENFIELD) $newelem[$k]["attrinfo"].= '/' . $attr->fieldSet->fieldSet->id;
315  }
316 
317  if (($attr->type == "array") || (strtolower(get_class($attr)) == "fieldsetattribute")) $newelem[$k]["fieldweight"] = "bold";
318  else $newelem[$k]["fieldweight"] = "";
319 
320  if ($attr->docid == $docid) {
321  $newelem[$k]["disabled"] = "";
322  } else {
323  $newelem[$k]["disabled"] = "disabled";
324  }
325 
326  if ($attr->fieldSet && $attr->fieldSet->docid > 0) $newelem[$k]["framelabel"] = $attr->fieldSet->getLabel();
327  else $newelem[$k]["framelabel"] = "";
328  if (!empty($attr->waction)) $newelem[$k]["framelabel"] = _("Action");
329 
330  reset($selectvis);
331  foreach ($selectvis as $kopt => $opt) {
332  if (isset($tvisibilities[$attr->id]) && $opt["visid"] == $tvisibilities[$attr->id]) {
333  $selectvis[$kopt]["selected"] = "selected";
334  } else {
335  $selectvis[$kopt]["selected"] = "";
336  }
337  }
338  // idem for needed
339  reset($selectneed);
340  foreach ($selectneed as $kopt => $opt) {
341  if (isset($tneedeeds[$attr->id]) && $opt["needid"] == $tneedeeds[$attr->id]) {
342  $selectneed[$kopt]["selectedneed"] = "selected";
343  } else {
344  $selectneed[$kopt]["selectedneed"] = "";
345  }
346  }
347  $newelem[$k]["displayorder"] = ($attr->ordered) ? $attr->ordered : -2;
348  if ($attr->type == "menu" || $attr->type == "action") $newelem[$k]["displayorder"]+= 1000000; // at then end
349  if (($attr->ordered > 0) && $attr->fieldSet && $attr->fieldSet->id && $attr->fieldSet->ordered < - 1) {
350  $attr->fieldSet->ordered = $attr->ordered - 1;
351  $newelem[$attr->fieldSet->id]["displayorder"] = $attr->ordered - 1;
352  if ($attr->fieldSet->fieldSet && $attr->fieldSet->fieldSet->id) {
353  if ($attr->fieldSet->fieldSet->ordered < - 1) {
354  $attr->fieldSet->fieldSet->ordered = $attr->fieldSet->ordered - 1;
355  $newelem[$attr->fieldSet->fieldSet->id]["displayorder"] = $attr->fieldSet->ordered - 1;
356  }
357  }
358  }
359  $newelem[$k]["SELECTVIS"] = "SELECTVIS_$k";
360  $this->lay->SetBlockData($newelem[$k]["SELECTVIS"], $selectvis);
361  $newelem[$k]["SELECTNEED"] = "SELECTNEED_$k";
362  $this->lay->SetBlockData($newelem[$k]["SELECTNEED"], $selectneed);
363 
364  $ka++;
365  }
366  unset($newelem[\Adoc::HIDDENFIELD]);
367  uasort($newelem, array(
368  get_class($this) ,
369  'sortnewelem'
370  ));
371  $this->lay->SetBlockData("NEWELEM", $newelem);
372  }
373  $this->editattr(false);
374  }
375  /**
376  * use to usort attributes
377  * @param \BasicAttribute $a
378  * @param \BasicAttribute $b
379  * @return int
380  */
381  static function sortnewelem($a, $b)
382  {
383  if (isset($a["displayorder"]) && isset($b["displayorder"])) {
384  if ($a["displayorder"] == $b["displayorder"]) return 0;
385  if ($a["displayorder"] > $b["displayorder"]) return 1;
386  return -1;
387  }
388  if (isset($a["displayorder"])) return 1;
389  if (isset($b["displayorder"])) return -1;
390  return 0;
391  }
392 }
$attributes
Definition: Class.Doc.php:583
if($_POST["login"]=="")
Definition: chgpasswd.php:19
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
print $fam getTitle() $fam name
$attribute
addWarningMsg($msg)
Definition: Lib.Common.php:95
if(!function_exists('pgettext')) ___($message, $context="")
Definition: Lib.Common.php:46
preImport(array $extra=array())
Definition: Class.Mask.php:63
$attrids
Definition: Class.Doc.php:551
editattr($withtd=true)
Definition: Class.Doc.php:8129
$docid
Definition: cleanFamily.php:13
GetClassesDoc($dbaccess, $userid, $classid=0, $qtype="LIST", $extraFilters=array())
Definition: Lib.Dir.php:906
setValue($attrid, $value, $index=-1, &$kvalue=null)
Definition: Class.Doc.php:3528
getMultipleRawValues($idAttr, $def="", $index=-1)
Definition: Class.Doc.php:3240
static sortnewelem($a, $b)
Definition: Class.Mask.php:381
new_Doc($dbaccess, $id= '', $latest=false)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
← centre documentaire © anakeen