/var/www/hkosl.com/alliancealliance/webadmin/news_modify.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
<?php
    
require_once('check_login.php');
    require_once(
"function_cropimg.php");
    require_once(
"mime_type_lib.php");

    
$id = (int)$_POST["id"];

    
$sql        "select * from news where id = ? ";
    
$parameters = array($id);
    
$old_news_info  bind_pdo($sql$parameters"selectone");

    
$message "";

    if (!
validateDate($_POST["posted_date"], "Y-m-d")) {
        
$message .= "Please enter a correct posted date.\\n\\n";
    }

    if (
$old_news_info["typeid"] != "SPECIAL_OFFERS") {
        if (!
validateDate($_POST["published_from"], "Y-m-d H:i:s")) {
            
$message .= "Please enter a correct published from date.\\n\\n";
        }

        if (!
validateDate($_POST["published_to"], "Y-m-d H:i:s")) {
            
$message .= "Please enter a correct published to date.\\n\\n";
        }


        if(
validateDate($_POST["published_from"], "Y-m-d H:i:s") && validateDate($_POST["published_to"], "Y-m-d H:i:s") && $_POST["published_from"] > $_POST["published_to"]){
            
$message .= "Date of published from should be earlier than date of published to.\\n\\n";
        }
    }

    foreach (
$arraylangcode as $langcode => $langname) {

        
// Upload File
        
$filelimit 10 1048576//Filelimit in 10MB
        
if ($_FILES["cover_img_" $langcode]['name'] <> '') {
            if (
$_FILES["cover_img_" $langcode]['size'] < $filelimit) {

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

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

                    
$filename $_FILES["cover_img_" $langcode]['name'];
                    
preg_match("/\.([^\.]+)$/"$filename$file_ext);
                    
$newfilename random_string() . "_newsid_" $id "." $file_ext[1]; // default length 8

                    
move_uploaded_file($_FILES["cover_img_" $langcode]['tmp_name'], "../images/news/" $newfilename) or die ("Could not copy the file");

                    
$cover_img_path "../images/news/".$newfilename;

                    
createthumb($cover_img_path$cover_img_path150150);

                    
$cover_img[$langcode] = $newfilename;

                } else {
                    echo 
'<script language="javascript">
                alert("Image format should be JPEG, GIF or PNG. Image size should be lower than 10MB");
                history.back();
            </script>'
;

                    exit;
                }

            } else {
                echo 
'<script language="javascript">
                alert("Image format should be JPEG, GIF or PNG. Image size should be lower than 10MB");
                history.back();
            </script>'
;

                exit;
            }

        } else {
            
$cover_img[$langcode] = "";
            
//$message .= "Please select a cover image.\\n\\n";
        
}
    }


    foreach (
$arraylangcode as $langcode => $langname) {

        
// Upload File
        
$filelimit 10 1048576//Filelimit in 10MB
        
if ($_FILES["cover_img2_" $langcode]['name'] <> '') {
            if (
$_FILES["cover_img2_" $langcode]['size'] < $filelimit) {

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

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

                    
$filename $_FILES["cover_img2_" $langcode]['name'];
                    
preg_match("/\.([^\.]+)$/"$filename$file_ext);
                    
$newfilename random_string() . "_newsid_" $newsid "." $file_ext[1]; // default length 8

                    
move_uploaded_file($_FILES["cover_img2_" $langcode]['tmp_name'], "../images/news/" $newfilename) or die ("Could not copy the file");

                    
$cover_img_path "../images/news/".$newfilename;

                    
createthumb($cover_img_path$cover_img_path600600);

                    
$cover_img2[$langcode] = $newfilename;

                } else {
                    echo 
'<script language="javascript">
                alert("Image format should be JPEG, GIF or PNG. Image size should be lower than 10MB");
                history.back();
            </script>'
;

                    exit;
                }

            } else {
                echo 
'<script language="javascript">
                alert("Image format should be JPEG, GIF or PNG. Image size should be lower than 10MB");
                history.back();
            </script>'
;

                exit;
            }

        } else {
            
$cover_img2[$langcode] = "";
            
//$message .= "Please select a cover image.\\n\\n";
        
}
    }
    
    if (!empty(
$message)) {
        echo 
"<script>alert('" $message "'); history.back();</script>";
        exit;
    }

    if (isset(
$_POST["show_home"]) && $_POST["show_home"] == 1) {
        
$show_home 1;
    } else {
        
$show_home 0;
    }

    if (
$old_news_info["typeid"] != "SPECIAL_OFFERS") {
        
$sql        "update news set show_home=?, published_from=?, published_to=?,posted_date=?, lastupdate=?, lastupby=?, ";
        
$parameters = array($show_home$_POST["published_from"], $_POST["published_to"], $_POST["posted_date"], $nowdate$_SESSION['cmsloginid']);
    } else {
        
$sql        "update news set show_home=?, posted_date=?, lastupdate=?, lastupby=?, ";
        
$parameters = array( $show_home$_POST["posted_date"], $nowdate$_SESSION['cmsloginid']);
    }

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

        if (
$cover_img[$langcode] != '' || $_POST['delimage_' $langcode] > 0) {
            
$sql .= "cover_img_" $langcode "=?, ";
            
$parameters[] = $cover_img[$langcode];

            
//unlink image
            
$unlink_file_path "../images/news/".$old_news_info["cover_img_".$langcode];

            if( 
is_file ($unlink_file_path) ){
                
unlink($unlink_file_path);
            }
        }

        if (
$cover_img2[$langcode] != '' || $_POST['delimage2_' $langcode] > 0) {
            
$sql .= "cover_img2_" $langcode "=?, ";
            
$parameters[] = $cover_img2[$langcode];

            
//unlink image
            
$unlink_file_path "../images/news/".$old_news_info["cover_img2_".$langcode];

            if( 
is_file ($unlink_file_path) ){
                
unlink($unlink_file_path);
            }
        }
    }

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

    
$sql .= " where id=?";
    
$parameters[] = $id;

    
bind_pdo($sql$parameters);

    
$dbh null;

    
header("Location: news_index.php?typeid=" $old_news_info["typeid"] . "&msg=2");