<?php

/**
 * @Package: WordPress Plugin
 * @Subpackage: Ultra Portfolio
 * @Since: Ultra Portfolio 1.0
 * @Current Version: Ultra Portfolio 3.1
 * @WordPress Version: 3.5 or above
 * This file is part of Ultra Portofolio WordPress Plugin.
 */
function uport_dashboard() {
    ?>
    <div class='wrap'>
        <h2 class='uport_head'><?php _e('Portfolio Dashboard ', 'uport-framework'); ?><a href="<?php echo esc_url(home_url()); ?>/wp-admin/admin.php?page=uport_edit_portfolio" title="" class="add-new-h2"><?php _e('Add New', 'uport-framework'); ?></a></h2>
            <?php
            //echo path_join(WP_PLUGIN_URL, basename(dirname(__FILE__)).'/demos/');
            echo "<span class='uport_msg'></span>";

            global $wpdb;
            $table_name1 = $wpdb->prefix . "uport";
            $printdata = "";
            $querystr = " SELECT * FROM $table_name1 WHERE active = '1'";
            $obj_charts = $wpdb->get_results($querystr);

            echo "<table border=0 cellspacing=0 cellpadding=0 class='viewtable'>";
            echo "<tr>
                <td style='width:5%'>".__('ID', 'uport-framework')."</td>
                <td style='width:16%'>".__('Portfolio Name', 'uport-framework')."</td>
                <td style='width:22%'>".__('Code', 'uport-framework')."</td>
                <td style='width:25%'>".__('Actions', 'uport-framework')."</td>
                <td style='width:8%'><input type='checkbox' class='uportallrow' name='uportallrow' id='uportallrow'/>&nbsp;".__('Select', 'uport-framework')."</td>
             </tr>";


            if (sizeof($obj_charts) > 0) {
                foreach ($obj_charts as $chart) {

                    $id = $chart->id;
                    $val1arr = uport_get_arr($id, '1');
                    $val4arr = uport_get_arr($id, '4');

                    /* --------------------
                      get categories
                      --------------------- */
                    /*  
                    $catids = uport_catstrs('arr');
                    $str = "";
                    $catstr = array();
                    if (isset($val1arr['categories'])) {
                        $catstr = array_unique(array_filter(explode("|", $val1arr['categories'])));
                        foreach ($catstr as $catid) {
                            $str .= $catids[$catid] . ", ";
                        }
                        $str = substr($str, 0, -2);
                    }
                    */

                    /* --------------------
                      get effect
                      --------------------- */
                    /*
                    $effname = "";
                    if (isset($val4arr['overlayeffect']) && $val4arr['overlayeffect'] != "") {
                        $effexp = explode("|", $val4arr['overlayeffect']);
                        $effexp = array_filter($effexp);
                        $effarr = uport_effect_list('arr');
                        $effid = $effexp[0];
                        if (isset($effarr[$effid])) {
                            $effname = $effarr[$effid];
                        }
                    }
                    */
                    $portname = "";
                    if (isset($val1arr['name'])) {
                        $portname = $val1arr['name'];
                    }

                    /* --------------------
                      display row
                      --------------------- */
                    echo "<tr class='uportrow-".$id."'><td><strong>" . $id . "</strong></td><td class='maintitle'><strong>".__($portname, 'uport-framework')."</strong></td>";
                    //echo "<td>" . $str . "</td><td>" . $effname . "</td>";
                	echo "<td><strong>Shortcode:</strong>&nbsp;[ultra-portfolio id='" . $id . "']<br><strong>PHP:</strong>&nbsp;&lt;?php&nbsp;do_shortcode([ultra-portfolio id='" . $id . "']);&nbsp;?></td>
                	<td align='right' class='actions'>
                	<a class='smallbutton view' target='_blank' href='" . esc_url(add_query_arg(array('id' => $id, 'type' => 'uport_display_portfolio'))) . "'>".__('View', 'uport-framework')."</a>
                	<a class='smallbutton edit' href='" . esc_url(add_query_arg(array('id' => $id, 'page' => 'uport_edit_portfolio'))) . "'>".__('Edit', 'uport-framework')."</a>
                	<a class='smallbutton delete' href='javascript:;' onclick=\"uport_actionthis('" . esc_url(add_query_arg(array('page' => 'uport'))) . "','" . $id . "','del_portfolio')\" >".__('Del', 'uport-framework')."</a>
                    <a class='smallbutton copy' href='javascript:;' onclick=\"uport_actionthis('" . esc_url(add_query_arg(array('page' => 'uport'))) . "','" . $id . "','copy_portfolio')\" >".__('Copy', 'uport-framework')."</a>

                	</td>
                    <td align='right' class='selectrow'>
                    <input type='checkbox' class='uportrow' name='uportrow' id='uportrow_".$id."' data-id='".$id."' value='".$id."' data-type='portfolio'/>
                    </td>

                	</tr>";

                    //$printdata .= "@@@rows_affected = @@@wpdb->insert( @@@table_name1, array( 'id' => '".$chart->id."',  'step1val' => '".$chart->step1val."', 'step2val' => '".$chart->step2val."', 'step3val' => '".$chart->step3val."', 'step4val' => '".$chart->step4val."', 'step5val' => '".$chart->step5val."', 'step6val' => '".$chart->step6val."', 'step7val' => '".$chart->step7val."', 'active' => '".$chart->active."',  'updatedon' => '".$chart->updatedon."' ) ); <br><br>";	
                }
            } else {
                echo "<tr><td colspan=6>".__('No results found', 'uport-framework');
                ?>
            <a href='<?php echo esc_url(home_url()); ?>/wp-admin/admin.php?page=uport_install_demos'><?php echo __('Click to install demos', 'uport-framework'); ?></a>
            <?php
            echo "</td></tr>";
        }
        echo "</table>";

        echo "<div class='selactions_wrap'><button class='deletesel uport_selactions' disabled href='javascript:;' data-type='portfolio' data-action='delete' >".__('Delete Selected', 'uport-framework')."</button>
        <button class='copysel uport_selactions' disabled href='javascript:;' data-type='portfolio' data-action='copy' >".__('Copy Selected', 'uport-framework')."</button></div>";

//echo $printdata;
    }
    ?>