Platform  3.1
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  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Duplicate a document
9  *
10  * @author Anakeen 2000
11  * @version $Id: duplicate.php,v 1.17 2008/10/09 16:26:43 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Dir.php");
20 // -----------------------------------
21 function duplicate(&$action, $dirid, $docid, $temporary = false)
22 {
23  $dbaccess = $action->GetParam("FREEDOM_DB");
24  // test if doc with values
26 
27  if ($doc->isConfidential()) redirect($action, "FDL", "FDL_CONFIDENTIAL&id=" . $doc->id);
28 
29  $cdoc = $doc->getFamDoc();
30 
31  $err = $cdoc->control('create');
32  if ($err != "") $action->exitError(sprintf(_("no privilege to create this kind (%d) of document") , $doc->fromid));
33 
34  $values = $doc->getValues();
35  if (!is_array($values)) $action->exitError(_("this kind of document cannot be duplicate"));
36  // initiate a copy of the doc
37  $copy = $doc->copy($temporary);
38  if (!is_object($copy)) $action->exitError($copy);
39 
40  if ($err != "") $action->exitError($err);
41  // $copy->SetTitle($copy->title);
42  $copy->refresh();
43  $copy->postmodify();
44  $err = $copy->modify();
45  if ($err != "") $action->exitError($err);
46 
47  $copy->title = _("duplication of") . " " . $doc->title;
48  $copy->modify(true, array(
49  "title"
50  ) , true);
51  // add to the same folder
52  if (($dirid == 0) && ($copy->id > 0)) {
53  $dirid = $doc->prelid;
54  }
55 
56  if (($dirid > 0) && ($copy->id > 0)) {
57  $fld = new_Doc($dbaccess, $dirid);
58  if ($fld->isAlive()) {
59  $err = $fld->AddFile($copy->id);
60  if ($err != "") {
61  $copy->Delete();
62  $action->exitError($err);
63  } else {
64  $action->AddActionDone("ADDFILE", $fld->initid);
65  }
66  }
67  }
68 
69  $action->AddLogMsg(sprintf(_("new duplicate document is named : %s") , $copy->title));
70 
71  return $copy;
72 }
73 ?>
← centre documentaire © anakeen - published under CC License - Dynacase