Exemplo n.º 1
0
                    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'];
Exemplo n.º 2
0
                    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'];
 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']);
     }
 }
Exemplo n.º 4
0
                    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'];
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 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));
     }
 }
Exemplo n.º 8
0
 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;
 }