예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Gift();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Gift'])) {
         $model->attributes = $_POST['Gift'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
예제 #2
0
 public function insertData()
 {
     $gifts = json_decode(file_get_contents(app_path() . '/storage/gifts.txt'));
     $topics = json_decode(file_get_contents(app_path() . '/storage/topics.txt'));
     $gift_posters = json_decode(file_get_contents(app_path() . '/storage/gift_posters.txt'));
     $gift_photo_intros = json_decode(file_get_contents(app_path() . '/storage/gift_photo_intros.txt'));
     foreach ($topics as $topic) {
         $t = new Topic();
         $t->id = $topic->id;
         $t->title = $topic->title;
         $t->content = $topic->content;
         $t->topic_url = $topic->topic_url;
         if (!$t->save()) {
             return 'topic_false';
         }
     }
     foreach ($gifts as $gift) {
         $g = new Gift();
         $g->id = $gift->id;
         $g->topic_id = $gift->topic_id;
         $g->title = $gift->title;
         $g->price = $gift->price;
         $g->content = $gift->content;
         if (!$g->save()) {
             return 'gift_false';
         }
     }
     foreach ($gift_posters as $gift_poster) {
         $tp = new GiftPoster();
         $tp->gift_id = $gift_poster->gift_id;
         $tp->url = $gift_poster->url;
         if (!$tp->save()) {
             return 'gift_poster_false';
         }
     }
     foreach ($gift_photo_intros as $gift_photo_intro) {
         $gpi = new GiftPhotoIntro();
         $gpi->gift_id = $gift_photo_intro->gift_id;
         $gpi->url = $gift_photo_intro->url;
         if (!$gpi->save()) {
             return 'gift_photo_intro_false';
         }
     }
     return Response::json(array('errCode' => 0, 'message' => '插入成功'));
 }
예제 #3
0
 public function actionConfirmsuccess()
 {
     //Check for user action (if the user has already filled in his details or not)
     if (isset($_SESSION) && isset($_SESSION['userRegisterVal']) && $_SESSION['userRegisterVal']['email'] != '') {
         $this->layout = "homeinner";
         $modelUser = new Users();
         $modelGifts = new Gift();
         // for saving model users data through session value....
         $modelUser->first_name = $_SESSION['userRegisterVal']['first_name'];
         $modelUser->last_name = $_SESSION['userRegisterVal']['last_name'];
         $modelUser->email = $_SESSION['userRegisterVal']['email'];
         $modelUser->address1 = $_SESSION['userRegisterVal']['address1'];
         $modelUser->suburb = $_SESSION['userRegisterVal']['suburb'];
         $modelUser->country = $_SESSION['country'];
         if ($_SESSION['userRegisterVal']['region'] && $_SESSION['userRegisterVal']['region'] != "") {
             $modelUser->region = $_SESSION['userRegisterVal']['region'];
         } else {
             $modelUser->region = $_SESSION['region'];
         }
         $modelUser->postcode = $_SESSION['userRegisterVal']['postcode'];
         $modelUser->unique_code = $_SESSION['unique_code'];
         $modelUser->date_created = $_SESSION['date_created'];
         $modelUser->date_modified = $_SESSION['date_modified'];
         $modelUser->status = $_SESSION['status'];
         $modelUser->save();
         // for saving model users data ends here....
         //for getting lastInserted ID of User model....
         $max = Yii::app()->db->getLastInsertId();
         // for saving model "Gift" data....
         $modelGifts->user_id = $modelUser->id;
         $modelGifts->size = $_SESSION['size'];
         $modelGifts->custom_msg = $_SESSION['userCustomizeVal']['custom_msg'];
         $modelGifts->created = $_SESSION['date_created'];
         $modelGifts->modified = $_SESSION['date_modified'];
         if (isset($_SESSION['imagesrc']) && $_SESSION['imagesrc'] != "") {
             $img_info = getimagesize($_SESSION['imagesrc']);
             // print_r($img_info);  die();
             if ($img_info['mime'] == 'image/png') {
                 //for saving image into directory
                 $content = file_get_contents($_SESSION['imagesrc']);
                 $name = md5($_SESSION['userRegisterVal']['first_name'] . $_SESSION['userRegisterVal']['last_name']) . time() . '.png';
                 $imagename = $name;
                 file_put_contents('tshirt/' . $imagename, $content);
                 $_SESSION['jersey_mockup'] = $imagename;
                 //for saving image into directory
             } else {
                 unlink('tshirt/' . $imagename);
             }
         } else {
             $_SESSION['jersey_mockup'] = $_SESSION['anotherimagesrc'];
         }
         $modelGifts->jersey_mockup = $_SESSION['jersey_mockup'];
         $modelGifts->status = $_SESSION['statusGift'];
         $modelGifts->shared = 0;
         /*if data in both Model will be saved......*/
         // for saving data through transaction process
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if (!$modelUser->save()) {
                 $transaction->rollback();
                 return false;
             }
             if (!$modelGifts->save()) {
                 $transaction->rollback();
                 return false;
             }
             $transaction->commit();
             Yii::app()->user->setFlash('successmessage', 'You are registered properly');
             $_SESSION['giftId'] = $modelGifts->id;
             $userEmail = $modelUser->email;
             $userFname = $modelUser->first_name;
             //for sending email to users registered
             $message = new YiiMailMessage();
             //this points to the file thanks.php inside the view path
             $message->view = "thanks";
             $params = array('name' => $userFname);
             $message->subject = 'Thanks for registering for your customised EA SPORTS Football Club Jersey';
             $message->setBody($params, 'text/html');
             $message->addTo($userEmail);
             $message->from = '*****@*****.**';
             Yii::app()->mail->send($message);
             //for sending email to users registered ends here
             $this->redirect(array('confirm'));
             //for sending values to fbshare page
             $userGiftId = $modelGifts->id;
             // for sending values to fbshare page
             $giftLastValue = Gift::model()->findByAttributes(array('id' => $userGiftId));
             // for sending values to fbshare page
             $this->render('finalconfirmed', array('modelUser' => $modelUser, 'maxIdGift' => $userGiftId, 'giftLastValue' => $giftLastValue));
         } catch (Exception $ex) {
             $transaction->rollback();
             return false;
             Yii::app()->user->setFlash('failmessage', 'Please fill the form properly again');
         }
     } else {
         //Redirect to home page
         $this->redirect('../index.php', '');
     }
 }