/** * * @param type $property_id * @return boolean */ public static function changeActiveProperty($property_id) { $userId = Yii::app()->user->getState('id'); $userModel = new \User(); $isValidProperty = UserAccessTable::checkUser2PropertyAccess($userId, $property_id, UserAccessTable::GUEST); if (!$isValidProperty) { return false; } else { $result = $userModel->updateByPk($userId, array('property_id' => $property_id)); $userControl = new userControl(); $userControl->update(); return true; } }
public function actionIndex($propertyId) { $this->pageName = "billing"; if (Yii::app()->user->isGuest) { $this->redirect(basePath('?url=property/' . $propertyId)); } $this->updateActiveProperty($propertyId); $property = Properties::model()->findByPk($propertyId); YII::app()->user->setState("redirect_url", null); //$property->trialPeriodStartDate != null && if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::OWNER)) { Yii::app()->user->logout(); $this->redirect(basePath('?url=property/' . $propertyId)); } $adminMode = false; if (UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), Yii::app()->user->getState('property_id'), UserAccessTable::OWNER)) { $adminMode = true; } if ($property->getAttribute('isdeactivated') == 0 && $property->trialPeriodStartDate == null) { $this->redirect(basePath('app/properties')); } //TODO Live // $DaysAfterTrialWhenUserCanReturnProperty = 7; // $TrialPeriod = 31; if ($property->trialPeriodStartDate != null) { $DaysAfterTrialWhenUserCanReturnProperty = 2; $TrialPeriod = 2; $allDays = $DaysAfterTrialWhenUserCanReturnProperty + $TrialPeriod; $trialStartDate = new DateTime($property->trialPeriodStartDate); $trialStartDate->modify("+{$allDays} day"); $nowDate = new DateTime(); if ($trialStartDate->format("Y/m/d") < $nowDate->format("Y/m/d")) { $this->redirect(basePath('app/properties')); } } $this->render('index', array('errors' => null, 'adminMode' => $adminMode, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); }
Latest Login </th> <th> Created On </th> </tr> </thead> <tbody> <?php $count = 0; foreach ($guests as $guests) { ?> <tr> <td> <?php echo $guests['firstname'] . " " . $guests['lastname'] . " (" . UserAccessTable::accessLevelToString($guests['access']) . ")"; ?> </td> <td> <?php echo $guests['property']['property_name']; ?> </td> <td> <?php echo $guests['email']; ?> </td> <td> <?php echo $guests['property']['property_phone'];
protected function getAllProperties() { $propertiesModel = new \User2property(); $userId = Yii::app()->user->getState('id'); $propertiesLinks = $propertiesModel->with('property')->findAllByAttributes(array('userId' => $userId)); //Delete deleted properties foreach ($propertiesLinks as $key => $link) { if ($link->property->getAttribute('isdeactivated') == 1) { unset($propertiesLinks[$key]); } } //Formating data foreach ($propertiesLinks as $key => $propertiLink) { $this->properties[$key] = $propertiLink->getAttributes(); $this->properties[$key]['property'] = $propertiLink->property->getAttributes(); $this->properties[$key]['property']['members'] = array(); $this->properties[$key]['property']['guests'] = array(); foreach ($propertiLink->property->user2properties as $index => $link) { if ($link->getAttribute('access') <= \UserAccessTable::BASIC_ACCESS) { $this->properties[$key]['property']['members'][$index] = $link->getAttributes(); } else { $this->properties[$key]['property']['guests'][$index] = $link->getAttributes(); } } $this->properties[$key]['property']['members_count'] = count($this->properties[$key]['property']['members']); $this->properties[$key]['property']['guests_count'] = count($this->properties[$key]['property']['guests']); $galleryModel = new Gallery(); $primaryImage = $galleryModel->with('file')->findByAttributes(array('propertyid' => $this->properties[$key]['property']['id']), array('order' => 't.index')); if ($primaryImage) { $this->properties[$key]['property']['minimage'] = basePath('propertyfile/') . $primaryImage->file->getAttribute('systempath') . '?propertyid=' . $this->properties[$key]['property']['id'] . "&thumb=true"; $this->properties[$key]['property']['image'] = basePath('propertyfile/') . $primaryImage->file->getAttribute('systempath') . '?propertyid=' . $this->properties[$key]['property']['id']; } else { $this->properties[$key]['property']['minimage'] = basePath('images/property-placeholder.png'); $this->properties[$key]['property']['image'] = basePath('images/property-placeholder.png'); } $this->properties[$key]['access_name'] = UserAccessTable::accessLevelToString($this->properties[$key]['access']); } }
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')); }
Latest Login </th> <th> Created On </th> </tr> </thead> <tbody> <?php $count = 0; foreach ($admins as $admin) { ?> <tr> <td> <?php echo $admin['firstname'] . " " . $admin['lastname'] . " (" . UserAccessTable::accessLevelToString($admin['access']) . ")"; ?> </td> <td> <?php echo $admin['property']['property_name']; ?> </td> <td> <?php echo $admin['email']; ?> </td> <td> <?php echo $admin['property']['property_phone'];
Latest Login </th> <th> Created On </th> </tr> </thead> <tbody> <?php $count = 0; foreach ($members as $member) { ?> <tr> <td> <?php echo $member['firstname'] . " " . $member['lastname'] . " (" . UserAccessTable::accessLevelToString($member['access']) . ")"; ?> </td> <td> <?php echo $member['property']['property_name']; ?> </td> <td> <?php echo $member['email']; ?> </td> <td> <?php echo $member['property']['property_phone'];
public function actionInviteGuestEmail($email = false) { $testData = array('data' => array('senderFullName' => "Dart Vaider", 'propertyName' => "Dead star", 'from' => "06/06/06 060606", 'to' => "07/07/07 070707", 'access' => UserAccessTable::accessLevelToString(UserAccessTable::GUEST), 'event' => "NewYear", 'message' => "hello !", 'userFullName' => 'Ilya Mineev', 'url' => "localhost/sfsdhuifg", 'token' => 'dgdfgdfgf', 'email' => '*****@*****.**', 'password' => 'pasw'), 'userFullName' => 'Ilya Mineev', 'url' => "localhost/sfsdhuifg", 'token' => 'dgdfgdfgf', 'email' => '*****@*****.**', 'password' => 'pasw'); if ($email != false) { $emailBody = $this->renderPartial('InviteGuestEmail', $testData, true); MailHelper::send($emailBody, "SharedKey.com", array($email)); $this->layout = 'app'; $this->render('index', array('text' => "Letter was sent to {$email}")); } else { $this->renderPartial('InviteGuestEmail', $testData); } }
private function createViewItem($u2p) { $user = array(); $user['id'] = $u2p->getAttribute('id'); $user['fullName'] = $u2p->user->getAttribute('firstname') . ' ' . $u2p->user->getAttribute('lastname'); $date = $u2p->user->getAttribute('loginDate'); $dateTime = ''; if (isset($date)) { $dateTime = new DateTime($date); } $user['lastLogin'] = isset($date) ? 'Last login ' . $dateTime->format('M j, Y h:i A') : 'Has never logged-in'; $inviteDate = $u2p->getAttribute('inviteDate'); $inviteDateTime = new DateTime($inviteDate); $user['inviteDate'] = $inviteDateTime->format('M j, Y'); $inviteSentByUser = User::model()->findByPk($u2p->getAttribute('inviteUserId')); if ($inviteSentByUser != null) { $user['inviteByFullName'] = $inviteSentByUser->getAttribute('firstname') . ' ' . $inviteSentByUser->getAttribute('lastname'); } else { $user['inviteByFullName'] = ''; } $user['email'] = $u2p->user->getAttribute('email'); $fromDate = $u2p->getAttribute('fromDate'); if (isset($fromDate)) { $fromDateTime = new DateTime($fromDate); $user['fromDate'] = $fromDateTime->format('M j, Y'); } else { $user['fromDate'] = ''; } $toDate = $u2p->getAttribute('toDate'); if (isset($toDate)) { $toDateTime = new DateTime($toDate); $user['toDate'] = $toDateTime->format('M j, Y'); } else { $user['toDate'] = ''; } $user['status'] = UserAccessTable::statusToString($u2p->getAttribute('status')); $user['statusInt'] = $u2p->getAttribute('status'); return $user; }
public function actionDownloadCSV() { $type = $_GET['type']; $csvpath = 'csv/'; $filename = $type . '_' . date('d-m-Y') . '.csv'; $fullname = $csvpath . $filename; $headers = array(); $data = array(); switch ($type) { case 'administratorspermonth': $headers = array('date', 'count'); $data = Yii::app()->db->createCommand("SELECT DATE_FORMAT(u.createdDate, '%M %Y') AS mthyr , COUNT(DISTINCT u.id) AS count FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access = 5 GROUP BY DATE_FORMAT(u.createdDate, '%Y-%m')")->queryAll(); break; case 'administrators': $headers = array('name', 'username', '# of logins', 'latest login', 'created on', 'profile name', 'phone', 'city', 'prov', 'country'); $data = Yii::app()->db->createCommand("SELECT DISTINCT CONCAT_WS(' ', u.firstname, u.lastname) AS name, u.email, u.numoflogins, u.loginDate, u.createdDate, up.propertyId, up.access FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access= 5")->queryAll(); foreach ($data as $key => $admin) { $prop = Yii::app()->db->createCommand("SELECT property_name, property_phone, city, state, country FROM properties where id = " . $admin['propertyId'])->queryRow(); $data[$key] = array_merge($data[$key], $prop); $data[$key]['name'] = $data[$key]['name'] . ' (' . UserAccessTable::accessLevelToString($data[$key]['access']) . ')'; unset($data[$key]['propertyId']); unset($data[$key]['access']); } break; case 'guestspermonth': $headers = array('date', 'count'); $data = Yii::app()->db->createCommand("SELECT DATE_FORMAT(u.createdDate, '%M %Y') AS mthyr , COUNT(DISTINCT u.id) AS count FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access = 30 GROUP BY DATE_FORMAT(u.createdDate, '%Y-%m')")->queryAll(); break; case 'guests': $headers = array('name', 'username', '# of logins', 'latest login', 'created on', 'profile name', 'phone', 'city', 'prov', 'country'); $data = Yii::app()->db->createCommand("SELECT DISTINCT CONCAT_WS(' ', u.firstname, u.lastname) AS name, u.email, u.numoflogins, u.loginDate, u.createdDate, up.propertyId FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access= 30")->queryAll(); foreach ($data as $key => $guest) { $prop = Yii::app()->db->createCommand("SELECT property_name, property_phone, city, state, country FROM properties where id = " . $guest['propertyId'])->queryRow(); $data[$key] = array_merge($data[$key], $prop); unset($data[$key]['propertyId']); } break; case 'memberspermonth': $headers = array('date', 'count'); $data = Yii::app()->db->createCommand("SELECT DATE_FORMAT(u.createdDate, '%M %Y') AS mthyr , COUNT(DISTINCT u.id) AS count FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access = 10 OR up.access = 20 GROUP BY DATE_FORMAT(u.createdDate, '%Y-%m')")->queryAll(); break; case 'members': $headers = array('name', 'username', '# of logins', 'latest login', 'created on', 'profile name', 'phone', 'city', 'prov', 'country'); $data = Yii::app()->db->createCommand("SELECT DISTINCT CONCAT_WS(' ', u.firstname, u.lastname) AS name, u.email, u.numoflogins, u.loginDate, u.createdDate, up.propertyId FROM users u INNER JOIN user2property up ON u.id = up.userId WHERE up.access= 10 OR up.access= 20")->queryAll(); foreach ($data as $key => $member) { $prop = Yii::app()->db->createCommand("SELECT property_name, property_phone, city, state, country FROM properties where id = " . $member['propertyId'])->queryRow(); $data[$key] = array_merge($data[$key], $prop); unset($data[$key]['propertyId']); } break; case 'propertiescountsbymonth': $headers = array('date', 'count'); $data = Yii::app()->db->createCommand("SELECT DATE_FORMAT(edt, '%M %Y') AS mthyr, COUNT(id) AS count FROM properties GROUP BY DATE_FORMAT(edt, '%Y-%m')")->queryAll(); break; case 'propertiescountsusers': $headers = array('# properies', 'count'); $res = Yii::app()->db->createCommand("SELECT COUNT(id) AS count FROM user2property GROUP BY userId ORDER BY count")->queryAll(); $group1 = $group2 = $group3 = $group4 = $group5 = 0; foreach ($res as $proprtyCount) { switch ($proprtyCount['count']) { case "1": $group1++; break; case "2": $group2++; break; case "3": $group3++; break; case "4": $group4++; break; default: $group5++; } } $data = array(array("1 property", $group1), array("2", $group2), array("3", $group3), array("4", $group4), array("> 4", $group5)); break; case 'properties': $headers = array('profile name (access type)', 'city', 'prov/state', 'country', 'created on', 'property data'); $data = Yii::app()->db->createCommand("SELECT id, property_name, city, state, country, edt, isdeactivated FROM properties")->queryAll(); foreach ($data as $key => $prop) { $activestr = $data[$key]['isdeactivated'] == 0 ? '(INACTIVE)' : '(ACTIVE)'; $data[$key]['property_name'] = $data[$key]['property_name'] . ' ' . $activestr; $propId = $prop['id']; //get property users $users = Yii::app()->db->createCommand("SELECT CONCAT_WS(' ', u.firstname, u.lastname) AS name, up.access FROM user2property up INNER JOIN users u ON u.id = up.userId WHERE up.propertyId = {$propId}")->queryAll(); foreach ($users as $idx => $user) { $user['name'] = $user['name'] . ' (' . UserAccessTable::accessLevelToString($user['access']) . ')'; $data[$key]['property_name'] = $data[$key]['property_name'] . ' ' . $user['name']; } //get property data $photos = Yii::app()->db->createCommand("SELECT count(*) FROM propertyfile p WHERE p.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = 'Photos: ' . $photos . ' '; $events = Yii::app()->db->createCommand("SELECT count(*) FROM calendar ca WHERE ca.propertyid = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Events: ' . $events . ' '; $directions = Yii::app()->db->createCommand("SELECT count(*) FROM direction di WHERE di.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Directions: ' . $directions . ' '; $map = Yii::app()->db->createCommand("SELECT count(*) FROM property_attachments pa WHERE pa.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Map attach: ' . $map . ' '; $tourist = Yii::app()->db->createCommand("SELECT count(*) FROM touristinfo ti WHERE ti.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Tourist info: ' . $tourist . ' '; $rules = Yii::app()->db->createCommand("SELECT count(*) FROM houserules hr WHERE hr.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Rules: ' . $rules . ' '; $contacts = Yii::app()->db->createCommand("SELECT count(*) FROM keycontact WHERE property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Contacts: ' . $contacts . ' '; $notices = Yii::app()->db->createCommand("SELECT count(*) FROM noticeboard nb WHERE nb.property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' Notices: ' . $notices . ' '; $guentries = Yii::app()->db->createCommand("SELECT count(*) FROM guestbook WHERE property_id = {$propId}")->queryScalar(); $data[$key]['property_data'] = $data[$key]['property_data'] . ' GU entries: ' . $guentries; unset($data[$key]['id']); unset($data[$key]['isdeactivated']); } break; default: Yii::app()->request->redirect(basePath('stats/index')); } $fp = fopen($fullname, 'w'); fputcsv($fp, $headers); foreach ($data as $fields) { fputcsv($fp, $fields); } fclose($fp); if (file_exists($fullname)) { return Yii::app()->getRequest()->sendFile($filename, @file_get_contents($fullname)); } }
private function createViewItem($u2p) { $user = array(); $user['color'] = $u2p->getAttribute('color'); $user['fullName'] = $u2p->user->getAttribute('firstname') . ' ' . $u2p->user->getAttribute('lastname'); $date = $u2p->user->getAttribute('loginDate'); $dateTime = ''; if (isset($date)) { $dateTime = new DateTime($date); } $user['lastLogin'] = isset($date) ? 'Last login ' . $dateTime->format('M j, Y h:i A') : 'Has never logged-in'; $user['firstname'] = $u2p->user->getAttribute('firstname'); $user['lastname'] = $u2p->user->getAttribute('lastname'); $user['bookingName'] = $u2p->bookingName; $user['access'] = UserAccessTable::accessLevelToString($u2p->getAttribute('access')); $user['accessInt'] = $u2p->getAttribute('access'); $user['status'] = UserAccessTable::statusToString($u2p->getAttribute('status')); $user['statusInt'] = $u2p->getAttribute('status'); $user['email'] = $u2p->user->getAttribute('email'); $user['phone'] = $u2p->user->getAttribute('phone'); $user['can_delete'] = $u2p->user->getAttribute('email') != Yii::app()->user->getState('email'); $user['id'] = $u2p->getAttribute('id'); if ($u2p->getAttribute('access') == UserAccessTable::OWNER) { $user['can_delete'] = false; } return $user; }