Example #1
0
File: Ad.php Project: gorvic/L17
 public static function handleGetQuery(array $sanitized_get_array)
 {
     // The result of the request
     $ajax_result = array('status' => '', 'message' => '', 'data' => '');
     $id = (int) $sanitized_get_array['id'];
     $mode = $sanitized_get_array['mode'];
     if ($mode == 'show') {
         $ad_fields = Ad::find_by_id($id)->getFieldsForTemplate();
         unset($ad_fields['db_fields']);
         $ajax_result['status'] = 'success';
         $ajax_result['data'] = $ad_fields;
     } elseif ($mode == 'delete') {
         $ad_title = Ad::find_by_id($id)->getTitle();
         $sanitized_ad_title = htmlentities($ad_title);
         Ad::delete($id);
         $ajax_result['status'] = 'success';
         if (Ad::count_all()) {
             $ajax_result['message'] = 'Ad "' . $sanitized_ad_title . '" has been deleted successfully';
         } else {
             $ajax_result['message'] = 'There is no more ads in database';
         }
     } else {
         $ajax_result['status'] = 'error';
         $ajax_result['message'] = 'Undefined mode';
     }
     return $ajax_result;
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     /*
      * Verifies access to the particular AD.
      */
     if (Yii::app()->user->checkAccess('AdCreate', $this->bizruleCreate())) {
         $model = new Ad();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Ad'])) {
             $model->attributes = $_POST['Ad'];
             if ($model->save()) {
                 $screenAdAssignment = new ScreenAdAssignment();
                 $screenAdAssignment->ad_id = $model->id;
                 $screenAdAssignment->screen_id = $this->_screen->id;
                 if ($screenAdAssignment->save()) {
                     Yii::app()->user->setFlash('success', YII::t('ad', 'Ad created successfully.'));
                     $this->redirect(array('screen/view', 'id' => $this->_screen->id));
                 } else {
                     Yii::app()->user->setFlash('error', YII::t('ad', 'Could not assign the Ad to the Screen.'));
                     $model->delete();
                 }
             }
         }
         $this->render('create', array('model' => $model));
     } else {
         throw new CHttpException(403, YII::t('default', 'You are not authorized to perform this action.'));
     }
 }
Example #3
0
function pageController()
{
    session_start();
    if (!Auth::check()) {
        header('Location: /auth/login');
        exit;
    }
    $username = Auth::user();
    $user = User::findUserByUsername($username);
    $adid = Input::get('id');
    $ad = Ad::find($adid);
    $item_name = $ad->attributes['item_name'];
    $price = $ad->attributes['price'];
    $description = $ad->attributes['description'];
    $image_path = $ad->attributes['image_path'];
    $contact = $ad->attributes['contact'];
    $errors = array();
    if (!empty($_POST)) {
        if (Input::notEmpty('item_name')) {
            $item_name = ValidateAd::getItemName();
        }
        if (Input::notEmpty('price')) {
            $price = ValidateAd::getPrice();
        }
        if (Input::notEmpty('description')) {
            $description = ValidateAd::getDescription();
        }
        if (Input::notEmpty('contact')) {
            $contact = ValidateAd::getContact();
        }
        $errors = ValidateAd::getErrors();
        if (empty($errors)) {
            $ad->attributes['item_name'] = $item_name;
            $ad->attributes['price'] = $price;
            $ad->attributes['description'] = $description;
            $ad->attributes['contact'] = $contact;
            $ad->attributes['image_path'] = $image_path;
            $ad->save();
        }
        if (!Input::notEmpty('delete-id')) {
            //if the form has been submitted
            Ad::delete($ad->attributes['id']);
            header("Location: /ads");
            die;
            //delete the specific ad - going to need to somehow tie in the ad id to the delete buttn for that specific id
        }
    }
    return array('ad' => $ad, 'username' => $username, 'item_name' => $item_name, 'price' => $price, 'description' => $description, 'image_path' => $image_path, 'contact' => $contact);
}
<?php

