Ejemplo n.º 1
0
function qem_template()
{
    if (isset($_POST['Submit']) && check_admin_referer("save_qem")) {
        $theme_data = get_theme_data(get_stylesheet_uri());
        $templateIdentifier = '<?php
/*
Template Name: Single Event
*/
?>
';
        $templateDirectory = get_template_directory() . '/single.php';
        $newFilePath = get_stylesheet_directory() . '/single-event.php';
        $currentFile = fopen($templateDirectory, "r");
        $pageTemplate = fread($currentFile, filesize($templateDirectory));
        fclose($currentFile);
        $newTemplateFile = fopen($newFilePath, "w");
        fwrite($newTemplateFile, $templateIdentifier);
        $written = fwrite($newTemplateFile, $pageTemplate);
        fclose($newTemplateFile);
        if ($written != false) {
            qem_admin_notice('The template has been created. <a href="' . admin_url('theme-editor.php?file=single-event.php') . '">Edit Template</a>.');
        } else {
            qem_admin_notice('<strong>' . __('ERROR: Unable to create new theme file', 'quick-event-manager') . '</strong>');
        }
    }
    $content = '<div class="qem-settings"><div class="qem-options">
    <h2>' . __('The Automated Option', 'quick-event-manager') . '</h2>';
    $new = get_stylesheet_directory() . '/single.php';
    if (file_exists($new)) {
        $content .= '<p>' . __('If your theme adds posting dates and other unwanted features to your event page you can set up and edit a template for single events.', 'quick-event-manager') . '</p>
        <p>' . __('This function clones the \'single.php\' theme file and saves it as \'single-event.php\'.', 'quick-event-manager') . '</p>
        <p>' . __('Once created you can edit the file in your <a href="' . admin_url('theme-editor.php') . '">appearance editor', 'quick-event-manager') . '</a>.</p>
        <p>' . __('If you aren\'t confident editing theme files it may be prudent to read the', 'quick-event-manager') . ' <a href="http://codex.wordpress.org/Page_Templates">WordPress documentation</a> ' . __('first.', 'quick-event-manager') . '</p>';
        $new = get_stylesheet_directory() . '/single-event.php';
        if (file_exists($new)) {
            $content .= '<p style="color:red">' . __('An Event Template already exists. Clicking the button below will overwrite the existing file.', 'quick-event-manager') . ' <a href="' . admin_url('theme-editor.php?file=single-event.php') . '">' . __('View Template file', 'quick-event-manager') . '</a>.</p>';
        }
        $content .= '<form id="" method="post" action="">
        <p><input type="submit" name="Submit" class="button-primary" style="color: #FFF;" value="' . __('Create Event Template', 'quick-event-manager') . '" /></p>';
        $content .= wp_nonce_field("save_qem");
        $content .= '</form>';
    } else {
        $content .= __('Your theme doesn\'t appear to have the \'single.php\' file needed to create an event template. To create an event template follow the instrctions on the right.', 'quick-event-manager') . '</p>';
    }
    $content .= '</div>
    <div class="qem-options" style="float:right">
    <h2>' . __('The DIY Option', 'quick-event-manager') . '</h2>
    <p>' . __('It\'s very easy to create your own template if you have FTP access to your theme', 'quick-event-manager') . '.</p>
    <p>' . __('1. Connect to your domain using FTP', 'quick-event-manager') . '.</p>
    <p>' . __('2. Navigate to the theme directory. Normally wp-content/themes/your theme', 'quick-event-manager') . '.</p>
    <p>' . __('3. Download the file called single.php to your computer', 'quick-event-manager') . '.</p>
    <p>' . __('4. Open the file using a text editor', 'quick-event-manager') . '.</p>
    <p>' . __('5. Add the following to the very top of the file', 'quick-event-manager') . ':
    <code><&#063;php
    /*
    Template Name: Single Event
    */
    &#063;>
    </code>
    </p>
    <p>' . __('6. Save as: <code>single-event.php</code>', 'quick-event-manager') . '.</p>
    <p>' . __('7. Upload the file to your theme directory', 'quick-event-manager') . '.</p>
    <p>' . __('The event manager will detect the new template and use it for single events', 'quick-event-manager') . '.</p>
    </div>
    </div>';
    echo $content;
}
function qem_messages()
{
    $event = $title = '';
    global $_GET;
    $event = isset($_GET["event"]) ? $_GET["event"] : null;
    $title = isset($_GET["title"]) ? $_GET["title"] : null;
    $unixtime = get_post_meta($event, 'event_date', true);
    $date = date_i18n("d M Y", $unixtime);
    $noregistration = '<p>No event selected</p>';
    $register = qem_get_stored_register();
    $category = 'All Categories';
    if (isset($_POST['qem_reset_message'])) {
        $event = $_POST['qem_download_form'];
        $title = get_the_title($event);
        delete_option('qem_messages_' . $event);
        delete_option($event);
        qem_admin_notice('Registrants for ' . $title . ' have been deleted.');
        $eventnumber = get_post_meta($event, 'event_number', true);
        update_option($event . 'places', $eventnumber);
    }
    if (isset($_POST['category'])) {
        $category = $_POST["category"];
    }
    if (isset($_POST['select_event']) || isset($_POST['eventid'])) {
        $event = $_POST["eventid"];
        if ($event) {
            $unixtime = get_post_meta($event, 'event_date', true);
            $date = date_i18n("d M Y", $unixtime);
            $title = get_the_title($event);
            $noregistration = '<h2>' . $title . ' | ' . $date . '</h2><p>Nobody has registered for ' . $title . ' yet</p>';
        } else {
            $noregistration = '<p>No event selected</p>';
        }
    }
    if (isset($_POST['changeoptions'])) {
        $options = array('showevents', 'category');
        foreach ($options as $item) {
            $messageoptions[$item] = stripslashes($_POST[$item]);
        }
        $category = $messageoptions['category'];
        update_option('qem_messageoptions', $messageoptions);
    }
    if (isset($_POST['qem_delete_selected'])) {
        $event = $_POST["qem_download_form"];
        $message = get_option('qem_messages_' . $event);
        $eventnumber = get_option($event . 'places');
        $check = get_post_meta($event, 'event_counter', true);
        for ($i = 0; $i <= 100; $i++) {
            if ($_POST[$i] == 'checked') {
                $num = $message[$i]['yourplaces'] ? $message[$i]['yourplaces'] : 1;
                if ($check) {
                    $eventnumber = $eventnumber + $num;
                }
                unset($message[$i]);
            }
        }
        $message = array_values($message);
        update_option('qem_messages_' . $event, $message);
        if ($check) {
            update_option($event . 'places', $eventnumber);
        }
        qem_admin_notice('Selected registrations have been deleted.');
    }
    if (isset($_POST['qem_emaillist'])) {
        $event = $_POST["qem_download_form"];
        $title = $_POST["qem_download_title"];
        $message = get_option('qem_messages_' . $event);
        $register = qem_get_stored_register();
        $content = '';
        $content = qem_build_registration_table($register, $message, '', '', '', '');
        global $current_user;
        get_currentuserinfo();
        $qem_email = $current_user->user_email;
        $headers = "From: {<{$qem_email}>\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=\"utf-8\"\r\n";
        wp_mail($qem_email, $title, $content, $headers);
        qem_admin_notice('Registration list has been sent to ' . $qem_email . '.');
    }
    qem_generate_csv();
    $content = $current = $all = '';
    $messageoptions = qem_get_stored_msg();
    ${$messageoptions}['showevents'] = "checked";
    $message = get_option('qem_messages_' . $event);
    $places = get_option($event . 'places');
    $check = get_post_meta($event, 'event_counter', true);
    if (!is_array($message)) {
        $message = array();
    }
    $dashboard = '<div class="wrap">
<h1>Event Registation Report</h1>
<p><form method="post" action="">' . qem_message_categories($category) . '
&nbsp;&nbsp;' . qem_get_eventlist($event, $register, $messageoptions, $category) . '
&nbsp;&nbsp;<b>Show:</b> <input style="margin:0; padding:0; border:none;" type="radio" name="showevents" value="all" ' . $all . ' /> All Events <input style="margin:0; padding:0; border:none;" type="radio" name="showevents" value="current" ' . $current . ' /> Current Events&nbsp;&nbsp;<input type="submit" name="changeoptions" class="button-secondary" value="Update options" />
</form>
</p>
<div id="qem-widget">
<form method="post" id="qem_download_form" action="">';
    $content = qem_build_registration_table($register, $message, $check, '', $event);
    if ($content) {
        $dashboard .= '<h2>' . $title . ' | ' . $date . '</h2>';
        $dashboard .= '<p>Event ID: ' . $event . '</p>';
        $dashboard .= $content;
        $dashboard .= '<input type="hidden" name="qem_download_form" value = "' . $event . '" />
    <input type="hidden" name="qem_download_title" value = "' . $title . '" />
    <input type="submit" name="qem_download_csv" class="button-primary" value="Export to CSV" />
    <input type="submit" name="qem_emaillist" class="button-primary" value="Email List" />
    <input type="submit" name="qem_reset_message" class="button-secondary" value="Delete All Registrants" onclick="return window.confirm( \'Are you sure you want to delete all the registrants for ' . $title . '?\' );"/>
    <input type="submit" name="qem_delete_selected" class="button-secondary" value="Delete Selected" onclick="return window.confirm( \'Are you sure you want to delete the selected registrants?\' );"/>
    </form>';
    } else {
        $dashboard .= $noregistration;
    }
    $dashboard .= '</div></div>';
    echo $dashboard;
}