Пример #1
0
/**
* Function _fnDemoRenderListPage is called to display list of table.
*/
function _fnDemoRenderListPage()
{
    //Create an instance of our package class...
    $testListTable = new Testimonial_List_Table();
    //for message display
    $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[] = '<div id="message" class="updated"><p>' . sprintf(_n('testimonial deleted.', '%s testimonials deleted.', $delete_count), number_format_i18n($delete_count)) . '</p></div>';
                break;
            case 'add':
                $strmsg = isset($_GET['id']) ? "updated" : "Added";
                $messages[] = '<div id="message" class="updated"><p>' . __('New record $strmsg.') . '</p></div>';
                break;
        }
    }
    $this_file = "?page=" . $_REQUEST['page'];
    switch ($testListTable->current_action()) {
        case "add":
        case "edit":
        case "delete":
            global $wpdb;
            if (isset($_GET['action2']) && $_GET['action2'] == "-1") {
                $del_id = $_GET['testimonial'];
                $del_data = swpt_delete_data($del_id);
            }
            if (isset($_GET['testimonial_id']) && $_GET['testimonial_id']) {
                $del_id = $_GET['testimonial_id'];
                $del_data = swpt_delete_data($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:
            ?>
            <script type='text/javascript' src="<?php 
            echo plugins_url('js/jquery.validate.js', __FILE__);
            ?>
"></script>
            <script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery("#add_testi").validate();
            });
            </script>

            <?php 
            global $wpdb;
            $strTbl = $wpdb->prefix . "testimonials";
            $strPageListingParam = "testimonial";
            $arrWhere = array();
            if (!empty($_POST['description'])) {
                substr($_POST['description'], 0, 5000);
            }
            //check blank data & add record
            if (!empty($_POST['addTesti'])) {
                //call function add_update_testi to add / edit record
                if ($_POST['id'] != "") {
                    $arrWhere = array("id" => $_POST['id']);
                    unset($_POST['id']);
                }
                //remove submit button & remove blank field
                unset($_POST['addTesti']);
                $arrData = array();
                $arrData = array_filter($_POST);
                $arrMsg = array();
                if (count($arrData) > 0) {
                    $boolAdded = swpt_add_update_testi($strTbl, $arrData, $arrWhere);
                    if (!empty($arrWhere) && $boolAdded) {
                        $arrMsg = array('msg' => 'Testimonial Updated.', 'msgClass' => 'updated');
                    } elseif (empty($arrWhere) && $boolAdded) {
                        $arrMsg = array('msg' => 'Testimonial Added.', 'msgClass' => 'updated');
                    } else {
                        $arrMsg = array('msg' => 'Error occured while saving your testimonial.', 'msgClass' => 'error');
                    }
                }
            }
            if (isset($_GET['testimonial'])) {
                $intEditId = $_GET['testimonial'];
                if ($intEditId > 0) {
                    $arrWhere = array("id = {$intEditId}");
                    $arrTestiData = swpt_edit_data($strTbl, $arrWhere);
                }
            }
            //Fetch, prepare, sort, and filter our data...
            $testListTable->prepare_items();
            if (!empty($messages)) {
                foreach ($messages as $msg) {
                    echo $msg;
                }
            }
            ?>
            
            <div class="wrap">
                <div class="icon32 icon32-posts-post" id="icon-edit">
                    <br>
                </div>
                <h2>Testimonials</h2>
                <?php 
            if (isset($arrMsg) && !empty($arrMsg)) {
                ?>
                    <div class="<?php 
                echo $arrMsg['msgClass'];
                ?>
">
                    <p><?php 
                echo $arrMsg['msg'];
                ?>
</p>
                </div>
                <?php 
            }
            ?>
                <div id="col-container">
                    <div id="col-right">
                        <div class="col-wrap">
                            <div class="form-wrap">
                                <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions -->
                                <form id="testimonials-filter" method="get">
                                    <!-- For plugins, we also need to ensure that the form posts back to our current page -->
                                    <input type="hidden" name="page" value="<?php 
            echo $_REQUEST['page'];
            ?>
" />
                                    <!-- Now we can render the completed list table -->
                                    <?php 
            $testListTable->display();
            ?>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div id="col-left">
                        <div class="col-wrap">
                            <div class="form-wrap">
                                <?php 
            if (isset($intEditId)) {
                $strLabel = "Edit";
            } else {
                $strLabel = "Add";
            }
            ?>
                                <h3>
                                    <?php 
            echo $strLabel;
            ?>
 Testimonial
                                    <?php 
            if (isset($intEditId)) {
                ?>
                                    <a href="?page=testimonial" class="add-new-h2">Add New</a>
                                    <?php 
            }
            ?>
                                </h3>
                                <form id="add_testi" name="add_testi"  method="post" action="" class="frm_testi">
                                    <div class="form-field">
                                        <label for="name">Customer Name<span class="chkRequired">*</span></label>
                                        <p>Name of customer who given you the feedback.</p>
                                        <input type="text" size="40" class="required" value="<?php 
            if (isset($arrTestiData->name)) {
                echo stripslashes($arrTestiData->name);
            }
            ?>
" id="name" name="name">
                                    </div>
                                    <div class="form-field">
                                        <label for="country">Country</label>
                                        <p>Country where your customer is located in.</p>
                                        <input type="text" size="40" value="<?php 
            if (isset($arrTestiData->country)) {
                echo $arrTestiData->country;
            }
            ?>
" id="country" name="country" class="required">
                                    </div>
                                    <div class="form-field">
                                        <label for="Description">Testimonial<span class="chkRequired">*</span></label>
                                        <p>Few words said by the company.</p>
                                        <textarea name ='description' class="required" cols="51" rows="7" maxlength="5000" ><?php 
            if (isset($arrTestiData->description)) {
                echo stripslashes($arrTestiData->description);
            }
            ?>
</textarea>
                                        <p>Maximum 5000 characters are allowed.</p>
                                    </div>
                                    <p class="submit">
                                        <?php 
            $strBtn = 'Add';
            if (isset($_GET['testimonial'])) {
                $strBtn = 'Update';
            }
            ?>
                                        <input type="hidden" value="<?php 
            if (isset($_GET['testimonial'])) {
                echo $arrTestiData->id;
            }
            ?>
" name="id">
                                        <input type="submit" value="<?php 
            echo $strBtn;
            ?>
" class="button" id="addTestis" name="addTesti">
                                    </p>
                                </form>
                            </div>
                        </div>
                    </div><!-- /col-left -->
                </div><!-- /col-container -->
            </div>
            <?php 
            break;
    }
}
Пример #2
0
    if (count($arrData) > 0) {
        $boolAdded = swpt_add_update_testi($strTbl, $arrData, $arrWhere);
        if (!empty($arrWhere) && $boolAdded) {
            $arrMsg = array('msg' => 'Testimonial Updated.', 'msgClass' => 'updated');
        } elseif (empty($arrWhere) && $boolAdded) {
            $arrMsg = array('msg' => 'Testimonial Added.', 'msgClass' => 'updated');
        } else {
            $arrMsg = array('msg' => 'Error occured while saving your testimonial.', 'msgClass' => 'error');
        }
    }
}
if (isset($_GET['testimonial'])) {
    $intEditId = $_GET['testimonial'];
    if ($intEditId > 0) {
        $arrWhere = array("id = {$intEditId}");
        $arrTestiData = swpt_edit_data($strTbl, $arrWhere);
    }
}
?>
<div class="wrap">
 	<div class="icon32 icon32-posts-post" id="icon-edit"><br></div>
 	<?php 
if (isset($intEditId)) {
    $strLabel = "Edit";
} else {
    $strLabel = "Add";
}
?>
	<h2> <?php 
echo $strLabel;
?>