finalising upload_data_file
[mirrors/Kyberia-bloodline.git] / wwwroot / inc / eventz / display.inc
1 <?php
2 function display() {
3 global $node,$db,$error,$referer_id,$smarty,$permissions,$template_id;
4 global $timer_start;
5 if (!$referer_id) $referer_id=1;
6 $content='';
7
8 $node_id=$node['node_id'];
9 $user_id=(empty($_SESSION['user_id'])) ? "" : $_SESSION['user_id'];
10
11 if ($permissions['r']) {
12
13 // these 4 lines are not the source of kyberia lagging problems.
14 // leave them. started on the 10.4.
15 // data gained will be used for scientific purposes
16
17 // if (isset($_SESSION['user_id']) {
18 // log_levenshtein($_SESSION['user_id'],$node['node_id']);
19 // }
20
21 if ((isset($_SESSION['user_id'])) && ($_SESSION['user_id'])) {
22 $q="insert delayed into levenshtein set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."'";
23 $db->update($q);
24 }
25
26 //if node is css
27 //XXX into function
28 if ($node['template_id']!='2019721'){
29
30 logger::log('enter',$node['node_id'],'ok',$node['node_user_subchild_count']);
31 if (!empty($_SESSION['user_id']) && is_numeric($node['node_id'])) {
32 $q="update node_access set visits=visits+1,node_user_subchild_count='0',last_visit=NOW() where node_id='".$node['node_id']."' and user_id='".$_SESSION['user_id']."'";
33 // echo $q;
34 $result=$db->update($q);
35
36 if (!$result) {
37 $q="insert into node_access set user_id='".$_SESSION['user_id']."',node_id='".$node['node_id']."',last_visit=NOW()";
38 $db->query($q);
39 }
40 }//end of if node os css
41 }
42
43 }
44
45 //XXX into function
46 // if (isset($_SESSION['user_id']) {
47 // if (isset($referer_id)) {
48 // update_nodes($_SESSION['user_id'],$node['node_id'],$referer_id);
49 // } else {
50 // update_nodes($_SESSION['user_id'],$node['node_id'],0);
51 // }
52 // }
53
54
55 //assigning user data to smarty if user logged in
56 if (isset($_SESSION['user_id'])&&($user_id=$_SESSION['user_id'])) {
57 $smarty->assign('_POST',$_POST);
58 $smarty->assign('bookmarks',$_SESSION['bookmarks']);
59 if (isset($_SESSION['ignore'])) { $smarty->assign('ignore',$_SESSION['ignore']); };
60 $smarty->assign('bookstyl',$_SESSION['bookstyl']);
61 if (isset($_SESSION['fook'])) {$smarty->assign('fook',$_SESSION['fook']); };
62 $smarty->assign('user_id',$_SESSION['user_id']);
63 $smarty->assign('user_name',$_SESSION['user_name']);
64 if (!empty($_SESSION['cube_vector']))
65 $smarty->assign('cube_vector',$_SESSION['cube_vector']);
66 $smarty->assign('friends',$_SESSION['friends']); //req by freezy, done by darkaural
67 if (isset($_SESSION['user_quota'])) {$smarty->assign('user_quota',$_SESSION['user_quota']);};
68
69 // XXX into function
70 $newmail_q = sprintf('select u.user_mail_id
71 , u.user_k
72 , u.k_wallet
73 , u.user_mail
74 , ms.user_id as mail_sender_id
75 , ms.login as mail_sender
76 from users u
77 left join users ms on ms.user_id = u.user_mail_id
78 where u.user_id = %d',
79 $user_id);
80 $newmailset = $db->query($newmail_q);
81
82
83 $newmailset->next();
84 $new_mail=$newmailset->getString('user_mail');
85 // XXX into function
86 $newmailset2 = $db->query("select users.user_mail_id,mailsender.login
87 from users left join users as mailsender on users.user_mail_id = mailsender.user_id where users.user_id = '$user_id'");
88 $newmailset2->next();
89 $smarty->assign('new_mail',$new_mail);
90 $smarty->assign('new_mail_name',$newmailset->getString('mail_sender'));
91 $smarty->assign('new_mail_name2',$newmailset2->getString('login'));
92 $user_k=$newmailset->getString('user_k');
93 $smarty->assign('user_k',$user_k);
94 $k_wallet=$newmailset->getString('k_wallet');
95 $smarty->assign('k_wallet',$k_wallet);
96 $user_id=$_SESSION['user_id'];
97
98 //mail node
99 if ($node['node_name']=='mail') {
100
101 //clear new mail message
102
103 if ($new_mail) $db->query("update users set user_mail=0 where user_id='$user_id'");
104
105 //set messages as delivered to recipient
106 $set=$db->query("select mail_id,mail_duplicate_id from mail where mail_user='$user_id' and mail_to='$user_id' and mail_read='no'");
107 while($set->next()) {
108 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_duplicate_id')."'");
109 $db->query("update mail set mail_read='yes' where mail_id='".$set->getString('mail_id')."'");
110
111 $new_messages[$set->getString('mail_id')]=true;
112 }
113 /*
114 if (count($new_messages)) {
115 $db->query("update mail set mail_read='yes' where mail_user='$user_id' and mail_user=mail_to and mail_read='no'");
116 $smarty->assign('new_messages',$new_messages);
117
118 }
119 */
120 }
121 }
122
123
124
125 if ($node['node_system_access']=='crypto') {
126 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
127 }
128
129 $smarty->assign('error',$error);
130 $smarty->assign('permissions',$permissions);
131 $smarty->assign('current_vector',$node['node_vector']);
132 if ($permissions['r']) {
133 $smarty->assign('node',$node);
134 $smarty->assign('node_json',json_encode($node));
135 }
136 else {
137 $smarty->assign('node',$node);
138 //new templates by Dark matter
139 $smarty->template_dir=OWN_TEMPLATE_DIR;
140
141 $smarty->display('1549864.tpl');
142 $smarty->display('1549885.tpl');
143 $smarty->display('630526.tpl');
144 die();
145
146 //redirect to mainpage
147 // looks like poeple totaly hate this redirect!
148 // header("Location: /id/1");
149 }
150
151
152 // XXX into function
153 if (isset($_SESSION['user_id'])){
154 //setting user location
155 $q="update users set last_action=NOW(),user_location_vector='".$node['node_vector']."',user_action='".addslashes($node['node_name'])."',user_action_id='".$node['node_id']."' where user_id='".$_SESSION['user_id']."'";
156 $db->query($q);
157 }
158
159 $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
160 $smarty->assign('whole_time',$whole_time);
161
162
163 if ($template_id=='data') {
164 if ($permissions['r']) {
165 $linkname = FILE_DIR."/".$node['node_id'];
166 $filename= readlink($linkname);
167 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
168
169 $ext = substr( $filename,-3 );
170 if( $filename == "" ) {
171 echo "ERROR: Empty file to download. ";
172 exit;
173 } elseif ( ! file_exists( $filename ) ) {
174 exit;
175 };
176 switch( strtolower($ext) ){
177 case "pdf": $ctype="application/pdf"; break;
178 case "exe": $ctype="application/octet-stream"; break;
179 case "zip": $ctype="application/zip"; break;
180 case "doc": $ctype="application/msword"; break;
181 case "xls": $ctype="application/vnd.ms-excel"; break;
182 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
183 case "gif": $ctype="image/gif"; break;
184 case "png": $ctype="image/png"; break;
185 case "jpg": $ctype="image/jpg"; break;
186 default: $ctype="application/force-download";
187 }
188 $file=str_replace(" ","_",$node['node_name']).".$ext";
189 header("Pragma: public");
190 header("Expires: 0");
191 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
192 header("Content-Type: $ctype");
193 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
194 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
195 (strpos($user_agent, "win")))) {
196 header( "Content-Disposition: filename=$file;" );
197 } else {
198 header( "Content-Disposition: attachment;
199 filename=$file;" );
200 }
201 header("Content-Transfer-Encoding: binary");
202 header("Content-Length: ".filesize($filename));
203 readfile("$filename");
204 exit();
205 }
206 else {
207 echo "you don't have permissions for downloading this data";
208 die();
209 }
210 }
211
212
213
214 //for cases like search & preview
215 $smarty->assign('post_vars',$_POST);
216 if (!empty($_POST['template_event'])) {
217 $smarty->assign('template_event',$_POST['template_event']);
218
219 }
220
221 //setting listing parameters
222 $children_count=$node['node_children_count'];
223 $descendant_count=$node['node_descendant_count'];
224
225 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
226 $listing_amount=db_escape_string($_POST['listing_amount']);
227 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
228 else $listing_amount=DEFAULT_LISTING_AMOUNT;
229 $smarty->assign('listing_amount',$listing_amount);
230
231 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
232 $listing_order=db_escape_string($_POST['listing_order']);
233 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
234 else $listing_order=DEFAULT_LISTING_ORDER;
235 $smarty->assign('listing_order',$listing_order);
236
237 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
238 $offset=$_POST['get_children_offset'];
239 } else { $offset=0; }
240
241
242 //movement forward and backward
243 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
244
245 if (isset($_POST['get_children_move'])) {
246 if ($_POST['get_children_move']=='<') {
247 $offset=$offset-$listing_amount;
248 if ($offset<0) $offset=0;
249 }
250 elseif ($_POST['get_children_move']=='>') {
251 $offset=$offset+$listing_amount;
252 }
253 elseif ($_POST['get_children_move']=='>>') {
254 $offset=$descendant_count-$listing_amount;
255 }
256
257 elseif ($_POST['get_children_move']=='<<') {
258 $offset=0;
259 }
260 }
261 if ($offset<0) $offset=0;
262 $_POST['offset']=$offset; // XXX sqli?
263 $smarty->assign('offset',$offset);
264
265 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
266 header("Content-Type: image/svg+xml");
267 }
268
269 //show own header
270 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
271 $smarty->assign('header_id',$_SESSION['header_id']);
272 $smarty->template_dir=OWN_TEMPLATE_DIR;
273 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
274 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
275 //not registered user
276 if ($_SESSION['header_id']==2091520) {
277 echo $content;
278 session_destroy();
279 die();
280 }
281 }
282
283 $smarty->template_dir=OWN_TEMPLATE_DIR;
284
285 if (is_numeric($template_id)) {
286 $content.=$smarty->fetch($template_id.".tpl");
287 }
288
289 else {
290 $template_id=$node['template_id'];
291 $content.=$smarty->fetch($node['template_id'].".tpl");
292 }
293
294 // XXX remove constant
295 if ($template_id=='2019721'){
296 $content=$smarty->fetch($template_id.".tpl");
297 echo $content;
298 }else{
299 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
300 echo $content;
301 // echo "<center>page generation took: $time second</center>";
302 }
303 //end of displaying
304
305 return true;
306 }
This page took 0.362054 seconds and 4 git commands to generate.