<?php

/**
 * Open Source Social Network
 *
 * @package   Open Source Social Network
 * @author    Open Social Website Core Team <*****@*****.**>
 * @copyright 2014 iNFORMATIKON TECHNOLOGIES
 * @license   General Public Licence http://www.opensource-socialnetwork.org/licence
 * @link      http://www.opensource-socialnetwork.org/licence
 */
$delete = new OssnAds();
$entites = $_REQUEST['entites'];
foreach ($entites as $entity) {
    $entity = get_ad_entity((int) $entity);
    if (empty($entity->guid)) {
        ossn_trigger_message(ossn_print('ad:delete:fail'), 'error');
    } else {
        if (!$delete->deleteAd($entity->guid)) {
            ossn_trigger_message(ossn_print('ad:delete:fail'), 'error');
        } else {
            ossn_trigger_message(ossn_print('ad:deleted', array($entity->title)), 'success');
        }
    }
}
redirect(REF);
 /**
  * Edit
  * 
  * @param (array) $params Contain title , description and guid of ad
  *
  * @return bool;
  */
 public function EditAd($params)
 {
     self::initAttributes();
     if (!empty($params['guid']) && !empty($params['title']) && !empty($params['description']) && !empty($params['siteurl'])) {
         $entity = get_ad_entity($params['guid']);
         $fields = array('title', 'description');
         $data = array($params['title'], $params['description']);
         $this->data->site_url = $params['siteurl'];
         if ($this->updateObject($fields, $data, $entity->guid)) {
             if (isset($_FILES['ossn_ads']) && $_FILES['ossn_ads']['size'] !== 0) {
                 $path = $entity->getParam('file:ossnads');
                 $replace_file = ossn_get_userdata("object/{$entity->guid}/{$path}");
                 if (!empty($path)) {
                     $regen_image = ossn_resize_image($_FILES['ossn_ads']['tmp_name'], 2048, 2048);
                     file_put_contents($replace_file, $regen_image);
                 }
             }
             return true;
         }
     }
     return false;
 }