public function go() { $this->setViewTemplate('addchallenge.tpl'); if (isset($_GET['type']) && $_GET['type'] == "code") { $add_type = "code"; } else { $add_type = "challenge"; } if (isset($_POST['continue'])) { if ($_POST['title'] == '') { $this->addErrorMessage("Title of the challenge should not be empty"); } elseif ($_POST['description'] == '') { $this->addErrorMessage("Description should not be empty"); } elseif ($_POST['authors'] == '') { $this->addErrorMessage("Authors field should not be empty"); } elseif ($_POST['category'] == '') { $this->addErrorMessage("Category field should not be empty"); } else { $array = array('title' => $_POST['title'], 'description' => $_POST['description'], 'authors' => $_POST['authors'], 'category' => $_POST['category']); $_SESSION['challenge_arr'] = $array; $this->addSuccessMessage("Now Please upload the challenge code"); $this->addToView('step', 'step2'); } } if (isset($_FILES['fupload'])) { $filename = $_FILES['fupload']['name']; $source = $_FILES['fupload']['tmp_name']; $type = $_FILES['fupload']['type']; $name = explode('.', $filename); $target = HACKADEMIC_PATH . "challenges/" . $name[0] . '/'; if (!isset($name[1])) { $this->addErrorMessage("Please select a file"); return $this->generateView(); } if (isset($name[0])) { $challenge = ChallengeBackend::doesChallengeExist($name[0]); if ($challenge == true) { if (isset($_SESSION['challenge_arr'])) { $this->addToView('step', 'step2'); } else { $this->addToView('type', $add_type); } $this->addErrorMessage("This file already exists!!"); return $this->generateView(); } } $okay = strtolower($name[1]) == 'zip' ? true : false; if (!$okay) { if (isset($_SESSION['challenge_arr'])) { $this->addToView('step', 'step2'); } else { $this->addToView('type', $add_type); } $this->addErrorMessage("Please choose a zip file!"); return $this->generateView(); } mkdir($target); $saved_file_location = $target . $filename; if (move_uploaded_file($source, $target . $filename)) { $data = $this->installChallenge($saved_file_location, $target, $name[0]); if ($data == true) { $pkg_name = $name[0]; $date_posted = date("Y-m-d H-i-s"); ChallengeBackend::addchallenge($data['title'], $pkg_name, $data['description'], $data['author'], $data['category'], $date_posted); header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/challengemanager.php?action=add"); } } } $this->addToView('type', $add_type); return $this->generateView(); }