/** * Action MODERATION */ public function action_moderate() { //template header $this->template->title = __('Moderation'); $this->template->meta_description = __('Moderation'); $this->template->scripts['footer'][] = '/js/oc-panel/moderation.js'; //find all tables $ads = new Model_Ad(); $res_count = $ads->where('status', '=', Model_Ad::STATUS_NOPUBLISHED)->count_all(); if ($res_count > 0) { $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action())); $ads = $ads->where('ad.status', '=', Model_Ad::STATUS_NOPUBLISHED)->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); //find all tables $hits = new Model_Visit(); $hits->find_all(); $list_cat = Model_Category::get_all(); $list_loc = Model_Location::get_all(); $arr_hits = array(); // array of hit integers // fill array with hit integers foreach ($ads as $key_ads) { // match hits with ad $h = $hits->where('id_ad', '=', $key_ads->id_ad); $count = count($h->find_all()); // count individual hits array_push($arr_hits, $count); } $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => $ads, 'pagination' => $pagination, 'category' => $list_cat, 'location' => $list_loc, 'hits' => $arr_hits)); // create view, and insert list with data } else { Alert::set(Alert::INFO, __('You do not have any advertisements waiting to be published')); $this->template->content = View::factory('oc-panel/pages/moderate', array('ads' => NULL)); } }
/** * overwrites the default crud index * @param string $view nothing since we don't use it * @return void */ public function action_index($view = NULL) { //template header $this->template->title = __('Locations'); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Locations'))); $this->template->styles = array('css/sortable.css' => 'screen'); $this->template->scripts['footer'][] = 'js/jquery-sortable-min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/locations.js'; list($locs, $order) = Model_Location::get_all(); $this->template->content = View::factory('oc-panel/pages/locations', array('locs' => $locs, 'order' => $order)); }
/** * * NEW ADVERTISEMENT * */ public function action_index() { if (isset($_SESSION['_wb_app_x'])) { } else { //template header $this->template->title = __('Publish new advertisement'); $this->template->meta_description = __('Publish new advertisement'); $this->template->scripts['footer'] = array('js/new.js'); //find all, for populating form select fields list($categories, $order_categories) = Model_Category::get_all(); list($locations, $order_locations) = Model_Location::get_all(); // 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'), 'address' => core::config('advertisement.address'), 'price' => core::config('advertisement.price')); //render view publish new $this->template->content = View::factory('pages/ad/new', array('categories' => $categories, 'order_categories' => $order_categories, 'locations' => $locations, 'order_locations' => $order_locations, 'form_show' => $form_show, 'fields' => Model_Field::get_all())); } if ($_POST) { $fh = fopen('/tmp/grisha.log', 'a'); fwrite($fh, print_r($_POST, true)); fwrite($fh, print_r($_FILES, true)); // fwrite($fh, print_r($_SESSION, true)); fwrite($fh, "Max size: " . core::config('image.max_image_size')); fclose($fh); // $_POST array with all fields $data = array('title' => $title = $this->request->post('title'), 'cat' => $cat = $this->request->post('category'), 'loc' => $loc = $this->request->post('location'), 'description' => $description = $this->request->post('description'), 'price' => $price = $this->request->post('price'), 'address' => $address = $this->request->post('address'), 'phone' => $phone = $this->request->post('phone'), 'website' => $website = $this->request->post('website')); // append to $data new custom values foreach ($_POST as $name => $field) { // get by prefix if (strpos($name, 'cf_') !== false) { $data[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $data[$name] = 1; } if (empty($field)) { $data[$name] = NULL; } } } // depending on user flow (moderation mode), change usecase $moderation = core::config('general.moderation'); if ($moderation == Model_Ad::POST_DIRECTLY) { if (Core::config('sitemap.on_post') == TRUE) { Sitemap::generate(); } $status = Model_Ad::STATUS_PUBLISHED; $this->save_new_ad($data, $status, $published = TRUE, $moderation, $form_show['captcha']); } elseif ($moderation == Model_Ad::MODERATION_ON || $moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::EMAIL_CONFIRMATION || $moderation == Model_Ad::EMAIL_MODERATION || $moderation == Model_Ad::PAYMENT_MODERATION) { $status = Model_Ad::STATUS_NOPUBLISHED; $this->save_new_ad($data, $status, $published = FALSE, $moderation, $form_show['captcha']); } } }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { // get all categories if ($this->categories != FALSE) { // loaded category list($categories, $order_categories) = Model_Category::get_all(); $arr_cat = array(); foreach ($categories as $cat => $value) { if ($value['id'] != 1) { $arr_cat[$value['id']] = $value['name']; } } $this->cat_items = $categories; $this->cat_order_items = $order_categories; } // get all locations if ($this->locations != FALSE) { list($locations, $order_locations) = Model_Location::get_all(); $this->loc_items = $locations; $this->loc_order_items = $order_locations; } if ($this->price != FALSE) { $this->price = TRUE; } // user if (Auth::instance()->logged_in()) { //subscriber // check if user is already subscribed $user_id = Auth::instance()->get_user()->id_user; $obj_subscriber = new Model_Subscribe(); $subscriber = $obj_subscriber->where('id_user', '=', $user_id)->limit(1)->find(); if ($subscriber->loaded()) { $this->subscriber = TRUE; } //if user logged in pass email and id $this->user_email = Auth::instance()->get_user()->email; $this->user_id = $user_id; } else { $this->user_id = 0; } //min - max price selected $this->min_price = $this->min_price; $this->max_price = $this->max_price; }
/** * Automatically executed before the widget action. Can be used to set * class properties, do authorization checks, and execute other custom code. * * @return void */ public function before() { // get all categories if ($this->advanced != FALSE) { // loaded category list($categories, $order_categories) = Model_Category::get_all(); $arr_cat = array(); foreach ($categories as $cat => $value) { if ($value['id'] != 1) { $arr_cat[$value['id']] = $value['name']; } } $this->cat_items = $categories; $this->cat_order_items = $order_categories; // get all locations list($locations, $order_locations) = Model_Location::get_all(); $this->loc_items = $locations; $this->loc_order_items = $order_locations; } if ($this->custom != FALSE) { $fields = Model_Field::get_all(); $this->custom_fields = $fields; } }
public function action_advanced_search() { //template header $this->template->title = __('Advanced Search'); $this->template->meta_description = __('Advanced Search'); //breadcrumbs Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $this->template->scripts['footer'] = array('js/search.js'); // $cat_obj = new Model_Category(); // $loc_obj = new Model_Location(); list($cat_obj, $order_categories) = Model_Category::get_all(); list($loc_obj, $order_locations) = Model_Location::get_all(); $pagination = NULL; $ads = NULL; $user = Auth::instance()->get_user() == NULL ? NULL : Auth::instance()->get_user(); if ($this->request->query()) { // variables $search_advert = core::get('title'); $search_loc = core::get('location'); // filter by each variable $ads = new Model_Ad(); //if ad have passed expiration time dont show if (core::config('advertisement.expire_date') > 0) { $ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', DB::expr('NOW()')); } if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) { // if user is using search from header if (core::get('search')) { $search_advert = core::get('search'); } $ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close(); } $cf_fields = array(); foreach ($this->request->query() as $name => $field) { // get by prefix if (strpos($name, 'cf_') !== false) { $cf_fields[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $cf_fields[$name] = 1; } elseif (empty($field)) { $cf_fields[$name] = NULL; } } } $category = NULL; //filter by category if (core::get('category') !== NULL) { $category = new Model_Category(); $category->where('seoname', '=', core::get('category'))->limit(1)->find(); if ($category->loaded()) { $ads->where('id_category', 'IN', $category->get_siblings_ids()); } } $location = NULL; //filter by location if (core::get('location') !== NULL) { $location = new Model_location(); $location->where('seoname', '=', core::get('location'))->limit(1)->find(); if ($location->loaded()) { $ads->where('id_location', 'IN', $location->get_siblings_ids()); } } //filter by price if (is_numeric(core::get('price-min')) and is_numeric(core::get('price-max'))) { $ads->where('price', 'BETWEEN', array(core::get('price-min'), core::get('price-max'))); } foreach ($cf_fields as $key => $value) { if (isset($value) and $value != NULL) { if (is_numeric($value)) { $ads->where($key, '=', $value); } elseif (is_string($value)) { $ads->where($key, 'like', '%' . $value . '%'); } } } $ads = $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED); // count them for pagination $res_count = $ads->count_all(); if ($res_count > 0) { // pagination module $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $res_count, 'items_per_page' => core::config('general.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action(), 'category' => $category !== NULL ? $category->seoname : NULL)); Breadcrumbs::add(Breadcrumb::factory()->set_title(__("Page ") . $pagination->offset)); $ads = $ads->order_by('published', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); } } $this->template->bind('content', $content); $this->template->content = View::factory('pages/ad/advanced_search', array('ads' => $ads, 'categories' => $cat_obj, 'order_categories' => $order_categories, 'locations' => $loc_obj, 'order_locations' => $order_locations, 'pagination' => $pagination, 'user' => $user, 'fields' => Model_Field::get_all())); }
/** * Edit advertisement: Update * * All post fields are validated */ public function action_update() { //template header $this->template->title = __('Edit advertisement'); $this->template->meta_description = __('Edit advertisement'); //local files if (Theme::get('cdn_files') == FALSE) { $this->template->styles = array('css/datepicker.css' => 'screen'); $this->template->scripts['footer'] = array('js/bootstrap-datepicker.js', 'js/jquery.validate.min.js', 'js/oc-panel/edit_ad.js'); } else { $this->template->styles = array('http://cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen'); $this->template->scripts['footer'] = array('http://cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/jquery.validate.min.js', 'js/oc-panel/edit_ad.js'); } Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); $form = new Model_Ad($this->request->param('id')); //find all, for populating form select fields list($categories, $order_categories) = Model_Category::get_all(); list($locations, $order_locations) = Model_Location::get_all(); if (Auth::instance()->logged_in() && Auth::instance()->get_user()->id_user == $form->id_user || Auth::instance()->logged_in() && Auth::instance()->get_user()->id_role == 10) { $extra_payment = core::config('payment'); Breadcrumbs::add(Breadcrumb::factory()->set_title("Update")); $this->template->content = View::factory('oc-panel/profile/edit_ad', array('ad' => $form, 'locations' => $locations, 'order_locations' => $order_locations, 'categories' => $categories, 'order_categories' => $order_categories, 'extra_payment' => $extra_payment, 'fields' => Model_Field::get_all())); if ($this->request->post()) { $cat = new Model_Category(); $loc = new Model_Location(); // deleting single image by path $deleted_image = core::post('img_delete'); if ($deleted_image) { $img_path = $form->gen_img_path($form->id_ad, $form->created); if (!is_dir($img_path)) { return FALSE; } else { //delete formated image unlink($img_path . $deleted_image . '.jpg'); //delete original image $orig_img = str_replace('thumb_', '', $deleted_image); unlink($img_path . $orig_img . ".jpg"); $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $form->id_ad))); } } // end of img delete $data = array('_auth' => $auth = Auth::instance(), 'title' => $title = Model_Ad::banned_words(core::post('title')), 'seotitle' => $seotitle = core::post('title'), 'loc' => $loc = core::post('location'), 'description' => $description = Model_Ad::banned_words(core::post('description')), 'price' => $price = floatval(str_replace(',', '.', core::post('price'))), 'address' => $address = core::post('address'), 'website' => $website = core::post('website'), 'phone' => $phone = core::post('phone'), 'has_images' => 0, 'user' => $user = new Model_User()); // append to $data new custom values foreach ($_POST as $name => $field) { // get by prefix if (strpos($name, 'cf_') !== false) { $data[$name] = $field; //checkbox when selected return string 'on' as a value if ($field == 'on') { $data[$name] = 1; } } } //insert data if (core::post('title') != $form->title) { if ($form->has_images == 1) { $current_path = $form->gen_img_path($form->id_ad, $form->created); // rename current image path to match new seoname rename($current_path, $form->gen_img_path($form->id_ad, $form->created)); } $seotitle = $form->gen_seo_title($data['title']); $form->seotitle = $seotitle; } else { $form->seotitle = $form->seotitle; } $form->title = $data['title']; $form->id_location = $data['loc']; //$form->id_category = $data['cat']; $form->description = $data['description']; // $form->status = $data['status']; $form->price = $data['price']; $form->address = $data['address']; $form->website = $data['website']; $form->phone = $data['phone']; // set custom values foreach ($data as $key => $value) { // get only custom values with prefix if (strpos($key, 'cf_') !== false) { $form->{$key} = $value; } } // d($data['cf_radio']); $obj_ad = new Model_Ad(); // IMAGE UPLOAD // in case something wrong happens user is redirected to edit advert. $filename = NULL; $counter = 0; for ($i = 0; $i < core::config("advertisement.num_images"); $i++) { $counter++; if (isset($_FILES['image' . $i])) { $img_files = $_FILES['image' . $i]; $filename = $obj_ad->save_image($img_files, $form->id_ad, $form->created, $form->seotitle, $counter); } if ($filename) { $form->has_images = 1; try { $form->save(); } catch (Exception $e) { throw new HTTP_Exception_500($e->getMessage()); } } if ($filename = FALSE) { $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $form->id_ad))); } } try { // if user changes category, do payment first // moderation 2 -> payment on, moderation 5 -> payment with moderation // data['cat'] -> category selected , last_known_ad->id_category -> obj of current ad (before save) $moderation = core::config('general.moderation'); $last_known_ad = $obj_ad->where('id_ad', '=', $this->request->param('id'))->limit(1)->find(); if ($moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::PAYMENT_MODERATION) { // PAYMENT METHOD ACTIVE $payment_order = new Model_Order(); $advert_have_order = $payment_order->where('id_ad', '=', $this->request->param('id')); if ($data['cat'] == $last_known_ad->id_category) { // check if he payed when ad was created (is successful), // if not give him alert that he didn't payed, and ad will not be published until he do $cat_check = $cat->where('id_category', '=', $last_known_ad->id_category)->limit(1)->find(); // current category $advert_have_order->and_where('description', '=', $cat_check->seoname)->limit(1)->find(); if ($advert_have_order->loaded()) { if ($advert_have_order->status != Model_Order::STATUS_PAID) { // order is not payed, $form->status = 0; Alert::set(Alert::INFO, __('Advertisement is updated, but it won\'t be published until payment is done.')); } else { if ($moderation == Model_Ad::PAYMENT_ON) { $form->status = 1; Alert::set(Alert::SUCCESS, __('Advertisement is updated!')); } else { if ($moderation == 5) { Alert::set(Alert::SUCCESS, __('Advertisement is updated!')); } } } } $form->save(); $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $form->id_ad))); } else { // user have pending order with new category(possible that he previously tried to do the same action) $cat_check = $cat->where('id_category', '=', $data['cat'])->limit(1)->find(); // newly selected category $advert_have_order->and_where('description', '=', $cat_check->seoname)->limit(1)->find(); if ($advert_have_order->loaded()) { // sanity check -> we don't want to charge him twice for same category if ($advert_have_order->status != Model_Order::STATUS_PAID) { $this->request->redirect(Route::url('default', array('controller' => 'payment_paypal', 'action' => 'form', 'id' => $advert_have_order->id_order))); } else { if ($moderation == Model_Ad::PAYMENT_ON) { $form->status = 1; Alert::set(Alert::SUCCESS, __('Advertisement is updated!')); } else { if ($moderation == Model_Ad::PAYMENT_MODERATION) { Alert::set(Alert::SUCCESS, __('Advertisement is updated!')); } } } $form->save(); } else { $order_id = $payment_order->make_new_order($data, Auth::instance()->get_user()->id_user, $form->seotitle); if ($order_id == NULL) { if ($moderation == Model_Ad::PAYMENT_ON) { // publish $form->status = 1; } } else { // redirect to payment $this->request->redirect(Route::url('default', array('controller' => 'payment_paypal', 'action' => 'form', 'id' => $order_id))); // @TODO - check route } $form->save(); } } } // save ad $form->status = $last_known_ad->status; $form->save(); Alert::set(Alert::SUCCESS, __('Advertisement is updated')); $this->request->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $form->id_ad))); } catch (Exception $e) { //throw 500 throw new HTTP_Exception_500($e->getMessage()); } } } else { Alert::set(Alert::ERROR, __('You dont have permission to access this link')); $this->request->redirect(Route::url('default')); } // QR!!! $qr = new Qr($this->request->param('id')); $qr->reset(); $f = $qr->qr(); $qr->calendar(); // $qr->map(); $qr->website(); $qr->contact(); Alert::set(Alert::SUCCESS, "Wrote " . print_r($f, true)); }