function lhg_scan_overview_shortcode($attr)
{
    require_once plugin_dir_path(__FILE__) . "../../lhg-hardware-profile-manager/templates/uid.php";
    require_once plugin_dir_path(__FILE__) . "lhg.conf";
    global $region;
    $langurl = lhg_get_lang_url_from_region($region);
    if ($langurl == "de") {
        $langurl = "";
    }
    $myquery = $lhg_price_db->prepare("SELECT id, sid, pub_id, scandate, kversion, distribution, status FROM `lhgscansessions` GROUP BY scandate ORDER BY scandate DESC LIMIT 10;");
    #$sql = "SELECT id FROM `lhgshops` WHERE region <> \"de\"";
    $identified_scans = $lhg_price_db->get_results($myquery);
    #$output = "List of Scans";
    $output .= "<h2>Latest Hardware Scans:</h2>";
    $output .= '<table id="registration">';
    $output .= '<tr id="header">

                <td id="title-scandate">Scan Date</td>
                <td id="title-scanstatus">Status</td>
                ';
    $output .= '<td id="title-scanlist-distribution" width="30%">Distribution</td>
                      
                      <td id="hwscan-col2" width="20%">Kernel Version</td>
                <td id="hwscan-col2" width="13%">Hardware Components</td>
                </tr>';
    foreach ($identified_scans as $a_identified_scan) {
        $SID = $a_identified_scan->sid;
        $pub_id = $a_identified_scan->pub_id;
        if ($pub_id == "") {
            $pub_id = lhg_create_pub_id($SID);
        }
        $myquery = $lhg_price_db->prepare("SELECT COUNT(DISTINCT idstring) FROM `lhghwscans` WHERE sid = %s AND postid = 0", $SID);
        #$sql = "SELECT id FROM `lhgshops` WHERE region <> \"de\"";
        $num_unidentified_hw = $lhg_price_db->get_var($myquery);
        #print "NU: $num_unidentified_hw";
        $myquery = $lhg_price_db->prepare("SELECT COUNT(DISTINCT postid) FROM `lhghwscans` WHERE sid = %s AND postid <> 0", $SID);
        #$sql = "SELECT id FROM `lhgshops` WHERE region <> \"de\"";
        $num_identified_hw = $lhg_price_db->get_var($myquery);
        #print "NI: $num_identified_hw";
        $scandate = $a_identified_scan->scandate;
        $scandate_txt = gmdate("Y-m-d, H:i:s", $scandate);
        $distribution = "unknown";
        $kversion = "unkwnown";
        $distribution = $a_identified_scan->distribution;
        $kversion = $a_identified_scan->kversion;
        $scan_status_raw = $a_identified_scan->status;
        #unassigned scan
        #print "SST:
        if ($scan_status_raw == "") {
            $scan_status_raw = "new";
        }
        if ($scan_status_raw == "duplicate") {
            $scan_status_raw = "new";
        }
        # ToDo: Duplicates should be handled separately with pointing system not taking scans into account
        if ($scan_status_raw == "new") {
            $scan_status = '<span class="scan-status-new">New</span>';
        }
        if ($scan_status_raw == "ongoing") {
            $scan_status = '<span class="scan-status-ongoing">Ongoing</span>';
        }
        if ($scan_status_raw == "complete") {
            $scan_status = '<span class="scan-status-done">Done</span>';
        }
        if ($scan_status_raw == "feedback") {
            $scan_status = '<span class="scan-status-ongoing">User feedback needed</span>';
        }
        $logo = get_distri_logo($distribution);
        $output .= "<tr id=\"regcont\">";
        $langurl = "/" . $langurl;
        if ($langurl == "/") {
            $langurl = "";
        }
        $langurl = str_replace("//", "/", $langurl);
        $output .= "\n                        <td id=\"col-hw\">\n\n                        " . '<div class="subscribe-hwtext-scanlist"><div class="subscribe-hwtext-span-scanlist">&nbsp;<a href="' . $langurl . '/hardware-profile/system-' . $pub_id . '" target="_blank">' . $scandate_txt . ' (see details ...)</a></div></div>';
        $output .= " </td>";
        # Status ---
        $output .= "\n                        <td id=\"col-scan-status\">\n\n                        " . '<div class="subscribe-hwtext-scanlist"><div class="subscribe-hwtext-span-scanstatus">' . $scan_status . '</div></div>';
        $output .= " </td>";
        $output .= "\n                        <td id=\"col-scanresults-distri\">\n                        " . '<div class="scan-overview-distri-logo"><img src="' . $logo . '" width="40" ></div>' . "<div class='subscribe-column-2-pub'>{$distribution}</div>\n                        </td>";
        $output .= "\n                        <td id=\"col4\">\n                        <span class='subscribe-column-2'>{$kversion}</span>\n                        </td>";
        #$registration_date=$a_subscription->dt;
        #list ($registration_date, $registration_time) = explode(" ",$registration_date);
        $categorypart2 = "";
        if ($category_name2 != "") {
            $categorypart2 = "<br>({$category_name2})";
        }
        $output .= "\n                        <td id=\"col2\">\n                        <span class='subscribe-column-1'><center>Identified: {$num_identified_hw} <br> Unknown: {$num_unidentified_hw}  </center></span>\n                        </td>";
        $output .= "</tr>\n";
    }
    #var_dump($identified_scans);
    $output .= "</table>";
    return $output;
}
function lhg_menu_hw_scans()
{
    global $lhg_price_db;
    if ($_POST != "") {
        lhg_db_update_scaninfo();
    }
    $res = lhg_db_get_scan_sids();
    print "<h1>Hardware Scans</h1>";
    print "<br>";
    #print "POST:";
    #var_dump ( $_POST );
    #var_dump( $res );
    print '<form action="admin.php?page=lhg_menu_hw_scans" method="post">';
    $user = wp_get_current_user();
    $userid = $user->ID;
    #defaults
    $show_new = true;
    $show_ongoing = true;
    $show_complete = false;
    $show_feedback = false;
    $show_new = get_user_meta($userid, 'lhg_scan_show_new', true);
    $show_ongoing = get_user_meta($userid, 'lhg_scan_show_ongoing', true);
    $show_complete = get_user_meta($userid, 'lhg_scan_show_complete', true);
    $show_feedback = get_user_meta($userid, 'lhg_scan_show_feedback', true);
    #not defined -> set defaults
    #if ($show_new      == "") {add_user_meta( $userid, 'lhg_scan_show_new',      true , true); $show_new      = true;}
    #if ($show_ongoing  == "") {add_user_meta( $userid, 'lhg_scan_show_ongoing',  true , true); $show_ongoing  = true;}
    #if ($show_complete == "") {add_user_meta( $userid, 'lhg_scan_show_complete', false, true); $show_complete = false;}
    print "Show: ";
    # $userid: $show_new - $show_ongoing - $show_complete";
    $show_new == true ? print '<input name="filter_show_new" type="checkbox" value="1" checked /> New ' : (print '<input name="filter_show_new" type="checkbox" value="1" /> New ');
    $show_ongoing == true ? print '<input name="filter_show_ongoing" type="checkbox" value="true" checked /> Ongoing ' : (print '<input name="filter_show_ongoing" type="checkbox" value="false" /> Ongoing ');
    $show_complete == true ? print '<input name="filter_show_complete" type="checkbox" value="true" checked /> Complete ' : (print '<input name="filter_show_complete" type="checkbox" value="false" /> Complete ');
    $show_feedback == true ? print '<input name="filter_show_feedback" type="checkbox" value="true" checked /> Feedback needed ' : (print '<input name="filter_show_feedback" type="checkbox" value="false" /> Feedback needed ');
    print "<table border=1><tr>";
    print "<td><b>Date</b></td><td><b>Link</b></td><td><b>Comment User</b></td> <td><b>Comment Admins</b></td> <td><b>Status</b></td> </tr>";
    foreach ($res as $resN) {
        $sid = $resN->sid;
        $status = $resN->status;
        if ($status == "" or $status == "duplicate" or $status == "new" && $show_new == true or $status == "ongoing" && $show_ongoing == true or $status == "feedback" && $show_feedback == true or $status == "complete" && $show_complete == true) {
            $pub_id = $resN->pub_id;
            if ($result->pub_id == "") {
                $pub_id = lhg_create_pub_id($sid);
            }
            $time = $resN->scandate;
            $date = gmdate("m/d/Y g:i:s A", $time);
            $acomment = $resN->admincomment;
            $ucomment = $resN->usercomment;
            #
            # check for comments on articles, i.e. cycle through all postids
            $myquery = $lhg_price_db->prepare("SELECT usercomment FROM `lhghwscans` WHERE sid = %s", $sid);
            $commentlist = $lhg_price_db->get_results($myquery);
            foreach ($commentlist as $usercomment) {
                if ($usercomment->usercomment != "") {
                    if ($ucomment == "") {
                        $ucomment .= $usercomment->usercomment;
                    } else {
                        $ucomment .= "; " . $usercomment->usercomment;
                    }
                }
            }
            $email = $resN->email;
            $ucomment_short = $ucomment;
            if (strlen($ucomment) > 50) {
                $ucomment_short = substr(sanitize_text_field($ucomment), 0, 50) . "...";
            }
            $distribution = $resN->distribution;
            $status = $resN->status;
            #$sid2 = $res[1]->sid;
            #var_dump ($sid ."--".$sid2);
            #print "SID: $sid<br>";
            #extract userdata
            $uploader_guid = lhg_get_scan_uploader_guid($sid);
            $usertxt = "";
            $duplicate_txt = "";
            if ($status == "duplicate") {
                $duplicate_txt = "dup";
            }
            if ($uploader_guid > 0) {
                $user_tmp = lhg_get_userdata_guid($uploader_guid);
                $user = $user_tmp[0];
                $user_nicename = $user->user_nicename;
                $avatar = $user->avatar;
                $wpuid_de = $user->wpuid_de;
                $wpuid_com = $user->wpuid;
                #Gravatar stored avatar image
                if (strpos($avatar, "gravatar") > 1) {
                    $start = strpos($avatar, "src='");
                    $imgurl = substr($avatar, $start + 5);
                    $tmp = explode("' class", $imgurl);
                    $imgurl = $tmp[0];
                    $usertxt = '<img src="' . $imgurl . '" width="20px" heigth="20px" title="User: '******'" alt="User: '******'">';
                } else {
                    if (strpos($avatar, "http://")) {
                        #local avatar .com
                        $start = strpos($avatar, 'src="');
                        $imgurl = substr($avatar, $start + 5);
                        $tmp = explode('" class', $imgurl);
                        $imgurl = $tmp[0];
                        $usertxt = '<img src="' . $imgurl . '" width="20px" heigth="20px" title="User: '******'" alt="User: '******'">';
                    } else {
                        #local avatar .de
                        $start = strpos($avatar, "src='");
                        $imgurl = substr($avatar, $start + 5);
                        $tmp = explode("' class", $imgurl);
                        $imgurl = $tmp[0];
                        $usertxt = '<img src="http://www.linux-hardware-guide.de' . $imgurl . '" width="20px" heigth="20px" title="User: '******'" alt="User: '******'">';
                    }
                }
            }
            $statusSelector = '
				<select name="status-' . $sid . '">';
            $statusSelector .= ($status == "new" or $status == "duplicate") ? '<option value="new" selected>New</option>' : '<option value="new">New</option>';
            $statusSelector .= $status == "ongoing" ? '<option value="ongoing" selected>Ongoing</option>' : '<option value="ongoing">Ongoing</option>';
            $statusSelector .= $status == "complete" ? '<option value="complete" selected>Complete</option>' : '<option value="complete">Complete</option>';
            $statusSelector .= $status == "feedback" ? '<option value="feedback" selected>Feedback needed</option>' : '<option value="feedback">Feedback needed</option>';
            $statusSelector .= '</select>';
            $distrilogo = get_distri_logo($distribution);
            if ($email == "") {
                $maillogo = '<span class="emailgrey" style="color: grey; font-weight: bold; font-size: 1.4em; position: relative; top: -3px;"> @</span>';
            }
            #<i class="icon-envelope icon-large2"></i>';
            if ($email != "") {
                $maillogo = '<span class="emailgreen" style="color: green; font-weight: bold; font-size: 1.4em; position: relative; top: -3px;">@</span>';
            }
            #<i class="icon-envelope icon-large2"></i>';
            $commentavail = '<span class="emailgrey" style="color: grey; font-weight: bold; font-size: 1.4em; position: relative; top: -3px;">C</span>';
            if ($ucomment != "") {
                $commentavail = '<span class="emailgreen" style="color: green; font-weight: bold; font-size: 1.4em; position: relative; top: -3px;">C</span>';
            }
            #<i class="icon-envelope icon-large2"></i>';
            $ratingavail = '<img src="/wp-content/plugins/wp-postratings/images/stars_crystal/rating_off.gif">';
            if ($rated != "") {
                $ratingavail = '<img src="/wp-content/plugins/wp-postratings/images/stars_crystal/rating_on.gif">';
            }
            print "<tr>";
            print "<td>{$date} </td>";
            print '<td><a href="/hardware-profile/editscan-' . $sid . '">' . $sid . '</a> (<a href="/hardware-profile/system-' . $pub_id . '">pub</a>)</td>';
            $tooltiptext = "Distribution: " . preg_replace("/\r|\n/", "", $resN->distribution) . "\nKernel: " . preg_replace("/\r|\n/", "", $resN->kversion);
            print '<td>
                          <img src="' . $distrilogo . '" alt="' . $tooltiptext . '" title="' . $tooltiptext . '" width=20>
                          ' . $maillogo . " " . $commentavail . " " . $ratingavail . " " . $usertxt . " " . $duplicate_txt . " " . $ucomment_short . "</td>";
            print '<td>
	        	        <input name="hwscan_acomment_' . $sid . '" type="text" size="20" value="' . $acomment . '">
	                       </td>';
            print "<td>{$statusSelector}</td>";
            print "</tr>";
        }
    }
    print "</tr></table>";
    print '<input type="submit" value="update">';
    print "</form>";
}