1 |
<? |
2 |
|
3 |
set_magic_quotes_runtime(0); |
4 |
|
5 |
include("inc/class.FastTemplate.pinc"); |
6 |
include("inc/conn.inc"); |
7 |
include("inc/fixsql.inc"); |
8 |
|
9 |
$tpl = new FastTemplate("./html"); |
10 |
|
11 |
$tpl->define( |
12 |
array( |
13 |
main => "main.html", |
14 |
nologin => "nologin.html", |
15 |
listall => "list.html", |
16 |
newtopic => "new.html", |
17 |
startnew => "startnew.html", |
18 |
ttable => "topics-table.html", |
19 |
theader => "topics-header.html", |
20 |
tlheader => "topics-list-header.html", |
21 |
trow => "topics-row.html", |
22 |
tlrow => "topics-list-row.html", |
23 |
reply => "reply.html", |
24 |
checkboxes => "checkboxes.html" |
25 |
) |
26 |
); |
27 |
|
28 |
if (isset($PHP_AUTH_USER)) { |
29 |
$sth = $dbh->prepare("select id,login,passwd,full_name,analitical,solution from osobe where login like '$PHP_AUTH_USER'"); |
30 |
$sth->execute(); |
31 |
if ($row=$sth->fetchrow_hash()) { |
32 |
if ($row && $row[passwd] == $PHP_AUTH_PW) { |
33 |
$md5user=md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
34 |
$osoba_id=$row[id]; |
35 |
if ($row[analitical] == "t") { |
36 |
$analitical_room=1; |
37 |
$tpl->assign(array( ROOM => "You are member of analitical room" )); |
38 |
} else { |
39 |
$sql_poruke_where.="and poruke.analitical is false"; |
40 |
} |
41 |
if ($row[solution] == "t") { |
42 |
$solution_room=1; |
43 |
$sql_poruke_where.="and poruke.solution is true"; |
44 |
$tpl->assign(array( ROOM => "You are in solution room" )); |
45 |
} |
46 |
$tpl->assign(array( |
47 |
FULL_NAME => $row[full_name], |
48 |
RELOGIN => "$PHP_SELF?relogin=$md5user" |
49 |
)); |
50 |
} |
51 |
} else { // try to verify user via pop3 |
52 |
include("class.POP3.php3"); |
53 |
$pop3 = new POP3(); |
54 |
|
55 |
if($pop3->connect("intranet.pliva.hr")) { |
56 |
$Count = $pop3->login($PHP_AUTH_USER,$PHP_AUTH_PW); |
57 |
if ( $Count != -1 ) { |
58 |
$pop3->quit(); |
59 |
// o.k., user exists now insert it in db! |
60 |
include("finger.inc"); |
61 |
$full_name=finger($PHP_AUTH_USER); |
62 |
$dbh->dbh_do("insert into osobe (login,full_name,email,passwd) values ('$PHP_AUTH_USER','$full_name','$PHP_AUTH_USER@pliva.hr','$PHP_AUTH_PW')"); |
63 |
$sth = $dbh->prepare("select last_value as id from osobe_id_seq"); |
64 |
$sth->execute(); |
65 |
$row=$sth->fetchrow_hash(); |
66 |
$md5user=md5($PHP_AUTH_USER.$PHP_AUTH_PW); |
67 |
$osoba_id=$row[id]; |
68 |
$tpl->assign(array( |
69 |
FULL_NAME => $row[full_name], |
70 |
RELOGIN => "$PHP_SELF?relogin=$md5user" |
71 |
)); |
72 |
} |
73 |
} |
74 |
} |
75 |
} |
76 |
if (md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $md5user || isset($relogin) && $md5user == $relogin ) { |
77 |
header("WWW-authenticate: basic realm=\"Innovation Commitie\"") ; |
78 |
header("HTTP/1.0 401 Unauthorized") ; |
79 |
$tpl->parse(MAIN, "nologin"); |
80 |
$tpl->parse(MAIN, "main"); |
81 |
$tpl->FastPrint(); |
82 |
exit ; |
83 |
} |
84 |
|
85 |
//---- insert reply into database |
86 |
|
87 |
if (isset($insert_reply) && isset($p)) { |
88 |
$sth=$dbh->prepare("select sadrzaj,level,thread_id,pos from poruke where id=$p"); |
89 |
$sth->execute(); |
90 |
$row=$sth->fetchrow_hash(); |
91 |
|
92 |
$thread_id=$row[thread_id]; |
93 |
if ($thread_id == 0) $thread_id=$p; // reply to top level topic |
94 |
|
95 |
$level=$row[level] + 1; |
96 |
$pos=$row[pos]; |
97 |
|
98 |
while(strlen($pos) < $level) $pos.="a"; |
99 |
$sth=$dbh->prepare("select pos from poruke where pos like '$pos'"); |
100 |
$sth->execute(); |
101 |
if ($row=$sth->fetchrow_hash()) { |
102 |
for($i=0; $i<$level; $i++) $mask.="_"; |
103 |
$sth=$dbh->prepare("select pos from poruke where thread_id=$thread_id and pos like '$mask' order by pos desc limit 1"); |
104 |
$sth->execute(); |
105 |
if ($row=$sth->fetchrow_hash()) { |
106 |
$pos=$row[pos]; |
107 |
$pos_l=substr($pos,0,strlen($pos)-1); |
108 |
$pos_r=substr($pos,strlen($pos)-1,1); |
109 |
$pos_r++; |
110 |
$pos=$pos_l.$pos_r; |
111 |
} |
112 |
} |
113 |
|
114 |
function fix_checkbox($what) { |
115 |
if (isset($GLOBALS[$what])) { |
116 |
$GLOBALS[$what]="true"; |
117 |
} else { |
118 |
$GLOBALS[$what]="false"; |
119 |
} |
120 |
} |
121 |
|
122 |
fix_checkbox("analitical"); |
123 |
fix_checkbox("solution"); |
124 |
|
125 |
$sadrzaj=trim($sadrzaj); |
126 |
$dbh->dbh_do(fixsql("insert into poruke (thread_id,reply_id,osoba_id,sadrzaj,level,pos,analitical,solution) values ($thread_id,$p,$osoba_id,'$sadrzaj',$level,'$pos',$analitical,$solution)")); |
127 |
|
128 |
$sth=$dbh->prepare("select currval('poruke_id_seq') as id"); |
129 |
$sth->execute(); |
130 |
|
131 |
if ($row=$sth->fetchrow_hash()) { |
132 |
$p=$row[id]; // poruka_id for later |
133 |
} |
134 |
$what="show"; |
135 |
|
136 |
} elseif (isset($insert_newtopic)) { |
137 |
|
138 |
//---- insert new topic into database |
139 |
|
140 |
if (isset($osoba_id)) { |
141 |
$dbh->dbh_do(fixsql("insert into poruke (thread_id,osoba_id,sadrzaj) values (0,$osoba_id,'$sadrzaj')")); |
142 |
$sth=$dbh->prepare("select currval('poruke_id_seq') as id"); |
143 |
$sth->execute(); |
144 |
if ($row=$sth->fetchrow_hash()) { |
145 |
$t=$row[id]; // topic for later |
146 |
$title=trim($title); |
147 |
$dbh->dbh_do(fixsql("insert into topics (id,title) values ($t,'$title')")); |
148 |
} |
149 |
} |
150 |
} |
151 |
|
152 |
//----- end of inserts/updates... |
153 |
|
154 |
if (($what=="reply" || $what=="show") && isset($t)) { |
155 |
$sql_where=" and topics.id=$t"; |
156 |
} |
157 |
|
158 |
if ($solution_room == 1) { |
159 |
// don't limit just to topics starts |
160 |
$sql_where.=" and poruke.thread_id=topics.id and poruke.thread_id!=0"; |
161 |
} else { |
162 |
// limit just to topics start |
163 |
$sql_where.=" and poruke.id=topics.id and poruke.thread_id=0"; |
164 |
} |
165 |
|
166 |
$sth = $dbh->prepare("select topics.id as topic_id,title,sadrzaj,full_name,poruke.datum as datum |
167 |
from topics,poruke,osobe |
168 |
where poruke.osoba_id=osobe.id $sql_where $sql_poruke_where |
169 |
order by datum asc |
170 |
"); |
171 |
|
172 |
$sth->execute(); |
173 |
$topics=""; |
174 |
while ($row=$sth->fetchrow_hash()) { |
175 |
$tpl->assign( array( |
176 |
TITLE => $row[title], |
177 |
AUTHOR => $row[full_name], |
178 |
DATE => $row[datum], |
179 |
SADRZAJ => $row[sadrzaj], |
180 |
COMMENTS => "<a href=\"$PHP_SELF?what=show&t=$row[topic_id]\">comments>></a>", |
181 |
PHP_SELF => $PHP_SELF |
182 |
)); |
183 |
|
184 |
if (isset($t) && $t==$row[topic_id]) { |
185 |
$tpl->parse(ROWS,".theader"); |
186 |
$sth2 = $dbh->prepare(" |
187 |
select poruke.id as id,sadrzaj as topic,level,thread_id,reply_id,full_name,poruke.datum as datum,poruke.analitical as poruka_analitical |
188 |
from poruke,osobe |
189 |
where (thread_id=$t or poruke.id=$t) and poruke.osoba_id=osobe.id $sql_poruke_where |
190 |
order by pos |
191 |
"); |
192 |
$sth2->execute(); |
193 |
|
194 |
while ($row2=$sth2->fetchrow_hash()) { |
195 |
$l_ul=$r_ul=""; |
196 |
for ($i=0; $i<$row2[level]; $i++) { |
197 |
$l_ul.="<ul>"; |
198 |
$r_ul.="</ul>"; |
199 |
} |
200 |
// don't indent in solution room |
201 |
if ($solution_room == 1) { $l_ul=$r_ul=""; } |
202 |
$tpl->assign( array( |
203 |
L_INDENT => $l_ul, |
204 |
R_INDENT => $r_ul |
205 |
)); |
206 |
$topic=trim(strip_tags($row2[topic])); |
207 |
if (isset($p) && $p == $row2[id] && $what=="reply") { |
208 |
$topic="<font color=red>$topic...</font>"; |
209 |
$tpl->assign( array( P => $p, T => $t )); |
210 |
if ($analitical_room == 1) { |
211 |
$tpl->parse(CHECKBOXES, ".checkboxes"); |
212 |
} |
213 |
$tpl->parse(REPLY, ".reply"); |
214 |
} elseif (isset($p) && $p == $row2[id]) { |
215 |
$topic="<font color=red>$topic...</font>"; |
216 |
$tpl->assign( array( P => $p, T => $t )); |
217 |
} else { |
218 |
if (!isset($p)) { $p=$t; } |
219 |
$tmp_t=$row2[thread_id]; |
220 |
if ($tmp_t == 0) { $tmp_t=$row2[id]; } |
221 |
$tpl->assign( array( |
222 |
REPLY => "<a href=\"$PHP_SELF?what=reply&p=$row2[id]&t=$tmp_t\">reply</a>" |
223 |
)); |
224 |
} |
225 |
$this.="<br>"; |
226 |
|
227 |
if ($row2[poruka_analitical] == "t") { |
228 |
$topic="<i>$topic</i>"; |
229 |
} |
230 |
|
231 |
$tpl->assign( array( |
232 |
AUTHOR => $row2[full_name], |
233 |
DATE => $row2[datum], |
234 |
SADRZAJ => $topic |
235 |
)); |
236 |
$tpl->parse(ROWS,".trow"); |
237 |
} |
238 |
} else { |
239 |
// non-unroll topics (list) |
240 |
$tpl->assign( array( |
241 |
SADRZAJ => $row[sadrzaj], |
242 |
COMMENTS => "<a href=\"$PHP_SELF?what=show&t=$row[topic_id]\">comments>></a>" |
243 |
)); |
244 |
$tpl->parse(ROWS,".tlheader"); |
245 |
$tpl->parse(ROWS,".tlrow"); |
246 |
} |
247 |
|
248 |
} |
249 |
$tpl->parse(TOPIC_LIST, "ttable"); |
250 |
|
251 |
$tpl->assign( array( |
252 |
PHP_SELF => $PHP_SELF, |
253 |
TITLE => "List of topics" |
254 |
) ); |
255 |
|
256 |
if ($what != "new") { |
257 |
$tpl->parse(START_NEW_TOPIC, "startnew"); |
258 |
} |
259 |
$tpl->parse(MAIN, "listall"); |
260 |
if ($what == "new") { |
261 |
$tpl->parse(MAIN, ".newtopic"); |
262 |
$tpl->assign(array( TITLE => "Start of new topic" )); |
263 |
} elseif ($what == "show") { |
264 |
$tpl->assign(array( |
265 |
TITLE => "Select article for reply", |
266 |
P => $p |
267 |
)); |
268 |
} elseif ($what == "reply") { |
269 |
$tpl->assign(array( |
270 |
TITLE => "Reply to selected article", |
271 |
P => $p |
272 |
)); |
273 |
} |
274 |
$tpl->parse(MAIN, "main"); |
275 |
|
276 |
$tpl->FastPrint(); |
277 |
|
278 |
#include("debug.inc"); |
279 |
|
280 |
?> |