public function run($arg) { // $last_working = Yii::app()->setting->getItem('last_working'); // if(!empty($last_working)) // { // $timestampNext = strtotime(ActiveRecord::timeCalMinutes(-10)); // if(strtotime($last_working) > $timestampNext) // { //// Yii::log(strtotime($last_working), 'error', 'NewsletterCommand.run'); //// Yii::log($timestampNext, 'error', 'NewsletterCommand.run'); // echo 'waiting because last working is nearly'; // return; // } // } $member = Users::model()->findAll('role_id = ' . ROLE_MEMBER); if (count($member) > 0) { foreach ($member as $item) { $email = Subscriber::model()->find('email ="' . $item->email . '"'); if (count($email) == 0) { $subcribe = new Subscriber(); $subcribe->email = $item->email; $subcribe->name = $item->username; $subcribe->subscriber_group_id = GROUP_MEMBER; $subcribe->save(); } } } //Yii::app()->setting->setDbItem('last_working', date('Y-m-d h:i:s')); }
public function submitPlus(DataContainer $dc) { $subscriber = new Subscriber($dc->activeRecord->email); $subscriber->setByDc($dc); $cid = $dc->activeRecord->pid; $time = time(); // set active if ($dc->activeRecord->active == 1) { $subscriber->activated = $time; $subscriber->deactivated = ''; } else { $subscriber->deactivated = $time; } if ($this->isCRActive($cid)) { // new record - added manually --> call add() method if (!$dc->activeRecord->addedOn && !$dc->activeRecord->tstamp) { $subscriber->registered = $time; $subscriber->addToCR(); } // existing record - call update() method if ($dc->activeRecord->tstamp) { $subscriber->updateCR(); } } }
public function createNewUser($userId, $arrData) { $arrNewsletters = deserialize($arrData['newsletter'], true); // Return if there are no newsletters if (!is_array($arrNewsletters)) { return; } $time = time(); // Add recipients foreach ($arrNewsletters as $intNewsletter) { $intNewsletter = intval($intNewsletter); if ($intNewsletter < 1) { continue; } $objRecipient = $this->Database->prepare("SELECT COUNT(*) AS total FROM tl_newsletter_recipients WHERE pid=? AND email=?")->execute($intNewsletter, $arrData['email']); if ($objRecipient->total < 1) { $subscriber = new Subscriber($arrData['email']); $subscriber->tstamp = $time; $subscriber->salutation = $arrData['gender']; $subscriber->firstname = $arrData['firstname']; $subscriber->lastname = $arrData['lastname']; $subscriber->company = $arrData['company']; $subscriber->addedOn = $time; $subscriber->ip = $this->anonymizeIp($this->Environment->ip); $subscriber->pid = $intNewsletter; $subscriber->active = ''; $subscriber->token = ''; // account will get activated by registration token from registration E-Mail $subscriber->registered = $time; $subscriber->add(); } } }
/** * @magentoDataFixture Magento/Newsletter/_files/subscribers.php * @magentoAppArea frontend */ public function testUnsubscribeSubscribeByCustomerId() { // Unsubscribe and verify $this->assertSame($this->_model, $this->_model->unsubscribeCustomerById(1)); $this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->_model->getSubscriberStatus()); // Subscribe and verify $this->assertSame($this->_model, $this->_model->subscribeCustomerById(1)); $this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->_model->getSubscriberStatus()); }
public static function replaceCustomFieldValues($string, Subscriber $subscriber) { $name = $subscriber->getName(); $string = str_replace("[!name!]", $name, $string); $values = $subscriber->getCustomFieldValuesByLabels(); foreach ($values as $name => $value) { $string = str_replace("[!{$name}!]", $value, $string); } return $string; }
function _wpr_process_sendmail_parameters($sid, $params, $footerMessage = "") { global $wpdb; $subscriber = new Subscriber($sid); $newsletter = _wpr_newsletter_get($subscriber->getNewsletterId()); //if the fromname field is set in the newsletter, then use that value otherwise use the blog name. $fromname = !empty($params['fromname']) ? $params['fromname'] : !empty($newsletter->fromname) ? $newsletter->fromname : get_bloginfo("name"); if ($newsletter->reply_to) { $replyto = $newsletter->reply_to; } $unsuburl = wpr_get_unsubscription_url($sid); $subject = $params['subject']; $address = get_option("wpr_address"); $textUnSubMessage = "\n\n{$address}\n\n" . __("To unsubscribe or change subscription options visit", 'wpr_autoresponder') . ":\r\n\r\n{$unsuburl}"; $reply_to = $newsletter->reply_to; $htmlbody = trim($params['htmlbody']); $textbody = $params['textbody']; $subject = $params['subject']; //append the address and the unsub link to the email $address = "<br>\n<br>\n" . nl2br(get_option("wpr_address")) . "<br>\n<br>\n"; $htmlUnSubscribeMessage = "<br><br>" . $address . "<br><br>" . __("To unsubscribe or change subscriber options visit:", 'wpr_autoresponder') . "<br />\n\r\n <a href=\"{$unsuburl}\">{$unsuburl}</a>"; $htmlenabled = $params['htmlenabled'] ? 1 : 0; if (!empty($htmlbody)) { if ($footerMessage && !empty($htmlbody)) { $htmlbody .= nl2br($footerMessage) . "<br>\n<br>\n"; } if (strstr($htmlbody, "[!unsubscribe!]")) { $htmlbody = str_replace("[!unsubscribe!]", $unsuburl, $htmlbody); } else { $htmlbody .= $htmlUnSubscribeMessage; } } if ($footerMessage) { $params['textbody'] .= $footerMessage . "\n\n"; } if (strstr($params['textbody'], "[!unsubscribe!]")) { $textbody = str_replace("[!unsubscribe!]", $unsuburl, $textbody); } else { $textbody = $params['textbody'] . $textUnSubMessage; } $textbody = addslashes($textbody); $htmlbody = addslashes($htmlbody); $subject = addslashes($subject); $time = time(); $subject = str_replace("[!name!]", $subscriber->getName(), $subject); $textbody = str_replace("[!name!]", $subscriber->getName(), $textbody); $htmlbody = str_replace("[!name!]", $subscriber->getName(), $htmlbody); $delivery_type = !empty($params['delivery_type']) ? $params['delivery_type'] : 0; $email_type = !empty($params['email_type']) ? $params['email_type'] : 'misc'; $meta_key = !empty($params['meta_key']) ? $params['meta_key'] : "Misc-{$sid}-{$time}"; $hash = make_hash(array_merge(array('sid' => $sid), $params)); $from = !empty($params['fromemail']) ? $params['fromemail'] : !empty($newsletter->fromemail) ? $newsletter->fromemail : get_bloginfo('admin_email'); $parameters = array('from' => $from, 'fromname' => $fromname, 'to' => $subscriber->email, 'reply_to' => $reply_to, 'subject' => $subject, 'htmlbody' => $htmlbody, 'textbody' => $textbody, 'headers' => '', 'htmlenabled' => $htmlenabled, 'delivery_type' => $delivery_type, 'email_type' => $email_type, 'meta_key' => $meta_key, 'hash' => $hash); return $parameters; }
public function actionSend($id) { $model = $this->loadModel($id); if (isset($_POST['Massmail'])) { $model->attributes = $_POST['Massmail']; if (empty($model->groups)) { $mailList = Subscriber::model()->findAll(array('condition' => 'confirmed=1 AND enabled=1')); } else { $mailList = Subscriber::model()->findAll(array('condition' => 'FIND_IN_SET(' . $model->groups . ', groups)>0 AND confirmed=1 AND enabled=1')); } $bccList = null; $total = array_filter($mailList); if (!empty($total)) { //get email lists foreach ($mailList as $values) { $bccList .= $values['email'] . ','; } //send mail $to = Yii::app()->params['adminEmail']; $subject = $model->subject; $message = $model->message_body; $fromName = Yii::app()->params['Companyname']; $fromMail = Yii::app()->params['adminEmail']; Massmail::sendMail($to, $subject, $message, $fromName, $fromMail, $bccList); Yii::app()->user->setFlash('success', 'Mail has been sent successfully!'); $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('error', 'No subscriber found in this group!'); $this->redirect(array('admin')); } } $this->render('send', array('model' => $model)); }
public static function newInstance() { if (!self::$instance instanceof self) { self::$instance = new self(); } return self::$instance; }
public function getRecharge() { $accounts = Subscriber::where('is_admin', 0)->where(function ($query) { $query->where('plan_type', PREPAID_PLAN)->orWhere('plan_type', FREE_PLAN); })->orderby('uname')->lists('uname', 'id'); return View::make('admin.refill_coupons.recharge')->with('accounts', $accounts); }
/** * Send an email with an activation link to verify the subscriber is the owner of the email address. * * @throws InvalidArgumentException * @throws Exception * * @return bool */ protected function sendActivationMail(Subscriber $subscriber) { try { $from = sfNewsletterPluginConfiguration::getFromEmail(); $mailer = new Swift(new Swift_Connection_NativeMail()); $message = new Swift_Message(sfConfig::get('sf_newsletter_plugin_activation_mail_subject', 'Newsletter Subscription'), $this->getPartial('activation_mail', array('subscriber' => $subscriber)), 'text/html'); $sent = $mailer->send($message, $subscriber->getEmail(), $from); $mailer->disconnect(); return $sent === 1; } catch (Exception $e) { if (!empty($mailer)) { $mailer->disconnect(); } throw $e; } }
/** * @param bool $refresh * * @return Channel[] */ public function getChannels($refresh = false) { if ($this->_channels && !$refresh) { return $this->_channels; } return $this->_channels = $this->getDbDriver()->findByAttributes(array('subscriber_id' => $this->id), Subscriber::model()); }
public function run() { $faker = Faker::create(); foreach (range(1, 30) as $index) { $created = $faker->dateTimeThisYear; Subscriber::create(array('subscriberName' => $faker->name, 'subscriberEmail' => $faker->email, 'created_at' => $created)); } }
public function saveData($aSubscriberData) { $oSubscriber = SubscriberQuery::create()->findPk($this->iSubscriberId); if ($oSubscriber === null) { $oSubscriber = new Subscriber(); $oSubscriber->setCreatedBy(Session::getSession()->getUserId()); $oSubscriber->setCreatedAt(date('c')); } $oSubscriber->setPreferredLanguageId($aSubscriberData['preferred_language_id']); $oSubscriber->setName($aSubscriberData['name']); $oSubscriber->setEmail($aSubscriberData['email']); $this->validate($aSubscriberData, $oSubscriber); if (!Flash::noErrors()) { throw new ValidationException(); } // Subscriptions foreach ($oSubscriber->getSubscriberGroupMemberships() as $oSubscriberGroupMembership) { $oSubscriberGroupMembership->delete(); } $aSubscriptions = isset($aSubscriberData['subscriber_group_ids']) ? $aSubscriberData['subscriber_group_ids'] : array(); foreach ($aSubscriptions as $iSubscriberGroupId) { $oSubscriberGroupMembership = new SubscriberGroupMembership(); $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId); $oSubscriber->addSubscriberGroupMembership($oSubscriberGroupMembership); } return $oSubscriber->save(); }
/** * Get matched users with limit 10 * @param string $qry * @return array */ public function find($qry, $catid, $tid) { $cid = (int) $catid; $tid = (int) $tid; $selector = ''; if ($cid) { $selector = ', MAX(p.granted) AS allowed'; } $users = \DB::table(PREFIX . 'codo_users AS u'); $users->select(\DB::raw('u.id, u.username, u.avatar' . $selector))->where('u.username', 'LIKE', "{$qry}%")->where('u.mail', '<>', 'anonymous@localhost'); if ($cid) { $users->leftJoin(PREFIX . 'codo_user_roles AS r', 'r.uid', '=', 'u.id')->leftJoin(PREFIX . 'codo_permissions AS p', function ($join) use($cid) { $join->on('p.permission', '=', \DB::raw('\'view all topics\''))->on('p.rid', '=', 'r.rid')->on('p.cid', '=', \DB::raw($cid))->on('p.tid', '=', \DB::raw(0)); })->groupBy('u.id'); } $users = $users->take(10)->get(); $type = ''; if ($cid) { $type = 'new_topic'; } if ($tid) { $type = 'new_reply'; } $mutedIds = array(); if ($type != '' && count($users)) { $uids = array_column($users, 'id'); $subscriber = new Subscriber(); $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $uids); } $_users = array(); $i = 0; foreach ($users as $user) { $_users[$i]["username"] = $user['username']; $_users[$i]["avatar"] = \CODOF\Util::get_avatar_path($user['avatar'], $user['id'], false); if ($cid) { //if $cid is not provided can't say whether user is mentionable or not $notMentionable = in_array($user['id'], $mutedIds) || $user['allowed'] === 0; $_users[$i]["mentionable"] = !$notMentionable ? 'yes' : 'no'; //better for js -> y/n } $i++; } return $_users; }
function print_form($post_data, $errors) { $sub = new Subscriber(); try { $msisdn = $_GET['id']; $sub->get($msisdn); } catch (SubscriberException $e) { echo "<img src='img/false.png' width='200' height='170' /><br/><br/>"; echo "<span style='font-size: 20px; color: red;'>" . _("ERROR GETTING SUBSCRIBER INFO!") . "<br/> " . $e->getMessage() . " </span><br/><br/><br/><br/>"; echo "<a href='#' onclick=\"parent.jQuery.fancybox.close()\"><button class='b1'>" . _("Close") . "</button></a>"; } ?> <br/> <div id="stylized" class="myform"> <form id="form" name="form" method="post" action="subscriber_delete.php"> <h1><?php echo _("Delete Subscriber"); ?> </h1><br/> <input type="hidden" name="msisdn" value="<?php echo $sub->msisdn; ?> " /> <?php echo _("Confirm deletion of"); ?> <?php echo $sub->name; ?> <?php echo $sub->msisdn; ?> <button type="submit" name="delete_subscriber"><?php echo _("Delete"); ?> </button> <div class="spacer"></div> </form> </div> <?php }
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.'; } }
public function doApplySubscriber() { $validator = Validator::make(array('email' => trim(Input::get('email'))), array('email' => 'required|email|min:6|max:32')); if ($validator->fails()) { return Response::json(array('status' => false)); } $existed = Subscriber::where('email', trim(Input::get('email')))->first(); if ($existed) { return Response::json(array('status' => false, 'exist' => true)); } Subscriber::create(array('email' => trim(Input::get('email')))); return Response::json(array('status' => true)); }
public function send_email($dummy) { $rules = array('from_name' => 'required|max:128', 'from_email' => 'required|email|max:255', 'subject' => 'required|max:128', 'emailbody' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Response::json(array('validation' => $validator->messages()->toArray())); } else { $from_name = Input::get('from_name'); $from_email = Input::get('from_email'); $selected = Input::get('to'); $subject = Input::get('subject'); $emailbody = Input::get('emailbody'); $from = $from_name . ' (' . $from_email . ')'; $recipients = Subscriber::whereIn('email', $selected)->where('active', '=', 1)->get(); $email = new Email(); $email->from = $from; $email->subject = $subject; $email->message = $emailbody; $email->save(); $email_id = $email->id; $numrecipients = $recipients->count(); $numsent = 0; foreach ($recipients as $key => $recipient) { $tracker = new Tracker(); $tracker->subscriber_id = $recipient->id; $tracker->email_id = $email_id; $tracker->save(); $tracker_id = $tracker->id; $tracker_url = URL::to('tracker/' . $tracker_id); $unsubscriber_url = URL::to('unsubscribe/' . $tracker_id); $subscriber = $recipient; $data = array('emailbody' => $emailbody, 'tracker' => $tracker_url, 'unsubscribe' => $unsubscriber_url, 'subscriber' => $subscriber); $to_email = $subscriber->email; $to_name = $subscriber->first_name . ' ' . $subscriber->last_name; $issent = Mail::send('emails.sub-emails', $data, function ($message) use($from_email, $from_name, $to_email, $to_name, $subject) { $message->from($from_email, $from_name)->to($to_email, $to_name)->subject($subject); }); if ($issent) { $numsent += 1; } else { $tracker->bounced = 1; $tracker->save(); } } if ($numsent == $numrecipients) { return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . ' subscribers you selected. <b>Rejoice!</b>')); } else { return Response::json(array('success' => 'Your email was successfully sent to <b>' . $numsent . '</b> subscribers out of the ' . $numrecipients . 'All bounces have been logged.')); } } }
protected function doJob($arg) { $models = Newsletter::model()->findAll(array('condition' => 't.remain_subscribers IS NOT NULL AND length(t.remain_subscribers) > 0 AND t.send_time <= NOW()', 'order' => 't.id ASC')); foreach ($models as $model) { $mail_models = ProNewsletterMail::model()->findAll(array('condition' => 't.newsletter_id = ' . $model->id, 'order' => 't.id ASC')); if (count($mail_models)) { $receivers = explode(',', $model->remain_subscribers); $subscriber_count = 0; foreach ($mail_models as $key => $k) { $revei = array_shift($receivers); // need update this field $s = Subscriber::model()->getSubscriberByEmail($k->email); if (empty($s)) { continue; } if ($s) { if ($s->status == 0) { continue; } } // add by Nguyen Dung $url = Yii::app()->setting->getItem('server_name') . '/site/track_newsletter?newsletter_id=' . $model->id . '&subscriber_email=' . $s->email; $img_track_read_email = '<img src="' . $url . '" alt="" height="1" width="1"/>'; $r = array('subject' => $model->subject, 'params' => array('content' => $model->content . $img_track_read_email, 'newsletterName' => Yii::app()->params['title'], 'unsubscribe' => Yii::app()->setting->getItem('server_name') . '/site/unsubscribe?id=' . $s->id . '&code=' . md5($s->id . $s->email)), 'view' => 'newsletter', 'to' => $s->email, 'from' => Yii::app()->params['autoEmail']); $this->data[] = $r; //Delete record in newsletter mail ProNewsletterMail::model()->deleteByPk($k->id); $subscriber_count++; //count subscriber is served for current newsletter job $this->index++; //count email is sent for current cron job if ($this->index >= $this->max) { break; } } $model->total_sent = $model->total_sent + $subscriber_count; // track amount mail sent $model->remain_subscribers = implode(',', $receivers); $model->update(array('remain_subscribers', 'total_sent')); } } //when sent all subscriber of a newsletter job but the // if($this->index < $this->max) // $this->doJob($arg); }
public function postSelfRegister() { $input = Input::only('uname', 'pword', 'pword_confirmation', 'status', 'fname', 'lname', 'email', 'address', 'contact'); $rules = Config::get('validations.accounts'); $rules['uname'][] = 'unique:user_accounts'; $rules['pword'][] = 'confirmed'; $v = Validator::make($input, $rules); $v->setAttributeNames(Config::get('attributes.accounts')); if ($v->fails()) { return Redirect::back()->withInput()->withErrors($v); } $input['plan_type'] = PREPAID_PLAN; $input['clear_pword'] = $input['pword']; $input['pword'] = Hash::make($input['pword']); $input['is_admin'] = 0; if (Subscriber::create($input)) { Session::flash('success', 'succeed'); } return Redirect::back(); }
/** addSubscibers() * @param array of email addresses to be added, if they don't exist * @param string number of target subscriber group * description: * • subscribers are added if they don't exist * • subscriber_group_membership is added if it does'nt exist * * @return array of integer received all / actually added */ public function addSubscibers($aSubscribers, $mTargetSubscriberGroup) { $sSubscribers = ''; $aTargetSubscriberGroups = is_array($mTargetSubscriberGroup) ? $mTargetSubscriberGroup : array($mTargetSubscriberGroup); // If is string the addresses have not been processed and validated by js if (is_string($aSubscribers)) { // preg_match_all, use $sSubscribers = trim($aSubscribers); $aSubscribers = array(); $sSubscribers = preg_replace_callback('/' . Flash::$EMAIL_CHECK_PATTERN . '/', function ($aMatches) use(&$aSubscribers) { $aSubscribers[] = $aMatches[0]; return ''; }, $sSubscribers); } $aSubscribers = array_unique($aSubscribers); $iCountAll = count($aSubscribers); $iMembershipsAdded = 0; // Always create temporary groups with all imported subscribers $oSubscriberGroup = new SubscriberGroup(); $oSubscriberGroup->setName(self::GENERATED_PREFIX . date('Ymd-Hs')); $oSubscriberGroup->save(); array_push($aTargetSubscriberGroups, $oSubscriberGroup->getId()); foreach ($aSubscribers as $sEmail) { $oSubscriber = SubscriberQuery::create()->filterByEmail($sEmail)->findOne(); // Create new if subscriber does not exist and email is correct if ($oSubscriber === null) { $oSubscriber = new Subscriber(); $oSubscriber->setEmail($sEmail); $oSubscriber->setName($sEmail); } // Add subscriber_group_membership if it does not exists // @todo check change jm > handle multiple groups including generated one // Please check meaning and function of counting new subscriptions, only one is counted per subsriber $iMembershipsAdded $bHasMemberShip = false; foreach ($aTargetSubscriberGroups as $iSubscriberGroupId) { if (!$oSubscriber->hasSubscriberGroupMembership($iSubscriberGroupId)) { $bHasMemberShip = true; $oSubscriberGroupMembership = new SubscriberGroupMembership(); $oSubscriberGroupMembership->setSubscriberGroupId($iSubscriberGroupId); $oSubscriber->addSubscriberGroupMembership($oSubscriberGroupMembership); } } if ($bHasMemberShip) { $iMembershipsAdded++; } $oSubscriber->save(); } return array('all' => $iCountAll, 'added' => $iMembershipsAdded, 'text' => $sSubscribers); }
// $this->render('admin_user/myprofile', // array('model'=>$mUser) // ); // // } catch (Exception $exc) { // echo $exc->getMessage(); // } // } /** * <Jason> * <My profile of normal user> */ public function actionMyprofile() { try { if (Yii::app()->user->role_id == ROLE_AGENT) { $this->redirect(Yii::app()->createAbsoluteUrl('member/agent/myprofile')); } $this->pageTitle = 'My Profile - ' . Yii::app()->params['title']; $this->layout = 'application.views.layouts.layout_user'; $mUser = Users::model()->findByPk(Yii::app()->user->id); $mUser->scenario = 'myprofile'; if (isset($_POST['Users'])) { $mUser->attributes = $_POST['Users']; if ($mUser->validate()) { if ($_POST['Users']['newpassword'] != null && $_POST['Users']['password_confirm'] != null) { if ($mUser->password_hash == md5($_POST['Users']['newpassword'])) { $mUser->addError('newpassword', 'New password cannot be duplicate with current password.'); } else { $mUser->password_hash = md5(trim($_POST['Users']['newpassword'])); $mUser->temp_password = $_POST['Users']['newpassword']; } } if (!$mUser->getErrors()) { $mUser->is_subscriber = $_POST['Users']['is_subscriber']; if ($mUser->is_subscriber) { Subscriber::saveSubscriberUser($mUser->id); } else { Subscriber::updateSubscriberUser($mUser->id); } if ($mUser->save('title', 'first_name', 'password_hash', 'temp_password', 'last_name', 'phone', 'country_id', 'address', 'address2', 'postal_code', 'issubcriber')) { Yii::app()->user->setFlash('success', "My Profile has changed!");
public function actionSynchronize() { set_time_limit(7200); $idNameGroup = array(); $criteria = new CDbCriteria(); $mSubG = SubscriberGroup::model()->findAll($criteria); if (count($mSubG) > 0) { foreach ($mSubG as $i) { $idNameGroup[$i->id] = $i->name; } } $criteria = new CDbCriteria(); $criteria->addCondition('subscriber_group_id = 1 OR subscriber_group_id = 2'); $mSubscriber = Subscriber::model()->findAll($criteria); //var_dump($mSubscriber); $test = array(); if (count($mSubscriber) > 0) { Yii::import('ext.MailChimp.MailChimp', true); foreach ($mSubscriber as $item) { $mailChimp = new MailChimp(); // $mailChimp->removeSubscriber('*****@*****.**'); // die; $sGroupName = Yii::app()->params['mailchimp_title_groups']; $sGroup = strtolower($idNameGroup[$item->subscriber_group_id]); $merge_vars = array('GROUPINGS' => array(array('name' => $sGroupName, 'groups' => $sGroup))); if ($item->status == 1) { // echo '<pre>'; //echo print_r($merge_vars); //echo '</pre>'; //echo $item->email; //die(); $test[] = $mailChimp->addSubscriber($item->email, $merge_vars); } else { $mailChimp->removeSubscriber($item->email); } } } Yii::app()->user->setFlash('mailchimp', "Synchronize Mailling list successfully!"); $this->redirect(Yii::app()->createAbsoluteUrl("admin/setting/mailchimp")); }
public function buildListSubscriberAdd($mNewsletter) { $newsletter_id = $mNewsletter->id; $send_time = $mNewsletter->send_time; $criteria = new CDbCriteria(); $criteria->compare('t.status', 1); $listIdSubsciber = ''; $totalSubscriber = 0; // if not select group => we get all subscriber => don't exist if (!isset($_POST['Newsletter']['newsletter_group_subscriber']) || count($_POST['Newsletter']['newsletter_group_subscriber']) < 1) { $subscribers = Subscriber::model()->findAll($criteria); foreach ($subscribers as $s) { $listIdSubsciber .= $s->id . ','; } $totalSubscriber = count($subscribers); } else { // if select group => we get all subscriber of this group $criteria->addInCondition('t.subscriber_group_id', $_POST['Newsletter']['newsletter_group_subscriber']); $subscribers = Subscriber::model()->findAll($criteria); $aRowInsert = array(); $tableName = ProNewsletterMail::model()->tableName(); foreach ($subscribers as $s) { $listIdSubsciber .= $s->id . ','; $new_model = new ProNewsletterMail(); $new_model->name = $s->name; $new_model->email = $s->email; $new_model->subscriber_group_id = $s->subscriber_group_id; $new_model->newsletter_id = $newsletter_id; $new_model->send_time = $send_time; $aRowInsert[] = "('{$new_model->name}',\n '{$new_model->email}',\n '{$new_model->subscriber_group_id}',\n '{$new_model->newsletter_id}',\n '{$new_model->send_time}'\n )"; } $totalSubscriber = count($subscribers); if (count($aRowInsert)) { $sql = "insert into {$tableName} (name,\n email,\n subscriber_group_id,\n newsletter_id,\n send_time\n ) values " . implode(',', $aRowInsert); ProNewsletterMail::model()->deleteAll("newsletter_id={$mNewsletter->id}"); Yii::app()->db->createCommand($sql)->execute(); } } return array('listIdSubsciber' => $listIdSubsciber, 'totalSubscriber' => $totalSubscriber); }
public function postChangePassword() { $input = Input::all(); $admin = Subscriber::findOrFail(Auth::user()->id)->first(); if (!Hash::check($input['current'], $admin->pword)) { $this->notifyError("Invalid Current Password."); return Redirect::back(); } $rules = Config::get('validations.admin_password', NULL); $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::back()->withInput()->withErrors($v); } $admin->pword = Hash::make($input['password']); $admin->clear_pword = $input['password']; if ($admin->save()) { $this->notifySuccess("Admin Password Successfully Updated."); } else { $this->notifyError("Failed to update admin password, please try again.."); } return Redirect::back(); }
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; } }
/** * Resets all references to other model objects or collections of model objects. * * This method is a user-space workaround for PHP's inability to garbage collect * objects with circular references (even in PHP 5.3). This is currently necessary * when using Propel in certain daemon or large-volume/high-memory operations. * * @param boolean $deep Whether to also clear the references on all referrer objects. */ public function clearAllReferences($deep = false) { if ($deep && !$this->alreadyInClearAllReferencesDeep) { $this->alreadyInClearAllReferencesDeep = true; if ($this->aSubscriber instanceof Persistent) { $this->aSubscriber->clearAllReferences($deep); } if ($this->aSubscriberGroup instanceof Persistent) { $this->aSubscriberGroup->clearAllReferences($deep); } if ($this->aUserRelatedByCreatedBy instanceof Persistent) { $this->aUserRelatedByCreatedBy->clearAllReferences($deep); } if ($this->aUserRelatedByUpdatedBy instanceof Persistent) { $this->aUserRelatedByUpdatedBy->clearAllReferences($deep); } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) $this->aSubscriber = null; $this->aSubscriberGroup = null; $this->aUserRelatedByCreatedBy = null; $this->aUserRelatedByUpdatedBy = null; }
public function postChangePassword() { $user_id = Input::get('user_id', 0); $current = Input::get('current', NULL); $user = Subscriber::findOrFail($user_id); if ($user->clear_pword != $current) { $this->notifyError("Incorrect current password."); return Redirect::back(); } $password = Input::get('password', NULL); $confirm = Input::get('confirm_password', NULL); if ($password != $confirm) { $this->notifyError("New password & confirm password do not match."); return Redirect::back(); } $user->clear_pword = $password; $user->pword = Hash::make($password); if ($user->save()) { $this->notifySuccess("Password Updated."); } else { $this->notifyError("Password Updation Failed."); } return Redirect::back(); }
public function update($id) { $addressbook = Addressbook::find($id); $inputs = []; foreach (Input::all() as $key => $input) { $inputs[$key] = Jamesy\Sanitiser::trimInput($input); } if ($inputs['name'] == $addressbook->name) { $validation = NULL; } else { $validation = Jamesy\MyValidations::validate($inputs, $this->rules); } if ($validation != NULL) { return Redirect::back()->withErrors($validation)->withInput(); } else { $addressbook->name = $inputs['name']; $addressbook->active = $inputs['active']; $addressbook->save(); if ($addressbook->active == 0) { $subscribers = Subscriber::with(['addressbooks' => function ($query) use($id) { $query->where('addressbook_id', $id); }])->get(); foreach ($subscribers as $subscriber) { $subscriber->active = 0; $subscriber->save(); } } return Redirect::to('dashboard/lists')->withSuccess($addressbook->active == 0 ? 'List updated. NOTE: All subscribers in the list are now inactive.' : 'List updated.'); } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Subscriber $obj A Subscriber object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null SubscriberPeer::$instances[$key] = $obj; } }