private function onAdd() { $form = $this->getForm(); if (false !== ($errors = $form->validate($this->module))) { return $errors . $this->templateAdd(); } if (false === ($file = $this->getFile())) { $this->uploadedFile($form); $file = $form->getVar('file'); } $tempname = $file['tmp_name']; if (!file_exists($tempname)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd(); } $mod = $this->module->isModerated($this->module); $userid = GWF_Session::getUserID(); $options = 0; $options |= isset($_POST['adult']) ? GWF_Download::ADULT : 0; $options |= isset($_POST['huname']) ? GWF_Download::HIDE_UNAME : 0; $options |= isset($_POST['guest_view']) ? GWF_Download::GUEST_VISIBLE : 0; $options |= isset($_POST['guest_down']) ? GWF_Download::GUEST_DOWNLOAD : 0; $options |= $mod ? 0 : GWF_Download::ENABLED; $dl = new GWF_Download(array('dl_id' => 0, 'dl_uid' => $userid, 'dl_gid' => $form->getVar('group'), 'dl_level' => $form->getVar('level'), 'dl_token' => GWF_Download::generateToken(), 'dl_count' => 0, 'dl_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'dl_filename' => $form->getVar('filename'), 'dl_realname' => $file['name'], 'dl_descr' => $form->getVar('descr'), 'dl_mime' => GWF_Upload::getMimeType($file['tmp_name']), 'dl_price' => sprintf('%.02f', $form->getVar('price', 0.0)), 'dl_options' => $options, 'dl_voteid' => 0, 'dl_purchases' => 0, 'dl_expire' => GWF_TimeConvert::humanToSeconds($form->getVar('expire')))); if (false === $dl->insert()) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd(); } $dlid = $dl->getID(); $filename = 'dbimg/dl/' . $dlid; if (false === GWF_Upload::moveTo($file, $filename)) { return GWF_HTML::err('ERR_WRITE_FILE', array($filename)) . $this->templateAdd(); } if (false === @unlink($tempname)) { return GWF_HTML::err('ERR_WRITE_FILE', array($tempname)) . $this->templateAdd(); } if (false === $dl->createVotes($this->module)) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)) . $this->templateAdd(); } $this->clearFile(); if ($mod) { $this->sendModMail($dl); return $this->module->message('msg_uploaded_mod'); } return $this->module->message('msg_uploaded'); }