Go to the source code of this file.
Functions | |
| cmp_coll ($a, $b) | |
| callback function for usort() | |
| show_index () | |
Definition in file index.php.
| show_index | ( | ) |
Definition at line 82 of file index.php.
References $actions_info, $validation_info, check_input(), do_template(), expire(), smarty_init(), sql_exit(), sql_init(), and sql_query().
00082 { 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 }
Here is the call graph for this function:

1.4.7