collection.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 
00012 
00013 set_include_path( '../php' . PATH_SEPARATOR . get_include_path());
00014 set_include_path( '../smarty/libs' . PATH_SEPARATOR . get_include_path());
00015 
00016 if (session_id() == "") { session_start(); }
00017 
00018 require_once 'Smarty.class.php';
00019 require_once 'sql.php';
00020 require_once 'error.php';
00021 require_once 'redirect.php';
00022 require_once 'util.php';
00023 require_once 'mod_item.php';
00024 require_once 'upload.php';
00025 
00047 
00048 
00049 function show_collection() {
00050 
00051 global $_GET, $_POST, $_SESSION, $actions_info, $validation_info;
00052 
00053 $smarty =& smarty_init();
00054 
00055 ## parameters accepted by this php script
00056 
00057 $defaults = array (
00058         "id" => "",
00059         "state" => "active",
00060         "sort_crit" => "relevance desc",
00061         "mode" => "view",
00062         "type" => "",
00063         "item" => "collection",
00064 );      
00065 
00066 ## check user input 
00067 
00068 $INPUT = array_merge($defaults, $_GET, $_POST);
00069 $errors = check_input($INPUT, $validation_info); 
00070 
00071 if (isset($_SESSION['mode']) and ($INPUT['mode'] != "print")) {
00072         $INPUT['mode'] = $_SESSION['mode'];
00073 }
00074 
00075 if ($debug_level > 10) {
00076          print "<hr><pre>Input: ";
00077         print_r($INPUT);
00078         print "</pre><hr>";
00079 }
00080 
00081 
00082 if (!empty($errors)) {
00083         user_error("Missing or malformed input parameter(s): " . join($errors, ", "),
00084                 E_USER_ERROR); 
00085 }
00086 
00087 # init mysql connection
00088 $db = sql_init();
00089 
00090 expire($smarty, $db);
00091 
00092 if (isset($INPUT['lecture_no'])) {
00093         $INPUT['collection_no'] = $INPUT['lecture_no'];
00094 }
00095 
00096 if (isset($INPUT['collection_no'])) {
00097 
00098         $n = intval($INPUT['collection_no']);
00099 
00100         $p = array( "cond" => "collection_no = $n",
00101                 "tables" => "collection", "cols" => "id");
00102 
00103         $ans = sql_query('select', $p, $db);
00104 
00105         if (!empty($ans)) {
00106                 $url= "collection.php?id=" . $ans[0]['id'];
00107                 redirect($url);
00108         } else  {
00109                 redirect('index.php');
00110         }
00111 
00112         exit(0);
00113 }
00114 
00115 
00116 if ($INPUT['id'] == "") {
00117 
00118         $collection = array ();
00119 
00120 } else {
00121 
00122         $sql_param = array ( 
00123                 "tables" => "collection,user,degree", 
00124                 "columns" => "collection.*, 
00125         IF(user.use_alias,user.alias_forename,user.forename) AS forename, 
00126         IF(user.use_alias,user.alias_surname,user.surname) AS surname, 
00127         IF(user.use_alias,user.alias_sex,user.sex) AS sex, 
00128                 degree.description AS degree_description", 
00129                         "cond" => "
00130 
00131                         degree.id = 
00132                         IF(user.use_alias,user.alias_degree_id,user.degree_id) 
00133                         AND user.id = collection.user_id 
00134                         AND collection.id = " . $INPUT['id'], 
00135         );
00136 
00137         $ans = sql_query('select', $sql_param, $db);
00138 
00139         if (empty($ans)) {
00140                 redirect("index.php");
00141                 exit(0);
00142         }
00143 
00144         $collection = $ans[0];
00145 } 
00146 
00147 # construct sql query
00148 
00149 $sql_param = array ( 
00150         "tables" => "document,user,collection,state,doc_type,url_type,location,degree", 
00151          "cond" => "
00152         IF(user.use_alias,user.alias_degree_id,user.degree_id) = degree.id AND
00153         user.id = collection.user_id AND 
00154         collection.id = document.collection_id AND 
00155         state.id = document.state_id AND 
00156         document.doc_type_id = doc_type.id AND 
00157         document.url_type_id = url_type.id AND 
00158         location.id = collection.location_id",
00159          "columns" => "document.*,
00160         IF(user.use_alias,user.alias_forename,user.forename) AS forename, 
00161         IF(user.use_alias,user.alias_surname,user.surname) AS surname, 
00162         IF(user.use_alias,user.alias_sex,user.sex) AS sex, 
00163         degree.description AS degree_description,
00164         collection.title AS collection_title, 
00165         count(email.id) AS num_email, state.name AS state_name, 
00166         state.description AS state_description, 
00167         state.color AS state_color, 
00168         doc_type.name AS type, 
00169         url_type.description AS url_type_description, 
00170         location.description AS location_description",
00171          "order" => "document.@sort_crit@, document.title ASC, document.author ASC",
00172          "group_by" => "GROUP BY document.id",
00173          "join" => "LEFT JOIN email ON email.document_id = document.id"
00174 );
00175 
00176 if ($INPUT['id'] != "") {
00177         $sql_param['cond'] .= " AND document.collection_id = '@id@' "; 
00178 }
00179 if ($INPUT['state'] == "processing" ) {
00180         $sql_param['cond'] .= " AND document.state_id = state.id AND ( state.name = 'new' or state.name='obsolete' )  "; 
00181 } else if ($INPUT['state'] != "" ) {
00182         $sql_param['cond'] .= " AND document.state_id = state.id AND state.name = '@state@' "; 
00183 }
00184 
00185 if ($INPUT['type'] != "" ) {
00186         $sql_param['cond'] .= " AND document.doc_type_id = doc_type.id AND doc_type.name = '@type@' "; 
00187 }
00188 
00189 if (isset($INPUT['user_id'])) {
00190         $sql_param['cond'] .= " AND document.user_id = @user_id@ ";
00191 }
00192 
00193 foreach ($INPUT as $k => $v) {
00194         $kw = array( '@' . $k . '@' => $v);
00195         $sql_param['cond'] = strtr($sql_param['cond'], $kw);
00196         $sql_param['order'] = strtr($sql_param['order'], $kw);
00197 }
00198 
00199 # execute sql query
00200 
00201 $ans = sql_query('select', $sql_param, $db);
00202 
00203 # display results
00204 
00205 $tpl_vars = $INPUT;
00206 
00207 # how many files attached?
00208 
00209 foreach ($ans as $k => $v) {
00210         $ans[$k]['num_files'] = count( list_files( $v['type'], $v['id']) );
00211 }
00212 
00213 $tpl_vars['document_info']   = $ans;
00214 
00215 $tpl_vars['collection_info'] = $collection;
00216 
00217 
00218 
00219 $t = array ("doc_type", "state"); 
00220 
00221 $tpl_vars['html_options'] = get_html_options($t, $db, "name", 
00222                 "description", "id", array("" => "alles", "processing" => "offen") ); 
00223 
00224 $tpl_vars['html_options']['item'] = $tpl_vars['html_options']['doc_type'];
00225 
00226 unset($tpl_vars['html_options']['item'][""]);
00227 unset($tpl_vars['html_options']['item']['processing']);
00228 unset($tpl_vars['html_options']['doc_type']['processing']);
00229 
00230 
00231 $tpl_vars['html_options']['sort_crit'] = array (
00232         "relevance desc" => "Relevanz",
00233         "title asc" => "Titel",
00234         "author asc" => "Autor",
00235         "signature asc" => "Signatur",
00236 );
00237 
00238 
00239 $tpl_vars['actions_info'] = $actions_info;
00240 
00241 do_template($smarty, 'collection.tpl', $tpl_vars, ($INPUT['mode'] != 'print'));
00242 
00243 sql_exit($db);
00244 
00245 }
00246 
00247 show_collection(); 
00248 ?>

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