Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Application.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Application Class
8  *
9  * @author Anakeen
10  * @version $Id: Class.Application.php,v 1.64 2008/08/01 09:03:01 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 
17 require_once ('WHAT/autoload.php');
18 include_once ('WHAT/Lib.Http.php');
19 include_once ('WHAT/Lib.Common.php');
20 
21 function f_paramglog($var)
22 { // filter to select only not global
23  return (!((isset($var["global"]) && ($var["global"] == 'Y'))));
24 }
25 /**
26  * Application managing
27  * @class Application
28  *
29  */
30 class Application extends DbObj
31 {
32  public $fields = array(
33  "id",
34  "name",
35  "short_name",
36  "description",
37  "access_free", //@deprecated
38  "available",
39  "icon",
40  "displayable",
41  "with_frame",
42  "childof",
43  "objectclass", //@deprecated
44  "ssl", //@deprecated
45  "machine", //@deprecated
46  "iorder",
47  "tag"
48  );
49  /**
50  * @var int application identifier
51  */
52  public $id;
53  public $name;
54  public $short_name;
55  public $description;
56  /**
57  * @deprecated
58  * @var $access_free
59  */
60  public $access_free;
61  public $available;
62  public $icon;
63  public $displayable;
64  public $with_frame;
65  public $childof;
66  /**
67  * @deprecated
68  * @var $objectclass
69  */
70  public $objectclass;
71  /**
72  * @deprecated
73  * @var $ssl
74  */
75  public $ssl;
76  /**
77  * @deprecated
78  * @var $machine
79  */
80  public $machine;
81  public $iorder;
82  public $tag;
83  public $id_fields = array(
84  "id"
85  );
86  public $rootdir = '';
87  public $fulltextfields = array(
88  "name",
89  "short_name",
90  "description"
91  );
92  public $sqlcreate = '
93 create table application ( id int not null,
94  primary key (id),
95  name text not null,
96  short_name text,
97  description text ,
98  access_free char,
99  available char,
100  icon text,
101  displayable char,
102  with_frame char,
103  childof text,
104  objectclass char,
105  ssl char,
106  machine text,
107  iorder int,
108  tag text);
109 create index application_idx1 on application(id);
110 create index application_idx2 on application(name);
111 create sequence SEQ_ID_APPLICATION start 10;
112 ';
113 
114  public $dbtable = "application";
115 
116  public $def = array(
117  "criteria" => "",
118  "order_by" => "name"
119  );
120 
121  public $criterias = array(
122  "name" => array(
123  "libelle" => "Nom",
124  "type" => "TXT"
125  )
126  );
127  /**
128  * @var Application
129  */
130  public $parent = null;
131  /**
132  * @var Session
133  */
134  public $session = null;
135  /**
136  * @var Account
137  */
138  public $user = null;
139  /**
140  * @var Style
141  */
142  public $style;
143  /**
144  * @var Param
145  */
146  public $param;
147  /**
148  * @var Permission
149  */
150  public $permission = null; // permission object
151 
152  /**
153  * @var Log
154  */
155  public $log = null;
156  public $jsref = array();
157  public $jscode = array();
158  public $logmsg = array();
159  /**
160  * true if application is launched from admin context
161  * @var bool
162  */
163  protected $adminMode = false;
164 
165  public $cssref = array();
166  public $csscode = array();
167  /**
168  * Application constructor.
169  * @param string $dbaccess
170  * @param string|string[] $id
171  * @param string|array $res
172  * @param int $dbid
173  */
174  function __construct($dbaccess = '', $id = '', $res = '', $dbid = 0)
175  {
176  parent::__construct($dbaccess, $id, $res, $dbid);
177  $this->rootdir = DEFAULT_PUBDIR;
178  }
179  /**
180  * initialize Application object
181  * @param string $name application name to set
182  * @param Application|string $parent the parent object (generally CORE app) : empty string if no parent
183  * @param string $session parent session
184  * @param bool $autoinit set to true to auto create app if not exists yet
185  *
186  * @param bool $verifyAvailable set to true to not exit when unavailable action
187  * @return string error message
188  * @throws \Dcp\Core\Exception if application not exists
189  * @throws \Dcp\Db\Exception
190  * @code
191  $CoreNull = "";
192  * $core = new Application();
193  * $core->Set("CORE", $CoreNull); // init core application from nothing
194  * $core->session = new Session();
195  * $core->session->set();
196  * $one = new Application();
197  * $one->set("ONEFAM", $core, $core->session);// init ONEFAM application from CORE
198  *
199  * @endcode
200  *
201  */
202  public function set($name, &$parent, $session = "", $autoinit = false, $verifyAvailable = true)
203  {
204  $this->log->debug("Entering : Set application to $name");
205 
206  $query = new QueryDb($this->dbaccess, "Application");
207  $query->order_by = "";
208  $query->criteria = "name";
209  $query->operator = "=";
210  $query->string = "'" . pg_escape_string($name) . "'";
211  $list = $query->Query(0, 0, "TABLE");
212  if ($query->nb != 0) {
213  $this->affect($list[0]);
214  $this->log->debug("Set application to $name");
215  if (!isset($parent)) {
216  $this->log->debug("Parent not set");
217  }
218  } else {
219  if ($autoinit) {
220  // Init the database with the app file if it exists
221  $this->InitApp($name);
222  if ($parent != "") {
223  $this->parent = & $parent;
224  if ($this->name == "") {
225  printf("Application name %s not found", $name);
226  exit;
227  } elseif (!empty($_SERVER['HTTP_HOST'])) {
228  Redirect($this, $this->name, "");
229  }
230  } else {
231  global $_SERVER;
232  if (!empty($_SERVER['HTTP_HOST'])) Header("Location: " . $_SERVER['HTTP_REFERER']);
233  }
234  } else {
235  $e = new Dcp\Core\Exception("CORE0004", $name);
236  $e->addHttpHeader('HTTP/1.0 404 Application not found');
237  throw $e;
238  }
239  }
240 
241  if ($this !== $parent) $this->parent = & $parent;
242  if (is_object($this->parent) && isset($this->parent->session)) {
243  $this->session = $this->parent->session;
244  if (isset($this->parent->user) && is_object($this->parent->user)) {
245  $this->user = $this->parent->user;
246  }
247  }
248 
249  if ($session != "") $this->SetSession($session);
250  $this->param = new Param($this->dbaccess);
251  $style = false;
252  if ($this->session) $style = $this->session->read("userCoreStyle", false);
253 
254  if ($style) {
255  $this->InitStyle(false, $style);
256  } else {
257  $this->InitStyle();
258  }
259  if ($this->session) {
260  $pStyle = $this->getParam("STYLE");
261  if ($pStyle) {
262  $this->session->register("userCoreStyle", $pStyle);
263  }
264  }
265 
266  $this->param->SetKey($this->id, isset($this->user->id) ? $this->user->id : false, $this->style->name);
267  if ($verifyAvailable && $this->available === "N") {
268  // error
269  $e = new Dcp\Core\Exception("CORE0007", $name);
270  $e->addHttpHeader('HTTP/1.0 503 Application unavailable');
271  throw $e;
272  }
273  $this->permission = null;
274  return '';
275  }
276 
277  public function complete()
278  {
279  }
280 
281  public function setSession(&$session)
282  {
283  $this->session = $session;
284  // Set the user if possible
285  if (is_object($this->session)) {
286  if ($this->session->userid != 0) {
287  $this->log->debug("Get user on " . $this->dbaccess);
288  $this->user = new Account($this->dbaccess, $this->session->userid);
289  } else {
290  $this->log->debug("User not set ");
291  }
292  }
293  }
294 
295  public function preInsert()
296  {
297  if ($this->Exists($this->name)) return "Ce nom d'application existe deja...";
298  if ($this->name == "CORE") {
299  $this->id = 1;
300  } else {
301  $this->exec_query("select nextval ('seq_id_application')");
302  $arr = $this->fetch_array(0);
303  $this->id = $arr["nextval"];
304  }
305  return '';
306  }
307 
308  public function preUpdate()
309  {
310  if ($this->dbid == - 1) return false;
311  if ($this->Exists($this->name, $this->id)) return "Ce nom d'application existe deja...";
312  return '';
313  }
314  /**
315  * Verify an application name exists
316  * @param string $app_name application reference name
317  * @param int $id_application optional numeric id to verify if not itself
318  * @return bool
319  */
320  public function exists($app_name, $id_application = 0)
321  {
322  $this->log->debug("Exists $app_name ?");
323  $query = new QueryDb($this->dbaccess, "application");
324  $query->order_by = "";
325  $query->criteria = "";
326 
327  if ($id_application != '') {
328  $query->basic_elem->sup_where = array(
329  "name='$app_name'",
330  "id!=$id_application"
331  );
332  } else {
333  $query->criteria = "name";
334  $query->operator = "=";
335  $query->string = "'" . $app_name . "'";
336  }
337 
338  $r = $query->Query(0, 0, "TABLE");
339 
340  return ($query->nb > 0) ? $r[0]["id"] : false;
341  }
342  /**
343  * Strip the pubdir/wpub directory from a file pathname
344  * @param string $pathname the file pathname
345  * @return string file pathname without the root dir
346  */
347  private function stripRootDir($pathname)
348  {
349  if (substr($pathname, 0, strlen($this->rootdir)) === $this->rootdir) {
350  $pathname = substr($pathname, strlen($this->rootdir) + 1);
351  }
352 
353  return $pathname;
354  }
355  /**
356  * Try to resolve a JS/CSS reference to a supported location
357  * @param string $ref the JS/CSS reference
358  * @return string the resolved location of the reference or an empty string on failure
359  */
360  private function resolveResourceLocation($ref)
361  {
362  if (strstr($ref, '../') !== false) {
363  return '';
364  }
365  /* Resolve through getLayoutFile */
366  $location = $this->GetLayoutFile($ref);
367  if ($location != '') {
368  return $this->stripRootDir($location);
369  }
370  /* Try "APP:file.extension" notation */
371  if (preg_match('/^(?P<appname>[a-z][a-z0-9_-]*):(?P<filename>.*)$/i', $ref, $m)) {
372  $location = sprintf('%s/%s/Layout/%s', $this->rootdir, $m['appname'], $m['filename']);
373  if (is_file($location)) {
374  return sprintf('%s/Layout/%s', $m['appname'], $m['filename']);
375  }
376  }
377  /* Try hardcoded locations */
378  foreach (array(
379  $ref,
380  sprintf("%s/Layout/%s", $this->name, $ref)
381  ) as $filename) {
382  if (is_file(sprintf("%s/%s", $this->rootdir, $filename))) {
383  return $filename;
384  }
385  }
386  /* Detect URLs */
387  $pUrl = parse_url($ref);
388  if (isset($pUrl['scheme']) || isset($pUrl['query'])) {
389  return $ref;
390  }
391 
392  if (is_file($ref)) return $ref;
393  /* TODO : update with application log class */
394  $this->log->error(__METHOD__ . " Unable to identify the ref $ref");
395 
396  return '';
397  }
398  /**
399  * Add a resource (JS/CSS) to the page
400  *
401  * @param string $type 'js' or 'css'
402  * @param string $ref the resource reference
403  * @param boolean $needparse should the resource be parsed (default false)
404  * @param string $packName
405  *
406  * @return string resource location
407  */
408  public function addRessourceRef($type, $ref, $needparse, $packName)
409  {
410  /* Try to attach the resource to the parent app */
411  if ($this->hasParent()) {
412  $ret = $this->parent->AddRessourceRef($type, $ref, $needparse, $packName);
413  if ($ret !== '') {
414  return $ret;
415  }
416  }
417 
418  $resourceLocation = $this->getResourceLocation($type, $ref, $needparse, $packName, true);
419  if (!$resourceLocation) {
420  $wng = sprintf(_("Cannot find %s resource file") , $ref);
421  $this->addLogMsg($wng);
422  $this->log->warning($wng);
423  }
424  if ($type == 'js') {
425  $this->jsref[$resourceLocation] = $resourceLocation;
426  } elseif ($type == 'css') {
427  $this->cssref[$resourceLocation] = $resourceLocation;
428  } else {
429  return '';
430  }
431 
432  return $resourceLocation;
433  }
434  /**
435  * Get resourceLocation with cache handling
436  *
437  * @param string $type (js|css)
438  * @param string $ref path or URI of the resource
439  * @param bool $needparse need to parse
440  * @param string $packName use it to pack all the ref with the same packName into a single file
441  * @param bool $fromAdd (do not use this param) true only if you call it from addRessourceRef function
442  *
443  * @return string new location
444  */
445  private function getResourceLocation($type, $ref, $needparse, $packName, $fromAdd = false)
446  {
447  static $firstPack = array();
448  $resourceLocation = '';
449 
450  $key = isset($this->session) ? $this->session->getUKey(getParam("WVERSION")) : uniqid(getParam("WVERSION"));
451  if ($packName) {
452 
453  $resourcePackParseLocation = sprintf("?app=CORE&amp;action=CORE_CSS&amp;type=%s&amp;ukey=%s&amp;pack=%s", $type, $key, $packName);
454  $resourcePackNoParseLocation = sprintf("pack.php?type=%s&amp;pack=%s&amp;wv=%s", $type, $packName, getParam("WVERSION"));
455 
456  if (!isset($firstPack[$packName])) {
457  $packSession = array();
458  $firstPack[$packName] = true;
459  } else {
460  $packSession = ($this->session ? $this->session->Read("RSPACK_" . $packName) : array());
461  if (!$packSession) {
462  $packSession = array();
463  }
464  }
465  $packSession[$ref] = array(
466  "ref" => $ref,
467  "needparse" => $needparse
468  );
469  if ($this->session) {
470  $this->session->Register("RSPACK_" . $packName, $packSession);
471  }
472 
473  if ($needparse) {
474  if ($fromAdd) {
475  if ($type == "js") {
476  unset($this->jsref[$resourcePackNoParseLocation]);
477  } elseif ($type == "css") {
478  unset($this->cssref[$resourcePackNoParseLocation]);
479  }
480  }
481  $resourceLocation = $resourcePackParseLocation;
482  } else {
483  $hasParseBefore = (($type === "js") && isset($this->jsref[$resourcePackParseLocation]));
484  if (!$hasParseBefore) {
485  $hasParseBefore = (($type === "css") && isset($this->cssref[$resourcePackParseLocation]));
486  }
487  if (!$hasParseBefore) {
488  $resourceLocation = $resourcePackNoParseLocation;
489  }
490  }
491  } elseif ($needparse) {
492  $resourceLocation = "?app=CORE&amp;action=CORE_CSS&amp;ukey=" . $key . "&amp;layout=" . $ref . "&amp;type=" . $type;
493  } else {
494  $location = $this->resolveResourceLocation($ref);
495  if ($location != '') {
496  $resourceLocation = (strpos($location, '?') !== false) ? $location : $location . '?wv=' . getParam("WVERSION");
497  }
498  }
499 
500  return $resourceLocation;
501  }
502  /**
503  * Get dynacase CSS link
504  *
505  * @api Get the src of a CSS with dynacase cache
506  *
507  * @param string $ref path, or URL, or filename (if in the current application), or APP:filename
508  * @param bool $needparse if true will be parsed by the template engine (false by default)
509  * @param string $packName use it to pack all the ref with the same packName into a single file
510  *
511  * @return string the src of the CSS or "" if non existent ref
512  */
513  public function getCssLink($ref, $needparse = null, $packName = '')
514  {
515  if (substr($ref, 0, 2) == './') {
516  $ref = substr($ref, 2);
517  }
518  $styleParseRule = $this->detectCssParse($ref, $needparse);
519  $rl = $this->getResourceLocation('css', $ref, $styleParseRule, $packName);
520  if (!$rl) {
521  $msg = sprintf(_("Cannot find %s resource file") , $ref);
522  $this->addLogMsg($msg);
523  $this->log->warning($msg);
524  }
525  return $rl;
526  }
527  /**
528  * Get dynacase JS link
529  *
530  * @api Get the src of a JS with dynacase cache
531  *
532  * @param string $ref path, or URL, or filename (if in the current application), or APP:filename
533  * @param bool $needparse if true will be parsed by the template engine (false by default)
534  * @param string $packName use it to pack all the ref with the same packName into a single file
535  *
536  * @return string the src of the JS or "" if ref not exists
537  */
538  public function getJsLink($ref, $needparse = false, $packName = '')
539  {
540  if (substr($ref, 0, 2) == './') {
541  $ref = substr($ref, 2);
542  }
543  $rl = $this->getResourceLocation('js', $ref, $needparse, $packName);
544  if (!$rl) {
545  $msg = sprintf(_("Cannot find %s resource file") , $ref);
546  $this->addLogMsg($msg);
547  $this->log->warning($msg);
548  }
549  return $rl;
550  }
551  /**
552  * Add a CSS in an action
553  *
554  * Use this method to add a CSS in an action that use the zone [CSS:REF] and the template engine
555  *
556  * @api Add a CSS in an action
557  *
558  * @param string $ref path, or URL, or filename (if in the current application), or APP:filename
559  * @param bool $needparse if true will be parsed by the template engine (false by default)
560  * @param string $packName use it to pack all the ref with the same packName into a single file
561  *
562  * @throws Dcp\Style\Exception
563  * @return string the path of the added ref or "" if the ref is not valid
564  */
565  public function addCssRef($ref, $needparse = null, $packName = '')
566  {
567  $styleParseRule = $this->detectCssParse($ref, $needparse);
568 
569  if (substr($ref, 0, 2) == './') $ref = substr($ref, 2);
570  return $this->AddRessourceRef('css', $ref, $styleParseRule, $packName);
571  }
572 
573  private function detectCssParse($ref, $askParse)
574  {
575  $needparse = $askParse;
576  $currentFileRule = $this->style->getRule('css', $ref);
577  if (is_array($currentFileRule)) {
578  if (isset($currentFileRule['flags']) && ($currentFileRule['flags'] & Style::RULE_FLAG_PARSE_ON_RUNTIME)) {
579  if (isset($currentFileRule['runtime_parser']) && is_array($currentFileRule['runtime_parser']) && isset($currentFileRule['runtime_parser']['className']) && null !== $currentFileRule['parse_on_runtime']['className']) {
580  throw new \Dcp\Style\Exception("STY0007", 'custom parse_on_runtime class is not supported yet');
581  }
582  $parseOnLoad = true;
583  if ((null !== $needparse) && ($parseOnLoad !== $needparse)) {
584  $this->log->warning(sprintf("%s was added with needParse to %s but style has a rule saying %s", $ref, var_export($needparse, true) , var_export($parseOnLoad, true)));
585  }
586  $needparse = $parseOnLoad;
587  }
588  }
589  $needparse = $needparse ? true : false;
590 
591  return $needparse;
592  }
593  /**
594  * Get the current CSS ref of the current action
595  *
596  * @return string[]
597  */
598  public function getCssRef()
599  {
600  if ($this->hasParent()) {
601  return ($this->parent->GetCssRef());
602  } else {
603  return ($this->cssref);
604  }
605  }
606  /**
607  * Add a JS in an action
608  *
609  * Use this method to add a JS in an action that use the zone [JS:REF] and the template engine
610  *
611  * @api Add a JS in an action
612  *
613  * @param string $ref path to a js, or URL to a js, or js file name (if in the current application), or APP:jsfilename
614  * @param bool $needparse if true will be parsed by the template engine (false by default)
615  * @param string $packName use it to pack all the ref with the same packName into a single file
616  *
617  * @return string the path of the added ref or "" if the ref is not valid
618  */
619  public function addJsRef($ref, $needparse = false, $packName = '')
620  {
621  if (substr($ref, 0, 2) == './') $ref = substr($ref, 2);
622  return $this->AddRessourceRef('js', $ref, $needparse, $packName);
623  }
624  /**
625  * Get the js ref array of the current action
626  *
627  * @return string[] array of location
628  */
629  public function getJsRef()
630  {
631  if ($this->hasParent()) {
632  return ($this->parent->GetJsRef());
633  } else {
634  return ($this->jsref);
635  }
636  }
637  /**
638  * Add a JS code in an action
639  * Use this method to add a JS in an action that use the zone [JS:REF] and the template engine
640  * (beware use protective ; because all the addJsCode are concatened)
641  *
642  * @api Add a JS code in an action
643  *
644  * @param string $code code to add
645  *
646  * @return void
647  */
648  public function addJsCode($code)
649  {
650  // Js Code are stored in the top level application
651  if ($this->hasParent()) {
652  $this->parent->AddJsCode($code);
653  } else {
654  $this->jscode[] = $code;
655  }
656  }
657  /**
658  * Get the js code of the current action
659  *
660  * @return string[]
661  */
662  public function getJsCode()
663  {
664  if ($this->hasParent()) {
665  return ($this->parent->GetJsCode());
666  } else {
667  return ($this->jscode);
668  }
669  }
670  /**
671  * Add a CSS code in an action
672  * Use this method to add a CSS in an action that use the zone [CSS:REF] and the template engine
673  *
674  * @api Add a CSS code in an action
675  *
676  * @param string $code code to add
677  *
678  * @return void
679  */
680  public function addCssCode($code)
681  {
682  // Css Code are stored in the top level application
683  if ($this->hasParent()) {
684  $this->parent->AddCssCode($code);
685  } else {
686  $this->csscode[] = $code;
687  }
688  }
689  /**
690  * Get the current CSS code of the current action
691  *
692  * @return string[]
693  */
694  public function getCssCode()
695  {
696  if ($this->hasParent()) {
697  return ($this->parent->GetCssCode());
698  } else {
699  return ($this->csscode);
700  }
701  }
702  /**
703  * Add message to log (syslog)
704  * The message is also displayed in the console of the web interface
705  *
706  * @param string $code message to add to log
707  * @param int $cut truncate message longer than this length (set to <= 0 to not truncate the message)(default is 0).
708  */
709  public function addLogMsg($code, $cut = 0)
710  {
711  if ($code == "") return;
712  // Js Code are stored in the top level application
713  if ($this->hasParent()) {
714  $this->parent->AddLogMsg($code, $cut);
715  } else {
716  if ($this->session) {
717  $logmsg = $this->session->read("logmsg", array());
718  if (is_array($code)) {
719  $code["stack"] = getDebugStack(4);
720  $logmsg[] = json_encode($code);
721  } else {
722  $logmsg[] = strftime("%H:%M - ") . str_replace("\n", "\\n", (($cut > 0) ? mb_substr($code, 0, $cut) : $code));
723  }
724  $this->session->register("logmsg", $logmsg);
725  $suser = sprintf("%s %s [%d] - ", $this->user->firstname, $this->user->lastname, $this->user->id);
726  if (is_array($code)) $code = print_r($code, true);
727  $this->log->info($suser . $code);
728  } else {
729  error_log($code);
730  }
731  }
732  }
733  /**
734  * send a message to the user interface
735  *
736  * @param string $code message
737  * @return void
738  */
739  public function addWarningMsg($code)
740  {
741  if (($code == "") || ($code == "-")) return;
742  // Js Code are stored in the top level application
743  if ($this->hasParent()) {
744  $this->parent->addWarningMsg($code);
745  } else {
746  if (!empty($_SERVER['HTTP_HOST']) && $this->session) {
747  $logmsg = $this->session->read("warningmsg", array());
748  $logmsg[] = $code;
749  $this->session->register("warningmsg", $logmsg);
750  } else {
751  error_log("dcp warning: $code");
752  }
753  }
754  }
755  /**
756  * Get log text messages
757  * @return array
758  */
759  public function getLogMsg()
760  {
761  return ($this->session ? ($this->session->read("logmsg", array())) : array());
762  }
763 
764  public function clearLogMsg()
765  {
766  if ($this->session) {
767  $this->session->unregister("logmsg");
768  }
769  }
770  /**
771  * Get warning texts
772  * @return array
773  */
774  public function getWarningMsg()
775  {
776  return ($this->session ? ($this->session->read("warningmsg", array())) : array());
777  }
778 
779  public function clearWarningMsg()
780  {
781  if ($this->session) {
782  $this->session->unregister("warningmsg");
783  }
784  }
785  /**
786  * mark the application as launched from admin context
787  *
788  * @param bool $enable true to enable admin mode, false to disable it
789  */
790  public function setAdminMode($enable = true)
791  {
792  if ($this->hasParent()) {
793  $this->parent->setAdminMode($enable);
794  } else {
795  $this->adminMode = ($enable ? true : false);
796  }
797  }
798  /**
799  * @return bool true if application is launched from admin context
800  */
801  public function isInAdminMode()
802  {
803  if ($this->hasParent()) {
804  return $this->parent->isInAdminMode();
805  }
806  return $this->adminMode === true;
807  }
808  /**
809  * Test permission for current user in current application
810  *
811  * @param string $acl_name acl name to test
812  * @param string $app_name application if test for other application
813  * @param bool $strict to not use substitute account information
814  * @return bool true if permission granted
815  */
816  public function hasPermission($acl_name, $app_name = "", $strict = false)
817  {
818  if (Action::ACCESS_FREE == $acl_name) {
819  return true;
820  }
821  if (!isset($this->user) || !is_object($this->user)) {
822  $this->log->warning("Action {$this->parent->name}:{$this->name} requires authentification");
823  return false;
824  }
825  if ($this->user->id == 1) return true; // admin can do everything
826  if ($app_name == "") {
827 
828  $acl = new Acl($this->dbaccess);
829  if (!$acl->Set($acl_name, $this->id)) {
830  $this->log->warning("Acl $acl_name not available for App $this->name");
831  return false;
832  }
833  if (!$this->permission) {
834  $permission = new Permission($this->dbaccess, array(
835  $this->user->id,
836  $this->id
837  ));
838  if (!$permission->IsAffected()) { // case of no permission available
839  $permission->Affect(array(
840  "id_user" => $this->user->id,
841  "id_application" => $this->id
842  ));
843  }
844  $this->permission = & $permission;
845  }
846 
847  return ($this->permission->HasPrivilege($acl->id, $strict));
848  } else {
849  // test permission for other application
850  if (!is_numeric($app_name)) $appid = $this->GetIdFromName($app_name);
851  else $appid = $app_name;
852 
853  $wperm = new Permission($this->dbaccess, array(
854  $this->user->id,
855  $appid
856  ));
857  if ($wperm->isAffected()) {
858  $acl = new Acl($this->dbaccess);
859  if (!$acl->Set($acl_name, $appid)) {
860  $this->log->warning("Acl $acl_name not available for App $this->name");
861  return false;
862  } else {
863  return ($wperm->HasPrivilege($acl->id, $strict));
864  }
865  }
866  }
867  return false;
868  }
869  /**
870  * create style parameters
871  * @param bool $init
872  * @param string $useStyle
873  */
874  public function initStyle($init = true, $useStyle = '')
875  {
876  if ($init == true) {
877  if (isset($this->user)) $pstyle = new Param($this->dbaccess, array(
878  "STYLE",
879  Param::PARAM_USER . $this->user->id,
880  "1"
881  ));
882  else $pstyle = new Param($this->dbaccess, array(
883  "STYLE",
885  "1"
886  ));
887  if (!$pstyle->isAffected()) $pstyle = new Param($this->dbaccess, array(
888  "STYLE",
890  "1"
891  ));
892 
893  $style = $pstyle->val;
894  $this->style = new Style($this->dbaccess, $style);
895 
896  $this->style->Set($this);
897  } else {
898  $style = ($useStyle) ? $useStyle : $this->getParam("STYLE");
899  $this->style = new Style($this->dbaccess, $style);
900 
901  $this->style->Set($this);
902  }
903  if ($style) {
904  // $this->AddCssRef("css/dcp/system.css");
905 
906 
907  }
908  }
909 
910  public function setLayoutVars($lay)
911  {
912  if ($this->hasParent()) {
913  $this->parent->SetLayoutVars($lay);
914  }
915  }
916 
917  public function getRootApp()
918  {
919  if ($this->parent == "") {
920  return ($this);
921  } else {
922  return ($this->parent->GetRootApp());
923  }
924  }
925 
926  public function getImageFile($img)
927  {
928 
929  return $this->rootdir . "/" . $this->getImageLink($img);
930  }
931 
932  var $noimage = "CORE/Images/core-noimage.png";
933  /**
934  * get image url of an application
935  * can also get another image by search in Images general directory
936  * @api get image url of an application
937  * @param string $img image filename
938  * @param bool $detectstyle to use theme image instead of original
939  * @param int $size to use image with another width (in pixel) - null is original size
940  * @return string url to download image
941  */
942  public function getImageLink($img, $detectstyle = true, $size = null)
943  {
944  static $cacheImgUrl = array();
945 
946  $cacheIndex = $img . $size;
947  if (isset($cacheImgUrl[$cacheIndex])) return $cacheImgUrl[$cacheIndex];
948  if ($img != "") {
949  // try style first
950  if ($detectstyle) {
951  $url = $this->style->GetImageUrl($img, "");
952  if ($url != "") {
953  if ($size !== null) $url = 'resizeimg.php?img=' . urlencode($url) . '&size=' . $size;
954  $cacheImgUrl[$cacheIndex] = $url;
955  return $url;
956  }
957  }
958  // try application
959  if (file_exists($this->rootdir . "/" . $this->name . "/Images/" . $img)) {
960  $url = $this->name . "/Images/" . $img;
961  if ($size !== null) $url = 'resizeimg.php?img=' . urlencode($url) . '&size=' . $size;
962  $cacheImgUrl[$cacheIndex] = $url;
963  return $url;
964  } else { // perhaps generic application
965  if (($this->childof != "") && (file_exists($this->rootdir . "/" . $this->childof . "/Images/" . $img))) {
966  $url = $this->childof . "/Images/" . $img;
967  if ($size !== null) $url = 'resizeimg.php?img=' . urlencode($url) . '&size=' . $size;
968  $cacheImgUrl[$cacheIndex] = $url;
969  return $url;
970  } else if (file_exists($this->rootdir . "/Images/" . $img)) {
971  $url = "Images/" . $img;
972  if ($size !== null) $url = 'resizeimg.php?img=' . urlencode($url) . '&size=' . $size;
973  $cacheImgUrl[$cacheIndex] = $url;
974  return $url;
975  }
976  }
977  // try in parent
978  if ($this->parent != "") {
979  $url = $this->parent->getImageLink($img);
980  if ($size !== null) $url = 'resizeimg.php?img=' . urlencode($url) . '&size=' . $size;
981  $cacheImgUrl[$cacheIndex] = $url;
982  return $url;
983  }
984  }
985  if ($size !== null) return 'resizeimg.php?img=' . urlencode($this->noimage) . '&size=' . $size;
986  return $this->noimage;
987  }
988  /**
989  * get image url of an application
990  * can also get another image by search in Images general directory
991  *
992  * @see Application::getImageLink
993  *
994  * @deprecated use { @link Application::getImageLink } instead
995  *
996  * @param string $img image filename
997  * @param bool $detectstyle to use theme image instead of original
998  * @param int $size to use image with another width (in pixel) - null is original size
999  * @return string url to download image
1000  */
1001  public function getImageUrl($img, $detectstyle = true, $size = null)
1002  {
1004  return $this->getImageLink($img, $detectstyle, $size);
1005  }
1006 
1007  public function imageFilterColor($image, $fcol, $newcol, $out = null)
1008  {
1009  if ($out === null) {
1010  $out = getTmpDir() . "/i.gif";
1011  }
1012  $im = imagecreatefromgif($image);
1013  $idx = imagecolorexact($im, $fcol[0], $fcol[1], $fcol[2]);
1014  imagecolorset($im, $idx, $newcol[0], $newcol[1], $newcol[2]);
1015  imagegif($im, $out);
1016  imagedestroy($im);
1017  }
1018 
1019  public function getFilteredImageUrl($imgf)
1020  {
1021 
1022  $ttf = explode(":", $imgf);
1023  $img = $ttf[0];
1024  $filter = $ttf[1];
1025 
1026  $url = $this->getImageLink($img);
1027  if ($url == $this->noimage) return $url;
1028 
1029  $tf = explode("|", $filter);
1030  if (count($tf) != 2) return $url;
1031 
1032  $fcol = explode(",", $tf[0]);
1033  if (count($fcol) != 3) return $url;
1034 
1035  if (substr($tf[1], 0, 1) == '#') $col = $tf[1];
1036  else $col = $this->getParam($tf[1]);
1037  $ncol[0] = hexdec(substr($col, 1, 2));
1038  $ncol[1] = hexdec(substr($col, 3, 2));
1039  $ncol[2] = hexdec(substr($col, 5, 2));
1040 
1041  $cdir = 'var/cache/image/';
1042  $rcdir = $this->rootdir . '/' . $cdir;
1043  if (!is_dir($rcdir)) mkdir($rcdir);
1044 
1045  $uimg = $cdir . $this->name . '-' . $fcol[0] . '.' . $fcol[1] . '.' . $fcol[2] . '_' . $ncol[0] . '.' . $ncol[1] . '.' . $ncol[2] . '.' . $img;
1046  $cimg = $this->rootdir . '/' . $uimg;
1047  if (file_exists($cimg)) return $uimg;
1048 
1049  $this->ImageFilterColor($this->rootdir . '/' . $url, $fcol, $ncol, $cimg);
1050  return $uimg;
1051  }
1052  /**
1053  * get file path layout from layout name
1054  * @param string $layname
1055  * @return string file path
1056  */
1057  public function getLayoutFile($layname)
1058  {
1059  if (strstr($layname, '..')) {
1060  return ""; // not authorized
1061 
1062  }
1063  $file = $this->style->GetLayoutFile($layname, "");
1064  if ($file != "") return $file;
1065 
1066  $laydir = $this->rootdir . "/" . $this->name . "/Layout/";
1067  $file = $laydir . $layname; // default file
1068  if (file_exists($file)) {
1069  return ($file);
1070  } else {
1071  // perhaps generic application
1072  $file = $this->rootdir . "/" . $this->childof . "/Layout/$layname";
1073  if (file_exists($file)) return ($file);
1074  }
1075  if ($this->parent != "") return ($this->parent->GetLayoutFile($layname));
1076  return ("");
1077  }
1078  public function OldGetLayoutFile($layname)
1079  {
1080  $file = $this->rootdir . "/" . $this->name . "/Layout/" . $layname;
1081  if (file_exists($file)) {
1082  $file = $this->style->GetLayoutFile($layname, $file);
1083  return ($file);
1084  }
1085  if ($this->parent != "") return ($this->parent->GetLayoutFile($layname));
1086  return ("");
1087  }
1088  /**
1089  * affect new value to an application parameter
1090  * @see ParameterManager to easily manage application parameters
1091  * @param string $key parameter id
1092  * @param string $val parameter value
1093  */
1094  public function setParam($key, $val)
1095  {
1096  if (is_array($val)) {
1097  if (isset($val["global"]) && $val["global"] == "Y") $type = Param::PARAM_GLB;
1098  else $type = Param::PARAM_APP;
1099  $this->param->Set($key, $val["val"], $type, $this->id);
1100  } else { // old method
1101  $this->param->Set($key, $val, Param::PARAM_APP, $this->id);
1102  }
1103  }
1104  /**
1105  * set user parameter for current user
1106  *
1107  * @see ParameterManager to easily manage application parameters
1108  * @param string $key parameter identifier
1109  * @param string $val value
1110  * @return string error message
1111  */
1112  public function setParamU($key, $val)
1113  {
1114  return $this->param->Set($key, $val, Param::PARAM_USER . $this->user->id, $this->id);
1115  }
1116  /**
1117  * declare new application parameter
1118  * @param string $key
1119  * @param array $val
1120  */
1121  public function setParamDef($key, $val)
1122  {
1123  // add new param definition
1124  $pdef = ParamDef::getParamDef($key, $this->id);
1125 
1126  $oldValues = array();
1127  if (!$pdef) {
1128  $pdef = new ParamDef($this->dbaccess);
1129  $pdef->name = $key;
1130  $pdef->isuser = "N";
1131  $pdef->isstyle = "N";
1132  $pdef->isglob = "N";
1133  $pdef->appid = $this->id;
1134  $pdef->descr = "";
1135  $pdef->kind = "text";
1136  } else {
1137  $oldValues = $pdef->getValues();
1138  }
1139 
1140  if (is_array($val)) {
1141  if (isset($val["kind"])) $pdef->kind = $val["kind"];
1142  if (isset($val["user"]) && $val["user"] == "Y") $pdef->isuser = "Y";
1143  else $pdef->isuser = "N";
1144  if (isset($val["style"]) && $val["style"] == "Y") $pdef->isstyle = "Y";
1145  else $pdef->isstyle = "N";
1146  if (isset($val["descr"])) $pdef->descr = $val["descr"];
1147  if (isset($val["global"]) && $val["global"] == "Y") $pdef->isglob = "Y";
1148  else $pdef->isglob = "N";
1149  }
1150 
1151  if ($pdef->appid == $this->id) {
1152  if ($pdef->isAffected()) {
1153  $pdef->Modify();
1154  // migrate paramv values in case of type changes
1155  $newValues = $pdef->getValues();
1156  if ($oldValues['isglob'] != $newValues['isglob']) {
1157  $ptype = $oldValues['isglob'] == 'Y' ? Param::PARAM_GLB : Param::PARAM_APP;
1158  $ptypeNew = $newValues['isglob'] == 'Y' ? Param::PARAM_GLB : Param::PARAM_APP;
1159  $pv = new Param($this->dbaccess, array(
1160  $pdef->name,
1161  $ptype,
1162  $pdef->appid
1163  ));
1164  if ($pv->isAffected()) {
1165  $pv->set($pv->name, $pv->val, $ptypeNew, $pv->appid);
1166  }
1167  }
1168  } else {
1169  $pdef->Add();
1170  }
1171  }
1172  }
1173  /**
1174  * Add temporary parameter to ths application
1175  * Can be use to transmit global variable or to affect Layout
1176  *
1177  * @param string $key
1178  * @param string $val
1179  */
1180  public function setVolatileParam($key, $val)
1181  {
1182  if ($this->hasParent()) $this->parent->setVolatileParam($key, $val);
1183  else $this->param->SetVolatile($key, $val);
1184  }
1185  /**
1186  * get parameter value
1187  * @param string $key
1188  * @param string $default value if not set
1189  * @return string
1190  */
1191  public function getParam($key, $default = "")
1192  {
1193  if (!isset($this->param)) return ($default);
1194  $z = $this->param->Get($key, "z");
1195 
1196  if ($z === "z") {
1197  if ($this->hasParent()) return $this->parent->GetParam($key, $default);
1198  } else {
1199  return ($z);
1200  }
1201  return ($default);
1202  }
1203  /**
1204  * create/update application parameter definition
1205  * @param array $tparam all parameter definition
1206  * @param bool $update
1207  */
1208  public function initAllParam($tparam, $update = false)
1209  {
1210  if (is_array($tparam)) {
1211  reset($tparam);
1212  foreach ($tparam as $k => $v) {
1213  $this->SetParamDef($k, $v); // update definition
1214  if ($update) {
1215  // don't modify old parameters
1216  if ($this->param && $this->param->Get($k, null) === null) {
1217  // set only new parameters or static variable like VERSION
1218  $this->SetParam($k, $v);
1219  }
1220  } else {
1221  $this->SetParam($k, $v);
1222  }
1223  }
1224  }
1225  }
1226  /**
1227  * get all parameters values indexed by name
1228  * @return array all paramters values
1229  */
1230  public function getAllParam()
1231  {
1232  $list = $this->param->buffer;
1233  if ($this->hasParent()) {
1234  $list2 = $this->parent->GetAllParam();
1235  $list = array_merge($this->param->buffer, $list2);
1236  }
1237 
1238  return ($list);
1239  }
1240  /**
1241  * initialize application description
1242  * from .app and _init.php configuration files
1243  * @param string $name application name reference
1244  * @param bool $update set to true when update application
1245  * @return bool true if init is done, false if error
1246  */
1247  public function initApp($name, $update = false)
1248  {
1249 
1250  $this->log->info("Init : $name");
1251  if (file_exists($this->rootdir . "/{$name}/{$name}.app")) {
1252  global $app_desc, $app_acl, $action_desc;
1253  // init global array
1254  $app_acl = array();
1255  $app_desc = array();
1256  $action_desc = array();
1257  include ("{$name}/{$name}.app");
1258  $action_desc_ini = $action_desc;
1259  if (sizeof($app_desc) > 0) {
1260  if (!$update) {
1261  $this->log->debug("InitApp : new application ");
1262  }
1263  if ($update) {
1264  foreach ($app_desc as $k => $v) {
1265  switch ($k) {
1266  case 'displayable':
1267  case 'available':
1268  break;
1269 
1270  default:
1271  $this->$k = $v;
1272  }
1273  }
1274  $this->Modify();
1275  } else {
1276  $this->available = "Y";
1277  foreach ($app_desc as $k => $v) {
1278  $this->$k = $v;
1279  }
1280  if ($this->isAffected()) {
1281  $this->modify();
1282  } else {
1283  $this->Add();
1284  }
1285  $this->param = new Param();
1286  $this->param->SetKey($this->id, isset($this->user->id) ? $this->user->id : Account::ANONYMOUS_ID);
1287  }
1288  } else {
1289  $this->log->info("can't init $name");
1290  return false;
1291  }
1292 
1293  $action_desc = $action_desc_ini;
1294  // init acl
1295  $acl = new Acl($this->dbaccess);
1296  $acl->Init($this, $app_acl, $update);
1297  // init actions
1298  $action = new Action($this->dbaccess);
1299  $action->Init($this, $action_desc, $update);
1300  // init father if has
1301  if ($this->childof != "") {
1302  // init ACL & ACTION
1303  // init acl
1304  simpleQuery($this->dbaccess, sprintf("INSERT INTO acl (id,id_application,name,grant_level,description, group_default) SELECT nextval('seq_id_acl') as id, %d as id_application, acl.name, acl.grant_level, acl.description, acl.group_default from acl as acl,application as app where acl.id_application=app.id and app.name='%s' and acl.name NOT IN (SELECT acl.name from acl as acl, application as app where id_application=app.id and app.name='%s')", $this->id, pg_escape_string($this->childof) , pg_escape_string($this->name)));
1305  // init actions
1306  simpleQuery($this->dbaccess, sprintf("INSERT INTO action (id, id_application, name, short_name, long_name,script,function,layout,available,acl,grant_level,openaccess,root,icon,toc,father,toc_order) SELECT nextval('seq_id_action') as id, %d as id_application, action.name, action.short_name, action.long_name, action.script, action.function, action.layout, action.available, action.acl, action.grant_level, action.openaccess, action.root, action.icon, action.toc, action.father, action.toc_order from action as action,application as app where action.id_application=app.id and app.name='%s' and action.name NOT IN (SELECT action.name from action as action, application as app where action.id_application=app.id and app.name='%s')", $this->id, pg_escape_string($this->childof) , pg_escape_string($this->name)));
1307  $this->log->info(sprintf("Update Actions from %s parent", $this->childof));
1308  $err = $this->_initACLWithGroupDefault();
1309  if ($err != '') {
1310  return false;
1311  }
1312  }
1313  //----------------------------------
1314  // init application constant
1315  if (file_exists($this->rootdir . "/{$name}/{$name}_init.php")) {
1316  include ("{$name}/{$name}_init.php");
1317  if ($update) {
1318  /* Store previous version for post migration scripts */
1319  global $app_const;
1320  $nextVersion = isset($app_const['VERSION']) ? $app_const['VERSION'] : '';
1321  if ($nextVersion != '') {
1322  $currentVersion = $this->getParam('VERSION', '');
1323  if ($currentVersion != '' && $nextVersion != $currentVersion) {
1324  $this->setParam('PREVIOUS_VERSION', array(
1325  'val' => $currentVersion,
1326  'kind' => 'static'
1327  ));
1328  }
1329  }
1330  }
1331  if ($this->param) {
1332  // delete paramters that cannot be change after initialisation to be change now
1333  if ($update) $this->param->DelStatic($this->id);
1334  global $app_const;
1335  if (isset($app_const)) $this->InitAllParam($app_const, $update);
1336  }
1337  }
1338  //----------------------------------
1339  // add init father application constant
1340  if (file_exists($this->rootdir . "/{$this->childof}/{$this->childof}_init.php")) {
1341  include ("{$this->childof}/{$this->childof}_init.php");
1342  global $app_const;
1343  $this->InitAllParam(array_filter($app_const, "f_paramglog") , true);
1344  }
1345 
1346  if ($this->id > 1) {
1347  $this->SetParamDef("APPNAME", array(
1348  "descr" => "$name application",
1349  "val" => $name,
1350  "kind" => "static"
1351  )); // use by generic application
1352  $this->SetParam("APPNAME", array(
1353  "val" => $name,
1354  "kind" => "static"
1355  )); // use by generic application
1356 
1357  }
1358  $this->updateChildApplications();
1359  } else {
1360  $this->log->info("No {$name}/{$name}.app available");
1361  return false;
1362  }
1363  return true;
1364  }
1365  /**
1366  * update action/acl/param for application's childs
1367  * @throws Dcp\Exception|Exception
1368  */
1369  private function updateChildApplications()
1370  {
1371  $sql = sprintf("select id, name from application where childof ='%s'", pg_escape_string($this->name));
1372 
1373  simpleQuery($this->dbaccess, $sql, $childIds);
1374  foreach ($childIds as $childApp) {
1375  $childId = $childApp["id"];
1376  $childName = $childApp["name"];
1377  $a = new Application($this->dbaccess, $childId);
1378 
1379  if ($a->isAffected()) {
1380  try {
1381  $a->set($childName, $noParent);
1382  $a->initApp($childName, true);
1383  }
1384  catch(\Dcp\Exception $e) {
1385  if ($e->getDcpCode() != "CORE0007") {
1386  throw $e;
1387  }
1388  }
1389  }
1390  }
1391  }
1392  /**
1393  * update application description
1394  * from .app and _init.php configuration files
1395  */
1396  public function updateApp()
1397  {
1398  $name = $this->name;
1399  $this->InitApp($name, true);
1400  }
1401  /**
1402  * Update All available application
1403  * @see updateApp
1404  */
1405  public function updateAllApp()
1406  {
1407 
1408  $query = new QueryDb($this->dbaccess, $this->dbtable);
1409  $query->AddQuery("available = 'Y'");
1410  $allapp = $query->Query();
1411 
1412  foreach ($allapp as $app) {
1413  $application = new Application($this->dbaccess, $app->id);
1414 
1415  $application->Set($app->name, $this->parent);
1416  $application->UpdateApp();
1417  }
1418  }
1419  /**
1420  * delete application
1421  * database application reference are destroyed but application files are not removed from server
1422  * @return string
1423  */
1424  public function deleteApp()
1425  {
1426  // delete acl
1427  $acl = new Acl($this->dbaccess);
1428  $acl->DelAppAcl($this->id);
1429  // delete actions
1430  $this->log->debug("Delete {$this->name}");
1431  $query = new QueryDb("", "Action");
1432  $query->basic_elem->sup_where = array(
1433  "id_application = {$this->id}"
1434  );
1435  $list = $query->Query();
1436 
1437  if ($query->nb > 0) {
1438  /*
1439  * @var Action $v
1440  */
1441  foreach ($list as $v) {
1442  $this->log->debug(" Delete action {$v->name} ");
1443  $err = $v->Delete();
1444  if ($err != '') {
1445  return $err;
1446  }
1447  }
1448  }
1449  unset($query);
1450 
1451  unset($list);
1452  // delete params
1453  $param = new Param($this->dbaccess);
1454  $param->DelAll($this->id);
1455  // delete application
1456  $err = $this->Delete();
1457  return $err;
1458  }
1459  /**
1460  * translate text
1461  * use gettext catalog
1462  *
1463  * @param string $code text to translate
1464  * @return string
1465  */
1466  public static function text($code)
1467  {
1468  if ($code == "") return "";
1469  return _($code);
1470  }
1471  /**
1472  * Write default ACL when new user is created
1473  * @TODO not used - to remove
1474  * @param int $iduser
1475  * @throws \Dcp\Db\Exception
1476  */
1477  public function updateUserAcl($iduser)
1478  {
1479 
1480  $query = new QueryDb($this->dbaccess, $this->dbtable);
1481  $query->AddQuery("available = 'Y'");
1482  $allapp = $query->Query();
1483  $acl = new Acl($this->dbaccess);
1484 
1485  foreach ($allapp as $v) {
1486  $permission = new Permission($this->dbaccess);
1487  $permission->id_user = $iduser;
1488  $permission->id_application = $v->id;
1489 
1490  $privileges = $acl->getDefaultAcls($v->id);
1491 
1492  foreach ($privileges as $aclid) {
1493  $permission->id_acl = $aclid;
1494  if (($permission->id_acl > 0) && (!$permission->Exists($permission->id_user, $v->id))) {
1495  $permission->Add();
1496  }
1497  }
1498  }
1499  }
1500  /**
1501  * return id from name for an application
1502  * @param string $name
1503  * @return int (0 if not found)
1504  */
1505  public function getIdFromName($name)
1506  {
1507  $query = new QueryDb($this->dbaccess, $this->dbtable);
1508  $query->AddQuery("name = '" . pg_escape_string(trim($name)) . "'");
1509  $app = $query->Query(0, 0, "TABLE");
1510  if (is_array($app) && isset($app[0]) && isset($app[0]["id"])) return $app[0]["id"];
1511  return 0;
1512  }
1513  /**
1514  * verify if application object has parent application
1515  * @return bool
1516  */
1517  public function hasParent()
1518  {
1519  return (is_object($this->parent) && ($this->parent !== $this));
1520  }
1521  /**
1522  * Initialize ACLs with group_default='Y'
1523  */
1524  private function _initACLWithGroupDefault()
1525  {
1526  $res = array();
1527  try {
1528  simpleQuery($this->dbaccess, sprintf("SELECT * FROM acl WHERE id_application = %s AND group_default = 'Y'", $this->id) , $res, false, false, true);
1529  }
1530  catch(Exception $e) {
1531  return $e->getMessage();
1532  }
1533  foreach ($res as $acl) {
1534  $permission = new Permission($this->dbaccess);
1535  if ($permission->Exists(Account::GALL_ID, $this->id, $acl['id'])) {
1536  continue;
1537  }
1538  $permission->Affect(array(
1539  'id_user' => Account::GALL_ID,
1540  'id_application' => $this->id,
1541  'id_acl' => $acl['id']
1542  ));
1543  $err = $permission->Add();
1544  if ($err != '') {
1545  return $err;
1546  }
1547  }
1548  return '';
1549  }
1550 }
initAllParam($tparam, $update=false)
set($name, &$parent, $session="", $autoinit=false, $verifyAvailable=true)
const GALL_ID
setParamDef($key, $val)
const ACCESS_FREE
imageFilterColor($image, $fcol, $newcol, $out=null)
global $action
initApp($name, $update=false)
getParam($key, $default="")
global $app_const
updateUserAcl($iduser)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
exec_query($sql, $lvl=0, $prepare=false)
print $fam getTitle() $fam name
Add($nopost=false, $nopre=false)
hasPermission($acl_name, $app_name="", $strict=false)
$size
Definition: resizeimg.php:110
$ret
setVolatileParam($key, $val)
const ANONYMOUS_ID
getCssLink($ref, $needparse=null, $packName= '')
$filename
$core user
Definition: chgpasswd.php:38
$file
addRessourceRef($type, $ref, $needparse, $packName)
Redirect($action, $appname, $actionname, $otherurl="", $httpparamredirect=false)
Definition: Lib.Http.php:21
getFilteredImageUrl($imgf)
isAffected()
static getParamDef($name, $appid=null)
fetch_array($c, $type=PGSQL_ASSOC)
setParam($key, $val)
addLogMsg($code, $cut=0)
setParamU($key, $val)
const DEFAULT_PUBDIR
Definition: Lib.Prefix.php:28
exists($app_name, $id_application=0)
static text($code)
$ncol
Definition: Api/ods2csv.php:22
modify($nopost=false, $sfields="", $nopre=false)
const PARAM_USER
Definition: Class.Param.php:34
$core session
Definition: wsh.php:98
__construct($dbaccess= '', $id= '', $res= '', $dbid=0)
$app
if(!$img) $location
Definition: resizeimg.php:143
addCssRef($ref, $needparse=null, $packName= '')
const PARAM_APP
Definition: Class.Param.php:32
getDebugStack($slice=1)
Definition: Lib.Common.php:325
const RULE_FLAG_PARSE_ON_RUNTIME
Definition: Class.Style.php:18
f_paramglog($var)
getTmpDir($def= '/tmp')
Definition: Lib.Common.php:150
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
global $_SERVER
const PARAM_GLB
Definition: Class.Param.php:33
switch($command) exit
Definition: checkVault.php:46
getLayoutFile($layname)
setAdminMode($enable=true)
if(($docid!==0)&&(!is_numeric($docid))) $query
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
Definition: Lib.Common.php:484
getImageUrl($img, $detectstyle=true, $size=null)
if($file) if($subject==""&&$file) if($subject=="") $err
getImageLink($img, $detectstyle=true, $size=null)
getJsLink($ref, $needparse=false, $packName= '')
affect($array, $more=false, $reset=true)
OldGetLayoutFile($layname)
initStyle($init=true, $useStyle= '')
addJsRef($ref, $needparse=false, $packName= '')
$packName
Definition: pack.php:56
setSession(&$session)
← centre documentaire © anakeen