Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
freedom_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  * Form to edit or create a document
9  *
10  * @author Anakeen 2000
11  * @version $Id: freedom_edit.php,v 1.44 2008/08/14 09:59:14 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 include_once ("GENERIC/generic_edit.php");
20 /**
21  * Edit or create a document
22  * @param Action &$action current action
23  * @global id Http var : document identificator to édit (empty means create)
24  * @global classid Http var : family identificator use for create
25  * @global dirid Http var : folder identificator to add when create
26  * @global usefor Http var : set to "D" for edit default values
27  * @global onlysubfam Http var : to show in family list only sub family of classid
28  * @global alsosubfam Http var : N default (Y|N) in case of only sub fam view also the mother family
29  */
31 {
32  // -----------------------------------
33  // Get All Parameters
34  $docid = GetHttpVars("id", 0); // document to edit
35  $classid = GetHttpVars("classid", 0); // use when new doc or change class
36  $dirid = GetHttpVars("dirid", 0); // directory to place doc if new doc
37  $usefor = GetHttpVars("usefor"); // default values for a document
38  $onlysubfam = GetHttpVars("onlysubfam"); // restricy to sub fam of
39  $alsosub = (GetHttpVars("alsosubfam", "N") == "Y");
40  // Set the globals elements
41  $dbaccess = $action->GetParam("FREEDOM_DB");
42  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
43  else $classid = abs($classid);
44  setHttpVar("classid", $classid);
45 
46  if ($docid > 0) {
48  if (!$doc->isAlive()) $action->exitError(sprintf(_("document id %d not found") , $docid));
49  $fdoc = $doc->getFamDoc();
50  $tclassdoc[$doc->fromid] = array(
51  "id" => $fdoc->id,
52  "title" => $fdoc->getTitle()
53  );
54  } else {
55  // new document select special classes
56  if ($dirid > 0) {
57  $dir = new_Doc($dbaccess, $dirid);
58  if (method_exists($dir, "isAuthorized")) {
59  if ($dir->locked == - 1) $dir = new_Doc($dbaccess, $dir->latestId());
60 
61  if ($dir->isAuthorized($classid)) {
62  // verify if classid is possible
63  if (($dir->hasNoRestriction()) || (!$classid)) $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, $classid, "TABLE");
64  else $tclassdoc = $dir->getAuthorizedFamilies();
65  } else {
66  $tclassdoc = $dir->getAuthorizedFamilies();
67  $first = current($tclassdoc);
68  $classid = abs($first["id"]);
69  setHttpVar("classid", abs($classid)); // propagate to subzones
70 
71  }
72  } else {
73  $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, $classid, "TABLE");
74  }
75  } else {
76 
77  if ($onlysubfam) {
78 
79  if (!is_numeric($onlysubfam)) $onlysubfam = getFamIdFromName($dbaccess, $onlysubfam);
80  $cdoc = new_Doc($dbaccess, $onlysubfam);
81  $tsub = $cdoc->GetChildFam($cdoc->id, true);
82  if ($alsosub) {
83  $tclassdoc[$classid] = array(
84  "id" => $cdoc->id,
85  "title" => $cdoc->getTitle()
86  );
87  $tclassdoc = array_merge($tclassdoc, $tsub);
88  } else {
89  $tclassdoc = $tsub;
90  }
91  $first = current($tclassdoc);
92  if ($classid == "") $classid = $first["id"];
93  setHttpVar("classid", abs($classid)); // propagate to subzones
94 
95  } else $tclassdoc = GetClassesDoc($dbaccess, $action->user->id, $classid, "TABLE");
96  }
97  }
98  // when modification
99  if (($classid == 0) && ($docid != 0)) $classid = $doc->fromid;
100  setHttpVar("forcehead", "yes");
101 
103  // build list of class document
104  $selectclass = array();
105 
106  if ($tclassdoc) {
107  $first = false;
108  foreach ($tclassdoc as $k => $cdoc) {
109  if ($cdoc["id"] == $classid) $first = true;
110  $selectclass[$k]["idcdoc"] = $cdoc["id"];
111  $selectclass[$k]["classname"] = ucfirst(DocFam::getLangTitle($cdoc));
112  $selectclass[$k]["selected"] = "";
113  }
114  if (!$first) {
115  reset($tclassdoc);
116  $first = current($tclassdoc);
117  $classid = $first["id"];
118  setHttpVar("classid", abs($classid)); // propagate to subzones
119 
120  }
121  }
122  // add no inherit for class document
123  if (($docid > 0) && ($doc->doctype == "C")) {
124  $selectclass[$k + 1]["idcdoc"] = "0";
125  $selectclass[$k + 1]["classname"] = _("no document type");
126  }
127  if ($docid == 0) {
128  switch ($classid) {
129  case 2:
130  $action->lay->Set("refreshfld", "yes");
131  break;
132 
133  case 3:
134  case 4:
135  //$action->lay->Set("TITLE", _("new profile"));
136  break;
137 
138  default:
139  //$action->lay->Set("TITLE", _("new document"));
140 
141  }
142 
143  if ($usefor == "D") $action->lay->Set("TITLE", _("default values"));
144  if ($classid > 0) {
145  $doc = createDoc($dbaccess, $classid); // the doc inherit from chosen class
146  if ($doc === false) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
147  // restrict to possible family creation permission
148  foreach ($selectclass as $k => $cdoc) {
149  $tfid[] = abs($cdoc["idcdoc"]);
150  }
151  $tfid = getFamilyCreationIds($dbaccess, $action->user->id, $tfid);
152  foreach ($selectclass as $k => $cdoc) {
153  if (!in_array(abs($cdoc["idcdoc"]) , $tfid)) unset($selectclass[$k]);
154  }
155  }
156  // selected the current class document
157  foreach ($selectclass as $k => $cdoc) {
158  if ($classid == abs($cdoc["idcdoc"])) {
159  $selectclass[$k]["selected"] = "selected";
160  }
161  }
162  } else {
163  if (!$doc->isAlive()) $action->ExitError(_("document not referenced"));
164  // selected the current class document
165  while (list($k, $cdoc) = each($selectclass)) {
166  if ($doc->fromid == abs($selectclass[$k]["idcdoc"])) {
167  $selectclass[$k]["selected"] = "selected";
168  }
169  }
170  }
171 
172  $action->lay->Set("id", $docid);
173  $action->lay->Set("dirid", $dirid);
174  $action->lay->Set("onlysubfam", $onlysubfam);
175  $action->lay->Set("alsosubfam", GetHttpVars("alsosubfam"));
176  if ($docid > 0) $action->lay->Set("doctype", $doc->doctype);
177  // sort by classname
178  uasort($selectclass, "cmpselect");
179  $action->lay->SetBlockData("SELECTCLASS", $selectclass);
180  // control view of special constraint button
181  $action->lay->Set("boverdisplay", "none");
182 }
183 function cmpselect($a, $b)
184 {
185  return strcasecmp($a["classname"], $b["classname"]);
186 }
187 ?>
← centre documentaire © anakeen - published under CC License - Dynacase