Пример #1
0
 public function invitepost()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $db = $f3->get('db.instance');
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org = $f3->get('user_org');
     $user_org_links = $f3->get('user_org_links');
     $orgId = (int) $f3->get('PARAMS.id');
     // Check if user is part of the organisation
     $result = $db->exec('SELECT * FROM organisation_members WHERE orgId = :orgId AND memberId = :memberId', array('orgId' => $orgId, 'memberId' => $user['id']));
     if (empty($result)) {
         // Not member
         new Notification('You are not member of this organisation', 'danger', true);
         $f3->reroute('/organisations');
         return;
     } else {
         $orgMap = new Organisation();
         $orgMap->load($orgId);
         $f3->set('user_org_selected', $orgMap->cast());
         if ($f3->exists('POST.name') and !empty($f3->get('POST.name'))) {
             $invitedUser = new User();
             $invitedUser->load(array('(email = :email OR username = :email) AND deleted_date IS NULL', 'email' => $f3->get('POST.name')));
             if (!$invitedUser->loaded()) {
                 // No user with this email or username
                 $f3->set('error', 'No user with this email or password');
             } else {
                 // Generate new invitation entry
                 $security = new Security();
                 $accept_key = sha1($security->rand_bytes(32));
                 $db->exec('INSERT INTO organisations_invites(targetId, fromId, orgId, create_time, accept_key) VALUES(:targetId, :fromId, :orgId, :createTime, :acceptKey)', array('targetId' => $invitedUser->id, 'fromId' => $user['id'], 'orgId' => $orgId, 'createTime' => date("Y-m-d H:i:s"), 'acceptKey' => $accept_key));
                 new Notification("Invited <b>{$invitedUser->name}</b> to join this organisation", 'success', true);
                 $f3->reroute($f3->get('PATH'));
             }
         }
         $f3->set('target', 'dashboard/organisations/invite.html');
     }
     $this->_render('base.html');
 }
Пример #2
0
 /**
  * Returns the users selected organisation
  *
  * @return \Models\User|false
  */
 public static function getUserSelectedOrganisation($preference = 0)
 {
     $f3 = \Base::instance();
     $user = $f3->get('user');
     $user_org_links = $f3->get('user_org_links');
     // Preference will be passed (not used)
     if ($preference == 'active' || $preference == null) {
         $preference = 0;
     }
     // Try to load from preference
     if ($preference != 0) {
         foreach ($user_org_links as $link) {
             if ($link['orgId'] == $preference) {
                 $organisation = new Organisation();
                 $organisation->load($preference);
                 return $organisation;
             }
         }
     }
     // Try to load the selected one from SESSION
     $preference = $f3->get('SESSION.selected_organisation');
     foreach ($user_org_links as $link) {
         if ($link['orgId'] == $preference) {
             $organisation = new Organisation();
             $organisation->load($preference);
             return $organisation;
         }
     }
     // Just return the first one
     $preference = $user_org_links[0]['orgId'];
     $organisation = new Organisation();
     $organisation->load($preference);
     return $organisation;
 }