*    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
if (empty($current_user->id) || $current_user->is_admin !== 'y') {
    header('Location: ' . PCPIN_FORMLINK . '?' . md5(microtime()));
    die;
}
// JS files
$_js_files[] = './js/admin/avatar_gallery.js';
// JS language expressions
$_js_lng[] = 'delete_avatar';
$_js_lng[] = 'avatar_image_empty_error';
$_js_lng[] = 'confirm_delete_avatar';
$_js_lng[] = 'primary';
$_body_onload[] = 'initAvatarsForm()';
// Initialize template handler
_pcpin_loadClass('pcpintpl');
$tpl = new PcpinTpl();
$tpl->setBasedir('./tpl');
$tpl->readTemplatesFromFile('./admin/avatar_gallery.tpl');
// Add global vars to template
foreach ($global_tpl_vars as $key => $val) {
    $tpl->addGlobalVar($key, htmlspecialchars($val));
}
// Add language expressions to template
foreach ($tpl->tpl_vars_plain as $var) {
    if (0 === strpos($var, 'LNG_')) {
        $var = strtolower($var);
        $tpl->addGlobalVar($var, htmlspecialchars($l->g(substr($var, 4))));
    }
}
$invitations = $invitation->getNewInvitations($current_user->id, false, $invitation_id);
if (empty($invitations)) {
    $_body_onload[] = 'window.close()';
    $_body_onload[] = 'return false';
} else {
    $invitation_data = reset($invitations);
    // Init template
    _pcpin_loadClass('pcpintpl');
    $tpl = new PcpinTpl();
    $tpl->setBasedir('./tpl');
    $tpl->readTemplatesFromFile('./invitation.tpl');
    // Add language expressions to template
    foreach ($tpl->tpl_vars_plain as $var) {
        if (0 === strpos($var, 'LNG_')) {
            $var = strtolower($var);
            $tpl->addGlobalVar($var, htmlspecialchars($l->g(substr($var, 4))));
        }
    }
    // Add global vars to template
    foreach ($global_tpl_vars as $key => $val) {
        $tpl->addGlobalVar($key, htmlspecialchars($val));
    }
    $invitation_text = $l->g('user_invited_you');
    $invitation_text = str_replace('[ROOM]', $invitation_data['room_name'], $invitation_text);
    $invitation_text = str_replace('[USER]', '<b>' . $nickname->coloredToHTML($invitation_data['author_nickname']) . '</b>', htmlspecialchars($invitation_text));
    $tpl->addVar('main', 'invitation_text', nl2br($invitation_text));
    $tpl->addGlobalVar('user_id', htmlspecialchars($invitation_data['author_id']));
    $tpl->addGlobalVar('room_id', htmlspecialchars($invitation_data['room_id']));
    $tpl->addGlobalVar('mute_user_locally', htmlspecialchars(str_replace('[USER]', $nickname->coloredToPlain($invitation_data['author_nickname'], false), $l->g('mute_user_locally'))));
}
$_window_title .= ' ' . PCPIN_WINDOW_TITLE_SEPARATOR . ' ' . $l->g('invitation');