public function unsubscribe($id)
 {
     $subscriber = Subscriber::find((int) $id);
     if ($subscriber) {
         $subscriber->active = 0;
         $subscriber->save();
         $configs = Setting::getSiteSettings();
         return View::make('frontend.unsubscribe', ['subscriber' => $subscriber, 'configs' => $configs]);
     } else {
         echo 'User not found.';
     }
 }
Ejemplo n.º 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $post
  * @return Response
  */
 public function postDelete($subscriber)
 {
     // Declare the rules for the form validation
     $rules = array('id' => 'required|integer');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         $id = $subscriber->id;
         $subscriber->delete();
         // Was the blog post deleted?
         $subscriber = Subscriber::find($id);
         if (empty($subscriber)) {
             // Redirect to the blog posts management page
             return Redirect::to('admin/subscribers')->with('success', Lang::get('admin/subscribers/messages.delete.success'));
         }
     }
     // There was a problem deleting the blog post
     return Redirect::to('admin/subscribers')->with('error', Lang::get('admin/subscribers/messages.delete.error'));
 }
 public static function now($pin, $uid, $method = 'pin')
 {
     $coupon = self::where('pin', $pin)->first();
     if ($coupon == NULL) {
         throw new Exception("Invalid PIN.");
     }
     if ($coupon->user_id != NULL) {
         throw new Exception('Invalid/Used Voucher.');
     }
     $subscriber = Subscriber::find($uid);
     switch ($subscriber->plan_type) {
         case PREPAID_PLAN:
             $recharge = DB::table('user_recharges as r')->where('r.user_id', $uid)->join('prepaid_vouchers as v', 'r.voucher_id', '=', 'v.id')->join('user_accounts as u', 'u.id', '=', 'r.user_id')->leftJoin('voucher_limits as l', 'v.limit_id', '=', 'l.id')->select('r.id', 'v.plan_type', 'v.limit_id', 'r.expiration', 'l.aq_access', 'u.uname')->first();
             if (is_null($recharge)) {
                 throw new Exception("Cannot refill, account never recharged.");
             }
             if (strtotime($recharge->expiration) < time()) {
                 throw new Exception("Cannot recharge account, validity expired on: " . date('d-M-y H:i', strtotime($recharge->expiration)));
             }
             if ($recharge->plan_type == UNLIMITED) {
                 throw new Exception('Cannot refill Unlimited Account.');
             }
             return self::refillPrepaid($coupon, $recharge);
             break;
         case FREE_PLAN:
             $balance = Freebalance::where('free_balance.user_id', $uid)->join('user_accounts as u', 'u.id', '=', 'free_balance.user_id')->select('free_balance.plan_type', 'free_balance.limit_type', 'free_balance.id', 'free_balance.aq_access', 'free_balance.aq_invocked', 'free_balance.time_balance', 'free_balance.data_balance', 'free_balance.expiration', 'u.uname')->first();
             if (strtotime($balance->expiration) < time()) {
                 throw new Exception("Cannot refill account, validity expired on: " . date('d-M-y H:i', strtotime($balance->expiration)));
             }
             if ($balance->plan_type == UNLIMITED) {
                 throw new Exception("Cannot refill unlimited account.");
             }
             return self::refillFree($coupon, $balance);
             break;
     }
 }
 public function getSessionHistory()
 {
     $sess_history = Subscriber::find(Auth::id())->sessionHistory()->orderby('acctstarttime', 'desc')->paginate(10);
     return View::make('user.prepaid.session_history')->with('sess_history', $sess_history);
 }
 public function postEdit()
 {
     $input = Input::all();
     $rules = Config::get('validations.accounts');
     $rules['uname'][] = 'unique:user_accounts,uname,' . $input['id'];
     $v = Validator::make($input, $rules);
     $v->setAttributeNames(Config::get('attributes.accounts'));
     if ($v->fails()) {
         return Redirect::back()->withInput()->withErrors($v);
     }
     try {
         if (!Input::has('id')) {
             throw new Exception("Required parameter missing: ID");
         }
         $account = Subscriber::find($input['id']);
         if (!$account) {
             throw new Exception("No such user with id:{$input['id']}");
         }
         $account->fill($input);
         if (!$account->save()) {
             throw new Exception("Failed to update account.");
         }
         if ($account->status == DEACTIVE) {
             Subscriber::destroyAllSessions($account);
         }
         $this->notifySuccess("Account successfully updated.");
     } catch (Exception $e) {
         $this->notifyError($e->getMessage());
         return Redirect::route(self::HOME);
     }
     return Redirect::route(self::HOME);
 }
 public function getEdit()
 {
     $profile = Subscriber::find(Auth::user()->id);
     return View::make('admin.my_profile.edit')->with('profile', $profile);
 }
 public function unsubscribe($id)
 {
     $browser = new Browser();
     $userbrowser = $browser->getBrowser() . ' ' . $browser->getVersion();
     $userplatform = $browser->getPlatform();
     $userIP = $_SERVER["REMOTE_ADDR"];
     $tracker = Tracker::find($id);
     $tracker->unsubscribed = 1;
     if ($tracker->IP_address == '') {
         $tracker->IP_address = $userIP;
     }
     if ($tracker->browser == '') {
         $tracker->browser = $userbrowser;
     }
     if ($tracker->platform == '') {
         $tracker->platform = $userplatform;
     }
     if ($tracker->read == 0) {
         $tracker->read = 1;
     }
     if ($tracker->read_at == '0000-00-00 00:00:00') {
         $tracker->read_at = new Datetime();
     }
     $tracker->save();
     $sub_id = $tracker->subscriber_id;
     $subscriber = Subscriber::find($sub_id);
     $subscriber->active = 0;
     $subscriber->save();
     echo "You have been successfully unsubscribed.";
 }
 public function add_subscribers_to_list($id)
 {
     $subs_array = Input::get('subsarray');
     $list = Addressbook::find($id);
     $count = 0;
     foreach ($subs_array as $key => $value) {
         $list->subscribers()->attach($value);
         if ($list->active == 0) {
             $subscriber = Subscriber::find($value);
             $subscriber->active = 0;
             $subscriber->save();
         } else {
             if ($list->active == 1) {
                 $subscriber = Subscriber::with('lists')->find($value);
                 $check = 1;
                 foreach ($subscriber->lists as $alist) {
                     if ($alist->active == 0) {
                         $check = 0;
                     }
                 }
                 if ($check == 1) {
                     $subscriber->active = 1;
                 } else {
                     $subscriber->active = 0;
                 }
                 $subscriber->save();
             }
         }
         $count++;
     }
     return Response::json(array('success' => $count . ' subscribers successfully added to ' . $list->name));
 }
 public function restore($id)
 {
     $subscriber = Subscriber::find($id);
     $subscriber->is_deleted = 0;
     $subscriber->save();
     return Redirect::to('dashboard/subscribers/trash')->withSuccess('Subscriber restored.');
 }