Esempio n. 1
0
 /**
  * Let's users integrate subscribe buttons into their website
  */
 public function index()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $user_obj = $f3->get('user_obj');
     $user_org_links = $f3->get('user_org_links');
     if (count($user_org_links) == 0) {
         $f3->reroute('/dashboard');
     } 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;
                 }
             }
         }
         // Total views
         if (!isset($validated)) {
             // Select first
             $orgId = $user_org_links[0]['orgId'];
         }
         $totalViews = $f3->get('db.instance')->exec('SELECT * FROM newsletter_opens WHERE orgId = ?', $orgId);
         $f3->set('totalViews', count($totalViews));
         $orgMap = new \Models\Organisation();
         $orgMap->load($orgId);
         $f3->set('user_org_selected', $orgMap->cast());
         $f3->set('target', 'dashboard/integrations/index/index.html');
     }
     $this->_render('base.html');
 }
Esempio n. 2
0
 public function indexpost()
 {
     // Log-in stuff
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $activeOrganisation = User::getUserSelectedOrganisation($f3->get('PARAMS.id'));
     $listName = trim($f3->get('POST.listName'));
     if (strlen($listName) < 3) {
         $f3->set('error', 'List name must be at least 3 characters long');
     } else {
         $list = Lists::createList(['listName' => $listName, 'orgId' => $activeOrganisation->id]);
         if ($f3->exists('POST.redirectToList')) {
             $f3->reroute('/dashboard/lists/' . $list);
         } else {
             $f3->reroute($f3->get('PATH'));
         }
     }
     $lists = Lists::getOrganisationLists($activeOrganisation->id);
     $orgMap = new \Models\Organisation();
     $orgMap->load($activeOrganisation->id);
     $f3->set('user_org_selected', $orgMap->cast());
     $f3->set('lists', $lists);
     $f3->set('target', 'dashboard/organisations/lists/index.html');
     $this->_render('base.html');
 }
Esempio n. 3
0
 public function details()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $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 = $f3->get('PARAMS.id');
     if ($orgId == 'active') {
         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'];
         }
     }
     foreach ($user_org_links as $orgKey => $orgValue) {
         if ($orgValue['orgId'] == $orgId) {
             $validated = true;
         }
     }
     // Organisation either does not exists or he isn't a member
     if (!isset($validated)) {
         $f3->set('target', 'dashboard/organisations/details/unauthorized.html');
         $this->_render('base.html');
     } else {
         // Organisation details
         $orgMap = new \Models\Organisation();
         $orgMap->load($orgId);
         $f3->set('user_org_selected', $orgMap->cast());
         // Members
         $orgUsers = $f3->get('db.instance')->exec('SELECT * FROM organisation_members WHERE orgId = ' . $orgId);
         $members = array();
         foreach ($orgUsers as $orgUser) {
             $member = new \Models\User();
             $member->load($orgUser['memberId']);
             $members[] = $member->cast();
         }
         $f3->set('user_org_selected_members', $members);
         // Display a notification to masquerading administrators
         if ($f3->exists('SESSION.mask')) {
             new Notification('You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>', 'danger', true);
         }
         $f3->set('target', 'dashboard/organisations/details/details.html');
         $this->_render('base.html');
     }
 }
Esempio n. 4
0
 public function invites()
 {
     $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');
     // Organisation invitations
     $result = $db->exec('SELECT * FROM organisations_invites WHERE targetId = ?', $user['id']);
     if (count($result) == 0) {
         $f3->set('target', 'dashboard/organisations/invites/no-invites.html');
     } else {
         $invites = [];
         foreach ($result as $res) {
             $invite = [];
             // From
             $from = new \Models\User();
             $from->load($res['fromId']);
             $invite['from'] = $from->cast();
             // Target organisation
             $org = new \Models\Organisation();
             $org->load($res['orgId']);
             if (!$org) {
                 // Organisation has been deleted, so yeah, delete the invite
                 $db->exec('DELETE FROM organisations_invites WHERE id = ?', $res['id']);
                 $f3->reroute($f3->get('PATH'));
             }
             $invite['org'] = $org->cast();
             $invite['key'] = $res['accept_key'];
             $invites[] = $invite;
         }
         $f3->set('invites', $invites);
         $f3->set('target', 'dashboard/organisations/invites/invites.html');
     }
     // Display a notification to masquerading administrators
     if ($f3->exists('SESSION.mask')) {
         new Notification('You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>', 'danger', true);
     }
     $this->_render('base.html');
 }
