示例#1
0
 public static function getCurrentAccess()
 {
     $link = User2property::model()->find('userId=:userId AND propertyId=:propertyId', array(':userId' => Yii::app()->user->getState('id'), ':propertyId' => Yii::app()->user->getState('propertyId')));
     if (!$link) {
         return 1000;
     }
     return $link->getAttribute('access');
 }
 /**
  *
  * @param usersData $data
  * @return type 
  */
 public function createSignUp($data)
 {
     $format = $data->format;
     if ($format == 'doc') {
         $body = $this->renderPartial('auth/doc', array(), true);
         return $this->response->type('json')->goodResponse($body);
     }
     $tutModel = new Tutorial();
     $propModel = new Properties();
     $userModel = new Users();
     $user2PropertyModel = new \User2property();
     $transaction = $propModel->dbConnection->beginTransaction();
     $propertie = $propModel->createNewProperie($data->propertie, $data->PP_TRIAL);
     $tutModel->save();
     $tutorial = $tutModel->id;
     if ($propertie !== false || $tutorial !== false) {
         $data->property_id = $propertie;
         $data->tutorial_id = $tutorial;
         $user = $userModel->createNewUser((array) $data);
         if ($user !== false) {
             $color = 'type1';
             $bName = $data->firstname . ' ' . $data->lastname;
             $user2PropertyModel->unsetAttributes();
             $user2PropertyModel->setAttributes(array('userId' => $user, 'propertyId' => $propertie, 'access' => self::OWNER, 'status' => self::STATUS_ACTIVE, 'color' => 'type1', 'bookingName' => $bName));
             if ($user2PropertyModel->save()) {
                 $transaction->commit();
                 $result = true;
             } else {
                 $transaction->rollback();
                 $result = false;
             }
         } else {
             $transaction->rollback();
             $result = false;
         }
     } else {
         $transaction->rollback();
         $result = false;
     }
     $view = !$result ? 'signup/error' : 'signup/done';
     $body = $this->renderPartial($view, array('format' => $format), true);
     return $this->response->type('json')->goodResponse($body);
 }
 protected function getPropertyMembers()
 {
     $user2ProperyModel = new User2property();
     $property_id = $this->propertyId;
     $resultsModels = $user2ProperyModel->findAllByAttributes(array('propertyId' => $property_id));
     $results = array();
     foreach ($resultsModels as $key => $resultModel) {
         if ($resultModel->getAttribute('access') <= UserAccessTable::BASIC_ACCESS && $resultModel->getAttribute('status') == UserAccessTable::STATUS_ACTIVE) {
             $results[$key] = $resultModel->getAttributes();
             $results[$key]['user'] = $resultModel->user->getAttributes();
         }
     }
     return $results;
 }
