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

    if(empty(
$_POST["name_en"])){
        
$messgae .= "Please enter name.\\n\\n";
    }

    if(empty(
$_POST["menu_id"])){
        
$messgae .= "Please select a menu.\\n\\n";
    }

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

    
$sql    "select max(id) as maxid from course_category ";
    
$row    bind_pdo($sqlNULL"selectone");
    
$course_category_id $row{"maxid"} + 1;

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

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

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

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

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

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

                    
$icon_path "../images/course_category/".$newfilename;

                    
createthumb($icon_path$icon_path100100);

                    
$icon[$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 {
            
$icon[$langcode] = "";
            
//$messgae .= "Please select a banner image.\\n\\n";
        
}
    }

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

    
$sql     "select max(sort) as max_sort from course_category where deleted = 0";
    
$row     bind_pdo($sqlNULL"selectone");
    
$sort $row{"max_sort"} + 1;

    
$sql        "insert into course_category set show_home=?, menu_id=?, sort=?, createdate=?, createby=?, lastupdate=?, lastupby=?, ";
    
$parameters = array($show_home, (int)$_POST["menu_id"], $sort$nowdate$_SESSION['cmsloginid'], $nowdate$_SESSION['cmsloginid']);


    foreach (
$arraylangcode as $langcode => $langname) {
        
$sql .= "name_" $langcode "=?, desc1_" $langcode "=?, desc2_" $langcode "=?, icon_".$langcode."=?, ";
        
$parameters[] = $_POST["name_" $langcode];
        
$parameters[] = $_POST["desc1_" $langcode];
        
$parameters[] = $_POST["desc2_" $langcode];
        
$parameters[] = $icon[$langcode];
    }

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

    
$dbh null;

    
header("Location: course_category_index.php?msg=1");