if (isset($_GET['$progress_id'])) {
    $progress_id = $_GET['$progress_id'];
} else {
    $progress_id = '';
}
if ($action != null) {
    global $wpdb;
    if ($progress_id != null) {
        if ($action === "delete") {
            $wpdb->query($wpdb->prepare("delete from " . SMART_DONATIONS_PROGRESS_TABLE . " WHERE progress_id=%d", $progress_id));
        }
        if ($action === "edit") {
            $result = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . SMART_DONATIONS_PROGRESS_TABLE . " WHERE progress_id=%d", $progress_id));
            if (count($result) > 0) {
                $result = $result[0];
                $options = rednao_smart_donations_json_object($result->options, $result->styles, null, null, null, null);
                $script = <<<EOF
                        <script type="text/javascript" language="javascript">
                            var smartDonationsSavedProgress_Id="%s";
                            var smartDonationsSavedCampaign_Id="%s";
                            var smartDonationsSavedName="%s";
                            var smartDonationsSavedProgressType="%s";
                            var smartDonationsSavedOptions=jQuery.parseJSON('%s');
                        </script>
EOF;
                echo sprintf($script, $result->progress_id, $result->campaign_id, $result->progress_name, $result->progress_type, $options);
                include SMART_DONATIONS_DIR . '/smart-donations-progress-add.php';
                return;
            }
        }
    }
function rednao_smart_donations_load_progress($id, $title, $returnComponent)
{
    $options = get_transient("rednao_smart_donations_progress_{$id}");
    $options = false;
    if ($options == false) {
        $options = null;
        global $wpdb;
        $result = $wpdb->get_results($wpdb->prepare("select options,styles,campaign_id from " . SMART_DONATIONS_PROGRESS_TABLE . " where progress_id=%d", $id));
        if (count($result) > 0) {
            $result = $result[0];
            $options = $result->options;
            $styles = $result->styles;
            $campaign_id = $result->campaign_id;
            if ($campaign_id == null) {
                return "";
            }
            if ($campaign_id == 0) {
                $result = $wpdb->get_results($wpdb->prepare("select coalesce(goal,0) goal,sum(mc_gross) amount,(select count(*) from " . SMART_DONATIONS_TRANSACTION_TABLE . " where campaign_id=%d) donators\n                                                    from " . SMART_DONATIONS_TRANSACTION_TABLE . " tran\n                                                    left join wp_smart_donations_campaign_table camp\n                                                    on tran.campaign_id=camp.campaign_id\n                                                    where tran.campaign_id=%d\n                                                    group by tran.campaign_id,goal", $campaign_id, $campaign_id));
            } else {
                $result = $wpdb->get_results($wpdb->prepare("select coalesce(goal,0) goal,sum(mc_gross) amount,(select count(*) from " . SMART_DONATIONS_TRANSACTION_TABLE . " where campaign_id=%d) donators\n                                                    from " . SMART_DONATIONS_CAMPAIGN_TABLE . " camp\n                                                    left join " . SMART_DONATIONS_TRANSACTION_TABLE . " tran\n                                                    on tran.campaign_id=camp.campaign_id\n                                                    where camp.campaign_id=%d\n                                                    group by tran.campaign_id,goal", $campaign_id, $campaign_id));
            }
            $amount = 0;
            $goal = 0;
            $donators = 0;
            if (count($result) > 0) {
                $amount = $result[0]->amount;
                $goal = $result[0]->goal;
                $donators = $result[0]->donators;
            }
            if ($options != null) {
                $options = rednao_smart_donations_json_object($options, $styles, $amount, $goal, $donators, null);
                set_transient("rednao_smart_donations_progress_{$id}", $options, 60 * 60 * 24 * 31);
            }
        }
    }
    wp_enqueue_script('jquery');
    wp_enqueue_script('isolated-slider', plugin_dir_url(__FILE__) . 'js/rednao-isolated-jq.js');
    wp_enqueue_script('smart-donations-progress-gen', plugin_dir_url(__FILE__) . 'js/smart-donations-progress-gen.js', array('isolated-slider'));
    wp_enqueue_style('smart-donations-main-style', plugin_dir_url(__FILE__) . 'css/mainStyle.css');
    wp_enqueue_style('smart-donations-Slider', plugin_dir_url(__FILE__) . 'css/smartDonationsSlider/jquery-ui-1.10.2.custom.min.css');
    $random = rand();
    if ($returnComponent == false) {
        if ($options === null) {
            return;
        }
        if ($title) {
            echo "<div class='widget-wrapper widget'><div class='title-wrapper'><h3 class='widgettitle widget-title'>{$title}</h3><div class='clear'></div></div>";
        }
        ?>


        <div id="progressContainer<?php 
        echo $random;
        ?>
" class='wcontainer'></div>

        <script>
            var smartDonationsRootPath="<?php 
        echo plugin_dir_url(__FILE__);
        ?>
";

            if(!window.smartDonationsProgressItemsToLoad)
                window.smartDonationsProgressItemsToLoad=new Array();;

            window.smartDonationsProgressItemsToLoad.push({'options':<?php 
        echo $options;
        ?>
,'element':'progressContainer<?php 
        echo $random;
        ?>
'});

        </script>
    <?php 
        if ($title) {
            echo "</div>";
        }
    } else {
        if (options === null) {
            return "";
        }
        return "<div id='progressContainer{$random}'></div>\n            <script>\n                var smartDonationsRootPath=\"" . plugin_dir_url(__FILE__) . "\";\n                if(!window.smartDonationsProgressItemsToLoad)\n                    window.smartDonationsProgressItemsToLoad=new Array();;\n                window.smartDonationsProgressItemsToLoad.push({'options':{$options},'element':'progressContainer{$random}'});\n            </script>\n           ";
    }
}