Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Display edition interface
9  *
10  * @author Anakeen 2000
11  * @version $Id: generic_edit.php,v 1.75 2009/01/04 18:35:53 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 
21 include_once ("FDL/family_help.php");
22 include_once ("Class.QueryDb.php");
23 include_once ("GENERIC/generic_util.php");
24 /**
25  * Edit a document
26  * @param Action &$action current action
27  * @global id Http var : document identificator to see
28  * @global zone Http var : if set, special edit with special zone
29  * @global rzone Http var : if set, to return view with special zone
30  * @global rtarget Http var : if set, to return result in another window (the window will be closed)
31  * @global vid Http var : if set, edit represention describe in view control (can be use only if doc has controlled view)
32  * @global mskid Http var : is set special mask applied for edition
33  * @global autoclose Http var : set to yes to close window after modification
34  */
36 {
37  // -----------------------------------
38  // Get All Parameters
39  $docid = trim($action->getArgument("id", 0)); // document to edit
40  $classid = $action->getArgument("classid", getDefFam($action)); // use when new doc or change class
41  $dirid = $action->getArgument("dirid", 0); // directory to place doc if new doc
42  $usefor = $action->getArgument("usefor"); // default values for a document
43  $zonebodycard = $action->getArgument("zone"); // define view action
44  $rzone = $action->getArgument("rzone"); // special zone when finish edition
45  $rvid = $action->getArgument("rvid"); // special zone when finish edition
46  $rtarget = $action->getArgument("rtarget", "_self"); // special zone when finish edition return target
47  $updateAttrid = $action->getArgument("updateAttrid");
48  if ($docid == 0) setHttpVar("classid", $classid);
49  $vid = $action->getArgument("vid"); // special controlled view
50  $mskid = $action->getArgument("mskid"); // special mask
51  $autoclose = $action->getArgument("autoclose"); // to close window after modification
52  $recallhelper = $action->getArgument("recallhelper"); // to recall helper input
53  $action->lay->Set("vid", $vid);
54  $action->lay->Set("ezone", $zonebodycard); // use for return in case of constraint
55  $action->lay->Set("rzone", $rzone);
56  $action->lay->Set("rvid", $rvid);
57  $action->lay->Set("rtarget", $rtarget);
58  $action->lay->Set("autoclose", $autoclose);
59  $action->lay->Set("recallhelper", $recallhelper);
60  $action->lay->Set("updateAttrid", $updateAttrid);
61  $action->lay->Set("SELFTARGET", ($rtarget == "_self"));
62  // Set the globals elements
63  $dbaccess = $action->GetParam("FREEDOM_DB");
64 
65  if (($docid === 0) || ($docid === "") || ($docid === "0")) {
66  if ($classid == "") $action->exitError(sprintf(_("Creation aborded : no family specified")));
67  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
68  if ($classid == "") $action->exitError(sprintf(_("Creation aborded : unknow family %s") , GetHttpVars("classid", getDefFam($action))));
69  if ($classid > 0) {
70  $cdoc = new_Doc($dbaccess, $classid);
71  if ($cdoc->control('create') != "") $action->exitError(sprintf(_("no privilege to create this kind (%s) of document") , $cdoc->gettitle()));
72  if ($cdoc->control('icreate') != "") $action->exitError(sprintf(_("no privilege to create interactivaly this kind (%s) of document") , $cdoc->gettitle()));
73  $action->lay->Set("title", mb_convert_case(sprintf(_("creation %s") , $cdoc->getHTMLTitle()), MB_CASE_TITLE, 'UTF-8'));
74  } else {
75  $action->lay->Set("title", _("new card"));
76  }
77  if ($usefor == "D") $action->lay->Set("title", _("default values"));
78  if ($usefor == "Q") $action->lay->Set("title", _("parameters values"));
79 
80  $action->lay->Set("editaction", $action->text("Create"));
81  $doc = createDoc($dbaccess, $classid);
82  if ($usefor == 'D' || $usefor == 'Q') $doc->state = '';
83  if (!$doc) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
84  if ($usefor != "") $doc->doctype = 'T';
85  } else {
86  $doc = new_Doc($dbaccess, $docid, true); // always latest revision
87  $rev = getLatestRevisionNumber($dbaccess, $doc->initid, $doc->fromid);
88  if ($doc->revision != $rev) $action->ExitError(sprintf("document %d : multiple alive revision (%d <> %d)", $doc->initid, $doc->revision, $rev));
89  $docid = $doc->id;
90  setHttpVar("id", $doc->id);
91  $err = $doc->lock(true); // autolock
92  if ($err != "") $action->ExitError($err);
93  if ($err == "") $action->AddActionDone("LOCKFILE", $doc->id);
94 
95  $classid = $doc->fromid;
96  if (!$doc->isAlive()) $action->ExitError(_("document not referenced"));
97  if (GetHttpVars("viewconstraint") != "Y") {
98  // $doc->refresh(); // set in editcard
99  // update access date
100  $doc->adate = $doc->getTimeDate();
101  $doc->modify(true, array(
102  "adate"
103  ) , true);
104  }
105 
106  $action->lay->Set("title", $doc->getHTMLtitle());
107  }
108 
109  if ($action->read("navigator") == "EXPLORER") $action->lay->Set("shorticon", getParam("DYNACASE_FAVICO"));
110  else $action->lay->Set("shorticon", $doc->getIcon());
111  $action->lay->Set("docicon", $doc->getIcon('', 16));
112  $action->lay->Set("STITLE", addJsSlashes($action->lay->get("title"))); // for include in JS
113  if ($zonebodycard == "") {
114  if ($doc->cvid > 0) {
115  $cvdoc = new_Doc($dbaccess, $doc->cvid);
116  $cvdoc->set($doc);
117  if ($vid == "") {
118  // search preferred view
119  $vid = $doc->getDefaultView(true, "id");
120  if ($vid) setHttpVar("vid", $vid);
121  }
122 
123  if ($vid != "") {
124  // special controlled view
125  $err = $cvdoc->control($vid); // control special view
126  if ($err != "") $action->exitError($err);
127  $tview = $cvdoc->getView($vid);
128  $doc->setMask($tview["CV_MSKID"]);
129  if ($zonebodycard == "") $zonebodycard = $tview["CV_ZVIEW"];
130  }
131  }
132  }
133  if (($vid == "") && ($mskid != "")) {
134  $mdoc = new_Doc($dbaccess, $mskid);
135  if ($mdoc->isAlive() && ($mdoc->control('view') == "")) $doc->setMask($mdoc->id);
136  }
137 
138  if ($zonebodycard == "") {
139  if ((!$docid) && $doc->defaultcreate != "") $zonebodycard = $doc->defaultcreate;
140  else $zonebodycard = $doc->defaultedit;
141  }
142 
143  $action->lay->set("emblem", $doc->getEmblem());
144  $action->lay->Set("HEAD", (!preg_match("/[A-Z]+:[^:]+:[T|S|U|V]/", $zonebodycard, $reg)));
145  $action->lay->Set("FOOT", (!preg_match("/[A-Z]+:[^:]+:[S|U]/", $zonebodycard, $reg)));
146  $action->lay->Set("NOFORM", (preg_match("/[A-Z]+:[^:]+:U/", $zonebodycard, $reg)));
147  $action->lay->Set("NOSAVE", (preg_match("/[A-Z]+:[^:]+:V/", $zonebodycard, $reg)));
148  if (getHttpVars("forcehead") == "yes") $action->lay->Set("HEAD", true); // for freedom_edit
149  $action->lay->Set("iconsrc", $doc->geticon());
150  $action->lay->Set("viewstate", "none");
151  $action->lay->Set("dhelp", "none");
152  if (getFamilyHelpFile($action, $doc->fromid)) {
153  $action->lay->Set("dhelp", "");
154  $action->lay->Set("helpid", $doc->fromid);
155  }
156  $action->lay->Set("state", "");
157 
158  $state = $doc->getState();
159  $action->lay->Set("statecolor", $doc->getStateColor("transparent"));
160  $action->lay->Set("wid", false);
161  if ($doc->fromid > 0) {
162  $fdoc = $doc->getFamDoc();
163  $action->lay->Set("wid", ($fdoc->schar == 'R'));
164  $action->lay->Set("FTITLE", $fdoc->gettitle());
165  } else {
166  $action->lay->Set("FTITLE", _("no family"));
167  }
168  if ($state) { // see only if it is a transitionnal doc
169  if ($doc->locked == - 1) $action->lay->Set("state", $action->text($state));
170  else {
171  if ($doc->lmodify == 'Y') $stateaction = $doc->getStateActivity(_("current_state"));
172  else $stateaction = $doc->getStateActivity();
173  $action->lay->Set("state", sprintf("%s (<i>%s</i>)", $stateaction, $action->text($state)));
174  }
175  $action->lay->Set("viewstate", "inherit");
176  $action->lay->Set("wid", ($doc->wid > 0) ? $doc->wid : $doc->state);
177  }
178  $action->lay->Set("version", $doc->version);
179 
180  $action->lay->Set("initid", ($doc->initid != '') ? $doc->initid : 0);
181  $action->lay->Set("id", $docid);
182  $action->lay->Set("dirid", $dirid);
183 
184  $action->lay->set("VALTERN", ($action->GetParam("FDL_VIEWALTERN", "yes") == "yes"));
185  // information propagation
186  $action->lay->Set("classid", $classid);
187  $action->lay->Set("dirid", $dirid);
188 }
189 
190 function cmp_cvorder($a, $b)
191 {
192  if ($a["cv_order"] == $b["cv_order"]) {
193  return 0;
194  }
195  return ($a["cv_order"] < $b["cv_order"]) ? -1 : 1;
196 }
197 ?>
← centre documentaire © anakeen - published under CC License - Dynacase