require_once '../bootstrap.php';
if (!Auth::check()) {
    header("Location: login.php");
    exit;
}
$ads = [];
$ads = Ad::all();
if (Input::has('id') && Input::get('id') >= 0) {
    $id = Input::get('id');
} else {
    $id = 0;
}
Ad::isOwner($ads[$id]['user_id']);
Ad::delete($id);
header("Refresh: 3;url=/profile");
?>

<html>
<head>
    <title>Instrument Exchange</title>
    <!-- Bootstrap styling -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!-- Custom styling for site -->
    <link rel="stylesheet" type="text/css" href="../css/main.css">
</head>
<body>
    <?// include "../views/partials/navbar.php"; ?>

 * Admin area
 * 
 * @copyright  Copyright (c) Szilard Szabo
 * @license    GPL v3
 * @package    Admin
 */
include "./include/common.php";
include "Pager/Pager.php";
if (!User::is_logged_in() || User::get_id() != 1) {
    header('Location: index.php');
    exit;
}
if (isset($_GET['d'])) {
    $d = (int) $_GET['d'];
    if ($d > 0) {
        Ad::delete($d);
    }
}
if (isset($_GET['o'])) {
    $o = (int) $_GET['o'];
    $r = (int) $_GET['r'];
    if ($r != 0) {
        $r = 1;
    }
    $a['sponsored'] = $r;
    $a['sponsoredon'] = $r = 0 ? '' : date('Y-m-d', time());
    Ad::update($o, $a);
}
$tct = Ad::count();
//total count
$rpp = 10;
<?php

/**
 * Classified-ads-script
 * 
 * @copyright  Copyright (c) Szilard Szabo
 * @license    GPL v3
 * @package    Frontend
 */
include "./admin/include/common.php";
if (!User::is_logged_in() || User::get_id() != 1) {
    header('Location: index.php');
    exit;
}
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$exists = User::exists(0, array('id' => $id));
if ($exists) {
    $user = User::get_one($id);
    UserBanned::create($user, $id);
    Ad::delete(0, array('user_id' => $id));
    User::delete($id);
}
include "./templates/user-ban.php";
Example #7
0
 /**
  * @before _secure
  * @after _cleanUp
  */
 public function campaign($id = null)
 {
     $view = $this->getActionView();
     $org = $this->_org;
     $active = RequestMethods::get('active', 1);
     $fields = ['_id', 'title', 'description', 'image', 'url', 'device', 'expiry', 'created'];
     $commFields = ['model', 'rate', 'revenue', 'coverage'];
     if ($id) {
         $campaign = Ad::first(['_id' => $id, 'org_id' => $org->_id], $fields);
     } else {
         $campaign = null;
     }
     if ($id && !$campaign) {
         return $this->failure('30');
     }
     $type = RequestMethods::type();
     switch ($type) {
         case 'GET':
             if (!$id) {
                 // display list of campaigns
                 $ads = Ad::all(['org_id' => $org->_id, 'live' => $active], $fields);
                 $ads = Ad::objectArr($ads, $fields);
                 $results = [];
                 foreach ($ads as $id => $a) {
                     $arr = Utils::toArray($a);
                     $comms = Commission::all(['ad_id' => $a->_id], $commFields);
                     $arr['commissions'] = Ad::objectArr($comms, $commFields);
                     $results[$id] = (object) $arr;
                 }
                 $data = ['campaigns' => $results];
                 $view->set('data', $data);
             } else {
                 $ads = Ad::objectArr($campaign, $fields);
                 $campaign = array_shift($ads);
                 $comm = Commission::all(['ad_id' => $campaign->_id], $commFields);
                 $data = ['campaign' => $campaign, 'commissions' => Commission::objectArr($comm, $commFields)];
                 $view->set('data', $data);
             }
             break;
         case 'POST':
             if ($id) {
                 // edit a particular campaign
             } else {
                 // create a new campaign
                 $fields = ['title', 'description', 'url', 'expiry', 'category', 'device', 'user_id'];
                 $img = RequestMethods::post('image');
                 // contains image url
                 $campaign = new Ad(['org_id' => $org->_id, 'type' => 'article', 'image' => Utils::media($img, 'download')]);
                 foreach ($fields as $f) {
                     $campaign->{$f} = RequestMethods::post($f);
                 }
                 $view->set('success', false);
                 $visibility = RequestMethods::post('visibility', 'public');
                 if ($visibility === 'private') {
                     $campaign->getMeta()['private'] = true;
                 }
                 $opts = ['devices' => array_keys(Shared\Markup::devices()), 'advertisers' => $org->users('advertiser', false)];
                 if (true) {
                     // $campaign->save();
                     $arr = ArrayMethods::reArray($_POST['commissions']);
                     var_dump($arr);
                     var_dump($_POST['commissions']);
                     $view->set('success', true);
                 } else {
                     $data = ['errors' => $campaign->errors];
                     $view->set('data', $data);
                 }
             }
             break;
         case 'DELETE':
             $message = $campaign->delete();
             $view->set($message);
             break;
     }
 }