示例#4
0
 public function actionRemoveproperty($id)
 {
     $userId = Yii::app()->user->getState('id');
     //all users can remove itself from property member's list
     if (!UserAccessTable::checkUser2PropertyAccess($userId, $id, UserAccessTable::GUEST)) {
         Yii::app()->request->redirect(basePath('app/gallery'));
     }
     $user2property = User2property::model()->findByAttributes(array('userId' => $userId, 'propertyId' => $id));
     if ($user2property->getAttribute('access') != UserAccessTable::OWNER) {
         //email to member (NOT admin)
         $this->layout = "emailmaster";
         $body = $this->render("../emails/emailItselfRemove", array('name' => $user2property->user->getAttribute('firstname') . ' ' . $user2property->user->getAttribute('lastname'), 'propertyName' => $user2property->property->getAttribute('property_name')), true);
         MailHelper::send($body, "SharedKey - Removed Property", array($user2property->user->getAttribute('email')));
         //clear calendar events first
         $calendar = new Calendar();
         $calendar = $calendar->findAllByAttributes(array('linkid' => $user2property->getAttribute('id')));
         foreach ($calendar as $cal) {
             $cal->delete();
         }
         //for not property Administrator we just remove a link to property
         $user2property->delete();
         if ($this->_isAllUserPropertiesDeactivated($userId)) {
             //removed last property need remove user
             $this->removeUser($userId);
             return;
         }
         Yii::app()->request->redirect(basePath('app/properties'));
         return;
     }
     //member is administrator we need cancel RecurringPaymentsProfile and deactivate property
     //lets find last transaction
     $transaction = Transaction::model()->findByAttributes(array('userid' => $userId, 'propertyid' => $id));
     if (!$transaction) {
         //no previous transactions not need to refund
     }
     $userApi = sharedkeyApi::create('usersAPI');
     $userEmail = Yii::app()->user->getState('email');
     $userApi->addParams(array('email' => $userEmail));
     $byEmail = json_decode($userApi->byEmail('get'));
     $userData = (array) $byEmail->data;
     $userData['property_id'] = $id;
     //close RecurringPaymentsProfile
     if ($transaction) {
         YII::app()->user->setState("addPropertyEmailed", true);
         $temp = PayPalHelper::cancelRecurringPaymentsProfile($transaction->getAttribute('pp_PROFILEID'), $userData);
     }
     //do deactivated
     $property = Properties::model()->findByPk($id);
     $property->isdeactivated = 1;
     $property->edt = new CDbExpression('NOW()');
     //$property->trialPeriodStartDate = null;
     $property->save();
     $this->layout = "emailmaster";
     //mail to admin
     $token = uniqid();
     $body = $this->render("../emails/emailAdminAfterRemove", array('name' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'url' => basePathByHost("/app/changeactiveproperty/" . $property->getAttribute("id")) . '?token=' . $token), true);
     MailHelper::send($body, "SharedKey - Removed Property", array($userEmail));
     //informative other user about property deactivated
     $users2properties = User2property::model()->with('user')->findAll('propertyId=:propertyId', array(':propertyId' => $id));
     foreach ($users2properties as $key => $u2p) {
         if ($u2p->getAttribute('access') == UserAccessTable::OWNER) {
             continue;
         }
     }
     if ($this->_isAllUserPropertiesDeactivated($userId)) {
         $user = User::model()->find('id=:id', array(':id' => $userId));
         $user->verificationToken = $token;
         $user->save();
         $this->redirect(basePath('user/logout'));
         return;
     }
     Yii::app()->request->redirect(basePath('app/properties'));
 }
 private function clearDataAfterSignUp()
 {
     $userId = Yii::app()->user->getState('id');
     $propertyId = Yii::app()->user->getState('propertyId');
     $tutorialId = Yii::app()->user->getState('tutorial_id');
     $u2p = User2property::model()->findByAttributes(array("userId" => $userId, "propertyId" => $propertyId));
     if ($u2p) {
         $u2p->delete();
     }
     $user = User::model()->findByPk($userId);
     if ($user) {
         $user->delete();
     }
     $tut = TutorialModel::model()->findByPk($tutorialId);
     if ($tut) {
         $tut->delete();
     }
 }
 public function actionBullingInformation()
 {
     $this->pageName = "billing";
     //        if (!Yii::app()->request->isPostRequest) {
     //            $this->redirect(basePath(''));
     //        }
     if (Yii::app()->user->isGuest) {
         Yii::app()->request->redirect(basePath(''));
     }
     //        if (UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), Yii::app()->user->getState('propertyId'), UserAccessTable::OWNER)) {
     //            $this->redirect(basePath(''));
     //            ;
     //        }
     $model = new PayPalPaymentModel();
     $model->setAttributes($_POST);
     $model->validate();
     $errors = $model->getErrors();
     if (count($errors) > 0) {
         $this->render('index', array('errors' => $errors, 'bull' => $model->attributes, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces()));
         return;
     }
     $userApi = sharedkeyApi::create('usersAPI');
     $userApi->addParams(array('email' => Yii::app()->user->getState('email'), 'format' => 'json'));
     $property = Properties::model()->findByPk(Yii::app()->user->getState('propertyId'));
     $byEmail = json_decode($userApi->byEmail('get'));
     $userData = (array) $byEmail->data;
     $userData['prop_name'] = $property ? $property->property_name : "";
     $response = PayPalHelper::createBullingRequest($model, $userData);
     if (!$response->status) {
         $errors['0'] = $response->errorMessage;
         $this->render('index', array('errors' => $errors, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces()));
         return;
     }
     //activate property
     $property->isdeactivated = 0;
     $property->trialPeriodStartDate = null;
     $property->edt = new CDbExpression('NOW()');
     $property->save();
     //update property Admin
     $user2property = User2property::model()->findByAttributes(array('propertyId' => $property->getAttribute('id'), 'access' => UserAccessTable::OWNER));
     if ($user2property->getAttribute('userId') != Yii::app()->user->getState('id')) {
         //need update property admin
         $user2property->access = UserAccessTable::FULL_ACCESS;
         $user2property->save();
         //find current payer link and set it to Admin mode
         $u2p = User2property::model()->findByAttributes(array('userId' => Yii::app()->user->getState('id'), 'propertyId' => $property->getAttribute('id')));
         $u2p->access = UserAccessTable::OWNER;
         $u2p->save();
     }
     $this->redirect(basePath('app/gallery'));
 }
