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