/var/www/hkosl.com/imusiccircle/webadmin/music_channel_process.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
<?php
    $page_settings 
= array(
        
'formid'     => 'Approval'// for permission
        
'section'    => 'Master'// parent/page title
        
'subsection' => 'Music Channel'// page title
        
'domain'     => 'music_channel'// table/model name
        
'access'     => 'GNr'// for permission
    
);
    require_once 
"check_login.php";

    if (
$_REQUEST["action"] == "ADD" || $_REQUEST["action"] == "MODIFY" ) {
        require_once(
"mime_type_lib.php");

        
$message "";

        foreach (
$arraylangcode as $langcode => $langname) {
            if (empty(
$_POST["title_" $langcode])) {
                
$message .= _lang("Please enter Title") . " [" $langname "]\\n\\n";
            }
        }

        if (empty(
$_POST["date_time"])) {
            
$message .= _lang("Please enter Date") . "\\n\\n";
        }

        foreach (
$arraylangcode as $langcode => $langname) {
            if (empty(
$_POST["location_" $langcode])) {
                
$message .= _lang("Please enter Location") . " [" $langname "]\\n\\n";
            }
        }

        
$img = array("en" => """cn" => "");
        foreach (
$arraylangcode as $langcode => $langname) {
            if (
$_FILES["img_" $langcode]['name'] <> '') {

                
//check if image type is valid or not
                
$mime get_file_mime_type($_FILES["img_" $langcode]['tmp_name']);

                if ((
$mime == "image/jpeg") || ($mime == "image/png")) {

                    
$sql    "select max(id) as max_id from music_channel";
                    
$result bind_pdo($sqlnull"selectone");
                    
$id     = (int)$result["max_id"] + 1;

                    
$filename $_FILES["img_" $langcode]['name'];
                    
preg_match("/\.([^\.]+)$/"$filename$file_ext);
                    
$newfilename random_string(10) . "_music_channel_id_" $id "." $file_ext[1]; // default length 8
                    
move_uploaded_file($_FILES["img_" $langcode]['tmp_name'], "../file/music_channel/" $newfilename) or die ("Could not copy the file");

                    
image_fix_orientation("../file/music_channel/" $newfilename);

                    
$photo          $newfilename;
                    
$img[$langcode] = $photo;
                } else {
                    
$invalid_upload_file_format true;
                }

                if (
$invalid_upload_file_format) {
                    
$message .= _lang("Invalid file format.");
                }
            }
        }

        if (!empty(
$message)) {
            echo 
"<script>alert('" $message "'); history.back();</script>";
            exit;
        }
    }

    if (
$_REQUEST["action"] == "ADD") {
        
$sql        "insert into music_channel (img_en, img_cn, title_en, title_cn, location_en, location_cn, desc_en, desc_cn, date_time, createby, createdate, lastupby, lastupdate) value (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        
$parameters = array($img["en"], $img["cn"], $_POST["title_en"], $_POST["title_cn"], $_POST["location_en"], $_POST["location_cn"], $_POST["desc_en"], $_POST["desc_cn"], $_POST["date_time"], $_SESSION["cmsloginid"], date("Y-m-d H:i:s"), $_SESSION["cmsloginid"], date("Y-m-d H:i:s"));

        
bind_pdo($sql$parameters);

        
header("Location: " $page_settings["domain"] . "_index.php?msg=1");
    } else if (
$_REQUEST["action"] == "MODIFY") {

        
$sql        "update music_channel set date_time=?, lastupby=?, lastupdate=?,";
        
$parameters = array($_POST['date_time'], $_SESSION['cmsloginid'], $nowdate);

        foreach (
$arraylangcode as $langcode => $langname) {
            
$sql .= "title_" $langcode "=?,location_" $langcode "=?,desc_" $langcode "=?,";
            
$parameters[] = $_POST["title_" $langcode];
            
$parameters[] = $_POST["location_" $langcode];
            
$parameters[] = $_POST["desc_" $langcode];

            if(!empty(
$img[$langcode])){
                
$sql .= "img_".$langcode."=?,";
                
$parameters[] = $img[$langcode];
            }else{
                if(isset(
$_POST["delete_img_".$langcode])){
                    
$sql .= "img_".$langcode."=?,";
                    
$parameters[] = "";
                }
            }

        }

        
$sql substr_replace($sql" ", -1);


        
$sql .= " where id = ?";
        
$parameters[] = (int)$_POST["id"];

        
bind_pdo($sql$parameters);

        
header("Location: " $page_settings["domain"] . "_form.php?id=".(int)$_POST["id"]."&msg=2");
    } else if (
$_REQUEST["action"] == "STATUS") {
        
$id      = (int)$_GET["id"];

        
$sql        "update music_channel set status=case when status = 1 then 0 else 1 end, lastupdate=?, lastupby=? where id = ?";
        
$parameters = array(date("Y-m-d H:i:s"), $_SESSION['cmsloginid'], $id);

        
bind_pdo($sql$parameters);

        
header("Location: " $page_settings["domain"] . "_index.php?msg=2");
    } else if (
$_REQUEST["action"] == "DELETE") {
        
$id      = (int)$_GET["id"];

        
$sql "update music_channel set deleted = ?, status = ?, lastupdate=?, lastupby=? where id = ?";
        
$parameters = array(10date("Y-m-d H:i:s"), $_SESSION['cmsloginid'], $id);
        
bind_pdo($sql$parameters);

        
header("Location: " $page_settings["domain"] . "_index.php?msg=2");
    }