function EditFav($msg_id, $priority = 0, $title = '', $action = 'edit') { global $session; session_start(); $user_id = $_SESSION['uid']; $objResponse = new xajaxResponse(); $msg_id = intval($msg_id); $GLOBALS['xajax']->setCharEncoding('windows-1251'); $sort = $_COOKIE['commune_fav_order'] != '' ? $_COOKIE['commune_fav_order'] : 'date'; $action = trim($action); $title = trim($title); switch ($action) { case 'update': $title = substr($title, 0, 128); $updatefav = commune::AddFav($msg_id, $user_id, 0, $priority, $title); $editfav = current(commune::GetFavorites($user_id, $msg_id, $sort)); $key = $msg_id; $om = ''; $outHTML = __commPrntFavContent($editfav, $key, $user_id, $om); $objResponse->assign('fav' . $msg_id, 'innerHTML', $outHTML); break; case 'edit': $editfav = current(commune::GetFavorites($user_id, $msg_id, $sort)); //$editfav = current($editfav); $editfav['title'] = preg_replace('/<br.*?>/mix', "\r\n", stripslashes(reformat2($editfav['title'], 20, 0, 1))); $outHTML = '<table border="0" cellpadding="1" cellspacing="0"><tbody><tr valign="top"><td style="padding-left: 3px;">'; $outHTML .= '<ul class="post-f-fav-sel">'; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $msg_id . "-0' width=\"15\" height=\"15\" src=\"" . ($editfav['priority'] == 0 ? commune::getStarByPR(0) : commune::getEmptyStarByPR(0)) . "\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriority({$msg_id}, 0)\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $msg_id . "-1' width=\"15\" height=\"15\" src=\"" . ($editfav['priority'] == 1 ? commune::getStarByPR(1) : commune::getEmptyStarByPR(1)) . "\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriority({$msg_id}, 1)\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $msg_id . "-2' width=\"15\" height=\"15\" src=\"" . ($editfav['priority'] == 2 ? commune::getStarByPR(2) : commune::getEmptyStarByPR(2)) . "\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriority({$msg_id}, 2)\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $msg_id . "-3' width=\"15\" height=\"15\" src=\"" . ($editfav['priority'] == 3 ? commune::getStarByPR(3) : commune::getEmptyStarByPR(3)) . "\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriority({$msg_id}, 3)\" style=\"cursor:pointer;\"></li>"; $outHTML .= '</ul></td><td>'; $outHTML .= '<div class="fav-one-edit-txt">'; $outHTML .= "<INPUT id='favpriority" . $msg_id . "' type='hidden' value='" . $editfav['priority'] . "'>"; $outHTML .= "<INPUT id='currtitle' type='hidden' value='" . $editfav['title'] . "'>"; $outHTML .= "<textarea rows=\"3\" cols=\"7\" id='favtext" . $msg_id . "'>{$editfav['title']}</textarea>"; $outHTML .= '<div class="fav-one-edit-btns">'; $outHTML .= "<INPUT type='button' value='Сохранить' onClick='if(document.getElementById(\"favtext" . $msg_id . '").value.length>128){alert("Слишком длинное название закладки!");return false;}else{xajax_EditFav(' . $msg_id . ', document.getElementById("favpriority' . $msg_id . '").value, document.getElementById("favtext' . $msg_id . "\").value, \"update\");}'>"; $outHTML .= "<INPUT type='button' value='Отмена' onClick='xajax_EditFav(" . $msg_id . ', ' . $editfav['priority'] . ", document.getElementById(\"currtitle\").value, \"default\");'>"; $outHTML .= '</div></td></tr></tbody></table>'; $objResponse->assign('fav' . $msg_id, 'innerHTML', $outHTML); break; default: $editfav = current(commune::GetFavorites($user_id, $msg_id, $sort)); $key = $msg_id; $om = ''; $outHTML = __commPrntFavContent($editfav, $key, $user_id, $om); $objResponse->assign('fav' . $msg_id, 'innerHTML', $outHTML); break; } $objResponse->script('communeObj.initFavs();'); return $objResponse; }
/** * вывод блока закладок * * @param array $favs Избранное * @param integer $user_id ИД пользователя * @param integer $om Для навигации * @return string HTML */ function __commPrntFavs($favs, $user_id, $om) { if (empty($favs) || !is_array($favs) || !count($favs)) { return ''; } ob_start(); ?> <?php foreach ($favs as $key => $fav) { ?> <li id="fav<?php echo $key; ?> " class="b-menu__item b-menu__item_padbot_10"> <?php echo __commPrntFavContent($fav, $key, $user_id, $om); ?> </li> <?php } $str = ob_get_contents(); ob_end_clean(); return $str; }