Esempio n. 1
0
 /**
  * Set up the file
  */
 private static function setup()
 {
     if (self::$fd === NULL) {
         self::$fd = fopen(Local::getinstance()->makebasepath('debug', 'debug.txt'), 'a');
     }
 }
 *        /twigs        TWIG template files go in here
 *        /twigs/admin  Twig files for the admin support of the framework
 *        /vendor       If you are using composer then it puts stuff in here.
 *
 * The .htaccess file directs
 *         anything in /assets to be served by Apache.
 *         anything beginning "ajax" to be called directly i.e. ajax.php (this may or may not be useful - remove it if not)
 *         everything else gets passed into this script where it treats the URL thus:
 *                 /                        =>        /home and then
 *                 /action/r/e/st/          =>        Broken down in Context class. An action and an array of parameters.
 *
 *         Query strings and/or post fields are in the $_ arrays as normal.
 */
include 'class/support/framework.php';
Framework::initialise();
$local = Local::getinstance()->setup(__DIR__, FALSE, TRUE, TRUE, TRUE);
# Not Ajax, debug on, load twig, load RB
$context = Context::getinstance()->setup($local);
$action = $context->action();
if ($action === '') {
    $action = 'home';
}
$page = R::findOne('page', 'name=? and active=?', array($action, 1));
if (!is_object($page)) {
    # No such page or it is marked as inactive
    $context->divert('/error/404?page=' . urlencode($_SERVER['REQUEST_URI']));
    # does not return
}
if ($page->needlogin && !$context->hasuser()) {
    # not logged in or not an admin
    $context->divert('/login?page=' . urlencode($local->debase($_SERVER['REQUEST_URI'])));
Esempio n. 3
0
<?php

/**
 * Ajax entry point of the system
 *
 * @author Lindsay Marshall <*****@*****.**>
 * @copyright 2012-2015 Newcastle University
 */
/**
 * The real work is all done in the Ajax class.
 */
include 'class/support/framework.php';
Framework::initialise();
// Ajax on, debug on, load twig, load RB
$ld = Local::getinstance()->setup(__DIR__, TRUE, TRUE, TRUE, TRUE);
# setup the Local singleton
Ajax::getinstance()->handle(Context::getinstance()->setup());
<?php

/**
 * Ajax entry point of the system
 *
 * @author Lindsay Marshall <*****@*****.**>
 * @copyright 2012-2015 Newcastle University
 */
/**
 * The real work is all done in the Ajax class.
 */
include 'class/support/framework.php';
Framework::initialise();
// Ajax on, debug on, load twig, load RB
Ajax::getinstance()->handle(Context::getinstance()->setup(Local::getinstance()->setup(__DIR__, TRUE, TRUE, TRUE, TRUE)));
Esempio n. 5
0
 /**
  * Return the local object
  *
  * @return object
  */
 public function local()
 {
     return Local::getinstance();
 }
Esempio n. 6
0
 /**
  * Handle various admin operations /admin/xxxx
  *
  * @param object	$context	The context object for the site
  *
  * @return string	A template name
  */
 public function handle($context)
 {
     $rest = $context->rest();
     switch ($rest[0]) {
         case 'pages':
             $tpl = 'support/pages.twig';
             break;
         case 'contexts':
             $tpl = 'support/contexts.twig';
             break;
         case 'roles':
             $tpl = 'support/roles.twig';
             break;
         case 'users':
             $tpl = 'support/users.twig';
             break;
         case 'forms':
             $tpl = 'support/forms.twig';
             break;
         case 'config':
             $tpl = 'support/config.twig';
             break;
         case 'info':
             $_SERVER['PHP_AUTH_PW'] = '*************';
             # hide the password in case it is showing.
             phpinfo();
             exit;
         case 'edit':
             // Edit something - forms and users
             if (count($rest) < 3) {
                 Web::getinstance()->bad();
             }
             $kind = $rest[1];
             $obj = $context->load($kind, $rest[2]);
             if (!is_object($obj)) {
                 Web::getinstance()->bad();
             }
             if (($bid = $context->formdata()->post('bean', '')) !== '') {
                 # this is a post
                 if ($bid != $obj->getID()) {
                     # something odd...
                     Web::getinstance()->bad();
                 }
                 $obj->edit($context);
                 // The edit call might divert to somewhere else so sometimes we may not get here.
             }
             Local::getinstance()->addval($kind, $obj);
             $tpl = 'support/edit' . $kind . '.twig';
             break;
         case 'view':
             // view something - forms
             if (count($rest) < 3) {
                 Web::getinstance()->bad();
             }
             $kind = $rest[1];
             $obj = $context->load($kind, $rest[2]);
             if (!is_object($obj)) {
                 Web::getinstance()->bad();
             }
             if (($bid = $context->formdata()->post('bean', '')) !== '') {
                 # this is a post
                 if ($bid != $obj->getID()) {
                     # something odd...
                     Web::getinstance()->bad();
                 }
                 $obj->edit($context);
                 // The edit call might divert to somewhere else so sometimes we may not get here.
             }
             Local::getinstance()->addval($kind, $obj);
             $tpl = 'support/view' . $kind . '.twig';
             break;
         case 'update':
             if (function_exists('zip_open')) {
                 $formd = $context->formdata();
                 if ($formd->hasfile('update')) {
                     $data = $formd->filedata('update');
                     if (($zd = zip_open($data['tmp_name'])) === FALSE) {
                         $context->local()->message(Local::ERROR, 'Cannot open the file');
                     } else {
                         $context->local()->message(Local::MESSAGE, 'Done');
                     }
                 }
             } else {
                 $context->local()->addval('nozip', TRUE);
             }
             $tpl = 'support/update.twig';
             break;
         default:
             $tpl = 'support/admin.twig';
             break;
     }
     return $tpl;
 }