/var/www/enzatesting.onesolution.hk/01_20240711_full_backup/dgn_drawing_index.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php 
$formid 
"Drawing";
require_once 
"inc/configure.php";

search_requestField($_REQUEST['act'], $_REQUEST['status'], $_REQUEST['customer'], $_REQUEST['finished'], $_REQUEST['prodtype'] );    
rowperpage($_REQUEST['act'], $_REQUEST['p'], $_REQUEST['perp']);

search_miscField($_REQUEST['act'], $_REQUEST['projectmanager'], $_REQUEST['sales']);

$customer setDefaultReqVar("customer"'');
$p = (int)evl($_REQUEST["pg"], evl($_REQUEST["p"], 1));
list(
$row_offset_start$row_offset_end) = page_offset($p);

$sql_clause='';

if( !empty(
$_REQUEST['status']) ){
    
$sql_clause .= 'AND status = :status ';
    
$sql_param[':status'] = $_REQUEST['status'];            
}

if( !empty(
$_REQUEST['customer']) ){
    
$sql_clause .= 'AND (custname_en LIKE :custname_en OR custname_sc LIKE :custname_sc OR dgn_drawing.custcode LIKE :custcode OR clientname LIKE :clientname ) ';
    
$sql_param[':custname_en'] = "%$customer%";
    
$sql_param[':custname_sc'] = "%$customer%";
    
$sql_param[':custcode'] = "%$customer%";
    
$sql_param[':clientname'] = "%$customer%";            
}

if( !empty(
$_REQUEST['prodtype']) ){
    
$sql_clause .= 'AND (pdt_type=:pdt_type) ';
    
$sql_param[':pdt_type'] = $_REQUEST['prodtype'];            
}

if( !empty(
$_REQUEST['finished']) ){
    
$sql_clause .= 'AND finished = :finished ';
    
$sql_param[':finished'] = '1';    
}    else {
    
$sql_clause .= 'AND ( finished <> :finished OR finished IS NULL )';
    
$sql_param[':finished'] = '1';            
}

if( !empty(
$_REQUEST['projectmanager']) ){
    
$sql_clause .= 'AND projectmanager=:projectmanager ';
    
$sql_param[':projectmanager'] = $_REQUEST['projectmanager'];
}

if( !empty(
$_REQUEST['sales']) ){
    
$sql_clause .= 'AND sales=:sales ';
    
$sql_param[':sales'] = $_REQUEST['sales'];
}    
 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$system_var['COMPANY_NAME']?></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php require_once "inc/jsheader.php"?>
<script>
$(document).ready(function(e) {
    $( ".photobtn" ).button({
      icons: {
        primary: "ui-icon-image"
      },
      text: false
    });
});
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" class="top"><?php require"mod_webhead.php"?></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="200" valign="top" class="menu_bg"><?php require"mod_menu.php"?></td>
        <td valign="top" class="padding1"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr></tr>
          <tr>
            <td class="c1_bg">
            <form action="dgn_drawing_index.php" method="post">
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search">
              <tr>
                <td width="120" valign="top" ><?=SEARCH_CRITERIA?>:<br />
                  <span class="stext1"><?=DRAWING?>:</span></td>
                <td valign="top" rowspan="2">                
                
                <table>
                <tr>
                <td class="stext2"><?=CUSTOMER?></td>
                <td class="stext2"><input type="text" name="customer" value="<?=$_REQUEST['customer']?>" /></td>
                <td></td>
                <td class="stext2"><?=PROJECT_MANAGER?></td>
                <td class="stext2"><select name="projectmanager"><option value=""></option><?=master_user_option($_REQUEST['projectmanager'], false"WHERE department='Sales'")?></select></td>
                </tr>
                
                <tr>
                <td class="stext2"><?=PRODTYPE?></td>
                <td class="stext2"><select name="prodtype"><option value=""></option><?=dgntype_option($_REQUEST['prodtype'], true)?></select></td>
                <td></td>
                <td class="stext2"><?=SALESMAN?></td>
                <td class="stext2"><select name="sales"><option value=""></option><?=master_user_option($_REQUEST['sales'], false"WHERE department='Sales'")?></select></td>
                </tr>
            
                <tr>
                <td class="stext2"><?=STATUS?></td>
                <td class="stext2"><select name="status"><option value=""></option><?=master_option("DRAWING_STATUS"$_REQUEST['status'], true)?></select></td>
                <td></td>
                <td class="stext2"><?=FINISHED?></td>
                <td class="stext2"><input type="checkbox" name="finished" <?=empty($_REQUEST['finished'])?'':'checked="checked"'?>  /></td>
                </tr>
                </table>
