$new_elements_query .= " LEFT JOIN elements_description ed ON ed.elements_id=e.elements_id AND languages_id=2";
$new_elements_query .= " WHERE is_new='1' ORDER BY e.is_new_start_date ASC";
$new_elements_result = tep_db_query($new_elements_query);
$new_elements[0]['sel'] = ' ';
$new_elements[0]['id'] = 'ID';
$new_elements[0]['model'] = 'Element Code';
$new_elements[0]['since'] = 'Since';
$new_elements[0]['dur'] = 'Duration';
$new_elements[0]['name'] = 'Element Name';
$total_ne = tep_db_num_rows($new_elements_result);
if ($total_ne > 0) {
    while ($row = tep_db_fetch_array($new_elements_result)) {
        $e_code = $row['elements_code'] == '' ? ' ' : $row['elements_code'];
        $e_name = $row['name'] == '' ? ' ' : $row['name'];
        $e_since = date('d M Y', strtotime($row['is_new_start_date']));
        $e_duration = countDuration($row['is_new_start_date']);
        $p_sel['sel'] = '<input id="cb_el' . $row['elements_id'] . '" type="checkbox" name="cb_el[]" value="' . $row['elements_code'] . '">';
        $p_sel['id'] = '<label for="cb_el' . $row['elements_id'] . '">' . $row['elements_id'] . '</label>';
        $p_sel['model'] = '<label for="cb_el' . $row['elements_id'] . '">' . $e_code . '</label>';
        $p_sel['since'] = '<label for="cb_el' . $row['elements_id'] . '">' . $e_since . '</label>';
        $p_sel['dur'] = '<label for="cb_el' . $row['elements_id'] . '">' . $e_duration . '</label>';
        $p_sel['name'] = '<label for="cb_el' . $row['elements_id'] . '">' . $e_name . '</label>';
        $new_elements[] = $p_sel;
    }
} else {
    $new_elements[1]['sel'] = '&nbsp;';
    $new_elements[1]['id'] = '&nbsp;';
    $new_elements[1]['model'] = '&nbsp;';
    $new_elements[1]['since'] = '&nbsp;';
    $new_elements[1]['dur'] = '&nbsp;';
    $new_elements[1]['name'] = '&nbsp;';
$content .= '<table border="0" cellpadding="0" cellspacing="0">';
foreach ($waxings as $row) {
    $confitype = $class_ow->elements_type[$row['elements_id']];
    $thumb = webImage("webconfi-{$confitype}-{$row['elements_id']}-1-small.jpg", '', '', 'Element ID: ' . $row['elements_id'], 'img-border img-padding');
    $thumb2 = '';
    if ($row['image_id'] != '') {
        $q = tep_db_query("SELECT * FROM elements_custom_image_uploaded WHERE id IN ({$row['image_id']})");
        while ($r = tep_db_fetch_array($q)) {
            $imgsrc = $r['shape_image'] == '' ? $r['uploaded_image'] : $r['shape_image'];
            $thumbnew = webImage($imgsrc, '100', '100', $confitype, 'img-border img-padding');
            if (strpos($thumbnew, 'color-pattern-8.png') === false) {
                $thumb2 .= $thumbnew;
            }
        }
    }
    $age = countDuration($row['status_date']);
    $content .= '<tr>';
    if ($thumb2 == '') {
        $content .= '<td class="c1">' . $thumb . '</td>';
        $content .= '<td class="c2" colspan="2">';
    } else {
        $content .= '<td class="c1">' . $thumb . '</td>';
        $content .= '<td class="c1b">' . $thumb2 . '</td>';
        $content .= '<td class="c2b">';
    }
    $content .= '<div>Order ID: ' . $row['orders_no'] . '</div>';
    $content .= '<div>Order Date: ' . date('d M Y', strtotime($row['date_purchased'])) . '</div>';
    $content .= '<div>Customer: ' . $row['customers_name'] . '</div>';
    $content .= '</td>';
    $content .= '<td class="c3">';
    if ($row['text'] != '') {
 function retrieveListOverview($status)
 {
     global $ENGRAVED_PRODUCTS;
     $waxings = $this->retrieveList("ow.status={$status}");
     if (count($waxings) > 0) {
         $orders = array();
         $o = array();
         $o['d'] = 'Date';
         $o['d2'] = 'Status Date';
         $o['g'] = 'Age';
         $o['r'] = 'Source';
         $o['c'] = 'Customer Name';
         $o['o'] = 'Order No';
         $o['a'] = 'Product Code';
         $o['e'] = 'Customized';
         $o['t'] = 'Action';
         $orders[] = $o;
         foreach ($waxings as $row) {
             $order_date = strtotime($row['date_purchased']);
             $o = array();
             $o['d'] = date('d-M-y', $order_date);
             $o['d2'] = date('d-M-Y', strtotime($row['status_date']));
             $o['g'] = countDuration($row['status_date'], 'now', 1);
             $o['r'] = $row['dti_referrers_code'] == '' ? '<span class="notice">julie-grace.de</span>' : $row['dti_referrers_code'];
             $o['c'] = '<a href="?open=customer&amp;id=' . $row['customers_id'] . '" title="View Customer Detail" >' . $row['customers_name'] . '</a> <sup>' . $row['customers_order_count'] . '</sup>';
             $o['o'] = '<a href="?open=order&amp;id=' . $row['orders_id'] . '" title="View Order Detail">' . $row['orders_no'] . '</a>';
             //$thumb = webImage($row['elements_image'], '80', '80');
             if ($row['elements_id'] != '0') {
                 $confitype = $this->elements_type[$row['elements_id']];
                 $thumb = '<div class="thumb" style="display:none;">' . webImage("webconfi-{$confitype}-{$row['elements_id']}-1-small.jpg", '', '', $row['elements_id'], 'img-border img-padding') . '</div>';
             } else {
                 $thumb = '<div class="thumb" style="display:none;">' . webImage($row['products_image'], '80', '80', '', 'img-border img-padding') . '</div>';
             }
             $product = $thumb . $row['products_model'];
             $o['a'] = $product;
             $personalize = nl2br($row['text']);
             if ($row['image_id'] != '') {
                 if ($row['elements_id'] != '0') {
                     $imgids = explode(',', $row['image_id']);
                     foreach ($imgids as $imgid) {
                         if ($personalize != '') {
                             $personalize .= '<br />';
                         }
                         $personalize .= '<a href="?open=pe-uploaded-image&amp;id=' . $imgid . '&amp;hidemenu=true" class="view_webpage" target="_blank" title="View uploaded image and comment">Image</a>';
                     }
                 } else {
                     $custom_image = '<a class="view_webpage" href="?open=customers-images&amp;id=' . $row['customers_image_id'] . '&amp;hidemenu=true" title="View uploaded image and comment">';
                     $custom_image .= '<span class="thumb" style="display:none;">';
                     $custom_image .= webImage($row['customers_image'], '80', '80', '', 'img-border img-padding');
                     $custom_image .= '<br /></span>';
                     $custom_image .= '<span>Image</span></a>';
                     if ($personalize != '') {
                         $personalize .= '<br />';
                     }
                     $personalize .= $custom_image;
                 }
             }
             $o['e'] = $personalize;
             $action = '';
             if ($row['status'] == '1') {
                 $action .= $cancelbtn;
                 if (in_array($row['products_id'], $ENGRAVED_PRODUCTS)) {
                     $action .= '<input type="button" class="actbtn" name="7" value="Engraving" title="Set to Engraving" />';
                 } else {
                     $action .= '<input type="button" class="actbtn" name="2" value="Waxing" title="Set to Waxing" />';
                 }
             } elseif ($row['status'] == '2') {
                 $action .= '<input type="button" class="actbtn" name="3" value="Casting" title="Set to Casting" />';
                 $action .= '<input type="button" class="actbtn" name="1" value="&laquo;" title="Set back to New" />';
             } elseif ($row['status'] == '3') {
                 $action .= '<input type="button" class="actbtn" name="4" value="Assembly" title="Set to Assembly" />';
                 $action .= '<input type="button" class="actbtn" name="2" value="&laquo;" title="Set back to Casting" />';
             } elseif ($row['status'] == '4') {
                 $action .= '<input type="button" class="actbtn" name="5" value="Finish" title="Set to Finish" />';
                 $action .= '<input type="button" class="actbtn" name="3" value="&laquo;" title="Set back to Assembly" />';
             } elseif ($row['status'] == '7') {
                 $action .= '<input type="button" class="actbtn" name="4" value="Assembly" title="Set to Assembly" />';
                 $action .= '<input type="button" class="actbtn" name="1" value="&laquo;" title="Set back to New" />';
             }
             $action .= '<input type="button" class="actbtn" name="6" value="C" title="Set as cancelled" />';
             //Default Row Action Value (id, status)
             $action .= '<input type="hidden" id="owid-' . $row['orders_waxing_id'] . '" name="ow_id" value="' . $row['orders_waxing_id'] . '" >';
             $action .= '<input type="hidden" name="ow_status" value="' . $row['status'] . '" >';
             $o['t'] = $action;
             $orders[] = $o;
         }
         $buttons = '';
         $result = '<div id="waxing-' . $status . '">';
         $result .= tep_draw_table('spo', $orders);
         $result .= '</div>';
     } else {
         $result = '<h3>No Orders in this status</h3>';
     }
     return $result;
 }
$lastrun_query = "SELECT esl.* FROM elements_stock_lastrun esl WHERE esl.jng_warehouses_id={$whid} ORDER BY esl.lastrun DESC LIMIT 10";
$lastrun_result = tep_db_query($lastrun_query);
if (tep_db_num_rows($lastrun_result) > 0) {
    $lastrun_exist = true;
    $lastrun_opt = '<form name="frm_lastrun" action="?open=elements-stock" method="post">';
    $lastrun_opt .= '<select name="lastrunid" onchange="frm_lastrun.submit();">';
    while ($row = tep_db_fetch_array($lastrun_result)) {
        $selected = '';
        $lr_id = $row['elements_stock_lastrun_id'];
        $lr_date = date("l, j F Y H:i:s", strtotime($row['lastrun']));
        if (!isset($lastrunid)) {
            $lastrunid = $lr_id;
        }
        if ($lr_id == $lastrunid) {
            $lastrundate = $lr_date;
            $lastruninterval = countDuration($row['lastrun']);
            $selected = 'selected="selected"';
        }
        $lastrun_opt .= '<option value="' . $lr_id . '" ' . $selected . '">' . $lr_date . '</option>';
    }
    $lastrun_opt .= '</select>';
    $lastrun_opt .= '</form>';
} else {
    $lastrun_exist = false;
    $lastrun_opt = '';
}
if ($lastrun_exist) {
    $lastrun = 'This report is queried <strong>' . $lastruninterval . '</strong> ago.';
    $filter_query = " WHERE esr.jng_warehouses_id={$whid} AND esr.elements_stock_lastrun_id={$lastrunid} AND esr.elements_id!=700";
    if ($filter_query_add != '') {
        $filter_query .= " AND {$filter_query_add}";