Ignore:
Timestamp:
07/23/10 10:18:02 (22 months ago)
Author:
fuze
Message:

Личные сообщения: html вынесен в smarty, добавлена пагинация, мелкие недочеты исправлены.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/fuze/components/users/messages.php

    r181 r235  
    88//                                                                                           // 
    99/*********************************************************************************************/ 
    10 function pageSelect($records, $current, $perpage){ 
    11         $html = ''; 
    12         global $_LANG; 
    13         if ($records){ 
    14                 $pages = ceil($records / $perpage); 
    15  
    16                 if($pages>1){ 
    17                         $html .= '<td width="60"><strong>'.$_LANG['PAGE'].': </strong></span></td>'; 
    18                         $html .= '<td width="60" align="center"><form style="margin:0px;padding:0px" action="" name="pageform" method="POST">'; 
    19                         $html .= '<select style="width:60px" name="cpage" onchange="document.pageform.submit()">'; 
    20                         for ($p=1; $p<=$pages; $p++){ 
    21                                 if ($p != $current) {                    
    22                                         $html .= '<option value="'.$p.'">'.$p.'</option>';               
    23                                 } else { 
    24                                         $html .= '<option value="'.$p.'" selected>'.$p.'</option>';              
    25                                 } 
    26                         } 
    27                         $html .= '</select></form></td>'; 
    28                         $html .= '<td width="30"> èç <strong>'.$pages.'</strong><td>'; 
    29                 } 
    30         } 
    31         return $html; 
    32 } 
    33  
     10        $inPage->backButton(false);  
    3411    $opt = $inCore->request('opt', 'str', 'in'); 
    3512    $with_id = $inCore->request('with_id', 'int', 0); 
     
    3714        if (usrCheckAuth()){ 
    3815        global $_LANG; 
    39                 echo '<div class="con_heading" style="margin-bottom:25px">'.$_LANG['MY_MESS'].'</div>'; 
    4016                //current page 
    4117                $perpage = 15; 
    42                 if (isset($_POST['cpage'])) { $page = $_REQUEST['cpage']; } else { $page = 1; } 
     18                $page = $inCore->request('cpage', 'int', 1); 
    4319 
    4420                if ($opt=='in'){ 
     
    8561                } 
    8662 
    87                 $result = $inDB->query($sql) or die(mysql_error().'<br/><br/>'.$sql); 
     63                $result = $inDB->query($sql); 
    8864 
    89                 echo '<div style="margin-bottom:10px">';                                 
    9065                        if ($opt=='in'){                                 
    9166                                $inPage->addPathway($_LANG['INBOX']); 
    92                                 echo '<span class="usr_msgmenu_active in_span">'.$_LANG['INBOX'].'</span> '; 
    93                                 echo '<a class="usr_msgmenu_link out_link" href="/users/'.$id.'/messages-sent.html">'.$_LANG['SENT'].'</a>'; 
    94                                 echo '<a class="usr_msgmenu_link new_link" href="/users/'.$id.'/messages-new.html">'.$_LANG['WRITE'].'</a>'; 
    9567                        } elseif ($opt=='out') { 
    9668                                $inPage->addPathway($_LANG['SENT']); 
    97                                 echo '<a class="usr_msgmenu_link in_link" href="/users/'.$id.'/messages.html">'.$_LANG['INBOX'].'</a> '; 
    98                                 echo '<span class="usr_msgmenu_active out_span">'.$_LANG['SENT'].'</span>'; 
    99                                 echo '<a class="usr_msgmenu_link new_link" href="/users/'.$id.'/messages-new.html">'.$_LANG['WRITE'].'</a>'; 
    10069                        } elseif ($opt=='new') { 
    10170                                $inPage->addPathway($_LANG['NEW_MESS']); 
    102                                 echo '<a class="usr_msgmenu_link in_link" href="/users/'.$id.'/messages.html">'.$_LANG['INBOX'].'</a> '; 
    103                                 echo '<a class="usr_msgmenu_link out_link" href="/users/'.$id.'/messages-sent.html">'.$_LANG['SENT'].'</a>'; 
    104                                 echo '<span class="usr_msgmenu_active new_span">'.$_LANG['WRITE'].'</span>'; 
    10571                        } elseif ($opt=='history') { 
    10672                                $inPage->addPathway($_LANG['MESSEN_WITH'].' '.$with_name, $_SERVER['REQUEST_URI']); 
    107                                 echo '<a class="usr_msgmenu_link in_link" href="/users/'.$id.'/messages.html">'.$_LANG['INBOX'].'</a> '; 
    108                                 echo '<a class="usr_msgmenu_link out_link" href="/users/'.$id.'/messages-sent.html">'.$_LANG['SENT'].'</a>'; 
    109                                 echo '<a class="usr_msgmenu_link new_link" href="/users/'.$id.'/messages-new.html">'.$_LANG['WRITE'].'</a>'; 
    110                                 echo '<span class="usr_msgmenu_active history_span">'.$_LANG['MESSEN'].' &rarr; '.$with_name.'</span>'; 
    11173                        } 
    112                 echo '</div>'; 
    11374                 
    11475                if ($opt=='in' || $opt=='out' || $opt=='history'){ 
    115                  
    116                         echo '<table class="usr_msgmenu_bar" width="100%" height="30" border="0" cellpadding="5" cellspacing="0"><tr>'; 
    117                  
    118                                 echo '<td><strong>'.$_LANG['MESS_INBOX'].':</strong> '.$msg_count.'</td>'; 
     76                                 
     77                        if ($msg_count > $perpage){ 
     78                                if ($opt=='in'){ 
     79                                $pagebar = cmsPage::getPagebar($msg_count, $page, $perpage, '/users/%user_id%/messages%page%.html', array('user_id'=>$id)); 
     80                                } elseif ($opt=='out') { 
     81                                $pagebar = cmsPage::getPagebar($msg_count, $page, $perpage, '/users/%user_id%/messages-sent%page%.html', array('user_id'=>$id)); 
     82                                } elseif ($opt=='history') { 
     83                                $pagebar = cmsPage::getPagebar($msg_count, $page, $perpage, '/users/%user_id%/messages-history%to_id%-%page%.html', array('user_id'=>$id, 'to_id'=>$with_id)); 
     84                                } 
     85                        } 
    11986                         
    120                                 if ($opt=='out'){ 
    121                                         echo '<td align="center"><span style="color:gray">'.$_LANG['SENT_TEXT'].'</span></td>'; 
    122                                 } 
    123                                  
    124                                 if ($msg_count > $perpage){ 
    125                                         echo pageSelect($msg_count, $page, $perpage); 
    126                                 } 
    127                                  
    128                                 if ($opt=='in' && $msg_count>0){ 
    129                                         echo '<td width="100" align="right"><a href="/users/'.$id.'/delmessages.html">'.$_LANG['CLEAN_CAT'].'</a></td>'; 
    130                                 } 
    131                          
    132                         echo '</tr></table>'; 
    133                                                                          
     87                        $is_mes = false; 
    13488                        if ($inDB->num_rows($result)){ 
    135                                         echo '<div>'; 
     89                                        $is_mes = true; 
     90                                        $records = array(); 
    13691                                        while($record = $inDB->fetch_assoc($result)){ 
    13792         
    13893                                                if($record['sender_id']>0){  
    139                                                         $authorlink = '<a href="'.cmsUser::getProfileURL($record['author_login']).'">'.$record['author'].'</a>'; 
     94                                                        $record['authorlink'] = '<a href="'.cmsUser::getProfileURL($record['author_login']).'">'.$record['author'].'</a>'; 
    14095                                                } else { 
    14196                                                        if ($record['sender_id']==USER_UPDATER){ 
    142                                                                 $authorlink = $_LANG['SERVICE_UPDATE']; 
     97                                                                $record['authorlink'] = $_LANG['SERVICE_UPDATE']; 
    14398                                                        } 
    14499                                                        if ($record['sender_id']==USER_MASSMAIL){ 
    145                                                                 $authorlink = $_LANG['SERVICE_MAILING']; 
     100                                                                $record['authorlink'] = $_LANG['SERVICE_MAILING']; 
    146101                                                        } 
    147102                                                }                                                                                
    148          
    149                                                 echo '<table style="width:100%" cellspacing="0">'; 
    150                                                 echo '<tr>'; 
    151                                                         echo '<td class="usr_msg_title" width=""><strong>'.$authorlink.'</strong>, '.$record['fpubdate'].'</td>'; 
    152                                                         if ($record['is_new']){ 
    153                                                                 if ($opt=='in'){ 
    154                                                                         //erase new mark 
    155                                                                         $inDB->query("UPDATE cms_user_msg SET is_new = 0 WHERE id = ".$record['id']); 
    156                                                                         echo '<td class="usr_msg_title" width="14" align="right"><img src="/components/users/images/warning.gif" /></td>'; 
    157                                                                         echo '<td class="usr_msg_title" width="20" align="right"><span style="color: red">'.$_LANG['NEW'].'!</span></td>'; 
    158                                                                 } else { 
    159                                                                         echo '<td class="usr_msg_title" width="90" align="right"><a class="msg_delete" href="/users/delmsg'.$record['id'].'.html">'.$_LANG['CANCEL_MESS'].'</a></td>'; 
    160                                                                 } 
    161                                                         } else { 
    162                                                                 echo '<td class="usr_msg_title" width="14" align="right">&nbsp;</td>';                                           
    163                                                                 echo '<td class="usr_msg_title" width="20" align="right">&nbsp;</td>'; 
    164                                                         } 
     103 
     104                                                $record['fpubdate'] = $inCore->dateFormat($record['fpubdate'], true, true, true); 
     105                                                if ($record['is_new']){ 
    165106                                                        if ($opt=='in'){ 
    166                                                                 if ($record['sender_id']>0){ 
    167                                                                         echo '<td class="usr_msg_title" width="80" align="right"><a class="msg_reply" href="/users/'.$record['from_id'].'/reply'.$record['id'].'.html">'.$_LANG['REPLY'].'</a></td>'; 
    168                                                                         echo '<td class="usr_msg_title" width="80" align="right"><a class="msg_history" href="/users/'.$id.'/messages-history'.$record['from_id'].'.html">'.$_LANG['HISTORY'].'</a></td>'; 
    169                                                                 } 
    170                                                         } 
    171                                                         if ($opt=='in' || $record['to_id']==$inUser->id){ 
    172                                                                 echo '<td class="usr_msg_title" width="70" align="right"><a class="msg_delete" href="/users/delmsg'.$record['id'].'.html">'.$_LANG['DELETE'].'</a></td>'; 
    173                                                         } 
    174                                                 echo '</tr>'; 
    175                                                 echo '</table>'; 
    176                                                 echo '<table style="width:100%; margin-bottom:8px; padding-bottom:10px;background-color:#FFFFFF; border-bottom:dashed 1px #666;" cellspacing="4">';              
    177          
    178                                                 $text = $record['message'];// nl2br(); 
    179                                                 $text = $inCore->parseSmiles($text, true); 
    180                                                 $text = str_replace('&gt;', '>', $text); 
    181                                                 $text = str_replace('&lt;', '<', $text);                                         
    182                                                 $text = str_replace('&amp;', '&', $text);                                        
    183                                                 $text = strip_tags($text, '<img><br><a><b><u><i><table><tr><td><th><h1><h2><h3><div><span><pre>'); 
     107                                                                //erase new mark 
     108                                                                $inDB->query("UPDATE cms_user_msg SET is_new = 0 WHERE id = ".$record['id']); 
     109                                                        }  
     110                                                }  
     111                                                $record['message'] = $inCore->parseSmiles($record['message'], true); 
     112                                                $record['message'] = str_replace('&gt;', '>', $record['message']); 
     113                                                $record['message'] = str_replace('&lt;', '<', $record['message']);                                       
     114                                                $record['message'] = str_replace('&amp;', '&', $record['message']);                                      
     115                                                $record['message'] = strip_tags($record['message'], '<img><br><a><b><u><i><table><tr><td><th><h1><h2><h3><div><span><pre>'); 
    184116                                                 
    185117                                                if ($record['sender_id']>0){ 
    186                                                         $user_img = '<a href="'.cmsUser::getProfileURL($record['author_login']).'">'.usrImageNOdb($record['sender_id'], 'small', $record['imageurl'], $record['is_deleted'], $record['author_login']).'</a>'; 
     118                                                        $record['user_img'] = '<a href="'.cmsUser::getProfileURL($record['author_login']).'">'.usrImageNOdb($record['sender_id'], 'small', $record['imageurl'], $record['is_deleted'], $record['author_login']).'</a>'; 
    187119                                                } else { 
    188                                                         $user_img = usrImageNOdb($record['sender_id'], 'small', $record['imageurl'], $record['is_deleted'], $record['author_login']); 
     120                                                        $record['user_img'] = usrImageNOdb($record['sender_id'], 'small', $record['imageurl'], $record['is_deleted'], $record['author_login']); 
    189121                                                } 
    190                                                  
    191                                                 echo '<tr>';                                             
    192                                                         echo '<td width="70" height="70" valign="middle" align="center" style="border:solid 1px silver">'.$user_img.'</td>';                     
    193                                                         echo '<td width="" valign="top"><div style="padding:6px">'.$text.'</div></td>'; 
    194                                                 echo '</tr>'; 
    195                                                 echo '</table>'; 
     122                                                $records[] = $record; 
    196123                                        } 
    197                                         echo '</div>'; 
    198                                 } else { echo '<p>'.$_LANG['NOT_MESS_IN_CAT'].'</p>'; } 
     124                        }  
    199125         
    200126                } 
     
    202128                if ($opt=='new'){ 
    203129                        $inPage->addHeadJS('components/users/js/newmessage.js'); 
    204          
    205                         echo '<form action="" id="newmessage" method="POST" name="msgform">';                    
    206                                 echo '<table class="usr_msgmenu_bar" width="100%" height="30" border="0" cellpadding="5" cellspacing="0"><tr>'; 
    207                                         echo '<tr>'; 
    208                                                 echo '<td width="40"><strong>'.$_LANG['SEND_TO'].':</strong> </td>'; 
    209                                                 echo '<td width="160"><select name="id" id="to_id" style="width:150px">'.cmsUser::getFriendsList($inUser->id).'</select></td>'; 
    210                                                 if ($inUser->is_admin){ 
    211                                                         echo '<td width="10"><input name="massmail" type="checkbox" value="1" /></td>';                                  
    212                                                         echo '<td width="">'.$_LANG['SEND_TO_ALL'].'</td>'; 
    213                                                 } else { 
    214                                                         echo '<td>&nbsp;</td>'; 
    215                                                 } 
    216                                         echo '</tr>';                                                            
    217                                 echo '</table>'; 
    218                                  
    219                                         echo '<div>'; 
    220                                                         echo '<input type="hidden" name="gosend"   value="1"/>'; 
    221                                                         echo '<div class="usr_msg_bbcodebox">'; 
    222                                                                 echo cmsPage::getBBCodeToolbar('message'); 
    223                                                         echo '</div>';                                                   
    224                                                         echo cmsPage::getSmilesPanel('message'); 
    225                                                         echo '<textarea style="font-size:18px;border:solid 1px gray;width:100%;height:200px;" name="message" id="message"></textarea>';                                          
    226                                                         echo '<div style="margin-top:6px;"><input type="button" id="gosend" value="'.$_LANG['SEND'].'" onclick="sendMessage()" style="font-size:18px"/></div>'; 
    227                                         echo '</div>';                   
    228                         echo '</form>';                          
     130                        $user_opt = cmsUser::getFriendsList($inUser->id); 
     131                        $bb_toolbar = cmsPage::getBBCodeToolbar('message'); 
     132                        $bb_smiles      = cmsPage::getSmilesPanel('message'); 
    229133                } 
     134                $smarty = $inCore->initSmarty('components', 'com_users_messages.tpl'); 
     135                $smarty->assign('opt', $opt); 
     136                $smarty->assign('is_mes', $is_mes); 
     137                $smarty->assign('id', $id); 
     138                $smarty->assign('with_name', $with_name); 
     139                $smarty->assign('msg_count', $msg_count); 
     140                $smarty->assign('pagebar', $pagebar); 
     141                $smarty->assign('perpage', $perpage); 
     142                $smarty->assign('user_opt', $user_opt); 
     143                $smarty->assign('is_admin', $inUser->is_admin); 
     144                $smarty->assign('bb_toolbar', $bb_toolbar); 
     145                $smarty->assign('bb_smiles', $bb_smiles); 
     146                $smarty->assign('usr_id', $inUser->id); 
     147                $smarty->assign('records', $records); 
     148                $smarty->display('com_users_messages.tpl'); 
    230149} 
    231150 
Note: See TracChangeset for help on using the changeset viewer.