Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_edit.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Display edition interface
8  *
9  * @author Anakeen
10  * @version $Id: generic_edit.php,v 1.75 2009/01/04 18:35:53 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
18 
19 include_once ("FDL/family_help.php");
20 include_once ("Class.QueryDb.php");
21 include_once ("GENERIC/generic_util.php");
22 /**
23  * Edit a document
24  * @param Action &$action current action
25  * @global id string Http var : document identifier to see
26  * @global zone string Http var : if set, special edit with special zone
27  * @global rzone string Http var : if set, to return view with special zone
28  * @global rtarget string Http var : if set, to return result in another window (the window will be closed)
29  * @global vid string Http var : if set, edit represention describe in view control (can be use only if doc has controlled view)
30  * @global mskid string Http var : is set special mask applied for edition
31  * @global autoclose string Http var : set to yes to close window after modification
32  */
34 {
35  // -----------------------------------
36  // Get All Parameters
37  $docid = trim($action->getArgument("id", 0)); // document to edit
38  $classid = $action->getArgument("classid", getDefFam($action)); // use when new doc or change class
39  $dirid = $action->getArgument("dirid", 0); // directory to place doc if new doc
40  $usefor = $action->getArgument("usefor"); // default values for a document
41  $zonebodycard = $action->getArgument("zone"); // define view action
42  $rzone = $action->getArgument("rzone"); // special zone when finish edition
43  $rvid = $action->getArgument("rvid"); // special zone when finish edition
44  $rtarget = $action->getArgument("rtarget", "_self"); // special zone when finish edition return target
45  $updateAttrid = $action->getArgument("updateAttrid");
46  if ($docid == 0) setHttpVar("classid", $classid);
47  $vid = $action->getArgument("vid"); // special controlled view
48  $mskid = $action->getArgument("mskid"); // special mask
49  $autoclose = $action->getArgument("autoclose"); // to close window after modification
50  $recallhelper = $action->getArgument("recallhelper"); // to recall helper input
51  $action->lay->eSet("vid", $vid);
52  $action->lay->eSet("ezone", $zonebodycard); // use for return in case of constraint
53  $action->lay->eSet("rzone", $rzone);
54  $action->lay->eSet("rvid", $rvid);
55  $action->lay->eSet("rtarget", $rtarget);
56  $action->lay->eSet("autoclose", $autoclose);
57  $action->lay->eSet("recallhelper", $recallhelper);
58  $action->lay->eSet("updateAttrid", $updateAttrid);
59  $action->lay->Set("SELFTARGET", ($rtarget == "_self"));
60  // Set the globals elements
61  $dbaccess = $action->dbaccess;
62 
63  if (($docid === 0) || ($docid === "") || ($docid === "0")) {
64  if ($classid == "") $action->exitError(sprintf(_("Creation aborded : no family specified")));
65  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
66  if ($classid == "") $action->exitError(sprintf(_("Creation aborded : unknow family %s") , GetHttpVars("classid", getDefFam($action))));
67  if ($classid > 0) {
68  $cdoc = new_Doc($dbaccess, $classid);
69  $errc = $cdoc->control('create');
70  $erric = $cdoc->control('icreate');
71  if ($errc || $erric) {
72  redirectAsGuest($action);
73  }
74  if ($errc != "") $action->exitError(sprintf(_("no privilege to create this kind (%s) of document") , $cdoc->gettitle()));
75  if ($erric != "") $action->exitError(sprintf(_("no privilege to create interactivaly this kind (%s) of document") , $cdoc->gettitle()));
76  $action->lay->Set("title", mb_convert_case(sprintf(_("creation %s") , $cdoc->getHTMLTitle()) , MB_CASE_TITLE, 'UTF-8'));
77  } else {
78  $action->lay->Set("title", _("new card"));
79  }
80  if ($usefor == "D") $action->lay->eSet("title", _("default values"));
81  if ($usefor == "Q") $action->lay->eSet("title", _("parameters values"));
82 
83  $action->lay->eSet("editaction", $action->text("Create"));
84  $doc = createDoc($dbaccess, $classid);
85  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
86  if ($usefor == 'D' || $usefor == 'Q') $doc->state = '';
87  if ($usefor != "") $doc->doctype = 'T';
88  } else {
89  $doc = new_Doc($dbaccess, $docid, true); // always latest revision
91  $docid = $doc->id;
92  setHttpVar("id", $doc->id);
93  $err = $doc->lock(true); // autolock
94  if ($err != "") {
95  redirectAsGuest($action);
96  $action->ExitError($err);
97  } else {
98  $action->AddActionDone("LOCKFILE", $doc->id);
99  }
100 
101  $classid = $doc->fromid;
102  if (!$doc->isAlive()) $action->ExitError(_("document not referenced"));
103  if (GetHttpVars("viewconstraint") != "Y") {
104  // $doc->refresh(); // set in editcard
105  // update access date
106  $doc->adate = $doc->getTimeDate();
107  $doc->modify(true, array(
108  "adate"
109  ) , true);
110  }
111 
112  $action->lay->Set("title", $doc->getHTMLtitle());
113  }
114 
115  if ($action->read("navigator") == "EXPLORER") $action->lay->Set("shorticon", getParam("DYNACASE_FAVICO"));
116  else $action->lay->Set("shorticon", $doc->getIcon());
117  $action->lay->Set("docicon", $doc->getIcon('', 16));
118  $param_zone_footer = json_decode($action->getParam("FOOTER_ZONE_EDIT") , true);
119  $zone_footer = array();
120  foreach ($param_zone_footer as $zone) {
121  $zone_footer[] = array(
122  "my_zone" => $zone
123  );
124  }
125  $action->lay->SetBlockData("ZONE_FOOTER", $zone_footer);
126 
127  if ($zonebodycard == "") {
128  if ($doc->cvid > 0) {
129  /*
130  * @var CVDoc $cvdoc
131  */
132  $cvdoc = new_Doc($dbaccess, $doc->cvid);
133  $cvdoc->set($doc);
134  if ($vid == "") {
135  // search preferred view
136  $vid = $doc->getDefaultView(true, "id");
137  if ($vid) setHttpVar("vid", $vid);
138  }
139 
140  if ($vid != "") {
141  // special controlled view
142  $err = $cvdoc->control($vid); // control special view
143  if ($err != "") $action->exitError($err);
144  $tview = $cvdoc->getView($vid);
145  $doc->setMask($tview["CV_MSKID"]);
146  if ($zonebodycard == "") $zonebodycard = $tview["CV_ZVIEW"];
147  }
148  }
149  }
150  if (($vid == "") && ($mskid != "")) {
151  $mdoc = new_Doc($dbaccess, $mskid);
152  if ($mdoc->isAlive() && ($mdoc->control('view') == "")) $doc->setMask($mdoc->id);
153  }
154 
155  if ($zonebodycard == "") {
156  if ((!$docid) && $doc->defaultcreate != "") $zonebodycard = $doc->defaultcreate;
157  else $zonebodycard = $doc->defaultedit;
158  }
159 
160  $action->lay->set("emblem", $doc->getEmblem());
161  $action->lay->Set("HEAD", (!preg_match("/[A-Z]+:[^:]+:[T|S|U|V]/", $zonebodycard, $reg)));
162  $action->lay->Set("FOOT", (!preg_match("/[A-Z]+:[^:]+:[S|U]/", $zonebodycard, $reg)));
163  $action->lay->Set("NOFORM", (preg_match("/[A-Z]+:[^:]+:U/", $zonebodycard, $reg)));
164  $action->lay->Set("NOSAVE", (preg_match("/[A-Z]+:[^:]+:V/", $zonebodycard, $reg)));
165  if (getHttpVars("forcehead") == "yes") $action->lay->Set("HEAD", true); // for freedom_edit
166  $action->lay->Set("iconsrc", $doc->geticon());
167  $action->lay->Set("viewstate", "none");
168  $action->lay->Set("dhelp", "none");
169  if (getFamilyHelpFile($action, $doc->fromid)) {
170  $action->lay->Set("dhelp", "");
171  $action->lay->Set("helpid", $doc->fromid);
172  }
173  $action->lay->Set("state", "");
174 
175  $state = $doc->getState();
176  $action->lay->Set("statecolor", $doc->getStateColor("transparent"));
177  $action->lay->Set("wid", false);
178  if ($doc->fromid > 0) {
179  $fdoc = $doc->getFamilyDocument();
180  $action->lay->Set("wid", ($fdoc->schar == 'R'));
181  $action->lay->eSet("FTITLE", $fdoc->gettitle());
182  } else {
183  $action->lay->eSet("FTITLE", _("no family"));
184  }
185  if ($state) { // see only if it is a transitionnal doc
186  if ($doc->locked == - 1) $action->lay->Set("state", $action->text($state));
187  else {
188 
189  $action->lay->eSet("state", $action->Text($doc->getStateActivity($doc->getState())));
190  }
191  $action->lay->Set("viewstate", "inherit");
192  $action->lay->Set("wid", ($doc->wid > 0) ? $doc->wid : $doc->state);
193  }
194  $action->lay->eSet("version", $doc->version);
195 
196  $action->lay->Set("initid", ($doc->initid != '') ? $doc->initid : 0);
197  $action->lay->eSet("id", $doc->id);
198 
199  $action->lay->set("VALTERN", ($action->GetParam("FDL_VIEWALTERN", "yes") == "yes"));
200  // information propagation
201  $action->lay->eSet("classid", $classid);
202  $action->lay->eSet("dirid", $dirid);
203  // Set help URL
204  $help = $doc->getHelpPage();
205  $action->lay->Set("helpurl", ($help->isAlive()) ? $help->getAttributeHelpUrl() : false);
206  $action->lay->Set("helpid", ($help->isAlive()) ? $help->id : false);
207 }
208 
209 function cmp_cvorder($a, $b)
210 {
211  if ($a["cv_order"] == $b["cv_order"]) {
212  return 0;
213  }
214  return ($a["cv_order"] < $b["cv_order"]) ? -1 : 1;
215 }
static text($code)
global $action
fixMultipleAliveDocument(Doc &$doc)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
redirectAsGuest(Action &$action)
Definition: Lib.Http.php:104
getDefFam(Action &$action)
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
cmp_cvorder($a, $b)
$docid
Definition: cleanFamily.php:13
getFamilyHelpFile(Action &$action, $docid)
Definition: family_help.php:34
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
getFamIdFromName($dbaccess, $name)
new_Doc($dbaccess, $id= '', $latest=false)
getParam($name, $def="")
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
generic_edit(Action &$action)
← centre documentaire © anakeen