public function action_message() { Controller::$full_width = TRUE; if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) { $messages = Model_Message::get_thread($id_msg_thread, $this->user->id_user); if ($messages !== FALSE) { $msg_thread = new Model_Message(); $msg_thread = $msg_thread->where('id_message', '=', $this->request->param('id'))->find(); // send reply message if ($this->request->post() and Form::token('reply_message', TRUE)) { $validation = Validation::factory($this->request->post())->rule('message', 'not_empty'); if ($validation->check()) { $ret = Model_Message::reply(core::post('message'), $this->user->id_user, $id_msg_thread, NULL); if ($ret !== FALSE) { //who is who? if from is the same then send to TO, else to from if ($msg_thread->id_user_from == $this->user->id_user) { $user_to = $msg_thread->to; $user_from = $msg_thread->from; } else { $user_to = $msg_thread->from; $user_from = $msg_thread->to; } //email title if ($msg_thread->id_ad !== NULL) { $email_title = $msg_thread->ad->title; } else { $email_title = sprintf(__('Direct message from %s'), $user_from->name); } $user_to->email('messaging-reply', array('[TITLE]' => $email_title, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user_to->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $this->request->param('id'))))); Alert::set(Alert::SUCCESS, __('Reply created.')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id')))); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { $errors = $validation->errors('message'); } } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')))); if ($msg_thread->id_ad !== NULL) { Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title)); } else { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message'))); } $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/messages.js'); $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user)); } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } }
public function action_message() { Controller::$full_width = TRUE; if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) { $messages = Model_Message::get_thread($id_msg_thread, $this->user); if ($messages !== FALSE) { $msg_thread = new Model_Message(); $msg_thread = $msg_thread->where('id_message', '=', $id_msg_thread)->where('id_message_parent', '=', $id_msg_thread)->find(); // send reply message if ($this->request->post() and Form::token('reply_message', TRUE)) { $validation = Validation::factory($this->request->post())->rule('message', 'not_empty'); if ($validation->check()) { $ret = Model_Message::reply(core::post('message'), $this->user, $id_msg_thread, NULL); if ($ret !== FALSE) { Alert::set(Alert::SUCCESS, __('Reply created.')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id')))); } else { Alert::set(Alert::ERROR, __('Message not sent')); } } else { $errors = $validation->errors('message'); } } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')))); if ($msg_thread->id_ad !== NULL) { Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title)); } else { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message'))); } $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.css' => 'screen'); $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.js', 'js/messages.js'); $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user)); } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } } else { Alert::set(Alert::ERROR, __('Message not found')); $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))); } }
public function action_stats() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('My ads'))->set_url(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index')))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Stats'))); Controller::$full_width = TRUE; $this->template->scripts['footer'] = array('js/chart.min.js', 'js/chart.js-php.js', 'js/oc-panel/stats/dashboard.js'); $this->template->title = __('Stats'); $this->template->bind('content', $content); $content = View::factory('oc-panel/profile/stats'); $list_ad = array(); $advert = new Model_Ad(); //single stats for 1 ad if (is_numeric($id_ad = $this->request->param('id'))) { $advert = new Model_Ad($id_ad); if ($advert->loaded()) { //if admin or moderator user is the advert user ;) hack!! if ($this->user->id_role == Model_Role::ROLE_ADMIN or $this->user->id_role == Model_Role::ROLE_MODERATOR) { $user = $advert->user; } else { $user = $this->user; } if ($user->id_user !== $advert->id_user) { Alert::set(Alert::ALERT, __("This is not your advertisement.")); HTTP::redirect(Route::url('oc-panel', array('controller' => 'myads', 'action' => 'index'))); } Breadcrumbs::add(Breadcrumb::factory()->set_title($advert->title)); // make a list of 1 ad (array), and than pass this array to query (IN).. To get correct visits $list_ad[] = $id_ad; } } //we didnt filter by ad, so lets get them all! if (empty($list_ad)) { $ads = new Model_Ad(); $collection_of_user_ads = $ads->where('id_user', '=', $this->user->id_user)->find_all(); $list_ad = array(); foreach ($collection_of_user_ads as $key) { // make a list of ads (array), and than pass this array to query (IN).. To get correct visits $list_ad[] = $key->id_ad; } } // if user doesn't have any ads if (empty($list_ad)) { $list_ad = array(NULL); } $content->advert = $advert; //Getting the dates and range $from_date = Core::post('from_date', strtotime('-1 month')); $to_date = Core::post('to_date', time()); //we assure is a proper time stamp if not we transform it if (is_string($from_date) === TRUE) { $from_date = strtotime($from_date); } if (is_string($to_date) === TRUE) { $to_date = strtotime($to_date); } //mysql formated dates $my_from_date = Date::unix2mysql($from_date); $my_to_date = Date::unix2mysql($to_date); //dates range we are filtering $dates = Date::range($from_date, $to_date, '+1 day', 'Y-m-d', array('date' => 0, 'count' => 0), 'date'); //dates displayed in the form $content->from_date = date('Y-m-d', $from_date); $content->to_date = date('Y-m-d', $to_date); /////////////////////CONTACT STATS//////////////////////////////// //visits created last XX days $query = DB::select(DB::expr('DATE(created) date'))->select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where('created', 'between', array($my_from_date, $my_to_date))->group_by(DB::expr('DATE( created )'))->order_by('date', 'asc')->execute(); $contacts_dates = $query->as_array('date'); //Today $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', DB::expr('CURDATE()'))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $contacts = $query->as_array(); $content->contacts_today = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; //Yesterday $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', date('Y-m-d', strtotime('-1 day')))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $contacts = $query->as_array(); $content->contacts_yesterday = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; // //Last 30 days contacts $query = DB::select(DB::expr('COUNT(contacted) count'))->from('visits')->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->where('created', 'between', array(date('Y-m-d', strtotime('-30 day')), date::unix2mysql()))->execute(); $contacts = $query->as_array(); $content->contacts_month = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; //total contacts $query = DB::select(DB::expr('COUNT(contacted) count'))->where('contacted', '=', 1)->where('id_ad', 'in', $list_ad)->from('visits')->execute(); $contacts = $query->as_array(); $content->contacts_total = isset($contacts[0]['count']) ? $contacts[0]['count'] : 0; /////////////////////VISITS STATS//////////////////////////////// //visits created last XX days $query = DB::select(DB::expr('DATE(created) date'))->select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where('created', 'between', array($my_from_date, $my_to_date))->group_by(DB::expr('DATE( created )'))->order_by('date', 'asc')->execute(); $visits = $query->as_array('date'); $stats_daily = array(); foreach ($dates as $date) { $count_contants = isset($contacts_dates[$date['date']]['count']) ? $contacts_dates[$date['date']]['count'] : 0; $count_visits = isset($visits[$date['date']]['count']) ? $visits[$date['date']]['count'] : 0; $stats_daily[] = array('date' => $date['date'], 'views' => $count_visits, 'contacts' => $count_contants); } $content->stats_daily = $stats_daily; //Today $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', DB::expr('CURDATE()'))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $visits = $query->as_array(); $content->visits_today = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //Yesterday $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where(DB::expr('DATE( created )'), '=', date('Y-m-d', strtotime('-1 day')))->group_by(DB::expr('DATE( created )'))->order_by('created', 'asc')->execute(); $visits = $query->as_array(); $content->visits_yesterday = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //Last 30 days visits $query = DB::select(DB::expr('COUNT(id_visit) count'))->from('visits')->where('id_ad', 'in', $list_ad)->where('created', 'between', array(date('Y-m-d', strtotime('-30 day')), date::unix2mysql()))->execute(); $visits = $query->as_array(); $content->visits_month = isset($visits[0]['count']) ? $visits[0]['count'] : 0; //total visits $query = DB::select(DB::expr('COUNT(id_visit) count'))->where('id_ad', 'in', $list_ad)->from('visits')->execute(); $visits = $query->as_array(); $content->visits_total = isset($visits[0]['count']) ? $visits[0]['count'] : 0; }
public function action_favorites() { $user = Auth::instance()->get_user(); //favs or unfavs if (is_numeric($id_ad = $this->request->param('id'))) { $this->auto_render = FALSE; $this->template = View::factory('js'); $ad = new Model_Ad($id_ad); //ad exists if ($ad->loaded()) { //if fav exists we delete if (Model_Favorite::unfavorite($user->id_user, $id_ad) === TRUE) { //fav existed deleting $this->template->content = __('Deleted'); } else { //create the fav Model_Favorite::favorite($user->id_user, $id_ad); $this->template->content = __('Saved'); } } else { $this->template->content = __('Ad Not Found'); } } else { $this->template->title = __('My Favorites'); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->styles = array('//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/favorite.js'; $favorites = new Model_Favorite(); $favorites = $favorites->where('id_user', '=', $user->id_user)->order_by('created', 'desc')->find_all(); $this->template->bind('content', $content); $this->template->content = View::factory('oc-panel/profile/favorites', array('favorites' => $favorites)); } }
/** * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control * @return [type] [description] */ public function action_checkout() { $order = new Model_Order($this->request->param('id')); if ($order->loaded()) { //if paid...no way jose if ($order->status != Model_Order::STATUS_CREATED) { Alert::set(Alert::INFO, __('This order was already paid.')); $this->redirect(Route::url('default')); } //checks coupons or amount of featured days $order->check_pricing(); //template header $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/checkout', array('order' => $order)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }
/** * * NEW ADVERTISEMENT * */ public function action_index() { //Detect early spam users, show him alert if (core::config('general.black_list') == TRUE and Model_User::is_spam(Core::post('email')) === TRUE) { Alert::set(Alert::ALERT, __('Your profile has been disable for posting, due to recent spam content! If you think this is a mistake please contact us.')); $this->redirect('default'); } //advertisement.only_admin_post if (Core::config('advertisement.only_admin_post') == 1 and (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role != Model_Role::ROLE_ADMIN)) { $this->redirect('default'); } if (Core::post('ajaxValidateCaptcha')) { $this->auto_render = FALSE; $this->template = View::factory('js'); if (captcha::check('publish_new', TRUE)) { $this->template->content = 'true'; } else { $this->template->content = 'false'; } return; } Controller::$full_width = TRUE; //template header $this->template->title = __('Publish new advertisement'); $this->template->meta_description = __('Publish new advertisement'); $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen', '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen'); $this->template->scripts['footer'][] = 'js/jquery.sceditor.bbcode.min.js'; $this->template->scripts['footer'][] = 'js/jasny-bootstrap.min.js'; $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.min.js'; $this->template->scripts['footer'][] = '//cdnjs.cloudflare.com/ajax/libs/ouibounce/0.0.10/ouibounce.min.js'; $this->template->scripts['footer'][] = 'js/canvasResize.js'; if (core::config('advertisement.map_pub_new')) { $this->template->scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7'; $this->template->scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js'; } $this->template->scripts['footer'][] = 'js/new.js?v=' . Core::VERSION; // redirect to login, if conditions are met if (core::config('advertisement.login_to_post') == TRUE and !Auth::instance()->logged_in()) { Alert::set(Alert::INFO, __('Please, login before posting advertisement!')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login'))); } $categories = new Model_Category(); $categories = $categories->where('id_category_parent', '=', '1'); // NO categories redirect ADMIN to categories panel if ($categories->count_all() == 0) { if (Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role == Model_Role::ROLE_ADMIN) { Alert::set(Alert::INFO, __('Please, first create some categories.')); $this->redirect(Route::url('oc-panel', array('controller' => 'category', 'action' => 'index'))); } else { Alert::set(Alert::INFO, __('Posting advertisements is not yet available.')); $this->redirect('default'); } } //get locations $locations = new Model_Location(); $locations = $locations->where('id_location', '!=', '1'); // bool values from DB, to show or hide this fields in view $form_show = array('captcha' => core::config('advertisement.captcha'), 'website' => core::config('advertisement.website'), 'phone' => core::config('advertisement.phone'), 'location' => core::config('advertisement.location'), 'description' => core::config('advertisement.description'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price')); $id_category = NULL; $selected_category = new Model_Category(); //if theres a category by post or by get if (Core::request('category') !== NULL) { if (is_numeric(Core::request('category'))) { $selected_category->where('id_category', '=', core::request('category'))->limit(1)->find(); } else { $selected_category->where('seoname', '=', core::request('category'))->limit(1)->find(); } if ($selected_category->loaded()) { $id_category = $selected_category->id_category; } } $id_location = NULL; $selected_location = new Model_Location(); //if theres a location by post or by get if (Core::request('location') !== NULL) { if (is_numeric(Core::request('location'))) { $selected_location->where('id_location', '=', core::request('location'))->limit(1)->find(); } else { $selected_location->where('seoname', '=', core::request('location'))->limit(1)->find(); } if ($selected_location->loaded()) { $id_location = $selected_location->id_location; } } //render view publish new $this->template->content = View::factory('pages/ad/new', array('form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all())); if ($this->request->post()) { if (captcha::check('publish_new')) { $data = $this->request->post(); $validation = Validation::factory($data); //validate location since its optional if (core::config('advertisement.location')) { if ($locations->count_all() > 1) { $validation = $validation->rule('location', 'not_empty')->rule('location', 'digit'); } } //user is not logged in validate input if (!Auth::instance()->logged_in()) { $validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145)); } // Optional banned words validation if (core::config('advertisement.validate_banned_words')) { $validation = $validation->rule('title', 'no_banned_words'); $validation = $validation->rule('description', 'no_banned_words'); } if ($validation->check()) { // User detection, if doesnt exists create if (!Auth::instance()->logged_in()) { $user = Model_User::create_email(core::post('email'), core::post('name')); } else { $user = Auth::instance()->get_user(); } //to make it backward compatible with older themes: UGLY!! if (isset($data['category']) and is_numeric($data['category'])) { $data['id_category'] = $data['category']; unset($data['category']); } if (isset($data['location']) and is_numeric($data['location'])) { $data['id_location'] = $data['location']; unset($data['location']); } //lets create!! $return = Model_Ad::new_ad($data, $user); //there was an error on the validation if (isset($return['validation_errors']) and is_array($return['validation_errors'])) { foreach ($return['validation_errors'] as $f => $err) { Alert::set(Alert::ALERT, $err); } } elseif (isset($return['error'])) { Alert::set($return['error_type'], $return['error']); } elseif (isset($return['message']) and isset($return['ad'])) { $new_ad = $return['ad']; // IMAGE UPLOAD $filename = NULL; for ($i = 0; $i < core::config('advertisement.num_images'); $i++) { if (Core::post('base64_image' . $i)) { $filename = $new_ad->save_base64_image(Core::post('base64_image' . $i)); } elseif (isset($_FILES['image' . $i])) { $filename = $new_ad->save_image($_FILES['image' . $i]); } } Alert::set(Alert::SUCCESS, $return['message']); //redirect user if (isset($return['checkout_url']) and !empty($return['checkout_url'])) { $this->redirect($return['checkout_url']); } else { $this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad))); } } } else { $errors = $validation->errors('ad'); foreach ($errors as $f => $err) { Alert::set(Alert::ALERT, $err); } } } else { Alert::set(Alert::ALERT, __('Captcha is not correct')); } } }
/** * pay an invoice, renders the paymenthods button, anyone with an ID of an order can pay it, we do not have control * @return [type] [description] */ public function action_checkout() { $order = new Model_Order($this->request->param('id')); if ($order->loaded()) { //if paid...no way jose if ($order->status != Model_Order::STATUS_CREATED) { Alert::set(Alert::INFO, __('This order was already paid.')); $this->redirect(Route::url('default')); } //update order based on the price and the amount of $days = core::get('featured_days'); if (is_numeric($days) and ($price = Model_Order::get_featured_price($days)) !== FALSE) { $order->amount = $price; //get price from config $order->featured_days = $days; $order->save(); } //template header $this->template->title = __('Checkout') . ' ' . Model_Order::product_desc($order->id_product); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); Controller::$full_width = TRUE; $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/checkout', array('order' => $order)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }