protected function OnInput() { parent::OnInput(); $this->title = 'Заявка'; $this->id = $_GET['id']; $this->user = $_SESSION['uid']; makeopen($this->user, $this->id); $this->claiminfo = getClaimInfo($this->id); if (isset($_POST['submit']) && isClosed($this->id)) { closeThisClaim($this->id); } if (isset($_POST['submit']) && ($_SESSION['role'] == '2' || $_SESSION['role'] == '5')) { $comment = $_POST['comment']; $str = $_POST['manager']; $n = strlen($str); if ($n >= 4) { $manager = substr($str, 3, $n - 1); } else { $m = getManagerFromSection($_POST['manager']); $manager = $m->id; } if ($comment != '') { addcomment($this->user, $this->id, $manager, $comment); } makestate($_SESSION['uid'], $this->id); sendtouser($manager, $this->id, $this->user); } if (isset($_POST['submit']) && $_SESSION['role'] == '3') { $comment = $_POST['comment']; $user = $_POST['user']; if ($comment != '') { addcomment($this->user, $this->id, $user, $comment); } makestate($_SESSION['uid'], $this->id); sendtouser($user, $this->id, $this->user); } if (isset($_POST['submit']) && $_SESSION['role'] == '4') { move_uploaded_file($_FILES["filename"]['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/dt/uploads/act/" . $_FILES["filename"]["name"]); makestate($_SESSION['uid'], $this->id); closeClaim($this->id, $_SESSION['uid'], $_FILES['filename']['name']); if ($comment != '') { addcomment($this->user, $this->id, $user, $comment); } } }
<?php switch ($_GET['req']) { case '1': addcomment(); break; case '2': fetchcomments(); break; case '3': deletecomments(); break; } function addcomment() { $name = ucwords(trim(strip_tags($_GET['name']))); $comment = trim(strip_tags($_GET['comment'])); $data = json_decode(file_get_contents('../files/comments.json', true)); $i = count($data); $data[$i]['name'] = $name; $data[$i]['comment'] = $comment; $data[$i]['moment'] = time(); file_put_contents('../files/comments.json', json_encode($data)); print json_encode("Comment posted!"); } function fetchcomments() { $data = file_get_contents('../files/comments.json'); print $data; } function deletecomments()