Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_mod.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Modify a document
8  *
9  * @author Anakeen
10  * @version $Id: generic_mod.php,v 1.34 2008/03/14 13:58:03 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/modcard.php");
18 
19 include_once ("FDL/Class.DocFam.php");
20 include_once ("FDL/Class.Dir.php");
21 // -----------------------------------
23 {
24  if (check_max_input_vars($action) === false) {
25  $action->exitError(sprintf(_("Input variables exceeded %s. To increase the limit change max_input_vars in php.ini.") , ini_get('max_input_vars')));
26  }
27  // -----------------------------------
28  // Get all the params
29  $dirid = $action->getArgument("dirid", 0);
30  $docid = $action->getArgument("id", 0);
31  $catgid = $action->getArgument("catgid", 0);
32  $retedit = ($action->getArgument("retedit", "N") == "Y"); // true if return need edition
33  $noredirect = ($action->getArgument("noredirect") == "1"); // true if return need edition
34  $quicksave = ($action->getArgument("quicksave") == "1"); // true if return need edition
35  $rzone = $action->getArgument("rzone"); // special zone when finish edition
36  $rvid = $action->getArgument("rvid"); // special zone when finish edition
37  $viewext = $action->getArgument("viewext") == "yes"; // special zone when finish edition
38  $autoclose = $action->getArgument("autoclose") == "yes"; // special zone when finish edition
39  $recallhelper = $action->getArgument("recallhelper") == "yes"; // special zone when finish edition
40  $updateAttrid = $action->getArgument("updateAttrid");
41 
42  $dbaccess = $action->dbaccess;
43  $action->parent->addJsRef("GENERIC:generic_mod.js", true);
44  $err = modcard($action, $ndocid, $info); // ndocid change if new doc
45  if (!$noredirect) $action->AddWarningMsg($err);
46  $doc = null;
47  if ($err == "") {
48  $doc = new_Doc($dbaccess, $ndocid);
49  if ($docid > 0) AddLogMsg(sprintf(_("%s has been modified") , $doc->title));
50 
51  if ($docid == 0) { // new file => add in a folder
52  AddLogMsg(sprintf(_("%s has been created") , $doc->title));
53 
54  $cdoc = $doc->getFamilyDocument();
55  //if (($cdoc->dfldid>0) && ($dirid==0)) $dirid=$cdoc->dfldid;// we not insert in defaut folder
56  if ($dirid > 0) {
57  /*
58  * @var Dir $fld
59  */
60  $fld = new_Doc($dbaccess, $dirid);
61  if ($fld->locked == - 1) { // it is revised document
62  $dirid = $fld->getLatestId();
63  if ($dirid != $fld->id) $fld = new_Doc($dbaccess, $dirid);
64  }
65  if (method_exists($fld, "insertDocument")) {
66  $err = $fld->insertDocument($doc->id);
67  if ($err != "") {
68  //try in home folder
69  $home = $fld->getHome(false);
70  if ($home && ($home->id > 0)) {
71  $fld = $home;
72  $err = $fld->insertDocument($doc->id);
73  }
74  }
75 
76  if ($err != "") {
77  $action->AddLogMsg($err);
78  } else {
79  if (($doc->doctype == 'D') || ($doc->doctype == 'S')) $action->AddActionDone("ADDFOLDER", $fld->initid);
80  else $action->AddActionDone("ADDFILE", $fld->initid);
81  }
82  } else {
83  //try in home folder
84  $fld = new Dir($dbaccess);
85  $home = $fld->getHome(false);
86  if ($home && ($home->id > 0)) {
87  $fld = $home;
88  $err = $fld->insertDocument($doc->id);
89  }
90  }
91  }
92  }
93  }
94 
95  if ($noredirect) {
96  if ((!$err) && $updateAttrid && $doc) {
97  $action->lay->set("updateData", json_encode(array(
98  "id" => $doc->id,
99  "title" => $doc->getTitle() ,
100  "attrid" => $updateAttrid,
101  "recallhelper" => $recallhelper
102  )));
103  } else {
104  $action->lay->set("updateData", "null");
105  }
106 
107  $action->lay->set("autoclose", $autoclose ? "true" : "false");
108  $action->lay->eSet("id", $ndocid);
109  if (is_array($info)) {
110  foreach ($info as $k => $v) {
111  $info[$k]["prefix"] = sprintf(_("constraint not validated for %s attribute") , $v["label"]);
112  }
113  }
114  $action->lay->set("constraintinfo", json_encode($info));
115  $action->lay->set("quicksave", (bool)$quicksave);
116  if ($rzone != "") $zone = sprintf("&zone=%s", urlencode($rzone));
117  else $zone = "";
118  if ($rvid != "") $zone = sprintf("&vid=%s", urlencode($rvid));
119  if ($err == "-") $err = "";
120  $action->lay->set("error", json_encode($err));
121  $warning = $action->parent->getWarningMsg();
122  if ($warning && count($warning) > 0) $warning = implode("\n", $warning);
123  else $warning = '';
124  $action->lay->set("warning", json_encode($warning));
125  if ($retedit) {
126  $ract = getHttpVars("redirect_act", null);
127  if ($ract === null) {
128  $ract = "GENERIC_EDIT&id=" . urlencode($ndocid);
129  }
130  $url = sprintf("?app=%s&action=%s", urlencode(getHttpVars("redirect_app", "GENERIC")) , $ract) . $zone;
131  $action->lay->set("url", json_encode($url));
132  } else {
133  $ract = getHttpVars("redirect_act", '');
134  $ract = str_replace("%ID%", $ndocid, $ract);
135  if ($viewext) {
136  if ($ract === '') {
137  $ract = "EUI_VIEWDOC$zone&refreshfld=Y&id=" . urlencode($ndocid);
138  }
139  $url = sprintf("?app=%s&action=%s", urlencode(getHttpVars("redirect_app", "EXTUI")) , $ract) . $zone;
140  $action->lay->set("url", json_encode($url));
141  } else {
142  if ($ract === '') {
143  $ract = "FDL_CARD$zone&refreshfld=Y&id=" . urlencode($ndocid);
144  }
145  $url = sprintf("?app=%s&action=%s", urlencode(getHttpVars("redirect_app", "FDL")) , $ract) . $zone;
146  $action->lay->set("url", json_encode($url));
147  }
148  }
149  return;
150  }
151 
152  if ($ndocid == 0) {
153  redirect($action, GetHttpVars("redirect_app", "GENERIC") , GetHttpVars("redirect_act", "GENERIC_LOGO") , $action->GetParam("CORE_STANDURL"));
154  }
155  if ($retedit) {
156  redirect($action, GetHttpVars("redirect_app", "GENERIC") , GetHttpVars("redirect_act", "GENERIC_EDIT&id=" . urlencode($ndocid)) , $action->GetParam("CORE_STANDURL"));
157  } else {
158 
159  if ($rzone != "") $zone = sprintf("&zone=%s", urlencode($rzone));
160  else $zone = "";
161  if ($rvid != "") $zone = sprintf("&vid=%s", urlencode($rvid));
162  // $action->register("reload$ndocid","Y"); // to reload cached client file
163  redirect($action, GetHttpVars("redirect_app", "FDL") , GetHttpVars("redirect_act", "FDL_CARD$zone&refreshfld=Y&id=" . urlencode($ndocid)) , $action->GetParam("CORE_STANDURL"));
164  }
165 }
global $action
exitError($texterr, $exit=true, $code="")
AddLogMsg($msg, $cut=80)
Definition: Lib.Common.php:77
$docid
Definition: cleanFamily.php:13
generic_mod(Action &$action)
Definition: generic_mod.php:22
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
new_Doc($dbaccess, $id= '', $latest=false)
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
modcard(Action &$action, &$ndocid, &$info=array())
Definition: modcard.php:30
if($file) if($subject==""&&$file) if($subject=="") $err
check_max_input_vars(Action &$action, $inputNameValue= '__check_max_input_vars__')
Definition: modcard.php:678
← centre documentaire © anakeen