/var/www/hkosl.com/kelvin/webadmin/mate_tech_content_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
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
<?php
include 'config.php';

// Check if the user is logged in

if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1'))
{
header("Location: login.php");
exit;
}
require(
"configure.php");
    require(
"function_resizethumb.php");
    
$menuid=check_input($_REQUEST["menuid"]);
$contentdesctc        preg_replace("/'/","\'",$_POST["contentdesctc"]);
$contentdescen        preg_replace("/'/","\'",$_POST["contentdescen"]);
$belongpage check_input($_REQUEST["menuid"]);
$belongcatid check_input($_REQUEST["belongcatid"]);

//$sort        = '1';
$nowdate             date("Y-m-d H:i:s");
//print_r($_POST); 


$sql "select max(contentid) as maxid ";
$sql .= "from mate_tech_content ";
$result=mysql_query($sql);
$row mysql_fetch_array($result,MYSQL_ASSOC);
$contentid $row{maxid}+1;



    
// Upload File
    
$filelimit 1048576//Filelimit in 2MB
    
if ($_FILES['contentimgtc']['name'] <> '')
    {
        if (
$_FILES['contentimgtc']['size'] < $filelimit ){

            if ((
$_FILES["contentimgtc"]["type"] == "image/gif") || ($_FILES["contentimgtc"]["type"] == "image/GIF") || ($_FILES["contentimgtc"]["type"] == "image/jpg") || ($_FILES["contentimgtc"]["type"] == "image/JPG") || ($_FILES["contentimgtc"]["type"] == "image/jpeg") || ($_FILES["contentimgtc"]["type"] == "image/JPEG") || ($_FILES["contentimgtc"]["type"] == "image/pjpeg") || ($_FILES["contentimgtc"]["type"] == "image/PJEG") || ($_FILES["contentimgtc"]["type"] == "image/png") || ($_FILES["contentimgtc"]["type"] == "image/x-png") || ($_FILES["contentimgtc"]["type"] == "image/PNG") || ($_FILES["contentimgtc"]["type"] == "image/X-PNG"))
            {
                
move_uploaded_file  ($_FILES['contentimgtc']['tmp_name'], "../images/mate_tech_contentid_tc_".$contentid.$_FILES['contentimgen']['name'])
                or die (
"Could not copy the file");

                
$contentimgtcimg "../images/mate_tech_contentid_tc_".$contentid.$_FILES['contentimgen']['name'];
                
//createthumb($contentimgtcimg, $contentimgtcimg, 980, 310);

                
$contentimgtc "mate_tech_contentid_tc_".$contentid.$_FILES['contentimgen']['name'];
            }

        }
        else
        {
            
// upload error
            
?>
            <script language="javascript">
                alert("Files must be JPEG, GIF, or PNG and under 2MB in size");
                history.back();
            </script>
            <?php
            
exit;
        }

    }
    else
    {
        
$contentimgtc "";
    }

    if (
$_FILES['contentimgen']['name'] <> '')
    {
        if (
$_FILES['contentimgen']['size'] < $filelimit ){

            if ((
$_FILES["contentimgen"]["type"] == "image/gif") || ($_FILES["contentimgen"]["type"] == "image/GIF") || ($_FILES["contentimgen"]["type"] == "image/jpg") || ($_FILES["contentimgen"]["type"] == "image/JPG") || ($_FILES["contentimgen"]["type"] == "image/jpeg") || ($_FILES["contentimgen"]["type"] == "image/JPEG") || ($_FILES["contentimgen"]["type"] == "image/pjpeg") || ($_FILES["contentimgen"]["type"] == "image/PJEG") || ($_FILES["contentimgen"]["type"] == "image/png") || ($_FILES["contentimgen"]["type"] == "image/x-png") || ($_FILES["contentimgen"]["type"] == "image/PNG") || ($_FILES["contentimgen"]["type"] == "image/X-PNG"))
            {
                
move_uploaded_file  ($_FILES['contentimgen']['tmp_name'], "../images/mate_tech_contentid_en_".$contentid.$_FILES['contentimgen']['name'])
                or die (
"Could not copy the file");

                
$contentimgenimg "../images/mate_tech_content/mate_tech_contentid_en_".$contentid.$_FILES['contentimgen']['name'];
                
//createthumb($contentimgenimg, $contentimgenimg, 980, 310);

                
$contentimgen "mate_tech_contentid_en_".$contentid.$_FILES['contentimgen']['name'];
            }

        }
        else
        {
            
// upload error
            
?>
            <script language="javascript">
                alert("Files must be JPEG, GIF, or PNG and under 2MB in size");
                history.back();
            </script>
            <?php
            
exit;
        }

    }
    else
    {
        
$contentimgen "";
    }
    
    
    
// Sort
//if ($sort == '' || $sort == '0') {
    
$sql2 "select max(sort) as maxid from mate_tech_content where belongpage='$belongpage'";

    
$result2=mysql_query($sql2);
    
$row2 mysql_fetch_array($result2,MYSQL_ASSOC);
    
$sort $row2{maxid}+1;
//}
/*if( mysql_num_rows(mysql_query("SELECT contentid FROM content WHERE sort=$sort ")) > 0){
    mysql_query("UPDATE content SET sort= sort+1 WHERE sort >=$sort ");
}*/

$sql "insert into mate_tech_content (contentimgtc, contentimgen, belongpage, belongcatid, contentid, contentdesctc, contentdescen,sort, status, createdate, createby, lastupdate, lastupby) values ('$contentimgen', '$contentimgtc', '$belongpage','$belongcatid', '$contentid', '$contentdesctc',  '$contentdescen', '$sort', '1', '$nowdate', '".$_SESSION['cmsloginid']."', '$nowdate', '".$_SESSION['cmsloginid']."')";


mysql_query($sql);
if( 
mysql_errno() > ){
    echo 
'Add Material or Technology Content Error:<br />'mysql_error() .'<br />SQL: '$sql;
    exit;
}

mysql_close($dbh);


header("Location: mate_tech_content_index.php?menuid=$menuid&msg=Add Successful");
?>