index.php

Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of the "Electronic Semester Apparatus"
00004 // of University Library Braunschweig, Germany.
00005 // Copyright (C) 2005 University Library Braunschweig, Germany.
00006 //
00007 // Author: Martin Butkus <mb@biblio.tu-bs.de>
00008 
00011 
00059 
00060 set_include_path( '../php' . PATH_SEPARATOR . get_include_path());
00061 set_include_path( '../smarty/libs' . PATH_SEPARATOR . get_include_path());
00062 
00063 if (session_id() == "") { session_start(); }
00064 
00065 require_once 'Smarty.class.php';
00066 require_once 'sql.php';
00067 require_once 'error.php';
00068 require_once 'util.php';
00069 require_once 'const.php';
00070 require_once 'config.php';
00071 require_once 'mod_item.php';
00072 
00074 
00075 function cmp_coll($a, $b) {
00076         $key_a = $a['title'] . $a['collection_no'];
00077         $key_b = $b['title'] . $b['collection_no'];
00078 
00079         return strcmp($key_a, $key_b);
00080 }
00081 
00082 function show_index() {
00083 
00093 
00094 global $_GET, $_POST, $validation_info, $actions_info;
00095 $smarty = smarty_init();
00096 
00097 ## parameters accepted by this php script
00098 
00099 $default = array(
00100         "mode" => "view",
00101 );
00102 
00103 ## check user input 
00104 
00105 $INPUT = array_merge($default, $_GET, $_POST  );
00106 $errors = check_input($INPUT, $validation_info); 
00107 
00108 if (isset($_SESSION['mode'])) {
00109         $INPUT['mode'] = $_SESSION['mode'];
00110 }
00111 
00112 if ($debug_level > 10) {
00113          print "<hr><pre>Input: ";
00114         print_r($INPUT);
00115         print "</pre><hr>";
00116 }
00117 
00118 if (!empty($errors)) {
00119         user_error("Missing or malformed input parameter(s): " . join($errors, ", "),
00120                 E_USER_ERROR); 
00121 }
00122 
00123 # init mysql connection
00124 $db = sql_init();
00125 
00126 expire($smarty,$db);
00127 
00128 $param = array ( "tables" => "user,role,state,degree", 
00129                  "cond" => "user.state_id = state.id  AND 
00130                             user.role_id = role.id and 
00131                             role.name = 'edit' and 
00132                             IF(user.use_alias,user.alias_degree_id,user.degree_id) = degree.id ", 
00133                 "columns" => "user.*, 
00134         IF(user.use_alias,user.alias_forename,user.forename) AS forename, 
00135         IF(user.use_alias,user.alias_surname,user.surname) AS surname, 
00136         user.forename as real_forename,
00137         user.surname as real_surname,
00138         IF(user.use_alias,user.alias_sex,user.sex) AS sex, 
00139         IF(user.use_alias,user.alias_degree_id,user.degree_id) AS degree_id, 
00140         degree.description AS degree_description 
00141         ",
00142                  "order" => "surname,forename,degree_description,sex,real_surname,real_forename" 
00143                 );
00144 
00145 if ($INPUT['mode'] == "edit" and isset($_SESSION['user'])) {
00146         $param['cond'] .= " AND user.id=" . $_SESSION['user']['id'];
00147 }
00148 
00149 if ($INPUT['mode'] == "view") {
00150         $param['cond'] .= " AND state.name = 'active'";
00151 } else {
00152         $param['cond'] .= " AND state.name != 'new'";
00153 }
00154 
00155 $user = sql_query('select', $param, $db);
00156 
00157 $tpl_var = $INPUT;
00158 $tpl_var['collection'] = array();
00159 
00160 foreach ($user as $u) {
00161         $k = $u['id'];
00162         $v = $u['degree_description'] . " ". $u['forename'] . " " . $u['surname'];
00163         if ($u['use_alias']) {
00164         $v .= " (" . $u['real_forename'] . " " . $u['real_surname'] . ")";
00165         }
00166         $tpl_var['html_options']['user'][$k] = $v;
00167 }
00168 
00169 
00170 foreach ($user as $u) {
00171 
00172         $param = array ( "tables" => "collection,user,state,degree", 
00173         "columns" => "collection.*,
00174         IF(user.use_alias,user.alias_forename,user.forename) AS forename, 
00175         IF(user.use_alias,user.alias_surname,user.surname) AS surname, 
00176         IF(user.use_alias,user.alias_sex,user.sex) AS sex, 
00177         IF(user.use_alias,user.alias_degree_id,user.degree_id) AS degree_id, 
00178         degree.description AS degree_description,
00179         state.name AS state_name",
00180         "cond" => "degree.id = IF(user.use_alias,user.alias_degree_id,
00181                                 user.degree_id) AND 
00182                    state.id = collection.state_id AND
00183                    user.id = collection.user_id AND 
00184                    user.id=" . $u['id']. " ",
00185         "order" => "collection.title,collection.collection_no",
00186         );
00187 
00188         if ($INPUT['mode'] == "view") {
00189                 $param['cond'] .= "AND state.name = 'active'";
00190         }
00191 
00192         $ans = sql_query('select', $param, $db);
00193 
00194         $key  = trim($u['surname']);
00195         $key .= trim($u['forename']);
00196         $key .= trim($u['degree_description']);
00197         $key .= trim($u['sex']);
00198 
00199         if (!empty($ans)) {
00200                 $tpl_var['collection'][$key] = array_merge($tpl_var['collection'][$key],  $ans);
00201         }
00202 
00203 #       if (!empty($ans)) {
00204 #               $tpl_var['collection'][] = $ans;
00205 #       }
00206 
00207 }
00208 
00209 # sort collections
00210 
00211 foreach ($tpl_var['collection'] as $k => $v) {
00212 
00213         usort($v, "cmp_coll");
00214         $tpl_var['collection'][$k] = $v;
00215         #print_r($v);
00216 }
00217 #exit(0);
00218 
00219 
00220 $tpl_var['actions_info'] = $actions_info;
00221 
00222 #echo '<pre>';
00223 #print_r($tpl_var);
00224 #echo '</pre>';
00225 #exit(0);
00226 
00227 do_template( $smarty, 'index.tpl', $tpl_var, TRUE );
00228 
00229 sql_exit($db);
00230 
00231 }
00232 
00233 show_index(); // execute this function
00234 ?>

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