/
category_api.php
114 lines (94 loc) · 3.72 KB
/
category_api.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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: category_api.php,v 1.3 2002-08-27 04:26:42 jfitzell Exp $
# --------------------------------------------------------
###########################################################################
# Category API
###########################################################################
# --------------------
# checks to see if the category is a duplicate
# we do it this way because each different project can have the same category names
# The old category name is excluded from the search for duplicate since a category
# can re-take its name. It is also useful when changing the case of a category name.
# For example, "category" -> "Category".
function is_duplicate_category( $p_project_id, $p_category , $p_old_category = '' ) {
global $g_mantis_project_category_table;
$c_project_id = (integer)$p_project_id;
$c_category = addslashes($p_category);
$query = "SELECT COUNT(*)
FROM $g_mantis_project_category_table
WHERE project_id='$c_project_id' AND
category='$c_category'";
if (strlen($p_old_category) != 0) {
$c_old_category = addslashes($p_old_category);
$query = $query . " AND category <> '$c_old_category'";
}
$result = db_query( $query );
$category_count = db_result( $result, 0, 0 );
return ( $category_count > 0 );
}
# --------------------
function category_add( $p_project_id, $p_category ) {
global $g_mantis_project_category_table;
$c_project_id = (integer)$p_project_id;
$c_category = addslashes($p_category);
$query = "INSERT
INTO $g_mantis_project_category_table
( project_id, category )
VALUES
( '$c_project_id', '$c_category' )";
return db_query( $query );
}
# --------------------
function category_update( $p_project_id, $p_category, $p_orig_category, $p_assigned_to ) {
global $g_mantis_project_category_table;
$c_project_id = (integer)$p_project_id;
$c_category = addslashes($p_category);
$c_orig_category = addslashes($p_orig_category);
$c_assigned_to = (integer)$p_assigned_to;
$query = "UPDATE $g_mantis_project_category_table
SET category='$c_category', user_id=$c_assigned_to
WHERE category='$c_orig_category' AND
project_id='$c_project_id'";
return db_query( $query );
}
# --------------------
function category_delete( $p_project_id, $p_category ) {
global $g_mantis_project_category_table;
$c_project_id = (integer)$p_project_id;
$c_category = addslashes($p_category);
$query = "DELETE
FROM $g_mantis_project_category_table
WHERE project_id='$c_project_id' AND
category='$c_category'";
return db_query( $query );
}
# --------------------
# return all categories for the specified project id
function category_get_all( $p_project_id ) {
global $g_mantis_project_category_table;
$c_project_id = (integer)$p_project_id;
$query = "SELECT category, user_id
FROM $g_mantis_project_category_table
WHERE project_id='$c_project_id'
ORDER BY category";
return db_query( $query );
}
# --------------------
# delete all categories associated with a project
function category_delete_all( $p_project_id ) {
$c_project_id = db_prepare_int( $p_project_id );
$t_project_category_table = config_get( 'mantis_project_category_table' );
$query = "DELETE
FROM $t_project_category_table
WHERE project_id='$c_project_id'";
db_query( $query );
# db_query() errors on failure so:
return true;
}
?>