public function handleForm($context, $action) { if ($action == "createAd") { if (isset($_POST['start']) && $_POST['start'] != "" && (isset($_POST['size']) && $_POST['size'] != "") && (isset($_POST['name']) && $_POST['name'] != "") && (isset($_POST['url']) && $_POST['url'] != "")) { $start = $_POST['start']; $dayOfWeek = date("D", strtotime($start)); if ($dayOfWeek == "Mon") { $splitStart = explode("/", $start); $mysqlStart = $splitStart[2] . "-" . $splitStart[0] . "-" . $splitStart[1]; if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { $filename = $this->saveSampleImage($context, $_FILES['image'], SessionUtil::getUsername()); if ($filename != "") { WebAdDao::createWebAd($_POST['name'], $mysqlStart, $_POST['size'], $filename, $_POST['url']); } else { $context->addError("Error Uploading File, Please Try Again."); } } else { $context->addError("No File Uploaded."); } } else { $context->addError("Starting Date Not a Monday."); } } else { $context->addError("Required Field Left Blank."); } } else { $context->addError("Incorrect Action."); } }
public function generateHTML() { $ads = WebAdDao::getAdsByDay($this->startingMonday); $adsHtml = ""; foreach ($ads as $ad) { $adsHtml = $adsHtml . $ad->generateTRHTML(); } return "<br />" . $this->context->getErrorHTML() . "<div class=\"centered\" style=\"width: 65%\">\n\t\t" . $this->generateMondaySelectForm() . "\n\t\t<table style=\"margin-left: auto; margin-right: auto;\" border=\"0\">\n\t\t\n\t\t\t<tr><th>Name</th><th>Starting Monday</th><th>Size</th><th>Impressions</th><th>Clicks</th><th>-</th></tr>\n\t\t\t" . $adsHtml . "\n\t\t\n\t\t</table>\n\t\t\n\t\t</div>"; }
public static function getAdsByDay($date) { $query = "SELECT * FROM " . Database::addPrefix('webads') . " WHERE StartingMonday = '" . DateUtil::findPreviousMonday($date) . "'"; $result = Database::doQuery($query); $webads = array(); while ($row = mysql_fetch_assoc($result)) { $webads[] = WebAdDao::makeAd($row); } return $webads; }
public function handleForm($context, $action) { if ($action == "deleteAd") { if (isset($_POST['adId'])) { WebAdDao::deleteAdById($_POST['adId']); } else { $context->addError("Required Field Left Blank."); } } else { $context->addError("Incorrect Action."); } }
<?php require_once './config.php'; require_once './lib/DB/Database.php'; require_once './lib/DB/WebAd.php'; require_once './lib/DB/WebAdDao.php'; require_once './lib/DB/WebAdView.php'; require_once './lib/DB/WebAdViewDao.php'; require_once './lib/Util/DateUtil.php'; require_once './lib/Util/SimpleImage.php'; require_once './lib/Util/SessionUtil.php'; Database::Open(); SessionUtil::start(); if (isset($_GET['size'])) { $view = WebAdViewDao::getView($_SERVER['REMOTE_ADDR'], $_GET['site'], $_GET['size']); if ($view) { $webad = WebAdDao::getWebAdByID($view->webadID); } else { $webad = WebAd::getDefaultAd($_GET['size'], null); } if ($webad) { WebAdDao::incrementClicks($webad); header("Location: " . $webad->getRedirectUrl()); } else { header("Location: " . WebAd::getDefaultAd($_GET['size'])->getRedirectUrl()); } } Database::Close();
<?php require_once './config.php'; require_once './lib/DB/Database.php'; require_once './lib/DB/WebAd.php'; require_once './lib/DB/WebAdDao.php'; require_once './lib/DB/WebAdViewDao.php'; require_once './lib/Util/DateUtil.php'; require_once './lib/Util/SimpleImage.php'; require_once './lib/Util/SessionUtil.php'; Database::Open(); SessionUtil::start(); if (isset($_GET['size'])) { $webad = WebAdDao::getRandomAdBySizeAndDate($_GET['size'], Database::CurrentMySQLDate(), true); if (!$webad) { //SessionUtil::setLastViewed($_GET['size'], 0); WebAdViewDao::setView($_SERVER['REMOTE_ADDR'], gethostbyaddr($_SERVER['REMOTE_ADDR']), $_GET['site'], $_GET['size'], 0); $image = new SimpleImage(); $image->load('./images/notfound.png'); header('Content-Type: image/jpeg'); echo $image->output(); Database::Close(); exit; } else { WebAdViewDao::setView($_SERVER['REMOTE_ADDR'], gethostbyaddr($_SERVER['REMOTE_ADDR']), $_GET['site'], $_GET['size'], $webad->getID()); //SessionUtil::setLastViewed($_GET['size'], $webad->getID()); $image_info = getimagesize($webad->getImage()); $image_type = $image_info[2]; if ($image_type == IMAGETYPE_JPEG) { header('Content-Type: image/jpeg'); } elseif ($image_type == IMAGETYPE_GIF) {