15 require_once (
'WHAT/autoload.php');
16 include_once (
"FDL/Lib.Util.php");
18 define(
"THROW_EXITERROR", 1968);
83 create table action (id int not null,
85 id_application int not null,
101 create index action_idx1 on action(id);
102 create index action_idx2 on action(id_application);
103 create index action_idx3 on action(name);
104 create sequence SEQ_ID_ACTION;
172 $this->
function =
"";
176 $query->basic_elem->sup_where = array(
178 "id_application={$parent->id}"
181 $query->basic_elem->sup_where = array(
183 "id_application={$parent->id}"
186 $query->Query(0, 0,
"TABLE");
188 $this->Affect(
$query->list[0]);
189 $this->log->debug(
"Set Action to {$this->name}");
192 $e->addHttpHeader(
'HTTP/1.0 404 Action not found');
206 if ($this->script ==
"") $this->script = strtolower($this->
name) .
".php";
207 if ($this->layout ==
"") $this->layout = strtolower($this->
name) .
".xml";
208 if ($this->
function ==
"") $this->
function = substr($this->script, 0, strpos($this->script,
'.php'));
214 $this->url = $this->GetParam(
"CORE_BASEURL") .
"app=" . $this->parent->name .
"&action=" .
$this->name;
216 if ($this->
user) $this->log->loghead = sprintf(
"%s %s [%d] - ", $this->
user->firstname, $this->user->lastname, $this->user->id);
217 else $this->log->loghead =
"user not defined - ";
220 $this->log->application = $this->parent->name;
236 if (is_object($this->
session)) {
251 return ($this->
session->Register($k, $v));
263 if (is_object($this->
session)) {
264 return ($this->
session->Unregister($k));
271 return ($this->
Read(
"{$this->id}_" . $k,
$d));
276 return ($this->
Register(
"{$this->id}_" . $k, $v));
281 return ($this->
Unregister(
"{$this->id}_" . $k));
286 if ($this->Exists($this->
name, $this->id_application))
return "Action {$this->name} already exists...";
287 $this->
exec_query(
"select nextval ('seq_id_action')");
289 $this->
id = $arr[
"nextval"];
294 if ($this->dbid == - 1)
return false;
295 if ($this->Exists($this->
name, $this->id_application, $this->
id))
return "Action {$this->name} already exists...";
308 if (isset($this->parent)) {
309 return ($this->parent->GetParam(
$name,
$def));
322 if (isset($this->parent)) {
323 return ($this->parent->setParamU(
$name, $val));
343 if (isset($this->parent)) {
344 return ($this->parent->getImageLink(
$name, $detectstyle,
$size));
351 if (isset($this->parent)) {
352 return ($this->parent->GetFilteredImageUrl(
$name));
359 if (isset($this->parent)) {
360 return ($this->parent->GetImageFile(
$name));
367 if (isset($this->parent)) {
368 $this->parent->AddLogMsg($msg, $cut);
374 if (isset($this->parent)) {
375 $this->parent->AddWarningMsg($msg);
387 if ($actdone !=
"") {
388 $sact = $this->
session->read(
"actdone_name", array());
389 $sarg = $this->
session->read(
"actdone_arg", array());
392 $this->
session->register(
"actdone_name", $sact);
393 $this->
session->register(
"actdone_arg", $sarg);
401 $this->
session->unregister(
"actdone_name");
402 $this->
session->unregister(
"actdone_arg");
412 $actdone = $this->
session->read(
"actdone_name", array());
413 $arg = $this->
session->read(
"actdone_arg", array());
426 if ($width !=
"") $width =
"width = \"" . $width .
"\"";
427 if ($height !=
"") $height =
"height = \"" . $height .
"\"";
429 return (
"<img border=0 " . $width .
" " . $height .
" src=\"" . $this->parent->getImageLink(
$name) .
"\" title=\"" . $this->
text($text) .
"\" alt=\"" . $this->
text($text) .
"\">");
439 if (isset($this->parent))
return ($this->parent->GetLayoutFile($layname));
451 if ($idapp ==
'')
return false;
454 if ($id_func !=
'') {
456 $query->AddQuery(sprintf(
"name='%s' and id != %d and id_application=%d", pg_escape_string(
$name) , $id_func, $idapp));
458 $query->AddQuery(sprintf(
"name='%s' and id_application=%d", pg_escape_string(
$name) , $idapp));
474 if (self::ACCESS_FREE == $acl_name)
return (
true);
475 return ($this->parent->HasPermission($acl_name, $app_name,
$strict));
488 if ($this->
user->id == 1)
return "";
493 if (!$aclname)
return "";
494 $acl =
new Acl($this->dbaccess);
496 return sprintf(_(
"Acl [%s] not available for App %s") , $aclname,
$appid);
502 if (!$p->HasPrivilege(
$acl->id))
return sprintf(
"no privilege %s for %s %s", $aclname,
$appid, $actname);
515 $query->AddQuery(
"name = '$actname'");
516 $query->AddQuery(
"id_application = $appid");
518 if (is_array(
$q))
return $q[0][
"acl"];
534 if (!isset($this->parent))
return '';
536 if ($this->auth && $this->auth->parms[
"type"] ===
"open") {
537 if ($this->openaccess !==
'Y') {
538 $this->
exitForbidden(sprintf(_(
"action %s is not declared to be access in open mode") , $this->
name));
542 if ($this->available ==
"N") {
544 $e->addHttpHeader(
'HTTP/1.0 503 Action unavalaible');
548 $appTag = $this->parent->tag;
549 if (preg_match(
'/(\W|\A)ADMIN(\W|\Z)/i', $appTag)) {
550 if (!$this->parent->isInAdminMode()) {
551 $e =
new Dcp\Exception(
"CORE0009", $this->short_name, $this->
name, $this->parent->name, $this->parent->short_name);
552 $e->addHttpHeader(
'HTTP/1.0 503 Action forbidden');
557 if (!$this->HasPermission($this->acl)) {
559 $e->addHttpHeader(
'HTTP/1.0 503 Action forbidden');
564 global $QUERY_STRING;
565 $this->log->info(
"{$this->parent->name}:{$this->name} [" . substr($QUERY_STRING, 48) .
"]");
568 $this->log->push(
"{$this->parent->name}:{$this->name}");
570 if ($this->layout !=
"") {
571 $layout = $this->GetLayoutFile($this->layout);
576 if (isset($this->script) && $this->script !=
"") {
586 $this->log->debug(
"$script does not exist");
589 $this->log->debug(
"No script provided : No script called");
592 $err = $this->
Read($this->parent->name .
"_ERROR",
"");
594 $this->lay->Set(
"ERR_MSG",
$err);
595 $this->
Unregister($this->parent->name .
"_ERROR");
597 $this->lay->Set(
"ERR_MSG",
"");
600 $out = $this->lay->gen();
615 public function exitError($texterr, $exit =
true, $code =
"")
617 if (!empty(
$_SERVER[
'HTTP_HOST'])) {
619 $useHtml = ((!empty($accept) && preg_match(
"@\\btext/html\\b@", $accept)));
622 $this->lay =
new Layout(
"CORE/Layout/error.xml", $this);
623 $this->lay->set(
"TITLE", _(
"Error"));
624 header(
'Warning: ' . strtok($texterr,
"\n"));
625 $texterr =
cleanhtmljs(\Dcp\Utils\htmlclean::normalizeHTMLFragment(nl2br($texterr)));
626 $this->lay->set(
"error", str_replace(
"[",
"[", $texterr));
627 $this->lay->set(
"serror", str_replace(
"[",
"\\u005b", json_encode($texterr, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP)));
628 $this->lay->set(
"appname", (empty($this->parent)) ?
'' : $this->parent->name);
629 $this->lay->set(
"appact", $this->
name);
630 $this->lay->eset(
"code", $code ?
"[$code]" :
"");
632 print $this->lay->gen();
635 $texterr = sprintf(
"[%s] %s", $code, $texterr);
637 $useJSON = ((!empty($accept) && preg_match(
"@\\bapplication/json\\b@", $accept)));
640 header(
'Content-Type: application/json');
641 $error = [
"success" =>
false,
"exceptionMessage" => $texterr];
642 print json_encode($error);
651 if ($this->parent && $this->parent->parent) {
652 $this->parent->parent->cssref = array();
653 $this->parent->parent->jsref = array();
662 if (php_sapi_name() !==
'cli') {
663 header(
"HTTP/1.0 403 Forbidden");
667 error_log(sprintf(
"Forbidden: %s\n", $texterr));
686 public function Init(
$app, $action_desc, $update =
false)
688 if (
sizeof($action_desc) == 0) {
689 $this->log->info(
"No action available");
694 foreach ($action_desc as $node) {
704 foreach ($node as $k => $v) {
705 if ($k ==
'available' && $update) {
712 foreach ($node as $k => $v) {
718 $acl =
new Acl($this->dbaccess);
733 $this->log->info(
"Update Action " . $node[
"name"]);
737 $this->log->info(
"Create Action " . $node[
"name"]);
744 $query->basic_elem->sup_where = array(
745 "id_application = {$app->id}"
748 foreach (
$list as $k => $act) {
755 while ((list($k2, $v2) = each($action_desc)) && (!$find)) {
756 $find = ($v2[
"name"] == $act->name);
760 $this->log->info(
"Delete Action " . $act->name);
778 if ($v === null)
return $def;
788 public static function text($code)
790 if ($code ==
"")
return "";
801 $this->log->debug($msg);
811 $this->log->info($msg);
821 $this->log->warning($msg);
831 $this->log->error($msg);
841 $this->log->fatal($msg);
863 $query->basic_elem->sup_where = array(
871 foreach (
$list as $k => $appli) {
872 if ($appli[
"access_free"] ==
"N") {
874 if (isset($this->
user)) {
875 if ($this->
user->id != 1) {
879 $queryact =
new QueryDb($this->dbaccess,
"Action");
880 $queryact->AddQuery(
"id_application=" . $appli[
"id"]);
881 $queryact->AddQuery(
"root='Y'");
882 $listact = $queryact->Query(0, 0,
"TABLE");
883 $root_acl_name = $listact[0][
"acl"];
884 if (!$this->HasPermission($root_acl_name, $appli[
"id"]))
continue;
890 $appli[
"description"] = $this->
text($appli[
"description"]);
891 $appli[
"iconsrc"] = $this->parent->getImageLink($appli[
"icon"]);
892 if ($appli[
"iconsrc"] ==
"CORE/Images/core-noimage.png") $appli[
"iconsrc"] = $appli[
"name"] .
"/Images/" . $appli[
"icon"];
hasPermission($acl_name="", $app_name="", $strict=false)
Layout is a template generator.
addActionDone($actdone, $arg="")
exec_query($sql, $lvl=0, $prepare=false)
exists($name, $idapp, $id_func=0)
Init($app, $action_desc, $update=false)
print $fam getTitle() $fam name
Exception class use exceptionCode to identifiy correctly exception.
getFilteredImageUrl($name)
getImageUrl($name, $detectstyle=true, $size=null)
static getError($code, $args=null)
fetch_array($c, $type=PGSQL_ASSOC)
exitError($texterr, $exit=true, $code="")
canExecute($actname, $appid="")
getHttpVars($name, $def="", $scope="all")
deprecatedFunction($msg= '')
getAvailableApplication()
getActionDone(&$actdone, &$arg)
static getArgument($k, $def= '')
if(($docid!==0)&&(!is_numeric($docid))) $query
getAcl($actname, $appid="")
if($file) if($subject==""&&$file) if($subject=="") $err
getIcon($name, $text, $width="", $height="")