Beispiel #1
0
 public function actionShare($type = 'share')
 {
     // TODO add check owner
     if (($type == 'assign' || $type == 'dassign') && !(Yii::app()->user->permissions == 2 || Yii::app()->user->permissions == 3)) {
         Yii::app()->user->setFlash('notify', array('type' => 'danger', 'message' => Yii::t('cams', 'Not allowed for you')));
         $this->redirect(array('manage'));
         Yii::app()->end();
     }
     if ($type == 'dassign' || $type == 'dshare') {
         $this->double = 1;
     }
     $form = new ShareForm();
     $form->type = $type;
     if (isset($_POST['ShareForm'])) {
         $form->attributes = $_POST['ShareForm'];
         if ($form->validate() && $form->save()) {
             Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('cams', 'Cam successfully shared')));
             $this->redirect(array('manage'));
             Yii::app()->end();
         }
     }
     if (Yii::app()->user->hasFlash('share')) {
         $cams = Yii::app()->user->getFlash('share');
         $cams = array_keys(array_filter($cams));
         $form->cams = join(', ', array_map(array($this, 'compileCams'), $cams));
         $form->hcams = join(',', array_map(array($this, 'compileHCams'), $cams));
     }
     $this->render('share', array('model' => $form, 'type' => $type));
 }
 public function actionEmail()
 {
     if (Yii::app()->user->isGuest) {
         _xls_404();
     }
     $model = new ShareForm();
     if (isset($_POST['ShareForm'])) {
         $model->attributes = $_POST['ShareForm'];
         if ($model->validate()) {
             $strCode = $model->code;
             //Make sure code we've been passed is valid
             $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode));
             if (!$objWishlist->Visible) {
                 _xls_404();
             }
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::model()->findByPk(Yii::app()->user->Id);
                 $model->fromEmail = $objCustomer->email;
                 $model->fromName = $objCustomer->fullname;
             }
             $strHtmlBody = $this->renderPartial('/mail/_cart', array('model' => $model), true);
             $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_WISHLIST', $objWishlist->customer->fullname, null);
             $objEmail = new EmailQueue();
             $objEmail->customer_id = $objWishlist->customer_id;
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $objEmail->to = $model->toEmail;
             $objHtml = new HtmlToText();
             //If we get back false, it means conversion failed which 99.9% of the time means improper HTML.
             $strPlain = $objHtml->convert_html_to_text($strHtmlBody);
             if ($strPlain !== false) {
                 $objEmail->plainbody = $strPlain;
             }
             $objEmail->save();
             $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Your wish list has been sent'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true);
         } else {
             $response_array['status'] = 'error';
             $response_array['errormsg'] = _xls_convert_errors($model->getErrors());
         }
         echo json_encode($response_array);
     }
 }
 /**
  * Email a cart to a recipient email address
  */
 public function actionEmail()
 {
     $model = new ShareForm();
     if (isset($_POST['ShareForm'])) {
         $model->attributes = $_POST['ShareForm'];
         if (Yii::app()->user->isGuest) {
             $model->setScenario('guest');
         } else {
             $model->setScenario('loggedin');
         }
         if ($model->validate()) {
             $strCode = $model->code;
             //Make sure code we've been passed is valid
             $objCart = Cart::model()->findByAttributes(array('linkid' => $strCode));
             if (!$objCart instanceof Cart) {
                 _xls_404();
             }
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::model()->findByPk(Yii::app()->user->Id);
                 $model->fromEmail = $objCustomer->email;
                 $model->fromName = $objCustomer->fullname;
             }
             $strHtmlBody = $this->renderPartial('/mail/_cart', array('model' => $model), true);
             $strSubject = _xls_format_email_subject('EMAIL_SUBJECT_CART', $model->fromName, null);
             $objEmail = new EmailQueue();
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $objEmail->to = $model->toEmail;
             $objEmail->save();
             $response_array = array('status' => "success", 'message' => Yii::t('wishlist', 'Your cart has been sent'), 'url' => CController::createUrl('site/sendemail', array("id" => $objEmail->id)), 'reload' => true);
         } else {
             $response_array['status'] = 'error';
             $response_array['errormsg'] = _xls_convert_errors($model->getErrors());
         }
         $this->renderJSON($response_array);
     }
 }