/** * Mark advertisement as active : STATUS = 1 */ public function action_activate() { $user = Auth::instance()->get_user(); $id = $this->request->param('id'); if (isset($id)) { $active_ad = new Model_Ad($id); if ($active_ad->loaded()) { $activate = FALSE; //admin whatever he wants if ($user->is_admin()) { $activate = TRUE; } elseif ($user->id_user == $active_ad->id_user and !in_array(core::config('general.moderation'), Model_Ad::$moderation_status)) { $activate = TRUE; } else { Alert::set(Alert::ALERT, __("This is not your advertisement.")); } //its not published if ($active_ad->status == Model_Ad::STATUS_PUBLISHED) { $activate = FALSE; Alert::set(Alert::ALERT, __("Advertisement is already marked as 'active'")); } //expired but cannot reactivate option if (Core::config('advertisement.expire_reactivation') == FALSE and core::config('advertisement.expire_date') > 0 and Date::formatted_time($active_ad->published . '+' . core::config('advertisement.expire_date') . ' days') < Date::formatted_time()) { $activate = FALSE; Alert::set(Alert::ALERT, __("Advertisement can not be marked as “active”. It's expired.")); } //pending payment if ($activate === TRUE and ($order = $active_ad->get_order()) !== FALSE and $order->status == Model_Order::STATUS_CREATED) { $activate = FALSE; Alert::set(Alert::ALERT, __("Advertisement can not be marked as “active”. There is a pending payment.")); } //activate the ad if ($activate === TRUE) { $active_ad->published = Date::unix2mysql(time()); $active_ad->status = Model_Ad::STATUS_PUBLISHED; try { $active_ad->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } else { HTTP::redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))); } } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } } // send confirmation email $cat = new Model_Category($active_ad->id_category); $usr = new Model_User($active_ad->id_user); if ($usr->loaded()) { //we get the QL, and force the regen of token for security $url_ql = $usr->ql('ad', array('category' => $cat->seoname, 'seotitle' => $active_ad->seotitle), TRUE); $ret = $usr->email('ads-activated', array('[USER.OWNER]' => $usr->name, '[URL.QL]' => $url_ql, '[AD.NAME]' => $active_ad->title)); } Alert::set(Alert::SUCCESS, __('Advertisement is active and published')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))); }