Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
duplicate.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Duplicate a document
8  *
9  * @author Anakeen
10  * @version $Id: duplicate.php,v 1.17 2008/10/09 16:26:43 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Dir.php");
18 // -----------------------------------
19 function duplicate(Action & $action, $dirid, $docid, $temporary = false)
20 {
21  $dbaccess = $action->dbaccess;
22  // test if doc with values
24 
25  if ($doc->isConfidential()) redirect($action, "FDL", "FDL_CONFIDENTIAL&id=" . $doc->id);
26 
27  $cdoc = $doc->getFamilyDocument();
28 
29  $err = $cdoc->control('create');
30  if ($err != "") $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $doc->fromid));
31 
32  $values = $doc->getValues();
33  if (!is_array($values)) $action->exitError(_("this kind of document cannot be duplicate"));
34  // initiate a copy of the doc
35  $copy = $doc->duplicate($temporary);
36  if (!is_object($copy)) $action->exitError($copy);
37 
38  if ($err != "") $action->exitError($err);
39  // $copy->SetTitle($copy->title);
40  $copy->refresh();
41  $copy->postStore();
42  $err = $copy->modify();
43  if ($err != "") $action->exitError($err);
44 
45  $copy->title = _("duplication of") . " " . $doc->title;
46  $copy->modify(true, array(
47  "title"
48  ) , true);
49  // add to the same folder
50  if (($dirid == 0) && ($copy->id > 0)) {
51  $dirid = $doc->prelid;
52  }
53 
54  if (($dirid > 0) && ($copy->id > 0)) {
55  /*
56  * @var Dir $fld
57  */
58  $fld = new_Doc($dbaccess, $dirid);
59  if ($fld->isAlive()) {
60  $err = $fld->insertDocument($copy->id);
61  if ($err != "") {
62  $copy->Delete();
63  $action->exitError($err);
64  } else {
65  $action->AddActionDone("ADDFILE", $fld->initid);
66  }
67  }
68  }
69 
70  $action->AddLogMsg(sprintf(_("new duplicate document is named : %s") , $copy->title));
71 
72  return $copy;
73 }
global $action
exitError($texterr, $exit=true, $code="")
$docid
Definition: cleanFamily.php:13
new_Doc($dbaccess, $id= '', $latest=false)
duplicate(Action &$action, $dirid, $docid, $temporary=false)
Definition: duplicate.php:19
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen