07f397b6967174e972adeceb906072b6c3190491
[fa-stable.git] / includes / references.inc
1 <?php
2
3 include_once($path_to_root . "/includes/db/references_db.inc");
4
5 class references 
6 {
7         
8         function save($type, $id, $reference) 
9         {
10                 add_reference($type, $id, $reference);
11                 
12                 references::save_last($reference, $type);
13         }
14         
15         function get($type, $id) 
16         {
17                 return get_reference($type, $id);
18         }       
19         
20         function delete($type, $id) 
21         {
22                 delete_reference($type, $id);
23         }       
24         
25         function exists($type, $reference) 
26         {
27                 return (find_reference($type, $reference) != null);
28         }
29         
30         function save_last($reference, $type) 
31         {
32                 $next = references::increment($reference);
33                 save_next_reference($type, $next);
34         }
35         
36         function get_next($type) 
37         {
38                 return get_next_reference($type);
39         }
40         
41         //------------------------------------
42
43         function is_valid($reference) 
44         {
45                 return strlen(trim($reference)) > 0;
46         }
47         
48         function increment($reference) 
49         {
50         if (is_numeric($reference))
51                 return $reference + 1;
52         else 
53                 return $reference;
54         }
55         
56         //------------------------------------
57 }
58
59 //----------------------------------------------------------------------------
60
61 function is_new_reference($ref, $type)
62 {
63         $db_info = get_systype_db_info($type);
64         $db_name = $db_info[0];
65         $db_type = $db_info[1];
66         $db_ref = $db_info[3];
67         
68         if ($db_ref != null) 
69         {
70                 $sql = "SELECT $db_ref FROM $db_name WHERE $db_ref='$ref'";
71                 if ($db_type != null)
72                         $sql .= " AND $db_type=$type";
73                          
74                 $result = db_query($sql, "could not test for unique reference");
75                 
76                 return (db_num_rows($result) == 0);
77         }
78         
79         // it's a type that doesn't use references - shouldn't be calling here, but say yes anyways
80         return true;
81 }
82
83 ?>