exit;
    }
}
if (isset($_GET['status']) && array_key_exists($_GET['status'], $tabs)) {
    $status = $_GET['status'];
    $tabcontent = '<div style="clear:left;height:5px;">&nbsp;</div>';
    $q = "SELECT * FROM promoboxes WHERE category='{$status}'";
    $r = tep_db_query($q);
    $datas = array();
    while ($row = tep_db_fetch_array($r)) {
        $datas[] = $row['id_promoboxes'];
    }
    if (count($datas) == 0) {
        $tabcontent .= $textNoDatas;
    } else {
        $descoldata = getDesCol($status);
        $tabcontent .= '<div class="datas-list-id" style="display:none;">' . implode(",", $datas) . '</div>';
        $tabcontent .= '<div class="draw-table">' . $descoldata['table'] . '</div>';
    }
    $tabcontent .= '<div class="datas-status" style="display:none;">' . $status . '</div>';
    $tabcontent .= '<div id="datas-counter" style="display:none;">' . datasCountByStatus() . '</div>';
    $tabcontent .= '<div id="check-date-form" style="display:none;">';
    $tabcontent .= '<span class="red">Manobo will auto move Improvement to Checkings Tab<br />on <strong>Check Date</strong> and notify Owner to confirm Test result.</span>';
    $tabcontent .= '<input type="hidden" id="check-date-id" value="" />';
    $tabcontent .= '<input type="hidden" id="check-date-old-status" value="" />';
    $tabcontent .= '<br /><br />Please set a check date <input type="text" id="check-date-value" />';
    $tabcontent .= '</div>';
    //#check-date-form
    echo utf8_encode($tabcontent);
    exit;
}
function drawDraftRow($draft_count, $drafts_id, $rowclass, $status, $sub_status = '', $designs_id = '')
{
    $descoldata = getDesCol($status);
    $descol = $descoldata['cols'];
    $descol_count = $descoldata['count'];
    $draft = new design_draft($drafts_id);
    $products = $draft->retrieveProducts();
    $detail_link = '<a href="?open=designs-draft-detail&amp;id=' . $draft->id . '&amp;hidemenu=true" class="view_webpage">';
    $row .= '<tr id="dra-' . $draft->id . '" class="dra ' . $rowclass . ' desdra-' . $draft->designs_id . '">';
    $new_elements = $draft->retrieveElements();
    $wax_stats = array();
    $wax_stats[] = 'New Wax';
    $wax_stats[] = 'Revision';
    $qwax = "SELECT mu.id, mu.username";
    $qwax .= " FROM minierp_users mu";
    $qwax .= " LEFT JOIN minierp_groups_members mgm ON mgm.minierp_users_id = mu.id";
    $qwax .= " WHERE mgm.minierp_groups_id = '46'";
    $rwax = tep_db_query($qwax);
    $waxers = array();
    while ($r = tep_db_fetch_array($rwax)) {
        $waxers[$r['id']] = $r['username'];
    }
    unset($waxers['137']);
    foreach ($descol as $class => $key) {
        $value = '&nbsp;';
        switch ($key) {
            //                            case 'Lead Time':
            //                                $value = 'DRAFT '.($x+1);
            //                                break;
            case 'ID':
                $value = $draft->id;
                if ($draft->colors_request != '') {
                    $value .= '<br/><img src="images/colors_circle_16x16.png" title="This Draft have Colors Requested" />';
                }
                break;
            case 'Image':
                $weblink = webImageSource($draft->image_1, IMAGE_SIZE_BIG_1, IMAGE_SIZE_BIG_1);
                $value = '<a href="' . $weblink . '" class="view_image">' . webImage($draft->image_1, IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, $draft->name, 'img-border') . '</a>';
                break;
            case 'Name':
                $value = '<strong>Draft ' . ($draft_count + 1) . '</strong><br />' . ($draft->name == '' ? '<span class="notice">No Name Specified</span>' : '<span>' . $draft->name . '</span>');
                break;
            case 'Products':
                if (count($products) > 0) {
                    $value = '';
                    if ($status <= 5 || $status == 13) {
                        foreach ($products as $p) {
                            $value .= productLinkWithID($p['products_id'], $p['products_name'], '&amp;designs_id=' . $designs_id);
                        }
                    } else {
                        foreach ($products as $p) {
                            $pname = htmlspecialchars($p['products_name']);
                            $link = '<a href="?open=product-detail&amp;products_id=' . $p['products_id'] . '" target="_blank" title="' . $pname . '">';
                            if ($status <= 5) {
                                $link_text = $p['products_id'];
                            } else {
                                $tooltip = $pname;
                                $img_class = '';
                                if ($status == 8) {
                                    $link = '<a href="?open=designs-finalize&amp;id=' . $p['products_id'] . '&amp;hidemenu=true" class="view_webpage">';
                                    if ($p['finalized_time'] != '' && $p['finalized_by'] != '') {
                                        $fint = time() - $p['finalized_time'];
                                        $duration = $fint > 0 ? displayDuration($fint, 1) . ' ago' : 'just now';
                                        $tooltip = 'Finalized by ' . $p['finalized_by'] . ' (' . trim($duration) . ')';
                                        $img_class = 'img-status-ok';
                                    } else {
                                        $img_class = 'img-status-bad';
                                    }
                                } elseif ($status == 7) {
                                    $link = '<a href="?open=designs-details&amp;id=' . $p['products_id'] . '&amp;hidemenu=true" class="view_webpage">';
                                    if ($p['detailed_time'] != '' && $p['detailed_by'] != '') {
                                        $fint = time() - $p['detailed_time'];
                                        $duration = $fint > 0 ? displayDuration($fint, 1) . ' ago' : 'just now';
                                        $tooltip = 'Details Completed by ' . $p['detailed_by'] . ' (' . trim($duration) . ')';
                                        $img_class = 'img-status-ok';
                                    } else {
                                        $img_class = 'img-status-bad';
                                    }
                                } elseif ($status == 6) {
                                    $link = '<a href="?open=designs-graphics&amp;id=' . $p['products_id'] . '&amp;hidemenu=true" class="view_webpage">';
                                }
                                $link_text = webimage($p['products_image'], IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, $tooltip, $img_class, 'style="margin-bottom:1px;"');
                            }
                            $del = '<div id="delpid-' . $p['products_id'] . '" class="ui-state-default ui-corner-all del-prod" style="width:16px;float:right;" title="Delete Product"><span class="ui-icon ui-icon-close" style="cursor: pointer;"></span></div>';
                            $value .= '<div>' . $del . $link . $link_text . '</a></div>';
                        }
                    }
                }
                break;
            case 'Elements':
                $value = '';
                if (count($new_elements) > 0) {
                    foreach ($new_elements as $ne) {
                        $el_style = '';
                        $el_image = '';
                        $el_class = '';
                        if ($ne['elements_image'] != '') {
                            $el_style = 'margin-bottom:1px;';
                            if ($sub_status == 7) {
                                $el_class = $ne['is_finalized'] == '1' ? 'img-status-ok' : 'img-status-bad';
                            }
                            $el_image = webImage($ne['elements_image'], IMAGE_SIZE_THUMBNAIL_1, IMAGE_SIZE_THUMBNAIL_1, '', $el_class);
                        }
                        use_class('element');
                        $e = new element($ne['elements_id']);
                        if ($sub_status == 2) {
                            //SHOW WAX COMPLEXITY ON TAB WAX
                            $wax_complexity = $e->wax_complexity != '' ? " ({$e->wax_complexity})" : '';
                            $wax_complexity_name = $e->wax_complexity != '' ? ' (' . getComplexity($e->wax_complexity) . ' wax complexity)' : '';
                        }
                        $value .= elementLinkWithID($ne['elements_id'], $ne['elements_id'] . " : " . $ne['elements_description'] . $wax_complexity_name, $drafts_id, $el_style, $el_image, "{$wax_complexity}");
                        unset($e);
                        //SET NEW ELEMENTS FINALIZED
                        if ((is_null($ne['finalized_date']) || $ne['finalized_date'] == '') && $ne['is_finalized'] == '1') {
                            $sda = array();
                            $sda['finalized_date'] = date("Y-m-d H:i:s");
                            $sda['finalized_by'] = $session_userinfo['username'];
                            tep_db_perform('designs_elements', $sda, 'update', "designs_id='" . $design->id . "' AND elements_id=" . $ne['elements_id']);
                        }
                    }
                }
                break;
            case 'Action':
                $value = '';
                $value .= '<input type="hidden" name="drafts_id" value="' . $draft->id . '" />';
                $value .= '<input type="hidden" name="status" value="' . $status . '" />';
                $value .= '<input type="hidden" name="sub_status" value="' . $sub_status . '" />';
                $actions = array();
                if ($status == 5) {
                    if ($sub_status == 3) {
                        $ap_class = count($products) > 0 ? ' class="red"' : ' class="green"';
                        $actions[] = '<input type="button" name="AP"' . $ap_class . ' value="&oplus; ADD PRODUCT" title="Add Products to this Draft" />';
                    }
                }
                //                if($status==6 && $draft->products_image_by=='') {
                //                    $actions[] = '<input type="button" name="GD" class="green" value="&reg; SET AS MINE" title="Set Draft as yours (GD Team only)" />';
                //                }
                if ($status == 14 && $draft->products_image_by == '') {
                    if ($sub_status == 1) {
                        $actions[] = '<input type="button" name="GD" class="green" value="&reg; SET AS MINE" title="Set Draft as yours (GD Team only)" />';
                    }
                }
                if ($status == 10 && ($sub_status == '' || $sub_status == 0 || $sub_status == 1)) {
                    $cel_class = count($new_elements) > 0 ? ' class="red"' : ' class="green"';
                    $actions[] = '<input type="button" name="CE"' . $cel_class . ' value="&oplus; CREATE ELEMENT" title="Create New Element for this Draft" />';
                }
                if ($status == 10 && $sub_status == 2) {
                    if ($draft->wax_history_info == '') {
                        $pic_wax = '<div class="pic_wax" style="margin-bottom:5px;float:left;"><strong style="margin-right:5px;">Wax PIC</strong><select id="pic_wax"><option value="0">Show All</option>' . loadComboListFromArray($waxers, null, null, false) . '</select></div>';
                        $pic_wax .= '<div class="wax_status" style="margin-bottom:5px;float:left;"><strong style="margin-right:5px;">Wax Status</strong><select id="wax_status"><option value="0">Show All</option>' . loadComboListFromArray($wax_stats, null, null, false) . '</select></div>';
                        $pic_wax .= '<input class="wax_submit" type="button" name="SW" value="Save WAX" title="Save WAX"/>';
                        $pic_wax .= '<input class="wax_done green" type="button" style="display:none;" name="WD" value="&#10003; WAX DONE" title="Set Wax as done" />';
                    } else {
                        if (substr($draft->wax_history_info, -1) == '|') {
                            $pic_wax = '<div class="pic_wax" style="margin-bottom:5px;float:left;"><strong style="margin-right:5px;">Wax PIC</strong><select id="pic_wax"><option value="0">Show All</option>' . loadComboListFromArray($waxers, null, null, false) . '</select></div>';
                            $pic_wax .= '<div class="wax_status" style="margin-bottom:5px;float:left;"><strong style="margin-right:5px;">Wax Status</strong><select id="wax_status"><option value="0">Show All</option>' . loadComboListFromArray($wax_stats, null, null, false) . '</select></div>';
                            $pic_wax .= '<input class="wax_submit" type="button" name="SW" value="Save WAX" title="Save WAX"/>';
                            $pic_wax .= '<input class="wax_done green" type="button" style="display:none;" name="WD" value="&#10003; WAX DONE" title="Set Wax as done" />';
                        } else {
                            $pic_wax = '<input class="wax_done green" type="button" name="WD" value="&#10003; WAX DONE" title="Set Wax as done" />';
                            $pic_wax .= '<div class="pic_wax" style="margin-bottom:5px;float:left;display:none;"><strong style="margin-right:5px;">Wax PIC</strong><select id="pic_wax"><option value="0">Show All</option>' . loadComboListFromArray($waxers, null, null, false) . '</select></div>';
                            $pic_wax .= '<div class="wax_status" style="margin-bottom:5px;float:left;display:none;"><strong style="margin-right:5px;">Wax Status</strong><select id="wax_status"><option value="0">Show All</option>' . loadComboListFromArray($wax_stats, null, null, false) . '</select></div>';
                            $pic_wax .= '<input class="wax_submit" type="button" style="display:none;" name="SW" value="Save WAX" title="Save WAX"/>';
                        }
                    }
                    $actions[] = $pic_wax;
                }
                if ($status == 12 || $status == 7 || $status == 8) {
                    $acttemp = '';
                    foreach ($products as $p) {
                        $acttemp .= '<div style="height:81px;"><div style="padding-top:40px"><input id="sof-' . $p['products_id'] . '" type="checkbox" name="sample_order"' . ($p['create_sample'] == '1' ? ' checked="checked"' : '') . ' style="width:auto;" title="Check this to auto generate sample order automatically when the product is finalized" /> <label for="sof-' . $p['products_id'] . '">Create <abbr title="Sample Order">SO</abbr></label></div></div>';
                    }
                    $actions[] = $acttemp;
                }
                $clear = '<input type="button" name="DC" value="&times; CLEAR" title="Clear Approval Status" />';
                $kill = '<input type="button" name="DR" class="red" value="&times; Kill" title="Kill Draft" />';
                if ($draft->approve_status == '0') {
                    if ($status == '4') {
                        $actions[] = '<input type="button" name="DA" class="green" value="&hearts; Approve" title="Approve Draft for New Elements" />';
                    }
                    if ($status == '4' || $status == '5' || $status == '10') {
                        $actions[] = $kill;
                    }
                } elseif ($draft->approve_status == 'A') {
                    if ($status < 5) {
                        $actions[] = '<input type="button" class="green" value="&hearts; Approved" disabled="disabled" />';
                    } elseif ($status == '5' || $status == '10') {
                        $actions[] = $kill;
                    }
                    if ($status >= 5) {
                        $clear = '';
                    }
                } elseif ($draft->approve_status == 'R' && $status < 5) {
                    $actions[] = '<input type="button" class="red" value="&hearts; Killed" disabled="disabled" />';
                }
                if ($draft->approve_status != '0') {
                    $actions[] = $clear;
                }
                $value .= implode('<br />', $actions);
                break;
        }
        if ($key == 'ID' || $key == 'Name') {
            $value = $detail_link . $value . '</a>';
        }
        if ($key == 'Name') {
            $showComment = false;
            $showGD = false;
            $showWaxHistory = false;
            if ($status == 10 && $sub_status == 2 && $draft->wax_history_info != '') {
                $showWaxHistory = true;
            }
            if ($draft->comments != '' && $draft->comments_lub != '' && $draft->comments_lut != '') {
                $showComment = true;
            }
            if ($showWaxHistory) {
                $wax_pic = explode('||', $draft->wax_history_info);
                $history_array = array();
                $p = array();
                $history_wax = false;
                $p['pic w100'] = 'PIC';
                $p['start w100'] = 'Start Date';
                $p['end w100'] = 'End Date';
                $p['wax_status w100'] = 'Status';
                $p['lead w100'] = 'Lead Time';
                $table_pic[] = $p;
                foreach ($wax_pic as $text) {
                    list($pics, $wax_status, $start_date, $end_date) = explode('|', $text);
                    if ($end_date == '') {
                        $wax_start = time() - strtotime($start_date);
                        $current_duration = $wax_start > 0 ? displayDuration($wax_start, 1) . ' ago' : 'just now';
                        $value .= '<br /><br /<span style="font-weight:bold;">PIC Wax: ' . $pics . ' (' . $current_duration . ') - ' . $wax_status . '</span>';
                    }
                    if ($end_date != '') {
                        $wax_end = strtotime($end_date) - strtotime($start_date);
                        $p['pic w100'] = $pics;
                        $p['start w100'] = date('d-M-y', strtotime($start_date));
                        $p['end w100'] = date('d-M-y', strtotime($end_date));
                        $p['wax_status w100'] = $wax_status;
                        $p['lead w100'] = displayDuration($wax_end, 1);
                        $table_pic[] = $p;
                        $history_wax = true;
                    }
                }
                if ($history_wax) {
                    $title_pic_wax = tep_draw_table('main_center', $table_pic);
                    $value .= '<br /><div style="float:left;">Wax History</div><span class="ui-icon ui-icon-info"></span><span style="display:none;">' . $title_pic_wax . '</span>';
                }
            }
            if ($status >= 6 && $draft->products_image_by != '' && $draft->products_image_start != '') {
                $showGD = true;
                if ($showComment) {
                    if ($draft->comments_lut < $draft->products_image_start) {
                        $showComment = false;
                    }
                }
            }
            if ($showGD) {
                $gdstart = time() - $draft->products_image_start;
                $duration = $gdstart > 0 ? displayDuration($gdstart, 1) . ' ago' : 'just now';
                $value .= '<br /><br /><span class="red">GD: <strong>' . $draft->products_image_by . '</strong>';
                $value .= ' (' . trim($duration) . ')</span>';
            }
            if ($showComment) {
                $lastcomment = time() - strtotime($draft->comments_lut);
                $duration = $lastcomment > 0 ? displayDuration($lastcomment, 1) . ' ago' : 'just now';
                //if($lastcomment<1*24*60*60) {
                $value .= '<br /><br /><span class="red">Last Comment by <strong>' . $draft->comments_lub . '</strong>';
                $value .= '<br />posted ' . $duration . '</span>';
            }
            $value = '<div>' . $value . '</div>' . drawObjectSocialLine($draft, 'dra');
        }
        $row .= '<td class="' . $class . '">' . $value . '</td>';
    }
    $row .= '</tr>';
    return $row;
}