mod_item.php File Reference

Functions that perform status changes on items. More...

Go to the source code of this file.

Functions

 extend_loan ($coll_id, $db)
 Extend the loan period for a document collection.
 coll_set_state ($smarty, $collection_id, $states, $db)
 Perform a status change on the members of a document collection.
 set_item_state ($smarty, $INPUT, $db)
 Change the state of an item.
 expire ($smarty, $db)
 Expire a document collection.


Detailed Description

Functions that perform status changes on items.

Definition in file mod_item.php.


Function Documentation

coll_set_state ( smarty,
collection_id,
states,
db 
)

Perform a status change on the members of a document collection.

Parameters:
$smarty -- Smarty template engine handle
$db -- SQL database handle
$collection_id -- id of the document collection
$states -- an associative array mapping original states to target states for items in this collection
This is a helper function for the set_item_state() function. It's purpose is to loop through all documents in a collection, and to apply the status changes described in the $states[] table.

Definition at line 59 of file mod_item.php.

References sql_query().

Referenced by set_item_state().

00059                                                                 {
00060 
00061         # set state of documents in collection
00062         $param = array ( 
00063 
00064                  "tables" => "document,state,doc_type",
00065                  "columns" => "document.*, state.name AS state_name, doc_type.name as doc_type_name",
00066                  "cond" => "document.collection_id = " . $collection_id . 
00067                            " AND document.state_id = state.id AND document.doc_type_id = doc_type.id",
00068 
00069                 );
00070         
00071 
00072         $docs = sql_query('select', $param, $db);
00073 
00074         $param = array ( "table" => "document");
00075 
00076         foreach ($docs as $d) {
00077 
00078                 $param['id'] = $d['id'];
00079 
00080                 $cur_state   = $d['state_name']; 
00081                 $cur_doctype = $d['doc_type_name']; 
00082 
00083                 $keys = array(  
00084                         $cur_doctype . '-' . $cur_state,
00085                         $cur_state,
00086                         'DEFAULT'
00087                 );
00088 
00089                 # print_r($keys);
00090 
00091                 unset($param['state']);
00092 
00093                 foreach ($keys as $k) {
00094                         if  (isset($states[$k])) {
00095                                 $param['state'] = $states[$k];
00096                                 break;
00097                         }
00098                 }
00099 
00100                 # print_r($param);
00101                 if (isset($param['state'])) {
00102                         sql_query('set_state', $param, $db);
00103                 }
00104         }
00105 
00106 }

Here is the call graph for this function:

expire ( smarty,
db 
)

Expire a document collection.

Parameters:
$smarty - Smarty handle
$db -- SQL database handle
This function is central to the "expiry" mechanism for document collections. It should be called ever so often to allow stale document collections to expire. For example, whenever the index page (index.php) is visited, a call to expiry() is made.

This function checks for document collections whose expiry date has been met. These collections are suspended (state is set to 'obsolete').

The owner of the collection will be informed on the next run of the nighty status report (see report() for details).

The owner can then choose to extend the loan period via the Web interface. In this case, the collection's status is changed back to "active", and a new expiry date is set.

After a grace period of 14 days, collections that still have 'obsolete' status are dissolved. This means that the status of the collection is set to 'inactive', and that the status of the documents in the collection also changes.

In the end, the collection itself as well as any of it's contents has reached the status "inactive". In this "final" state, there are two possibilities:

Definition at line 298 of file mod_item.php.

References set_item_state(), and sql_query().

Referenced by do_action(), show_collection(), and show_index().

00298                               {
00299 
00300         $param = array (
00301                 "tables" => "collection as c,state as s" ,
00302                 "columns" => "c.id" ,
00303                  cond => "c.state_id = s.id AND 
00304                           s.name = 'active' AND 
00305                           c.expiry_date <= NOW()",
00306         );
00307 
00308         $colls = sql_query('select', $param, $db);
00309 
00310         $input = array ("item" => "collection", "state" => "obsolete" );
00311 
00312         foreach ($colls as $c) {
00313                 $input['id'] = $c['id']; 
00314                 set_item_state($smarty, $input, $db);
00315         }
00316 
00317 
00318         $param = array (
00319                 "tables" => "collection AS c,state AS s" ,
00320                 "columns" => "c.id AS id",  
00321                  cond => "(c.state_id = s.id) AND 
00322                           (s.name = 'obsolete') AND 
00323                           DATE_ADD(c.expiry_date, INTERVAL 14 DAY) <= NOW()"
00324         );
00325 
00326         $colls = sql_query('select', $param, $db);
00327 
00328         $input = array ("item" => "collection", "state" => "inactive" );
00329 
00330         foreach ($colls as $c) {
00331                 $input['id'] = $c['id']; 
00332                 set_item_state($smarty, $input, $db);
00333         }
00334 }

Here is the call graph for this function:

extend_loan ( coll_id,
db 
)

Extend the loan period for a document collection.

Parameters:
$coll_id - document collection id
$db -- SQL database handle
This function will extend the loan period of an (already expired) document collection. The new expiry date is determined with the get_new_expiry_date() helper function.

Definition at line 20 of file mod_item.php.

References get_new_expiry_date(), and sql_query().

Referenced by set_item_state().

