Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
modonedefaultvalue.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 include_once ("FDL/Class.Doc.php");
8 include_once ("FDL/editutil.php");
10 {
11  $usage = new ActionUsage($action);
12 
13  $famid = $usage->addRequiredParameter("famid", "Family identifier", function ($value)
14  {
15  $family = new_doc("", $value);
16  if ($family->doctype !== "C") {
17  return "Must be a family identifier";
18  }
19  return '';
20  });
21  /*
22  * @var DocFam $family
23  */
24  $family = new_doc("", $famid);
25  $attrid = $usage->addRequiredParameter("attrid", "Attribute identifier", function ($value) use ($family)
26  {
27  $oa = $family->getAttribute($value);
28  if (!$oa) {
29  return sprintf("Attribute \"%s\" not found in family \"%s\"", $value, $family->name);
30  }
31  return '';
32  });
33  $value = $usage->addOptionalParameter("value", "New default value");
34  $err = '';
35  $oa = null;
36  try {
37  $usage->verify(true);
38  }
39  catch(Dcp\ApiUsage\Exception $e) {
40  $err = $e->getDcpMessage();
41  }
42 
43  if (!$err) {
44  $err = $family->control("edit");
45  if ($err) {
46  $action->exitError($err);
47  }
48 
49  $oa = $family->getAttribute($attrid);
50 
51  if ($oa->type === "file" || $oa->type === "image") {
52  if (isset($_FILES["defaultFile"])) {
53  $file = $_FILES["defaultFile"];
54  if ($file["error"] === 0) {
55  $vid = \Dcp\VaultManager::storeFile($file["tmp_name"], $file["name"]);
56  $value = sprintf("%s|%s|%s", $file["type"], $vid, $file["name"]);
57  } else {
58  $err = sprintf("Error file transfer : [code %s]", $file["error"]);
59  }
60  }
61  }
62 
63  if (!$err) {
64  $err = $family->setDefValue($oa->id, $value);
65 
66  if (!$err) {
67  $err = $family->modify();
68  }
69  }
70  }
71  if ($err) {
72  $out = array(
73  "success" => false,
74  "error" => $err
75  );
76  header('HTTP/1.0 400 Error');
77  } else {
78  $defval = $family->getDefValue($oa->id);
79  $out = array(
80  "success" => true,
81  "message" => ($defval === "") ? sprintf(_("Default value erased")) : sprintf(_("Default value recorded")) ,
82  "value" => $family->getDefValue($oa->id)
83  );
84  }
85  header('Content-Type: application/json');
86  $action->lay->template = json_encode($out);
87  $action->lay->noparse = true;
88 }
global $action
modonedefaultvalue(Action $action)
$file
exitError($texterr, $exit=true, $code="")
Verify arguments for action function.
if($file) if($subject==""&&$file) if($subject=="") $err
static storeFile($filepath, $ftitle="", $public_access=false)
$usage
$value
Verify arguments for wsh programs.
← centre documentaire © anakeen