19 require_once
'WHAT/autoload.php';
20 include_once (
'Class.DbObj.php');
21 include_once (
'Class.User.php');
22 include_once (
'Class.QueryDb.php');
23 include_once (
'Class.Application.php');
25 define(
"THROW_EXITERROR", 1968);
62 create table action (id int not null,
64 id_application int not null,
65 name varchar(30) not null,
80 create index action_idx1 on action(id);
81 create index action_idx2 on action(id_application);
82 create index action_idx3 on action(name);
83 create sequence SEQ_ID_ACTION;
106 $this->
function =
"";
110 $query->basic_elem->sup_where = array(
112 "id_application={$parent->id}"
115 $query->basic_elem->sup_where = array(
117 "id_application={$parent->id}"
120 $query->Query(0, 0,
"TABLE");
123 $this->log->debug(
"Set Action to {$this->name}");
136 if ($this->script ==
"") $this->script = strtolower($this->name) .
".php";
137 if ($this->layout ==
"") $this->layout = strtolower($this->name) .
".xml";
138 if ($this->
function ==
"") $this->
function = substr($this->script, 0, strpos($this->script,
'.php'));
144 $this->url = $this->
GetParam(
"CORE_BASEURL") .
"app=" . $this->parent->name .
"&action=" .
$this->name;
146 $this->log->loghead = sprintf(
"%s %s [%d] - ", $this->
user->firstname, $this->user->lastname, $this->user->id);
148 $this->log->application = $this->parent->name;
158 if (is_object($this->
session)) {
167 return ($this->
session->Register($k, $v));
173 if (is_object($this->
session)) {
174 return ($this->
session->Unregister($k));
180 return ($this->
Read(
"{$this->id}_" . $k,
$d));
185 return ($this->
Register(
"{$this->id}_" . $k, $v));
190 return ($this->
Unregister(
"{$this->id}_" . $k));
195 if ($this->
Exists($this->name, $this->id_application))
return "Action {$this->name} already exists...";
196 $msg_res = $this->
exec_query(
"select nextval ('seq_id_action')");
198 $this->
id = $arr[
"nextval"];
202 if ($this->dbid == - 1)
return FALSE;
203 if ($this->
Exists($this->name, $this->id_application, $this->
id))
return "Action {$this->name} already exists...";
208 if (isset($this->parent)) {
209 return ($this->parent->GetParam(
$name,
$def));
220 if (isset($this->parent)) {
221 return ($this->parent->setParamU(
$name, $val));
226 if (isset($this->parent)) {
227 return ($this->parent->GetImageUrl(
$name, $detectstyle,
$size));
233 if (isset($this->parent)) {
234 return ($this->parent->GetFilteredImageUrl(
$name));
240 if (isset($this->parent)) {
241 return ($this->parent->GetImageFile(
$name));
247 if (isset($this->parent)) {
248 return ($this->parent->AddLogMsg($msg, $cut));
254 if (isset($this->parent)) {
255 return ($this->parent->AddWarningMsg($msg));
265 if ($actdone !=
"") {
266 $sact = $this->
session->read(
"actdone_name", array());
267 $sarg = $this->
session->read(
"actdone_arg", array());
270 $sact = $this->
session->register(
"actdone_name", $sact);
271 $sarg = $this->
session->register(
"actdone_arg", $sarg);
281 $this->
session->unregister(
"actdone_name");
282 $this->
session->unregister(
"actdone_arg");
292 $actdone = $this->
session->read(
"actdone_name", array());
293 $arg = $this->
session->read(
"actdone_arg", array());
298 if ($width !=
"") $width =
"width = \"" . $width .
"\"";
299 if ($height !=
"") $height =
"height = \"" . $height .
"\"";
301 return (
"<img border=0 " . $width .
" " . $height .
" src=\"" . $this->
GetImageUrl(
$name) .
"\" title=\"" . $this->text($text) .
"\" alt=\"" . $this->text($text) .
"\">");
306 if (isset($this->parent))
return ($this->parent->GetLayoutFile($layname));
311 if ($idapp ==
'')
return false;
314 if ($id_func !=
'') {
315 $query->basic_elem->sup_where = array(
318 "id_application=$idapp"
321 $query->basic_elem->sup_where = array(
323 "id_application=$idapp"
334 if ($acl_name ==
"")
return (
true);
335 return ($this->parent->HasPermission($acl_name, $app_name));
347 if ($this->
user->id == 1)
return;
348 if ($appid ==
"") $appid = $this->parent->id;
349 elseif (!is_numeric($appid)) $appid = $this->parent->GetIdFromName($appid);
351 $aclname = $this->getAcl($actname, $appid);
352 if (!$aclname)
return;
353 $acl =
new Acl($this->dbaccess);
354 if (!$acl->Set($aclname, $appid)) {
355 return sprintf(_(
"Acl [%s] not available for App %s") , $aclname, $appid);
361 if (!$p->HasPrivilege($acl->id))
return sprintf(
"no privilege %s for %s %s", $aclname, $appid, $actname);
371 if ($appid ==
"") $appid = $this->parent->id;
373 $query->AddQuery(
"name = '$actname'");
374 $query->AddQuery(
"id_application = $appid");
376 if (is_array(
$q))
return $q[0][
"acl"];
386 if (!isset($this->parent))
return;
388 if ($this->auth && $this->auth->parms[
"type"] ==
"open") {
389 if ($this->openaccess !=
'Y') {
391 if ($this->auth->token && $this->auth->token[
"context"]) {
392 print $this->auth->token->context;
394 $context = unserialize($this->auth->token[
"context"]);
398 if (getHttpVars($k) != $v) {
402 if (!$allow) $this->
exitForbidden(sprintf(_(
"action %s is not declared to be access in open mode and token context not match") , $this->name));
405 if (!$allow) $this->
exitForbidden(sprintf(_(
"action %s is not declared to be access in open mode") , $this->name));
410 $this->
ExitError(sprintf(_(
"Access denied\nNeed ACL %s for action %s [%s]") , $this->acl, $this->short_name, $this->name));
414 global $QUERY_STRING;
415 $this->log->info(
"{$this->parent->name}:{$this->name} [" . substr($QUERY_STRING, 48) .
"]");
420 if ($this->parent->name !=
"CORE") {
421 $this->
register(
"LAST_ACT", $this->parent->name);
424 $this->log->push(
"{$this->parent->name}:{$this->name}");
425 $pubdir = $this->parent->GetParam(
"CORE_PUBDIR");
426 $nav = $this->
Read(
"navigator");
427 if ($this->layout !=
"") {
432 $this->lay =
new Layout($layout, $this);
433 if (isset($this->script) && $this->script !=
"") {
434 $script =
$pubdir .
"/" . $this->parent->name .
"/" . $this->script;
435 if (!file_exists($script))
436 $script =
$pubdir .
"/" . $this->parent->childof .
"/" . $this->script;
438 if (file_exists($script)) {
439 include_once ($script);
440 $call = $this->function;
443 $this->log->debug(
"$script does not exist");
446 $this->log->debug(
"No script provided : No script called");
449 $err = $this->
Read($this->parent->name .
"_ERROR",
"");
451 $this->lay->Set(
"ERR_MSG",
$err);
452 $this->
Unregister($this->parent->name .
"_ERROR");
454 $this->lay->Set(
"ERR_MSG",
"");
457 $out = $this->lay->gen();
470 $this->lay =
new Layout(
"CORE/Layout/error.xml", $this);
471 $this->lay->set(
"error", $texterr);
472 $this->lay->set(
"serror", str_replace(
"\n",
"\\n", addslashes($texterr)));
473 $this->lay->set(
"appname", $this->parent->name);
474 $this->lay->set(
"appact", $this->name);
475 if ($this->parent && $this->parent->parent) {
476 $this->parent->parent->cssref = array();
477 $this->parent->parent->jsref = array();
479 header(
'Warning: '.strtok($texterr,
"\n"));
480 print $this->lay->gen();
489 header(
"HTTP/1.0 401 Authorization Required ");
490 header(
"HTTP/1.0 301 Access Forbidden ");
505 if (
sizeof($action_desc) == 0) {
506 $this->log->info(
"No action available");
511 foreach ($action_desc as $k => $node) {
521 while (list($k, $v) = each($node)) {
522 if ($k ==
'available' && $update) {
529 while (list($k, $v) = each($node)) {
535 $acl =
new Acl($this->dbaccess);
538 $action->grant_level = $acl->grant_level;
550 $this->log->info(
"Update Action " . $node[
"name"]);
554 $this->log->info(
"Create Action " . $node[
"name"]);
561 $query->basic_elem->sup_where = array(
562 "id_application = {$app->id}"
565 while (list($k, $act) = each(
$list)) {
568 while ((list($k2, $v2) = each($action_desc)) && (!$find)) {
569 $find = ($v2[
"name"] == $act->name);
573 $this->log->info(
"Delete Action " . $act->name);
587 $v = getHttpVars($k, null);
588 if ($v === null)
return $def;
592 function Text($code, $args = NULL)
594 if ($code ==
"")
return "";
600 $this->log->debug($msg);
604 $this->log->info($msg);
608 $this->log->warning($msg);
612 $this->log->error($msg);
616 $this->log->fatal($msg);
625 $pubdir = $this->parent->GetParam(
"CORE_PUBDIR");
637 $query->basic_elem->sup_where = array(
645 foreach (
$list as $k => $appli) {
646 if ($appli[
"access_free"] ==
"N") {
648 if (isset($this->
user)) {
649 if ($this->
user->id != 1) {
653 $queryact =
new QueryDb($this->dbaccess,
"Action");
654 $queryact->AddQuery(
"id_application=" . $appli[
"id"]);
655 $queryact->AddQuery(
"root='Y'");
656 $listact = $queryact->Query(0, 0,
"TABLE");
657 $root_acl_name = $listact[0][
"acl"];
658 if (!$this->
HasPermission($root_acl_name, $appli[
"id"]))
continue;
664 $appli[
"description"] = $this->text($appli[
"description"]);
665 $appli[
"iconsrc"] = $this->
GetImageUrl($appli[
"icon"]);
666 if ($appli[
"iconsrc"] ==
"CORE/Images/noimage.png") $appli[
"iconsrc"] = $appli[
"name"] .
"/Images/" . $appli[
"icon"];