Commit | Line | Data |
---|---|---|
1e519a04 H |
1 | <?php |
2 | ||
51ff3226 | 3 | function smarty_function_get_mail($params, &$smarty) { |
4 | global $db, $node; | |
5 | ||
6 | $user_id=$_SESSION['user_id']; | |
7 | ||
8 | if (is_numeric($params['listing_amount'])) $listing_amount=$params['listing_amount']; | |
9 | else $listing_amount=23; | |
10 | ||
11 | /* zapnut, ked bezime len na jednej masine.. (br) | |
12 | if ($listing_amount > 100) | |
13 | $listing_amount = 100; | |
14 | */ | |
15 | ||
16 | if (is_numeric($params['offset'])) $offset=$params['offset']; | |
17 | else $offset=0; | |
18 | ||
19 | if (!empty($params['search'])) { | |
20 | if ($params['search_type']=='mail_text') { | |
21 | $sql_type.=" and mail_text like '%".addslashes($params['search'])."%' "; | |
22 | } | |
23 | elseif ($params['search_type']=='mail_both') { | |
24 | $userset=$db->query("select user_id from users where login='".addslashes($params['search'])."'"); | |
25 | $userset->next(); | |
26 | $id=$userset->getString('user_id'); | |
27 | $sql_type=" and (mail_to='$id' or mail_from='$id')"; | |
28 | } | |
29 | else { | |
30 | $userset=$db->query("select user_id from users where login='".addslashes($params['search'])."'"); | |
31 | $userset->next(); | |
32 | $id=$userset->getString('user_id'); | |
33 | $sql_type=" and ".$params['search_type']."='$id'"; | |
34 | } | |
35 | } | |
36 | ||
37 | $query = "select date_format(mail.mail_timestamp,\"%e.%c. %k:%i:%s\") as cas, | |
38 | userfrom.user_action as locationfrom_action, | |
39 | userfrom.user_action_id as locationfrom_action_id, | |
40 | userto.user_action as locationto_action, | |
41 | userto.user_action_id as locationto_action_id, | |
42 | userto.login as mail_to_name, userfrom.login as mail_from_name, | |
43 | mail.* from mail left join users as userfrom on | |
44 | mail_from=userfrom.user_id left join users as userto on mail_to=userto.user_id | |
45 | where mail_user='$user_id' "; | |
46 | if ($sql_type) $query.=$sql_type; | |
47 | $query.=" order by mail_id desc limit $offset,$listing_amount"; | |
48 | ||
49 | $set = $db->query($query); | |
50 | ||
51 | while($set->next()) { | |
52 | $get_mail[] = $set->getRecord(); | |
53 | } | |
54 | $smarty->assign('get_mail', $get_mail); | |
55 | } | |
56 | ?> |