Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
faddbook_main.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  * Freedom Address Book
9  *
10  * @author Anakeen 2000
11  * @version $Id: faddbook_main.php,v 1.27 2008/08/14 09:59:14 eric Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  * @subpackage USERCARD
15  */
16 /**
17  */
18 
19 include_once ("FDL/freedom_util.php");
20 include_once ("FDL/Lib.Dir.php");
21 /**
22  * View list of document for a same family
23  * @param Action &$action current action
24  * @global chgAttr Http var :
25  * @global chgId Http var :
26  * @global chgValue Http var :
27  * @global usedefaultview Http var : (Y|N) set Y if detail doc must be displayed with default view
28  * @global etarget Http var : window target when edit doc
29  * @global target Http var : window target when view doc
30  * @global dirid Http var : folder/search id to restric searches
31  * @global cols Http var : attributes id for column like : us_fname|us_lname
32  * @global viewone Http var : (Y|N) set Y if want display detail doc if only one found
33  * @global createsubfam Http var : (Y|N) set N if no want view possibility to create subfamily
34  */
36 {
37  global $_POST;
38 
39  $rqi_form = array();
40  foreach ($_POST as $k => $v) {
41  if (substr($k, 0, 4) == "rqi_") $rqi_form[substr($k, 4) ] = $v;
42  }
43 
44  $dbaccess = $action->getParam("FREEDOM_DB");
45  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
46 
47  $pstart = GetHttpVars("sp", 0);
48  $action->lay->set("choosecolumn", ($action->Haspermission("USERCARD_MANAGER", "USERCARD") == 1 ? true : false));
49  $chattr = GetHttpVars("chgAttr", "");
50  $chid = GetHttpVars("chgId", "");
51  $chval = GetHttpVars("chgValue", "");
52  $usedefaultview = (GetHttpVars("usedefaultview", "N") == "Y");
53  $viewone = (GetHttpVars("viewone", "N") == "Y");
54  $createsubfam = (GetHttpVars("createsubfam", "N") == "Y");
55  $etarget = GetHttpVars("etarget");
56  $target = GetHttpVars("target", "bookinfo");
57  $dirid = GetHttpVars("dirid"); // restrict search
58  $cols = GetHttpVars("cols"); // specific cols
59  if ($chattr != "" && $chid != "") {
60  $mdoc = new_Doc($dbaccess, $chid);
61  $mdoc->setValue($chattr, $chval);
62  $err = $mdoc->Modify();
63  if ($err == "") AddWarningMsg($mdoc->title . " modifié (" . $mdoc->getAttribute($chattr)->getLabel() . " : " . $chval . ")");
64  }
65  $action->lay->set("viewpref", ($cols == ""));
66  // Init page lines
67  $lpage = $action->getParam("FADDBOOK_MAINLINE", 25);
68  $action->lay->set("linep", $lpage);
69  $choicel = array(
70  10,
71  25,
72  50
73  );
74  foreach ($choicel as $k => $v) {
75  $tl[] = array(
76  "count" => $v,
77  "init" => ($lpage == $v ? "selected" : "")
78  );
79  }
80  $action->lay->setBlockData("BLine", $tl);
81  // propagate HTTP vars parameters
82  $action->lay->set("sp", $pstart);
83  $action->lay->set("lp", $lpage);
84  $action->lay->set("target", $target);
85  $action->lay->set("dirid", $dirid);
86  $action->lay->set("etarget", $etarget);
87  $action->lay->set("createsubfam", GetHttpVars("createsubfam"));
88  $action->lay->set("usedefaultview", GetHttpVars("usedefaultview"));
89  $action->lay->set("viewone", GetHttpVars("viewone"));
90  $action->lay->set("cols", GetHttpVars("cols"));
91  $action->lay->set("", GetHttpVars("cols"));
92 
93  $sfullsearch = (GetHttpVars("sfullsearch", "") == "on" ? true : false);
94  $action->lay->set("fullsearch", $sfullsearch);
95 
96  $sfam = GetHttpVars("dfam", $action->getParam("USERCARD_FIRSTFAM"));
97  $action->lay->set("dfam", $sfam);
98  $dnfam = new_Doc($dbaccess, $sfam);
99  $action->lay->set("famid", $dnfam->id);
100  $action->lay->set("famsearch", mb_convert_case(mb_strtolower($dnfam->title) , MB_CASE_TITLE));
101  $dfam = createDoc($dbaccess, $sfam, false);
102  $fattr = $dfam->GetAttributes();
103  // Get user configuration
104  $ucols = array();
105  if ($cols) {
106  $tccols = explode("|", $cols);
107  foreach ($tccols as $k => $v) $ucols[$v] = 1;
108  $action->lay->set("choosecolumn", false); // don't see choose column
109 
110  } else {
111  $pc = $action->getParam("FADDBOOK_MAINCOLS", "");
112  if ($pc != "") {
113  $tccols = explode("|", $pc);
114  foreach ($tccols as $k => $v) {
115  if ($v == "") continue;
116  $x = explode("%", $v);
117  if ($sfam == $x[0]) $ucols[$x[1]] = 1;
118  }
119  }
120  if (count($ucols) == 0) {
121  // default abstract
122  $la = $dnfam->getAbstractAttributes();
123  foreach ($la as $k => $v) {
124  if (($v->mvisibility != 'H') && ($v->mvisibility != 'I')) $ucols[$v->id] = 1;
125  }
126  }
127  }
128  // add sub families for creation
129  $child = array();
130  if (($dnfam->control("create") == "") && ($dnfam->control("icreate") == "")) {
131  $child[$famid] = array(
132  "title" => $dnfam->title,
133  "id" => $dnfam->id
134  );
135  } else $child = array();
136 
137  if ($createsubfam) {
138  $child+= $dnfam->GetChildFam($dnfam->id, true);
139  $action->lay->set("viewsubfam", count($child) > 1);
140  $action->lay->setBlockData("NEW", $child);
141  $fc = current($child);
142  $action->lay->set("famid", $fc["id"]);
143  $action->lay->set("famsearch", mb_convert_case(mb_strtolower($fc["title"]) , MB_CASE_TITLE));
144  } else {
145  $action->lay->set("viewsubfam", false);
146  }
147 
148  $action->lay->set("cancreate", count($child) > 0);
149  $orderby = "title";
150 
151  $cols = 0;
152  $filter = array();
153  $td = array();
154  $sf = "";
155  $clabel = mb_convert_case(mb_strtolower($dnfam->title) , MB_CASE_TITLE);
156  if (isset($rqi_form["__ititle"]) && $rqi_form["__ititle"] != "" && $rqi_form["__ititle"] != $clabel) {
157  if ($sfullsearch) $filter[] = "( title ~* '" . $rqi_form["__ititle"] . "' ) ";
158  else $filter[] = "( title ~* '^" . $rqi_form["__ititle"] . "' ) ";
159  $sf = $rqi_form["__ititle"];
160  }
161  $td[] = array(
162  "ATTimage" => false,
163  "ATTnormal" => true,
164  "id" => "__ititle",
165  "label" => ($sf == "" ? $clabel : "$sf") ,
166  "filter" => ($sf == "" ? false : true) ,
167  "firstCol" => false
168  );
169  $cols++;
170 
171  $vattr = array();
172  foreach ($fattr as $k => $v) {
173  if ($v->type != "menu" && $v->type != "frame") {
174  if (isset($ucols[$v->id]) && $ucols[$v->id] == 1) {
175  $sf = "";
176  $clabel = mb_convert_case(mb_strtolower($v->getLabel()) , MB_CASE_TITLE);
177  $vattr[] = $v;
178  $attimage = $attnormal = false;
179  switch ($v->type) {
180  case "image":
181  $attimage = true;
182  break;
183 
184  default:
185  $attnormal = true;
186  }
187  if (isset($rqi_form[$v->id]) && $rqi_form[$v->id] != "" && $rqi_form[$v->id] != $clabel) {
188  $filter[] = "( " . $v->id . " ~* '" . $rqi_form[$v->id] . "' ) ";
189  $sf = $rqi_form[$v->id];
190  }
191  $td[] = array(
192  "ATTimage" => $attimage,
193  "ATTnormal" => $attnormal,
194  "id" => $v->id,
195  "label" => ($sf == "" ? $clabel : "$sf") ,
196  "filter" => ($sf == "" ? false : true) ,
197  "firstCol" => false
198  );
199  $cols++;
200  }
201  }
202  $action->lay->SetBlockData("COLS", $td);
203  }
204 
205  $psearch = $pstart * $lpage;
206  $fsearch = $psearch + $lpage + 1;
207  $cl = $rq = getChildDoc($dbaccess, $dirid, $psearch, $fsearch, $filter, $action->user->id, "TABLE", $sfam, false, "title");
208 
209  $dline = array();
210  $il = 0;
211 
212  $action->lay->set("idone", ($viewone && (count($cl) == 1)) ? $cl[0]["id"] : false);
213 
214  foreach ($cl as $k => $v) {
215  if ($il >= $lpage) continue;
216  $dcol = array();
217  $ddoc = getDocObject($dbaccess, $v);
218  $attchange = ($ddoc->Control("edit") == "" ? true : false);
219  $dcol[] = array(
220  "ATTchange" => false,
221  "ATTname" => "",
222  "content" => mb_convert_case(mb_strtolower($v["title"]) , MB_CASE_TITLE) ,
223  "ATTimage" => false,
224  "ATTnormal" => true
225  );
226  foreach ($vattr as $ka => $va) {
227  $attimage = $attnormal = false;
228  switch ($va->type) {
229  case "image":
230  $attimage = true;
231  break;
232 
233  default:
234  $attnormal = true;
235  }
236  $dcol[] = array(
237  "ATTchange" => false,
238  "content" => $ddoc->GetHtmlAttrValue($va->id, "faddbook_blanck", false) ,
239  "cid" => $v["id"],
240  "ATTimage" => $attimage,
241  "ATTnormal" => $attnormal,
242  "ATTname" => $va->id
243  );
244  }
245  $action->lay->setBlockData("C$il", $dcol);
246  $dline[$il]["cid"] = $v["id"];
247  $dline[$il]["fabzone"] = $pzone;
248  $dline[$il]["canChange"] = $attchange;
249  $dline[$il]["fabzone"] = $pzone;
250  $dline[$il]["etarget"] = ($etarget) ? $etarget : "edit" . $v["id"];
251  $dline[$il]["title"] = mb_convert_case(mb_strtolower($v["title"]) , MB_CASE_TITLE);
252  $dline[$il]["Line"] = $il;
253  $dline[$il]["icop"] = $dnfam->GetIcon($v["icon"]);
254  $il++;
255  }
256  $pzone = ((!$usedefaultview) && isset($ddoc->faddbook_card)) ? $ddoc->faddbook_card : "";
257  $action->lay->set("fabzone", $pzone);
258 
259  $action->lay->setBlockData("DLines", $dline);
260  $action->lay->set("colspan", ($cols + 2));
261 
262  $action->lay->set("NextPage", false);
263  $action->lay->set("PrevPage", false);
264  if (count($cl) > $lpage) {
265  $action->lay->set("NextPage", true);
266  $action->lay->set("pnext", ($pstart + 1));
267  }
268  if ($pstart > 0) {
269  $action->lay->set("PrevPage", true);
270  $action->lay->set("sp", ($pstart - 1));
271  $action->lay->set("pprev", ($pstart - 1));
272  }
273  $action->lay->set("dirtitle", "");
274  if ($dirid > 0) {
275  $fdoc = new_doc($dbaccess, $dirid);
276  $action->lay->set("dirtitle", $fdoc->title);
277  }
278 }
279 ?>
← centre documentaire © anakeen - published under CC License - Dynacase