Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Method.Forum.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  * Image document
9  *
10  * @author Anakeen 2000
11  * @version $Id: Method.Forum.php,v 1.11 2007/10/16 16:17:46 marc 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  * @begin-method-ignore
20  * this part will be deleted when construct document class until end-method-ignore
21  */
22 class _FORUM extends Doc
23 {
24  /*
25  * @end-method-ignore
26  */
27  var $defaultview = "FDL:FORUM_VIEW:T";
28  var $defaultedit = "FDL:FORUM_VIEW:S";
29  var $specialmenu = "FDL:FDL_FORUMMENU";
30 
31  function getEntryId()
32  {
33  $dids = $this->getTValue("forum_d_id");
34  $max = 0;
35  foreach ($dids as $k => $v) $max = ($v > $max ? $v : $max);
36  $max++;
37  return $max;
38  }
39 
40  function forum_view()
41  {
42  global $action;
43 
44  setHttpVar("fid", $this->id);
45  $start = GetHttpVars("start", -1);
46  $this->lay->set("viewall", ($start == - 1 ? true : false));
47 
48  $action->parent->AddCssRef("FDL:forum.css", true);
49  $action->parent->AddJsRef("FDL:forum.js", true);
50  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDC/Layout/inserthtml.js");
51 
52  $entries = $this->getentries();
53  foreach ($entries as $k => $v) {
54  if (($start == - 1 && $v["prev"] == - 1) || ($start != - 1 && $start == $v["id"])) {
55  $el[] = array(
56  "fid" => $this->id,
57  "eid" => $v["id"]
58  );
59  }
60  }
61  $this->lay->setBlockData("entry_list", $el);
62  $this->lay->set("title", $this->getTitle());
63  $this->lay->set("opened", $this->canAnswer());
64  $this->lay->set("docid", $this->getValue("forum_docid"));
65  return;
66  }
67 
68  function removeentry($eid)
69  {
70 
71  $le = array(
72  $eid
73  );
74  $this->getsubentry($eid, $le);
75 
76  $t_id = $this->getTValue("forum_d_id");
77  $t_lid = $this->getTValue("forum_d_link");
78  $t_userid = $this->getTValue("forum_d_userid");
79  $t_user = $this->getTValue("forum_d_user");
80  $t_mail = $this->getTValue("forum_d_usermail");
81  $t_text = $this->getTValue("forum_d_text");
82  $t_flag = $this->getTValue("forum_d_flag");
83  $t_date = $this->getTValue("forum_d_date");
84 
85  $this->deleteValue("forum_d_id");
86  $this->deleteValue("forum_d_link");
87  $this->deleteValue("forum_d_userid");
88  $this->deleteValue("forum_d_user");
89  $this->deleteValue("forum_d_usermail");
90  $this->deleteValue("forum_d_text");
91  $this->deleteValue("forum_d_flag");
92  $this->deleteValue("forum_d_date");
93 
94  $nt_id = array();
95  $nt_lid = array();
96  $nt_userid = array();
97  $nt_user = array();
98  $nt_mail = array();
99  $nt_text = array();
100  $nt_flag = array();
101  $nt_date = array();
102  // print_r2($le);
103  $nc = 0;
104  foreach ($t_id as $k => $v) {
105  if (!in_array($v, $le)) {
106  // echo "je garde $v <br>";
107  $nt_id[$nc] = $t_id[$k];
108  $nt_lid[$nc] = $t_lid[$k];
109  $nt_userid[$nc] = $t_userid[$k];
110  $nt_user[$nc] = $t_user[$k];
111  $nt_mail[$nc] = $t_mail[$k];
112  $nt_text[$nc] = $t_text[$k];
113  $nt_flag[$nc] = $t_flag[$k];
114  $nt_date[$nc] = $t_date[$k];
115  $nc++;
116  } else {
117  // echo " --------> je supprime $v <br>";
118 
119  }
120  }
121 
122  $this->setValue("forum_d_id", $nt_id);
123  $this->setValue("forum_d_link", $nt_lid);
124  $this->setValue("forum_d_userid", $nt_userid);
125  $this->setValue("forum_d_user", $nt_user);
126  $this->setValue("forum_d_usermail", $nt_usermail);
127  $this->setValue("forum_d_text", $nt_text);
128  $this->setValue("forum_d_flag", $nt_flag);
129  $this->setValue("forum_d_date", $nt_date);
130 
131  $err = $this->modify(true, array(
132  "forum_d_id",
133  "forum_d_link",
134  "forum_d_userid",
135  "forum_d_user",
136  "forum_d_usermail",
137  "forum_d_text",
138  "forum_d_flag",
139  "forum_d_date"
140  ));
141  // echo "$err";
142  return;
143  }
144 
145  function getsubentry($top, &$le, $level = "")
146  {
147 
148  $level.= "-";
149  $lentries = $this->getentries();
150  foreach ($lentries[$top]["next"] as $k => $v) {
151  // echo $level." ".$v." (".$lentries[$v]["prev"].")<br>";
152  $le[count($le) ] = $v;
153  $this->getsubentry($v, $le, $level);
154  }
155  return;
156  }
157 
158  function getentries()
159  {
160  global $action;
161  static $elist = false;
162 
163  if ($elist !== false) return $elist;
164 
165  $elist = array();
166 
167  $docid = $this->getValue("forum_docid");
168  $t_id = $this->getTValue("forum_d_id");
169  $t_lid = $this->getTValue("forum_d_link");
170  $t_userid = $this->getTValue("forum_d_userid");
171  $t_user = $this->getTValue("forum_d_user");
172  $t_mail = $this->getTValue("forum_d_usermail");
173  $t_text = $this->getTValue("forum_d_text");
174  $t_flag = $this->getTValue("forum_d_flag");
175  $t_date = $this->getTValue("forum_d_date");
176 
177  $fopened = $this->canAnswer();
178  foreach ($t_id as $k => $v) {
179 
180  $next = array();
181  $prev = - 1;
182 
183  foreach ($t_id as $ki => $vi) {
184  if ($t_lid[$ki] == $v) $next[] = $vi;
185  if ($vi == $t_lid[$k]) $prev = $vi;
186  }
187 
188  $elist[$v] = array(
189  "id" => $v,
190  "docid" => $docid,
191  "next" => $next,
192  "prev" => $prev,
193  "whoid" => $t_userid[$k],
194  "who" => $t_user[$k], // ." [eid:".$v."|link:".$t_lid[$k]."]",
195  "mail" => $t_mail[$k],
196  "havemail" => ($t_mail[$k] == "" ? false : true) ,
197  "content" => nl2br($t_text[$k]) ,
198  "date" => $t_date[$k],
199  "flag" => $t_flag[$k],
200  "editable" => ($this->locked != - 1 && count($next) == 0 && $fopened && $action->user->fid == $t_userid[$k] ? true : false) ,
201  "opened" => $fopened,
202  );
203  }
204  return $elist;
205  }
206 
207  function canAnswer()
208  {
209  static $doc = false;
210  if ($doc === false) {
211  $doc = new_Doc($this->dbaccess, $this->getValue("forum_docid"));
212  }
213  if (intval($doc->forumid) < 0) return false;
214  if ($this->locked != - 1 && ($doc->Control("forum") == "" || $doc->Control("edit") == "")) return true;
215 
216  return false;
217  }
218  /**
219  * @begin-method-ignore
220  * this part will be deleted when construct document class until end-method-ignore
221  */
222 }
223 /*
224  * @end-method-ignore
225 */
226 ?>
← centre documentaire © anakeen - published under CC License - Dynacase