public function reveal() { $f3 = \Base::instance(); $this->_requireLogin(); $user = $f3->get('user'); if ($f3->exists('SESSION.mask')) { $f3->clear('SESSION.mask'); $notif = new Notification(); $notif->text = 'Welcome back !'; $notif->type = 'success'; $notif->save(); $f3->reroute('/dashboard'); } else { $notif = new Notification(); // User is ranked above 2, so he's a admin if ($user['rank'] > 2) { $notif->text = 'Welcome back !'; $notif->type = 'success'; } elseif (isset(json_decode($user['perms'])['masquerading']) && json_decode($user['perms'])['masquerading'] == true) { $notif->text = 'Welcome back !'; $notif->type = 'success'; } else { $notif->text = 'You do not have the permission to do this !'; $notif->type = 'danger'; } $notif->save(); $f3->reroute('/dashboard'); } }
public function key() { $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'); $key = $f3->get('PARAMS.key'); // Check if the key targets the user $result = $db->exec('SELECT * FROM organisations_invites WHERE accept_key = ?', $key); if ($user['id'] != $result[0]['targetId']) { $notif = new Notification(); $notif->text = 'An error occured, this key is not for you.'; $notif->type = 'danger'; $notif->save(); $f3->reroute('/organisations/invites'); return false; } if ($f3->exists('GET.faith')) { if ($f3->get('GET.faith') == 'decline') { // Decline invite $db->exec('DELETE FROM organisations_invites WHERE accept_key = ?', $key); new Notification('You declined the invitation.', 'danger', true); $f3->reroute('/dashboard'); return false; } else { // Accept invite $orgMemberEntry = new \Models\OrganisationMembers(); $orgMemberEntry->orgId = $result[0]['orgId']; $orgMemberEntry->memberId = $user['id']; $orgMemberEntry->rEdit = true; $orgMemberEntry->rSend = true; $orgMemberEntry->save(); // Delete key $db->exec('DELETE FROM organisations_invites WHERE accept_key = ?', $key); new Notification('You are now part of this organisation', 'success', true); $f3->reroute('/organisations'); } } else { $f3->reroute('/organisations/invites'); } }
public function welcomepost() { $f3 = \Base::instance(); $this->_requireLogin(); $user = $f3->get('user'); $user_obj = $f3->get('user_obj'); $user_org_links = $f3->get('user_org_links'); // Create new organisation if the user has none if ($f3->exists('POST.organisationName')) { $org = $f3->get('POST.organisationName'); $org = $f3->scrub($org); if (strlen($org) < 4) { $notif = new Notification(); $notif->title = 'Error'; $notif->body = 'Organisation name must be at least 4 long.'; $notif->save(); $f3->reroute('/dashboard/welcome?err_name=' . urlencode($org)); } else { $orgEntry = new \Models\Organisation(); $orgEntry->name = $org; $orgEntry->desc = NULL; $orgEntry->ownerId = $user['id']; $orgEntry->save(); // Create a new org member entry and give the user all rights to it (fields starting with 'r' for rights) $orgMemberEntry = new \Models\OrganisationMembers(); $orgMemberEntry->orgId = $orgEntry->id; $orgMemberEntry->memberId = $user['id']; $orgMemberEntry->rEdit = true; $orgMemberEntry->rSend = true; $orgMemberEntry->save(); // Create a new subsription entry $orgSubEntry = new \Models\Subscriptions(); $orgSubEntry->orgId = $orgEntry->id; $orgSubEntry->planId = 1; $orgSubEntry->payDay = date("d"); $orgSubEntry->save(); $f3->reroute('/dashboard'); } } }
/** * Shows the recent SquareMS update log and the user's newsletters statistics (or a button "Create a newsletter") * * @param $f3 */ public function home() { $f3 = \Base::instance(); $this->_requireLogin(); $user = $f3->get('user'); $user_obj = $f3->get('user_obj'); $user_org_links = $f3->get('user_org_links'); // Create new organisation if the user has none if ($f3->exists('POST.organisationName')) { $org = $f3->get('POST.organisationName'); $org = $f3->scrub($org); if (strlen($org) < 4) { $notif = new Notification(); $notif->title = 'Error'; $notif->body = 'Organisation name must be at least 4 long.'; $notif->save(); } else { $orgEntry = new \Models\Organisation(); $orgEntry->name = $org; $orgEntry->desc = NULL; $orgEntry->ownerId = $user['id']; $orgEntry->save(); // Create a new org member entry and give the user all rights to it (fields starting with 'r' for rights) $orgMemberEntry = new \Models\OrganisationMembers(); $orgMemberEntry->orgId = $orgEntry->id; $orgMemberEntry->memberId = $user['id']; $orgMemberEntry->rEdit = true; $orgMemberEntry->rSend = true; $orgMemberEntry->save(); // Create a new subsription entry $orgSubEntry = new \Models\Subscriptions(); $orgSubEntry->orgId = $orgEntry->id; $orgSubEntry->planId = 1; $orgSubEntry->payDay = date("d"); $orgSubEntry->save(); $f3->reroute($f3->get('PATH')); } } if (count($user_org_links) == 0) { $f3->set('target', 'dashboard/index/first-org.html'); } else { // Home-page stats if ($f3->exists('SESSION.selected_organisation')) { $orgId = $f3->get('SESSION.selected_organisation'); foreach ($user_org_links as $orgKey => $orgValue) { if ($orgValue['orgId'] == $orgId) { $validated = true; } } } if (!isset($validated)) { // Select first $orgId = $user_org_links[0]['orgId']; } // Gather some stats $result = $f3->get('db.instance')->exec('SELECT COUNT(*) AS `count` FROM newsletter_opens WHERE orgId = ? AND DATE(open_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)', $orgId); $f3->set('stats_views', $result[0]['count']); // $result = $f3->get('db.instance')->exec('SELECT COUNT(*) AS `count` FROM newsletter_unsub WHERE orgId = ? AND DATE(open_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)', $orgId); // $f3->set('stats_unsub', $result[0]['count']); // Gather some stats for the chart $f3->set('stats_chart_views', json_encode(Organisations::views($orgId))); $f3->set('stats_chart_sending', json_encode(Organisations::sends($orgId))); $orgMap = new \Models\Organisation(); $orgMap->load($orgId); $f3->set('user_org_selected', $orgMap->cast()); // Stats Subscriptions $db = $f3->get('db.instance'); $result = $db->exec('SELECT COUNT(*) AS `count` FROM organisation_subs WHERE orgId = ? AND DATE(sub_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND unsub_time = NULL', $orgId); $f3->set('stats_subs', $result[0]['count']); $result = $db->exec('SELECT COUNT(*) AS `count` FROM organisation_subs WHERE orgId = ? AND DATE(sub_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND unsub_time IS NOT NULL', $orgId); $f3->set('stats_unsubs', $result[0]['count']); // Stats mails sent $result = $db->exec('SELECT COUNT(*) AS `count` FROM mails_sent WHERE orgId = ? AND DATE(sent_time) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)', $orgId); $f3->set('stats_mails_sent', $result[0]['count']); // Organisation subscription details $orgSub = new \Models\Subscriptions(); $orgSub->load(array('orgId = ?', $orgId)); $f3->set('org_sub', $orgSub->calculate()); $f3->set('target', 'dashboard/index/index.html'); if ($f3->exists('SESSION.mask')) { $notif = new Notification(); $notif->text = 'You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>'; $notif->type = 'danger'; $notif->save(); } } $this->_render('base.html'); }