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