<div class="postbox" id="TemplateVersionsBox">
						<h3><span><?php 
echo __('Installed Feed Templates', 'wpla');
?>
</span></h3>
						<div class="inside">


							<!-- <h4>Categories</h4> -->
							<ul>
							<?php 
foreach ($wpl_installed_templates as $template) {
    ?>
								<?php 
    $profile_count = WPLA_AmazonProfile::countProfilesUsingTemplate($template->id);
    $remove_link = 'admin.php?page=wpla-settings&tab=categories&action=wpla_remove_tpl&tpl_id=' . $template->id;
    ?>
								
								<li>
									<hr>
									<?php 
    if ($profile_count == 0) {
        ?>
										<a href="<?php 
        echo $remove_link;
        ?>
" style="float:right; margin-top:1.3em;" class="button button-small"><?php 
        echo __('Remove', 'wpla');
        ?>
</a>
 public function deleteProfiles($profiles)
 {
     if (!is_array($profiles)) {
         $profiles = array($profiles);
     }
     $count = 0;
     foreach ($profiles as $id) {
         if (!$id) {
             continue;
         }
         // check if there are listings using this profile
         $lm = new WPLA_ListingsModel();
         $listings = $lm->findAllListingsByColumn($id, 'profile_id');
         if (!empty($listings)) {
             $this->showMessage('This profile is applied to ' . count($listings) . ' listings and can not be deleted.', 1, 1);
             continue;
         }
         $profile = new WPLA_AmazonProfile($id);
         $profile->delete();
         $count++;
     }
     if ($count) {
         $this->showMessage(sprintf(__('%s profile(s) were removed.', 'wpla'), $count));
     }
 }
 function addPrepareActions($wp_admin_bar, $post_id)
 {
     // Prepare listing link
     $url = '';
     $args = array('id' => 'wpla_prepare_listing', 'title' => __('Prepare listing', 'wpla'), 'href' => $url, 'parent' => 'wpla_top');
     $wp_admin_bar->add_node($args);
     $pm = new WPLA_AmazonProfile();
     $profiles = $pm->getAll();
     foreach ($profiles as $profile) {
         // echo "<pre>";print_r($profile);echo"</pre>";#die();
         $profile_id = $profile->profile_id;
         $url = admin_url('admin.php?page=wpla&action=wpla_prepare_single_listing&product_id=' . $post_id . '&profile_id=' . $profile_id);
         $args = array('id' => 'wpla_list_on_amazon_' . $profile->profile_id, 'title' => $profile->profile_name, 'href' => $url, 'parent' => 'wpla_prepare_listing');
         $wp_admin_bar->add_node($args);
     }
     return $args;
 }
 public function ajax_wpla_show_profile_selection()
 {
     // fetch profiles
     $profiles = WPLA_AmazonProfile::getAll();
     // load template
     $tpldata = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'profiles' => $profiles, 'form_action' => 'admin.php?page=' . self::ParentMenuId);
     @WPLA_Page::display('profile/select_profile', $tpldata);
     exit;
 }
    function extra_tablenav($which)
    {
        if ('top' != $which) {
            return;
        }
        $wpl_profiles = WPLA_AmazonProfile::getAll();
        $wpl_accounts = WPLA_AmazonAccount::getAll(true);
        $profile_id = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : false;
        $account_id = isset($_REQUEST['account_id']) ? $_REQUEST['account_id'] : false;
        // echo "<pre>";print_r($wpl_profiles);echo"</pre>";die();
        ?>
        <div class="alignleft actions" style="">

            <select name="profile_id">
                <option value=""><?php 
        _e('All profiles', 'wpla');
        ?>
</option>
                <option value="_NONE_" <?php 
        if ($profile_id == '_NONE_') {
            echo 'selected';
        }
        ?>
 ><?php 
        _e('No profile', 'wpla');
        ?>
</option>
                <?php 
        foreach ($wpl_profiles as $profile) {
            ?>
                    <option value="<?php 
            echo $profile->profile_id;
            ?>
"
                        <?php 
            if ($profile_id == $profile->profile_id) {
                echo 'selected';
            }
            ?>
                        ><?php 
            echo $profile->profile_name;
            ?>
</option>
                <?php 
        }
        ?>
            </select>            

            <select name="account_id">
                <option value=""><?php 
        _e('All accounts', 'wpla');
        ?>
</option>
                <?php 
        foreach ($wpl_accounts as $account) {
            ?>
                    <option value="<?php 
            echo $account->id;
            ?>
"
                        <?php 
            if ($account_id == $account->id) {
                echo 'selected';
            }
            ?>
                        ><?php 
            echo $account->title;
            ?>
 (<?php 
            echo $account->market_code;
            ?>
)</option>
                <?php 
        }
        ?>
            </select>            

            <input type="submit" name="" id="post-query-submit" class="button" value="Filter">

        </div>
        <?php 
    }
 public function displayEditPage()
 {
     // get item
     $listingsModel = new WPLA_ListingsModel();
     $item = $listingsModel->getItem($_REQUEST['listing']);
     // get other data
     $profiles = WPLA_AmazonProfile::getAll();
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'item' => $item, 'feed_profiles' => $profiles, 'form_action' => 'admin.php?page=' . self::ParentMenuId . (isset($_REQUEST['paged']) ? '&paged=' . $_REQUEST['paged'] : ''));
     $this->display('listings_edit_page', array_merge($aData, $item));
 }
 /** ************************************************************************
  * REQUIRED! This is where you prepare your data for display. This method will
  * usually be used to query the database, sort and filter the data, and generally
  * get it ready to be displayed. At a minimum, we should set $this->items and
  * $this->set_pagination_args(), although the following properties and methods
  * are frequently interacted with here...
  * 
  * @uses $this->_column_headers
  * @uses $this->items
  * @uses $this->get_columns()
  * @uses $this->get_sortable_columns()
  * @uses $this->get_pagenum()
  * @uses $this->set_pagination_args()
  **************************************************************************/
 function prepare_items()
 {
     // process bulk actions
     $this->process_bulk_action();
     // get pagination state
     $current_page = $this->get_pagenum();
     $per_page = $this->get_items_per_page('profiles_per_page', 20);
     // define columns
     $this->_column_headers = $this->get_column_info();
     // fetch profiles from model
     $profilesModel = new WPLA_AmazonProfile();
     $this->items = $profilesModel->getPageItems($current_page, $per_page);
     $total_items = $profilesModel->total_items;
     // register our pagination options & calculations.
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }