Esempio n. 1
0
 public function action_index()
 {
     //template header
     $this->template->title = __('Contact Us');
     $this->template->meta_description = __('Contact') . ' ' . core::config('general.site_name');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Contact Us')));
     if ($this->request->post()) {
         //captcha check
         if (captcha::check('contact')) {
             //check if user is loged in
             if (Auth::instance()->logged_in()) {
                 $email_from = Auth::instance()->get_user()->email;
                 $name_from = Auth::instance()->get_user()->name;
             } else {
                 $email_from = core::post('email');
                 $name_from = core::post('name');
             }
             //akismet spam filter
             if (!core::akismet($name_from, $email_from, core::post('message'))) {
                 $replace = array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => $name_from, '[EMAIL.FROM]' => $email_from);
                 if (Email::content(core::config('email.notify_email'), core::config('general.site_name'), $email_from, $name_from, 'contact-admin', $replace)) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
             } else {
                 Alert::set(Alert::WARNING, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Wrong captcha'));
         }
     }
     $this->template->content = View::factory('pages/contact');
 }
Esempio n. 2
0
 /**
  * Function to notify subscribers
  */
 public static function notify(Model_Ad $ad)
 {
     $subscribers = new Model_Subscribe();
     if ($ad->price > 0) {
         $subscribers->where_open()->where(DB::EXPR((int) $ad->price), 'BETWEEN', array('min_price', 'max_price'))->or_where('max_price', '=', 0)->where_close();
     }
     //location is set
     if (is_numeric($ad->id_location)) {
         $subscribers->where('id_location', 'in', array($ad->id_location, 0));
     }
     //filter by category, 0 means all the cats, in case was not set
     $subscribers->where('id_category', 'in', array($ad->id_category, 0));
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         // Send mails like in newsletter, to multiple users simultaneously
         if (count($users) > 0) {
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $ad->title);
             Email::content($users, '', core::config('email.notify_email'), core::config('general.site_name'), 'ads-subscribers', $replace);
         }
     }
 }
Esempio n. 3
0
 public function action_index()
 {
     //template header
     $this->template->title = __('Contact Us');
     $this->template->meta_description = __('Contact Us');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Contact Us')));
     if ($this->request->post()) {
         //captcha check
         if (captcha::check('contact')) {
             //akismet spam filter
             if (!core::akismet(core::post('name'), core::post('email'), core::post('message'))) {
                 $replace = array('[EMAIL.BODY]' => core::post('message'), '[EMAIL.SENDER]' => core::post('name'), '[EMAIL.FROM]' => core::post('email'));
                 if (Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::post('email'), core::post('name'), 'contact.admin', $replace)) {
                     Alert::set(Alert::SUCCESS, __('Your message has been sent'));
                 } else {
                     Alert::set(Alert::ERROR, __('Message not sent'));
                 }
             } else {
                 Alert::set(Alert::SUCCESS, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Check the form for errors'));
         }
     }
     $this->template->content = View::factory('pages/contact');
 }
Esempio n. 4
0
 /**
  * confirm payment for order
  *
  * @param string    $id_order [unique indentifier of order]
  * @param string    $txn_id id of the transaction depending on provider
  */
 public function confirm_payment($paymethod = 'paypal', $txn_id = NULL)
 {
     // update orders
     if ($this->loaded()) {
         $ad = $this->ad;
         $this->status = self::STATUS_PAID;
         $this->pay_date = Date::unix2mysql();
         $this->paymethod = $paymethod;
         $this->txn_id = $txn_id;
         try {
             $this->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         //if saved delete coupon from session and -- number of coupons.
         Model_Coupon::sale($this->coupon);
         //send email to site owner! new sale!!
         if (core::config('email.new_ad_notify') == TRUE) {
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace = array('[AD.TITLE]' => $ad->title, '[URL.AD]' => $url_ad, '[ORDER.ID]' => $this->id_order, '[PRODUCT.ID]' => $this->id_product);
             Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads-sold', $replace);
         }
         //depending on the product different actions
         switch ($this->id_product) {
             case Model_Order::PRODUCT_AD_SELL:
                 $ad->sale($this);
                 break;
             case Model_Order::PRODUCT_TO_TOP:
                 $ad->to_top();
                 break;
             case Model_Order::PRODUCT_TO_FEATURED:
                 $ad->to_feature($this->featured_days);
                 break;
             case Model_Order::PRODUCT_CATEGORY:
                 $ad->paid_category();
                 break;
         }
     }
 }
Esempio n. 5
0
 /**
  * Sends an email with a link to change your password
  * 
  */
 public function action_forgot()
 {
     //template header
     $this->template->title = __('Remember password');
     $this->template->meta_description = __('Here you can reset your password if you forgot it');
     $this->template->content = View::factory('pages/auth/forgot');
     //if user loged in redirect home
     if (Auth::instance()->logged_in()) {
         $this->redirect(Route::get('oc-panel')->uri());
     } elseif (core::post('email') and CSRF::valid('forgot')) {
         $email = core::post('email');
         if (Valid::email($email, TRUE)) {
             //check we have this email in the DB
             $user = new Model_User();
             $user = $user->where('email', '=', $email)->limit(1)->find();
             if ($user->loaded()) {
                 //we get the QL, and force the regen of token for security
                 $url_ql = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'changepass'), TRUE);
                 //we don't use this since checks if the user is subscribed which is stupid since you want to remember your password.
                 //$ret = $user->email('auth-remember',array('[URL.QL]'=>$url_ql));
                 $ret = Email::content($user->email, $user->name, NULL, NULL, 'auth-remember', array('[URL.QL]' => $url_ql));
                 //email sent notify and redirect him
                 if ($ret) {
                     Alert::set(Alert::SUCCESS, __('Email to recover password sent'));
                     $this->redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')));
                 }
             } else {
                 Form::set_errors(array(__('User not in database')));
             }
         } else {
             Form::set_errors(array(__('Invalid Email')));
         }
     }
 }
Esempio n. 6
0
 /**
  * displays the form new topic
  * @return [type] [description]
  */
 public function action_new()
 {
     if (!Auth::instance()->logged_in()) {
         Alert::set(Alert::ALERT, __('Please login before posting'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login')));
     }
     $forums = Model_Forum::get_forum_count();
     if (count($forums) == 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 Forums.'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'forum', 'action' => 'index')));
         } else {
             Alert::set(Alert::INFO, __('New Topic is not available as a feature.'));
             $this->redirect(Route::url('default'));
         }
     }
     $errors = NULL;
     if ($this->request->post()) {
         //captcha check
         if (captcha::check('new-forum')) {
             $user = Auth::instance()->get_user();
             //akismet spam filter
             if (!core::akismet($user->name, $user->email, core::post('description'))) {
                 $validation = Validation::factory($this->request->post())->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000))->rule('title', 'not_empty')->rule('title', 'min_length', array(':value', 5))->rule('id_forum', 'numeric');
                 // Optional banned words validation
                 if (core::config('advertisement.validate_banned_words')) {
                     $validation = $validation->rule('title', 'no_banned_words');
                 }
                 if ($validation->check()) {
                     $topic = new Model_Post();
                     $topic->id_user = $user->id_user;
                     $topic->id_forum = core::post('id_forum');
                     $topic->title = Text::banned_words(core::post('title'));
                     $topic->seotitle = $topic->gen_seotitle($topic->title);
                     $topic->description = Text::banned_words(core::post('description'));
                     $topic->status = Model_Post::STATUS_ACTIVE;
                     $topic->ip_address = ip2long(Request::$client_ip);
                     $topic->save();
                     $forum_url = Route::url('forum-topic', array('forum' => $topic->forum->seoname, 'seotitle' => $topic->seotitle));
                     if (core::config('email.new_ad_notify') == TRUE or core::config('email.new_sale_notify') == TRUE) {
                         Email::content(core::config('email.notify_email'), '', NULL, NULL, 'new-forum-answer', array('[FORUM.LINK]' => $forum_url));
                     }
                     $this->redirect($forum_url);
                 } else {
                     $errors = $validation->errors('ad');
                 }
             } else {
                 Alert::set(Alert::WARNING, __('This email has been considered as spam! We are sorry but we can not send this email.'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Check the form for errors'));
         }
     }
     //template header
     $this->template->title = __('New Forum Topic');
     $this->template->meta_description = $this->template->title;
     Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
     $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
     $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/forum-new.js');
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/forum/new', array('forums' => $forums));
     $content->errors = $errors;
 }
Esempio n. 7
0
 /**
  * notify admins of new ad
  * @return void 
  */
 public function notify_admins()
 {
     //NOTIFY ADMIN
     // new ad notification email to admin (notify_email), if set to TRUE
     if (core::config('email.new_ad_notify') == TRUE) {
         $url_ad = Route::url('ad', array('category' => $this->category->seoname, 'seotitle' => $this->seotitle));
         $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $this->title);
         Email::content(Email::get_notification_emails(), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads-to-admin', $replace);
     }
 }
Esempio n. 8
0
 /**
  * Sends request to admin (private site)
  * 
  */
 public function action_request()
 {
     //template header
     $this->template->title = __('Request Access');
     $this->template->content = View::factory('pages/auth/request');
     $this->template->meta_description = __('Send your Name and Email to the administrator of the website');
     //if user loged in redirect home
     if (Auth::instance()->logged_in()) {
         $this->redirect(Route::get('oc-panel')->uri());
     } elseif (core::post('email') and core::post('name')) {
         $name = core::post('name');
         $email = core::post('email');
         if (Valid::email($email)) {
             //check we have this email in the DB
             $user = new Model_User();
             $user = $user->where('email', '=', $email)->limit(1)->find();
             if (!$user->loaded()) {
                 // email sent to admin
                 $replace = array('[EMAIL.BODY]' => $name . ' requests access.', '[EMAIL.SUBJECT]' => 'Access Request', '[EMAIL.SENDER]' => $name, '[EMAIL.FROM]' => $email);
                 if (Email::content(core::config('email.notify_email'), core::config('general.site_name'), $email, $name, 'contact-admin', $replace)) {
                     Alert::set(Alert::SUCCESS, __('Your request has been sent'));
                 } else {
                     Alert::set(Alert::ERROR, __('Request not sent'));
                 }
             } else {
                 Alert::set(Alert::ERROR, __('User already exists'));
             }
         } else {
             Alert::set(Alert::ERROR, __('Invalid Email'));
         }
     }
     $this->redirect(Route::get('default')->uri());
 }
Esempio n. 9
0
 /**
  * confirm payment for order
  *
  * @param string    $id_order [unique indentifier of order]
  * @param string    $txn_id id of the transaction depending on provider
  */
 public function confirm_payment($paymethod = 'paypal', $txn_id = NULL)
 {
     // update orders
     if ($this->loaded()) {
         $this->status = self::STATUS_PAID;
         $this->pay_date = Date::unix2mysql();
         $this->paymethod = $paymethod;
         $this->txn_id = $txn_id;
         try {
             $this->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         //if saved delete coupon from session and -- number of coupons.
         Model_Coupon::sale($this->coupon);
         //for membership plans
         if ($this->id_product >= 100) {
             Model_Subscription::new_order($this);
             $replace_email = array('[AD.TITLE]' => $this->description, '[URL.AD]' => Route::url('pricing'), '[ORDER.ID]' => $this->id_order, '[PRODUCT.ID]' => $this->id_product, '[VAT.COUNTRY]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_country : '', '[VAT.NUMBER]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_number : '', '[VAT.PERCENTAGE]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT : '');
         } else {
             $ad = $this->ad;
             //depending on the product different actions
             switch ($this->id_product) {
                 case Model_Order::PRODUCT_AD_SELL:
                     $ad->sale($this);
                     break;
                 case Model_Order::PRODUCT_TO_TOP:
                     $ad->to_top();
                     break;
                 case Model_Order::PRODUCT_TO_FEATURED:
                     $ad->to_feature($this->featured_days);
                     Social::social_post_featured_ad($ad);
                     break;
                 case Model_Order::PRODUCT_CATEGORY:
                     $ad->paid_category();
                     break;
             }
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace_email = array('[AD.TITLE]' => $ad->title, '[URL.AD]' => $url_ad, '[ORDER.ID]' => $this->id_order, '[PRODUCT.ID]' => $this->id_product, '[VAT.COUNTRY]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_country : '', '[VAT.NUMBER]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT_number : '', '[VAT.PERCENTAGE]' => (isset($this->VAT) and $this->VAT > 0) ? $this->VAT : '');
         }
         //send email to site owner! new sale!!
         if (core::config('email.new_ad_notify') == TRUE) {
             Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads-sold', $replace_email);
         }
     }
 }
Esempio n. 10
0
 public function action_changepass()
 {
     // only admins can change password
     if ($this->request->post() and $this->user->id_role == Model_Role::ROLE_ADMIN) {
         $user = new Model_User($this->request->param('id'));
         if (core::post('password1') == core::post('password2')) {
             if (!empty(core::post('password1'))) {
                 $user->password = core::post('password1');
                 $user->last_modified = Date::unix2mysql();
                 $user->failed_attempts = 0;
                 $user->last_failed = NULL;
                 try {
                     $user->save();
                     // email user with new password
                     Email::content($user->email, $user->name, NULL, NULL, 'password-changed', array('[USER.PWD]' => core::post('password1')));
                 } catch (ORM_Validation_Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 } catch (Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 }
                 Alert::set(Alert::SUCCESS, __('Password is changed'));
             } else {
                 Form::set_errors(array(__('Nothing is provided')));
             }
         } else {
             Form::set_errors(array(__('Passwords do not match')));
         }
     }
     $this->redirect(Route::url('oc-panel', array('controller' => 'user', 'action' => 'update', 'id' => $this->request->param('id'))));
 }
Esempio n. 11
0
 public function action_update()
 {
     //template header
     $this->template->title = __('Edit Product');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Product')));
     $this->template->styles = array('css/sortable.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/css/jquery.fileupload.css' => 'screen', 'css/jasny-bootstrap.min.css' => 'screen');
     $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/jasny-bootstrap.min.js', 'js/oc-panel/products.js', 'js/jquery-sortable-min.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/vendor/jquery.ui.widget.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.iframe-transport.js', '//cdn.jsdelivr.net/jquery.fileupload/9.5.2/js/jquery.fileupload.js');
     $cats = Model_Category::get_as_array();
     $order = Model_Category::get_multidimensional();
     $obj_product = new Model_Product($this->request->param('id'));
     if ($obj_product->loaded()) {
         // get currencies from product, returns array
         $currency = $obj_product::get_currency();
         $this->template->content = View::factory('oc-panel/pages/products/update', array('product' => $obj_product, 'categories' => $cats, 'order_categories' => $order, 'currency' => $currency));
         if ($product = $this->request->post()) {
             // save product file
             if (isset($_FILES['file_name'])) {
                 if ($file = $_FILES['file_name']) {
                     $file = $obj_product->save_product($file);
                     if ($file != FALSE) {
                         $obj_product->file_name = $file;
                     } else {
                         Alert::set(Alert::INFO, __('Product is not uploaded.'));
                     }
                 }
             }
             // deleting single image by path
             $deleted_image = core::post('img_delete');
             if (is_numeric($deleted_image)) {
                 $img_path = $obj_product->gen_img_path($obj_product->id_product, $obj_product->created);
                 $img_seoname = $obj_product->seotitle;
                 // delete image from Amazon S3
                 if (core::config('image.aws_s3_active')) {
                     require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
                     $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
                     //delete original image
                     $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $deleted_image . '.jpg');
                     //delete formated image
                     $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg');
                     //re-ordering image file names
                     for ($i = $deleted_image; $i < $obj_product->has_images; $i++) {
                         //rename original image
                         $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ);
                         $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . $img_seoname . '_' . ($i + 1) . '.jpg');
                         //rename formated image
                         $s3->copyObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg', S3::ACL_PUBLIC_READ);
                         $s3->deleteObject(core::config('image.aws_s3_bucket'), $img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg');
                     }
                 }
                 if (!is_dir($img_path)) {
                     return FALSE;
                 } else {
                     //delete original image
                     @unlink($img_path . $img_seoname . '_' . $deleted_image . '.jpg');
                     //delete formated image
                     @unlink($img_path . 'thumb_' . $img_seoname . '_' . $deleted_image . '.jpg');
                     //re-ordering image file names
                     for ($i = $deleted_image; $i < $obj_product->has_images; $i++) {
                         rename($img_path . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . $img_seoname . '_' . $i . '.jpg');
                         rename($img_path . 'thumb_' . $img_seoname . '_' . ($i + 1) . '.jpg', $img_path . 'thumb_' . $img_seoname . '_' . $i . '.jpg');
                     }
                 }
                 $obj_product->has_images = $obj_product->has_images > 0 ? $obj_product->has_images - 1 : 0;
                 $obj_product->updated = Date::unix2mysql();
                 try {
                     $obj_product->save();
                 } catch (Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 }
                 $this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product)));
             }
             // end of img delete
             //delete product file
             $product_delete = core::post('product_delete');
             if ($product_delete) {
                 $p_path = $obj_product->get_file($obj_product->file_name);
                 if (!is_file($p_path)) {
                     return FALSE;
                 } else {
                     @chmod($p_path, 0755);
                     //delete product
                     unlink($p_path);
                     $obj_product->file_name = '';
                     $obj_product->save();
                     $this->redirect(Route::url('oc-panel', array('controller' => 'product', 'action' => 'update', 'id' => $obj_product->id_product)));
                 }
             }
             $product['status'] = (!isset($_POST['status']) or core::post('status') === NULL) ? Model_Product::STATUS_NOACTIVE : Model_Product::STATUS_ACTIVE;
             $product['updated'] = Date::unix2mysql();
             //we do this so we assure use the entire day , nasty
             $product['offer_valid'] .= ' 23:59:59';
             $product['featured'] .= ' 23:59:59';
             // each field in edit product
             foreach ($product as $field => $value) {
                 // do not include submit
                 if ($field != 'submit' and $field != 'notify') {
                     // check if its different, and set it is
                     if ($value != $obj_product->{$field}) {
                         $obj_product->{$field} = $value;
                         // if title is changed, make new seotitle
                         if ($field == 'title') {
                             $seotitle = $obj_product->gen_seotitle($product['title']);
                             $obj_product->seotitle = $seotitle;
                         }
                     }
                 }
             }
             // save product or trow exeption
             try {
                 $obj_product->save();
                 Alert::set(Alert::SUCCESS, __('Product saved.'));
                 Sitemap::generate();
                 //notify users of new update
                 if ($this->request->post('notify')) {
                     //get users with that product
                     $query = DB::select('email')->select('name')->from(array('users', 'u'))->join(array('orders', 'o'), 'INNER')->on('u.id_user', '=', 'o.id_user')->where('u.status', '=', Model_User::STATUS_ACTIVE)->where('o.status', '=', Model_Order::STATUS_PAID)->where('o.id_product', '=', $obj_product->id_product)->execute();
                     $users = $query->as_array();
                     if (count($users) > 0) {
                         //download link
                         $download = '';
                         if ($obj_product->has_file() == TRUE) {
                             $download = '\\n\\n==== ' . __('Download') . ' ====\\n' . Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders'));
                         }
                         //theres an expire? 0 = unlimited
                         $expire = '';
                         $expire_hours = Core::config('product.download_hours');
                         $expire_times = Core::config('product.download_times');
                         if (($expire_hours > 0 or $expire_times > 0) and $obj_product->has_file() == TRUE) {
                             if ($expire_hours > 0 and $expire_times > 0) {
                                 $expire = sprintf(__('Your download expires in %u hours and can be downloaded %u times.'), $expire_hours, $expire_times);
                             } elseif ($expire_hours > 0) {
                                 $expire = sprintf(__('Your download expires in %u hours.'), $expire_hours);
                             } elseif ($expire_times > 0) {
                                 $expire = sprintf(__('Can be downloaded %u times.'), $expire_times);
                             }
                             $expire = '\\n' . $expire;
                         }
                         if (!Email::content($users, '', NULL, NULL, 'product-update', array('[TITLE]' => $obj_product->title, '[URL.PRODUCT]' => Route::url('product', array('seotitle' => $obj_product->seotitle, 'category' => $obj_product->category->seoname)), '[DOWNLOAD]' => $download, '[EXPIRE]' => $expire, '[VERSION]' => $obj_product->version))) {
                             Alert::set(Alert::ERROR, __('Error on mail delivery, not sent'));
                         } else {
                             Alert::set(Alert::SUCCESS, __('Email sent to all the users'));
                         }
                     } else {
                         Alert::set(Alert::ERROR, __('Mail not sent'));
                     }
                 }
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
             // save images
             if (isset($_FILES)) {
                 foreach ($_FILES as $file_name => $file) {
                     if ($file_name != 'file_name') {
                         $file = $obj_product->save_image($file);
                     }
                     if ($file) {
                         $obj_product->has_images++;
                     }
                 }
                 //since theres images save the ad again...
                 try {
                     $obj_product->save();
                 } catch (Exception $e) {
                     throw HTTP_Exception::factory(500, $e->getMessage());
                 }
             }
         }
     }
 }
Esempio n. 12
0
 /**
  * sends email to the current user replacing tags
  * @param  string $seotitle from Model_Content
  * @param  array $replace
  * @param  array $file  file to be uploaded
  * @return boolean
  */
 public function email($seotitle, array $replace = NULL, $from = NULL, $from_name = NULL, $file = NULL, $to = NULL)
 {
     if ($this->loaded() and $this->subscriber == 1) {
         return Email::content($to == NULL ? $this->email : $to, $this->name, $from, $from_name, $seotitle, $replace, $file);
     }
     return FALSE;
 }
Esempio n. 13
0
 public function action_ticket()
 {
     $this->template->scripts['footer'] = array('js/oc-panel/ticket.js');
     //after creating the reply we redirect to the ticket view
     $errors = NULL;
     $user = Auth::instance()->get_user();
     $ticket_id = $this->request->param('id', 0);
     //getting the parent ticket
     $ticket = new Model_Ticket();
     if (!$user->has_access('supportadmin')) {
         $ticket->where('id_user', '=', $user->id_user);
     }
     $ticket->where('id_ticket', '=', $ticket_id)->where('id_ticket_parent', 'IS', NULL)->limit(1)->find();
     if (!$ticket->loaded()) {
         Alert::set(Alert::ERROR, __('Not your ticket.'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'support', 'action' => 'index')));
     }
     //marking it as read if was not assign we assign an agent.
     if ($ticket->status == Model_Ticket::STATUS_CREATED and $user->has_access('supportadmin') and !is_numeric($ticket->id_user_support)) {
         //modify status of parent ticket
         $ticket->id_user_support = $user->id_user;
         $ticket->read_date = Date::unix2mysql();
         $ticket->status = Model_Ticket::STATUS_READ;
         $ticket->save();
     }
     //Change the agent assigned to this ticket
     if (core::post('agent') and $user->has_access('supportadmin')) {
         //modify ticket
         $ticket->id_user_support = core::post('agent');
         $ticket->status = Model_Ticket::STATUS_CREATED;
         $ticket->save();
         //send notification to agent
         $agent = new Model_User(core::post('agent'));
         $agent->email('assign-agent', array('[TITLE]' => $ticket->title, '[DESCRIPTION]' => $ticket->description, '[URL.QL]' => $agent->ql('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket))));
         Alert::set(Alert::SUCCESS, __('Agent assigned.'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'support', 'action' => 'index', 'id' => 'admin')));
     }
     //create new reply
     if ($this->request->post() and Form::token('reply_ticket', TRUE)) {
         $validation = Validation::factory($this->request->post())->rule('description', 'not_empty')->rule('description', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000));
         if ($validation->check()) {
             //creates the answer ticket
             $ticketr = new Model_Ticket();
             $ticketr->id_user = $user->id_user;
             $ticketr->id_order = $ticket->id_order;
             $ticketr->id_ticket_parent = $ticket->id_ticket;
             $ticketr->description = core::post('description');
             $ticketr->ip_address = ip2long(Request::$client_ip);
             $ticketr->save();
             unset($_POST['description']);
             //modify status of parent ticket
             $ticket->status = Model_Ticket::STATUS_CREATED;
             $ticket->save();
             //an admin answer so we send email to owner of ticket
             if ($user->has_access('supportadmin')) {
                 $ticket->id_user_support = $user->id_user;
                 $ticket->read_date = Date::unix2mysql();
                 $ticket->status = Model_Ticket::STATUS_HOLD;
                 $ticket->save();
                 //send email to creator of the ticket
                 $ticket->user->email('new-reply', array('[TITLE]' => $ticket->title, '[DESCRIPTION]' => $user->signature, '[URL.QL]' => $ticket->user->ql('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket))));
             } elseif (is_numeric($ticket->id_user_support)) {
                 //send notification to agent
                 $agent = new Model_User($ticket->id_user_support);
                 $agent->email('new-reply', array('[TITLE]' => $ticket->title, '[DESCRIPTION]' => $ticketr->description, '[URL.QL]' => $agent->ql('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket))));
             } elseif (core::config('email.new_sale_notify')) {
                 Email::content(core::config('email.notify_email'), NULL, NULL, NULL, 'new-reply', array('[TITLE]' => $ticket->title, '[DESCRIPTION]' => $ticketr->description, '[URL.QL]' => Route::url('oc-panel', array('controller' => 'support', 'action' => 'ticket', 'id' => $ticket->id_ticket))));
             }
             //set empty since they already replied
             Request::current()->post('description', '');
             Alert::set(Alert::SUCCESS, __('Reply created.'));
         } else {
             $errors = $validation->errors('ad');
         }
     }
     //getting all the ticket replies
     $replies = new Model_Ticket();
     $replies = $replies->where('id_ticket_parent', '=', $ticket->id_ticket)->order_by('created', 'asc')->find_all();
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Ticket')));
     $this->template->title = $ticket->title . ' - ' . __('Ticket');
     //loading agents/admins
     $users = NULL;
     if ($user->has_access('supportadmin')) {
         //getting the roles that have access to the supportadmin since are the agents ;)
         $support_roles = array(Model_Role::ROLE_ADMIN);
         $access = new Model_Access();
         $access = $access->where('access', '=', 'supportadmin.*')->find_all();
         foreach ($access as $a) {
             $support_roles[] = $a->id_role;
         }
         //getting agents ;)
         $users_db = DB::select('u.id_user')->select('u.name')->from(array('users', 'u'))->where('id_role', 'in', $support_roles)->as_object()->execute();
         foreach ($users_db as $key => $value) {
             $users[$value->id_user] = $value->name;
         }
     }
     $this->template->bind('content', $content);
     $this->template->content = View::factory('oc-panel/pages/support/ticket', array('replies' => $replies, 'ticket' => $ticket, 'users' => $users));
     $content->errors = $errors;
 }
Esempio n. 14
0
 /**
  * sends email to the current user replacing tags
  * @param  string $seotitle from Model_Content
  * @param  array $replace
  * @param  array $file  file to be uploaded
  * @return boolean
  */
 public function email($seotitle, array $replace = NULL, $from = NULL, $from_name = NULL, $file = NULL)
 {
     if ($this->loaded()) {
         return Email::content($this->email, $this->name, $from, $from_name, $seotitle, $replace, $file);
     }
     return FALSE;
 }
Esempio n. 15
0
 /**
  * send notification of new answer to the repliers of a topic
  */
 public function notify_repliers()
 {
     $data = array('[FORUM.LINK]' => Route::url('forum-topic', array('forum' => $this->forum->seoname, 'seotitle' => $this->seotitle)));
     Email::content($this->get_repliers(), '', NULL, NULL, 'new-forum-answer', $data);
 }
Esempio n. 16
0
 /**
  * [save_new_ad Save new advertisement if validated, with a given parameters 
  * 
  * @param  [array] $data   [post values]
  * @param  [int] $status [status of advert.]
  * @param  [bool] $published [Confirms if advert is published. ref to model_ad]
  * @param  [int] $moderation [moderation status/mode]
  * 
  * @return [view] View dependant on usecase 
  */
 public function save_new_ad($data, $status, $published, $moderation)
 {
     $user = new Model_User();
     $new_ad = new Model_Ad();
     //$_POST is submitted for a new ad
     if ($this->request->post()) {
         if (captcha::check('publish_new')) {
             //FORM DATA
             $seotitle = $new_ad->gen_seo_title($data['title']);
             $new_ad->title = Model_Ad::banned_words($data['title']);
             $new_ad->id_location = $data['loc'];
             $new_ad->id_category = $data['cat'];
             $new_ad->description = Model_Ad::banned_words($data['description']);
             $new_ad->seotitle = $seotitle;
             $new_ad->status = $status;
             $new_ad->price = floatval(str_replace(',', '.', $data['price']));
             $new_ad->address = $data['address'];
             $new_ad->phone = $data['phone'];
             $new_ad->website = $data['website'];
             // set custom values
             foreach ($data as $name => $field) {
                 // get only custom values with prefix
                 if (strpos($name, 'cf_') !== false) {
                     $new_ad->{$name} = $field;
                 }
             }
             // d($data);
             // User detection, if doesnt exists create
             $auth_user = Auth::instance();
             if (!$auth_user->logged_in()) {
                 $name = core::post('name');
                 $email = core::post('email');
                 $user_id = $user->create_new_user($name, $email);
             } else {
                 $user_id = $auth_user->get_user()->id_user;
                 $name = $auth_user->get_user()->name;
                 $email = $auth_user->get_user()->email;
             }
             // SAVE AD
             $new_ad->id_user = $user_id;
             // after handling user
             try {
                 //akismet spam filter
                 if (!core::akismet(Model_Ad::banned_words($data['title']), $email, Model_Ad::banned_words($data['description']))) {
                     if ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) {
                         $new_ad->status = Model_Ad::STATUS_UNCONFIRMED;
                     }
                     $new_ad->save();
                 } else {
                     Alert::set(Alert::SUCCESS, __('This post has been considered as spam! We are sorry but we cant publish this advertisement.'));
                     $this->request->redirect('default');
                 }
                 //akismet
                 // if moderation is off update db field with time of creation
                 if ($published) {
                     $_ad_published = new Model_Ad();
                     $_ad_published->where('seotitle', '=', $seotitle)->limit(1)->find();
                     $_ad_published->published = $_ad_published->created;
                     $_ad_published->save();
                     $created = $_ad_published->created;
                 } else {
                     $created = new Model_Ad();
                     $created = $created->where('seotitle', '=', $seotitle)->limit(1)->find();
                     $created = $created->created;
                 }
                 $user = $user->where('email', '=', $email)->limit(1)->find();
                 // after successful posting send them email depending on moderation
                 if ($moderation == Model_Ad::EMAIL_CONFIRMATION or $moderation == Model_Ad::EMAIL_MODERATION) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     //we get the QL, and force the regen of token for security
                     $url_ql = $user->ql('default', array('controller' => 'ad', 'action' => 'confirm_post', 'id' => $new_ad->id_ad), TRUE);
                     $ret = $user->email('ads.confirm', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                 } elseif ($moderation == Model_Ad::MODERATION_ON) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     //we get the QL, and force the regen of token for security
                     $url_ql = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'update', 'id' => $new_ad->id_ad), TRUE);
                     $ret = $user->email('ads.notify', array('[URL.QL]' => $url_ql, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                     // email to notify user of creating, but it is in moderation currently
                 } elseif ($moderation == Model_Ad::POST_DIRECTLY) {
                     $edit_url = core::config('general.base_url') . 'oc-panel/profile/update/' . $new_ad->id_ad;
                     $delete_url = core::config('general.base_url') . 'oc-panel/ad/delete/' . $new_ad->id_ad;
                     $url_cont = $user->ql('contact', array(), TRUE);
                     $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
                     $ret = $user->email('ads.user_check', array('[URL.CONTACT]' => $url_cont, '[URL.AD]' => $url_ad, '[AD.NAME]' => $new_ad->title, '[URL.EDITAD]' => $edit_url, '[URL.DELETEAD]' => $delete_url));
                 }
                 // new ad notification email to admin (notify_email), if set to TRUE
                 if (core::config('email.new_ad_notify')) {
                     $url_ad = $user->ql('ad', array('category' => $data['cat'], 'seotitle' => $seotitle), TRUE);
                     $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $new_ad->title);
                     Email::content(core::config('email.notify_email'), core::config('general.site_name'), core::config('email.notify_email'), core::config('general.site_name'), 'ads.to_admin', $replace);
                 }
             } catch (Exception $e) {
                 throw new HTTP_Exception_500($e->getMessage());
             }
             // 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])) {
                     $fh = fopen('/tmp/grisha.log', 'a');
                     $img_files = $_FILES['image' . $i];
                     if (isset($_REQUEST['wb_base64'])) {
                         fwrite($fh, "Base64 is true\n");
                         $old_name = $_FILES['image' . $i]['tmp_name'];
                         $new_name = $old_name . "_decoded";
                         $img_files['tmp_name'] = $_FILES['image' . $i]['tmp_name'] = $new_name;
                         $img_files['old_name'] = $old_name;
                         copy($old_name, '/tmp/grisha/' . basename($old_name));
                         fwrite($fh, "Decoding from {$old_name} to {$new_name}\n");
                         $encoded = file_get_contents($old_name);
                         $decoded = base64_decode($encoded);
                         $result = file_put_contents($new_name, $decoded);
                         $img_files['size'] = $_FILES['image' . $i]['size'] = filesize($new_name);
                         copy($new_name, '/tmp/grisha/' . basename($new_name));
                         fwrite($fh, "Wrote: " . $result . " to {$new_name}");
                         fwrite($fh, "{$_FILES}: " . print_r($_FILES, true));
                         fwrite($fh, "{$img_files}: " . print_r($img_files, true));
                         fclose($fh);
                     }
                     $filename = $new_ad->save_image($img_files, $new_ad->id_ad, $created, $new_ad->seotitle, $counter);
                 }
                 if ($filename) {
                     $new_ad->has_images = 1;
                     try {
                         $new_ad->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' => $new_ad->id_ad)));
                 }
             }
             // PAYMENT METHOD ACTIVE (and other alerts)
             if ($moderation == Model_Ad::PAYMENT_ON || $moderation == Model_Ad::PAYMENT_MODERATION) {
                 $payment_order = new Model_Order();
                 $order_id = $payment_order->make_new_order($data, $user, $seotitle);
                 if ($order_id == NULL) {
                     if ($moderation == Model_Ad::PAYMENT_ON) {
                         $new_ad->status = 1;
                         $new_ad->published = Date::unix2mysql(time());
                         try {
                             $new_ad->save();
                             Alert::set(Alert::SUCCESS, __('Advertisement is published. Congratulations!'));
                         } catch (Exception $e) {
                             throw new HTTP_Exception_500($e->getMessage());
                         }
                     }
                     if ($moderation == Model_Ad::PAYMENT_MODERATION) {
                         Alert::set(Alert::SUCCESS, __('Advertisement is created but needs to be validated first before it is published.'));
                     }
                     $this->request->redirect(Route::url('default'));
                 }
                 // redirect to payment
                 $this->request->redirect(Route::url('default', array('controller' => 'payment_paypal', 'action' => 'form', 'id' => $order_id)));
                 // @TODO - check route
             } elseif ($moderation == Model_Ad::EMAIL_MODERATION or $moderation == Model_Ad::EMAIL_CONFIRMATION) {
                 Alert::set(Alert::INFO, __('Advertisement is posted but first you need to activate. Please check your email!'));
                 $this->request->redirect(Route::url('default'));
             } elseif ($moderation == Model_Ad::MODERATION_ON) {
                 Alert::set(Alert::INFO, __('Advertisement is received, but first administrator needs to validate. Thank you for being patient!'));
                 $this->request->redirect(Route::url('default'));
             } else {
                 Model_Subscribe::find_subscribers($data, floatval(str_replace(',', '.', $data['price'])), $seotitle, $email);
                 Alert::set(Alert::SUCCESS, __('Advertisement is posted. Congratulations!'));
                 $this->request->redirect(Route::url('default'));
             }
         } else {
             Alert::set(Alert::ALERT, __('Captcha is not correct'));
         }
     }
     //is post
 }