17 include_once (
"FDL/Class.Doc.php");
18 include_once (
"FDL/Class.DocAttr.php");
19 include_once (
"FDL/freedom_util.php");
20 include_once (
"FDL/Lib.Vault.php");
21 include_once (
"VAULT/Class.VaultFile.php");
22 include_once (
"Lib.FileMime.php");
35 $docid = GetHttpVars(
"id", 0);
36 $classid = GetHttpVars(
"classid", 0);
37 $usefor = GetHttpVars(
"usefor");
38 $vid = GetHttpVars(
"vid");
39 $noredirect = (GetHttpVars(
"noredirect"));
40 $quicksave = (GetHttpVars(
"quicksave") ==
"1");
41 $force = (GetHttpVars(
"fstate",
"no") ==
"yes");
46 if (count($_POST) == 0)
return sprintf(_(
"Document cannot be created.\nThe upload size limit is %s bytes.") , ini_get(
'post_max_size'));
48 if (($usefor ==
"D") || ($usefor ==
"Q")) {
54 $commentSubstitute =
'';
59 if (!
$doc) $action->
exitError(sprintf(_(
"no privilege to create this kind (%d) of document") , $classid));
61 $fdoc =
$doc->getFamilyDocument();
62 if ($fdoc->control(
'icreate') !=
"") $action->
exitError(sprintf(_(
"no privilege to create interactivaly this kind (%s) of document") , $fdoc->title));
63 $doc->owner = $action->user->id;
65 if (
$doc->fromid <= 0) {
70 $incumbentName = $action->user->getIncumbentPrivilege($fdoc,
'icreate');
71 if ($incumbentName) $commentSubstitute = sprintf(_(
"(substitute of %s) : ") , $incumbentName);
77 if (
$err !=
"") $action->ExitError(
$err);
80 if (
$err !=
"") $action->ExitError(
$err);
81 $incumbentName = $action->user->getIncumbentPrivilege(
$doc,
'edit');
82 if ($incumbentName) $commentSubstitute = sprintf(_(
"(substitute of %s) : ") , $incumbentName);
85 if (($vid !=
"") && (
$doc->cvid > 0)) {
93 $err = $cvdoc->control($vid);
95 $tview = $cvdoc->getView($vid);
96 $doc->setMask($tview[
"CV_MSKID"]);
98 }
else if (
$doc->cvid > 0) {
99 $doc->setMask($doc::USEMASKCVEDIT);
104 if ((!$noredirect) && (
$err !=
"")) {
105 $action->Addwarningmsg(
$err);
111 if (($action->
getArgument(
"noconstraint") !=
"Y") || ($action->user->id != 1)) {
117 if (
$err && !$noredirect) {
123 $appl = $action->parent;
125 $appl->Set($eapp, $action->parent->parent);
126 $action->set($eact,
$appl);
128 $eparams = explode(
'&', $eparams);
129 foreach ($eparams as $eparam) {
130 $eparam = explode(
'=', $eparam);
131 setHttpVar($eparam[0], $eparam[1]);
135 if (
$appl->name !=
"GENERIC") {
137 $appl->Set(
"GENERIC", $core);
139 $action->
Set(
"GENERIC_EDIT",
$appl);
142 setHttpVar(
"viewconstraint",
"Y");
143 $action->
addWarningMsg(_(
"Some constraint attribute are not respected.\nYou must correct these values before save document."));
158 $action->ExitError(
$err);
161 $doc->disableEditControl();
172 $msg =
$doc->postStore();
179 $olds =
$doc->getOldRawValues();
180 if (is_array($olds)) {
182 foreach ($olds as $ka => $va) {
183 $oa =
$doc->getAttribute($ka);
184 $keys[] = $oa->getLabel();
186 $skeys = implode(
", ", $keys);
187 $doc->addHistoryEntry($commentSubstitute . sprintf(_(
"change %s") , $skeys) ,
HISTO_INFO,
"MODIFY");
189 $doc->addHistoryEntry($commentSubstitute . _(
"change") ,
HISTO_INFO,
"MODIFY");
197 if ((
$err ==
"") && (
$doc->doctype !=
'T')) {
199 $newstate = GetHttpVars(
"newstate",
"");
200 $comment = GetHttpVars(
"comment",
"");
204 if (($newstate !=
"") && ($newstate !=
"-")) {
207 if ($newstate !=
"-") {
214 $wdoc->disableEditControl();
216 $wdoc->enableEditControl();
222 $fdoc =
$doc->getFamilyDocument();
224 if ($fdoc->schar ==
"R") {
225 $doc->revise(sprintf(
"%s : %s", _(
"auto revision") ,
$comment));
239 catch(Exception $e) {
240 $err = $e->getMessage();
246 foreach (
$info as $k => $v) {
247 if ($v[
"err"] !=
"")
$err = $v[
"err"];
251 $fdlids =
$doc->getParentFolderIds();
252 foreach ($fdlids as
$fldid) {
253 $action->AddActionDone(
"MODFOLDERCONTAINT", $fldid);
266 foreach ($_POST as $k => $v) {
271 $attrid = substr($k, 1);
273 if (isset($v[
"-1"])) unset($v[
"-1"]);
274 if (isset($v[
"__1x_"])) unset($v[
"__1x_"]);
276 if ((count($v) == 0))
$value =
" ";
282 if ($oa && $oa->fieldSet && $oa->fieldSet->type ==
"array") {
286 $arrayAids = $doc->attributes->getArrayElements($oa->fieldSet->id);
289 foreach ($arrayAids as $taid) {
290 if (!empty($_POST[
'_' . $taid->id][0])) {
303 $seterr = $doc->SetValue($attrid,
$value, -1, $kerr);
307 $info[$oa->id] = array(
311 if ($oa->inArray()) {
312 $info[$oa->id][
"index"] = $kerr;
314 $ola = $oa->getLabel();
315 $err.= sprintf(
"%s : %s\n", $ola, $seterr);
323 foreach ($_FILES as $k => $v) {
330 if (substr($k, 0, 4) ==
"UPL_") $k = substr($k, 4);
337 foreach ($ta as $k => $v) {
338 if ($v->type ==
"array") {
340 if (count($tv) == 1) {
343 foreach ($fv as $fk => $fvv) {
373 if (
$strict) $postfiles = $_FILES[$attrid];
374 else $postfiles = $_FILES[
"_" . $attrid];
376 $oriid =
"IFORI_" . substr($attrid, 4);
378 if (is_array($postfiles[
'tmp_name'])) {
413 $tuserfiles = array();
414 foreach ($postfiles as $kp => $v) {
415 foreach ($v as $k => $ufv) {
417 $tuserfiles[$k][$kp] = $ufv;
418 if (!empty($orinames[$k])) {
419 if (!$tuserfiles[$k][
"realname"]) {
420 $tuserfiles[$k][
"realname"] = $tuserfiles[$k][
"name"];
421 $tuserfiles[$k][
"name"] = $orinames[$k];
430 $postfiles[
"realname"] = $postfiles[
"name"];
431 $postfiles[
"name"] = $orinames;
433 if ($oa) $postfiles[
"oldvalue"] = $doc->
getRawValue($oa->id);
434 $tuserfiles[] = $postfiles;
441 unset($tuserfiles[
'__1x_']);
443 foreach ($tuserfiles as $k => $userfile) {
445 if ($userfile[
'name'] ==
" ") {
450 if ($userfile[
'error'] != UPLOAD_ERR_OK) {
451 if ($userfile[
'error'] == UPLOAD_ERR_NO_FILE) {
461 if (substr($attrid, 0, 3) ==
"UPL") {
463 if (!is_array($oldfile)) {
466 if (isset($rtold[0]) && preg_match(
PREGEXPFILE, $rtold[0], $reg)) {
473 if (($vid1 > 0) && ($vid2 > 0) && ($vid1 > $vid2)) {
480 if (isset($oldfile[$k])) {
483 if ($recent) $rt[$k] = $recent;
484 else $rt[$k] = $oldfile[$k];
492 switch ($userfile[
'error']) {
493 case UPLOAD_ERR_INI_SIZE:
494 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nThe Size Limit is %s bytes.") , $userfile[
'name'], ini_get(
'upload_max_filesize'));
497 case UPLOAD_ERR_FORM_SIZE:
498 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nThe Size Limit was specified in the HTML form.") , $userfile[
'name']);
501 case UPLOAD_ERR_PARTIAL:
502 $err = sprintf(_(
"Filename '%s' cannot be transmitted completly.\nMay be saturation of server disk.") , $userfile[
'name']);
505 case UPLOAD_ERR_NO_TMP_DIR:
506 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nMissing a temporary folder.") , $userfile[
'name']);
509 case UPLOAD_ERR_CANT_WRITE:
510 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nFailed to write file to disk.") , $userfile[
'name']);
513 case UPLOAD_ERR_EXTENSION:
514 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nA PHP extension stopped the file upload.") , $userfile[
'name']);
518 $err = sprintf(_(
"Filename '%s' cannot be transmitted (%d).") , $userfile[
'name'], $userfile[
'error']);
520 $action->ExitError(
$err);
526 if (file_exists($userfile[
'tmp_name'])) {
527 if (is_uploaded_file($userfile[
'tmp_name'])) {
529 $fname = rawurldecode($userfile[
'name']);
532 $userfile[
'type'] =
getSysMimeFile($userfile[
'tmp_name'], $userfile[
'name']);
538 if ($oa && $oa->getOption(
'preventfilechange') ==
"yes") {
539 if (preg_match(
PREGEXPFILE, $userfile[
"oldvalue"], $reg)) {
541 if ($expectname && ($expectname != $userfile[
"realname"])) {
542 $ext = substr($expectname, strrpos($expectname,
'.'));
543 $prefix = substr($expectname, 0, strrpos($expectname,
'}') + 1);
545 $realext = substr($userfile[
"realname"], strrpos($userfile[
"realname"],
'.'));
546 $realprefix = substr($userfile[
"realname"], 0, strrpos($userfile[
"realname"],
'}', strrpos($expectname,
'.') - 2) + 1);
548 if ((
$ext != $realext) || (
$prefix != $realprefix)) {
549 $doc->
addHistoryEntry(sprintf(_(
"%s : file %s has been replaced by new file %s") , $oa->getLabel() , $reg[3], $userfile[
"name"]) ,
HISTO_WARNING);
554 $rt[$k] = $userfile[
'type'] .
"|" . $vid .
'|' . $fname;
558 $err = sprintf(_(
"Possible file upload attack: filename '%s'.") , $userfile[
'name']);
559 $action->ExitError(
$err);
562 $err = sprintf(_(
"Filename '%s' cannot be transmitted.\nNo file was uploaded.") , $userfile[
'name']);
563 $action->exitError(
$err);
568 if ((count($rt) == 0) || ((count($rt) == 1) && (current($rt) ==
"")))
return "";
574 $fa = $doc->GetFileAttributes();
575 foreach ($fa as $aid => $oa) {
576 $rn = $oa->getOption(
"rn");
578 if ($rn && $ov)
return true;
585 foreach ($rt as $k => $v) {
592 if (($vid1 > 0) && ($vid2 > 0) && ($vid1 > $vid2) && ($fn1 == $fn2))
return $v;
606 $classid = GetHttpVars(
"classid", 0);
613 foreach ($_POST as $k => $v) {
617 $attrid = substr($k, 1);
619 if (isset($v[
"-1"])) unset($v[
"-1"]);
620 if (isset($v[
"__1x_"])) unset($v[
"__1x_"]);
625 if ($cdoc->getAttribute($attrid)) {
626 if ($usefor ==
"D") $cdoc->setDefValue($attrid,
$value);
627 else if ($usefor ==
"Q")
$err.= $cdoc->setParam($attrid,
$value);
634 foreach ($_FILES as $k => $v) {
642 if (substr($k, 0, 4) ==
"UPL_") $k = substr($k, 4);
643 if ($usefor ==
"D") $cdoc->setDefValue($k,
$filename);
644 else if ($usefor ==
"Q")
$err.= $cdoc->setParam($k,
$filename);
653 if (count($tmod) > 0) {
655 if ($usefor ==
"D")
$s = _(
"modify default values :");
656 else if ($usefor ==
"Q")
$s = _(
"modify parameters :");
658 foreach ($tmod as $k => $v) {
660 $v =
'[' . join(
', ', $v) .
']';
664 $cdoc->addHistoryEntry(
$s);
680 if ($action->
getArgument(
'checkMaxInputVars') ==
'yes' && $action->
getArgument($inputNameValue) != $inputNameValue) {
specialmodcard(Action &$action, $usefor)
vault_uniqname($idfile, $teng_name="")
getNormalAttributes($onlyopt=false)
& getAttribute($idAttr, &$oa=null, $useMask=true)
static rawValueToArray($v)
getSysMimeFile($f, $fn="")
getArrayRawValues($idAttr, $index=-1)
setPostVars(Doc &$doc, &$info=array())
removeArrayRow($idAttr, $index)
exitError($texterr, $exit=true, $code="")
searchmorerecent($rt, $file)
getMultipleRawValues($idAttr, $def="", $index=-1)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
getHttpVars($name, $def="", $scope="all")
new_Doc($dbaccess, $id= '', $latest=false)
vault_store($filename, &$vid, $ftitle="")
static getArgument($k, $def= '')
modcard(Action &$action, &$ndocid, &$info=array())
insert_file(Doc &$doc, $attrid, $strict=false)
if($file) if($subject==""&&$file) if($subject=="") $err
addHistoryEntry($comment= '', $level=DocHisto::INFO, $code= '', $uid= '')
check_max_input_vars(Action &$action, $inputNameValue= '__check_max_input_vars__')
getRawValue($idAttr, $def="")