Пример #1
0
 public function actionCreate($id = 0)
 {
     $model = new Message();
     $model->mglist_id = $id;
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Message'])) {
         $model->attributes = $_POST['Message'];
         $model->created_at = new CDbExpression('NOW()');
         $model->modified_at = new CDbExpression('NOW()');
         if ($model->save()) {
             Yii::app()->user->setFlash('messageSubmitted', 'Thank you, your message has been posted.');
             $lookup_item = Mglist::model()->findByPk($model->mglist_id);
             $yg = new Yiigun();
             $yg->send_simple_message($lookup_item['address'], $model->subject, $model->body, Yii::app()->params['superuser']);
             $this->redirect('/mglist/index');
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     $model = new Request();
     $mglist = Mglist::model()->findByPk($id);
     $model->list_id = $id;
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Request'])) {
         $model->mglist_id = $id;
         $model->attributes = $_POST['Request'];
         $model->checksum = 0;
         // unused now - prior rand(100,10000);
         $yg = new Yiigun();
         $model->hash = $yg->generateVerifyHash($model, $mglist);
         $res = $model->save();
         if ($model->save()) {
             $yg->sendVerificationRequest($model, $mglist);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('id' => $id, 'model' => $model, 'mglist' => $mglist));
 }
Пример #3
0
 public function getListOptions()
 {
     $listsArray = CHtml::listData(Mglist::model()->findAll(), 'id', 'name');
     return $listsArray;
 }
Пример #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionImport($id = 0)
 {
     $model = new Import();
     $model->mglist_id = $id;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Import'])) {
         $temp_email_list = $_POST['Import']['email_list'];
         include 'Mail/RFC822.php';
         $parser = new Mail_RFC822();
         // replace the backslash quotes
         $tolist = str_replace('\\"', '"', $temp_email_list);
         // split the elements by line and by comma
         $to_email_array = preg_split("(\r|\n|,)", $tolist, -1, PREG_SPLIT_NO_EMPTY);
         $num_emails = count($to_email_array);
         $temp = '';
         // construct bulk list of new members for mailgun api call
         $json_upload = '[';
         for ($count = 0; $count < $num_emails && $count <= 500; $count++) {
             $json_upload .= '{';
             $toAddress = trim($to_email_array[$count]);
             if ($toAddress != '') {
                 $addresses = $parser->parseAddressList('my group:' . $toAddress, 'yourdomain.com', false, true);
                 foreach ($addresses as $i) {
                     if ($i->mailbox != '' and $i->host != '') {
                         $temp .= $i->mailbox . '@' . $i->host . ',';
                     }
                     $m = new Member();
                     if ($i->personal != '') {
                         $m->name = $i->personal;
                         $json_upload .= '"name": "' . $m->name . '", ';
                     } else {
                         $m->name = '';
                     }
                     $m->address = $i->mailbox . '@' . $i->host;
                     $json_upload .= '"address": "' . $m->address . '"';
                     $m->status = 1;
                     $m->created_at = new CDbExpression('NOW()');
                     $m->modified_at = new CDbExpression('NOW()');
                     // echo $m->name.' '.$m->address.' ->'.$id.'<br />';
                     $lookup_item = Member::model()->findByAttributes(array('address' => $m->address));
                     if (!is_null($lookup_item)) {
                         // member exists
                         // echo 'exists'.$lookup_item['id'];
                         $m->addToList($lookup_item['id'], $id);
                     } else {
                         // new member
                         $m->save();
                         $last_id = Yii::app()->db->getLastInsertID();
                         // echo 'saved'.$last_id;
                         $m->addToList($last_id, $id);
                     }
                 }
             }
             $json_upload .= '},';
         }
         $temp = trim($temp, ',');
         $model->email_list = $temp;
         $json_upload = trim($json_upload, ',');
         $json_upload .= ']';
         if ($model->save()) {
             Yii::app()->user->setFlash('import_success', 'Thank you! Your messages have been submitted.');
             $yg = new Yiigun();
             // echo $json_upload;
             $list_item = Mglist::model()->findByPk($id);
             // echo $list_item['address'];
             $yg->memberBulkAdd($list_item['address'], $json_upload);
             $this->redirect('/mglist/' . $id);
         }
     }
     $this->render('import', array('model' => $model, 'mglist_id' => $id));
 }
Пример #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Mglist::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Пример #6
0
<?php

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'message-form', 'enableAjaxValidation' => false));
?>

	<p class="help-block">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

  <?php 
if ($model->mglist_id == 0) {
    echo CHtml::activeLabel($model, 'mglist_id', array('label' => 'Send to Mailing List:'));
    echo $form->dropDownList($model, 'mglist_id', Mglist::model()->getListOptions(), array('empty' => 'Select a List'));
} else {
    echo CHtml::hiddenField('mglist_id', $model->mglist_id);
}
?>

	<?php 
//  echo $form->textFieldRow($model,'mglist_id',array('class'=>'span5'));
?>

	<?php 
echo $form->textFieldRow($model, 'subject', array('class' => 'span5', 'maxlength' => 255));
?>

	<?php 
echo $form->textAreaRow($model, 'body', array('rows' => 6, 'cols' => 50, 'class' => 'span8'));
?>