7a7cfc76e98eb6204e9a4b338b1436382996c86e
[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 //OMG remove constant
99 if ($node['node_id']==MAIL_NODE) {
100
101 //clear new mail message
102 if ($new_mail) {
103 //set messages as delivered
104 $db->query("update users set user_mail=0 where user_id='$user_id'");
105 $db->query("update mail set mail_read='yes' where mail_to='$user_id' and mail_read='no'");
106 }
107
108 }
109 }
110
111
112
113 if ($node['node_system_access']=='crypto') {
114 $smarty->assign('crypto_pass',$_SESSION['crypto'][$node['node_id']]);
115 }
116
117 $smarty->assign('error',$error);
118 $smarty->assign('permissions',$permissions);
119 $smarty->assign('current_vector',$node['node_vector']);
120 if ($permissions['r']) {
121 $smarty->assign('node',$node);
122 $smarty->assign('node_json',json_encode($node));
123 }
124 else {
125 $smarty->assign('node',$node);
126 //new templates by Dark matter
127 $smarty->template_dir=OWN_TEMPLATE_DIR;
128
129 $smarty->display('1549864.tpl');
130 $smarty->display('1549885.tpl');
131 $smarty->display('630526.tpl');
132 die();
133
134 //redirect to mainpage
135 // looks like poeple totaly hate this redirect!
136 // header("Location: /id/1");
137 }
138
139
140 // XXX into function
141 if (isset($_SESSION['user_id'])){
142 //setting user location
143 $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']."'";
144 $db->query($q);
145 }
146
147 $whole_time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
148 $smarty->assign('whole_time',$whole_time);
149
150
151 if ($template_id=='data') {
152 if ($permissions['r']) {
153 $linkname = FILE_DIR."/".$node['node_id'];
154 $filename= readlink($linkname);
155 $suffix=preg_replace("/(.*?)\.(.*?)/i","$2",$filename);
156
157 $ext = substr( $filename,-3 );
158 if( $filename == "" ) {
159 echo "ERROR: Empty file to download. ";
160 exit;
161 } elseif ( ! file_exists( $filename ) ) {
162 exit;
163 };
164 switch( strtolower($ext) ){
165 case "pdf": $ctype="application/pdf"; break;
166 case "exe": $ctype="application/octet-stream"; break;
167 case "zip": $ctype="application/zip"; break;
168 case "doc": $ctype="application/msword"; break;
169 case "xls": $ctype="application/vnd.ms-excel"; break;
170 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
171 case "gif": $ctype="image/gif"; break;
172 case "png": $ctype="image/png"; break;
173 case "jpg": $ctype="image/jpg"; break;
174 default: $ctype="application/force-download";
175 }
176 $file=str_replace(" ","_",$node['node_name']).".$ext";
177 header("Pragma: public");
178 header("Expires: 0");
179 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
180 header("Content-Type: $ctype");
181 $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
182 if ((is_integer (strpos($user_agent, "msie"))) && (is_integer
183 (strpos($user_agent, "win")))) {
184 header( "Content-Disposition: filename=$file;" );
185 } else {
186 header( "Content-Disposition: attachment;
187 filename=$file;" );
188 }
189 header("Content-Transfer-Encoding: binary");
190 header("Content-Length: ".filesize($filename));
191 readfile("$filename");
192 exit();
193 }
194 else {
195 echo "you don't have permissions for downloading this data";
196 die();
197 }
198 }
199
200
201
202 //for cases like search & preview
203 $smarty->assign('post_vars',$_POST);
204 if (!empty($_POST['template_event'])) {
205 $smarty->assign('template_event',$_POST['template_event']);
206
207 }
208
209 //setting listing parameters
210 $children_count=$node['node_children_count'];
211 $descendant_count=$node['node_descendant_count'];
212
213 if (isset($_POST['listing_amount']) && is_numeric($_POST['listing_amount'])) {
214 $listing_amount=db_escape_string($_POST['listing_amount']);
215 }elseif (!empty($_SESSION['listing_amount'])) $listing_amount=$_SESSION['listing_amount'];
216 else $listing_amount=DEFAULT_LISTING_AMOUNT;
217 $smarty->assign('listing_amount',$listing_amount);
218
219 if (isset($_POST['listing_order']) && $_POST['listing_order']) {
220 $listing_order=db_escape_string($_POST['listing_order']);
221 } elseif (!empty($_SESSION['listing_order'])) $listing_order=$_SESSION['listing_order'];
222 else $listing_order=DEFAULT_LISTING_ORDER;
223 $smarty->assign('listing_order',$listing_order);
224
225 if (isset ($_POST['get_children_offset']) && is_numeric($_POST['get_children_offset'])) {
226 $offset=$_POST['get_children_offset'];
227 } else { $offset=0; }
228
229
230 //movement forward and backward
231 // if ($listing_order=='asc' && !$offset) $offset=$descendant_count-$listing_amount;
232
233 if (isset($_POST['get_children_move'])) {
234 if ($_POST['get_children_move']=='<') {
235 $offset=$offset-$listing_amount;
236 if ($offset<0) $offset=0;
237 }
238 elseif ($_POST['get_children_move']=='>') {
239 $offset=$offset+$listing_amount;
240 }
241 elseif ($_POST['get_children_move']=='>>') {
242 $offset=$descendant_count-$listing_amount;
243 }
244
245 elseif ($_POST['get_children_move']=='<<') {
246 $offset=0;
247 }
248 }
249 if ($offset<0) $offset=0;
250 $_POST['offset']=$offset; // XXX sqli?
251 $smarty->assign('offset',$offset);
252
253 if ($node['external_link']=='header://svg' && !is_numeric($template_id)) {
254 header("Content-Type: image/svg+xml");
255 }
256
257 //show own header
258 elseif (isset($_SESSION['header_id']) && ($_SESSION['header_id']==true)) {
259 $smarty->assign('header_id',$_SESSION['header_id']);
260 $smarty->template_dir=OWN_TEMPLATE_DIR;
261 $content=$smarty->fetch($_SESSION['header_id'].".tpl");
262 $smarty->template_dir = TEMPLATE_DIR.TEMPLATE_SET;
263 //not registered user
264 if ($_SESSION['header_id']==2091520) {
265 echo $content;
266 session_destroy();
267 die();
268 }
269 }
270
271 $smarty->template_dir=OWN_TEMPLATE_DIR;
272
273 if (is_numeric($template_id)) {
274 $content.=$smarty->fetch($template_id.".tpl");
275 }
276
277 else {
278 $template_id=$node['template_id'];
279 $content.=$smarty->fetch($node['template_id'].".tpl");
280 }
281
282 // XXX remove constant
283 if ($template_id=='2019721'){
284 $content=$smarty->fetch($template_id.".tpl");
285 echo $content;
286 }else{
287 $time=SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
288 echo $content;
289 // echo "<center>page generation took: $time second</center>";
290 }
291 //end of displaying
292
293 return true;
294 }
This page took 0.365871 seconds and 3 git commands to generate.