</td>
                <td align="right" valign="top"><input type="image" src="image/btn_search.jpg" width="64" height="20" />&nbsp; <a href="dgn_drawing_addform.php" ><!--<img src="image/btn_new.jpg" width="52" height="20" />--></a>&nbsp;<a href="<?=basename($_SERVER['PHP_SELF'])?>"><img src="image/icon_close.jpg" width="20" height="20" align="top" alt="<?=CLEAR?>" /></a></td>
              </tr>
<tr>
                <td class="tdvalignbottom"><span class="mod_menu"><a href="dgn_drawing_validform.php" class="photobtn"><?=DESIGN_VALID?></a></span>&nbsp;&nbsp;</td>
              <?php    //get number of row 
              //todo: adding an SUBSTRING_INDEX(drawing_no, '-', 2) indexed column for better performance
    
$sql "SELECT count(*) as cnt
            from dgn_drawing
            LEFT JOIN
            
            (SELECT
                        max(dgn_drawing.refid) as mrefid
                    FROM
                        dgn_drawing
                    GROUP BY
                        "
.SUBSTRING_INDEX."(drawing_no, '-', 2)
            ) as hdr
            
            on dgn_drawing.refid= hdr.mrefid
            LEFT JOIN master_customer ON dgn_drawing.custcode = master_customer.custcode
            where hdr.mrefid is not NULL 
$sql_clause";    

    
$sth $dbh->prepare($sql);
    
$sth->execute$sql_param );
//echo $sth->getSQL( $sql_param ) . HTML_EOL;
                            
    
$row $sth->fetch();
    
$ttlrow $row['cnt'];
    
//vdump($row);                
?>    
                <td class="tdalignright tdvalignbottom"><?=pagination($ttlrow$p)?></td>
              </tr>              
<!--              <tr>
                <td height="25" colspan="3" valign="bottom" class="stext2">        </td>
                </tr>-->
            </table>
</form></td>
          </tr>
          <tr>
            <td valign="top" class="c2_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablelist">
                  <tr>
                          <th><?=DRAWING?></th>
                        <th><?=LAUNCH_DATE?></th>
                        <th><?=PRODUCT_TYPE?></th>                        
                        <th><?=CUSTOMER?></th>
                        <!--<th><?=TARGET?><?=WS?><?=WEIGHT?></th>-->
                        <th><?=TARGET?><?=WS?><?=DATE?></th>
                        <th><?=STATUS?></th>
                        <th><?=LAST_MODIFY?></th>
                        <!--<th>Delete</th>-->
                    </tr>
<?php

    $sql 
"SELECT * FROM(
                SELECT dgn_drawing.*, master_customer.custname_en,
                master_customer.custname_sc,
                ROW_NUMBER() OVER (ORDER BY launch_date) as RowNum
                from dgn_drawing
                LEFT JOIN
                
                (SELECT
                            max(dgn_drawing.refid) as mrefid
                        FROM
                            dgn_drawing
                        GROUP BY
                            "
.SUBSTRING_INDEX."(drawing_no, '-', 2)
                ) as hdr
                
                on dgn_drawing.refid= hdr.mrefid
                LEFT JOIN master_customer ON dgn_drawing.custcode = master_customer.custcode
                where hdr.mrefid is not NULL 
$sql_clause
            ) AS ROWCST 
            WHERE RowNum >= 
$row_offset_start AND RowNum <= $row_offset_end
            ORDER BY RowNum"
;    


    
$sth $dbh->prepare($sql);
    
$sth->execute$sql_param );
//echo $sth->getSQL( $sql_param ) . HTML_EOL;
                            
    
while($row $sth->fetch()) {
        if(empty(
$refid)) $refid $row['refid'];    //default select the first item
        
?>
        
                  <tr>
                    <td class="code"><a href="dgn_drawing_modifyform.php?edit=1&refid=<?=$row['refid']?>" rel="ajax_thumb_dgn_drawing.php?refid=<?=$row['refid']?>&formid=<?=$formid?>" class="uibutton0 cluetip" title="<?=$row['drawing_no']?> <?=$row['pdt_type']?><br/><?=datef($row['launch_date'])?>"><?=$row['drawing_no']?></a></td>
                    <td><?=datef($row['launch_date'])?></td>
                    <td><?=$row['pdt_type']?></td>                    
                    <td><?php if($row['isnewcust']) { ?>
                        <?=$row['clientname']?>
                    <?php } else { ?>
                        <?=$row['custname_'.SYS_LANG]?>
                    <?php ?></td>
                    <!--<td><?=numf($row['target_wt'])?>&nbsp;<?=$row['uom_wt']?></td>-->
                    <td><?=datef($row['target_date'])?></td>
                    <td><?=resolveCode_master_type_code("DRAWING_STATUS"$row['status'])?></td>
                    <td><?=datef($row['createdate'])?></td>
                  </tr>
<?php ?>
                </table></td>
<!--                <td width="150" valign="top" class="product_image"><img src="image/image2.jpg" width="150" height="150" /></td>-->
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>