Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
generic_util.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Collection of utilities functions for GENERIC application
8  *
9  * @author Anakeen
10  * @version $Id: generic_util.php,v 1.33 2008/11/14 12:43:12 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Lib.Dir.php");
18 
20 {
21  // special for onefam application
22  $famid = GetHttpVars("famid");
23  if (!is_numeric($famid)) $famid = getIdFromName($action->dbaccess, $famid);
24  if ($famid != "") return $famid;
25 
26  $famid = $action->GetParam("DEFAULT_FAMILY", 1);
27  if ($famid == 1) {
28  $famid = $action->Read("DEFAULT_FAMILY", 0);
29  $action->parent->SetVolatileParam("DEFAULT_FAMILY", $famid);
30  }
31 
32  return $famid;
33 }
34 
36 {
37  $famid = getDefFam($action);
38  $dbaccess = $action->dbaccess;
39  /*
40  * @var DocFam $fdoc
41  */
42  $fdoc = new_Doc($dbaccess, $famid);
43  if ($fdoc->dfldid > 0) return $fdoc->dfldid;
44 
45  return 0;
46 }
47 // return attribute sort default
48 function getDefUSort(Action & $action, $def = "-revdate", $famid = "")
49 {
50  if (!$famid) $famid = getDefFam($action);
51  $pu = $action->GetParam("GENERIC_USORT");
52  if ($pu) {
53  $tu = explode("|", $pu);
54 
55  foreach ($tu as $k => $v) {
56  list($afamid, $aorder, $sqlorder) = explode(":", $v);
57  if (!is_numeric($afamid)) {
58  $afamid = getFamIdFromName($action->dbaccess, $afamid);
59  }
60  if ($afamid == $famid) {
61  return $aorder;
62  }
63  }
64  }
65  return $def;
66 }
67 // return parameters key search
69 {
70  $famid = getDefFam($action);
71  $pu = $action->GetParam("GENE_LATESTTXTSEARCH");
72  if ($pu) {
73  $tu = explode("|", $pu);
74  foreach ($tu as $k => $v) {
75  list($afamid, $aorder) = explode(":", $v);
76  if ($afamid == $famid) return $aorder;
77  }
78  }
79  return "";
80 }
81 /**
82  * memorize search key for generic applications
83  * @param Action $action current action
84  * @param int $famid family identifier
85  * @param string $key key to memorize
86  * @return string
87  */
88 function setUkey(Action & $action, $famid, $key)
89 {
90 
91  $famid = getDefFam($action);
92  $dbaccess = $action->dbaccess;
93 
94  $fdoc = new_Doc($dbaccess, $famid);
95 
96  $pu = $action->GetParam("GENE_LATESTTXTSEARCH");
97  $tr = array();
98  if ($pu) {
99  // disambled parameter
100  $tu = explode("|", $pu);
101 
102  foreach ($tu as $k => $v) {
103  list($afamid, $uk) = explode(":", $v);
104  $tr[$afamid] = $uk;
105  }
106  }
107  if (trim($key) == "") unset($tr[$famid]);
108  else $tr[$famid] = $key;
109  // rebuild parameter
110  $tu = array();
111  foreach ($tr as $k => $v) {
112  $tu[] = "$k:$v";
113  }
114 
115  return implode("|", $tu);
116 }
117 /**
118  * return parameters key search
119  * @param action $action current action
120  * @param string $key parameter name
121  * return string the value of the parameter according to default family
122  */
123 function getDefU(Action & $action, $key)
124 {
125  $famid = getDefFam($action);
126  return getFamilyParameter($action, $famid, $key);
127 }
128 /**
129  * return attribute split mode
130  * @return string [V|H] vertical or horizontal split according to family
131  */
133 {
134  if ($famid == "") $famid = getDefFam($action);
135  return getFamilyParameter($action, $famid, "GENE_SPLITMODE", "V");
136 }
137 /**
138  * return attribute view mode
139  * @return string [abstract|column] according to family
140  */
141 function getViewMode(Action & $action, $famid = "")
142 {
143  if ($famid == "") $famid = getDefFam($action);
144  return getFamilyParameter($action, $famid, "GENE_VIEWMODE", "abstract");
145 }
146 /**
147  * return attribute view tab letters
148  * @return string [Y|N] Yes/No according to family
149  */
151 {
152  if ($famid == "") $famid = getDefFam($action);
153  return getFamilyParameter($action, $famid, "GENE_TABLETTER", "N");
154 }
155 /**
156  * return if search is also in inherit famileis
157  * @return string [Y|N] Yes/No according to family
158  */
159 function getInherit(Action & $action, $famid = "")
160 {
161  if ($famid == "") $famid = getDefFam($action);
162  return getFamilyParameter($action, $famid, "GENE_INHERIT", "Y");
163 }
164 /**
165  * set attribute split mode
166  * @param string $split [V|H]
167  */
168 function setSplitMode(Action & $action, $famid, $split)
169 {
170  setFamilyParameter($action, $famid, 'GENE_SPLITMODE', $split);
171 }
172 /**
173  * set attribute view mode
174  * @param string $view [abstract|column]
175  */
176 function setViewMode(&$action, $famid, $view)
177 {
178  setFamilyParameter($action, $famid, 'GENE_VIEWMODE', $view);
179 }
180 /**
181  * set attribute view tab letters
182  * @param string $letter [Y|N] Yes/No
183  */
184 function setTabLetter(&$action, $famid, $letter)
185 {
186  setFamilyParameter($action, $famid, 'GENE_TABLETTER', $letter);
187 }
188 /**
189  * set attribute view tab letters
190  * @param string $inherit [Y|N] Yes/No
191  */
192 function setInherit(&$action, $famid, $inherit)
193 {
194  setFamilyParameter($action, $famid, 'GENE_INHERIT', $inherit);
195 }
196 /**
197  * return parameters key search for all familly
198  * @param action $action current action
199  * @param string $key parameter name
200  * return array all values indexed by family id
201  */
202 function getFamilyParameters(&$action, $key)
203 {
204  $pu = $action->GetParam($key);
205  $t = array();
206  if ($pu) {
207  $tu = explode(",", $pu);
208  foreach ($tu as $k => $v) {
209  list($afamid, $aorder) = explode("|", $v);
210  $t[$afamid] = $aorder;
211  }
212  }
213  return $t;
214 }
215 /**
216  * return parameters key search
217  * @param action $action current action
218  * @param int $famid family identifier
219  * @param string $key parameter name
220  * return string the value of the parameter according to family
221  */
222 function getFamilyParameter(&$action, $famid, $key, $def = "")
223 {
224  $pu = $action->GetParam($key);
225  if ($pu) {
226  $tu = explode(",", $pu);
227  foreach ($tu as $v) {
228  if (strpos($v, '|') !== false) {
229  list($afamid, $aorder) = explode("|", $v);
230  if (!is_numeric($afamid)) {
231  $afamid = getFamIdFromName($action->dbaccess, $afamid);
232  }
233  if ($afamid == $famid) {
234  return $aorder;
235  }
236  }
237  }
238  }
239  return $def;
240 }
241 /**
242  * set family attribute for generic application
243  */
245 {
246  $tmode = explode(",", $action->getParam($attrid));
247  // explode parameters
248  foreach ($tmode as $k => $v) {
249  $values = explode("|", $v);
250  $fid = isset($values[0]) ? $values[0] : "";
251  $val = isset($values[1]) ? $values[1] : "";
252  $tview[$fid] = $val;
253  }
254  if ((!isset($tview[$famid])) || $tview[$famid] != $value) {
255  $tview[$famid] = $value;
256  // implode parameters to change user preferences
257  $tmode = array();
258  foreach ($tview as $k => $v) {
259  if ($k > 0) $tmode[] = "$k|$v";
260  }
261  $pmode = implode(",", $tmode);
262  $action->setParamU($attrid, $pmode);
263  }
264 }
265 /**
266  * delete family attribute for generic application
267  */
269 {
270  $tmode = explode(",", $action->getParam($attrid));
271  // explode parameters
272  $tview = array();
273  foreach ($tmode as $k => $v) {
274  list($fid, $val) = explode("|", $v);
275  $tview[$fid] = $val;
276  }
277  if (isset($tview[$famid]) && $tview[$famid]) {
278  unset($tview[$famid]);
279  // implode parameters to change user preferences
280  $tmode = array();
281  foreach ($tview as $k => $v) {
282  if ($k > 0) $tmode[] = "$k|$v";
283  }
284  $pmode = implode(",", $tmode);
285  $action->setParamU($attrid, $pmode);
286  }
287 }
288 // -----------------------------------
289 function getChildCatg($docid, $level, $notfldsearch = false, $maxlevel = 2)
290 {
291  // -----------------------------------
292  global $dbaccess;
293  global $action;
294 
295  $ltree = array();
296 
297  if ($level <= $maxlevel) {
298  $ldir = getChildDir($dbaccess, $action->user->id, $docid, $notfldsearch, "TABLE");
299 
300  if (count($ldir) > 0) {
301 
302  foreach ($ldir as $k => $v) {
303  $ltree[$v["id"]] = array(
304  "level" => $level * 20,
305  "id" => $v["id"],
306  "doctype" => $v["doctype"],
307  "fromid" => $v["fromid"],
308  "title" => $v["title"]
309  );
310 
311  if ($v["doctype"] == "D") $ltree = $ltree + getChildCatg($v["id"], $level + 1, $notfldsearch, $maxlevel);
312  }
313  }
314  }
315  return $ltree;
316 }
317 // -----------------------------------
319 {
320  // -----------------------------------
321  $fdoc = new_Doc($dbaccess, $docid);
322  $child = $fdoc->GetChildFam();
323  return GetSqlCond(array_merge(array(
324  $docid
325  ) , array_keys($fdoc->GetChildFam())) , "fromid");
326 }
getSplitMode(Action &$action, $famid="")
global $action
$ldir
Definition: resizeimg.php:145
setSplitMode(Action &$action, $famid, $split)
getDefUSort(Action &$action, $def="-revdate", $famid="")
getSqlFrom($dbaccess, $docid)
getDefFld(Action &$action)
setViewMode(&$action, $famid, $view)
getDefFam(Action &$action)
setParamU($name, $val)
getFamilyParameters(&$action, $key)
getViewMode(Action &$action, $famid="")
deleteFamilyParameter(Action &$action, $famid, $attrid)
$docid
Definition: cleanFamily.php:13
getChildDir($dbaccess, $userid, $dirid, $notfldsearch=false, $restype="LIST")
Definition: Lib.Dir.php:38
Read($k, $d="")
setTabLetter(&$action, $famid, $letter)
getTabLetter(Action &$action, $famid="")
getChildCatg($docid, $level, $notfldsearch=false, $maxlevel=2)
getFamIdFromName($dbaccess, $name)
new_Doc($dbaccess, $id= '', $latest=false)
setUkey(Action &$action, $famid, $key)
getFamilyParameter(&$action, $famid, $key, $def="")
GetSqlCond($Table, $column, $integer=false)
getParam($name, $def="")
getDefU(Action &$action, $key)
getDefUKey(Action &$action)
$dbaccess
Definition: checkVault.php:17
getIdFromName($dbaccess, $name)
setInherit(&$action, $famid, $inherit)
getInherit(Action &$action, $famid="")
$value
setFamilyParameter(Action &$action, $famid, $attrid, $value)
← centre documentaire © anakeen