19 include_once (
"FDL/Class.Doc.php");
20 include_once (
"FDL/Class.DocAttr.php");
21 include_once (
"FDL/freedom_util.php");
22 include_once (
"FDL/Lib.Vault.php");
23 include_once (
"VAULT/Class.VaultFile.php");
24 include_once (
"Lib.FileMime.php");
48 if (count($_POST) == 0)
return sprintf(_(
"Document cannot be created.\nThe upload size limit is %s bytes.") , ini_get(
'post_max_size'));
50 if (($usefor ==
"D") || ($usefor ==
"Q")) {
60 if (!
$doc) $action->exitError(sprintf(_(
"no privilege to create this kind (%d) of document") , $classid));
63 if (
$fdoc->control(
'icreate') !=
"") $action->exitError(sprintf(_(
"no privilege to create interactivaly this kind (%s) of document") ,
$fdoc->title));
64 $doc->owner = $action->user->id;
66 if (
$doc->fromid <= 0) {
81 if (($vid !=
"") && (
$doc->cvid > 0)) {
85 $err = $cvdoc->control($vid);
86 if (
$err !=
"") $action->exitError(
$err);
87 $tview = $cvdoc->getView($vid);
88 $doc->setMask($tview[
"CV_MSKID"]);
94 if ((!$noredirect) && (
$err !=
"")) $action->Addwarningmsg(
$err);
96 if (((
GetHttpVars(
"noconstraint") !=
"Y") || ($action->user->id != 1)) && ((
$err.=
$doc->verifyAllConstraints(
false, $info)) !=
"")) {
99 $eapp = getHttpVars(
"eapp");
100 $eact = getHttpVars(
"eact");
101 $eparams = getHttpVars(
"eparams");
102 $appl = $action->parent;
105 $appl->Set($eapp, $action->parent->parent);
106 $action->set($eact,
$appl);
108 $eparams = explode(
'&', $eparams);
109 foreach ($eparams as $eparam) {
110 $eparam = explode(
'=', $eparam);
111 setHttpVar($eparam[0], $eparam[1]);
115 if (
$appl->name !=
"GENERIC") {
117 $appl->Set(
"GENERIC", $core);
119 $action->
Set(
"GENERIC_EDIT",
$appl);
121 setHttpVar(
"zone", getHttpVars(
"ezone"));
122 setHttpVar(
"viewconstraint",
"Y");
123 $action->addWarningMsg(_(
"Some constraint attribute are not respected.\nYou must correct these values before save document."));
124 $action->addWarningMsg(
$err);
141 $doc->disableEditControl();
150 if (
$doc->hasNewFiles)
$doc->refreshRn();
151 $msg =
$doc->PostModify();
152 if ($msg) $action->addWarningMsg($msg);
158 $olds =
$doc->getOldValues();
159 if (is_array($olds)) {
161 foreach ($olds as $ka => $va) {
162 $oa =
$doc->getAttribute($ka);
163 $keys[] = $oa->getLabel();
165 $skeys = implode(
", ", $keys);
166 $doc->Addcomment(sprintf(_(
"change %s") , $skeys) ,
HISTO_INFO,
"MODIFY");
176 if ((
$err ==
"") && (
$doc->doctype !=
'T')) {
183 if (($newstate !=
"") && ($newstate !=
"-")) {
186 if ($newstate !=
"-") {
190 $wdoc->disableEditControl();
192 $wdoc->enableEditControl();
200 if (
$fdoc->schar ==
"R") {
201 $doc->AddRevision(sprintf(
"%s : %s", _(
"auto revision") ,
$comment));
218 foreach ($info as $k => $v) {
219 if ($v[
"err"] !=
"")
$err = $v[
"err"];
223 $fdlids =
$doc->getParentFolderIds();
224 foreach ($fdlids as
$fldid) {
238 foreach ($_POST as $k => $v) {
243 $attrid = substr($k, 1);
245 if (isset($v[
"-1"])) unset($v[
"-1"]);
246 if (isset($v[
"__1x_"])) unset($v[
"__1x_"]);
248 if ((count($v) == 0))
$value =
" ";
249 else $value = array_map(
"stripslashes", $v);
252 }
else $value = stripslashes($v);
256 $seterr =
$doc->SetValue($attrid,
$value, -1, $kerr);
258 $oa =
$doc->getAttribute($attrid);
260 $info[$oa->id] = array(
264 if ($oa->inArray()) {
265 $info[$oa->id][
"index"] = $kerr;
267 $ola = $oa->getLabel();
268 $err.= sprintf(
"%s : %s\n", $ola, $seterr);
276 foreach ($_FILES as $k => $v) {
283 if (substr($k, 0, 4) ==
"UPL_") $k = substr($k, 4);
289 $ta =
$doc->getNormalAttributes();
290 foreach (
$ta as $k => $v) {
291 if ($v->type ==
"array") {
292 $tv =
$doc->getAvalues($v->id);
293 if (count($tv) == 1) {
296 foreach ($fv as $fk => $fvv) {
303 $doc->removeArrayRow($v->id, 0);
319 global $upload_max_filesize;
321 if ($strict) $postfiles = $_FILES[$attrid];
322 else $postfiles = $_FILES[
"_" . $attrid];
323 $oa =
$doc->getAttribute(substr($attrid, 4));
325 $oriid =
"IFORI_" . substr($attrid, 4);
326 $orinames = getHttpVars($oriid);
327 if (is_array($postfiles[
'tmp_name'])) {
328 $tuserfiles = array();
329 while (list($kp, $v) = each($postfiles)) {
330 while (list($k, $ufv) = each($v)) {
332 $tuserfiles[$k][$kp] = $ufv;
334 if (!$tuserfiles[$k][
"realname"]) {
335 $tuserfiles[$k][
"realname"] = $tuserfiles[$k][
"name"];
336 $tuserfiles[$k][
"name"] = $orinames[$k];
339 if ($oa) $tuserfiles[$k][
"oldvalue"] =
$doc->getTValue($oa->id,
"", $k);
345 $postfiles[
"realname"] = $postfiles[
"name"];
346 $postfiles[
"name"] = $orinames;
348 if ($oa) $postfiles[
"oldvalue"] =
$doc->getValue($oa->id);
349 $tuserfiles[] = $postfiles;
353 if (
$doc) $rtold =
$doc->_val2array(
$doc->getOldValue(substr($attrid, 4)));
354 $oa =
$doc->getAttribute(substr($attrid, 4));
355 $rt =
$doc->getTvalue($attrid);
356 unset($tuserfiles[
'__1x_']);
358 foreach ($tuserfiles as $k => $userfile) {
360 if ($userfile[
'name'] ==
" ") {
364 $userfile[
'name'] = stripslashes($userfile[
'name']);
365 if (($userfile[
'tmp_name'] ==
"none") || ($userfile[
'tmp_name'] ==
"") || ($userfile[
'size'] == 0)) {
367 if ($userfile[
'name'] !=
"") {
368 switch ($userfile[
'error']) {
369 case UPLOAD_ERR_INI_SIZE:
370 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nThe Size Limit is %s bytes.") , $userfile[
'name'], ini_get(
'upload_max_filesize'));
373 case UPLOAD_ERR_FORM_SIZE:
374 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nThe Size Limit was specified in the HTML form.") , $userfile[
'name']);
377 case UPLOAD_ERR_PARTIAL:
378 $err = sprintf(_(
"Filename '%s' cannot be transmitted completly.\nMay be saturation of server disk.") , $userfile[
'name']);
382 $err = sprintf(_(
"Filename '%s' cannot be transmitted.") , $userfile[
'name']);
384 $action->ExitError(
$err);
387 if (substr($attrid, 0, 3) ==
"UPL") {
388 $oldfile = getHttpVars(substr($attrid, 3));
389 if (!is_array($oldfile)) {
392 if (preg_match(
PREGEXPFILE, $rtold[0], $reg)) $vid1 = $reg[2];
393 if (preg_match(
PREGEXPFILE, $oldfile, $reg)) $vid2 = $reg[2];
395 if (($vid1 > 0) && ($vid2 > 0) && ($vid1 > $vid2)) $rt[$k] = $rtold[0];
396 else $rt[$k] = $oldfile;
399 if (isset($oldfile[$k])) {
402 if (preg_match(
PREGEXPFILE, $rtold[$k], $reg)) $vid1 = $reg[2];
403 if (preg_match(
PREGEXPFILE, $oldfile[$k], $reg)) $vid2 = $reg[2];
406 if ($recent) $rt[$k] = $recent;
407 else $rt[$k] = $oldfile[$k];
415 preg_match(
"/(.*)\.(.*)$/", $userfile[
'name'], $reg);
419 if (file_exists($userfile[
'tmp_name'])) {
420 if (is_uploaded_file($userfile[
'tmp_name'])) {
422 $fname = $userfile[
'name'];
423 $doc->hasNewFiles =
true;
426 $userfile[
'type'] =
getSysMimeFile($userfile[
'tmp_name'], $userfile[
'name']);
431 if ($oa && $oa->getOption(
'preventfilechange') ==
"yes") {
432 if (preg_match(
PREGEXPFILE, $userfile[
"oldvalue"], $reg)) {
434 if ($expectname && ($expectname != $userfile[
"realname"])) {
435 $ext = substr($expectname, strrpos($expectname,
'.'));
436 $prefix = substr($expectname, 0, strrpos($expectname,
'}') + 1);
438 $realext = substr($userfile[
"realname"], strrpos($userfile[
"realname"],
'.'));
439 $realprefix = substr($userfile[
"realname"], 0, strrpos($userfile[
"realname"],
'}', strrpos($expectname,
'.') - 2) + 1);
441 if (($ext != $realext) || (
$prefix != $realprefix)) {
442 $doc->addComment(sprintf(_(
"%s : file %s has been replaced by new file %s") , $oa->getLabel() , $reg[3], $userfile[
"name"]) ,
HISTO_WARNING);
449 $err = sprintf(_(
"Possible file upload attack: filename '%s'.") , $userfile[
'name']);
450 $action->ExitError(
$err);
452 $rt[$k] = $userfile[
'type'] .
"|" . $vid .
'|' . $userfile[
'name'];
457 if ((count($rt) == 0) || ((count($rt) == 1) && (current($rt) ==
"")))
return "";
464 foreach ($rt as $k => $v) {
471 if (($vid1 > 0) && ($vid2 > 0) && ($vid1 > $vid2) && ($fn1 == $fn2))
return $v;
490 foreach ($_POST as $k => $v) {
494 $attrid = substr($k, 1);
496 if (isset($v[
"-1"])) unset($v[
"-1"]);
497 if (isset($v[
"__1x_"])) unset($v[
"__1x_"]);
498 $value = stripslashes(implode(
"\n", str_replace(
"\n",
"<BR>", $v)));
499 }
else $value = stripslashes($v);
501 if ($usefor ==
"D") $cdoc->setDefValue($attrid,
$value);
502 else if ($usefor ==
"Q") $cdoc->setParam($attrid,
$value);
508 foreach ($_FILES as $k => $v) {
516 if (substr($k, 0, 4) ==
"UPL_") $k = substr($k, 4);
517 if ($usefor ==
"D") $cdoc->setDefValue($k,
$filename);
518 else if ($usefor ==
"Q") $cdoc->setParam($k,
$filename);
526 if (count($tmod) > 0) {
527 if ($usefor ==
"D")
$s = _(
"modify default values :");
528 else if ($usefor ==
"Q")
$s = _(
"modify parameters :");
530 foreach ($tmod as $k => $v) {
533 $cdoc->AddComment(
$s);