00020                                     {
00021 
00022         # $param = array (
00023         #       "tables" => "collection",
00024         #       "cond" => "expiry_date <= NOW() AND id = " . $coll_id
00025         # );
00026         # 
00027         # $ans = sql_query('select', $param, $db);
00028         #
00029         # # not expired? --> do nothing
00030         #
00031         # if (empty($ans)) { 
00032         #       return;
00033         # }
00034 
00035         # set a new expiry date
00036 
00037         $param = array (
00038                 "tables" => "collection",
00039                 "id" => $coll_id,
00040                 "data" => array ("expiry_date" => get_new_expiry_date()) 
00041         );
00042 
00043         sql_query('update', $param, $db);
00044 
00045 }

Here is the call graph for this function:

set_item_state ( smarty,
INPUT,
db 
)

Change the state of an item.

Parameters:
$smarty -- Smarty handle
$db -- SQL database handle
$INPUT['item'] -- item type
$INPUT['id'] -- item id
$INPUT['state'] -- new state
Note:
Certain state changes have side effects. For instance, changing a new user account to "open" causes a password to be assigned and mailed that the user, and to promote the user to status "active".

Also, changing a collection's status to inactive (or back to active) also affects the status of all documents inside the collection. See expire() for an explanation for this behaviour.

Definition at line 127 of file mod_item.php.

References $validation_info, coll_set_state(), do_template(), extend_loan(), get_item_owner(), get_new_expiry_date(), send_email(), set_random_pw(), and sql_query().

Referenced by expire().

00127                                               {
00128 
00129 global $_SESSION, $validation_info;
00130 
00131 $default = array(
00132 );
00133 
00134 ## check user input 
00135 
00136 # $INPUT = array_merge($default, $_GET, $_POST);
00137 
00138 $INPUT = array_merge($default, $INPUT);
00139 
00140 # $errors = check_input($INPUT, $validation_info); 
00141 
00142 
00143 #if ($debug_level > 10) {
00144 #        print "<hr><pre>Input: ";
00145 #       print_r($INPUT);
00146 #       print "</pre><hr>";
00147 #}
00148 
00149 #if (!empty($errors)) {
00150 #       user_error("Missing or malformed input parameter(s): " . join($errors, ", "),
00151 #               E_USER_ERROR); 
00152 #}
00153 
00154 $item_tables = array(
00155         "DEFAULT" => "document", 
00156         "collection" => "collection", 
00157         "user"    => "user", 
00158 );
00159 
00160 
00161 $action = $INPUT['item'] . "-" . $INPUT['state'];
00162 
00163 ## special cases
00164 
00165 switch($action) {
00166 
00167         case "collection-inactive": 
00168 
00169                 $new_states = array(
00170                         "DEFAULT"       => "inactive",
00171                         "open"          => "obsolete",
00172                         "active"        => "obsolete",
00173                         "obsolete"      => "obsolete",
00174                         "file-active"    => "inactive",
00175                         "url-active"    => "inactive",
00176                 );
00177 
00178                 coll_set_state($smarty, $INPUT['id'], $new_states, $db);
00179 
00180         break;
00181 
00182         case "collection-active": 
00183 
00184                 # $new_states = array (
00185                 #       "file-inactive"    => "active",
00186                 #       "url-inactive"    => "active",
00187                 # );
00188 
00189                 coll_set_state($smarty, $INPUT['id'], $new_states, $db);
00190                 extend_loan($INPUT['id'], $db); 
00191 
00192         break;
00193 
00194 
00195         case "user-open":
00196 
00197                 # create random password and mail it to the user
00198          
00199                 $passwd = set_random_pw($INPUT['id'], $db);
00200 
00201                 $user = get_item_owner("user", $INPUT['id'], $db);
00202                         
00203                 $email_to = $user['degree_name'] . " ";
00204                 $email_to .= $user['forename'] . " ";
00205                 $email_to .= $user['surname'] . " ";
00206                 $email_to .= "<" . $user['email'] . ">";
00207 
00208                 $tpl_vars = array();
00209                 $tpl_vars['user_info'] = $user; 
00210                 $tpl_vars['user_info']['password'] = $passwd;   
00211 
00212                 send_email($smarty,'msg_new_account.tpl',$tpl_vars,
00213                         $email_to);
00214 
00215                 # set state to active
00216                 $INPUT['state'] = "active";
00217 
00218         break;
00219 }
00220 
00221 $tbl = $item_tables['DEFAULT'];
00222 
00223 if (isset($item_tables[$INPUT['item']])) {
00224         $tbl = $item_tables[$INPUT['item']];
00225 }
00226 
00227 $param = array ( "table" => $tbl,
00228                  "state" => $INPUT['state'],
00229                  "id" => $INPUT['id'],
00230 );
00231 
00232 sql_query('set_state', $param, $db);
00233 
00234 if ($action == "collection-active") {
00235         # show message for user
00236 
00237         $tpl_vars = array (
00238                 "expiry_date" => get_new_expiry_date() ,
00239                 "id" => $INPUT['id']
00240         );
00241 
00242         do_template($smarty,'extend_loan.tpl', $tpl_vars);
00243         exit(0);
00244 }
00245 
00246 }

Here is the call graph for this function:


Generated on Fri Jul 14 17:38:58 2006 for semapp by  doxygen 1.4.7