Initial commit
[2ch-be.git] / dev-test / bak / messaging / reply.php
blob64df04af1f9965618a98758fbdf5f346aa3428aa
1 <?php
2 session_start();
3 $sub = strip_tags(addslashes(trim($_POST['zxcvbnm'])));
4 $msg = strip_tags(addslashes(trim($_POST['msg'])));
6 if (strlen($msg) > 250) {
7 $echo = "Content too long";
8 exit;
11 $from = substr($sub, 0, 9);
12 $to = substr($sub, 9, 9);
13 $file = substr($sub, 18);
14 //echo $from."-".$to."-".$file;
15 //exit;
17 include('../encrypt.php');
19 $reply = new Message;
20 $msg = $reply->BeSanitize($msg);
21 $reply_receiver = $reply->FindUser($to,$id_mail_path);
23 $fdir = substr($reply_receiver, 0, 1);
24 $sdir = substr($reply_receiver, 1, 1);
25 $udir = str_replace("@", "-", $reply_receiver);
26 $file_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/{$file}.dat";
27 $ufile_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}/u_{$file}.dat";
28 $tmp_copy_path = MDB_PATH."{$fdir}/{$sdir}/{$udir}";
30 //echo $file_path;
31 //exit;
33 $sender_path = $reply->FindUser($from,$id_mail_path);
34 $fdir2 = substr($sender_path, 0, 1);
35 $sdir2 = substr($sender_path, 1, 1);
36 $udir2 = str_replace("@", "-", $sender_path);
37 $sender_file_path = MDB_PATH."{$fdir2}/{$sdir2}/{$udir2}/{$file}.dat";
38 $usender_file_path = MDB_PATH."{$fdir2}/{$sdir2}/{$udir2}/u_{$file}.dat";
39 $time = time();
40 $writeData = "<id>{$time}</id><from>{$from}</from><subj></subj><msg>{$msg}</msg>\n";
42 echo $file_path."<br>";
43 echo $sender_file_path;
44 if (!file_exists($file_path)) {
45 if (file_exists($sender_file_path)) {
46 if (!file_exists($tmp_copy_path)) {
47 @mkdir(MDB_PATH."{$fdir}");
48 @mkdir(MDB_PATH."{$fdir}/{$sdir}");
49 @mkdir(MDB_PATH."{$fdir}/{$sdir}/{$udir}");
51 $aa = file($sender_file_path);
52 $aa = implode("\n", $aa);
53 file_put_contents($file_path, $aa);
54 $handle = fopen($sender_file_path, "a+");
55 if(!fwrite($handle, $writeData)) {
56 echo "Error 1!";
57 exit;
59 fclose($handle);
60 } else {
61 echo "Error 2!";
63 if (trim($sender_file_path) <> trim($file_path)) {
64 $handle = fopen($file_path, "a+");
65 //var_dump($file_path);
66 //exit;
67 if(!fwrite($handle, $writeData)) {
68 echo "Error 3!";
69 exit;
71 fclose($handle);
73 // echo "Success!";
74 rename($file_path, $ufile_path);
75 if (trim($sender_file_path) <> trim($file_path)) {
76 rename($sender_file_path, $usender_file_path);
78 $_SESSION['msg'] = "Message succesfully sent";
79 header('Location: ../inbox.php');
81 } else {
82 //if (trim($sender_file_path) <> trim($file_path)) {
83 $handle = fopen($sender_file_path, "a+");
84 if(!fwrite($handle, $writeData)) {
85 echo "Error 4";
86 exit;
88 fclose($handle);
89 //}
90 if (trim($sender_file_path) <> trim($file_path)) {
91 $handle = fopen($file_path, "a+");
92 if(!fwrite($handle, $writeData)) {
93 echo "Error 5";
94 exit;
96 fclose($handle);
98 rename($file_path, $ufile_path);
99 if (trim($sender_file_path) <> trim($file_path)) {
100 rename($sender_file_path, $usender_file_path);
102 $_SESSION['msg'] = "Message succesfully sent";
103 header('Location: ../inbox.php');