diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/common.mod.php | 113 | ||||
| -rw-r--r-- | examples/root.control.php | 131 | ||||
| -rw-r--r-- | examples/setting.modal.view.php | 130 | 
3 files changed, 1 insertions, 373 deletions
diff --git a/examples/common.mod.php b/examples/common.mod.php index 6cba871..0d740ef 100644 --- a/examples/common.mod.php +++ b/examples/common.mod.php @@ -1,54 +1,5 @@  <?php -/* - * SCROTT Copyright (C) 2016 Malf Furious - * - * Scrott is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * Scrott is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public - * License for more details. - */ - -require_once "model/master.mod.php"; -require_once "class/form.class.php"; -require_once "class/setting.class.php"; -require_once "class/object.class.php"; -require_once "class/user.class.php"; -require_once "class/group.class.php"; - -class CommonModel extends MasterModel -{ -    var $HEAD_IMG_MAX_SIZE = 1048576; // 1MB -    var $HEAD_IMG_MIME = array( -        "image/jpg", -        "image/jpeg" -    ); - -    /* -     * Constructor -     */ -    function __construct($guid = null) -    { -        parent::__construct(); -        $this->first_setting_tab_active = 0; -        $this->first_setting_tab_disp = 0; -        $this->common_handleFormSubmissions($_REQUEST['input'], $_FILES['attachment']); - -        if (!is_null($guid)) -        { -            $this->obj = new DBObject($guid); -            $this->owner = $this->obj->getOwner(); -            $this->members = $this->obj->getMembers(); -        } - -        $this->common_deflt(); -    } -      /*       * Default action       */ @@ -84,41 +35,6 @@ class CommonModel extends MasterModel      }      /* -     * Handle form submissions from common views -     */ -    function common_handleFormSubmissions($input, $attachment) -    { -        switch ($input['action']) -        { -            case "common-group-add":                 $this->addNewGroup($input);                              break; -            case "common-setting-group":             $this->saveSettingGroup($input, $attachment);            break; -            case "common-setting-user":              $this->saveSettingUser($input, $attachment);             break; -            case "common-setting-admin":             $this->saveSettingAdmin($input);                         break; -            case "common-setting-allusers-adduser":  $this->saveSettingAllusersAdduser($input);               break; -            case "common-setting-allusers-edituser": $this->saveSettingAllusersEdituser($input, $attachment); break; -            case "common-setting-allusers-deluser":  $this->saveSettingAllusersDeluser($input);               break; -        } -    } - -    /* -     * Create a new user group -     */ -    function addNewGroup($input) -    { -        $form = new Form(); -        $form->field_text("name"); - -        if (!$form->populate($input)) -        { -            $this->logFormErrors($form); -            return; -        } - -        $group = new Group(); -        $group->createNewGroup($form->name, $this->getCurrentUser()); -    } - -    /*       * Save changes to user group settings       */      function saveSettingGroup($input, $attachment) @@ -465,33 +381,4 @@ class CommonModel extends MasterModel          }      } -    /* -     * Set CSS class for the first tab title in the setting modal only -     */ -    function getSettingModalTabActiveClass() -    { -        if (!$this->first_setting_tab_active) -        { -            $this->first_setting_tab_active = 1; -            return "active"; -        } - -        return ""; -    } - -    /* -     * Set CSS classes for the first tab in the setting modal only -     */ -    function getSettingModalTabDispClasses() -    { -        if (!$this->first_setting_tab_disp) -        { -            $this->first_setting_tab_disp = 1; -            return "in active"; -        } - -        return ""; -    } -} -  ?> diff --git a/examples/root.control.php b/examples/root.control.php index 7e4d1ab..614ab33 100644 --- a/examples/root.control.php +++ b/examples/root.control.php @@ -1,87 +1,3 @@ -<?php - -/* - * SCROTT Copyright (C) 2016 Malf Furious - * - * Scrott is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * Scrott is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public - * License for more details. - */ - -require_once "class/controller.class.php"; -require_once "class/object.class.php"; -require_once "class/setting.class.php"; -require_once "controller/sysconf.control.php"; -require_once "controller/except.control.php"; -require_once "controller/auth.control.php"; -require_once "controller/deauth.control.php"; -require_once "controller/dashboard.control.php"; -require_once "controller/obj.control.php"; -require_once "controller/deleteacct.control.php"; - -/* - * Root-level controller for Scrott app.  This object will delegate the page request to the - * appropriate controller or handle it with an error message page. - */ -class Root extends Controller -{ -    /* -     * Controller implementation -     */ -    function handle($argv) -    { -        global $_SCROTT; -        $argv = $this->normalizeArgv($argv); - -        try -        { -            /* Assert that the system config file exists and has been included */ -            if (!$this->scrottConfExists()) -            { -                $ctrl = new Sysconf(); -                $ctrl->handle($argv); -                return; -            } - -            /* Assert we are running over HTTP(S), whichever is desired */ -            switch ($_SCROTT['settSSL']) -            { -                case "force":  $this->sec_require_https(); break; -                case "forbid": $this->sec_forbid_https();  break; -                default: -                    switch (Setting::settSSL()) -                    { -                        case "force":  $this->sec_require_https(); break; -                        case "forbid": $this->sec_forbid_https();  break; -                    } -            } - -            /* Assert session IP */ -            $this->sec_verify_ip(); - -            /* Assert that a user is logged in */ -            if (!$this->getCurrentUser()) -            { -                $ctrl = new Auth(); -                $ctrl->handle($argv); -                return; -            } - -            /* Handle page request */ -            if (count($argv) == 0) -                $ctrl = new Dashboard(); - -            else -            { -                switch ($argv[0]) -                { -                    case "logout": $ctrl = new Deauth(); break;                      case "deleteaccount": $ctrl = new Deleteacct(); break;                      default:                          /* Check if arg is an object guid */ @@ -96,50 +12,3 @@ class Root extends Controller                          /* No page to show for requested path */                          throw new Exception("The requested path is not valid.");                          break; -                } -            } - -            $ctrl->handle($argv); -        } - -        catch (Exception $e) -        { -            $ctrl = new Except(); -            $ctrl->handle($e->getMessage()); -        } -    } - -    /* -     * Get a useful path string by normalizeing the $argv array received from the main function. -     * This will remove directory names that appear in the $this->ar() string and the initial -     * and trailing (if present) empty strings -     */ -    function normalizeArgv($argv) -    { -        $argv = array_values(array_filter($argv)); -        $ar = array_values(array_filter(explode("/", $this->ar()))); -        $i = 0; -        $trunc = true; - -        if (count($ar) == 0) -            return $argv; - -        foreach ($ar as $elem) -        { -            if ($elem != $argv[$i]) -            { -                $trunc = false; -                break; -            } - -            $i++; -        } - -        if (!$trunc) -            return $argv; - -        return array_values(array_slice($argv, count($ar))); -    } -} - -?> diff --git a/examples/setting.modal.view.php b/examples/setting.modal.view.php index 2217805..029b58b 100644 --- a/examples/setting.modal.view.php +++ b/examples/setting.modal.view.php @@ -1,147 +1,24 @@ -<?php - -/* - * SCROTT Copyright (C) 2016 Malf Furious - * - * Scrott is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * Scrott is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public - * License for more details. - */ - -?> - -<div id="settingModal" class="modal fade" tabindex="-1" role="dialog"> -    <div class="modal-dialog" role="document"> -        <div class="modal-content"> -            <div class="modal-header"> - -                <button type="button" class="close" data-dismiss="modal"> -                    <span aria-hidden="true">×</span> -                </button> - -                <h4 class="modal-title"><span class="glyphicon glyphicon-cog"></span> Settings</h4> - -            </div> - -            <div class="modal-body"> -                <ul class="nav nav-tabs" role="tablist">                      <?php if ($mod->common_settingShowTab['group']) { ?>                          <li class="<?=$mod->getSettingModalTabActiveClass()?>"><a href="#settGroupTab" aria-controls="settGroupTab" data-toggle="tab">                              <span class="glyphicon glyphicon-th"></span> <?=$mod->group->name?>                          </a></li>                      <?php } ?> -                    <li class="<?=$mod->getSettingModalTabActiveClass()?>"><a href="#settUserTab" aria-controls="settUserTab" data-toggle="tab"> -                        <span class="glyphicon glyphicon-user"></span> <?=$mod->getCurrentUser()->getDisplayName()?> -                    </a></li> -                      <?php if ($mod->getCurrentUser()->admin == 1) { ?>                          <li><a href="#settAdminTab" aria-controls="settAdminTab" data-toggle="tab"><span class="glyphicon glyphicon-sunglasses"></span> Admin</a></li>                          <li><a href="#settUsersTab" aria-controls="settUsersTab" data-toggle="tab"><span class="glyphicon glyphicon-th"></span> All Users</a></li>                      <?php } ?> -                </ul> -                <div class="tab-content"> +                      <?php if ($mod->common_settingShowTab['group']) { ?>                          <?php include "view/common/group.setting.modal.view.php"; ?>                      <?php } ?> -                    <div class="tab-pane fade <?=$mod->getSettingModalTabDispClasses()?>" id="settUserTab"> -                        <p> </p> - -                        <form method="post" action="<?=$mod->ap()?>" enctype="multipart/form-data"> -                            <input type="hidden" name="input[action]" value="common-setting-user" /> - -                            <div class="row"> -                                <div class="col-md-8"> -                                    <?php if ($mod->getCurrentUser()->admin == 1) { ?> -                                        <p class="pull-right"><span class="glyphicon glyphicon-sunglasses"></span> <?=$mod->getCurrentUser()->getDisplayName()?> is a Scrott Administrator</p> -                                    <?php } ?> - -                                    <div class="form-group"> -                                        <label>Username</label> -                                        <input type="text" class="form-control" value="<?=$mod->getCurrentUser()->name?>" disabled /> -                                    </div> - -                                    <div class="checkbox"> -                                        <label data-toggle="collapse" data-target="#inputUserPasswdCollapse"> -                                            <input type="checkbox" name="input[setPasswd]" value="1" /> Change Password -                                        </label> -                                    </div> -                                </div> - -                                <div class="col-md-4 text-center"> -                                    <img src="<?=$mod->getCurrentUser()->getHeadImage()?>" alt="<?=$mod->getCurrentUser()->getDisplayName()?>" class="img-circle" height="100" /> -                                    <br /> -                                    <br /> -                                    <button type="button" class="btn btn-default btn-xs" data-toggle="collapse" data-target="#inputUserImageCollapse"> -                                        <span class="glyphicon glyphicon-camera"></span> Upload new image -                                    </button> -                                    <br /> -                                    <button type="submit" name="input[rmImage]" class="btn btn-danger btn-xs" onclick="return assertConfirm()"> -                                        <span class="glyphicon glyphicon-remove"></span> Remove image -                                    </button> -                                </div> -                            </div> - -                            <div class="collapse" id="inputUserImageCollapse"> -                                <div class="form-group"> -                                    <label>User Image</label> -                                    <input type="file" name="attachment" /> -                                </div> -                            </div> - -                            <div class="collapse" id="inputUserPasswdCollapse"> -                                <div class="form-group"> -                                    <label>Current Password</label> -                                    <input type="password" name="input[curPasswd]" class="form-control" /> -                                </div> - -                                <div class="form-group"> -                                    <label>New Password</label> -                                    <input type="password" name="input[newPasswd]" class="form-control" /> -                                </div> - -                                <div class="form-group"> -                                    <label>Confirm Password</label> -                                    <input type="password" name="input[confPasswd]" class="form-control" /> -                                </div> -                            </div> - -                            <div class="form-group"> -                                <label>Alias</label> -                                <input type="text" name="input[alias]" class="form-control" value="<?=$mod->getCurrentUser()->alias?>" maxlength="50" /> -                            </div> - -                            <div class="form-group"> -                                <label>Email</label> -                                <input type="text" name="input[email]" class="form-control" value="<?=$mod->getCurrentUser()->email?>" maxlength="50" /> -                            </div> -                            <?php if ($mod->getCurrentUser()->email != "" && $mod->getCurrentUser()->emailConf == 0) { ?> -                                <div class="form-group has-warning"> -                                    <label class="control-label">Email Confirmation Key</label> -                                    <input type="text" name="input[emailConfKey]" class="form-control" /> -                                    <span class="help-block">You have not yet confirmed ownership of your saved email address</span> -                                </div> -                            <?php } ?> -                            <button type="submit" class="btn btn-success pull-right">Save</button> -                        </form> -                        <p> </p> -                        <p> </p> -                        <a href="<?=$mod->ar()?>/deleteaccount" class="btn btn-danger btn-xs pull-right"><span class="glyphicon glyphicon-trash"></span> Delete Account</a> -                        <p> </p> -                    </div>                      <?php if ($mod->getCurrentUser()->admin == 1) { ?>                          <div class="tab-pane fade" id="settAdminTab"> @@ -339,8 +216,3 @@                              </div>                          </div>                      <?php } ?> -                </div> -            </div> -        </div> -    </div> -</div>  | 
