1 |
dpavlin |
1.1 |
<? |
2 |
|
|
|
3 |
dpavlin |
1.4 |
set_magic_quotes_runtime(0); |
4 |
|
|
|
5 |
dpavlin |
1.1 |
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 |
dpavlin |
1.6 |
tlheader => "topics-list-header.html", |
21 |
dpavlin |
1.1 |
trow => "topics-row.html", |
22 |
dpavlin |
1.6 |
tlrow => "topics-list-row.html", |
23 |
dpavlin |
1.1 |
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 |
dpavlin |
1.7 |
$osoba_id=$row[id]; |
35 |
dpavlin |
1.1 |
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 |
dpavlin |
1.3 |
$tpl->assign(array( ROOM => "You are in solution room" )); |
45 |
dpavlin |
1.1 |
} |
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 |
dpavlin |
1.7 |
if ( $Count && $Count != -1 ) { |
58 |
dpavlin |
1.1 |
$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 |
dpavlin |
1.7 |
FULL_NAME => $full_name, |
70 |
dpavlin |
1.1 |
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 |
dpavlin |
1.7 |
} else { |
84 |
|
|
$dbh->dbh_do("update osobe set last_login=now() where login='$PHP_AUTH_USER'"); |
85 |
dpavlin |
1.1 |
} |
86 |
|
|
|
87 |
|
|
//---- insert reply into database |
88 |
|
|
|
89 |
|
|
if (isset($insert_reply) && isset($p)) { |
90 |
|
|
$sth=$dbh->prepare("select sadrzaj,level,thread_id,pos from poruke where id=$p"); |
91 |
|
|
$sth->execute(); |
92 |
|
|
$row=$sth->fetchrow_hash(); |
93 |
|
|
|
94 |
|
|
$thread_id=$row[thread_id]; |
95 |
|
|
if ($thread_id == 0) $thread_id=$p; // reply to top level topic |
96 |
|
|
|
97 |
|
|
$level=$row[level] + 1; |
98 |
|
|
$pos=$row[pos]; |
99 |
|
|
|
100 |
|
|
while(strlen($pos) < $level) $pos.="a"; |
101 |
|
|
$sth=$dbh->prepare("select pos from poruke where pos like '$pos'"); |
102 |
|
|
$sth->execute(); |
103 |
|
|
if ($row=$sth->fetchrow_hash()) { |
104 |
|
|
for($i=0; $i<$level; $i++) $mask.="_"; |
105 |
|
|
$sth=$dbh->prepare("select pos from poruke where thread_id=$thread_id and pos like '$mask' order by pos desc limit 1"); |
106 |
|
|
$sth->execute(); |
107 |
|
|
if ($row=$sth->fetchrow_hash()) { |
108 |
|
|
$pos=$row[pos]; |
109 |
|
|
$pos_l=substr($pos,0,strlen($pos)-1); |
110 |
|
|
$pos_r=substr($pos,strlen($pos)-1,1); |
111 |
|
|
$pos_r++; |
112 |
|
|
$pos=$pos_l.$pos_r; |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
function fix_checkbox($what) { |
117 |
|
|
if (isset($GLOBALS[$what])) { |
118 |
|
|
$GLOBALS[$what]="true"; |
119 |
|
|
} else { |
120 |
dpavlin |
1.2 |
$GLOBALS[$what]="false"; |
121 |
dpavlin |
1.1 |
} |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
fix_checkbox("analitical"); |
125 |
|
|
fix_checkbox("solution"); |
126 |
|
|
|
127 |
dpavlin |
1.2 |
$sadrzaj=trim($sadrzaj); |
128 |
|
|
$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)")); |
129 |
dpavlin |
1.1 |
|
130 |
|
|
$sth=$dbh->prepare("select currval('poruke_id_seq') as id"); |
131 |
|
|
$sth->execute(); |
132 |
|
|
|
133 |
|
|
if ($row=$sth->fetchrow_hash()) { |
134 |
|
|
$p=$row[id]; // poruka_id for later |
135 |
|
|
} |
136 |
dpavlin |
1.2 |
$what="show"; |
137 |
dpavlin |
1.1 |
|
138 |
|
|
} elseif (isset($insert_newtopic)) { |
139 |
|
|
|
140 |
|
|
//---- insert new topic into database |
141 |
|
|
|
142 |
|
|
if (isset($osoba_id)) { |
143 |
|
|
$dbh->dbh_do(fixsql("insert into poruke (thread_id,osoba_id,sadrzaj) values (0,$osoba_id,'$sadrzaj')")); |
144 |
|
|
$sth=$dbh->prepare("select currval('poruke_id_seq') as id"); |
145 |
|
|
$sth->execute(); |
146 |
|
|
if ($row=$sth->fetchrow_hash()) { |
147 |
|
|
$t=$row[id]; // topic for later |
148 |
dpavlin |
1.2 |
$title=trim($title); |
149 |
dpavlin |
1.1 |
$dbh->dbh_do(fixsql("insert into topics (id,title) values ($t,'$title')")); |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
//----- end of inserts/updates... |
155 |
|
|
|
156 |
dpavlin |
1.5 |
if (($what=="reply" || $what=="show") && isset($t)) { |
157 |
dpavlin |
1.1 |
$sql_where=" and topics.id=$t"; |
158 |
|
|
} |
159 |
|
|
|
160 |
dpavlin |
1.2 |
if ($solution_room == 1) { |
161 |
|
|
// don't limit just to topics starts |
162 |
|
|
$sql_where.=" and poruke.thread_id=topics.id and poruke.thread_id!=0"; |
163 |
|
|
} else { |
164 |
|
|
// limit just to topics start |
165 |
|
|
$sql_where.=" and poruke.id=topics.id and poruke.thread_id=0"; |
166 |
|
|
} |
167 |
|
|
|
168 |
dpavlin |
1.1 |
$sth = $dbh->prepare("select topics.id as topic_id,title,sadrzaj,full_name,poruke.datum as datum |
169 |
|
|
from topics,poruke,osobe |
170 |
dpavlin |
1.2 |
where poruke.osoba_id=osobe.id $sql_where $sql_poruke_where |
171 |
dpavlin |
1.1 |
order by datum asc |
172 |
|
|
"); |
173 |
dpavlin |
1.2 |
|
174 |
dpavlin |
1.1 |
$sth->execute(); |
175 |
|
|
$topics=""; |
176 |
|
|
while ($row=$sth->fetchrow_hash()) { |
177 |
|
|
$tpl->assign( array( |
178 |
|
|
TITLE => $row[title], |
179 |
|
|
AUTHOR => $row[full_name], |
180 |
|
|
DATE => $row[datum], |
181 |
|
|
SADRZAJ => $row[sadrzaj], |
182 |
dpavlin |
1.2 |
COMMENTS => "<a href=\"$PHP_SELF?what=show&t=$row[topic_id]\">comments>></a>", |
183 |
dpavlin |
1.1 |
PHP_SELF => $PHP_SELF |
184 |
|
|
)); |
185 |
|
|
|
186 |
|
|
if (isset($t) && $t==$row[topic_id]) { |
187 |
dpavlin |
1.6 |
$tpl->parse(ROWS,".theader"); |
188 |
dpavlin |
1.1 |
$sth2 = $dbh->prepare(" |
189 |
|
|
select poruke.id as id,sadrzaj as topic,level,thread_id,reply_id,full_name,poruke.datum as datum,poruke.analitical as poruka_analitical |
190 |
|
|
from poruke,osobe |
191 |
|
|
where (thread_id=$t or poruke.id=$t) and poruke.osoba_id=osobe.id $sql_poruke_where |
192 |
|
|
order by pos |
193 |
|
|
"); |
194 |
|
|
$sth2->execute(); |
195 |
|
|
|
196 |
|
|
while ($row2=$sth2->fetchrow_hash()) { |
197 |
|
|
$l_ul=$r_ul=""; |
198 |
|
|
for ($i=0; $i<$row2[level]; $i++) { |
199 |
|
|
$l_ul.="<ul>"; |
200 |
|
|
$r_ul.="</ul>"; |
201 |
|
|
} |
202 |
dpavlin |
1.2 |
// don't indent in solution room |
203 |
|
|
if ($solution_room == 1) { $l_ul=$r_ul=""; } |
204 |
dpavlin |
1.1 |
$tpl->assign( array( |
205 |
|
|
L_INDENT => $l_ul, |
206 |
|
|
R_INDENT => $r_ul |
207 |
|
|
)); |
208 |
|
|
$topic=trim(strip_tags($row2[topic])); |
209 |
dpavlin |
1.2 |
if (isset($p) && $p == $row2[id] && $what=="reply") { |
210 |
dpavlin |
1.1 |
$topic="<font color=red>$topic...</font>"; |
211 |
dpavlin |
1.2 |
$tpl->assign( array( P => $p, T => $t )); |
212 |
|
|
if ($analitical_room == 1) { |
213 |
|
|
$tpl->parse(CHECKBOXES, ".checkboxes"); |
214 |
|
|
} |
215 |
dpavlin |
1.1 |
$tpl->parse(REPLY, ".reply"); |
216 |
dpavlin |
1.2 |
} elseif (isset($p) && $p == $row2[id]) { |
217 |
|
|
$topic="<font color=red>$topic...</font>"; |
218 |
|
|
$tpl->assign( array( P => $p, T => $t )); |
219 |
dpavlin |
1.1 |
} else { |
220 |
|
|
if (!isset($p)) { $p=$t; } |
221 |
|
|
$tmp_t=$row2[thread_id]; |
222 |
|
|
if ($tmp_t == 0) { $tmp_t=$row2[id]; } |
223 |
|
|
$tpl->assign( array( |
224 |
|
|
REPLY => "<a href=\"$PHP_SELF?what=reply&p=$row2[id]&t=$tmp_t\">reply</a>" |
225 |
|
|
)); |
226 |
|
|
} |
227 |
|
|
$this.="<br>"; |
228 |
|
|
|
229 |
|
|
if ($row2[poruka_analitical] == "t") { |
230 |
|
|
$topic="<i>$topic</i>"; |
231 |
|
|
} |
232 |
|
|
|
233 |
|
|
$tpl->assign( array( |
234 |
|
|
AUTHOR => $row2[full_name], |
235 |
|
|
DATE => $row2[datum], |
236 |
|
|
SADRZAJ => $topic |
237 |
|
|
)); |
238 |
|
|
$tpl->parse(ROWS,".trow"); |
239 |
|
|
} |
240 |
|
|
} else { |
241 |
dpavlin |
1.6 |
// non-unroll topics (list) |
242 |
dpavlin |
1.1 |
$tpl->assign( array( |
243 |
|
|
SADRZAJ => $row[sadrzaj], |
244 |
dpavlin |
1.2 |
COMMENTS => "<a href=\"$PHP_SELF?what=show&t=$row[topic_id]\">comments>></a>" |
245 |
dpavlin |
1.1 |
)); |
246 |
dpavlin |
1.6 |
$tpl->parse(ROWS,".tlheader"); |
247 |
|
|
$tpl->parse(ROWS,".tlrow"); |
248 |
dpavlin |
1.1 |
} |
249 |
|
|
|
250 |
|
|
} |
251 |
|
|
$tpl->parse(TOPIC_LIST, "ttable"); |
252 |
|
|
|
253 |
|
|
$tpl->assign( array( |
254 |
|
|
PHP_SELF => $PHP_SELF, |
255 |
|
|
TITLE => "List of topics" |
256 |
|
|
) ); |
257 |
|
|
|
258 |
|
|
if ($what != "new") { |
259 |
|
|
$tpl->parse(START_NEW_TOPIC, "startnew"); |
260 |
|
|
} |
261 |
|
|
$tpl->parse(MAIN, "listall"); |
262 |
|
|
if ($what == "new") { |
263 |
|
|
$tpl->parse(MAIN, ".newtopic"); |
264 |
|
|
$tpl->assign(array( TITLE => "Start of new topic" )); |
265 |
dpavlin |
1.2 |
} elseif ($what == "show") { |
266 |
|
|
$tpl->assign(array( |
267 |
|
|
TITLE => "Select article for reply", |
268 |
|
|
P => $p |
269 |
|
|
)); |
270 |
dpavlin |
1.1 |
} elseif ($what == "reply") { |
271 |
|
|
$tpl->assign(array( |
272 |
|
|
TITLE => "Reply to selected article", |
273 |
|
|
P => $p |
274 |
|
|
)); |
275 |
|
|
} |
276 |
|
|
$tpl->parse(MAIN, "main"); |
277 |
|
|
|
278 |
|
|
$tpl->FastPrint(); |
279 |
|
|
|
280 |
|
|
#include("debug.inc"); |
281 |
|
|
|
282 |
|
|
?> |