Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
createprof.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  * Create profile
9  *
10  * @author Anakeen 2009
11  * @version $Id: $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage GED
15  */
16 /**
17  */
18 
19 include_once ("FDL/Class.Doc.php");
20 include_once ("FDL/Class.Dir.php");
21 include_once ("FDL/Class.DocAttr.php");
22 include_once ("FDL/freedom_util.php");
23 
24 function createprof(&$action)
25 {
26  // Get all the params
27  $docid = GetHttpVars("targetid");
28  $famid = GetHttpVars("famid");
29  $attrid = GetHttpVars("attrid");
30  $redirid = GetHttpVars("redirid");
31 
32  if ($docid == 0) $action->exitError(_("the document is not referenced: cannot apply profile access modification"));
33 
34  $dbaccess = $action->GetParam("FREEDOM_DB");
35  // initialise object
37  if ($attrid != "cprofid") {
38  $oa = $doc->getAttribute($attrid);
39  if (!$oa) $action->exitError(sprintf(_("attribut %s not found for document %s [%d]") , $attrid, $doc->getTitle() , $doc->id));
40  }
41  // control modify acl
42  $err = $doc->Control("modifyacl");
43  if ($err != "") $action->ExitError($err);
44 
45  $tmpdoc = createTmpDoc($dbaccess, $famid);
46 
47  switch ($tmpdoc->defDoctype) {
48  case 'D':
49  $pdoc = createDoc($dbaccess, "PDIR");
50  break;
51 
52  case 'S':
53  $pdoc = createDoc($dbaccess, "PSEARCH");
54  break;
55 
56  case 'F':
57  $pdoc = createDoc($dbaccess, "PDOC");
58  break;
59 
60  default:
61  $action->exitError(_("Automatic profil creation not possible for this kind of family"));
62  break;;
63  }
64 
65  if (!$pdoc) $action->exitError("not allowed to create profil");
66 
67  $pdoc->setValue("ba_title", sprintf(_("For %s of %s") , $oa ? $oa->getLabel() : _("document creation") , $doc->title));
68  $err = $pdoc->add();
69 
70  if ($err == "") {
71  $err = $pdoc->setControl($pdoc->id); // change profile
72 
73  }
74 
75  if ($err == "") {
76  if ($oa) $doc->setValue($attrid, $pdoc->id);
77  else $doc->$attrid = $pdoc->id;
78  $err = $doc->modify();
79  if ($err == "") $doc->addComment(sprintf(_("add new profil %s") , $pdoc->getTitle()));
80  }
81 
82  if ($err != "") $action->exitError($err);
83 
84  if (!$redirid) $redirid = $docid;
85  redirect($action, "FDL", "FDL_CARD&props=Y&id=$redirid", $action->GetParam("CORE_STANDURL"));
86 }
87 ?>
← centre documentaire © anakeen - published under CC License - Dynacase