OSDN Git Service

23169e7bfec71c96fa4afeb33d0e563b0bfac6a5
[ntch/develop.git] / nce / nc_query_board_attribute_list_db.php
1 <?php
2 /*
3  nce (ntch cloud environment.)
4  name: nc_update_readcnt_db.php
5  author: Akira Ohta (akohta001.gmail.com)
6  date: 2013-apr-14th
7  description:
8  License: GPLv3
9  */
10 include_once "account.php";
11 include_once "preference.php";
12 include_once "database.php";
13 include_once "log.php";
14 include_once "http_util.php";
15 include_once "error_code.php";
16
17 $user_id = $_POST['user'];
18 $hashed_passwd = $_POST['hashed_passwd'];
19 $board_name = $_POST['board_name'];
20 $type1 = $_POST['type1'];
21 $type2 = $_POST['type2'];
22
23 //--- authorization ---
24 $user = chk_passwd( $user_id, $hashed_passwd);
25 if(FALSE === $user){
26         echo $ERROR_MSG;
27         exit;
28 }
29
30 //--- parameter check start ---
31 if(!chk_param($board_name) || !chk_param($type1)){
32         echo ERROR303;
33         exit;
34 }
35 if(!is_numeric($type1)){
36         echo ERROR303;
37         exit;
38 }
39 if($type1!=2 && $type1!=3 && $type1!=5 && $type1!=6){
40         echo ERROR304;
41         exit;
42 }
43 //--- parameter check end ---
44
45 $table_name = TABLE_PREFIX."tbl{$user->home_dir}";
46 $query = <<< QUERY1
47 select res_number, record_type, dat_name from $table_name 
48     where board_name='{$board_name}' and ( record_type = '{$type1}'
49 QUERY1;
50
51 if(chk_param($type2)){
52         if(!is_numeric($type2) ||
53                 ($type2!=2 && $type2!=3 && $type2!=5 && $type2!=6) ||
54                 ($type1 == $type2)){
55                 echo ERROR303;
56                 exit;
57         }
58         $query = $query." or record_type = '{$type2}')"; 
59 }else{
60         $query = $query." )"; 
61 }
62
63 try{
64         $db->open();
65         $result = $db->execute($query);
66         
67         if(!$result){
68                 echo ERROR503;
69                 exit;
70         }
71         $db->close();
72 }catch(Exception $e){
73         $error = __FILE__."(".__LINE__.
74                 ") An error occured during query.";
75         nc_logging($error, $e);
76         echo ERROR500;
77         exit;
78 }
79
80 echo SUCCESS100;
81 for($i = 0; $i < $result->num_rows; $i++){
82         $row = $result->fetch_assoc();
83         echo $row['dat_name'].",".$row['record_type'].",".$row['res_number']."\n";
84 }
85
86 ?>