Core  3.2
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  * @package FDL
5 */
6 /**
7  * Form to edit or create a document
8  *
9  * @author Anakeen
10  * @version $Id: freedom_edit.php,v 1.44 2008/08/14 09:59:14 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 
17 include_once ("GENERIC/generic_edit.php");
18 /**
19  * Edit or create a document
20  * @param Action &$action current action
21  * @global string $id Http var : document identifier to édit (empty means create)
22  * @global string $classid Http var : family identifier use for create
23  * @global string $dirid Http var : folder identifier to add when create
24  * @global string $usefor Http var : set to "D" for edit default values
25  * @global string $onlysubfam Http var : to show in family list only sub family of classid
26  * @global string $alsosubfam Http var : N default (Y|N) in case of only sub fam view also the mother family
27  */
29 {
30  // -----------------------------------
31  // Get All Parameters
32  $docid = GetHttpVars("id", 0); // document to edit
33  $classid = GetHttpVars("classid", 0); // use when new doc or change class
34  $dirid = GetHttpVars("dirid", 0); // directory to place doc if new doc
35  $usefor = GetHttpVars("usefor"); // default values for a document
36  $onlysubfam = GetHttpVars("onlysubfam"); // restricy to sub fam of
37  $alsosub = (GetHttpVars("alsosubfam", "N") == "Y");
38  $type = GetHttpVars("type", "");
39  // Set the globals elements
40  $dbaccess = $action->dbaccess;
41  if (!is_numeric($classid)) $classid = getFamIdFromName($dbaccess, $classid);
42  else $classid = abs($classid);
43  setHttpVar("classid", $classid);
44 
45  $tmpDoc = createDoc($action->dbaccess, $classid);
46  $isSystemDoc = (is_object($tmpDoc) && substr($tmpDoc->usefor, 0, 1) == 'S');
47  unset($tmpDoc);
48  $doc = null;
49  if ($docid > 0) {
51  if (!$doc->isAlive()) $action->exitError(sprintf(_("document id %d not found") , $docid));
52  $fdoc = $doc->getFamilyDocument();
53  $tclassdoc[$doc->fromid] = array(
54  "id" => $fdoc->id,
55  "title" => $fdoc->getTitle()
56  );
57  } else {
58  // new document select special classes
59  if ($dirid > 0) {
60  /*
61  * @var Dir $dir
62  */
64  if (method_exists($dir, "isAuthorized")) {
65  if ($dir->locked == - 1) $dir = new_Doc($dbaccess, $dir->getLatestId());
66 
67  if ($dir->isAuthorized($classid)) {
68  // verify if classid is possible
69  if (($dir->hasNoRestriction()) || (!$classid)) {
70  $tclassdoc = getFamiliesWithTypeOrClassId($dbaccess, $action->user->id, $type, $classid, "TABLE");
71  } else $tclassdoc = $dir->getAuthorizedFamilies();
72  } else {
73  $tclassdoc = $dir->getAuthorizedFamilies();
74  $first = current($tclassdoc);
75  $classid = abs($first["id"]);
76  setHttpVar("classid", abs($classid)); // propagate to subzones
77 
78  }
79  } else {
80  $tclassdoc = getFamiliesWithTypeOrClassId($dbaccess, $action->user->id, $type, $classid, "TABLE"); // ($isSystemDoc) ? getSystemFamilies($dbaccess, $action->user->id, "TABLE") : getNonSystemFamilies($dbaccess, $action->user->id, "TABLE);");
81 
82  }
83  } else {
84 
85  if ($onlysubfam) {
86 
87  if (!is_numeric($onlysubfam)) $onlysubfam = getFamIdFromName($dbaccess, $onlysubfam);
88  $cdoc = new_Doc($dbaccess, $onlysubfam);
89  $tsub = $cdoc->GetChildFam($cdoc->id, true);
90  if ($alsosub) {
91  $tclassdoc[$classid] = array(
92  "id" => $cdoc->id,
93  "title" => $cdoc->getTitle()
94  );
95  $tclassdoc = array_merge($tclassdoc, $tsub);
96  } else {
97  $tclassdoc = $tsub;
98  }
99  $first = current($tclassdoc);
100  if ($classid == "") $classid = $first["id"];
101  setHttpVar("classid", abs($classid)); // propagate to subzones
102 
103  } else {
104  $tclassdoc = getFamiliesWithTypeOrClassId($dbaccess, $action->user->id, $type, $classid, "TABLE"); //($isSystemDoc) ? getSystemFamilies($dbaccess, $action->user->id, "TABLE") : getNonSystemFamilies($dbaccess, $action->user->id, "TABLE);");
105 
106  }
107  }
108  }
109  // when modification
110  if (($classid == 0) && ($docid != 0)) $classid = $doc->fromid;
111  setHttpVar("forcehead", "yes");
112 
113  generic_edit($action);
114  // build list of class document
115  $selectclass = array();
116  $k = 0;
117  if ($tclassdoc) {
118  $first = false;
119  foreach ($tclassdoc as $k => $cdoc) {
120  if ($cdoc["id"] == $classid) $first = true;
121  $selectclass[$k]["idcdoc"] = $cdoc["id"];
122  $selectclass[$k]["classname"] = ucfirst(DocFam::getLangTitle($cdoc));
123  $selectclass[$k]["selected"] = "";
124  }
125  if (!$first) {
126  reset($tclassdoc);
127  $first = current($tclassdoc);
128  $classid = $first["id"];
129  setHttpVar("classid", abs($classid)); // propagate to subzones
130 
131  }
132  }
133  // add no inherit for class document
134  if (($docid > 0) && ($doc->doctype == "C")) {
135  $selectclass[$k + 1]["idcdoc"] = "0";
136  $selectclass[$k + 1]["classname"] = _("no document type");
137  }
138  if ($docid == 0) {
139  switch ($classid) {
140  case 2:
141  $action->lay->Set("refreshfld", "yes");
142  break;
143 
144  case 3:
145  case 4:
146  //$action->lay->Set("TITLE", _("new profile"));
147  break;
148 
149  default:
150  //$action->lay->Set("TITLE", _("new document"));
151 
152  }
153 
154  if ($usefor == "D") $action->lay->Set("TITLE", _("default values"));
155  if ($classid > 0) {
156  $doc = createDoc($dbaccess, $classid); // the doc inherit from chosen class
157  if ($doc === false) $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $classid));
158  // restrict to possible family creation permission
159  $tfid = array();
160  foreach ($selectclass as $k => $cdoc) {
161  $tfid[] = abs($cdoc["idcdoc"]);
162  }
163  $tfid = getFamilyCreationIds($dbaccess, $action->user->id, $tfid);
164  foreach ($selectclass as $k => $cdoc) {
165  if (!in_array(abs($cdoc["idcdoc"]) , $tfid)) unset($selectclass[$k]);
166  }
167  }
168  // selected the current class document
169  foreach ($selectclass as $k => $cdoc) {
170  if ($classid == abs($cdoc["idcdoc"])) {
171  $selectclass[$k]["selected"] = "selected";
172  }
173  }
174  } else {
175  if (!$doc->isAlive()) $action->ExitError(_("document not referenced"));
176  // selected the current class document
177  foreach ($selectclass as $k => $cdoc) {
178  if ($doc->fromid == abs($selectclass[$k]["idcdoc"])) {
179  $selectclass[$k]["selected"] = "selected";
180  }
181  }
182  }
183 
184  $action->lay->eSet("id", $docid);
185  $action->lay->eSet("dirid", $dirid);
186  $action->lay->eSet("onlysubfam", $onlysubfam);
187  $action->lay->eSet("alsosubfam", GetHttpVars("alsosubfam"));
188  if ($docid > 0) $action->lay->Set("doctype", $doc->doctype);
189  // sort by classname
190  uasort($selectclass, "cmpselect");
191  $action->lay->SetBlockData("SELECTCLASS", $selectclass);
192  // control view of special constraint button
193  $action->lay->Set("boverdisplay", "none");
194 }
195 function cmpselect($a, $b)
196 {
197  return strcasecmp($a["classname"], $b["classname"]);
198 }
199 function getFamiliesWithTypeOrClassId($dbaccess, $userid, $type, $classid, $qtype)
200 {
201  switch ($type) {
202  case 'system':
203  return getSystemFamilies($dbaccess, $userid, $qtype);
204  break;
205 
206  case 'not(system)':
207  return getNonSystemFamilies($dbaccess, $userid, $qtype);
208  break;
209  }
210  return GetClassesDoc($dbaccess, $userid, $classid, $qtype);
211 }
getSystemFamilies($dbaccess, $userid, $qtype="TABLE")
Definition: Lib.Dir.php:966
cmpselect($a, $b)
global $action
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
getNonSystemFamilies($dbaccess, $userid, $qtype="TABLE")
Definition: Lib.Dir.php:952
Set($name, &$parent)
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
GetClassesDoc($dbaccess, $userid, $classid=0, $qtype="LIST", $extraFilters=array())
Definition: Lib.Dir.php:906
freedom_edit(Action &$action)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getFamilyCreationIds($dbaccess, $uid, $tfid=array())
Definition: Lib.Dir.php:1009
getFamIdFromName($dbaccess, $name)
getFamiliesWithTypeOrClassId($dbaccess, $userid, $type, $classid, $qtype)
new_Doc($dbaccess, $id= '', $latest=false)
$dir
Definition: resizeimg.php:144
static getLangTitle($values)
$dbaccess
Definition: checkVault.php:17
generic_edit(Action &$action)
← centre documentaire © anakeen