Go to the source code of this file.
Functions | |
| del_item ($smarty, $INPUT, $db) | |
| delete an item from the database | |
| do_delete_item ($item, $id, $db) | |
| delete an item from the database, without safety checks | |
| may_delete_item ($item, $id, $db) | |
| perform safety checks on whether it is possible to delete an item | |
Definition in file del_item.php.
| del_item | ( | $ | smarty, | |
| $ | INPUT, | |||
| $ | db | |||
| ) |
delete an item from the database
This is a function to delete an item, called by action.php. Before performing the delete, it checks whether the item can be deleted without corrupting the database.
If the item cannot be deleted, the action is aborted and the user is informed about the error.
| $smarty | -- Smarty template engine handle | |
| $INPUT['item'] | -- item type | |
| $INPUT['id'] | -- id of the item to be deleted | |
| $db | -- MySQL database handle |
Definition at line 29 of file del_item.php.
References $validation_info, check_input(), delete_file(), do_delete_item(), do_template(), and may_delete_item().
00029 { 00030 global $_SESSION, $validation_info; 00031 00032 00033 $default = array( 00034 ); 00035 00036 $INPUT = array_merge($default, $INPUT); 00037 $errors = check_input($INPUT, $validation_info); 00038 00039 if ($debug_level > 10) { 00040 print "<hr><pre>Input: "; 00041 print_r($INPUT); 00042 print "</pre><hr>"; 00043 } 00044 00045 if (!empty($errors)) { 00046 user_error("Missing or malformed input parameter(s): " . join($errors, ", "), 00047 E_USER_ERROR); 00048 } 00049 00050 00051 if (!empty($INPUT['file'])) { 00052 00053 00054 # just delete an attached file 00055 delete_file($INPUT['item'], $INPUT['id'], $INPUT['file']); 00056 00057 00058 } else { 00059 00060 if (!may_delete_item($INPUT['item'], $INPUT['id'], $db)) { 00061 do_template($smarty, 'no_delete.tpl' , $INPUT, FALSE); 00062 exit(0); 00063 } 00064 00065 # delete the whole item 00066 do_delete_item($INPUT['item'], $INPUT['id'], $db); 00067 00068 } 00069 00070 }
Here is the call graph for this function:

| do_delete_item | ( | $ | item, | |
| $ | id, | |||
| $ | db | |||
| ) |
delete an item from the database, without safety checks
Actually performs the deletion, without checking whether it would corrupt the database.
| $smarty | -- Smarty template engine handle | |
| $INPUT['item'] | -- item type | |
| $INPUT['id'] | -- id of the item to be deleted | |
| $db | -- MySQL database handle |
Definition at line 82 of file del_item.php.
References delete_file(), list_files(), and sql_query().
Referenced by del_item().
00082 { 00083 00084 $sql_table = array ( 00085 "article" => "document", 00086 "book" => "document", 00087 "file" => "document", 00088 "url" => "document", 00089 "collection" => "collection", 00090 "user" => "user", 00091 "email" => "email", 00092 ); 00093 00094 switch($item) { 00095 00096 case "user": 00097 00098 $p = array ( 00099 "tables" => "collection", 00100 "cond" => "collection.user_id = $id", 00101 "columns" => "id" 00102 ); 00103 00104 $ans = sql_query('select', $p, $db); 00105 00106 foreach ($ans as $a) { 00107 do_delete_item("collection",$a['id'], $db); 00108 } 00109 00110 break; 00111 00112 case "collection": 00113 00114 $p = array ( 00115 "tables" => "document, doc_type", 00116 "cond" => "document.collection_id = $id AND doc_type.id = document.doc_type_id", 00117 "columns" => "document.id AS id, doc_type.name AS type" 00118 ); 00119 00120 $ans = sql_query('select', $p, $db); 00121 00122 foreach ($ans as $a) { 00123 do_delete_item($a['type'], $a['id'], $db); 00124 } 00125 00126 break; 00127 00128 case "email": 00129 break; 00130 00131 default: // document 00132 00133 $p = array ( 00134 "tables" => "email", 00135 "cond" => "email.document_id = $id", 00136 "columns" => "id" 00137 ); 00138 00139 $ans = sql_query('select', $p, $db); 00140 00141 foreach ($ans as $a) { 00142 do_delete_item("email",$a['id'], $db); 00143 } 00144 00145 break; 00146 00147 } 00148 00149 00150 $t = $sql_table[$item]; 00151 00152 $p = array ( 00153 "table" => $t, 00154 "cond" => "id = $id", 00155 ); 00156 00157 sql_query('delete', $p, $db); 00158 00159 # delete all attached documents 00160 00161 $files = list_files($item, $id); 00162 00163 foreach ($files as $f => $f_info) { 00164 delete_file($item, $id, $f); 00165 } 00166 00167 }
Here is the call graph for this function:

| may_delete_item | ( | $ | item, | |
| $ | id, | |||
| $ | db | |||
| ) |
perform safety checks on whether it is possible to delete an item
Certain objects cannot be deleted without risking an inconsitent database. For example, a user cannot be deleted as long as there are any active collections that he owns. Likewise, a collection cannot be deleted as long as there are pending book orders for this collection. This function checks for these conditions.
| $item | -- item type | |
| $id | -- id of the item to be deleted | |
| $db | -- MySQL database handle |
Definition at line 183 of file del_item.php.
References sql_query().
Referenced by del_item().
00183 { 00184 00185 $sql_table = array ( 00186 "article" => "document", 00187 "book" => "document", 00188 "file" => "document", 00189 "url" => "document", 00190 "collection" => "collection", 00191 "user" => "user", 00192 "email" => "email", 00193 ); 00194 00195 $t = $sql_table[$item]; 00196 00197 $p = array ( 00198 "tables" => "state,$t", 00199 "cond" => "state.id = $t.state_id AND $t.id = $id", 00200 "columns" => "state.name AS state_name", 00201 "order" => "$t.id" 00202 ); 00203 00204 $ans = sql_query('select', $p, $db); 00205 00206 if (empty($ans)) { 00207 user_error("No such item: $item, id=$id", E_USER_ERROR); 00208 } 00209 00210 switch($item) { 00211 00212 case "user": 00213 00214 $ok = TRUE; 00215 00216 $p = array ( 00217 "tables" => "collection", 00218 "cond" => "collection.user_id = $id", 00219 "columns" => "id" 00220 ); 00221 00222 $ans = sql_query('select', $p, $db); 00223 00224 foreach ($ans as $a) { 00225 $ok = $ok && may_delete_item("collection",$a['id'], $db); 00226 } 00227 00228 break; 00229 00230 case "collection": 00231 00232 $ok = TRUE; 00233 00234 $p = array ( 00235 "tables" => "document, doc_type", 00236 "cond" => "document.collection_id = $id AND doc_type.id = document.doc_type_id", 00237 "columns" => "document.id AS id, doc_type.name AS type" 00238 ); 00239 00240 $ans = sql_query('select', $p, $db); 00241 00242 foreach ($ans as $a) { 00243 $ok = $ok && may_delete_item($a['type'], $a['id'], $db); 00244 } 00245 00246 break; 00247 00248 case "email": 00249 case "file": 00250 case "url": 00251 $ok = TRUE; 00252 break; 00253 00254 default: 00255 $ok = ($ans[0]['state_name'] == "inactive") or 00256 ($ans[0]['state_name'] == "new"); 00257 break; 00258 } 00259 00260 return $ok; 00261 }
Here is the call graph for this function:

1.4.7