Esempio n. 5
0
 public function createpost()
 {
     $f3 = \Base::instance();
     $this->_requireLogin();
     $user = $f3->get('user');
     $errors = array();
     if (strlen($f3->get('POST.orgName')) < 4) {
         $errors[] = 'Organisation name must be at least 4 long.';
     }
     if (!empty($errors)) {
         $f3->set('errors', implode('<br />', $errors));
         $f3->set('showPostContents', true);
         // Display a notification to masquerading administrators
         if ($f3->exists('SESSION.mask')) {
             new Notification('You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>', 'danger', true);
         }
         $f3->set('target', 'dashboard/organisations/new.html');
         $this->_render('base.html');
     } else {
         $orgEntry = new \Models\Organisation();
         $orgEntry->name = $f3->get('POST.orgName');
         $orgEntry->link = $f3->get('POST.orgLink');
         $orgEntry->desc = $f3->clean($f3->get('POST.orgDesc'), 'a');
         $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->rSend = true;
         $orgMemberEntry->rEdit = 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('/organisations');
     }
 }
Esempio n. 6
0
 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');
         }
     }
 }
Esempio n. 7
0
 public function index()
 {
     $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');
     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'];
     }
     $orgMap = new \Models\Organisation();
     $orgMap->load($orgId);
     $f3->set('user_org_selected', $orgMap->cast());
     // Subscriptions
     $orgSub = new \Models\Subscriptions();
     $orgSub->load(array('orgId = ?', $orgId));
     $f3->set('org_sub', $orgSub->calculate());
     // Organisation invitations
     $result = $db->exec('SELECT COUNT(*) AS `count` FROM organisations_invites WHERE targetId = ?', $user['id']);
     $f3->set('organisation_invites_count', $result[0]['count']);
     // Display a notification to masquerading administrators
     if ($f3->exists('SESSION.mask')) {
         new Notification('You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>', 'danger', true);
     }
     $f3->set('target', 'dashboard/organisations/index.html');
     $this->_render('base.html');
 }
Esempio n. 8
0
 /**
  * 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');
 }
Esempio n. 9
0
 public function updatepost()
 {
     $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 = $f3->get('PARAMS.id');
     if ($orgId == 'active') {
         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'];
         }
     }
     foreach ($user_org_links as $orgKey => $orgValue) {
         if ($orgValue['orgId'] == $orgId) {
             $validated = true;
         }
     }
     $orgMap = new \Models\Organisation();
     $orgMap->load($orgId);
     if ($orgMap->ownerId != $user['id']) {
         $validated = false;
     }
     // Organisation either does not exists or he isn't a member
     if (!isset($validated) or $validated == false) {
         $f3->set('target', 'dashboard/organisations/details/unauthorized.html');
         $this->_render('base.html');
     } else {
         $errors = array();
         if (strlen($f3->get('POST.orgName')) < 4) {
             $errors[] = 'Organisation name must be at least 4 long.';
         }
         if (!empty($f3->get('POST.orgLink')) and !filter_var($f3->get('POST.orgLink'), FILTER_VALIDATE_URL)) {
             $errors[] = 'Entered Link must be a valid URL, you can also leave it empty.';
         }
         if (empty($errors)) {
             $orgMap->name = $f3->get('POST.orgName');
             $orgMap->link = $f3->get('POST.orgLink');
             $orgMap->desc = $f3->clean($f3->get('POST.orgDesc'), 'a');
             $orgMap->save();
             $f3->reroute('/organisations/details/' . $orgId);
         } else {
             $f3->set('user_org_selected', $orgMap->cast());
             $f3->set('errors', $errors);
             $f3->set('target', 'dashboard/organisations/details/edit.html');
             $this->_render('base.html');
         }
     }
 }