/var/www/hkosl.com/e-ims/file_manager/company_management.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<script type="text/javascript">
$(document).ready(function(e) {
    $('#addcompany_btn')
        .click(function() {
            $('#addcompany').submit();
    });
    $("#addcompany").validate({
        rules: {
            title: "required",
            type: "required",
            username: "required",
            loginname: "required"
        },
        messages: {
            title: {
                required: "Please Enter Your Company Name"
            },
            type: {
                required: "Please Enter The Type"
            },
            username: {
                required: "Please Enter Your User Name"
            },
            loginname: {
                required: "Please Enter Your Login Name"
            }
        }
    });
    $('#modifycompany_btn')
        .click(function() {
            $('#modifycompany').submit();
    });
    $("#modifycompany").validate({
        rules: {
            title: "required",
            type: "required"
        },
        messages: {
            title: {
                required: "Please Enter Your Company Name"
            },
            type: {
                required: "Please Enter The Type"
            }
        }
    });
    $('#check_all')
        .click(function() {
            if($(this).is(':checked')) {
                $(".checkbox").prop('checked', true);
            }    else    {
                $(".checkbox").prop('checked', false);
            }
    });
});
</script>
<?php
include 'config.php';

// Check if the user is logged in

if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1'))
{
header("Location: login.php");
exit;
}
?>
<?php
$index 
= (int)$_GET["index"];
?>
<script type="text/javascript">
$(document).ready(function(e) {
    $('#cancel_btn')
        .click(function() {
            window.location.href = 'index.php?index=<?=$index;?>';
    });
});
</script>
<?php

