public function displayEditPage()
 {
     // init model
     // get item
     if ($this->requestAction() == 'add_new_profile') {
         $profile = new WPLA_AmazonProfile();
     } else {
         $profile = new WPLA_AmazonProfile($_REQUEST['profile']);
     }
     // $listingsModel = new ListingsModel();
     // $prepared_listings  = $listingsModel->getAllPreparedWithProfile( $item['profile_id'] );
     // $verified_listings  = $listingsModel->getAllVerifiedWithProfile( $item['profile_id'] );
     // $published_listings = $listingsModel->getAllPublishedWithProfile( $item['profile_id'] );
     // $ended_listings     = $listingsModel->getAllEndedWithProfile( $item['profile_id'] );
     $lm = new WPLA_ListingsModel();
     $listings = $profile->profile_id ? $lm->findAllListingsByColumn($profile->profile_id, 'profile_id') : array();
     $accounts = WPLA_AmazonAccount::getAll();
     $templates = WPLA_AmazonFeedTemplate::getAll();
     // separate ListingLoader templates
     $category_templates = array();
     $liloader_templates = array();
     foreach ($templates as $tpl) {
         if ($tpl->title == 'Offer') {
             $tpl->title = "Listing Loader";
             $liloader_templates[] = $tpl;
         } else {
             $category_templates[] = $tpl;
         }
     }
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'profile' => $profile, 'accounts' => $accounts, 'category_templates' => $category_templates, 'liloader_templates' => $liloader_templates, 'profile_listings' => $listings, 'profile_details' => maybe_unserialize($profile->details), 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-profiles');
     // $this->display( 'profiles_edit_page', array_merge( $aData, $profile ) );
     $this->display('profiles_edit_page', $aData);
 }
 public function displayCategoriesPage()
 {
     $templates = WPLA_AmazonFeedTemplate::getAll();
     $active_templates = array();
     foreach ($templates as $template) {
         $tpl_name = $template->name == 'Offer' ? 'ListingLoader' : $template->name;
         $active_templates[] = $template->site_id . $tpl_name;
     }
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'file_index' => WPLA_FeedTemplateIndex::get_file_index(), 'active_templates' => $active_templates, 'installed_templates' => $templates, 'settings_url' => 'admin.php?page=' . self::ParentMenuId . '-settings', 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-settings' . '&tab=categories');
     $this->display('settings_tpl_btg', $aData);
 }
    function display_feed_template_selector()
    {
        global $post;
        // get templates
        $templates = WPLA_AmazonFeedTemplate::getAll();
        $custom_feed_tpl_id = get_post_meta($post->ID, '_wpla_custom_feed_tpl_id', true);
        // separate ListingLoader templates
        $category_templates = array();
        $liloader_templates = array();
        foreach ($templates as $tpl) {
            if ($tpl->title == 'Offer') {
                $tpl->title = "Listing Loader";
                $liloader_templates[] = $tpl;
            } else {
                $category_templates[] = $tpl;
            }
        }
        // compatibility with profile code
        $wpl_category_templates = $category_templates;
        $wpl_liloader_templates = $liloader_templates;
        ?>
							<label for="wpl-text-tpl_id" class="text_label">
								<?php 
        echo __('Feed Template', 'wpla');
        ?>
                                <?php 
        wpla_tooltip('Each main category on Amazon uses a different feed template with special fields for that particular category.<br>You need to select the right template for your category and make sure all the required fields are filled in - or are populated from product details or attributes.');
        ?>
							</label>
							<select id="wpl-text-tpl_id" name="wpla_tpl_id" class="required-entry select">
							<option value="">-- <?php 
        echo __('Select feed template', 'wpla');
        ?>
 --</option> 
							<optgroup label="Generic Feeds">
								<?php 
        foreach ($wpl_liloader_templates as $tpl) {
            ?>
									<option value="<?php 
            echo $tpl->id;
            ?>
" 
										<?php 
            if ($custom_feed_tpl_id == $tpl->id) {
                ?>
											selected="selected"
										<?php 
            }
            ?>
										<?php 
            $site = new WPLA_AmazonMarket($tpl->site_id);
            ?>
										><?php 
            echo $tpl->title;
            ?>
 (<?php 
            echo $site ? $site->code : '?';
            ?>
)</option>
								<?php 
        }
        ?>
							</optgroup>
							<optgroup label="Category Specific Feeds">
								<?php 
        foreach ($wpl_category_templates as $tpl) {
            ?>
									<option value="<?php 
            echo $tpl->id;
            ?>
" 
										<?php 
            if ($custom_feed_tpl_id == $tpl->id) {
                ?>
											selected="selected"
										<?php 
            }
            ?>
										<?php 
            $site = new WPLA_AmazonMarket($tpl->site_id);
            ?>
										><?php 
            echo $tpl->title;
            ?>
 (<?php 
            echo $site ? $site->code : '?';
            ?>
)</option>
								<?php 
        }
        ?>
							</optgroup>
							</select>
							<br class="clear" />
							<p class="desc" style="">
								<?php 
        $link = sprintf('<a href="%s">%s</a>', 'admin.php?page=wpla-settings&tab=categories', __('Amazon &raquo; Settings &raquo; Categories', 'wpla'));
        ?>
								<?php 
        echo sprintf(__('You can add additional feed templates at %s.', 'wpla'), $link);
        ?>
							</p>


					<div id="FeedDataBox">
						<hr>
						<!-- <h3><span><?php 
        echo __('Feed Attributes', 'wpla');
        ?>
</span></h3> -->
						<div class="x-inside" id="wpla_feed_data_wrapper">
						</div>
					</div>

					<!-- hidden ajax categories tree -->
					<div id="amazon_categories_tree_wrapper">
						<div id="amazon_categories_tree_container">TEST</div>
					</div>

		<?php 
    }