Example #1
0
function front_end_users_admin_list()
{
    $markersTable = new FE_Users_Table();
    remove_wp_magic_quotes();
    // Render messages when a marker is added/updated
    $messages = array();
    if (isset($_GET['update'])) {
        switch ($_GET['update']) {
            case 'del':
            case 'del_many':
                $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0;
                $messages[] = sprintf("<div id=\"message\" class=\"updated\"><p>%s {$this->_args}['plural'] deleted.</p></div>", number_format_i18n($delete_count));
                break;
            case 'add':
                $strmsg = isset($_GET['status']) ? "updated" : "added";
                $messages[] = '<div id="message" class="updated"><p>' . __("Marker {$strmsg}.") . '</p></div>';
                break;
        }
    }
    $this_file = "?page=" . $_REQUEST['page'];
    switch ($markersTable->current_action()) {
        case "add":
        case "edit":
        case "delete":
            global $wpdb;
            if (isset($_GET['action2']) && $_GET['action2'] == "-1") {
                $del_id = $_GET[$this->_args['singular']];
                $del_data = front_end_users_delete($del_id);
            }
            if (isset($_GET['id']) && $_GET['id']) {
                $del_id = $_GET['id'];
                $del_data = front_end_users_delete($del_id);
            }
            if (isset($del_data)) {
                ?>
                <div class="<?php 
                echo $del_data['msgClass'];
                ?>
">
                    <p><?php 
                echo $del_data['msg'];
                ?>
</p>
                </div>
            <?php 
            }
            $this_file = $this_file . "&update=delete";
        default:
            ?>
            <?php 
            global $wpdb;
            $table = $wpdb->prefix . 'markers';
            $arrWhere = array();
            // handle add/update img
            if (!empty($_POST['caption'])) {
                substr($_POST['caption'], 0, 255);
            }
            if (!empty($_POST['addMarker'])) {
                if (!empty($_POST['id']) && is_numeric($_POST['id'])) {
                    $arrWhere = array('id' => $_POST['id']);
                    unset($_POST['id']);
                }
                unset($_POST['addMarker']);
                $arrData = array();
                $arrData = array_filter($_POST);
                $arrMsg = array();
                if (count($arrData) > 0) {
                    $boolAdded = front_end_users_add_update($table, $arrData, $arrWhere);
                    if (!empty($arrWhere) && $boolAdded) {
                        $arrMsg = array('msg' => __('Marker updated.'), 'msgClass' => 'updated');
                    } elseif (empty($arrWhere) && $boolAdded) {
                        $arrMsg = array('msg' => __('Marker added.'), 'msgClass' => 'updated');
                    } else {
                        $arrMsg = array('msg' => 'Error occured while saving data.', 'msgClass' => 'error');
                    }
                    $messages[] = '<div id="message" class="' . $arrMsg['msgClass'] . '"><p>' . $arrMsg['msg'] . '</p></div>';
                }
            }
            if (isset($_GET['id'])) {
                $imgEditId = $_GET['id'];
                if (is_numeric($imgEditId) && $imgEditId > 0) {
                    $arrWhere = array("id = {$imgEditId}");
                    $markersData = front_end_users_fetch_data($table, $arrWhere);
                }
            }
            ?>
				
				<script type="text/javascript">
					var fixedProvincesList = '<?php 
            echo json_encode($fixedProvincesList);
            ?>
';
					!function($) {
						$(function() {
							$(document).ready(function() {
								$("#add-marker-form").validate({
									rules: {
										field: {
										  required: true,
										  digits: true
										}
									}
								});
								$('#form-marker-country').trigger('change');
							});
							
							$(document).on('click', '#upload-img', function(e) {
								e.preventDefault();
								var button = $(this);
								var id = button.prev();
								wp.media.editor.send.attachment = function(props, attachment) {
									id.val(attachment.url);
								};
								wp.media.editor.open(button);
								return false;
							});
						})
					} (window.jQuery);
				</script>
				<?php 
            $markersTable->prepare_items();
            if (!empty($messages)) {
                foreach ($messages as $msg) {
                    echo $msg;
                }
            }
            ?>
            <div class="wrap">
                <h2><?php 
            _e('Users');
            ?>
</h2>
                <div id="col-container">
                    <div id="col-right">
                        <div class="col-wrap">
                            <div class="form-wrap">
                                <form id="gallery-filter" method="get">
                                    <input type="hidden" name="page" value="<?php 
            echo $_REQUEST['page'];
            ?>
" />
                                    <?php 
            $markersTable->display();
            ?>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div id="col-left">
                        <?php 
            if (isset($_GET['id'])) {
                $imgEditId = $_GET['id'];
                if ($imgEditId > 0) {
                    $arrWhere = array("id = {$imgEditId}");
                    $markersData = front_end_users_fetch_data($table, $arrWhere);
                }
            }
            ?>
                        <div class="col-wrap">
                            <div class="form-wrap">
                                <?php 
            if (isset($imgEditId)) {
                $actionLabel = __('Edit');
            } else {
                $actionLabel = __('Add');
            }
            ?>
                                <h3>
                                    <?php 
            echo $actionLabel . ' ' . __('Marker');
            ?>
                                    <?php 
            if (isset($imgEditId)) {
                ?>
                                        <a href="?page=markers" class="add-new-h2"><?php 
                _e('Add New');
                ?>
</a>
                                    <?php 
            }
            ?>
                                </h3>
                                <form id="add-marker-form" method="post" action="">
									<div class="form-field">
                                        <label for="form-marker-name"><?php 
            _e('Country');
            ?>
<span class="chkRequired">*</span></label>
                                        <select value="<?php 
            echo isset($markersData->country) ? htmlspecialchars($markersData->country) : '';
            ?>
" id="form-marker-country" name="country">
											<?php 
            foreach ($fixedCountriesList as $key => $_country) {
                ?>
												<option value="<?php 
                echo $_country;
                ?>
" <?php 
                if ($_country == $markersData->country) {
                    ?>
selected<?php 
                }
                ?>
><?php 
                echo $_country;
                ?>
</option>
											<?php 
            }
            ?>
										</select>
                                    </div>
									<div class="form-field">
                                        <label for="form-marker-name"><?php 
            _e('Province');
            ?>
<span class="chkRequired">*</span></label>
                                        <select id="form-marker-province" name="province">
											<option>---</option>
										</select>
										<input type="hidden" value="<?php 
            echo isset($markersData->region) ? htmlspecialchars($markersData->region) : '';
            ?>
" id="form-marker-region" name="region" />
										
										<!--input type="text" value="<?php 
            echo isset($markersData->province) ? htmlspecialchars($markersData->province) : '';
            ?>
" id="form-marker-province" name="province" class="required" /-->
                                    </div>
									<div class="form-field">
                                        <label for="form-img-url"><?php 
            _e('Image URL');
            ?>
<span class="chkRequired">*</span></label>
                                        <input type="text" size="40" class="required" placeholder="Marker's image URL" value="<?php 
            echo isset($markersData->image) ? $markersData->image : '';
            ?>
" id="form-img-url" name="image"/>
                                        <input type="button" id="upload-img" value="<?php 
            _e('Upload');
            ?>
" style="width: 15%"/>
                                    </div>
									<div class="form-field">
                                        <label for="form-marker-views"><?php 
            _e('Description');
            ?>
</label>
                                        <textarea size="40" class="" maxlength="255" value="<?php 
            echo isset($markersData->description) ? htmlspecialchars($markersData->description) : '';
            ?>
" id="form-marker-description" name="description" placeholder="Marker's description"></textarea>
                                    </div>
									<div class="form-field">
                                        <label for="form-marker-views"><?php 
            _e('Views');
            ?>
<span class="chkRequired">*</span></label>
                                        <input type="number" size="40" class="required validate-number" maxlength="255" value="<?php 
            echo isset($markersData->views) ? htmlspecialchars($markersData->views) : '';
            ?>
" id="form-marker-views" name="views" placeholder="Marker's views count"/>
                                    </div>
									<div class="form-field">
                                        <label for="form-marker-url"><?php 
            _e('URL');
            ?>
</label>
                                        <input type="text" size="40" maxlength="255" placeholder="Marker's additional url" value="<?php 
            echo isset($markersData->link) ? htmlspecialchars($markersData->link) : '';
            ?>
" id="form-marker-link" name="link"/>
                                    </div>
                                    <p class="submit">
                                        <?php 
            $strBtn = __('Add');
            if (isset($_GET['id'])) {
                $strBtn = __('Update');
            }
            ?>
                                        <input type="hidden" value="<?php 
            echo isset($_GET['id']) ? $markersData->id : '';
            ?>
" name="id"/>
                                        <input type="submit" value="<?php 
            echo $strBtn;
            ?>
" class="button" id="addMarker" name="addMarker"/>
                                    </p>
                                </form>
                            </div>
                        </div>
                    </div><!-- /col-left -->
                </div><!-- /col-container -->
            </div>
    <?php 
            break;
    }
}
function mfgigcal_save_record()
{
    global $wpdb;
    $mfgigcal_table = $wpdb->prefix . "mfgigcal";
    remove_wp_magic_quotes();
    if (empty($_POST['start_date']) || empty($_POST['title'])) {
        echo '<div class="updated"><p>' . _e('Oops! Required information was not provided. Event could not be saved.') . '</p></div>';
        return;
    }
    // catch bad submissions that might get lost in the database...
    if (empty($_POST['end_date'])) {
        $end_date = $_POST['start_date'];
    } else {
        $end_date = $_POST['end_date'];
    }
    if ($_POST[id]) {
        // update record
        $wpdb->update($mfgigcal_table, array('start_date' => $_POST[start_date], 'end_date' => $end_date, 'pub_date' => date("Y-m-d H:i:s"), 'time' => $_POST[time], 'title' => $_POST[title], 'location' => $_POST[location], 'details' => $_POST[details]), array('id' => $_POST[id]), array('%s', '%s', '%s', '%s', '%s', '%s'));
    } else {
        // new record
        $wpdb->insert($mfgigcal_table, array('start_date' => $_POST[start_date], 'end_date' => $end_date, 'pub_date' => date("Y-m-d H:i:s"), 'time' => $_POST[time], 'title' => $_POST[title], 'location' => $_POST[location], 'details' => $_POST[details]), array('%s', '%s', '%s', '%s', '%s', '%s'));
    }
}