Go to the source code of this file.
Functions | |
| report ($smarty, $INPUT, $db) | |
| Send a status report to all users via e-mail. | |
To set up automatic nightly status reports, you need a utility like curl(1) or wget(1). Create a cron job that runs a command like this:
curl http://yourserver/semapp/action.php?action=report
This will make action.php invoke the report() function. Alternatively, status reports can be triggered manually via the administrator's web interface.
Definition in file report.php.
| report | ( | $ | smarty, | |
| $ | INPUT, | |||
| $ | db | |||
| ) |
Send a status report to all users via e-mail.
| $smarty | -- a Smarty handle | |
| $INPUT | -- input data (currently unused) | |
| $db | -- a database handle |
The message report is created via Smarty, using the template file msg_report.tpl.
Definition at line 40 of file report.php.
References $actions_info, $item_info, $validation_info, send_email(), and sql_query().
00040 { 00041 00042 global $_SESSION, $default_role_id, $default_location_id, $debug_level; 00043 global $actions_info, $item_info, $validation_info; 00044 00045 # default parameters 00046 $default = array( 00047 ); 00048 00049 ## check user input (basic) 00050 00051 # $INPUT = array_merge($default, $_GET, $_POST); 00052 $INPUT = array_merge($default, $INPUT); 00053 00054 $now = strftime("%Y-%m-%d %H:%M:%S"); 00055 00056 00057 $param = array ( "tables" => "user,role,state,degree", 00058 "cond" => "user.state_id = state.id AND 00059 user.role_id = role.id and 00060 user.degree_id = degree.id", 00061 00062 "columns" => "user.*,degree.description AS degree_description,role.name AS role_name, state.name AS state_name", 00063 "order" => "user.surname,user.forename,user.sex,degree_description" 00064 ); 00065 00066 $users = sql_query('select', $param, $db); 00067 00068 00069 $param = array ( 00070 "tables" => "document,doc_type,state,collection,timestamp", 00071 "cond" => "document.state_id = state.id AND collection.id = document.collection_id AND document.last_state_change >= timestamp.time AND timestamp.name='report' AND doc_type.id = document.doc_type_id AND doc_type.for_loan != 0", 00072 "columns" => "document.*, state.name AS state_name, collection.user_id AS user_id, collection.title AS collection_title", 00073 ); 00074 00075 $docs = sql_query('select', $param, $db); 00076 00077 $param = array ( 00078 "tables" => "state,collection,timestamp", 00079 "cond" => "collection.state_id = state.id AND collection.last_state_change >= timestamp.time AND timestamp.name='report'", 00080 "columns" => "state.name AS state_name, collection.*", 00081 ); 00082 00083 $collections = sql_query('select', $param, $db); 00084 00085 00086 $report_info = array(); 00087 00088 00089 foreach ($users as $u) { 00090 00091 $uid = $u['id']; 00092 00093 if ($u['state_name'] != "active") { 00094 continue; 00095 } 00096 00097 00098 $report_info[$uid]['user_info'] = $u; 00099 00100 ## documents 00101 00102 foreach ($docs as $d) { 00103 00104 $doc_state = $d['state_name']; 00105 00106 $key = $u['role_name'] . "-" . $doc_state; 00107 00108 switch($key) { 00109 00110 case "staff-new": 00111 case "staff-obsolete": 00112 $report_info[$uid]['doc'][$doc_state][] = $d; 00113 00114 break; 00115 00116 case "edit-active": 00117 case "edit-inactive": 00118 00119 if ($uid == $d['user_id']) { 00120 $report_info[$uid]['doc'][$doc_state][] = $d; 00121 } 00122 break; 00123 00124 } 00125 00126 } 00127 00128 ## collections 00129 00130 foreach ($collections as $c) { 00131 00132 $coll_state = $c['state_name']; 00133 00134 $key = $u['role_name'] . "-" . $coll_state; 00135 00136 switch($key) { 00137 case "edit-obsolete": 00138 case "edit-inactive": 00139 if ($c['user_id'] == $uid) { 00140 $report_info[$uid]['coll'][$coll_state][] = $c; 00141 } 00142 break; 00143 } 00144 } 00145 00146 ## users 00147 00148 foreach ($users as $u2) { 00149 00150 $user_state = $u2['state_name']; 00151 00152 $key = $u['role_name'] . "-" . $user_state; 00153 00154 switch($key) { 00155 case "admin-new": 00156 $report_info[$uid]['user'][$user_state][] = $u2; 00157 break; 00158 } 00159 } 00160 00161 00162 } 00163 00164 foreach ($report_info as $r) { 00165 # send email report to user 00166 00167 00168 if ( (!isset($r['doc'])) and 00169 (!isset($r['coll'])) and 00170 (!isset($r['user'])) 00171 ) { 00172 continue; 00173 } 00174 00175 $tpl_vars = array(); 00176 $tpl_vars = $r; 00177 00178 $email_to = $r['user_info']['degree_name'] . " "; 00179 $email_to .= $r['user_info']['forename'] . " "; 00180 $email_to .= $r['user_info']['surname'] . " "; 00181 00182 00183 #debugging 00184 # $email_to .= "<mb@biblio.tu-bs.de>"; 00185 00186 $email_to .= "<" . $r['user_info']['email'] . ">"; 00187 00188 send_email($smarty,'msg_status.tpl',$tpl_vars, $email_to); 00189 00190 } 00191 00192 # update timestamp 00193 00194 $param = array ( 00195 "tables" => "timestamp", 00196 "cond" => "name = 'report'", 00197 "data" => array ("time" => $now ), 00198 ); 00199 00200 sql_query('update', $param, $db); 00201 00202 }
Here is the call graph for this function:

1.4.7