if($_REQUEST["modifycompany"] == "1"){
    
$companyid = (int)$_GET["modifycompanyid"];
    
$modify_company_sql "SELECT * FROM file_company Where companyid=:companyid";
    
$modify_company Db::getDbh()->prepare($modify_company_sql);
    
$modify_company->execute(array(":companyid" => $companyid));
    if( 
$error $modify_company->getError(array(":companyid" => $companyid)) ){
        
var_dump($error);
    }
    
$row_modify_company $modify_company->fetch(PDO::FETCH_ASSOC);
    echo
"<form action='modify_company.php' method='post' id='modifycompany' name='modifycompany' enctype='multipart/form-data'>
            <input type='hidden' name='companyid' value='"
.$companyid."' />
            <input type='hidden' name='index' value='"
.$index."' />";
    echo
"    <div class='tab_title'>Modify Company</div>
            <div class='tab_content'>
                <table class='tab_upload_table' width='400' border='0' cellspacing='0' cellpadding='0'>
                  <tr>
                    <td width='100'>Company Name</td>
                    <td width='300'>
                        <input type='text' id='title' name='title' value='"
.$row_modify_company{'title'}."'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Type</td>
                    <td width='300'>
                        <input type='text' id='type' name='type' value='"
.$row_modify_company{'type'}."'>
                    </td>
                  </tr>
                  <tr>
                    <td colspan='2'>
                        <a href='#' id='modifycompany_btn'><div class='tab_content_btn' style='width:50px; background:url(images/save_btn.png) center center no-repeat;'></div></a>
                        <a href='#' id='cancel_btn'><div class='tab_content_btn' style='width:50px; background:url(images/cancel_btn.png) center center no-repeat;'></div></a>
                    </td>
                  </tr>
                </table>
            </div>
        </form>"
;

}    elseif(
$_REQUEST["addcompany"] == "1"){
    echo
"<form action='add_company.php' method='post' id='addcompany' name='addcompany' enctype='multipart/form-data'>
            <input type='hidden' name='index' value='"
.$index."' />";
    echo
"    <div class='tab_title'>Add Company</div>
            <div class='tab_content'>
                <table class='tab_upload_table' width='400' border='0' cellspacing='0' cellpadding='0'>
                  <tr>
                    <td width='100'>Company Name</td>
                    <td width='300'>
                        <input type='text' id='title' name='title'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Type</td>
                    <td width='300'>
                        <input type='text' id='type' name='type'>
                    </td>
                  </tr>
                  <tr>
                    <td colspan='2'><b>Creat Admin User Account:</b></td>
                  </tr>
                  <tr>
                    <td width='100'>Role</td>
                    <td width='300'>"
;
                    echo
"<select name='roleid'>";
                    
$role_list_sql "SELECT * FROM file_role Where status = '1' AND title = 'Admin' ORDER BY sort ASC";
                    
$role_list Db::getDbh()->prepare($role_list_sql);
                    
$role_list->execute();
                    if( 
$error $role_list->getError() ){
                        
var_dump($error);
                    }
                    while (
$row_role_list $role_list->fetch(PDO::FETCH_ASSOC)){
                        echo
"<option value='".$row_role_list{'roleid'}."'>".$row_role_list{'title'}."</option>";
                    }
                    echo
"</select>";
    echo
"            </td>
                  </tr>
                  <tr>
                    <td width='100'>User Name</td>
                    <td width='300'>
                        <input type='text' id='username' name='username'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Login Name</td>
                    <td width='300'>
                        <input type='text' id='loginname' name='loginname'>
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Password</td>
                    <td width='300'>
                        <input type='password' id='loginpw' name='loginpw'>
                        "
.Password::ajax_validate('loginpw''ajax_passwordChecker.php''loginname'true)."
                    </td>
                  </tr>
                  <tr>
                    <td width='100'>Confirm Password</td>
                    <td width='300'>
                        <input type='password' name='loginpw_check'>
                    </td>
                  </tr>
                  <tr>
                    <td colspan='2'>
                        <a href='#' id='addcompany_btn'><div class='tab_content_btn' style='width:50px; background:url(images/save_btn.png) center center no-repeat;'></div></a>
                        <a href='#' id='cancel_btn'><div class='tab_content_btn' style='width:50px; background:url(images/cancel_btn.png) center center no-repeat;'></div></a>
                    </td>
                  </tr>
                </table>
            </div>
        </form>"
;
    
}    else    {
    
$i=0;
    echo
"<form action='delete_company.php' method='post' name='deletecompany' enctype='multipart/form-data'>
            <input type='hidden' name='index' value='"
.$index."' />";
    echo
"<div class='tab_title'>Company Management</div>
         <div class='tab_content'>
            <a href='index.php?index="
.$index."&addcompany=1'><div class='tab_content_btn' style='width:60px; background:url(images/add_btn.png) center center no-repeat;'></div></a>
            <a href='#' onclick='deletecompany.submit()'><div class='tab_content_btn' style='width: 80px; background: url(images/delete_btn.png) center center no-repeat; float: right; margin-right: 0px;'></div></a>
            <div style='clear:both;'></div>
            <table class='tab_content_table' width='100%' border='0' cellspacing='0' cellpadding='0'>
              <tr>
                <td class='title' width='40'>ID</td>
                <td class='title' width='390'>Company Name</td>
                <td class='title' width='200'>Type</td>
                <td class='title' width='130'>Uploader</td>
                <td class='title' width='120'>Date Uploaded</td>
                <td class='title' width='20'></td>
                <td class='title' width='20'></td>
                <td class='title' width='20'><input type='checkbox' class='check_all' id='check_all'></td>
              </tr>"
;
    
$i 0;
    
$company_list_sql "SELECT * FROM file_company Where deleted = '0' order by sort ASC";
    
$company_list Db::getDbh()->prepare($company_list_sql);
    
$company_list->execute();
    if( 
$error $company_list->getError() ){
        
var_dump($error);
    }
    while (
$row_company_list $company_list->fetch(PDO::FETCH_ASSOC)){
        
$company_uploader_sql "select * from sys_login where loginid=:loginid";
        
$company_uploader Db::getDbh()->prepare($company_uploader_sql);
        
$company_uploader->execute(array(":loginid" => $row_company_list{'lastupby'}));
        if( 
$error $company_uploader->getError(array(":loginid" => $row_company_list{'lastupby'})) ){
            
var_dump($error);
        }
        
$row_company_uploader $company_uploader->fetch(PDO::FETCH_ASSOC);
        echo
"  <tr>
                <td>"
.$row_company_list{'companyid'}."</td>
                <td>"
.$row_company_list{'title'}."</td>
                <td>"
.$row_company_list{'type'}."</td>
                <td>"
.$row_company_uploader{'username'}."</td>
                <td>"
.$row_company_list{'lastupdate'}."</td>
                <td align='center'>"
;
        if(
$row_company_list{'status'} == '1'){        
            echo
"<a href='status_company.php?index=".$index."&companyid=".$row_company_list{'companyid'}."'><img src='images/status_tick.png' alt='Enable'></a>";
        }    else    {
            echo
"<a href='status_company.php?index=".$index."&companyid=".$row_company_list{'companyid'}."'><img src='images/status_cross.png' alt='Disable'></a>";
        }
        echo
"    </td>
                <td align='center'><a href='index.php?index="
.$index."&modifycompany=1&modifycompanyid=".$row_company_list{'companyid'}."'><img src='images/modify_icon.png' alt='Modify'></a></td>
                <td><input type='checkbox' class='checkbox' name='companyid["
.$i."]' value='".$row_company_list{'companyid'}."'></td>
              </tr>"
;
        
$i++;
    }
    echo
"    </table>
          </div>"
;
}

function 
getSelect($field1$field2)
{
    if (
$field1 == $field2)
    {
        return 
"selected";
    }
    else
    {
        return 
"";
    }
}
?>