Commit | Line | Data |
---|---|---|
bc13d5d6 H |
1 | <?php |
2 | ||
3 | switch ($_POST['event']) { | |
4 | case 'filtrovat': | |
5 | $set=$kyberia->query("select * from user where login='$_POST[mail_from]'"); | |
6 | if ($set->getNumRows()) { | |
7 | $set->next(); | |
8 | header("Location: ?action=posta&from=".$set->getString("id")."&limit=$_POST[limit]"); | |
9 | exit(); | |
10 | } | |
11 | $error = "Co tak zadat spravne meno?"; | |
12 | break; | |
13 | ||
14 | case 'poslat': | |
15 | ||
16 | //do not send a message when limit number is changed | |
17 | if ($user_amount!=$limit) { | |
18 | $count=post_eventz::cachePost(); | |
19 | } | |
20 | ||
21 | else { | |
22 | $status=post_eventz::send(); | |
23 | if ($status) { | |
24 | Header("Location:".SCRIPT."?action=posta&nocache=".time()); | |
25 | } | |
26 | } | |
27 | break; | |
28 | ||
29 | case 'zmazat': | |
30 | post_eventz::delete(); | |
31 | ||
32 | Header("Location:".SCRIPT."?action=posta".(is_numeric($_GET['from']) ? "&from={$_GET[from]}" : '')); | |
33 | break; | |
34 | ||
35 | case 'vymaz vsetko': | |
36 | post_eventz::deleteAll(); | |
37 | ||
38 | header("Location: ?action=posta"); | |
39 | exit(); | |
40 | break; | |
41 | ||
42 | case ('<<' or '>>' or '>' or '<'): | |
43 | $count=post_eventz::cachePost(); | |
44 | break; | |
45 | } | |
46 | ||
47 | ||
48 | class post_eventz { | |
49 | ||
50 | function cachePost() { | |
51 | global $kyberia; | |
52 | global $user_id; | |
53 | $set=$kyberia->query("select count(*) as pocet from mail where mail_from='$user_id' or mail_to='$user_id'"); | |
54 | if ($set->getNumRows()) { | |
55 | $set->next(); | |
56 | return $set->getString('pocet'); | |
57 | } | |
58 | else { | |
59 | global $error; | |
60 | $error="Chyba? Kde sa ksakru stala chyba?"; | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | function send() { | |
66 | global $kyberia; | |
67 | global $user_id; | |
68 | global $user_name; | |
69 | global $user_mode_message; | |
70 | $mail_name=$_POST['mail_to']; | |
71 | $mail_to=explode(";",$mail_name); | |
72 | $mail_text=$_POST['mail_text']; | |
73 | $nohtml=$_POST['nohtml']; | |
74 | ||
75 | if ($mail_name=="hromi") { | |
76 | global $error; | |
77 | $error="there is no hromi. jhnprcvlhckwrth production wishes you happy consonant memorizing ;)"; | |
78 | return false; | |
79 | } | |
80 | ||
81 | if (count($mail_to)==1) { | |
82 | $q="select id from user where login='$mail_name'"; | |
83 | $result=$kyberia->query($q); | |
84 | $result->next(); | |
85 | $to=$result->getRecord(); | |
86 | $mail_to_id[]=$to['id']; | |
87 | } | |
88 | ||
89 | elseif (count($mail_to)>1) { | |
90 | foreach ($mail_to as $mail_to_exploded) { | |
91 | $q="select id from user where login='$mail_to_exploded'"; | |
92 | $result=$kyberia->query($q); | |
93 | $result->next(); | |
94 | $to=$result->getRecord(); | |
95 | $mail_to_id[]=$to['id']; | |
96 | } | |
97 | } | |
98 | ||
99 | ||
100 | if (empty($mail_text)) { | |
101 | global $error; | |
102 | $error="Prilis kratka sprava. Syr vesela krava, student prava a ci dobra trava?"; | |
103 | } | |
104 | ||
105 | /* | |
106 | if ($mail_to_id==$user_id) { | |
107 | $error="mas schizofreniu ked si pises postu?"; | |
108 | } | |
109 | */ | |
110 | ||
111 | if (!empty($nohtml)) { | |
112 | $mail_text=htmlspecialchars($mail_text); | |
113 | } | |
114 | ||
115 | if ($mail_to_id) { | |
116 | $mail_text=strip_tags($mail_text,'<a><b><i><u><img><br><p><font>'); | |
117 | $mail_text=str_replace("\n","<br>",$mail_text); | |
118 | $mail_text = EregI_Replace("((( )|(\n)|(^))+)(http://|ftp://|https://)([[:alnum:]][^,[:space:]]*)","\\2<a href=\"\\6\\7\">\\6\\7</a>",$mail_text); | |
119 | ||
120 | //add user mode message | |
121 | if (!empty($user_mode_message)) $mail_text.="<br><br>-->$user_mode_message<--"; | |
122 | ||
123 | $mail_text=addslashes($mail_text); | |
124 | ||
125 | foreach ($mail_to_id as $mail_to_id_send) { | |
126 | $q="insert into mail2 set mail_user='$user_id',mail_read='no',mail_from='$user_id',mail_text='$mail_text',mail_to='$mail_to_id_send',mail_timestamp=NOW()"; | |
127 | $result=mysql_query($q); | |
128 | $duplicate_id=mysql_insert_id(); | |
129 | $q="insert into mail2 set mail_duplicate_id='$duplicate_id',mail_read='no',mail_user='$mail_to_id_send',mail_from='$user_id',mail_text='$mail_text',mail_to='$mail_to_id_send',mail_timestamp=NOW()"; | |
130 | $result=mysql_query($q); | |
131 | $kyberia->query("update user set user_mail=user_mail+1,mail_name='$user_name' where id='$mail_to_id_send'"); | |
132 | } | |
133 | return true; | |
134 | ||
135 | } | |
136 | else { | |
137 | global $error; | |
138 | $error="<font color='red'>Uzivatel $mail_to neexistuje!!!</font>"; | |
139 | return false; | |
140 | } | |
141 | } | |
142 | ||
143 | function delete() { | |
144 | $delete=$_POST['delete']; | |
145 | global $user_id; | |
146 | global $kyberia; | |
147 | ||
148 | $delbetween=$_POST['delbetween']; | |
149 | if (!empty($delbetween)) { | |
150 | $max=max($delete); | |
151 | $min=min($delete); | |
152 | $q="delete from mail2 where mail_user='$user_id' and mail_id>'$min' and mail_id<'$max'"; | |
153 | $kyberia->update($q); | |
154 | } | |
155 | ||
156 | else { | |
157 | foreach ($delete as $messagedel) { | |
158 | $q="delete from mail2 where mail_id='$messagedel' and mail_user='$user_id'"; | |
159 | $kyberia->query($q); | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | function deleteAll() { | |
165 | global $kyberia; | |
166 | global $user_id; | |
167 | ||
168 | $kyberia->update("delete from mail2 where mail_user='$user_id'"); | |
169 | } | |
170 | } |