}
public function act($iid, $action) {
-// return $this->msession->getAppInst($iid)->act($action);
+ $this->json->reply($this->msession->getAppInst($iid)->act($action));
+ }
+
+ public function scripts($aid) {
+ $this->output->set_output(call_user_func(array($this->msession->getAppClass($aid), 'scripts'), $aid));
}
public function close($iid) {
);
$ulev = $this->CI->user->level();
- if ($ulev == 'operator') $chklevel = "a.access = 'user' OR a.access = 'operator'";
- elseif ($ulev == 'manager') $chklevel = "1"; // full access -> always true
+ if ($ulev == 'manager') $chklevel = "1"; // full access -> always true
+ elseif ($ulev == 'operator') $chklevel = "a.access = 'user' OR a.access = 'operator'";
else $chklevel = "a.access = 'user'"; // fallback
- $sql = 'SELECT a.parent AS catid, c.catname AS category, a.appname AS appname, a.aid AS appid FROM categories AS c, apps AS a WHERE c.cid = a.parent AND ('.$chklevel.')';
+ $sql = 'SELECT a.parent AS catid, c.catname AS category, a.appname AS appname, a.aid AS appid FROM categories AS c, apps AS a WHERE a.active = 1 AND c.cid = a.parent AND ('.$chklevel.')';
$q = $this->CI->db->query($sql);
foreach ($q->result() as $row) {
if ($row->category == 'System') {
return $this->lastError;
}
- protected function getApp($aid, $iid, $file, $class) {
- if (!is_file($this->config->item('app_prefix').$file)) {
- return $this->setError('App file does not exist');
+ protected function includeApp($file) {
+ $f = $this->config->item('app_prefix').$file;
+ if (!is_file($f)) {
+ return $this->setError('App file does not exist '.$f);
}
- if (!(include_once $this->config->item('app_prefix').$file)) {
- return $this->setError('Include error');
+ if (!(include_once $f)) {
+ return $this->setError('Include error '.$f);
}
+ }
- return new $class($iid);
+ protected function getApp($aid, $iid, $file, $class) {
+ $this->includeApp($file);
+ return new $class($iid, $aid);
}
+
+ public function getAppClass($aid) {
+ $this->db->select('classname, filename');
+ $this->db->where('aid', $aid);
+ $q = $this->db->get('apps');
+ if ($q->num_rows() == 0)
+ return FALSE;
+ $row = $q->row();
+ $filename = $row->filename;
+ $classname = $row->classname;
+ $this->includeApp($filename);
+ return $classname;
+ }
+
public function getAppInst($iid) {
- if ($this->apps[$iid]) {
+ if (isset($this->apps[$iid])) {
return $this->apps[$iid];
} else {
- $this->db->select('aid');
+ $this->db->select('aid, corename');
$this->db->where('iid', $iid);
$q = $this->db->get('session_apps');
if ($q->num_rows() == 0)
$row = $q->row();
$aid = $row->aid;
- $this->db->select('classname, filename');
- $this->db->where('aid', $aid);
- $q = $this->db->get('apps');
- if ($q->num_rows() == 0)
- return FALSE;
- $row = $q->row();
- return $this->getApp($aid, $iid, $row->filename, $row->classname);
+ if ($aid == -1) {
+ $filename = 'core/'.$row->corename.'.php';
+ $classname = ucfirst($row->corename);
+ } else {
+ $this->db->select('classname, filename');
+ $this->db->where('aid', $aid);
+ $q = $this->db->get('apps');
+ if ($q->num_rows() == 0)
+ return FALSE;
+ $row = $q->row();
+ $filename = $row->filename;
+ $classname = $row->classname;
+ }
+ return $this->getApp($aid, $iid, $filename, $classname);
}
}
$idata = array(
'sid' => $this->user->sid(),
'aid' => -1,
+ 'corename' => $name,
);
$this->db->insert('session_apps', $idata);
$iid = $this->db->insert_id();
<?php
abstract class KOS_App {
- function __construct($iid) {
+ function __construct($iid, $aid) {
$this->iid = $iid;
+ $this->aid = $aid;
}
- public function iid() {
- return $this->iid;
- }
+ public function iid() { return $this->iid; }
+ public function aid() { return $this->aid; }
abstract public function appName();
abstract public function windowTitle();
abstract public function windowContents();
- public function opening() { return; }
- public function closing() { return; }
+ public function opening() { return; } // default
+ public function closing() { return; } // default
- abstract public function act($action);
+ public static function scripts($aid) { return 'wos.appscripts['.$aid.'] = {load: function(t){this.target = t}};'; } // default
+ public function act($action) { return $action; } // default, but will only work for static ("content") apps.
}
?>
class Credits extends KOS_App {
protected $iid;
+ protected $aid;
public function appName() {
return "credits";
</ul>
EOF;
}
-
- public function act($action) {
- return $action;
- }
}
?>
--- /dev/null
+<?php
+
+/*
+DOCS:
+ <script>wos.applib.loadscripts(<?php echo $this->aid() ?>);</script>
+can be used to trigger load JS from: public function scripts()
+
+scripts should return valid javascript code including at least:
+ wos.apps[<?php echo $this->aid() ?>].load = function(target){ appName.ctr = target; }
+or etc. Don't include script tags, it's loaded a la <script src="...">
+*/
+
+require_once('kosapps/common.php');
+
+class User_Manager extends KOS_App {
+ protected $iid;
+
+ public function appName() {
+ return "usermanager";
+ }
+ public function windowTitle() {
+ return "User Manager";
+ }
+ public function windowContents() {
+ return <<<EOF
+<em>User Manager!</em>
+EOF;
+ }
+
+}
+
+?>
(function( $ ) {
- $.fn.pageConstruct = function( initvar ) {
+ $.fn.pageConstruct = function() {
this.buildPage = function() {
document.cookie = "session_id=0;expires=0";
var repl = resp.contents
var target = 'div#'+repl.name+repl.id;
- apps[repl.name] = {aid: appid, instance: repl.id, title: repl.title, target: target};
+ wos.apps[repl.id] = {aid: appid, instance: repl.id, title: repl.title, target: target};
+
+ $.getScript('control/scripts/'+appid, function() {
+ wos.appscripts[appid].load(target);
+ });
$('body').append('<div id="'+repl.name+repl.id+'" class="app modal hide fade"></div>');
$(target).remove();
}
+ this.apps = {};
+ this.appscripts = {}
+
return this;
};
})( jQuery );
$(function () {
- apps = {}
wos = $('document.body').pageConstruct();
wos.buildPage();