PageRenderTime 35ms CodeModel.GetById 18ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/gulliver/bin/tasks/templates/sysGeneric.php.tpl

https://github.com/caracolazo/pm
Smarty Template | 388 lines | 336 code | 52 blank | 0 comment | 62 complexity | cc8a636920692a8d076d7b127259c910 MD5 | raw file
  1<?php
  2/** autogenerated sysGeneric for project {projectName} */
  3/*** enable display_error On to caught even fatal errors ***/
  4ini_set('display_errors','On');
  5ini_set('error_reporting', E_ALL  );
  6ini_set('memory_limit', '80M');
  7
  8$path = Array();
  9$sf = $_SERVER['SCRIPT_FILENAME'];
 10
 11//sysGeneric, this file is used to redirect to workspace, the url should by encrypted or not
 12
 13//***************** In the PATH_SEP we know if the the path separator symbol will be '\\' or '/' **************************
 14  if ( PHP_OS == 'WINNT' && !strpos ( $_SERVER['DOCUMENT_ROOT'], '/' ) )
 15   define('PATH_SEP','\\');
 16  else
 17   define('PATH_SEP', '/');
 18
 19
 20//***************** Defining the Home Directory *********************************
 21$docuroot = explode ( PATH_SEP , $_SERVER['DOCUMENT_ROOT'] );
 22//  array_pop($docuroot);
 23  array_pop($docuroot);
 24  $pathhome = implode( PATH_SEP, $docuroot )  . PATH_SEP;
 25
 26
 27  //try to find automatically the trunk directory where are placed the RBAC and Gulliver directories
 28  //in a normal installation you don't need to change it.
 29  array_pop($docuroot);
 30  $pathTrunk = implode( PATH_SEP, $docuroot ) . PATH_SEP ;
 31
 32  array_pop($docuroot);
 33  $pathOutTrunk = implode( PATH_SEP, $docuroot ) . PATH_SEP ;
 34  // to do: check previous algorith for Windows  $pathTrunk = "c:/home/";
 35
 36  define('PATH_HOME',     $pathhome );
 37  define('PATH_TRUNK',    $pathTrunk  );
 38  define('PATH_OUTTRUNK', $pathOutTrunk );
 39
 40//***************** In this file we cant to get the PM paths , RBAC Paths and Gulliver Paths  ******************************
 41  require_once ( $pathhome . PATH_SEP . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php' );
 42
 43//***************** In this file we cant to get the PM definitions  ******************************
 44  require_once ( $pathhome . PATH_SEP . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'defines.php' );
 45
 46//******************* Error handler and log error *******************
 47  //to do: make different environments.  sys
 48  //G::setErrorHandler ( );
 49  //G::setFatalErrorHandler ( );
 50
 51  /*** enable ERROR_SHOW_SOURCE_CODE to display the source code for any WARNING OR NOTICE ***/
 52  define ('ERROR_SHOW_SOURCE_CODE', true);
 53
 54 /*** enable ERROR_LOG_NOTICE_ERROR to log Notices messages in default apache log ***/
 55  //  define ( 'ERROR_LOG_NOTICE_ERROR', true );
 56
 57//  ************* creat headPublisher singleton *****************
 58  G::LoadSystem('headPublisher');
 59  $oHeadPublisher =& headPublisher::getSingleton();
 60  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/maborak.js' );   
 61  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'common/core/common.js' );     
 62  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'common/core/webResource.js' );
 63  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'dveditor/core/dveditor.js' ); 
 64  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'common/tree/tree.js' );       
 65  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'json/core/json.js' );         
 66  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'form/core/form.js' );         
 67  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'form/core/pagedTable.js' );   
 68  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'grid/core/grid.js' );         
 69  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.panel.js'    , true );
 70  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.validator.js', true );
 71  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.app.js'      , true );
 72  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.rpc.js'      , true );
 73  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.fx.js'       , true );
 74  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.drag.js'     , true );
 75  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.drop.js'     , true );
 76  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.dom.js'      , true );
 77  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.abbr.js'     , true );
 78  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'maborak/core/module.dashboard.js', true );
 79  $oHeadPublisher->addMaborakFile( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'widgets/jscalendar/calendar.js' );
 80
 81//************ defining Virtual URLs ****************/
 82  $virtualURITable = array();
 83  $virtualURITable['/plugin/(*)']                    = 'plugin';
 84  $virtualURITable['/(sys*)/(*.js)']                 =  'jsMethod';
 85  $virtualURITable['/js/(*)']                        = PATH_GULLIVER_HOME . 'js/';
 86  $virtualURITable['/jscore/(*)']                    = PATH_CORE . 'js/';
 87  //$virtualURITable['/fckeditor/(*)']               = PATH_THIRDPARTY . 'fckeditor/';
 88  $virtualURITable['/htmlarea/(*)']                  = PATH_THIRDPARTY . 'htmlarea/';
 89  $virtualURITable['/sys[a-zA-Z][a-zA-Z0-9]{0,}()/'] = 'sysNamed';
 90  $virtualURITable['/(sys*)']                        = FALSE;
 91  $virtualURITable['/errors/(*)']                    = PATH_GULLIVER_HOME . 'methods/errors/';
 92  $virtualURITable['/controls/(*)']                  = PATH_GULLIVER_HOME . 'methods/controls/';
 93  $virtualURITable['/html2ps_pdf/(*)']               = PATH_THIRDPARTY . 'html2ps_pdf/';
 94  $virtualURITable['/Krumo/(*)']                     = PATH_THIRDPARTY . 'krumo/';
 95  $virtualURITable['/codepress/(*)']                 = PATH_THIRDPARTY . 'codepress/';
 96
 97  if(defined('PATH_C'))
 98 {
 99	  $virtualURITable['/jsform/(*.js)']                 = PATH_C . 'xmlform/';
100 }
101  /*To sysUnnamed*/
102  $virtualURITable['/[a-zA-Z][a-zA-Z0-9]{0,}()'] = 'sysUnnamed';
103  $virtualURITable['/(*)'] = PATH_HTML;
104
105//************** verify if we need to redirect or stream the file **************
106  if ( G::virtualURI($_SERVER['REQUEST_URI'], $virtualURITable , $realPath )) {
107  	// review if the file requested belongs to public_html plugin
108    if ( substr ( $realPath, 0,6) == 'plugin' ) {
109      $paths = explode ( PATH_SEP, $realPath );
110      $paths[0] = substr ( $paths[0],6);
111      if ( count($paths) == 2 )  {
112        $pathsQuery = explode('?', $paths[1]);
113        $pluginFilename = PATH_PLUGINS . $paths[0] . PATH_SEP . 'public_html'. PATH_SEP . $pathsQuery[0];
114        if ( file_exists ( $pluginFilename ) ) {
115        	G::streamFile ( $pluginFilename );
116        }
117      }
118      die;
119	  }
120
121  	switch ( $realPath  ) {
122    case 'sysUnnamed' :
123      require_once('sysUnnamed.php'); die;
124    	break;
125    case 'sysNamed' :
126      header('location : ' . $_SERVER['REQUEST_URI'] . 'en/classic/login/login' );
127      die;
128	    break;
129    case 'jsMethod' :
130		  G::parseURI ( getenv( "REQUEST_URI" ) );
131		  $filename = PATH_METHODS . SYS_COLLECTION . '/' . SYS_TARGET . '.js';
132    	G::streamFile ( $filename );
133    	die;
134	    break;
135    default :
136      $realPath = explode('?', $realPath);
137    	G::streamFile ( $realPath[0] );
138    	die;
139    }
140  }
141
142//************** verify if the URI is encrypted or not **************
143  G::parseURI ( getenv( "REQUEST_URI" ) );
144
145  define( 'SYS_URI' , '/sys' .  SYS_TEMP . '/' . SYS_LANG . '/' . SYS_SKIN . '/' );
146
147  require_once ( PATH_THIRDPARTY . 'krumo' . PATH_SEP . 'class.krumo.php' );
148
149//***************** Call Gulliver Classes **************************
150
151  G::LoadThirdParty('pear/json','class.json');
152  G::LoadThirdParty('smarty/libs','Smarty.class');
153
154  G::LoadSystem('error');
155  G::LoadSystem('dbconnection');
156  G::LoadSystem('dbsession');
157  G::LoadSystem('dbrecordset');
158  G::LoadSystem('dbtable');
159  G::LoadSystem('rbac' );
160  G::LoadSystem('publisher');
161  G::LoadSystem('templatePower');
162  G::LoadSystem('headPublisher');
163  G::LoadSystem('xmlDocument');
164  G::LoadSystem('xmlform');
165  G::LoadSystem('xmlformExtension');
166  G::LoadSystem('form');
167  G::LoadSystem('menu');
168  G::LoadSystem("xmlMenu");
169  G::LoadSystem('dvEditor');
170  G::LoadSystem('table');
171  G::LoadSystem('pagedTable');
172  G::LoadSystem('tree');
173
174  $oHeadPublisher =& headPublisher::getSingleton();
175  
176  //***************** database and workspace definition  ************************
177  //if SYS_TEMP exists, the URL has a workspace, now we need to verify if exists their db.php file
178  if ( defined('SYS_TEMP') && SYS_TEMP != '')
179  {
180	  //this is the default, the workspace db.php file is in /shared/{projectName}/sites/SYS_SYS
181    if ( file_exists( PATH_DB .  SYS_TEMP . '/db.php' ) ) {
182      require_once( PATH_DB .  SYS_TEMP . '/db.php' );
183      define ( 'SYS_SYS' , SYS_TEMP );
184    }
185    else {
186      $sysParts = explode('-',SYS_TEMP);
187      //try to find the definition in the module-file
188      if ( count($sysParts) == 3) {
189        $fileName = 'dbmodule_'.$sysParts[1].'.php';
190        $DB_INDEX = 0;
191        $DB_MODULE = array();
192
193        if ( !file_exists( PATH_DB . $fileName)) {
194          header ("location: errors/error701.php");
195          die;
196        }
197        require_once ( PATH_DB . $fileName );
198        $moduleName = $DB_MODULE[$DB_INDEX]['name'];
199        $modulePath = $DB_MODULE[$DB_INDEX]['path'];
200        $moduleType = $DB_MODULE[$DB_INDEX]['type'];
201        if ( !file_exists( $modulePath )) {
202          header ("location: /errors/error704.php"); die;
203        }
204        if ( $moduleType == 'single-file' ) {
205          $workspaceDB = $modulePath. 'db_'. $sysParts[2] . '.php';
206        }
207        else {
208          $workspaceDB = $modulePath.  $sysParts[2] . '/db.php';
209        }
210        if ( !file_exists( $workspaceDB )) {
211          header ("location: /errors/error704.php"); die;
212        }
213        require_once( $workspaceDB ) ;
214        define ( 'SYS_SYS', $sysParts[2]);
215      }
216      else {
217       $aMessage['MESSAGE'] = G::LoadTranslation ('ID_NOT_WORKSPACE');
218       $G_PUBLISH          = new Publisher;
219       $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
220       G::RenderPage( 'publish' );
221       die;
222      }
223    }
224  }
225  else {  //when we are in global pages, outside any valid workspace
226
227
228    if ((SYS_TARGET==='sysLoginVerify') || (SYS_TARGET==='sysLogin') || (SYS_TARGET==='newSite')) {
229  	  $phpFile = G::ExpandPath('methods') . SYS_COLLECTION . "/" . SYS_TARGET.'.php';
230  	  require_once($phpFile);
231  	  die();
232    }
233    else {
234      require_once( PATH_METHODS . "login/sysLogin.php" ) ;
235      die();
236    }
237  }
238
239//***************** PM Paths DATA **************************
240  define( 'PATH_DATA_SITE',   PATH_DATA . 'sites/' . SYS_SYS . '/');
241  define( 'PATH_DOCUMENT',    PATH_DATA_SITE . 'files/' );
242  define( 'PATH_DYNAFORM',    PATH_DATA_SITE . 'xmlForms/' );
243  define( 'PATH_IMAGES_ENVIRONMENT_FILES',  PATH_DATA_SITE.'usersFiles'.PATH_SEP);
244  define( 'PATH_IMAGES_ENVIRONMENT_USERS',  PATH_DATA_SITE.'usersPhotographies'.PATH_SEP);
245
246
247//***************** Plugins **************************
248	G::LoadClass('plugin');
249//  //here we are loading all plugins registered
250//  //the singleton has a list of enabled plugins
251
252//  $sSerializedFile = PATH_DATA_SITE . 'plugin.singleton';
253//  $oPluginRegistry =& PMPluginRegistry::getSingleton();
254//  if ( file_exists ($sSerializedFile) )
255//    $oPluginRegistry->unSerializeInstance( file_get_contents  ( $sSerializedFile ) );
256//
257//  $oPluginRegistry->setupPlugins(); //get and setup enabled plugins
258
259//***************** create $G_ENVIRONMENTS dependent of SYS_SYS **************************
260
261  define ( 'G_ENVIRONMENT', G_DEV_ENV );
262  $G_ENVIRONMENTS = array (
263    G_PRO_ENV => array (
264      'dbfile' => PATH_DB . 'production' . PATH_SEP . 'db.php' ,
265      'cache' => 1,
266      'debug' => 0,
267    ) ,
268    G_DEV_ENV => array (
269      'dbfile' => PATH_DB . SYS_SYS . PATH_SEP . 'db.php',
270      'datasource' => 'workflow',
271      'cache' => 0,
272      'debug' => 0,
273    ) ,
274    G_TEST_ENV => array (
275      'dbfile' => PATH_DB . 'test' . PATH_SEP . 'db.php' ,
276      'cache' => 0,
277      'debug' => 0,
278    )
279 );
280
281  // setup propel definitions and logging
282  //try {
283    require_once ( "propel/Propel.php" );
284    require_once ( "creole/Creole.php" );
285
286    if ( $G_ENVIRONMENTS[ G_ENVIRONMENT ]['debug'] ) {
287      require_once ( "Log.php" );
288
289      // register debug connection decorator driver
290      Creole::registerDriver('*', 'creole.contrib.DebugConnection');
291
292      // itialize Propel with converted config file
293      Propel::init( PATH_CORE . "config/databases.php" );
294
295      //log file for workflow database
296      $logFile = PATH_DATA . 'log' . PATH_SEP . 'workflow.log';
297      $logger = Log::singleton('file', $logFile, 'wf ' . SYS_SYS, null, PEAR_LOG_INFO);
298      Propel::setLogger($logger);
299      $con = Propel::getConnection('workflow');
300      if ($con instanceof DebugConnection) $con->setLogger($logger);
301
302      //log file for rbac database
303      $logFile = PATH_DATA . 'log' . PATH_SEP . 'rbac.log';
304      $logger = Log::singleton('file', $logFile, 'rbac ' . SYS_SYS, null, PEAR_LOG_INFO);
305      Propel::setLogger($logger);
306      $con = Propel::getConnection('rbac');
307      if ($con instanceof DebugConnection) $con->setLogger($logger);
308    }
309    else
310      Propel::init( PATH_CORE . "config/databases.php" );
311
312    Creole::registerDriver('dbarray', 'creole.contrib.DBArrayConnection');
313
314    //***************** Session Initializations **************************/
315      ini_alter( 'session.auto_start', '1' );
316      ini_alter( 'register_globals',   'Off' );
317      session_start();
318      ob_start();
319
320    //********* Log Page Handler *************
321    //  logPage ( $URL , SYS_CURRENT_PARMS);
322
323    //*********jump to php file in methods directory *************
324//    if ( $oPluginRegistry->isRegisteredFolder( SYS_COLLECTION ) )
325//      $phpFile = PATH_PLUGINS . SYS_COLLECTION . PATH_SEP . SYS_TARGET.'.php';
326//    else
327      $phpFile = G::ExpandPath('methods') . SYS_COLLECTION . PATH_SEP . SYS_TARGET.'.php';
328
329    //the index.php file, this new feature will allow automatically redirects to valid php file inside the methods directory
330    if ( SYS_TARGET == '' ) {
331      $phpFile = str_replace ( '.php', 'index.php', $phpFile );
332      $phpFile = include ( $phpFile );
333    }
334    if ( substr(SYS_COLLECTION , 0,8) === 'gulliver' ) {
335      $phpFile = PATH_GULLIVER_HOME . 'methods/' . substr( SYS_COLLECTION , 8) . SYS_TARGET.'.php';
336    }
337    else {
338      if ( ! file_exists( $phpFile ) ) {
339          $_SESSION['phpFileNotFound'] = $phpFile;
340          header ("location: /errors/error404.php");
341          die;
342      }
343    }
344
345//  ***************** enable rbac **************************
346
347    $RBAC =& RBAC::getSingleton();
348    $RBAC->sSystem = '{rbacProjectName}';
349
350//  ***************** Headers **************************
351    if ( ! defined('EXECUTE_BY_CRON') ) {
352      header("Expires: Tue, 19 Jan 1999 04:30:00 GMT");
353      header("Last-Modified: Tue, 19 Jan 1999 04:30:00 GMT");
354      header('Cache-Control: no-cache, must-revalidate, post-check=0,pre-check=0 ');
355      header('P3P: CP="CAO PSA OUR"');
356
357      if(isset( $_SESSION['USER_LOGGED'] )) {
358        $RBAC->initRBAC();
359        $RBAC->loadUserRolePermission( $RBAC->sSystem, $_SESSION['USER_LOGGED'] );
360      }
361      else {
362        //This sentence is used when you lost the Session
363        if ( SYS_TARGET != 'authentication' and  SYS_TARGET != 'login'
364        and  SYS_TARGET != 'dbInfo'         and  SYS_TARGET != 'sysLoginVerify'
365        and  SYS_TARGET != 'updateTranslation'  and  SYS_COLLECTION != 'services' ){
366          header ("location: ".SYS_URI."login/login.php");
367          die();
368        }
369      }
370
371      require_once( $phpFile );
372      if ( defined('SKIP_HEADERS') ) {
373	    header("Expires: " . gmdate("D, d M Y H:i:s", mktime( 0,0,0,date('m'),date('d'),date('Y') + 1) ) . " GMT");
374        header('Cache-Control: public');
375        header('Pragma: ');
376      }
377      ob_end_flush();
378    }
379/*
380  }
381  catch ( Exception $e ) {
382    $aMessage['MESSAGE'] = $e->getMessage();
383    $G_PUBLISH  = new Publisher;
384    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
385    G::RenderPage( 'publish' );
386    die;
387  }
388*/