Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Action.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Action class
8  *
9  * @author Anakeen
10  * @version $Id: Class.Action.php,v 1.40 2008/03/10 15:09:17 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 
15 require_once ('WHAT/autoload.php');
16 include_once ("FDL/Lib.Util.php");
17 
18 define("THROW_EXITERROR", 1968);
19 /**
20  * manage Action
21  * Action is part of Application
22  * @see Application
23  */
24 class Action extends DbObj
25 {
26  /**
27  * fake ACL to allow an action to be access free without its application being access_free
28  */
29  const ACCESS_FREE = "";
30  var $fields = array(
31  "id",
32  "id_application",
33  "name",
34  "short_name",
35  "long_name",
36  "script",
37  "function",
38  "layout",
39  "available",
40  "acl",
41  "grant_level",
42  "openaccess",
43  "root",
44  "icon",
45  "toc",
46  "father",
47  "toc_order"
48  );
49  public $id;
51  public $name;
52  public $short_name;
53  public $long_name;
54  public $script;
55  /**
56  * @var string
57  */
58  public $function;
59  public $layout;
60  public $available;
61  public $acl;
62  public $grant_level = 0;
63  public $openaccess;
64  public $root;
65  public $icon;
66  public $toc;
67  public $father;
68  public $toc_order;
69 
70  var $id_fields = array(
71  "id"
72  );
73 
74  var $idx = array(
75  "id",
76  "id_application",
77  "name"
78  );
79 
80  var $dbtable = "action";
81 
82  var $sqlcreate = '
83 create table action (id int not null,
84  primary key (id),
85  id_application int not null,
86  name text not null,
87  short_name text ,
88  long_name text,
89  script text,
90  function text,
91  layout text ,
92  available char,
93  acl text,
94  grant_level int,
95  openaccess char,
96  root char,
97  icon text,
98  toc char,
99  father int ,
100  toc_order int);
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;
105  ';
106  /**
107  * @var Application
108  */
109  public $parent;
110 
111  var $def = array(
112  "criteria" => "",
113  "order_by" => "name"
114  );
115 
116  var $criterias = array(
117  "name" => array(
118  "libelle" => "Nom",
119  "type" => "TXT"
120  )
121  );
122  /**
123  * current user
124  * @var Account
125  */
126  public $user;
127  /**
128  * current session
129  * @var Session
130  */
131  public $session;
132  /**
133  * @var string url to access action
134  */
135  public $url;
136  /**
137  * @var Authenticator|openAuthenticator
138  */
139  public $auth;
140  /**
141  * @var int inheritance level
142  */
143  public $level;
144  /**
145  * @var Layout
146  */
147  public $lay;
148  /**
149  * initialize Action object
150  * need set action to execute it
151  *
152  * @code
153  $core = new Application();
154  $core->Set("CORE", $CoreNull); // init core application from nothing
155  $core->session = new Session();
156  $core->session->set();
157  $one = new Application();
158  $one->set("ONEFAM", $core, $core->session);// init ONEFAM application from core
159  $myAct=new Action();
160  $myAct->set("ONEFAM_LIST", $one);
161  print $myAct->execute();
162  *
163  * @endcode
164  * @param string $name action name reference
165  * @param Application $parent application object where action depends
166  * @throws Dcp\Core\Exception if action not exists
167  */
168  public function Set($name, &$parent)
169  {
170  $this->script = "";
171  $this->layout = "";
172  $this->function = "";
173  $query = new QueryDb($this->dbaccess, "Action");
174  if ($name != "") {
175  $name = pg_escape_string($name);
176  $query->basic_elem->sup_where = array(
177  "name='$name'",
178  "id_application={$parent->id}"
179  );
180  } else {
181  $query->basic_elem->sup_where = array(
182  "root='Y'",
183  "id_application={$parent->id}"
184  );
185  }
186  $query->Query(0, 0, "TABLE");
187  if ($query->nb > 0) {
188  $this->Affect($query->list[0]);
189  $this->log->debug("Set Action to {$this->name}");
190  } else {
191  $e = new Dcp\Core\Exception("CORE0005", $name, $parent->name, $parent->id);
192  $e->addHttpHeader('HTTP/1.0 404 Action not found');
193  throw $e;
194  }
195 
196  $this->CompleteSet($parent);
197  }
198  /**
199  * add Application parent
200  * @param Application $parent
201  * @return string
202  */
203  public function completeSet(&$parent)
204  {
205  $this->parent = & $parent;
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'));
209 
210  $this->session = & $parent->session;
211 
212  $this->user = & $parent->user;
213  // Set the hereurl if possible
214  $this->url = $this->GetParam("CORE_BASEURL") . "app=" . $this->parent->name . "&action=" . $this->name;
215  // Init a log attribute
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 - ";
218 
219  $this->log->function = $this->name;
220  $this->log->application = $this->parent->name;
221  return "";
222  }
223 
224  public function complete()
225  {
226  }
227  /**
228  * read a session variable
229  *
230  * @param string $k key variable
231  * @param string $d default value
232  * @return string
233  */
234  public function Read($k, $d = "")
235  {
236  if (is_object($this->session)) {
237  return ($this->session->Read($k, $d));
238  }
239  return ($d . "--");
240  }
241  /**
242  * record a session variable
243  *
244  * @param string $k key variable
245  * @param string $v value to set
246  * @return bool return true if ok
247  */
248  public function Register($k, $v)
249  {
250  if (isset($this->session) && is_object($this->session)) {
251  return ($this->session->Register($k, $v));
252  }
253  return false;
254  }
255  /**
256  * remove variable from current session
257  *
258  * @param string $k key variable
259  * @return bool return true if ok
260  */
261  public function Unregister($k)
262  {
263  if (is_object($this->session)) {
264  return ($this->session->Unregister($k));
265  }
266  return false;
267  }
268 
269  public function actRead($k, $d = "")
270  {
271  return ($this->Read("{$this->id}_" . $k, $d));
272  }
273 
274  public function actRegister($k, $v)
275  {
276  return ($this->Register("{$this->id}_" . $k, $v));
277  }
278 
279  public function actUnregister($k)
280  {
281  return ($this->Unregister("{$this->id}_" . $k));
282  }
283 
284  public function PreInsert()
285  {
286  if ($this->Exists($this->name, $this->id_application)) return "Action {$this->name} already exists...";
287  $this->exec_query("select nextval ('seq_id_action')");
288  $arr = $this->fetch_array(0);
289  $this->id = $arr["nextval"];
290  return '';
291  }
292  public function PreUpdate()
293  {
294  if ($this->dbid == - 1) return false;
295  if ($this->Exists($this->name, $this->id_application, $this->id)) return "Action {$this->name} already exists...";
296  return '';
297  }
298  /**
299  * get parameter value of action'sapplication
300  * shorcut to Application::getParam
301  *
302  * @param string $name
303  * @param string $def default value if not set
304  * @return string
305  */
306  public function getParam($name, $def = "")
307  {
308  if (isset($this->parent)) {
309  return ($this->parent->GetParam($name, $def));
310  }
311  return $def;
312  }
313  /**
314  * set a new value for a user parameter
315  * @see ParameterManager::setUserApplicationParameter
316  * @param string $name parameter key
317  * @param string $val new value for the parameter
318  * @return string error message if not succeed else empty string
319  */
320  public function setParamU($name, $val)
321  {
322  if (isset($this->parent)) {
323  return ($this->parent->setParamU($name, $val));
324  }
325  return '';
326  }
327  /**
328  * get image url of an application
329  * shorcut to Application::getImageUrl
330  *
331  * @see Application::getImageLink
332  *
333  * @deprecated use { @link Application::getImageLink } instead
334  *
335  * @param string $name image filename
336  * @param bool $detectstyle to use theme image instead of original
337  * @param int $size to use image with another width (in pixel) - null is original size
338  * @return string url to download image
339  */
340  public function getImageUrl($name, $detectstyle = true, $size = null)
341  {
343  if (isset($this->parent)) {
344  return ($this->parent->getImageLink($name, $detectstyle, $size));
345  }
346  return '';
347  }
348 
349  public function getFilteredImageUrl($name)
350  {
351  if (isset($this->parent)) {
352  return ($this->parent->GetFilteredImageUrl($name));
353  }
354  return '';
355  }
356 
357  public function getImageFile($name)
358  {
359  if (isset($this->parent)) {
360  return ($this->parent->GetImageFile($name));
361  }
362  return '';
363  }
364 
365  public function addLogMsg($msg, $cut = 0)
366  {
367  if (isset($this->parent)) {
368  $this->parent->AddLogMsg($msg, $cut);
369  }
370  }
371 
372  public function addWarningMsg($msg)
373  {
374  if (isset($this->parent)) {
375  $this->parent->AddWarningMsg($msg);
376  }
377  return '';
378  }
379  /**
380  * store action done to be use in refreshing main window interface
381  *
382  * @param string $actdone the code of action
383  * @param string $arg the argument of action
384  */
385  public function addActionDone($actdone, $arg = "")
386  {
387  if ($actdone != "") {
388  $sact = $this->session->read("actdone_name", array());
389  $sarg = $this->session->read("actdone_arg", array());
390  $sact[] = $actdone;
391  $sarg[] = $arg;
392  $this->session->register("actdone_name", $sact);
393  $this->session->register("actdone_arg", $sarg);
394  }
395  }
396  /**
397  * clear action done to be use in refreshing main window interface
398  */
399  public function clearActionDone()
400  {
401  $this->session->unregister("actdone_name");
402  $this->session->unregister("actdone_arg");
403  }
404  /**
405  * get action code and argument for action code done
406  * to be use in refreshing main window interface
407  * @param string &$actdone the code of action
408  * @param string &$arg the argument of action
409  */
410  public function getActionDone(&$actdone, &$arg)
411  {
412  $actdone = $this->session->read("actdone_name", array());
413  $arg = $this->session->read("actdone_arg", array());
414  }
415  /**
416  * get image HTML fragment
417  * @param string $name icon filename
418  * @param string $text alternative text
419  * @param string $width icon width
420  * @param string $height icon Height
421  * @return string HTML fragment image tag
422  */
423  public function getIcon($name, $text, $width = "", $height = "")
424  {
425 
426  if ($width != "") $width = "width = \"" . $width . "\"";
427  if ($height != "") $height = "height = \"" . $height . "\"";
428 
429  return ("<img border=0 " . $width . " " . $height . " src=\"" . $this->parent->getImageLink($name) . "\" title=\"" . $this->text($text) . "\" alt=\"" . $this->text($text) . "\">");
430  }
431  /**
432  * get file path layout from layout name
433  * @see Application::getLayoutFile
434  * @param $layname
435  * @return string
436  */
437  public function getLayoutFile($layname)
438  {
439  if (isset($this->parent)) return ($this->parent->GetLayoutFile($layname));
440  return '';
441  }
442  /**
443  * Verify if action exists
444  * @param string $name action name
445  * @param int $idapp application numeric identifier
446  * @param int $id_func action identifier - when test itself @ internal purpose
447  * @return bool true if exists
448  */
449  public function exists($name, $idapp, $id_func = 0)
450  {
451  if ($idapp == '') return false;
452  $query = new QueryDb($this->dbaccess, "Action");
453 
454  if ($id_func != '') {
455 
456  $query->AddQuery(sprintf("name='%s' and id != %d and id_application=%d", pg_escape_string($name) , $id_func, $idapp));
457  } else {
458  $query->AddQuery(sprintf("name='%s' and id_application=%d", pg_escape_string($name) , $idapp));
459  }
460 
461  $query->Query();
462  return ($query->nb > 0);
463  }
464  /**
465  * Verify acl grant for current user
466  *
467  * @param string $acl_name acl name
468  * @param string $app_name app name to specify another appname (else current app name)
469  * @param bool $strict to not use substitute account information
470  * @return bool true if current user has acl privilege
471  */
472  public function hasPermission($acl_name = "", $app_name = "", $strict = false)
473  {
474  if (self::ACCESS_FREE == $acl_name) return (true); // no control for this action
475  return ($this->parent->HasPermission($acl_name, $app_name, $strict));
476  }
477  /**
478  * Check if the current user can execute the specified action.
479  * @api verify if an action can be executed
480  * @param string $actname action name
481  * @param string $appid application name or application id (default is the current application)
482  * @return string with error message if the user cannot execute the given action, or an empty string if the user can execute the action
483  *
484  */
485  public function canExecute($actname, $appid = "")
486  {
487 
488  if ($this->user->id == 1) return "";
489  if ($appid == "") $appid = $this->parent->id;
490  elseif (!is_numeric($appid)) $appid = $this->parent->GetIdFromName($appid);
491 
492  $aclname = $this->getAcl($actname, $appid);
493  if (!$aclname) return ""; // no control
494  $acl = new Acl($this->dbaccess);
495  if (!$acl->Set($aclname, $appid)) {
496  return sprintf(_("Acl [%s] not available for App %s") , $aclname, $appid);
497  }
498  $p = new Permission($this->dbaccess, array(
499  $this->user->id,
500  $appid
501  ));
502  if (!$p->HasPrivilege($acl->id)) return sprintf("no privilege %s for %s %s", $aclname, $appid, $actname);
503  return "";
504  }
505  /**
506  * return acl name for an action
507  * @param string $actname action name
508  * @param string $appid application id (default itself)
509  * @return string (false if not found)
510  */
511  public function getAcl($actname, $appid = "")
512  {
513  if ($appid == "") $appid = $this->parent->id;
514  $query = new QueryDb($this->dbaccess, $this->dbtable);
515  $query->AddQuery("name = '$actname'");
516  $query->AddQuery("id_application = $appid");
517  $q = $query->Query(0, 0, "TABLE");
518  if (is_array($q)) return $q[0]["acl"];
519  return false;
520  }
521  /**
522  * execute the action
523  * test if current user can execute it
524  *
525  *
526  * @throws Dcp\Core\Exception
527  * @throws Dcp\Exception
528  *
529  * @return string the composed associated layout
530  */
531  public function execute()
532  {
533  // If no parent set , it's a misconfiguration
534  if (!isset($this->parent)) return '';
535 
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));
539  }
540  }
541 
542  if ($this->available == "N") {
543  $e = new Dcp\Core\Exception("CORE0008", $this->name, $this->parent->name);
544  $e->addHttpHeader('HTTP/1.0 503 Action unavalaible');
545  throw $e;
546  }
547  // check if we are in an admin application and user can execute it
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');
553  throw $e;
554  }
555  }
556  // check if this action is permitted
557  if (!$this->HasPermission($this->acl)) {
558  $e = new Dcp\Exception("CORE0006", $this->short_name, $this->name, $this->acl, $this->user->login);
559  $e->addHttpHeader('HTTP/1.0 503 Action forbidden');
560  throw $e;
561  }
562 
563  if ($this->id > 0) {
564  global $QUERY_STRING;
565  $this->log->info("{$this->parent->name}:{$this->name} [" . substr($QUERY_STRING, 48) . "]");
566  }
567 
568  $this->log->push("{$this->parent->name}:{$this->name}");
570  if ($this->layout != "") {
571  $layout = $this->GetLayoutFile($this->layout);
572  } else {
573  $layout = "";
574  }
575  $this->lay = new Layout($layout, $this);
576  if (isset($this->script) && $this->script != "") {
577  $script = $pubdir . "/" . $this->parent->name . "/" . $this->script;
578  if (!file_exists($script)) // try generic application
579  $script = $pubdir . "/" . $this->parent->childof . "/" . $this->script;
580 
581  if (file_exists($script)) {
582  include_once ($script);
583  $call = $this->function;
584  $call($this);
585  } else {
586  $this->log->debug("$script does not exist");
587  }
588  } else {
589  $this->log->debug("No script provided : No script called");
590  }
591  // Is there any error messages
592  $err = $this->Read($this->parent->name . "_ERROR", "");
593  if ($err != "") {
594  $this->lay->Set("ERR_MSG", $err);
595  $this->Unregister($this->parent->name . "_ERROR");
596  } else {
597  $this->lay->Set("ERR_MSG", "");
598  }
599 
600  $out = $this->lay->gen();
601  $this->log->pop();
602 
603  return ($out);
604  }
605  /**
606  * display error to user and stop execution
607  *
608  * @param string $texterr the error message
609  * @param bool $exit if false , no exit are performed
610  * @param string $code error code (ref to error log)
611  *
612  * @throws \Dcp\Core\Exception
613  * @api abort action execution
614  */
615  public function exitError($texterr, $exit = true, $code = "")
616  {
617  if (!empty($_SERVER['HTTP_HOST'])) {
618  $accept = $_SERVER['HTTP_ACCEPT'];
619  $useHtml = ((!empty($accept) && preg_match("@\\btext/html\\b@", $accept)));
620 
621  if ($useHtml) {
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("[", "&#x5b;", $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]" : "");
631 
632  print $this->lay->gen();
633  } else {
634  if ($code) {
635  $texterr = sprintf("[%s] %s", $code, $texterr);
636  }
637  $useJSON = ((!empty($accept) && preg_match("@\\bapplication/json\\b@", $accept)));
638 
639  if ($useJSON) {
640  header('Content-Type: application/json');
641  $error = ["success" => false, "exceptionMessage" => $texterr];
642  print json_encode($error);
643  } else {
644  print $texterr;
645  }
646  }
647  if ($exit) {
648  exit;
649  }
650 
651  if ($this->parent && $this->parent->parent) { // reset js ans ccs
652  $this->parent->parent->cssref = array();
653  $this->parent->parent->jsref = array();
654  }
655  } else {
656  throw new Dcp\Core\Exception("CORE0001", $texterr);
657  }
658  }
659 
660  public function exitForbidden($texterr)
661  {
662  if (php_sapi_name() !== 'cli') {
663  header("HTTP/1.0 403 Forbidden");
664  print ErrorCode::getError("CORE0012", $texterr);
665  exit;
666  } else {
667  error_log(sprintf("Forbidden: %s\n", $texterr));
668  throw new Dcp\Core\Exception("CORE0012", $texterr);
669  }
670  }
671  /**
672  * unregister FT error
673  */
674  public function clearError()
675  {
676  $this->Unregister("FT_ERROR");
677  $this->Unregister("FT_ERROR_ACT");
678  }
679  /**
680  * record/update action
681  * @param Application $app application
682  * @param array $action_desc action description
683  * @param bool $update set to true if update only
684  * @return string none
685  */
686  public function Init($app, $action_desc, $update = false)
687  {
688  if (sizeof($action_desc) == 0) {
689  $this->log->info("No action available");
690  return ("");
691  }
692  $father[0] = "";
693 
694  foreach ($action_desc as $node) {
695  // set some default values
696  $action = new Action($this->dbaccess);
697  $action->root = "N";
698  $action->available = "Y";
699  $action->id_application = $app->id;
700  $action->toc = "N";
701  // If the action already exists ,set it
702  if ($action->Exists($node["name"], $app->id)) {
703  $action->Set($node["name"], $app);
704  foreach ($node as $k => $v) {
705  if ($k == 'available' && $update) {
706  continue;
707  }
708  $action->$k = $v;
709  }
710  reset($node);
711  } else {
712  foreach ($node as $k => $v) {
713  $action->$k = $v;
714  }
715  reset($node);
716  }
717  // Get the acl grant level
718  $acl = new Acl($this->dbaccess);
719  if (isset($action->acl)) {
720  $acl->Set($action->acl, $action->id_application);
721  $action->grant_level = $acl->grant_level;
722  } else {
723  $action->grant_level = 0;
724  }
725  // set non set values if possible
726  if ($action->long_name == "") $action->long_name = $action->short_name;
727  if ($action->script == "") $action->script = strtolower($action->name) . ".php";
728  if ($action->layout == "") $action->layout = strtolower($action->name) . ".xml";
729  if (!isset($action->level)) $action->level = 0;
730 
731  $action->father = $father[$action->level];
732  if ($action->Exists($node["name"], $app->id)) {
733  $this->log->info("Update Action " . $node["name"]);
734  $action->Modify();
735  } else {
736  $action->Add();
737  $this->log->info("Create Action " . $node["name"]);
738  }
739  $father[$action->level + 1] = $action->id;
740  }
741  // if update , remove unused actions
742  if ($update) {
743  $query = new QueryDb($this->dbaccess, "Action");
744  $query->basic_elem->sup_where = array(
745  "id_application = {$app->id}"
746  );
747  $list = $query->Query();
748  foreach ($list as $k => $act) {
749  /*
750  * @var Action $act
751  */
752  $find = false;
753  reset($action_desc);
754  /** @noinspection PhpUnusedLocalVariableInspection */
755  while ((list($k2, $v2) = each($action_desc)) && (!$find)) {
756  $find = ($v2["name"] == $act->name);
757  }
758  if (!$find) {
759  // remove the action
760  $this->log->info("Delete Action " . $act->name);
761  $act->Delete();
762  }
763  }
764  }
765  return '';
766  }
767  /**
768  * retrieve the value of an argument fot the action
769  * in web mode the value comes from http variable and in shell mode comes from args variable
770  *
771  * @param string $k the argument name
772  * @param mixed $def default value if no argument is not set
773  * @return mixed|string
774  */
775  public static function getArgument($k, $def = '')
776  {
777  $v = getHttpVars($k, null);
778  if ($v === null) return $def;
779  else return $v;
780  }
781  /**
782  * translate text
783  * use gettext catalog
784  *
785  * @param string $code text to translate
786  * @return string
787  */
788  public static function text($code)
789  {
790  if ($code == "") return "";
791  return _($code);
792  }
793  /**
794  * log with debug level
795  *
796  * @see Log
797  * @param string $msg message text
798  */
799  public function debug($msg)
800  {
801  $this->log->debug($msg);
802  }
803  /**
804  * log with info level
805  *
806  * @see Log
807  * @param string $msg message text
808  */
809  public function info($msg)
810  {
811  $this->log->info($msg);
812  }
813  /**
814  * log with warning level
815  *
816  * @see Log
817  * @param string $msg message text
818  */
819  public function warning($msg)
820  {
821  $this->log->warning($msg);
822  }
823  /**
824  * log with error level
825  *
826  * @see Log
827  * @param string $msg message text
828  */
829  public function error($msg)
830  {
831  $this->log->error($msg);
832  }
833  /**
834  * log with fatal level
835  *
836  * @see Log
837  * @param string $msg message text
838  */
839  public function fatal($msg)
840  {
841  $this->log->fatal($msg);
842  }
843  /**
844  * verify if an application is really installed in localhost
845  * @param string $appname application reference name
846  * @return bool true if application is installed
847  */
848  public function appInstalled($appname)
849  {
850 
852 
853  return (@is_dir($pubdir . "/" . $appname));
854  }
855  /**
856  * return available Applications for current user
857  * @return array
858  */
859  public function getAvailableApplication()
860  {
861 
862  $query = new QueryDb($this->dbaccess, "Application");
863  $query->basic_elem->sup_where = array(
864  "available='Y'",
865  "displayable='Y'"
866  );
867  $list = $query->Query(0, 0, "TABLE");
868  $tab = array();
869  if ($query->nb > 0) {
870  $i = 0;
871  foreach ($list as $k => $appli) {
872  if ($appli["access_free"] == "N") {
873 
874  if (isset($this->user)) {
875  if ($this->user->id != 1) { // no control for user Admin
876  //if ($p->id_acl == "") continue;
877  // test if acl of root action is granted
878  // search acl for root action
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;
885  }
886  } else {
887  continue;
888  }
889  }
890  $appli["description"] = $this->text($appli["description"]); // translate
891  $appli["iconsrc"] = $this->parent->getImageLink($appli["icon"]);
892  if ($appli["iconsrc"] == "CORE/Images/core-noimage.png") $appli["iconsrc"] = $appli["name"] . "/Images/" . $appli["icon"];
893 
894  $tab[$i++] = $appli;
895  }
896  }
897  return $tab;
898  }
899 }
hasPermission($acl_name="", $app_name="", $strict=false)
Layout is a template generator.
addActionDone($actdone, $arg="")
static text($code)
$appname
addWarningMsg($msg)
const ACCESS_FREE
global $action
clearActionDone()
global $pubdir
Definition: vault_init.php:18
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.
Definition: exceptions.php:19
Register($k, $v)
$size
Definition: resizeimg.php:110
getFilteredImageUrl($name)
cleanhtmljs($html)
Definition: Lib.Util.php:624
getImageUrl($name, $detectstyle=true, $size=null)
info($msg)
debug($msg)
$core user
Definition: chgpasswd.php:38
actUnregister($k)
getImageFile($name)
static getError($code, $args=null)
Definition: ErrorCode.php:27
setParamU($name, $val)
$d
Definition: dav.php:77
Unregister($k)
fetch_array($c, $type=PGSQL_ASSOC)
Set($name, &$parent)
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
completeSet(&$parent)
exitError($texterr, $exit=true, $code="")
exitForbidden($texterr)
error($msg)
$core session
Definition: wsh.php:98
getLayoutFile($layname)
fatal($msg)
canExecute($actname, $appid="")
Read($k, $d="")
$app
getHttpVars($name, $def="", $scope="all")
Definition: Lib.Http.php:124
print
Definition: checklist.php:49
appInstalled($appname)
warning($msg)
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
global $_SERVER
addLogMsg($msg, $cut=0)
switch($command) exit
Definition: checkVault.php:46
actRegister($k, $v)
getParam($name, $def="")
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="")
actRead($k, $d="")
← centre documentaire © anakeen