Example #8
0
} else {
    header("Location: welcome.php");
    exit;
}
if (Input::has('logout') && $_GET['logout'] == 'true') {
    Auth::logoutUser();
    header("Location: welcome.php");
    exit;
}
if (empty($_GET['page'])) {
    $page = '1';
} else {
    $page = $_GET['page'];
}
if (!empty($_GET['delete'])) {
    Ad::delete($_GET['id']);
}
$user = $_SESSION['email'];
$userPosts = Ad::paginateUserAds(5, ($page - 1) * 5, $user);
?>
<html>
<head>
    <title>Home</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

    <link rel="stylesheet" href="../css/sidebar.css">
    <link rel="stylesheet" href="../css/custom.css"> 

    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
</head>
Example #9
0
require 'connect_to_db.php';
require_once __DIR__ . "/firephp/FirePHP.class.php";
$firePHP = FirePHP::getInstance(true);
$firePHP->setEnabled(true);
require 'HtmlOption.php';
require 'functions_DbSimple.php';
require 'Ad.php';
require 'AdStorage.php';
require 'AdCompany.php';
require 'AdPrivate.php';
$db->setErrorHandler('databaseErrorHandler');
$db->setLogger('myLogger');
if (!empty($_GET['action']) && $_GET['action'] === 'delete') {
    $ad = new Ad();
    $ad->setId($_GET['id']);
    echo $ad->delete($db);
    die;
}
$smarty_dir = __DIR__ . '/smarty/';
require_once $smarty_dir . 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->compile_check = true;
$smarty->debugging = true;
$smarty->template_dir = $smarty_dir . 'templates/';
$smarty->compile_dir = $smarty_dir . 'templates_c/';
$smarty->config_dir = $smarty_dir . 'configs/';
$smarty->cache_dir = $smarty_dir . 'cache/';
if (!empty($_POST)) {
    $id = !empty($_POST['id']) ? $_POST['id'] : null;
    if ($_POST['type'] === 'private') {
        $ad = new AdPrivate($_POST);
<?php

/**
 * Classified-ads-script
 * 
 * @copyright  Copyright (c) Szilard Szabo
 * @license    GPL v3
 * @package    Frontend
 */
include "./admin/include/common.php";
include "./admin/include/thumb.php";
$panels = array();
$g_id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$g_code = isset($_GET['code']) ? trim(strip_tags($_GET['code'])) : '';
$exists = Ad::exists($g_id, array("code" => $g_code, "active" => 1));
if ($exists) {
    Ad::delete($g_id, array("code" => $g_code));
}
include "./templates/ad-removal.php";