示例#7
0
 public function actionInvite()
 {
     $newEvents = array();
     $propertyId = Yii::app()->user->getState('propertyId');
     if (isset($_POST['propId'])) {
         if (is_numeric($_POST['propId'])) {
             $propertyId = $_POST['propId'];
         }
     }
     if (!Yii::app()->request->isPostRequest) {
         echo json_encode(array('status' => 0, 'message' => 'Only Post request are allowed.'));
         die;
     }
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::BASIC_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     //check login
     if (Yii::app()->user->isGuest) {
         echo json_encode(array('status' => 0, 'message' => 'Please login.'));
         die;
     }
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::BASIC_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     $property = Properties::model()->findByPk($propertyId);
     $model = new InviteGuest();
     $model->setAttributes($_POST);
     //create user 2 property tables
     $u2propertyes = array();
     foreach ($model->emails as $key => $value) {
         $u2p = new User2property();
         $user = User::model()->findByAttributes(array('email' => $value));
         $newUserEmailBody = "";
         if ($user == null) {
             //need create new user
             if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                 continue;
             }
             $user = $this->createGuestUser($value, $model->names[$key], $propertyId);
             $this->layout = "emailmaster";
             $newUserEmailBody = $this->renderPartial('../emails/emailInviteNewGuest', array('userFullName' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'email' => $user->getAttribute('email'), 'access' => UserAccessTable::accessLevelToString(UserAccessTable::GUEST), 'password' => $user->getAttribute('password'), 'url' => basePathByHost('/')), true);
             // MailHelper::send($newUserEmailBody, "SharedKey.com - New Member Account", array($user->getAttribute('email')));
         } else {
             //we can use exist user
         }
         $checku2p = User2property::model()->findByAttributes(array('propertyId' => $propertyId, 'userId' => $user->getAttribute('id')));
         if ($checku2p != null) {
             echo json_encode(array('status' => 0, 'message' => 'User is already a member of this property.'));
             die;
         }
         $u2p->propertyId = $propertyId;
         $u2p->userId = $user->getAttribute('id');
         $u2p->access = UserAccessTable::GUEST;
         $u2p->status = UserAccessTable::STATUS_ACTIVE;
         $u2p->inviteDate = date('Y-m-d h:i:s');
         $fromDate = null;
         if (!empty($model->from)) {
             $fromDate = new DateTime($model->from);
             $u2p->fromDate = $fromDate->format('Y-m-d h:i:s');
         } else {
             $u2p->fromDate = null;
         }
         $toDate = null;
         if (!empty($model->to)) {
             $toDate = new DateTime($model->to);
             $u2p->toDate = $toDate->format('Y-m-d h:i:s');
         } else {
             $u2p->toDate = null;
         }
         $u2p->inviteUserId = Yii::app()->user->getState('id');
         $u2p->color = 'type13';
         $u2p->bookingName = $model->names[$key];
         $u2p->save();
         $this->layout = "emailmaster";
         $inviteEmail = $this->render('../emails/emailInvite', array('data' => array('fromName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'from' => isset($fromDate) ? $fromDate->format('F j, Y') : '-', 'to' => isset($toDate) ? $toDate->format('F j, Y') : '-', 'access' => UserAccessTable::accessLevelToString(UserAccessTable::GUEST), 'event' => $model->event, 'message' => nl2br($model->message), 'toUser' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'newUserBody' => $newUserEmailBody)), true);
         MailHelper::send($inviteEmail, "Sharedkey.com - Invitation to " . $property->getAttribute('property_name'), array($user->getAttribute('email')), "SharedKey.com", array(Yii::app()->user->getState('email')));
         $u2propertyes[$key] = $u2p;
         $username = $model->names[$key];
         $calendarEvent = new Calendar();
         $calendarEvent->create_date = $u2p->fromDate;
         $calendarEvent->end_date = $u2p->toDate;
         $calendarEvent->event = $_POST['event'];
         $calendarEvent->propertyid = $u2p->propertyId;
         $calendarEvent->notes = $model->message;
         $calendarEvent->linkid = $this->linkWithProperty->id;
         $calendarEvent->isguest = true;
         $calendarEvent->guestid = $u2p->userId;
         $calendarEvent->guestname = $model->names[$key];
         $result = $calendarEvent->save();
         $outputEvent = array("result" => true, "data" => (array) $calendarEvent->getAttributes(), "event" => $calendarEvent->event);
         $outputEvent['data']['link'] = (array) $u2p->getAttributes();
         array_push($newEvents, $outputEvent);
     }
     $users = array();
     foreach ($u2propertyes as $key => $u2p) {
         $users[$key] = $this->createViewItem($u2p);
     }
     echo json_encode(array('status' => 1, 'users' => $users, 'events' => $newEvents));
     die;
 }
示例#8
0
 public function actionSaveMember()
 {
     if (!Yii::app()->request->isPostRequest) {
         echo json_encode(array('status' => 0, 'message' => 'Only Post request are allowed.'));
         die;
     }
     if (Yii::app()->user->isGuest) {
         echo json_encode(array('status' => 0, 'message' => 'Only authorize user can allow this.'));
         die;
     }
     $member = new Member();
     $member->setAttributes($_POST);
     $member->validate();
     if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $member->propertyId, UserAccessTable::FULL_ACCESS)) {
         echo json_encode(array('status' => 0, 'message' => 'You can not do this action.'));
         die;
     }
     $errors = $member->getErrors();
     if (count($errors) > 0) {
         echo json_encode(array('status' => 0, 'errors' => $errors));
         die;
     }
     //get property
     $property = Properties::model()->findByPk($member->propertyId);
     //check new user in database
     $user = User::model()->findByAttributes(array('email' => $member->email));
     if ($user != null) {
         //system already contains user with some email
         $eu2p = User2property::model()->with('user')->findByAttributes(array('userId' => $user->getAttribute('id'), 'propertyId' => $member->propertyId));
         if ($eu2p != null) {
             echo json_encode(array('status' => 0, 'message' => 'User already exist.'));
             die;
         }
         $u2p = new User2property();
         $u2p->setAttribute('userId', $user->getAttribute('id'));
         $u2p->setAttribute('bookingName', $member->bookname);
         $u2p->setAttributes($member->attributes);
         $u2p->save();
         $this->layout = "emailmaster";
         $emailBody = $this->render('../emails/emailInviteMember', array('userFullName' => $user->getAttribute('firstname') . ' ' . $user->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'access' => UserAccessTable::accessLevelToString($member->access)), true);
         MailHelper::send($emailBody, "SharedKey.com - New Property Added to Your Account", array($user->getAttribute('email')));
         $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id'));
         echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp)));
         die;
     }
     $newUser = new User();
     $newUser->setAttributes($member->attributes);
     $password = PasswordGenerator::generatePassword();
     $newUser->setAttribute('password', $password);
     $newUser->setAttribute('property_id', $member->propertyId);
     $tutorialModel = new TutorialModel();
     $tutorialModel->setAttributes(array('gallery' => 1, 'guest_book' => 1, 'house_rules' => 1, 'key_contacts' => 1, 'mapdirections' => 1, 'notice_board' => 1, 'tourist_info' => 1));
     $tutorialModel->save();
     $newUser->setAttribute('tutorial_id', $tutorialModel->id);
     $newUser->setAttribute('status', 1);
     $newUser->setAttribute('createdDate', new CDbExpression('NOW()'));
     $newUser->save();
     $u2p = new User2property();
     $u2p->setAttribute('userId', $newUser->getAttribute('id'));
     $u2p->setAttribute('bookingName', $member->bookname);
     $u2p->setAttributes($member->attributes);
     $u2p->save();
     $this->layout = "emailmaster";
     $emailBody = $this->render('../emails/emailInviteNewMember', array('userFullName' => $newUser->getAttribute('firstname') . ' ' . $newUser->getAttribute('lastname'), 'senderFullName' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'email' => $newUser->getAttribute('email'), 'access' => UserAccessTable::accessLevelToString($member->access), 'password' => $password), true);
     MailHelper::send($emailBody, "Sharedkey.com - Invitation to " . $property->getAttribute('property_name'), array($newUser->getAttribute('email')));
     $temp = User2property::model()->with('user')->findByPk($u2p->getAttribute('id'));
     echo json_encode(array('status' => 1, 'member' => $this->createViewItem($temp)));
     die;
 }