Example #1
0
 protected function onGet(\Controllers\Request $input)
 {
     $id = $this->input->get('id');
     $this->data['module'] = Module::find($id);
     if (!$this->data['module']) {
         return $this->redirect($this->plugin->modules_url());
     }
     return parent::onGet($input);
 }
 function init()
 {
     parent::init();
     view_minify(Comm::config('admin_minify') ?: false);
     $t = $_GET['AdminThemeTryChange'];
     $t1 = Comm::config('admin_theme');
     if ($t) {
         $t1 = $t;
     }
     theme($t1 ?: 'admin');
 }
Example #3
0
 public function claimpost()
 {
     $f3 = \Base::instance();
     if ($f3->get('user')) {
         if ($f3->get('user')['rank'] == 1) {
             new Notification('You cannot claim an invite while logged in.', 'danger', true);
             $f3->reroute('/dashboard');
             return;
         }
     }
     $key = $f3->get('PARAMS.invite');
     if (\Helpers\Invites::isValidKey($key)) {
         if ($f3->get('POST.register-password') != $f3->get('POST.register-password-verify')) {
             $f3->set('errors', ['Password verify must match the first password.']);
         } else {
             $user = User::createUser(array('name' => $f3->get("POST.register-name"), 'username' => $f3->get("POST.register-username"), 'email' => $f3->get("POST.register-email"), 'password' => $f3->get("POST.register-password")));
             // Data missing
             if ($user == false) {
                 $f3->set('errors', ['Some information has not been entered correctly or is not long enough.']);
             } elseif (is_array($user)) {
                 $f3->set('errors', $user);
             } else {
                 $f3->set('SESSION.id', $user->id);
                 // Delete the key
                 \Helpers\Invites::deleteInvite($key);
                 // Send a mail
                 $f3->set('tplData', ['name' => $f3->get("POST.register-username")]);
                 SendingAPI::send(['mailTo' => $f3->get("POST.register-email"), 'mailSubject' => 'Thank you for registering on SquareMS !', 'mailContents' => ['html' => \Template::instance()->render('mails/register.html'), 'text' => "Thank you for registering on SquareMS ! \n" . "You can access your account now on https://squarems.net/ ! \n\n" . "Please do not respond to this email, it is sent by an automated system."]]);
                 $f3->reroute("/dashboard");
                 return;
             }
         }
         $f3->set('css', array('/static/css/auth.css'));
         $f3->set('target', 'invite.html');
         $this->_render('base.html');
     } else {
         $f3->error(404);
     }
 }
Example #4
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['orders'] = Order::orderBy('status', 'desc')->orderBy('created_at', 'asc')->paginate(25, ['*'], 'subpage');
     return parent::onGet($input);
 }
Example #5
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['orders'] = Order::all();
     return parent::onGet($input);
 }
Example #6
0
 public function resumepost()
 {
     $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');
     $errors = [];
     if ($f3->exists('POST.username')) {
         $username = $f3->get('POST.username');
         $username = $f3->scrub($username);
         if (preg_match('/^[a-z0-9]{5,}$/', $username)) {
             // Filter any already existing username
             if ($username != $user['username']) {
                 $user = new User();
                 $user->load(array('username = ?', $username));
                 if ($user->loaded()) {
                     $errors[] = 'This username is taken.';
                 } else {
                     $user_obj->username = $username;
                 }
             }
         } else {
             $errors[] = 'Username must be at least 5 characters long, with only numbers and lowercase letters in it.';
         }
     }
     if ($f3->exists('POST.fullName')) {
         $fullName = $f3->get('POST.fullName');
         $fullName = $f3->scrub($fullName);
         if (strlen($fullName) > 4) {
             $user_obj->name = htmlspecialchars($fullName);
         } else {
             $errors[] = 'Full name must be at least 5 characters long';
         }
     }
     if ($f3->exists('POST.email')) {
         $email = $f3->get('POST.email');
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
             // Filter any already existing email
             if ($email != $user['email']) {
                 $user = new User();
                 $user->load(array('email = ?', $email));
                 if ($user->loaded()) {
                     $errors[] = 'This email is taken.';
                 } else {
                     $user_obj->email = $email;
                 }
             }
         } else {
             $errors[] = 'Incorrect email';
         }
     }
     if ($f3->exists('POST.age')) {
         $age = (int) $f3->get('POST.age');
         if ($age > 12) {
             $user_obj->age = $age;
         } else {
             $errors[] = 'You need to be at least 13 years old to use this service.';
         }
     }
     // Saving if no errors
     if (empty($errors)) {
         $user_obj->save();
         new Notification('Profile saved', 'success', true);
         $f3->reroute($f3->get('PATH'));
         return;
     } else {
         $f3->set('errors', $errors);
     }
     // 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', 'account/resume.html');
     $this->_render('base.html');
 }
Example #7
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['modules'] = Module::all();
     return parent::onGet($input);
 }
Example #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');
 }
Example #9
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['modules'] = Module::orderBy('name')->paginate(10, ['*'], 'subpage');
     return parent::onGet($input);
 }
Example #10
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['soil_types'] = Soil::all();
     return parent::onGet($input);
 }
Example #11
0
 protected function onGet(\Controllers\Request $input)
 {
     $this->data['plants'] = Plant::orderBy('name')->paginate(25, ['*'], 'subpage');
     return parent::onGet($input);
 }
Example #12
0
 protected function onGet(\Illuminate\Http\Request $input)
 {
     $this->data['soil_types'] = Soil::orderBy('name')->paginate(25, ['*'], 'subpage');
     return parent::onGet($input);
 }